/src/libreoffice/include/drawinglayer/primitive2d/sceneprimitive2d.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <drawinglayer/drawinglayerdllapi.h> |
23 | | |
24 | | #include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx> |
25 | | #include <drawinglayer/primitive3d/baseprimitive3d.hxx> |
26 | | #include <drawinglayer/geometry/viewinformation3d.hxx> |
27 | | #include <basegfx/matrix/b2dhommatrix.hxx> |
28 | | #include <vcl/bitmap.hxx> |
29 | | #include <drawinglayer/attribute/sdrsceneattribute3d.hxx> |
30 | | #include <drawinglayer/attribute/sdrlightingattribute3d.hxx> |
31 | | |
32 | | namespace drawinglayer::primitive2d |
33 | | { |
34 | | /** ScenePrimitive2D class |
35 | | |
36 | | This primitive defines a 3D scene as a 2D primitive and is the anchor point |
37 | | for a 3D visualisation. The decomposition is view-dependent and will try to |
38 | | re-use already rendered 3D content. |
39 | | |
40 | | The rendering is done using the default-3D renderer from basegfx which supports |
41 | | AntiAliasing. |
42 | | |
43 | | The 2D primitive's geometric range is defined completely by the |
44 | | ObjectTransformation combined with evtl. 2D shadows from the 3D objects. The |
45 | | shadows of 3D objects are 2D polygons, projected with the 3D transformation. |
46 | | |
47 | | This is the class a renderer may process directly when he wants to implement |
48 | | an own (e.g. system-specific) 3D renderer. |
49 | | */ |
50 | | class DRAWINGLAYER_DLLPUBLIC ScenePrimitive2D final : public BufferedDecompositionPrimitive2D |
51 | | { |
52 | | private: |
53 | | /// the 3D geometry definition |
54 | | primitive3d::Primitive3DContainer mxChildren3D; |
55 | | |
56 | | /// 3D scene attribute set |
57 | | attribute::SdrSceneAttribute maSdrSceneAttribute; |
58 | | |
59 | | /// lighting attribute set |
60 | | attribute::SdrLightingAttribute maSdrLightingAttribute; |
61 | | |
62 | | /// object transformation for scene for 2D definition |
63 | | basegfx::B2DHomMatrix maObjectTransformation; |
64 | | |
65 | | /// scene transformation set and object transformation |
66 | | geometry::ViewInformation3D maViewInformation3D; |
67 | | |
68 | | /// the primitiveSequence for on-demand created shadow primitives (see mbShadow3DChecked) |
69 | | Primitive2DContainer maShadowPrimitives; |
70 | | |
71 | | /** flag if given 3D geometry is already checked for shadow definitions and 2d shadows |
72 | | are created in maShadowPrimitives |
73 | | */ |
74 | | bool mbShadow3DChecked : 1; |
75 | | |
76 | | /// the last used NewDiscreteSize and NewUnitVisiblePart definitions for decomposition |
77 | | double mfOldDiscreteSizeX; |
78 | | double mfOldDiscreteSizeY; |
79 | | basegfx::B2DRange maOldUnitVisiblePart; |
80 | | |
81 | | /** the last created Bitmap, e.g. for fast HitTest. This does not really need |
82 | | memory since Bitmap is internally RefCounted |
83 | | */ |
84 | | Bitmap maOldRenderedBitmap; |
85 | | |
86 | | /// private helpers |
87 | | bool impGetShadow3D() const; |
88 | | void calculateDiscreteSizes( |
89 | | const geometry::ViewInformation2D& rViewInformation, |
90 | | basegfx::B2DRange& rDiscreteRange, |
91 | | basegfx::B2DRange& rVisibleDiscreteRange, |
92 | | basegfx::B2DRange& rUnitVisibleRange) const; |
93 | | |
94 | | /// local decomposition. |
95 | | virtual Primitive2DReference create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const override; |
96 | | |
97 | | public: |
98 | | /// public helpers |
99 | | /** Geometry extractor. Shadow will be added as in create2DDecomposition, but |
100 | | the 3D content is not converted to a bitmap visualisation but to projected 2D geometry. This |
101 | | helper is useful e.g. for Contour extraction or HitTests. |
102 | | */ |
103 | | Primitive2DContainer getGeometry2D() const; |
104 | | Primitive2DContainer getShadow2D() const; |
105 | | |
106 | | /** Fast HitTest which uses the last buffered Bitmap from the last |
107 | | rendered area if available. The return value describes if the check |
108 | | could be done with the current information, so do NOT use o_rResult |
109 | | when it returns false. o_rResult will be changed on return true and |
110 | | then contains a definitive answer if content of this scene is hit or |
111 | | not. On return false, it is normally necessary to use the geometric |
112 | | HitTest (see CutFindProcessor usages). The given HitPoint |
113 | | has to be in logic coordinates in scene's ObjectCoordinateSystem. |
114 | | */ |
115 | | bool tryToCheckLastVisualisationDirectHit(const basegfx::B2DPoint& rLogicHitPoint, bool& o_rResult) const; |
116 | | |
117 | | /// constructor |
118 | | ScenePrimitive2D( |
119 | | primitive3d::Primitive3DContainer xChildren3D, |
120 | | attribute::SdrSceneAttribute aSdrSceneAttribute, |
121 | | attribute::SdrLightingAttribute aSdrLightingAttribute, |
122 | | basegfx::B2DHomMatrix aObjectTransformation, |
123 | | geometry::ViewInformation3D aViewInformation3D); |
124 | | |
125 | | /// data read access |
126 | 0 | const primitive3d::Primitive3DContainer& getChildren3D() const { return mxChildren3D; } |
127 | 0 | const attribute::SdrSceneAttribute& getSdrSceneAttribute() const { return maSdrSceneAttribute; } |
128 | 0 | const attribute::SdrLightingAttribute& getSdrLightingAttribute() const { return maSdrLightingAttribute; } |
129 | 0 | const basegfx::B2DHomMatrix& getObjectTransformation() const { return maObjectTransformation; } |
130 | 0 | const geometry::ViewInformation3D& getViewInformation3D() const { return maViewInformation3D; } |
131 | | |
132 | | /// compare operator |
133 | | virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; |
134 | | |
135 | | /// get range |
136 | | virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override; |
137 | | |
138 | | /// provide unique ID |
139 | | virtual sal_uInt32 getPrimitive2DID() const override; |
140 | | |
141 | | /// get local decomposition. Override since this decomposition is view-dependent |
142 | | virtual void get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const override; |
143 | | }; |
144 | | } // end of namespace drawinglayer::primitive2d |
145 | | |
146 | | |
147 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |