Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / engine3d / helperminimaldepth3d.cxx
blobcfcc2c7d148373ea4cea8b32dca57a67d013cbda
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sdr/contact/viewcontactofe3d.hxx>
28 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
29 #include <svx/obj3d.hxx>
30 #include <svx/scene3d.hxx>
33 namespace drawinglayer::processor3d
35 namespace {
37 class MinimalDephInViewExtractor : public BaseProcessor3D
39 private:
40 // the value which will be fetched as result
41 double mfMinimalDepth;
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;
47 public:
48 explicit MinimalDephInViewExtractor(const geometry::ViewInformation3D& rViewInformation)
49 : BaseProcessor3D(rViewInformation),
50 mfMinimalDepth(DBL_MAX)
53 // data access
54 double getMinimalDepth() const { return mfMinimalDepth; }
59 void MinimalDephInViewExtractor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
61 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
62 switch(rCandidate.getPrimitive3DID())
64 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
66 // transform group. Remember current transformations
67 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
68 const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
70 // create new transformation; add new object transform from right side
71 const geometry::ViewInformation3D aNewViewInformation3D(
72 aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
73 aLastViewInformation3D.getOrientation(),
74 aLastViewInformation3D.getProjection(),
75 aLastViewInformation3D.getDeviceToView(),
76 aLastViewInformation3D.getViewTime(),
77 aLastViewInformation3D.getExtendedInformationSequence());
78 updateViewInformation(aNewViewInformation3D);
80 // let break down
81 process(rPrimitive.getChildren());
83 // restore transformations
84 updateViewInformation(aLastViewInformation3D);
85 break;
87 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
89 // PolygonHairlinePrimitive3D
90 const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate);
91 const basegfx::B3DPolygon& rPolygon = rPrimitive.getB3DPolygon();
92 const sal_uInt32 nCount(rPolygon.count());
94 for(sal_uInt32 a(0); a < nCount; a++)
96 const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * rPolygon.getB3DPoint(a));
98 if(aPointInView.getZ() < mfMinimalDepth)
100 mfMinimalDepth = aPointInView.getZ();
104 break;
106 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
108 // PolyPolygonMaterialPrimitive3D
109 const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
110 const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon();
111 const sal_uInt32 nPolyCount(rPolyPolygon.count());
113 for(sal_uInt32 a(0); a < nPolyCount; a++)
115 const basegfx::B3DPolygon& aPolygon(rPolyPolygon.getB3DPolygon(a));
116 const sal_uInt32 nCount(aPolygon.count());
118 for(sal_uInt32 b(0); b < nCount; b++)
120 const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * aPolygon.getB3DPoint(b));
122 if(aPointInView.getZ() < mfMinimalDepth)
124 mfMinimalDepth = aPointInView.getZ();
129 break;
131 default :
133 // process recursively
134 process(rCandidate.get3DDecomposition(getViewInformation3D()));
135 break;
139 } // end of namespace
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
149 double getMinimalDepthInViewCoordinates(const E3dCompoundObject& rObject)
151 // this is an E3dCompoundObject, so it cannot be a scene (which is an E3dObject).
152 // Get primitive sequence using VC
153 const sdr::contact::ViewContactOfE3d& rVCObject = static_cast< sdr::contact::ViewContactOfE3d& >(rObject.GetViewContact());
154 const drawinglayer::primitive3d::Primitive3DContainer aPrimitives = rVCObject.getViewIndependentPrimitive3DContainer();
155 double fRetval(DBL_MAX);
157 if(!aPrimitives.empty())
159 const E3dScene* pScene(rObject.getRootE3dSceneFromE3dObject());
161 if(pScene)
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 and their 3d object hierarchy
173 basegfx::B3DHomMatrix aInBetweenSceneMatrix;
174 E3dScene* pParentScene(rObject.getParentE3dSceneFromE3dObject());
176 while(pParentScene && pParentScene != pScene)
178 aInBetweenSceneMatrix = pParentScene->GetTransform() * aInBetweenSceneMatrix;
179 pParentScene = pParentScene->getParentE3dSceneFromE3dObject();
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();
198 return fRetval;
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */