/src/libreoffice/svx/source/engine3d/helperminimaldepth3d.cxx
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 | | |
21 | | #include "helperminimaldepth3d.hxx" |
22 | | #include <drawinglayer/processor3d/baseprocessor3d.hxx> |
23 | | #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx> |
24 | | #include <drawinglayer/primitive3d/transformprimitive3d.hxx> |
25 | | #include <drawinglayer/primitive3d/polygonprimitive3d.hxx> |
26 | | #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx> |
27 | | #include <sdr/contact/viewcontactofe3d.hxx> |
28 | | #include <svx/sdr/contact/viewcontactofe3dscene.hxx> |
29 | | #include <svx/obj3d.hxx> |
30 | | #include <svx/scene3d.hxx> |
31 | | |
32 | | |
33 | | namespace drawinglayer::processor3d |
34 | | { |
35 | | namespace { |
36 | | |
37 | | class MinimalDephInViewExtractor : public BaseProcessor3D |
38 | | { |
39 | | private: |
40 | | // the value which will be fetched as result |
41 | | double mfMinimalDepth; |
42 | | |
43 | | // as tooling, the process() implementation takes over API handling and calls this |
44 | | // virtual render method when the primitive implementation is BasePrimitive3D-based. |
45 | | virtual void processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate) override; |
46 | | |
47 | | public: |
48 | | explicit MinimalDephInViewExtractor(const geometry::ViewInformation3D& rViewInformation) |
49 | 0 | : BaseProcessor3D(rViewInformation), |
50 | 0 | mfMinimalDepth(DBL_MAX) |
51 | 0 | {} |
52 | | |
53 | | // data access |
54 | 0 | double getMinimalDepth() const { return mfMinimalDepth; } |
55 | | }; |
56 | | |
57 | | } |
58 | | |
59 | | void MinimalDephInViewExtractor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate) |
60 | 0 | { |
61 | | // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch |
62 | 0 | switch(rCandidate.getPrimitive3DID()) |
63 | 0 | { |
64 | 0 | case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D : |
65 | 0 | { |
66 | | // transform group. Remember current transformations |
67 | 0 | const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate); |
68 | 0 | const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D()); |
69 | | |
70 | | // create new transformation; add new object transform from right side |
71 | 0 | const geometry::ViewInformation3D aNewViewInformation3D( |
72 | 0 | aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(), |
73 | 0 | aLastViewInformation3D.getOrientation(), |
74 | 0 | aLastViewInformation3D.getProjection(), |
75 | 0 | aLastViewInformation3D.getDeviceToView(), |
76 | 0 | aLastViewInformation3D.getViewTime(), |
77 | 0 | aLastViewInformation3D.getExtendedInformationSequence()); |
78 | 0 | setViewInformation3D(aNewViewInformation3D); |
79 | | |
80 | | // let break down |
81 | 0 | process(rPrimitive.getChildren()); |
82 | | |
83 | | // restore transformations |
84 | 0 | setViewInformation3D(aLastViewInformation3D); |
85 | 0 | break; |
86 | 0 | } |
87 | 0 | case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D : |
88 | 0 | { |
89 | | // PolygonHairlinePrimitive3D |
90 | 0 | const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate); |
91 | 0 | const basegfx::B3DPolygon& rPolygon = rPrimitive.getB3DPolygon(); |
92 | 0 | const sal_uInt32 nCount(rPolygon.count()); |
93 | |
|
94 | 0 | for(sal_uInt32 a(0); a < nCount; a++) |
95 | 0 | { |
96 | 0 | const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * rPolygon.getB3DPoint(a)); |
97 | |
|
98 | 0 | if(aPointInView.getZ() < mfMinimalDepth) |
99 | 0 | { |
100 | 0 | mfMinimalDepth = aPointInView.getZ(); |
101 | 0 | } |
102 | 0 | } |
103 | |
|
104 | 0 | break; |
105 | 0 | } |
106 | 0 | case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D : |
107 | 0 | { |
108 | | // PolyPolygonMaterialPrimitive3D |
109 | 0 | const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate); |
110 | 0 | const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon(); |
111 | 0 | const sal_uInt32 nPolyCount(rPolyPolygon.count()); |
112 | |
|
113 | 0 | for(sal_uInt32 a(0); a < nPolyCount; a++) |
114 | 0 | { |
115 | 0 | const basegfx::B3DPolygon& aPolygon(rPolyPolygon.getB3DPolygon(a)); |
116 | 0 | const sal_uInt32 nCount(aPolygon.count()); |
117 | |
|
118 | 0 | for(sal_uInt32 b(0); b < nCount; b++) |
119 | 0 | { |
120 | 0 | const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * aPolygon.getB3DPoint(b)); |
121 | |
|
122 | 0 | if(aPointInView.getZ() < mfMinimalDepth) |
123 | 0 | { |
124 | 0 | mfMinimalDepth = aPointInView.getZ(); |
125 | 0 | } |
126 | 0 | } |
127 | 0 | } |
128 | |
|
129 | 0 | break; |
130 | 0 | } |
131 | 0 | default : |
132 | 0 | { |
133 | | // process recursively |
134 | 0 | process(rCandidate.get3DDecomposition(getViewInformation3D())); |
135 | 0 | break; |
136 | 0 | } |
137 | 0 | } |
138 | 0 | } |
139 | | } // end of namespace |
140 | | |
141 | | |
142 | | // changed to create values using VCs, Primitive3DContainer and ViewInformation3D to allow |
143 | | // removal of old 3D bucket geometry. There is one slight difference in the result, it's |
144 | | // in [0.0 .. 1.0] for Z-Depth since the scaling of the scene as 2D object is no longer |
145 | | // part of the 3D transformations. This could be added since the ViewContactOfE3dScene is |
146 | | // given, but is not needed since the permutation of the depth values needs only be correct |
147 | | // relative to each other |
148 | | |
149 | | double getMinimalDepthInViewCoordinates(const E3dCompoundObject& rObject) |
150 | 0 | { |
151 | | // this is an E3dCompoundObject, so it cannot be a scene (which is an E3dObject). |
152 | | // Get primitive sequence using VC |
153 | 0 | const sdr::contact::ViewContactOfE3d& rVCObject = static_cast< sdr::contact::ViewContactOfE3d& >(rObject.GetViewContact()); |
154 | 0 | const drawinglayer::primitive3d::Primitive3DContainer aPrimitives = rVCObject.getViewIndependentPrimitive3DContainer(); |
155 | 0 | double fRetval(DBL_MAX); |
156 | |
|
157 | 0 | if(!aPrimitives.empty()) |
158 | 0 | { |
159 | 0 | const E3dScene* pScene(rObject.getRootE3dSceneFromE3dObject()); |
160 | |
|
161 | 0 | if(pScene) |
162 | 0 | { |
163 | | // get ViewInformation3D from scene using VC |
164 | 0 | const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(pScene->GetViewContact()); |
165 | 0 | const drawinglayer::geometry::ViewInformation3D& aViewInfo3D(rVCScene.getViewInformation3D()); |
166 | | |
167 | | // the scene's object transformation is already part of aViewInfo3D.getObjectTransformation() |
168 | | // for historical reasons (see ViewContactOfE3dScene::createViewInformation3D for more info) |
169 | | // and the object's transform is part of aPrimitives (and taken into account when decomposing |
170 | | // to PolygonHairlinePrimitive3D and PolyPolygonMaterialPrimitive3D). The missing part may be |
171 | | // some Scene SdrObjects lying in-between which may need to be added. This is e.g. used in chart, |
172 | | // and generally allowed in 3d scenes and their 3d object hierarchy |
173 | 0 | basegfx::B3DHomMatrix aInBetweenSceneMatrix; |
174 | 0 | E3dScene* pParentScene(rObject.getParentE3dSceneFromE3dObject()); |
175 | |
|
176 | 0 | while(pParentScene && pParentScene != pScene) |
177 | 0 | { |
178 | 0 | aInBetweenSceneMatrix = pParentScene->GetTransform() * aInBetweenSceneMatrix; |
179 | 0 | pParentScene = pParentScene->getParentE3dSceneFromE3dObject(); |
180 | 0 | } |
181 | | |
182 | | // build new ViewInformation containing all transforms |
183 | 0 | const drawinglayer::geometry::ViewInformation3D aNewViewInformation3D( |
184 | 0 | aViewInfo3D.getObjectTransformation() * aInBetweenSceneMatrix, |
185 | 0 | aViewInfo3D.getOrientation(), |
186 | 0 | aViewInfo3D.getProjection(), |
187 | 0 | aViewInfo3D.getDeviceToView(), |
188 | 0 | aViewInfo3D.getViewTime(), |
189 | 0 | aViewInfo3D.getExtendedInformationSequence()); |
190 | | |
191 | | // create extractor helper, process geometry and get return value |
192 | 0 | drawinglayer::processor3d::MinimalDephInViewExtractor aExtractor(aNewViewInformation3D); |
193 | 0 | aExtractor.process(aPrimitives); |
194 | 0 | fRetval = aExtractor.getMinimalDepth(); |
195 | 0 | } |
196 | 0 | } |
197 | |
|
198 | 0 | return fRetval; |
199 | 0 | } |
200 | | |
201 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |