LibreOffice Module svx (master) 1
helperminimaldepth3d.cxx
Go to the documentation of this file.
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
29#include <svx/obj3d.hxx>
30#include <svx/scene3d.hxx>
31
32
34{
35 namespace {
36
37 class MinimalDephInViewExtractor : public BaseProcessor3D
38 {
39 private:
40 // the value which will be fetched as result
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 : BaseProcessor3D(rViewInformation),
50 mfMinimalDepth(DBL_MAX)
51 {}
52
53 // data access
54 double getMinimalDepth() const { return mfMinimalDepth; }
55 };
56
57 }
58
59 void MinimalDephInViewExtractor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
60 {
61 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
62 switch(rCandidate.getPrimitive3DID())
63 {
65 {
66 // transform group. Remember current transformations
67 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
68 const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
69
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);
79
80 // let break down
81 process(rPrimitive.getChildren());
82
83 // restore transformations
84 updateViewInformation(aLastViewInformation3D);
85 break;
86 }
88 {
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());
93
94 for(sal_uInt32 a(0); a < nCount; a++)
95 {
96 const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * rPolygon.getB3DPoint(a));
97
98 if(aPointInView.getZ() < mfMinimalDepth)
99 {
100 mfMinimalDepth = aPointInView.getZ();
101 }
102 }
103
104 break;
105 }
107 {
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());
112
113 for(sal_uInt32 a(0); a < nPolyCount; a++)
114 {
115 const basegfx::B3DPolygon& aPolygon(rPolyPolygon.getB3DPolygon(a));
116 const sal_uInt32 nCount(aPolygon.count());
117
118 for(sal_uInt32 b(0); b < nCount; b++)
119 {
120 const basegfx::B3DPoint aPointInView(getViewInformation3D().getObjectToView() * aPolygon.getB3DPoint(b));
121
122 if(aPointInView.getZ() < mfMinimalDepth)
123 {
124 mfMinimalDepth = aPointInView.getZ();
125 }
126 }
127 }
128
129 break;
130 }
131 default :
132 {
133 // process recursively
134 process(rCandidate.get3DDecomposition(getViewInformation3D()));
135 break;
136 }
137 }
138 }
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
150{
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());
155 double fRetval(DBL_MAX);
156
157 if(!aPrimitives.empty())
158 {
159 const E3dScene* pScene(rObject.getRootE3dSceneFromE3dObject());
160
161 if(pScene)
162 {
163 // get ViewInformation3D from scene using VC
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 basegfx::B3DHomMatrix aInBetweenSceneMatrix;
174 E3dScene* pParentScene(rObject.getParentE3dSceneFromE3dObject());
175
176 while(pParentScene && pParentScene != pScene)
177 {
178 aInBetweenSceneMatrix = pParentScene->GetTransform() * aInBetweenSceneMatrix;
179 pParentScene = pParentScene->getParentE3dSceneFromE3dObject();
180 }
181
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());
190
191 // create extractor helper, process geometry and get return value
192 drawinglayer::processor3d::MinimalDephInViewExtractor aExtractor(aNewViewInformation3D);
193 aExtractor.process(aPrimitives);
194 fRetval = aExtractor.getMinimalDepth();
195 }
196 }
197
198 return fRetval;
199}
200
201/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const basegfx::B3DHomMatrix & GetTransform() const
Definition: obj3d.hxx:112
virtual E3dScene * getRootE3dSceneFromE3dObject() const
Definition: obj3d.cxx:271
E3dScene * getParentE3dSceneFromE3dObject() const
Definition: obj3d.cxx:265
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:261
sal_uInt32 count() const
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
B3DPoint const & getB3DPoint(sal_uInt32 nIndex) const
sal_uInt32 count() const
const css::uno::Sequence< css::beans::PropertyValue > & getExtendedInformationSequence() const
const basegfx::B3DHomMatrix & getDeviceToView() const
const basegfx::B3DHomMatrix & getObjectTransformation() const
const basegfx::B3DHomMatrix & getProjection() const
const basegfx::B3DHomMatrix & getOrientation() const
const drawinglayer::geometry::ViewInformation3D & getViewInformation3D(const ::basegfx::B3DRange &rContentRange) const
drawinglayer::primitive3d::Primitive3DContainer getViewIndependentPrimitive3DContainer() const
int nCount
#define PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D
#define PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D
#define PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
double getMinimalDepthInViewCoordinates(const E3dCompoundObject &rObject)
support extracting the minimal depth of a 3d object in its scene
double mfMinimalDepth
uno_Any a