LibreOffice Module chart2 (master) 1
BaseGFXHelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <BaseGFXHelper.hxx>
21#include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
22#include <com/sun/star/awt/Rectangle.hpp>
23
24using namespace ::com::sun::star;
25using namespace ::com::sun::star::drawing;
26using namespace ::basegfx;
27
29{
30
31::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
32{
34
35 bool bInited = false;
36 sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
37 for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
38 {
39 sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
40 for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
41 {
42 if(!bInited)
43 {
45 rPolyPoly.SequenceX[nPoly][nPoint]
46 , rPolyPoly.SequenceY[nPoly][nPoint]
47 , rPolyPoly.SequenceZ[nPoly][nPoint]));
48 bInited = true;
49 }
50 else
51 {
53 rPolyPoly.SequenceX[nPoly][nPoint]
54 , rPolyPoly.SequenceY[nPoly][nPoint]
55 , rPolyPoly.SequenceZ[nPoly][nPoint]));
56 }
57 }
58 }
59
60 return aRet;
61}
62
63::basegfx::B3DRange getBoundVolume( const std::vector<std::vector<css::drawing::Position3D>>& rPolyPoly )
64{
66
67 bool bInited = false;
68 sal_Int32 nPolyCount = rPolyPoly.size();
69 for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
70 {
71 sal_Int32 nPointCount = rPolyPoly[nPoly].size();
72 for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
73 {
74 if(!bInited)
75 {
77 rPolyPoly[nPoly][nPoint].PositionX
78 , rPolyPoly[nPoly][nPoint].PositionY
79 , rPolyPoly[nPoly][nPoint].PositionZ));
80 bInited = true;
81 }
82 else
83 {
85 rPolyPoly[nPoly][nPoint].PositionX
86 , rPolyPoly[nPoly][nPoint].PositionY
87 , rPolyPoly[nPoly][nPoint].PositionZ));
88 }
89 }
90 }
91
92 return aRet;
93}
94
95B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
96{
97 return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
98}
99
100B2IRectangle makeRectangle( const awt::Rectangle& rRect )
101{
102 return B2IRectangle(rRect.X, rRect.Y, rRect.X+rRect.Width, rRect.Y+rRect.Height);
103}
104
105awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
106{
107 return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
108}
109
110awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
111{
112 return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
113 static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
114}
115
116awt::Rectangle toAwtRectangle(const basegfx::B2IRectangle& rRectangle)
117{
118 return awt::Rectangle(rRectangle.getMinX(), rRectangle.getMinY(),
119 rRectangle.getWidth(), rRectangle.getHeight());
120}
121
122B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
123{
124 return B3DVector(
125 rDirection.DirectionX
126 , rDirection.DirectionY
127 , rDirection.DirectionZ
128 );
129}
130
131Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
132{
133 return Direction3D(
134 rB3DVector.getX()
135 , rB3DVector.getY()
136 , rB3DVector.getZ()
137 );
138}
139
140B3DVector Position3DToB3DVector( const Position3D& rPosition )
141{
142 return B3DVector(
143 rPosition.PositionX
144 , rPosition.PositionY
145 , rPosition.PositionZ
146 );
147}
148
149Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
150{
151 return Position3D(
152 rB3DVector.getX()
153 , rB3DVector.getY()
154 , rB3DVector.getZ()
155 );
156}
157
158B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
159{
160 B3DHomMatrix aResult;
161
162 aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
163 aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
164 aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
165 aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
166
167 aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
168 aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
169 aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
170 aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
171
172 aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
173 aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
174 aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
175 aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
176
177 aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
178 aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
179 aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
180 aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
181
182 return aResult;
183}
184
185HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
186{
187 HomogenMatrix aResult;
188
189 aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
190 aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
191 aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
192 aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
193
194 aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
195 aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
196 aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
197 aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
198
199 aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
200 aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
201 aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
202 aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
203
204 aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
205 aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
206 aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
207 aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
208
209 return aResult;
210}
211
212B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
213{
214 B3DTuple aScale, aTranslation, aRotation, aShearing;
215 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
216 return aRotation;
217}
218
219B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
220{
221 B3DTuple aScale, aTranslation, aRotation, aShearing;
222 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
223 return aScale;
224}
225
227{
228 B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
229 ::basegfx::B3DHomMatrix aRotationMatrix;
230 aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
231 rB3DMatrix = aRotationMatrix;
232}
233
234} // namespace chart::BaseGFXHelper
235
236/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void rotate(double fAngleX, double fAngleY, double fAngleZ)
void expand(const B3DTuple &rTuple)
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getHeight() const
B2IRange B2IRectangle
void ReduceToRotationMatrix(::basegfx::B3DHomMatrix &rB3DMatrix)
OOO_DLLPUBLIC_CHARTTOOLS css::awt::Point B2IRectangleToAWTPoint(const ::basegfx::B2IRectangle &rB2IRectangle)
OOO_DLLPUBLIC_CHARTTOOLS::basegfx::B3DTuple GetRotationFromMatrix(const ::basegfx::B3DHomMatrix &rB3DMatrix)
OOO_DLLPUBLIC_CHARTTOOLS css::drawing::HomogenMatrix B3DHomMatrixToHomogenMatrix(const ::basegfx::B3DHomMatrix &rB3DMatrix)
::basegfx::B3DVector Position3DToB3DVector(const css::drawing::Position3D &rPosition)
::basegfx::B3DVector Direction3DToB3DVector(const css::drawing::Direction3D &rDirection)
css::drawing::Direction3D B3DVectorToDirection3D(const ::basegfx::B3DVector &rB3DVector)
OOO_DLLPUBLIC_CHARTTOOLS::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix(const css::drawing::HomogenMatrix &rHomogenMatrix)
css::drawing::Position3D B3DVectorToPosition3D(const ::basegfx::B3DVector &rB3DVector)
OOO_DLLPUBLIC_CHARTTOOLS::basegfx::B2IRectangle makeRectangle(const css::awt::Point &rPosition, const css::awt::Size &rSize)
OOO_DLLPUBLIC_CHARTTOOLS css::awt::Rectangle toAwtRectangle(const basegfx::B2IRectangle &rB2IRectangle)
OOO_DLLPUBLIC_CHARTTOOLS::basegfx::B3DTuple GetScaleFromMatrix(const ::basegfx::B3DHomMatrix &rB3DMatrix)
OOO_DLLPUBLIC_CHARTTOOLS::basegfx::B3DRange getBoundVolume(const css::drawing::PolyPolygonShape3D &rPolyPoly)
OOO_DLLPUBLIC_CHARTTOOLS css::awt::Size B2IRectangleToAWTSize(const ::basegfx::B2IRectangle &rB2IRectangle)