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