1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "BaseGFXHelper.hxx" 28cdf0e10cSrcweir #include <com/sun/star/drawing/DoubleSequence.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir using namespace ::com::sun::star; 31cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 32cdf0e10cSrcweir using namespace ::basegfx; 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace chart 35cdf0e10cSrcweir { 36cdf0e10cSrcweir namespace BaseGFXHelper 37cdf0e10cSrcweir { 38cdf0e10cSrcweir 39cdf0e10cSrcweir ::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly ) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir ::basegfx::B3DRange aRet; 42cdf0e10cSrcweir 43cdf0e10cSrcweir bool bInited = false; 44cdf0e10cSrcweir sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength(); 45cdf0e10cSrcweir for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength(); 48cdf0e10cSrcweir for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir if(!bInited) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir aRet = ::basegfx::B3DRange(::basegfx::B3DTuple( 53cdf0e10cSrcweir rPolyPoly.SequenceX[nPoly][nPoint] 54cdf0e10cSrcweir , rPolyPoly.SequenceY[nPoly][nPoint] 55cdf0e10cSrcweir , rPolyPoly.SequenceZ[nPoly][nPoint])); 56cdf0e10cSrcweir bInited = true; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir else 59cdf0e10cSrcweir { 60cdf0e10cSrcweir aRet.expand( ::basegfx::B3DTuple( 61cdf0e10cSrcweir rPolyPoly.SequenceX[nPoly][nPoint] 62cdf0e10cSrcweir , rPolyPoly.SequenceY[nPoly][nPoint] 63cdf0e10cSrcweir , rPolyPoly.SequenceZ[nPoly][nPoint])); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir return aRet; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()), 84cdf0e10cSrcweir static_cast< sal_Int32 >( rB2IRectangle.getHeight())); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir awt::Rectangle B2IRectangleToAWTRectangle( 88cdf0e10cSrcweir const ::basegfx::B2IRectangle& rB2IRectangle ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir return awt::Rectangle( rB2IRectangle.getMinX(), rB2IRectangle.getMinY(), 91cdf0e10cSrcweir static_cast< sal_Int32 >( rB2IRectangle.getWidth()), 92cdf0e10cSrcweir static_cast< sal_Int32 >( rB2IRectangle.getHeight())); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir B3DVector Direction3DToB3DVector( const Direction3D& rDirection ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir return B3DVector( 98cdf0e10cSrcweir rDirection.DirectionX 99cdf0e10cSrcweir , rDirection.DirectionY 100cdf0e10cSrcweir , rDirection.DirectionZ 101cdf0e10cSrcweir ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir return Direction3D( 107cdf0e10cSrcweir rB3DVector.getX() 108cdf0e10cSrcweir , rB3DVector.getY() 109cdf0e10cSrcweir , rB3DVector.getZ() 110cdf0e10cSrcweir ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir B3DVector Position3DToB3DVector( const Position3D& rPosition ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir return B3DVector( 116cdf0e10cSrcweir rPosition.PositionX 117cdf0e10cSrcweir , rPosition.PositionY 118cdf0e10cSrcweir , rPosition.PositionZ 119cdf0e10cSrcweir ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir return Position3D( 125cdf0e10cSrcweir rB3DVector.getX() 126cdf0e10cSrcweir , rB3DVector.getY() 127cdf0e10cSrcweir , rB3DVector.getZ() 128cdf0e10cSrcweir ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir B3DHomMatrix aResult; 134cdf0e10cSrcweir 135cdf0e10cSrcweir aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 ); 136cdf0e10cSrcweir aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 ); 137cdf0e10cSrcweir aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 ); 138cdf0e10cSrcweir aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 ); 141cdf0e10cSrcweir aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 ); 142cdf0e10cSrcweir aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 ); 143cdf0e10cSrcweir aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 ); 146cdf0e10cSrcweir aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 ); 147cdf0e10cSrcweir aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 ); 148cdf0e10cSrcweir aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 ); 151cdf0e10cSrcweir aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 ); 152cdf0e10cSrcweir aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 ); 153cdf0e10cSrcweir aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir return aResult; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir HomogenMatrix aResult; 161cdf0e10cSrcweir 162cdf0e10cSrcweir aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 ); 163cdf0e10cSrcweir aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 ); 164cdf0e10cSrcweir aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 ); 165cdf0e10cSrcweir aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 ); 168cdf0e10cSrcweir aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 ); 169cdf0e10cSrcweir aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 ); 170cdf0e10cSrcweir aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 ); 173cdf0e10cSrcweir aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 ); 174cdf0e10cSrcweir aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 ); 175cdf0e10cSrcweir aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 ); 178cdf0e10cSrcweir aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 ); 179cdf0e10cSrcweir aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 ); 180cdf0e10cSrcweir aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir return aResult; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir B3DTuple aScale, aTranslation, aRotation, aShearing; 188cdf0e10cSrcweir rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing ); 189cdf0e10cSrcweir return aRotation; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir B3DTuple aScale, aTranslation, aRotation, aShearing; 195cdf0e10cSrcweir rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing ); 196cdf0e10cSrcweir return aScale; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) ); 202cdf0e10cSrcweir ::basegfx::B3DHomMatrix aRotationMatrix; 203cdf0e10cSrcweir aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ()); 204cdf0e10cSrcweir rB3DMatrix = aRotationMatrix; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir double Deg2Rad( double fDegrees ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir return fDegrees * ( F_PI / 180.0 ); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir double Rad2Deg( double fRadians ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir return fRadians * ( 180.0 / F_PI ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir } // namespace BaseGFXHelper 218cdf0e10cSrcweir } // namespace chart 219