xref: /AOO41X/main/chart2/source/tools/BaseGFXHelper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "BaseGFXHelper.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/drawing/DoubleSequence.hpp>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir using namespace ::com::sun::star;
35*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
36*cdf0e10cSrcweir using namespace ::basegfx;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace chart
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir namespace BaseGFXHelper
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir ::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir     ::basegfx::B3DRange aRet;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     bool bInited = false;
48*cdf0e10cSrcweir     sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
49*cdf0e10cSrcweir     for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir         sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
52*cdf0e10cSrcweir         for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
53*cdf0e10cSrcweir         {
54*cdf0e10cSrcweir             if(!bInited)
55*cdf0e10cSrcweir             {
56*cdf0e10cSrcweir                 aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
57*cdf0e10cSrcweir                           rPolyPoly.SequenceX[nPoly][nPoint]
58*cdf0e10cSrcweir                         , rPolyPoly.SequenceY[nPoly][nPoint]
59*cdf0e10cSrcweir                         , rPolyPoly.SequenceZ[nPoly][nPoint]));
60*cdf0e10cSrcweir                 bInited = true;
61*cdf0e10cSrcweir             }
62*cdf0e10cSrcweir             else
63*cdf0e10cSrcweir             {
64*cdf0e10cSrcweir                 aRet.expand( ::basegfx::B3DTuple(
65*cdf0e10cSrcweir                           rPolyPoly.SequenceX[nPoly][nPoint]
66*cdf0e10cSrcweir                         , rPolyPoly.SequenceY[nPoly][nPoint]
67*cdf0e10cSrcweir                         , rPolyPoly.SequenceZ[nPoly][nPoint]));
68*cdf0e10cSrcweir             }
69*cdf0e10cSrcweir         }
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     return aRet;
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
88*cdf0e10cSrcweir                       static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir awt::Rectangle B2IRectangleToAWTRectangle(
92*cdf0e10cSrcweir     const ::basegfx::B2IRectangle& rB2IRectangle )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     return awt::Rectangle( rB2IRectangle.getMinX(), rB2IRectangle.getMinY(),
95*cdf0e10cSrcweir                            static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
96*cdf0e10cSrcweir                            static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     return B3DVector(
102*cdf0e10cSrcweir           rDirection.DirectionX
103*cdf0e10cSrcweir         , rDirection.DirectionY
104*cdf0e10cSrcweir         , rDirection.DirectionZ
105*cdf0e10cSrcweir         );
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     return Direction3D(
111*cdf0e10cSrcweir           rB3DVector.getX()
112*cdf0e10cSrcweir         , rB3DVector.getY()
113*cdf0e10cSrcweir         , rB3DVector.getZ()
114*cdf0e10cSrcweir         );
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir B3DVector Position3DToB3DVector( const Position3D& rPosition )
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     return B3DVector(
120*cdf0e10cSrcweir           rPosition.PositionX
121*cdf0e10cSrcweir         , rPosition.PositionY
122*cdf0e10cSrcweir         , rPosition.PositionZ
123*cdf0e10cSrcweir         );
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     return Position3D(
129*cdf0e10cSrcweir           rB3DVector.getX()
130*cdf0e10cSrcweir         , rB3DVector.getY()
131*cdf0e10cSrcweir         , rB3DVector.getZ()
132*cdf0e10cSrcweir         );
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir     B3DHomMatrix aResult;
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
140*cdf0e10cSrcweir     aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
141*cdf0e10cSrcweir     aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
142*cdf0e10cSrcweir     aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
145*cdf0e10cSrcweir     aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
146*cdf0e10cSrcweir     aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
147*cdf0e10cSrcweir     aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
150*cdf0e10cSrcweir     aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
151*cdf0e10cSrcweir     aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
152*cdf0e10cSrcweir     aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
155*cdf0e10cSrcweir     aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
156*cdf0e10cSrcweir     aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
157*cdf0e10cSrcweir     aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     return aResult;
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir     HomogenMatrix aResult;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
167*cdf0e10cSrcweir     aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
168*cdf0e10cSrcweir     aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
169*cdf0e10cSrcweir     aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
172*cdf0e10cSrcweir     aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
173*cdf0e10cSrcweir     aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
174*cdf0e10cSrcweir     aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
177*cdf0e10cSrcweir     aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
178*cdf0e10cSrcweir     aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
179*cdf0e10cSrcweir     aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
182*cdf0e10cSrcweir     aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
183*cdf0e10cSrcweir     aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
184*cdf0e10cSrcweir     aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     return aResult;
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir     B3DTuple aScale, aTranslation, aRotation, aShearing;
192*cdf0e10cSrcweir     rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
193*cdf0e10cSrcweir     return aRotation;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     B3DTuple aScale, aTranslation, aRotation, aShearing;
199*cdf0e10cSrcweir     rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
200*cdf0e10cSrcweir     return aScale;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
206*cdf0e10cSrcweir     ::basegfx::B3DHomMatrix aRotationMatrix;
207*cdf0e10cSrcweir     aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
208*cdf0e10cSrcweir     rB3DMatrix = aRotationMatrix;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir double Deg2Rad( double fDegrees )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     return fDegrees * ( F_PI / 180.0 );
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir double Rad2Deg( double fRadians )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     return fRadians * ( 180.0 / F_PI );
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir } //  namespace BaseGFXHelper
222*cdf0e10cSrcweir } //  namespace chart
223