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 
27 #include "BaseGFXHelper.hxx"
28 #include <com/sun/star/drawing/DoubleSequence.hpp>
29 
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::drawing;
32 using namespace ::basegfx;
33 
34 namespace chart
35 {
36 namespace BaseGFXHelper
37 {
38 
getBoundVolume(const drawing::PolyPolygonShape3D & rPolyPoly)39 ::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
40 {
41     ::basegfx::B3DRange aRet;
42 
43     bool bInited = false;
44     sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
45     for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
46     {
47         sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
48         for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
49         {
50             if(!bInited)
51             {
52                 aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
53                           rPolyPoly.SequenceX[nPoly][nPoint]
54                         , rPolyPoly.SequenceY[nPoly][nPoint]
55                         , rPolyPoly.SequenceZ[nPoly][nPoint]));
56                 bInited = true;
57             }
58             else
59             {
60                 aRet.expand( ::basegfx::B3DTuple(
61                           rPolyPoly.SequenceX[nPoly][nPoint]
62                         , rPolyPoly.SequenceY[nPoly][nPoint]
63                         , rPolyPoly.SequenceZ[nPoly][nPoint]));
64             }
65         }
66     }
67 
68     return aRet;
69 }
70 
makeRectangle(const awt::Point & rPos,const awt::Size & rSize)71 B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
72 {
73     return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
74 }
75 
B2IRectangleToAWTPoint(const::basegfx::B2IRectangle & rB2IRectangle)76 awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
77 {
78     return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
79 }
80 
B2IRectangleToAWTSize(const::basegfx::B2IRectangle & rB2IRectangle)81 awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
82 {
83     return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
84                       static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
85 }
86 
B2IRectangleToAWTRectangle(const::basegfx::B2IRectangle & rB2IRectangle)87 awt::Rectangle B2IRectangleToAWTRectangle(
88     const ::basegfx::B2IRectangle& rB2IRectangle )
89 {
90     return awt::Rectangle( rB2IRectangle.getMinX(), rB2IRectangle.getMinY(),
91                            static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
92                            static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
93 }
94 
Direction3DToB3DVector(const Direction3D & rDirection)95 B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
96 {
97     return B3DVector(
98           rDirection.DirectionX
99         , rDirection.DirectionY
100         , rDirection.DirectionZ
101         );
102 }
103 
B3DVectorToDirection3D(const B3DVector & rB3DVector)104 Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
105 {
106     return Direction3D(
107           rB3DVector.getX()
108         , rB3DVector.getY()
109         , rB3DVector.getZ()
110         );
111 }
112 
Position3DToB3DVector(const Position3D & rPosition)113 B3DVector Position3DToB3DVector( const Position3D& rPosition )
114 {
115     return B3DVector(
116           rPosition.PositionX
117         , rPosition.PositionY
118         , rPosition.PositionZ
119         );
120 }
121 
B3DVectorToPosition3D(const B3DVector & rB3DVector)122 Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
123 {
124     return Position3D(
125           rB3DVector.getX()
126         , rB3DVector.getY()
127         , rB3DVector.getZ()
128         );
129 }
130 
HomogenMatrixToB3DHomMatrix(const HomogenMatrix & rHomogenMatrix)131 B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
132 {
133     B3DHomMatrix aResult;
134 
135     aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
136     aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
137     aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
138     aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
139 
140     aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
141     aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
142     aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
143     aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
144 
145     aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
146     aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
147     aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
148     aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
149 
150     aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
151     aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
152     aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
153     aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
154 
155     return aResult;
156 }
157 
B3DHomMatrixToHomogenMatrix(const B3DHomMatrix & rB3DMatrix)158 HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
159 {
160     HomogenMatrix aResult;
161 
162     aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
163     aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
164     aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
165     aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
166 
167     aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
168     aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
169     aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
170     aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
171 
172     aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
173     aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
174     aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
175     aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
176 
177     aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
178     aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
179     aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
180     aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
181 
182     return aResult;
183 }
184 
GetRotationFromMatrix(const B3DHomMatrix & rB3DMatrix)185 B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
186 {
187     B3DTuple aScale, aTranslation, aRotation, aShearing;
188     rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
189     return aRotation;
190 }
191 
GetScaleFromMatrix(const B3DHomMatrix & rB3DMatrix)192 B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
193 {
194     B3DTuple aScale, aTranslation, aRotation, aShearing;
195     rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
196     return aScale;
197 }
198 
ReduceToRotationMatrix(::basegfx::B3DHomMatrix & rB3DMatrix)199 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
200 {
201     B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
202     ::basegfx::B3DHomMatrix aRotationMatrix;
203     aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
204     rB3DMatrix = aRotationMatrix;
205 }
206 
Deg2Rad(double fDegrees)207 double Deg2Rad( double fDegrees )
208 {
209     return fDegrees * ( F_PI / 180.0 );
210 }
211 
Rad2Deg(double fRadians)212 double Rad2Deg( double fRadians )
213 {
214     return fRadians * ( 180.0 / F_PI );
215 }
216 
217 } //  namespace BaseGFXHelper
218 } //  namespace chart
219