LibreOffice Module svx (master) 1
helperhittest3d.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
23#include <svx/svdpage.hxx>
24#include <svx/scene3d.hxx>
25#include <svx/svditer.hxx>
29#include <com/sun/star/uno/Sequence.h>
30
31
32using namespace com::sun::star;
33
34namespace {
35
36class ImplPairDephAndObject
37{
38private:
40 double mfDepth;
41
42public:
43 ImplPairDephAndObject(const E3dCompoundObject* pObject, double fDepth)
45 mfDepth(fDepth)
46 {}
47
48 // for ::std::sort
49 bool operator<(const ImplPairDephAndObject& rComp) const
50 {
51 return (mfDepth < rComp.mfDepth);
52 }
53
54 // data read access
55 const E3dCompoundObject* getObject() const { return mpObject; }
56};
57
58}
59
61 const basegfx::B3DPoint& rFront,
62 const basegfx::B3DPoint& rBack,
63 const E3dCompoundObject& rObject,
64 const drawinglayer::geometry::ViewInformation3D& rObjectViewInformation3D,
65 ::std::vector< basegfx::B3DPoint >& o_rResult,
66 bool bAnyHit)
67{
68 o_rResult.clear();
69
70 if(rFront.equal(rBack))
71 return;
72
73 // rObject is an E3dCompoundObject, so it cannot be a scene (which is an E3dObject)
74 const sdr::contact::ViewContactOfE3d& rVCObject = static_cast< sdr::contact::ViewContactOfE3d& >(rObject.GetViewContact());
76
77 if(aPrimitives.empty())
78 return;
79
80 // make BoundVolume empty and overlapping test for speedup
81 const basegfx::B3DRange aObjectRange(aPrimitives.getB3DRange(rObjectViewInformation3D));
82
83 if(!aObjectRange.isEmpty())
84 {
85 const basegfx::B3DRange aFrontBackRange(rFront, rBack);
86
87 if(aObjectRange.overlaps(aFrontBackRange))
88 {
89 // bound volumes hit, geometric cut tests needed
90 drawinglayer::processor3d::CutFindProcessor aCutFindProcessor(rObjectViewInformation3D, rFront, rBack, bAnyHit);
91 aCutFindProcessor.process(aPrimitives);
92 o_rResult = aCutFindProcessor.getCutPoints();
93 }
94 }
95}
96
97
99{
100 // Search for root scene (outmost scene) of the 3d object since e.g. in chart, multiple scenes may
101 // be placed between object and outmost scene. On that search, remember the in-between scene's
102 // transformation for the correct complete ObjectTransformation. For historical reasons, the
103 // root scene's own object transformation is part of the scene's ViewTransformation, o do not
104 // add it. For more details, see ViewContactOfE3dScene::createViewInformation3D.
105 E3dScene* pParentScene(rCandidate.getParentE3dSceneFromE3dObject());
106 E3dScene* pRootScene(nullptr);
107 basegfx::B3DHomMatrix aInBetweenSceneMatrix;
108
109 while(pParentScene)
110 {
111 E3dScene* pParentParentScene(pParentScene->getParentE3dSceneFromE3dObject());
112
113 if(pParentParentScene)
114 {
115 // pParentScene is an in-between scene
116 aInBetweenSceneMatrix = pParentScene->GetTransform() * aInBetweenSceneMatrix;
117 }
118 else
119 {
120 // pParentScene is the root scene
121 pRootScene = pParentScene;
122 }
123
124 pParentScene = pParentParentScene;
125 }
126
127 if(pRootScene)
128 {
129 const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(pRootScene->GetViewContact());
130
131 if(aInBetweenSceneMatrix.isIdentity())
132 {
133 o_rViewInformation3D = rVCScene.getViewInformation3D();
134 }
135 else
136 {
137 // build new ViewInformation containing all transforms for the candidate
139
140 o_rViewInformation3D = drawinglayer::geometry::ViewInformation3D(
141 aViewInfo3D.getObjectTransformation() * aInBetweenSceneMatrix,
142 aViewInfo3D.getOrientation(),
143 aViewInfo3D.getProjection(),
144 aViewInfo3D.getDeviceToView(),
145 aViewInfo3D.getViewTime(),
146 aViewInfo3D.getExtendedInformationSequence());
147 }
148 }
149 else
150 {
151 const uno::Sequence< beans::PropertyValue > aEmptyParameters;
152 o_rViewInformation3D = drawinglayer::geometry::ViewInformation3D(aEmptyParameters);
153 }
154
155 return pRootScene;
156}
157
158
160 const basegfx::B2DPoint& rPoint,
161 const E3dScene& rScene,
162 ::std::vector< const E3dCompoundObject* >& o_rResult)
163{
164 o_rResult.clear();
165 SdrObjList* pList = rScene.GetSubList();
166
167 if(nullptr == pList || 0 == pList->GetObjCount())
168 return;
169
170 // prepare relative HitPoint. To do so, get the VC of the 3DScene and from there
171 // the Scene's 2D transformation. Multiplying with the inverse transformation
172 // will create a point relative to the 3D scene as unit-2d-object
174 basegfx::B2DHomMatrix aInverseSceneTransform(rVCScene.getObjectTransformation());
175 aInverseSceneTransform.invert();
176 const basegfx::B2DPoint aRelativePoint(aInverseSceneTransform * rPoint);
177
178 // check if test point is inside scene's area at all
179 if(!(aRelativePoint.getX() >= 0.0 && aRelativePoint.getX() <= 1.0 && aRelativePoint.getY() >= 0.0 && aRelativePoint.getY() <= 1.0))
180 return;
181
183 ::std::vector< ImplPairDephAndObject > aDepthAndObjectResults;
184 const uno::Sequence< beans::PropertyValue > aEmptyParameters;
185 drawinglayer::geometry::ViewInformation3D aViewInfo3D(aEmptyParameters);
186
187 while(aIterator.IsMore())
188 {
189 const E3dCompoundObject* pCandidate = dynamic_cast< const E3dCompoundObject* >(aIterator.Next());
190
191 if(pCandidate)
192 {
193 fillViewInformation3DForCompoundObject(aViewInfo3D, *pCandidate);
194
195 // create HitPoint Front and Back, transform to object coordinates
196 basegfx::B3DHomMatrix aViewToObject(aViewInfo3D.getObjectToView());
197 aViewToObject.invert();
198 const basegfx::B3DPoint aFront(aViewToObject * basegfx::B3DPoint(aRelativePoint.getX(), aRelativePoint.getY(), 0.0));
199 const basegfx::B3DPoint aBack(aViewToObject * basegfx::B3DPoint(aRelativePoint.getX(), aRelativePoint.getY(), 1.0));
200
201 if(!aFront.equal(aBack))
202 {
203 // get all hit points with object
204 ::std::vector< basegfx::B3DPoint > aHitsWithObject;
205 getAllHit3DObjectWithRelativePoint(aFront, aBack, *pCandidate, aViewInfo3D, aHitsWithObject, false);
206
207 for(const basegfx::B3DPoint & a : aHitsWithObject)
208 {
209 const basegfx::B3DPoint aPointInViewCoordinates(aViewInfo3D.getObjectToView() * a);
210 aDepthAndObjectResults.emplace_back(pCandidate, aPointInViewCoordinates.getZ());
211 }
212 }
213 }
214 }
215
216 // fill nRetval
217 const sal_uInt32 nCount(aDepthAndObjectResults.size());
218
219 if(nCount)
220 {
221 // sort aDepthAndObjectResults by depth
222 ::std::sort(aDepthAndObjectResults.begin(), aDepthAndObjectResults.end());
223
224 // copy SdrObject pointers to return result set
225 for(const auto& rResult : aDepthAndObjectResults)
226 {
227 o_rResult.push_back(rResult.getObject());
228 }
229 }
230}
231
232
234 const basegfx::B2DPoint& rPoint,
235 const E3dCompoundObject& rCandidate)
236{
237 const uno::Sequence< beans::PropertyValue > aEmptyParameters;
238 drawinglayer::geometry::ViewInformation3D aViewInfo3D(aEmptyParameters);
239 E3dScene* pRootScene = fillViewInformation3DForCompoundObject(aViewInfo3D, rCandidate);
240
241 if(pRootScene)
242 {
243 // prepare relative HitPoint. To do so, get the VC of the 3DScene and from there
244 // the Scene's 2D transformation. Multiplying with the inverse transformation
245 // will create a point relative to the 3D scene as unit-2d-object
246 const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(pRootScene->GetViewContact());
247 basegfx::B2DHomMatrix aInverseSceneTransform(rVCScene.getObjectTransformation());
248 aInverseSceneTransform.invert();
249 const basegfx::B2DPoint aRelativePoint(aInverseSceneTransform * rPoint);
250
251 // check if test point is inside scene's area at all
252 if(aRelativePoint.getX() >= 0.0 && aRelativePoint.getX() <= 1.0 && aRelativePoint.getY() >= 0.0 && aRelativePoint.getY() <= 1.0)
253 {
254 // create HitPoint Front and Back, transform to object coordinates
255 basegfx::B3DHomMatrix aViewToObject(aViewInfo3D.getObjectToView());
256 aViewToObject.invert();
257 const basegfx::B3DPoint aFront(aViewToObject * basegfx::B3DPoint(aRelativePoint.getX(), aRelativePoint.getY(), 0.0));
258 const basegfx::B3DPoint aBack(aViewToObject * basegfx::B3DPoint(aRelativePoint.getX(), aRelativePoint.getY(), 1.0));
259
260 if(!aFront.equal(aBack))
261 {
262 // get all hit points with object
263 ::std::vector< basegfx::B3DPoint > aHitsWithObject;
264 getAllHit3DObjectWithRelativePoint(aFront, aBack, rCandidate, aViewInfo3D, aHitsWithObject, true);
265
266 if(!aHitsWithObject.empty())
267 {
268 return true;
269 }
270 }
271 }
272 }
273
274 return false;
275}
276
277/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SbxObjectRef mpObject
const basegfx::B3DHomMatrix & GetTransform() const
Definition: obj3d.hxx:112
E3dScene * getParentE3dSceneFromE3dObject() const
Definition: obj3d.cxx:265
virtual SdrObjList * GetSubList() const override
Definition: scene3d.cxx:856
SdrObject * Next()
Definition: svditer.hxx:63
bool IsMore() const
Definition: svditer.hxx:62
size_t GetObjCount() const
Definition: svdpage.cxx:816
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:261
bool isIdentity() const
bool overlaps(const B3DRange &rRange) const
bool isEmpty() const
bool equal(const B3DTuple &rTup) const
TYPE getX() const
TYPE getY() const
TYPE getZ() const
const basegfx::B3DHomMatrix & getObjectToView() 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
basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D &aViewInformation) const
void process(const primitive3d::Primitive3DContainer &rSource)
const ::std::vector< basegfx::B3DPoint > & getCutPoints() const
const drawinglayer::geometry::ViewInformation3D & getViewInformation3D(const ::basegfx::B3DRange &rContentRange) const
const basegfx::B2DHomMatrix & getObjectTransformation() const
drawinglayer::primitive3d::Primitive3DContainer getViewIndependentPrimitive3DContainer() const
int nCount
EmbeddedObjectRef * pObject
bool checkHitSingle3DObject(const basegfx::B2DPoint &rPoint, const E3dCompoundObject &rCandidate)
support for checking if the single given 3d object is hit at position
E3dScene * fillViewInformation3DForCompoundObject(drawinglayer::geometry::ViewInformation3D &o_rViewInformation3D, const E3dCompoundObject &rCandidate)
support for getting a ViewInformation3D for a given CompoudObject3D with correct ObjectTransformation...
void getAllHit3DObjectsSortedFrontToBack(const basegfx::B2DPoint &rPoint, const E3dScene &rScene, ::std::vector< const E3dCompoundObject * > &o_rResult)
support for getting all from a 2d position hit objects in a 3d scene in a depth sorted array
static void getAllHit3DObjectWithRelativePoint(const basegfx::B3DPoint &rFront, const basegfx::B3DPoint &rBack, const E3dCompoundObject &rObject, const drawinglayer::geometry::ViewInformation3D &rObjectViewInformation3D, ::std::vector< basegfx::B3DPoint > &o_rResult, bool bAnyHit)
uno_Any a
bool operator<(const Subset &rLHS, const Subset &rRHS)
Definition: ucsubset.hxx:50