LibreOffice Module drawinglayer (master) 1
viewinformation3d.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
22#include <com/sun/star/beans/PropertyValue.hpp>
23#include <com/sun/star/geometry/AffineMatrix3D.hpp>
25#include <com/sun/star/uno/Sequence.hxx>
26#include <utility>
27
28
29using namespace com::sun::star;
30
31
33{
37 {
38 private:
39 // ViewInformation3D implementation can change refcount, so we have only
40 // two memory regions for pairs of ViewInformation3D/ImpViewInformation3D
41 friend class ::drawinglayer::geometry::ViewInformation3D;
42
43 // the 3D transformations
44 // Object to World. This may change and being adapted when entering 3D transformation
45 // groups
47
48 // World to Camera. This includes VRP, VPN and VUV camera coordinate system
50
51 // Camera to Device with X,Y and Z [-1.0 .. 1.0]. This is the
52 // 3D to 2D projection which may be parallel or perspective. When it is perspective,
53 // the last line of the homogen matrix will NOT be unused
55
56 // Device to View with X,Y and Z [0.0 .. 1.0]. This converts from -1 to 1 coordinates
57 // in camera coordinate system to 0 to 1 in unit 2D coordinates. This way it stays
58 // view-independent. To get discrete coordinates, the 2D transformation of a scene
59 // as 2D object needs to be involved
61
62 // Object to View is the linear combination of all four transformations. It's
63 // buffered to avoid too much matrix multiplying and created on demand
65
66 // the point in time
67 double mfViewTime;
68
69 // the extra PropertyValues; does not contain the transformations
70 uno::Sequence< beans::PropertyValue > mxExtendedInformation;
71
72 // the local UNO API strings
74 {
75 return "ObjectTransformation";
76 }
77
79 {
80 return "Orientation";
81 }
82
83 static OUString getNamePropertyProjection()
84 {
85 return "Projection";
86 }
87
89 {
90 return "Projection30";
91 }
92
94 {
95 return "Projection31";
96 }
97
99 {
100 return "Projection32";
101 }
102
104 {
105 return "Projection33";
106 }
107
109 {
110 return "DeviceToView";
111 }
112
113 static OUString getNamePropertyTime()
114 {
115 return "Time";
116 }
117
118 // a central PropertyValue parsing method to allow transportation of
119 // all ViewParameters using UNO API
120 void impInterpretPropertyValues(const uno::Sequence< beans::PropertyValue >& rViewParameters)
121 {
122 if(!rViewParameters.hasElements())
123 return;
124
125 const sal_Int32 nCount(rViewParameters.getLength());
126 sal_Int32 nExtendedInsert(0);
127
128 // prepare extended information for filtering. Maximum size is nCount
130 auto pExtendedInformation = mxExtendedInformation.getArray();
131
132 for(sal_Int32 a(0); a < nCount; a++)
133 {
134 const beans::PropertyValue& rProp = rViewParameters[a];
135
136 if(rProp.Name == getNamePropertyObjectTransformation())
137 {
138 css::geometry::AffineMatrix3D aAffineMatrix3D;
139 rProp.Value >>= aAffineMatrix3D;
141 }
142 else if(rProp.Name == getNamePropertyOrientation())
143 {
144 css::geometry::AffineMatrix3D aAffineMatrix3D;
145 rProp.Value >>= aAffineMatrix3D;
147 }
148 else if(rProp.Name == getNamePropertyProjection())
149 {
150 // projection may be defined using a frustum in which case the last line of
151 // the 4x4 matrix is not (0,0,0,1). Since AffineMatrix3D does not support that,
152 // these four values need to be treated extra
153 const double f_30(maProjection.get(3, 0));
154 const double f_31(maProjection.get(3, 1));
155 const double f_32(maProjection.get(3, 2));
156 const double f_33(maProjection.get(3, 3));
157
158 css::geometry::AffineMatrix3D aAffineMatrix3D;
159 rProp.Value >>= aAffineMatrix3D;
161
162 maProjection.set(3, 0, f_30);
163 maProjection.set(3, 1, f_31);
164 maProjection.set(3, 2, f_32);
165 maProjection.set(3, 3, f_33);
166 }
167 else if(rProp.Name == getNamePropertyProjection_30())
168 {
169 double f_30(0.0);
170 rProp.Value >>= f_30;
171 maProjection.set(3, 0, f_30);
172 }
173 else if(rProp.Name == getNamePropertyProjection_31())
174 {
175 double f_31(0.0);
176 rProp.Value >>= f_31;
177 maProjection.set(3, 1, f_31);
178 }
179 else if(rProp.Name == getNamePropertyProjection_32())
180 {
181 double f_32(0.0);
182 rProp.Value >>= f_32;
183 maProjection.set(3, 2, f_32);
184 }
185 else if(rProp.Name == getNamePropertyProjection_33())
186 {
187 double f_33(1.0);
188 rProp.Value >>= f_33;
189 maProjection.set(3, 3, f_33);
190 }
191 else if(rProp.Name == getNamePropertyDeviceToView())
192 {
193 css::geometry::AffineMatrix3D aAffineMatrix3D;
194 rProp.Value >>= aAffineMatrix3D;
196 }
197 else if(rProp.Name == getNamePropertyTime())
198 {
199 rProp.Value >>= mfViewTime;
200 }
201 else
202 {
203 // extra information; add to filtered information
204 pExtendedInformation[nExtendedInsert++] = rProp;
205 }
206 }
207
208 // extra information size is now known; realloc to final size
209 mxExtendedInformation.realloc(nExtendedInsert);
210 }
211
212 public:
214 basegfx::B3DHomMatrix aObjectTransformation,
215 basegfx::B3DHomMatrix aOrientation,
216 basegfx::B3DHomMatrix aProjection,
217 basegfx::B3DHomMatrix aDeviceToView,
218 double fViewTime,
219 const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
220 : maObjectTransformation(std::move(aObjectTransformation)),
221 maOrientation(std::move(aOrientation)),
222 maProjection(std::move(aProjection)),
223 maDeviceToView(std::move(aDeviceToView)),
224 mfViewTime(fViewTime)
225 {
226 impInterpretPropertyValues(rExtendedParameters);
227 }
228
229 explicit ImpViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
230 : mfViewTime()
231 {
232 impInterpretPropertyValues(rViewParameters);
233 }
234
236 : mfViewTime()
237 {
238 }
239
244 double getViewTime() const { return mfViewTime; }
245
247 {
248 // on demand WorldToView creation
249
251 {
253 }
254
255 return maObjectToView;
256 }
257
258 const uno::Sequence< beans::PropertyValue >& getExtendedInformationSequence() const
259 {
261 }
262
263 bool operator==(const ImpViewInformation3D& rCandidate) const
264 {
266 && maOrientation == rCandidate.maOrientation
267 && maProjection == rCandidate.maProjection
268 && maDeviceToView == rCandidate.maDeviceToView
269 && mfViewTime == rCandidate.mfViewTime
271 }
272 };
273} // end of namespace drawinglayer::geometry
274
275
277{
278 namespace
279 {
280 ViewInformation3D::ImplType& theGlobalDefault()
281 {
282 static ViewInformation3D::ImplType SINGLETON;
283 return SINGLETON;
284 }
285 }
286
288 const basegfx::B3DHomMatrix& rObjectObjectTransformation,
289 const basegfx::B3DHomMatrix& rOrientation,
290 const basegfx::B3DHomMatrix& rProjection,
291 const basegfx::B3DHomMatrix& rDeviceToView,
292 double fViewTime,
293 const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
294 : mpViewInformation3D(ImpViewInformation3D(
295 rObjectObjectTransformation, rOrientation, rProjection,
296 rDeviceToView, fViewTime, rExtendedParameters))
297 {
298 }
299
300 ViewInformation3D::ViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
301 : mpViewInformation3D(ImpViewInformation3D(rViewParameters))
302 {
303 }
304
306 : mpViewInformation3D(theGlobalDefault())
307 {
308 }
309
311
313
315
317 {
318 return mpViewInformation3D.same_object(theGlobalDefault());
319 }
320
322
324
326 {
327 return rCandidate.mpViewInformation3D == mpViewInformation3D;
328 }
329
331 {
332 return mpViewInformation3D->getObjectTransformation();
333 }
334
336 {
337 return mpViewInformation3D->getOrientation();
338 }
339
341 {
342 return mpViewInformation3D->getProjection();
343 }
344
346 {
347 return mpViewInformation3D->getDeviceToView();
348 }
349
351 {
352 return mpViewInformation3D->getObjectToView();
353 }
354
356 {
357 return mpViewInformation3D->getViewTime();
358 }
359
360 const uno::Sequence< beans::PropertyValue >& ViewInformation3D::getExtendedInformationSequence() const
361 {
362 return mpViewInformation3D->getExtendedInformationSequence();
363 }
364
365} // end of namespace
366
367/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
bool isIdentity() const
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
Implementation class for ViewInformation3D.
bool operator==(const ImpViewInformation3D &rCandidate) const
const uno::Sequence< beans::PropertyValue > & getExtendedInformationSequence() const
ImpViewInformation3D(const uno::Sequence< beans::PropertyValue > &rViewParameters)
ImpViewInformation3D(basegfx::B3DHomMatrix aObjectTransformation, basegfx::B3DHomMatrix aOrientation, basegfx::B3DHomMatrix aProjection, basegfx::B3DHomMatrix aDeviceToView, double fViewTime, const uno::Sequence< beans::PropertyValue > &rExtendedParameters)
const basegfx::B3DHomMatrix & getObjectToView() const
const basegfx::B3DHomMatrix & getDeviceToView() const
void impInterpretPropertyValues(const uno::Sequence< beans::PropertyValue > &rViewParameters)
const basegfx::B3DHomMatrix & getProjection() const
const basegfx::B3DHomMatrix & getObjectTransformation() const
uno::Sequence< beans::PropertyValue > mxExtendedInformation
const basegfx::B3DHomMatrix & getOrientation() const
ViewInformation3D()
default (empty) constructor
const basegfx::B3DHomMatrix & getObjectToView() const
for convenience, the linear combination of the above four transformations is offered
o3tl::cow_wrapper< ImpViewInformation3D, o3tl::ThreadSafeRefCountingPolicy > ImplType
const css::uno::Sequence< css::beans::PropertyValue > & getExtendedInformationSequence() const
Get the uno::Sequence< beans::PropertyValue > which contains only ViewInformation not offered directl...
ImplType mpViewInformation3D
pointer to private implementation class
const basegfx::B3DHomMatrix & getDeviceToView() const
const basegfx::B3DHomMatrix & getObjectTransformation() const
data access
const basegfx::B3DHomMatrix & getProjection() const
bool operator==(const ViewInformation3D &rCandidate) const
compare operators
ViewInformation3D & operator=(const ViewInformation3D &)
assignment operator
const basegfx::B3DHomMatrix & getOrientation() const
bool same_object(const cow_wrapper &rOther) const
int nCount
uno_Any a
::basegfx::B3DHomMatrix homMatrixFromAffineMatrix3D(const ::css::geometry::AffineMatrix3D &input)