LibreOffice Module chart2 (master) 1
Linear3DTransformation.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
21
22using namespace ::com::sun::star;
23
24using ::com::sun::star::uno::Sequence;
25
26namespace chart
27{
28
29 Linear3DTransformation::Linear3DTransformation( const drawing::HomogenMatrix& rHomMatrix, bool bSwapXAndY )
30 : m_Matrix(rHomMatrix)
31 , m_bSwapXAndY(bSwapXAndY)
32{}
33
35{}
36
37// ____ XTransformation2 ____
38css::drawing::Position3D Linear3DTransformation::transform(
39 const Sequence< double >& rSourceValues ) const
40{
41 double fX = rSourceValues[0];
42 double fY = rSourceValues[1];
43 double fZ = rSourceValues[2];
44 if(m_bSwapXAndY)
45 std::swap(fX,fY);
46 css::drawing::Position3D aNewVec;
47 double fZwi;
48
49 fZwi = m_Matrix.Line1.Column1 * fX
50 + m_Matrix.Line1.Column2 * fY
51 + m_Matrix.Line1.Column3 * fZ
52 + m_Matrix.Line1.Column4;
53 aNewVec.PositionX = fZwi;
54
55 fZwi = m_Matrix.Line2.Column1 * fX
56 + m_Matrix.Line2.Column2 * fY
57 + m_Matrix.Line2.Column3 * fZ
58 + m_Matrix.Line2.Column4;
59 aNewVec.PositionY = fZwi;
60
61 fZwi = m_Matrix.Line3.Column1 * fX
62 + m_Matrix.Line3.Column2 * fY
63 + m_Matrix.Line3.Column3 * fZ
64 + m_Matrix.Line3.Column4;
65 aNewVec.PositionZ = fZwi;
66
67 fZwi = m_Matrix.Line4.Column1 * fX
68 + m_Matrix.Line4.Column2 * fY
69 + m_Matrix.Line4.Column3 * fZ
70 + m_Matrix.Line4.Column4;
71 if(fZwi != 1.0 && fZwi != 0.0)
72 {
73 aNewVec.PositionX /= fZwi;
74 aNewVec.PositionY /= fZwi;
75 aNewVec.PositionZ /= fZwi;
76 }
77 return aNewVec;
78}
79
80css::drawing::Position3D Linear3DTransformation::transform(
81 const css::drawing::Position3D& rSourceValues ) const
82{
83 double fX = rSourceValues.PositionX;
84 double fY = rSourceValues.PositionY;
85 double fZ = rSourceValues.PositionZ;
86 if(m_bSwapXAndY)
87 std::swap(fX,fY);
88 css::drawing::Position3D aNewVec;
89 double fZwi;
90
91 fZwi = m_Matrix.Line1.Column1 * fX
92 + m_Matrix.Line1.Column2 * fY
93 + m_Matrix.Line1.Column3 * fZ
94 + m_Matrix.Line1.Column4;
95 aNewVec.PositionX = fZwi;
96
97 fZwi = m_Matrix.Line2.Column1 * fX
98 + m_Matrix.Line2.Column2 * fY
99 + m_Matrix.Line2.Column3 * fZ
100 + m_Matrix.Line2.Column4;
101 aNewVec.PositionY = fZwi;
102
103 fZwi = m_Matrix.Line3.Column1 * fX
104 + m_Matrix.Line3.Column2 * fY
105 + m_Matrix.Line3.Column3 * fZ
106 + m_Matrix.Line3.Column4;
107 aNewVec.PositionZ = fZwi;
108
109 fZwi = m_Matrix.Line4.Column1 * fX
110 + m_Matrix.Line4.Column2 * fY
111 + m_Matrix.Line4.Column3 * fZ
112 + m_Matrix.Line4.Column4;
113 if(fZwi != 1.0 && fZwi != 0.0)
114 {
115 aNewVec.PositionX /= fZwi;
116 aNewVec.PositionY /= fZwi;
117 aNewVec.PositionZ /= fZwi;
118 }
119 return aNewVec;
120}
121
122} // namespace chart
123
124/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::drawing::Position3D transform(const css::drawing::Position3D &rSourceValues) const override
transforms the given input data tuple, given in the source coordinate system, according to the intern...
Linear3DTransformation(const css::drawing::HomogenMatrix &rHomMatrix, bool bSwapXAndY)
css::drawing::HomogenMatrix m_Matrix