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_chart2.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 throw (RuntimeException,
49 lang::IllegalArgumentException)
50 {
51 double fX = rSourceValues[0];
52 double fY = rSourceValues[1];
53 double fZ = rSourceValues[2];
54 if(m_bSwapXAndY)
55 std::swap(fX,fY);
56 Sequence< double > aNewVec(3);
57 double fZwi;
58
59 fZwi = m_Matrix.Line1.Column1 * fX
60 + m_Matrix.Line1.Column2 * fY
61 + m_Matrix.Line1.Column3 * fZ
62 + m_Matrix.Line1.Column4;
63 aNewVec[0] = fZwi;
64
65 fZwi = m_Matrix.Line2.Column1 * fX
66 + m_Matrix.Line2.Column2 * fY
67 + m_Matrix.Line2.Column3 * fZ
68 + m_Matrix.Line2.Column4;
69 aNewVec[1] = fZwi;
70
71 fZwi = m_Matrix.Line3.Column1 * fX
72 + m_Matrix.Line3.Column2 * fY
73 + m_Matrix.Line3.Column3 * fZ
74 + m_Matrix.Line3.Column4;
75 aNewVec[2] = fZwi;
76
77 fZwi = m_Matrix.Line4.Column1 * fX
78 + m_Matrix.Line4.Column2 * fY
79 + m_Matrix.Line4.Column3 * fZ
80 + m_Matrix.Line4.Column4;
81 if(fZwi != 1.0 && fZwi != 0.0)
82 {
83 aNewVec[0] /= fZwi;
84 aNewVec[1] /= fZwi;
85 aNewVec[2] /= fZwi;
86 }
87 return aNewVec;
88 }
89
getSourceDimension()90 sal_Int32 SAL_CALL Linear3DTransformation::getSourceDimension()
91 throw (RuntimeException)
92 {
93 return 3;
94 }
95
getTargetDimension()96 sal_Int32 SAL_CALL Linear3DTransformation::getTargetDimension()
97 throw (RuntimeException)
98 {
99 return 3;
100 }
101
102
103 } // namespace chart
104