1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
21 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
23 #include <drawinglayer/drawinglayerdllapi.h>
25 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
26 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
27 #include <drawinglayer/geometry/viewinformation3d.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <vcl/bitmapex.hxx>
30 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
31 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
32 #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
36 namespace drawinglayer
40 /** ScenePrimitive2D class
42 This primitive defines a 3D scene as a 2D primitive and is the anchor point
43 for a 3D visualisation. The decomposition is view-dependent and will try to
44 re-use already rendered 3D content.
46 The rendering is done using the default-3D renderer from basegfx which supports
49 The 2D primitive's geometric range is defined completely by the
50 ObjectTransformation combined with evtl. 2D shadows from the 3D objects. The
51 shadows of 3D objects are 2D polygons, projected with the 3D transformation.
53 This is the class a renderer may process directly when he wants to implement
54 an own (e.g. system-specific) 3D renderer.
56 class DRAWINGLAYER_DLLPUBLIC ScenePrimitive2D
: public BufferedDecompositionPrimitive2D
59 /// the 3D geometry definition
60 primitive3d::Primitive3DSequence mxChildren3D
;
62 /// 3D scene attribute set
63 attribute::SdrSceneAttribute maSdrSceneAttribute
;
65 /// lighting attribute set
66 attribute::SdrLightingAttribute maSdrLightingAttribute
;
68 /// object transformation for scene for 2D definition
69 basegfx::B2DHomMatrix maObjectTransformation
;
71 /// scene transformation set and object transformation
72 geometry::ViewInformation3D maViewInformation3D
;
74 /// the primitiveSequence for on-demand created shadow primitives (see mbShadow3DChecked)
75 Primitive2DSequence maShadowPrimitives
;
78 /** flag if given 3D geometry is already cheched for shadow definitions and 2d shadows
79 are created in maShadowPrimitives
81 bool mbShadow3DChecked
: 1;
83 /// the last used NewDiscreteSize and NewUnitVisiblePart definitions for decomposition
84 double mfOldDiscreteSizeX
;
85 double mfOldDiscreteSizeY
;
86 basegfx::B2DRange maOldUnitVisiblePart
;
88 /** the last created BitmapEx, e.g. for fast HitTest. This does not really need
89 memory since BitmapEx is internally RefCounted
91 BitmapEx maOldRenderedBitmap
;
94 bool impGetShadow3D(const geometry::ViewInformation2D
& rViewInformation
) const;
95 void calculateDiscreteSizes(
96 const geometry::ViewInformation2D
& rViewInformation
,
97 basegfx::B2DRange
& rDiscreteRange
,
98 basegfx::B2DRange
& rVisibleDiscreteRange
,
99 basegfx::B2DRange
& rUnitVisibleRange
) const;
102 /// local decomposition.
103 virtual Primitive2DSequence
create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
107 /** Geometry extractor. Shadow will be added as in create2DDecomposition, but
108 the 3D content is not converted to a bitmap visualisation but to projected 2D gemetry. This
109 helper is useful e.g. for Contour extraction or HitTests.
111 Primitive2DSequence
getGeometry2D() const;
112 Primitive2DSequence
getShadow2D(const geometry::ViewInformation2D
& rViewInformation
) const;
114 /** Fast HitTest which uses the last buffered BitmapEx from the last
115 rendered area if available. The return value describes if the check
116 could be done with the current information, so do NOT use o_rResult
117 when it returns false. o_rResult will be changed on return true and
118 then contains a definitive answer if content of this scene is hit or
119 not. On return false, it is normally necessary to use the geometric
120 HitTest (see CutFindProcessor usages). The given HitPoint
121 has to be in logic coordinates in scene's ObjectCoordinateSystem.
123 bool tryToCheckLastVisualisationDirectHit(const basegfx::B2DPoint
& rLogicHitPoint
, bool& o_rResult
) const;
127 const primitive3d::Primitive3DSequence
& rxChildren3D
,
128 const attribute::SdrSceneAttribute
& rSdrSceneAttribute
,
129 const attribute::SdrLightingAttribute
& rSdrLightingAttribute
,
130 const basegfx::B2DHomMatrix
& rObjectTransformation
,
131 const geometry::ViewInformation3D
& rViewInformation3D
);
134 const primitive3d::Primitive3DSequence
& getChildren3D() const { return mxChildren3D
; }
135 const attribute::SdrSceneAttribute
& getSdrSceneAttribute() const { return maSdrSceneAttribute
; }
136 const attribute::SdrLightingAttribute
& getSdrLightingAttribute() const { return maSdrLightingAttribute
; }
137 const basegfx::B2DHomMatrix
& getObjectTransformation() const { return maObjectTransformation
; }
138 const geometry::ViewInformation3D
& getViewInformation3D() const { return maViewInformation3D
; }
141 virtual bool operator==(const BasePrimitive2D
& rPrimitive
) const SAL_OVERRIDE
;
144 virtual basegfx::B2DRange
getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
146 /// provide unique ID
147 DeclPrimitive2DIDBlock()
149 /// get local decomposition. Override since this decomposition is view-dependent
150 virtual Primitive2DSequence
get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
152 } // end of namespace primitive2d
153 } // end of namespace drawinglayer
157 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */