1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6e50924SAndrew Rist * distributed with this work for additional information
6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17*f6e50924SAndrew Rist * specific language governing permissions and limitations
18*f6e50924SAndrew Rist * under the License.
19*f6e50924SAndrew Rist *
20*f6e50924SAndrew Rist *************************************************************/
21*f6e50924SAndrew Rist
22*f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <helperminimaldepth3d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/processor3d/baseprocessor3d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
32cdf0e10cSrcweir #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
33cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3d.hxx>
34cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
35cdf0e10cSrcweir #include <svx/obj3d.hxx>
36cdf0e10cSrcweir #include <svx/scene3d.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39cdf0e10cSrcweir
40cdf0e10cSrcweir namespace drawinglayer
41cdf0e10cSrcweir {
42cdf0e10cSrcweir namespace processor3d
43cdf0e10cSrcweir {
44cdf0e10cSrcweir class MinimalDephInViewExtractor : public BaseProcessor3D
45cdf0e10cSrcweir {
46cdf0e10cSrcweir private:
47cdf0e10cSrcweir // the value which will be fetched as result
48cdf0e10cSrcweir double mfMinimalDepth;
49cdf0e10cSrcweir
50cdf0e10cSrcweir // as tooling, the process() implementation takes over API handling and calls this
51cdf0e10cSrcweir // virtual render method when the primitive implementation is BasePrimitive3D-based.
52cdf0e10cSrcweir virtual void processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate);
53cdf0e10cSrcweir
54cdf0e10cSrcweir public:
MinimalDephInViewExtractor(const geometry::ViewInformation3D & rViewInformation)55cdf0e10cSrcweir MinimalDephInViewExtractor(const geometry::ViewInformation3D& rViewInformation)
56cdf0e10cSrcweir : BaseProcessor3D(rViewInformation),
57cdf0e10cSrcweir mfMinimalDepth(DBL_MAX)
58cdf0e10cSrcweir {}
59cdf0e10cSrcweir
60cdf0e10cSrcweir // data access
getMinimalDepth() const61cdf0e10cSrcweir double getMinimalDepth() const { return mfMinimalDepth; }
62cdf0e10cSrcweir };
63cdf0e10cSrcweir
processBasePrimitive3D(const primitive3d::BasePrimitive3D & rCandidate)64cdf0e10cSrcweir void MinimalDephInViewExtractor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
67cdf0e10cSrcweir switch(rCandidate.getPrimitive3DID())
68cdf0e10cSrcweir {
69cdf0e10cSrcweir case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
70cdf0e10cSrcweir {
71cdf0e10cSrcweir // transform group. Remember current transformations
72cdf0e10cSrcweir const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
73cdf0e10cSrcweir const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
74cdf0e10cSrcweir
75cdf0e10cSrcweir // create new transformation; add new object transform from right side
76cdf0e10cSrcweir const geometry::ViewInformation3D aNewViewInformation3D(
77cdf0e10cSrcweir aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
78cdf0e10cSrcweir aLastViewInformation3D.getOrientation(),
79cdf0e10cSrcweir aLastViewInformation3D.getProjection(),
80cdf0e10cSrcweir aLastViewInformation3D.getDeviceToView(),
81cdf0e10cSrcweir aLastViewInformation3D.getViewTime(),
82cdf0e10cSrcweir aLastViewInformation3D.getExtendedInformationSequence());
83cdf0e10cSrcweir updateViewInformation(aNewViewInformation3D);
84cdf0e10cSrcweir
85cdf0e10cSrcweir // let break down
86cdf0e10cSrcweir process(rPrimitive.getChildren());
87cdf0e10cSrcweir
88cdf0e10cSrcweir // restore transformations
89cdf0e10cSrcweir updateViewInformation(aLastViewInformation3D);
90cdf0e10cSrcweir break;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
93cdf0e10cSrcweir {
94cdf0e10cSrcweir // PolygonHairlinePrimitive3D
95cdf0e10cSrcweir const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate);
96cdf0e10cSrcweir const basegfx::B3DPolygon& rPolygon = rPrimitive.getB3DPolygon();
97cdf0e10cSrcweir const sal_uInt32 nCount(rPolygon.count());
98cdf0e10cSrcweir
99cdf0e10cSrcweir for(sal_uInt32 a(0); a < nCount; a++)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * rPolygon.getB3DPoint(a));
102cdf0e10cSrcweir
103cdf0e10cSrcweir if(aPointInView.getZ() < mfMinimalDepth)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir mfMinimalDepth = aPointInView.getZ();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir break;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
112cdf0e10cSrcweir {
113cdf0e10cSrcweir // PolyPolygonMaterialPrimitive3D
114cdf0e10cSrcweir const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
115cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon();
116cdf0e10cSrcweir const sal_uInt32 nPolyCount(rPolyPolygon.count());
117cdf0e10cSrcweir
118cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPolyCount; a++)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir const basegfx::B3DPolygon aPolygon(rPolyPolygon.getB3DPolygon(a));
121cdf0e10cSrcweir const sal_uInt32 nCount(aPolygon.count());
122cdf0e10cSrcweir
123cdf0e10cSrcweir for(sal_uInt32 b(0); b < nCount; b++)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * aPolygon.getB3DPoint(b));
126cdf0e10cSrcweir
127cdf0e10cSrcweir if(aPointInView.getZ() < mfMinimalDepth)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir mfMinimalDepth = aPointInView.getZ();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir break;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir default :
137cdf0e10cSrcweir {
138cdf0e10cSrcweir // process recursively
139cdf0e10cSrcweir process(rCandidate.get3DDecomposition(getViewInformation3D()));
140cdf0e10cSrcweir break;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir } // end of namespace processor3d
145cdf0e10cSrcweir } // end of namespace drawinglayer
146cdf0e10cSrcweir
147cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
148cdf0e10cSrcweir // changed to create values using VCs, Primitive3DSequence and ViewInformation3D to allow
149cdf0e10cSrcweir // removal of old 3D bucket geometry. There is one slight difference in the result, it's
150cdf0e10cSrcweir // in [0.0 .. 1.0] for Z-Depth since the scaling of the scene as 2D object is no longer
151cdf0e10cSrcweir // part of the 3D transformations. This could be added since the ViewContactOfE3dScene is
152cdf0e10cSrcweir // given, but is not needed since the permutation of the depth values needs only be correct
153cdf0e10cSrcweir // relative to each other
154cdf0e10cSrcweir
getMinimalDepthInViewCoordinates(const E3dCompoundObject & rObject)155cdf0e10cSrcweir double getMinimalDepthInViewCoordinates(const E3dCompoundObject& rObject)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir // this is a E3dCompoundObject, so it cannot be a scene (which is a E3dObject).
158cdf0e10cSrcweir // Get primitive sequence using VC
159cdf0e10cSrcweir const sdr::contact::ViewContactOfE3d& rVCObject = static_cast< sdr::contact::ViewContactOfE3d& >(rObject.GetViewContact());
160cdf0e10cSrcweir const drawinglayer::primitive3d::Primitive3DSequence aPrimitives = rVCObject.getViewIndependentPrimitive3DSequence();
161cdf0e10cSrcweir double fRetval(DBL_MAX);
162cdf0e10cSrcweir
163cdf0e10cSrcweir if(aPrimitives.hasElements())
164cdf0e10cSrcweir {
165cdf0e10cSrcweir const E3dScene* pScene = rObject.GetScene();
166cdf0e10cSrcweir
167cdf0e10cSrcweir if(pScene)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir // get ViewInformation3D from scene using VC
170cdf0e10cSrcweir const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(pScene->GetViewContact());
171cdf0e10cSrcweir const drawinglayer::geometry::ViewInformation3D aViewInfo3D(rVCScene.getViewInformation3D());
172cdf0e10cSrcweir
173cdf0e10cSrcweir // the scene's object transformation is already part of aViewInfo3D.getObjectTransformation()
174cdf0e10cSrcweir // for historical reasons (see ViewContactOfE3dScene::createViewInformation3D for more info)
175cdf0e10cSrcweir // and the object's transform is part of aPrimitives (and taken into account when decomposing
176cdf0e10cSrcweir // to PolygonHairlinePrimitive3D and PolyPolygonMaterialPrimitive3D). The missing part may be
177cdf0e10cSrcweir // some Scene SdrObjects lying in-between which may need to be added. This is e.g. used in chart,
178cdf0e10cSrcweir // and generally allowed in 3d scenes an their 3d object hierarchy
179cdf0e10cSrcweir basegfx::B3DHomMatrix aInBetweenSceneMatrix;
180cdf0e10cSrcweir E3dScene* pParentScene = dynamic_cast< E3dScene* >(rObject.GetParentObj());
181cdf0e10cSrcweir
182cdf0e10cSrcweir while(pParentScene && pParentScene != pScene)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir aInBetweenSceneMatrix = pParentScene->GetTransform() * aInBetweenSceneMatrix;
185cdf0e10cSrcweir pParentScene = dynamic_cast< E3dScene* >(pParentScene->GetParentObj());
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir // build new ViewInformation containing all transforms
189cdf0e10cSrcweir const drawinglayer::geometry::ViewInformation3D aNewViewInformation3D(
190cdf0e10cSrcweir aViewInfo3D.getObjectTransformation() * aInBetweenSceneMatrix,
191cdf0e10cSrcweir aViewInfo3D.getOrientation(),
192cdf0e10cSrcweir aViewInfo3D.getProjection(),
193cdf0e10cSrcweir aViewInfo3D.getDeviceToView(),
194cdf0e10cSrcweir aViewInfo3D.getViewTime(),
195cdf0e10cSrcweir aViewInfo3D.getExtendedInformationSequence());
196cdf0e10cSrcweir
197cdf0e10cSrcweir // create extractor helper, proccess geometry and get return value
198cdf0e10cSrcweir drawinglayer::processor3d::MinimalDephInViewExtractor aExtractor(aNewViewInformation3D);
199cdf0e10cSrcweir aExtractor.process(aPrimitives);
200cdf0e10cSrcweir fRetval = aExtractor.getMinimalDepth();
201cdf0e10cSrcweir }
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir return fRetval;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
208cdf0e10cSrcweir // eof
209