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 .
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 <svx/sdr/contact/viewcontactofe3d.hxx>
28 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
29 #include <svx/obj3d.hxx>
30 #include <svx/scene3d.hxx>
34 namespace drawinglayer
38 class MinimalDephInViewExtractor
: public BaseProcessor3D
41 // the value which will be fetched as result
42 double mfMinimalDepth
;
44 // as tooling, the process() implementation takes over API handling and calls this
45 // virtual render method when the primitive implementation is BasePrimitive3D-based.
46 virtual void processBasePrimitive3D(const primitive3d::BasePrimitive3D
& rCandidate
) SAL_OVERRIDE
;
49 MinimalDephInViewExtractor(const geometry::ViewInformation3D
& rViewInformation
)
50 : BaseProcessor3D(rViewInformation
),
51 mfMinimalDepth(DBL_MAX
)
55 double getMinimalDepth() const { return mfMinimalDepth
; }
58 void MinimalDephInViewExtractor::processBasePrimitive3D(const primitive3d::BasePrimitive3D
& rCandidate
)
60 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
61 switch(rCandidate
.getPrimitive3DID())
63 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D
:
65 // transform group. Remember current transformations
66 const primitive3d::TransformPrimitive3D
& rPrimitive
= static_cast< const primitive3d::TransformPrimitive3D
& >(rCandidate
);
67 const geometry::ViewInformation3D
aLastViewInformation3D(getViewInformation3D());
69 // create new transformation; add new object transform from right side
70 const geometry::ViewInformation3D
aNewViewInformation3D(
71 aLastViewInformation3D
.getObjectTransformation() * rPrimitive
.getTransformation(),
72 aLastViewInformation3D
.getOrientation(),
73 aLastViewInformation3D
.getProjection(),
74 aLastViewInformation3D
.getDeviceToView(),
75 aLastViewInformation3D
.getViewTime(),
76 aLastViewInformation3D
.getExtendedInformationSequence());
77 updateViewInformation(aNewViewInformation3D
);
80 process(rPrimitive
.getChildren());
82 // restore transformations
83 updateViewInformation(aLastViewInformation3D
);
86 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D
:
88 // PolygonHairlinePrimitive3D
89 const primitive3d::PolygonHairlinePrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolygonHairlinePrimitive3D
& >(rCandidate
);
90 const basegfx::B3DPolygon
& rPolygon
= rPrimitive
.getB3DPolygon();
91 const sal_uInt32
nCount(rPolygon
.count());
93 for(sal_uInt32
a(0); a
< nCount
; a
++)
95 const basegfx::B3DPoint
aPointInView(getViewInformation3D().getObjectToView() * rPolygon
.getB3DPoint(a
));
97 if(aPointInView
.getZ() < mfMinimalDepth
)
99 mfMinimalDepth
= aPointInView
.getZ();
105 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
:
107 // PolyPolygonMaterialPrimitive3D
108 const primitive3d::PolyPolygonMaterialPrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D
& >(rCandidate
);
109 const basegfx::B3DPolyPolygon
& rPolyPolygon
= rPrimitive
.getB3DPolyPolygon();
110 const sal_uInt32
nPolyCount(rPolyPolygon
.count());
112 for(sal_uInt32
a(0); a
< nPolyCount
; a
++)
114 const basegfx::B3DPolygon
aPolygon(rPolyPolygon
.getB3DPolygon(a
));
115 const sal_uInt32
nCount(aPolygon
.count());
117 for(sal_uInt32
b(0); b
< nCount
; b
++)
119 const basegfx::B3DPoint
aPointInView(getViewInformation3D().getObjectToView() * aPolygon
.getB3DPoint(b
));
121 if(aPointInView
.getZ() < mfMinimalDepth
)
123 mfMinimalDepth
= aPointInView
.getZ();
132 // process recursively
133 process(rCandidate
.get3DDecomposition(getViewInformation3D()));
138 } // end of namespace processor3d
139 } // end of namespace drawinglayer
142 // changed to create values using VCs, Primitive3DSequence 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
149 double getMinimalDepthInViewCoordinates(const E3dCompoundObject
& rObject
)
151 // this is a E3dCompoundObject, so it cannot be a scene (which is a E3dObject).
152 // Get primitive sequence using VC
153 const sdr::contact::ViewContactOfE3d
& rVCObject
= static_cast< sdr::contact::ViewContactOfE3d
& >(rObject
.GetViewContact());
154 const drawinglayer::primitive3d::Primitive3DSequence aPrimitives
= rVCObject
.getViewIndependentPrimitive3DSequence();
155 double fRetval(DBL_MAX
);
157 if(aPrimitives
.hasElements())
159 const E3dScene
* pScene
= rObject
.GetScene();
163 // get ViewInformation3D from scene using VC
164 const sdr::contact::ViewContactOfE3dScene
& rVCScene
= static_cast< sdr::contact::ViewContactOfE3dScene
& >(pScene
->GetViewContact());
165 const drawinglayer::geometry::ViewInformation3D
aViewInfo3D(rVCScene
.getViewInformation3D());
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 an their 3d object hierarchy
173 basegfx::B3DHomMatrix aInBetweenSceneMatrix
;
174 E3dScene
* pParentScene
= dynamic_cast< E3dScene
* >(rObject
.GetParentObj());
176 while(pParentScene
&& pParentScene
!= pScene
)
178 aInBetweenSceneMatrix
= pParentScene
->GetTransform() * aInBetweenSceneMatrix
;
179 pParentScene
= dynamic_cast< E3dScene
* >(pParentScene
->GetParentObj());
182 // build new ViewInformation containing all transforms
183 const drawinglayer::geometry::ViewInformation3D
aNewViewInformation3D(
184 aViewInfo3D
.getObjectTransformation() * aInBetweenSceneMatrix
,
185 aViewInfo3D
.getOrientation(),
186 aViewInfo3D
.getProjection(),
187 aViewInfo3D
.getDeviceToView(),
188 aViewInfo3D
.getViewTime(),
189 aViewInfo3D
.getExtendedInformationSequence());
191 // create extractor helper, process geometry and get return value
192 drawinglayer::processor3d::MinimalDephInViewExtractor
aExtractor(aNewViewInformation3D
);
193 aExtractor
.process(aPrimitives
);
194 fRetval
= aExtractor
.getMinimalDepth();
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */