xref: /trunk/main/chart2/source/view/main/Linear3DTransformation.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartview.hxx"
26 #include "Linear3DTransformation.hxx"
27 #include <algorithm>
28 
29 using namespace ::com::sun::star;
30 
31 using ::com::sun::star::uno::Sequence;
32 using ::com::sun::star::uno::RuntimeException;
33 
34 namespace chart
35 {
36 
Linear3DTransformation(const drawing::HomogenMatrix & rHomMatrix,bool bSwapXAndY)37     Linear3DTransformation::Linear3DTransformation( const drawing::HomogenMatrix& rHomMatrix, bool bSwapXAndY )
38     : m_Matrix(rHomMatrix)
39     , m_bSwapXAndY(bSwapXAndY)
40 {}
41 
~Linear3DTransformation()42 Linear3DTransformation::~Linear3DTransformation()
43 {}
44 
45 // ____ XTransformation ____
transform(const Sequence<double> & rSourceValues)46 Sequence< double > SAL_CALL Linear3DTransformation::transform(
47                         const Sequence< double >& rSourceValues )
48 {
49     double fX = rSourceValues[0];
50     double fY = rSourceValues[1];
51     double fZ = rSourceValues[2];
52     if(m_bSwapXAndY)
53         std::swap(fX,fY);
54     Sequence< double > aNewVec(3);
55     double fZwi;
56 
57     fZwi = m_Matrix.Line1.Column1 * fX
58          + m_Matrix.Line1.Column2 * fY
59          + m_Matrix.Line1.Column3 * fZ
60          + m_Matrix.Line1.Column4;
61     aNewVec[0] = fZwi;
62 
63     fZwi = m_Matrix.Line2.Column1 * fX
64          + m_Matrix.Line2.Column2 * fY
65          + m_Matrix.Line2.Column3 * fZ
66          + m_Matrix.Line2.Column4;
67     aNewVec[1] = fZwi;
68 
69     fZwi = m_Matrix.Line3.Column1 * fX
70          + m_Matrix.Line3.Column2 * fY
71          + m_Matrix.Line3.Column3 * fZ
72          + m_Matrix.Line3.Column4;
73     aNewVec[2] = fZwi;
74 
75     fZwi = m_Matrix.Line4.Column1 * fX
76          + m_Matrix.Line4.Column2 * fY
77          + m_Matrix.Line4.Column3 * fZ
78          + m_Matrix.Line4.Column4;
79     if(fZwi != 1.0 && fZwi != 0.0)
80     {
81         aNewVec[0] /= fZwi;
82         aNewVec[1] /= fZwi;
83         aNewVec[2] /= fZwi;
84     }
85     return aNewVec;
86 }
87 
getSourceDimension()88 sal_Int32 SAL_CALL Linear3DTransformation::getSourceDimension()
89 {
90     return 3;
91 }
92 
getTargetDimension()93 sal_Int32 SAL_CALL Linear3DTransformation::getTargetDimension()
94 {
95     return 3;
96 }
97 
98 
99 }  // namespace chart
100