1*4f506f19SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*4f506f19SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4f506f19SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4f506f19SAndrew Rist  * distributed with this work for additional information
6*4f506f19SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4f506f19SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4f506f19SAndrew Rist  * "License"); you may not use this file except in compliance
9*4f506f19SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*4f506f19SAndrew Rist  *
11*4f506f19SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*4f506f19SAndrew Rist  *
13*4f506f19SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4f506f19SAndrew Rist  * software distributed under the License is distributed on an
15*4f506f19SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4f506f19SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4f506f19SAndrew Rist  * specific language governing permissions and limitations
18*4f506f19SAndrew Rist  * under the License.
19*4f506f19SAndrew Rist  *
20*4f506f19SAndrew Rist  *************************************************************/
21*4f506f19SAndrew Rist 
22*4f506f19SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
25cdf0e10cSrcweir #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
26cdf0e10cSrcweir 
27090f0eb8SEike Rathke #include <drawinglayer/drawinglayerdllapi.h>
28cdf0e10cSrcweir #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation3d.hxx>
31cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
32cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
33cdf0e10cSrcweir #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
34cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
35cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace drawinglayer
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	namespace primitive2d
42cdf0e10cSrcweir 	{
43cdf0e10cSrcweir         /** ScenePrimitive2D class
44cdf0e10cSrcweir 
45cdf0e10cSrcweir             This primitive defines a 3D scene as a 2D primitive and is the anchor point
46cdf0e10cSrcweir             for a 3D visualisation. The decomposition is view-dependent and will try to
47cdf0e10cSrcweir             re-use already rendered 3D content.
48cdf0e10cSrcweir 
49cdf0e10cSrcweir             The rendering is done using the default-3D renderer from basegfx which supports
50cdf0e10cSrcweir             AntiAliasing.
51cdf0e10cSrcweir 
52cdf0e10cSrcweir             The 2D primitive's geometric range is defined completely by the
53cdf0e10cSrcweir             ObjectTransformation combined with evtl. 2D shadows from the 3D objects. The
54cdf0e10cSrcweir             shadows of 3D objects are 2D polygons, projected with the 3D transformation.
55cdf0e10cSrcweir 
56cdf0e10cSrcweir             This is the class a renderer may process directly when he wants to implement
57cdf0e10cSrcweir             an own (e.g. system-specific) 3D renderer.
58cdf0e10cSrcweir          */
59090f0eb8SEike Rathke 		class DRAWINGLAYER_DLLPUBLIC ScenePrimitive2D : public BufferedDecompositionPrimitive2D
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 		private:
62cdf0e10cSrcweir             /// the 3D geometry definition
63cdf0e10cSrcweir 			primitive3d::Primitive3DSequence					mxChildren3D;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir             /// 3D scene attribute set
66cdf0e10cSrcweir 			attribute::SdrSceneAttribute						maSdrSceneAttribute;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir             /// lighting attribute set
69cdf0e10cSrcweir             attribute::SdrLightingAttribute						maSdrLightingAttribute;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir             /// object transformation for scene for 2D definition
72cdf0e10cSrcweir 			basegfx::B2DHomMatrix								maObjectTransformation;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             /// scene transformation set and object transformation
75cdf0e10cSrcweir 			geometry::ViewInformation3D							maViewInformation3D;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 			/// the primitiveSequence for on-demand created shadow primitives (see mbShadow3DChecked)
78cdf0e10cSrcweir 			Primitive2DSequence									maShadowPrimitives;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 			/// bitfield
81cdf0e10cSrcweir 			/** flag if given 3D geometry is already cheched for shadow definitions and 2d shadows
82cdf0e10cSrcweir 			    are created in maShadowPrimitives
83cdf0e10cSrcweir              */
84cdf0e10cSrcweir 			unsigned											mbShadow3DChecked : 1;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 			/// the last used NewDiscreteSize and NewUnitVisiblePart definitions for decomposition
87cdf0e10cSrcweir 			double												mfOldDiscreteSizeX;
88cdf0e10cSrcweir 			double												mfOldDiscreteSizeY;
89cdf0e10cSrcweir 			basegfx::B2DRange									maOldUnitVisiblePart;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir             /** the last created BitmapEx, e.g. for fast HitTest. This does not really need
92cdf0e10cSrcweir                 memory since BitmapEx is internally RefCounted
93cdf0e10cSrcweir              */
94cdf0e10cSrcweir             BitmapEx                                            maOldRenderedBitmap;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			/// private helpers
97cdf0e10cSrcweir 			bool impGetShadow3D(const geometry::ViewInformation2D& rViewInformation) const;
98cdf0e10cSrcweir 			void calculateDiscreteSizes(
99cdf0e10cSrcweir 				const geometry::ViewInformation2D& rViewInformation,
100cdf0e10cSrcweir 				basegfx::B2DRange& rDiscreteRange,
101cdf0e10cSrcweir 				basegfx::B2DRange& rVisibleDiscreteRange,
102cdf0e10cSrcweir 				basegfx::B2DRange& rUnitVisibleRange) const;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		protected:
105cdf0e10cSrcweir 			/// local decomposition.
106cdf0e10cSrcweir 			virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		public:
109cdf0e10cSrcweir 			/// public helpers
110cdf0e10cSrcweir 			/** Geometry extractor. Shadow will be added as in create2DDecomposition, but
111cdf0e10cSrcweir 			    the 3D content is not converted to a bitmap visualisation but to projected 2D gemetry. This
112cdf0e10cSrcweir 			    helper is useful e.g. for Contour extraction or HitTests.
113cdf0e10cSrcweir               */
114cdf0e10cSrcweir 			Primitive2DSequence getGeometry2D() const;
115cdf0e10cSrcweir 			Primitive2DSequence getShadow2D(const geometry::ViewInformation2D& rViewInformation) const;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir             /** Fast HitTest which uses the last buffered BitmapEx from the last
118cdf0e10cSrcweir                 rendered area if available. The return value describes if the check
119cdf0e10cSrcweir                 could be done with the current information, so do NOT use o_rResult
120cdf0e10cSrcweir                 when it returns false. o_rResult will be changed on return true and
121cdf0e10cSrcweir                 then contains a definitive answer if content of this scene is hit or
122cdf0e10cSrcweir                 not. On return false, it is normally necessary to use the geometric
123cdf0e10cSrcweir                 HitTest (see CutFindProcessor usages). The given HitPoint
124cdf0e10cSrcweir                 has to be in logic coordinates in scene's ObjectCoordinateSystem.
125cdf0e10cSrcweir              */
126cdf0e10cSrcweir             bool tryToCheckLastVisualisationDirectHit(const basegfx::B2DPoint& rLogicHitPoint, bool& o_rResult) const;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 			/// constructor
129cdf0e10cSrcweir 			ScenePrimitive2D(
130cdf0e10cSrcweir 				const primitive3d::Primitive3DSequence& rxChildren3D,
131cdf0e10cSrcweir 				const attribute::SdrSceneAttribute& rSdrSceneAttribute,
132cdf0e10cSrcweir 				const attribute::SdrLightingAttribute& rSdrLightingAttribute,
133cdf0e10cSrcweir 				const basegfx::B2DHomMatrix& rObjectTransformation,
134cdf0e10cSrcweir 				const geometry::ViewInformation3D& rViewInformation3D);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 			/// data read access
getChildren3D() const137cdf0e10cSrcweir 			const primitive3d::Primitive3DSequence& getChildren3D() const { return mxChildren3D; }
getSdrSceneAttribute() const138cdf0e10cSrcweir 			const attribute::SdrSceneAttribute& getSdrSceneAttribute() const { return maSdrSceneAttribute; }
getSdrLightingAttribute() const139cdf0e10cSrcweir 			const attribute::SdrLightingAttribute& getSdrLightingAttribute() const { return maSdrLightingAttribute; }
getObjectTransformation() const140cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& getObjectTransformation() const { return maObjectTransformation; }
getViewInformation3D() const141cdf0e10cSrcweir 			const geometry::ViewInformation3D& getViewInformation3D() const { return maViewInformation3D; }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 			/// compare operator
144cdf0e10cSrcweir 			virtual bool operator==(const BasePrimitive2D& rPrimitive) const;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 			/// get range
147cdf0e10cSrcweir 			virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 			/// provide unique ID
150cdf0e10cSrcweir 			DeclPrimitrive2DIDBlock()
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 			/// get local decomposition. Overloaded since this decomposition is view-dependent
153cdf0e10cSrcweir 			virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
154cdf0e10cSrcweir 		};
155cdf0e10cSrcweir 	} // end of namespace primitive2d
156cdf0e10cSrcweir } // end of namespace drawinglayer
157cdf0e10cSrcweir 
158cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
159cdf0e10cSrcweir 
160cdf0e10cSrcweir #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
163cdf0e10cSrcweir // eof
164