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