xref: /AOO41X/main/drawinglayer/source/primitive3d/sdrextrudelathetools3d.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_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrextrudelathetools3d.hxx>
32*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
33*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
34*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
35*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
36*cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx>
37*cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx>
38*cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygontools.hxx>
39*cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx>
40*cdf0e10cSrcweir #include <basegfx/range/b3drange.hxx>
41*cdf0e10cSrcweir #include <basegfx/matrix/b3dhommatrix.hxx>
42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
43*cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation3d.hxx>
44*cdf0e10cSrcweir #include <numeric>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
47*cdf0e10cSrcweir // decompositon helpers for extrude/lathe (rotation) objects
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////////////
52*cdf0e10cSrcweir 	// common helpers
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 	basegfx::B2DPolyPolygon impScalePolyPolygonOnCenter(
55*cdf0e10cSrcweir 		const basegfx::B2DPolyPolygon& rSource,
56*cdf0e10cSrcweir 		double fScale)
57*cdf0e10cSrcweir 	{
58*cdf0e10cSrcweir 		basegfx::B2DPolyPolygon aRetval(rSource);
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 		if(!basegfx::fTools::equalZero(fScale))
61*cdf0e10cSrcweir 		{
62*cdf0e10cSrcweir 			const basegfx::B2DRange aRange(basegfx::tools::getRange(rSource));
63*cdf0e10cSrcweir 			const basegfx::B2DPoint aCenter(aRange.getCenter());
64*cdf0e10cSrcweir 			basegfx::B2DHomMatrix aTrans;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 			aTrans.translate(-aCenter.getX(), -aCenter.getY());
67*cdf0e10cSrcweir 			aTrans.scale(fScale, fScale);
68*cdf0e10cSrcweir 			aTrans.translate(aCenter.getX(), aCenter.getY());
69*cdf0e10cSrcweir 			aRetval.transform(aTrans);
70*cdf0e10cSrcweir 		}
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 		return aRetval;
73*cdf0e10cSrcweir 	}
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	void impGetOuterPolyPolygon(
76*cdf0e10cSrcweir 		basegfx::B2DPolyPolygon& rPolygon,
77*cdf0e10cSrcweir 		basegfx::B2DPolyPolygon& rOuterPolyPolygon,
78*cdf0e10cSrcweir 		double fOffset,
79*cdf0e10cSrcweir 		bool bCharacterMode)
80*cdf0e10cSrcweir 	{
81*cdf0e10cSrcweir 		rOuterPolyPolygon = rPolygon;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 		if(basegfx::fTools::more(fOffset, 0.0))
84*cdf0e10cSrcweir 		{
85*cdf0e10cSrcweir 			if(bCharacterMode)
86*cdf0e10cSrcweir 			{
87*cdf0e10cSrcweir 				// grow the outside polygon and scale all polygons to original size. This is done
88*cdf0e10cSrcweir 				// to avoid a shrink which potentially would lead to self-intersections, but changes
89*cdf0e10cSrcweir 				// the original polygon -> not a precision step, so e.g. not usable for charts
90*cdf0e10cSrcweir 				const basegfx::B2DRange aRange(basegfx::tools::getRange(rPolygon));
91*cdf0e10cSrcweir 				rPolygon = basegfx::tools::growInNormalDirection(rPolygon, fOffset);
92*cdf0e10cSrcweir 				const basegfx::B2DRange aGrownRange(basegfx::tools::getRange(rPolygon));
93*cdf0e10cSrcweir 				const double fScaleX(basegfx::fTools::equalZero(aGrownRange.getWidth()) ? 1.0 : aRange.getWidth() / aGrownRange.getWidth());
94*cdf0e10cSrcweir 				const double fScaleY(basegfx::fTools::equalZero(aGrownRange.getHeight())? 1.0 : aRange.getHeight() / aGrownRange.getHeight());
95*cdf0e10cSrcweir 				basegfx::B2DHomMatrix aScaleTrans;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 				aScaleTrans.translate(-aGrownRange.getMinX(), -aGrownRange.getMinY());
98*cdf0e10cSrcweir 				aScaleTrans.scale(fScaleX, fScaleY);
99*cdf0e10cSrcweir 				aScaleTrans.translate(aRange.getMinX(), aRange.getMinY());
100*cdf0e10cSrcweir 				rPolygon.transform(aScaleTrans);
101*cdf0e10cSrcweir 				rOuterPolyPolygon.transform(aScaleTrans);
102*cdf0e10cSrcweir 			}
103*cdf0e10cSrcweir 			else
104*cdf0e10cSrcweir 			{
105*cdf0e10cSrcweir 				// use more precision, shrink the outer polygons. Since this may lead to self-intersections,
106*cdf0e10cSrcweir 				// some kind of correction should be applied here after that step
107*cdf0e10cSrcweir 				rOuterPolyPolygon = basegfx::tools::growInNormalDirection(rPolygon, -fOffset);
108*cdf0e10cSrcweir 				basegfx::tools::correctGrowShrinkPolygonPair(rPolygon, rOuterPolyPolygon);
109*cdf0e10cSrcweir 			}
110*cdf0e10cSrcweir 		}
111*cdf0e10cSrcweir 	}
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	void impAddInBetweenFill(
114*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon& rTarget,
115*cdf0e10cSrcweir 		const basegfx::B3DPolyPolygon& rPolA,
116*cdf0e10cSrcweir 		const basegfx::B3DPolyPolygon& rPolB,
117*cdf0e10cSrcweir 		double fTexVerStart,
118*cdf0e10cSrcweir 		double fTexVerStop,
119*cdf0e10cSrcweir 		bool bCreateNormals,
120*cdf0e10cSrcweir 		bool bCreateTextureCoordinates)
121*cdf0e10cSrcweir 	{
122*cdf0e10cSrcweir 		OSL_ENSURE(rPolA.count() == rPolB.count(), "impAddInBetweenFill: unequally sized polygons (!)");
123*cdf0e10cSrcweir 		const sal_uInt32 nPolygonCount(rPolA.count());
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 		for(sal_uInt32 a(0L); a < nPolygonCount; a++)
126*cdf0e10cSrcweir 		{
127*cdf0e10cSrcweir 			const basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a));
128*cdf0e10cSrcweir 			const basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a));
129*cdf0e10cSrcweir 			OSL_ENSURE(aSubA.count() == aSubB.count(), "impAddInBetweenFill: unequally sized polygons (!)");
130*cdf0e10cSrcweir 			const sal_uInt32 nPointCount(aSubA.count());
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 			if(nPointCount)
133*cdf0e10cSrcweir 			{
134*cdf0e10cSrcweir 				const sal_uInt32 nEdgeCount(aSubA.isClosed() ? nPointCount : nPointCount - 1L);
135*cdf0e10cSrcweir 				double fTexHorMultiplicatorA(0.0), fTexHorMultiplicatorB(0.0);
136*cdf0e10cSrcweir 				double fPolygonPosA(0.0), fPolygonPosB(0.0);
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 				if(bCreateTextureCoordinates)
139*cdf0e10cSrcweir 				{
140*cdf0e10cSrcweir 					const double fPolygonLengthA(basegfx::tools::getLength(aSubA));
141*cdf0e10cSrcweir 					fTexHorMultiplicatorA = basegfx::fTools::equalZero(fPolygonLengthA) ? 1.0 : 1.0 / fPolygonLengthA;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 					const double fPolygonLengthB(basegfx::tools::getLength(aSubB));
144*cdf0e10cSrcweir 					fTexHorMultiplicatorB = basegfx::fTools::equalZero(fPolygonLengthB) ? 1.0 : 1.0 / fPolygonLengthB;
145*cdf0e10cSrcweir 				}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 				for(sal_uInt32 b(0L); b < nEdgeCount; b++)
148*cdf0e10cSrcweir 				{
149*cdf0e10cSrcweir 					const sal_uInt32 nIndexA(b);
150*cdf0e10cSrcweir 					const sal_uInt32 nIndexB((b + 1L) % nPointCount);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 					const basegfx::B3DPoint aStartA(aSubA.getB3DPoint(nIndexA));
153*cdf0e10cSrcweir 					const basegfx::B3DPoint aEndA(aSubA.getB3DPoint(nIndexB));
154*cdf0e10cSrcweir 					const basegfx::B3DPoint aStartB(aSubB.getB3DPoint(nIndexA));
155*cdf0e10cSrcweir 					const basegfx::B3DPoint aEndB(aSubB.getB3DPoint(nIndexB));
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 					basegfx::B3DPolygon aNew;
158*cdf0e10cSrcweir 					aNew.setClosed(true);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 					aNew.append(aStartA);
161*cdf0e10cSrcweir 					aNew.append(aStartB);
162*cdf0e10cSrcweir 					aNew.append(aEndB);
163*cdf0e10cSrcweir 					aNew.append(aEndA);
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 					if(bCreateNormals)
166*cdf0e10cSrcweir 					{
167*cdf0e10cSrcweir 						aNew.setNormal(0L, aSubA.getNormal(nIndexA));
168*cdf0e10cSrcweir 						aNew.setNormal(1L, aSubB.getNormal(nIndexA));
169*cdf0e10cSrcweir 						aNew.setNormal(2L, aSubB.getNormal(nIndexB));
170*cdf0e10cSrcweir 						aNew.setNormal(3L, aSubA.getNormal(nIndexB));
171*cdf0e10cSrcweir 					}
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 					if(bCreateTextureCoordinates)
174*cdf0e10cSrcweir 					{
175*cdf0e10cSrcweir 						const double fRelTexAL(fPolygonPosA * fTexHorMultiplicatorA);
176*cdf0e10cSrcweir 						const double fEdgeLengthA(basegfx::B3DVector(aEndA - aStartA).getLength());
177*cdf0e10cSrcweir 						fPolygonPosA += fEdgeLengthA;
178*cdf0e10cSrcweir 						const double fRelTexAR(fPolygonPosA * fTexHorMultiplicatorA);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 						const double fRelTexBL(fPolygonPosB * fTexHorMultiplicatorB);
181*cdf0e10cSrcweir 						const double fEdgeLengthB(basegfx::B3DVector(aEndB - aStartB).getLength());
182*cdf0e10cSrcweir 						fPolygonPosB += fEdgeLengthB;
183*cdf0e10cSrcweir 						const double fRelTexBR(fPolygonPosB * fTexHorMultiplicatorB);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 						aNew.setTextureCoordinate(0L, basegfx::B2DPoint(fRelTexAL, fTexVerStart));
186*cdf0e10cSrcweir 						aNew.setTextureCoordinate(1L, basegfx::B2DPoint(fRelTexBL, fTexVerStop));
187*cdf0e10cSrcweir 						aNew.setTextureCoordinate(2L, basegfx::B2DPoint(fRelTexBR, fTexVerStop));
188*cdf0e10cSrcweir 						aNew.setTextureCoordinate(3L, basegfx::B2DPoint(fRelTexAR, fTexVerStart));
189*cdf0e10cSrcweir 					}
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 					rTarget.append(aNew);
192*cdf0e10cSrcweir 				}
193*cdf0e10cSrcweir 			}
194*cdf0e10cSrcweir 		}
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	void impSetNormal(
198*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon& rCandidate,
199*cdf0e10cSrcweir 		const basegfx::B3DVector& rNormal)
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		for(sal_uInt32 a(0L); a < rCandidate.count(); a++)
202*cdf0e10cSrcweir 		{
203*cdf0e10cSrcweir 			basegfx::B3DPolygon aSub(rCandidate.getB3DPolygon(a));
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 			for(sal_uInt32 b(0L); b < aSub.count(); b++)
206*cdf0e10cSrcweir 			{
207*cdf0e10cSrcweir 				aSub.setNormal(b, rNormal);
208*cdf0e10cSrcweir 			}
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 			rCandidate.setB3DPolygon(a, aSub);
211*cdf0e10cSrcweir 		}
212*cdf0e10cSrcweir 	}
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	void impCreateInBetweenNormals(
215*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon& rPolA,
216*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon& rPolB,
217*cdf0e10cSrcweir 		bool bSmoothHorizontalNormals)
218*cdf0e10cSrcweir 	{
219*cdf0e10cSrcweir 		OSL_ENSURE(rPolA.count() == rPolB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)");
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 		for(sal_uInt32 a(0L); a < rPolA.count(); a++)
222*cdf0e10cSrcweir 		{
223*cdf0e10cSrcweir 			basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a));
224*cdf0e10cSrcweir 			basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a));
225*cdf0e10cSrcweir 			OSL_ENSURE(aSubA.count() == aSubB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)");
226*cdf0e10cSrcweir 			const sal_uInt32 nPointCount(aSubA.count());
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 			if(nPointCount)
229*cdf0e10cSrcweir 			{
230*cdf0e10cSrcweir 				basegfx::B3DPoint aPrevA(aSubA.getB3DPoint(nPointCount - 1L));
231*cdf0e10cSrcweir 				basegfx::B3DPoint aCurrA(aSubA.getB3DPoint(0L));
232*cdf0e10cSrcweir 				const bool bClosed(aSubA.isClosed());
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 				for(sal_uInt32 b(0L); b < nPointCount; b++)
235*cdf0e10cSrcweir 				{
236*cdf0e10cSrcweir 					const sal_uInt32 nIndNext((b + 1L) % nPointCount);
237*cdf0e10cSrcweir 					const basegfx::B3DPoint aNextA(aSubA.getB3DPoint(nIndNext));
238*cdf0e10cSrcweir 					const basegfx::B3DPoint aCurrB(aSubB.getB3DPoint(b));
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 					// vector to back
241*cdf0e10cSrcweir 					basegfx::B3DVector aDepth(aCurrB - aCurrA);
242*cdf0e10cSrcweir 					aDepth.normalize();
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 					if(aDepth.equalZero())
245*cdf0e10cSrcweir 					{
246*cdf0e10cSrcweir 						// no difference, try to get depth from next point
247*cdf0e10cSrcweir 						const basegfx::B3DPoint aNextB(aSubB.getB3DPoint(nIndNext));
248*cdf0e10cSrcweir 						aDepth = aNextB - aNextA;
249*cdf0e10cSrcweir 						aDepth.normalize();
250*cdf0e10cSrcweir 					}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 					// vector to left (correct for non-closed lines)
253*cdf0e10cSrcweir 					const bool bFirstAndNotClosed(!bClosed && 0L == b);
254*cdf0e10cSrcweir 					basegfx::B3DVector aLeft(bFirstAndNotClosed ? aCurrA - aNextA : aPrevA - aCurrA);
255*cdf0e10cSrcweir 					aLeft.normalize();
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 					// create left normal
258*cdf0e10cSrcweir 					const basegfx::B3DVector aNormalLeft(aDepth.getPerpendicular(aLeft));
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 					if(bSmoothHorizontalNormals)
261*cdf0e10cSrcweir 					{
262*cdf0e10cSrcweir 						// vector to right (correct for non-closed lines)
263*cdf0e10cSrcweir 						const bool bLastAndNotClosed(!bClosed && b + 1L == nPointCount);
264*cdf0e10cSrcweir 						basegfx::B3DVector aRight(bLastAndNotClosed ? aCurrA - aPrevA : aNextA - aCurrA);
265*cdf0e10cSrcweir 						aRight.normalize();
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 						// create right normal
268*cdf0e10cSrcweir 						const basegfx::B3DVector aNormalRight(aRight.getPerpendicular(aDepth));
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 						// create smoothed in-between normal
271*cdf0e10cSrcweir 						basegfx::B3DVector aNewNormal(aNormalLeft + aNormalRight);
272*cdf0e10cSrcweir 						aNewNormal.normalize();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 						// set as new normal at polygons
275*cdf0e10cSrcweir 						aSubA.setNormal(b, aNewNormal);
276*cdf0e10cSrcweir 						aSubB.setNormal(b, aNewNormal);
277*cdf0e10cSrcweir 					}
278*cdf0e10cSrcweir 					else
279*cdf0e10cSrcweir 					{
280*cdf0e10cSrcweir 						// set aNormalLeft as new normal at polygons
281*cdf0e10cSrcweir 						aSubA.setNormal(b, aNormalLeft);
282*cdf0e10cSrcweir 						aSubB.setNormal(b, aNormalLeft);
283*cdf0e10cSrcweir 					}
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 					// prepare next step
286*cdf0e10cSrcweir 					aPrevA = aCurrA;
287*cdf0e10cSrcweir 					aCurrA = aNextA;
288*cdf0e10cSrcweir 				}
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 				rPolA.setB3DPolygon(a, aSubA);
291*cdf0e10cSrcweir 				rPolB.setB3DPolygon(a, aSubB);
292*cdf0e10cSrcweir 			}
293*cdf0e10cSrcweir 		}
294*cdf0e10cSrcweir 	}
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	void impMixNormals(
297*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon& rPolA,
298*cdf0e10cSrcweir 		const basegfx::B3DPolyPolygon& rPolB,
299*cdf0e10cSrcweir 		double fWeightA)
300*cdf0e10cSrcweir 	{
301*cdf0e10cSrcweir 		const double fWeightB(1.0 - fWeightA);
302*cdf0e10cSrcweir 		OSL_ENSURE(rPolA.count() == rPolB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)");
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 		for(sal_uInt32 a(0L); a < rPolA.count(); a++)
305*cdf0e10cSrcweir 		{
306*cdf0e10cSrcweir 			basegfx::B3DPolygon aSubA(rPolA.getB3DPolygon(a));
307*cdf0e10cSrcweir 			const basegfx::B3DPolygon aSubB(rPolB.getB3DPolygon(a));
308*cdf0e10cSrcweir 			OSL_ENSURE(aSubA.count() == aSubB.count(), "sdrExtrudePrimitive3D: unequally sized polygons (!)");
309*cdf0e10cSrcweir 			const sal_uInt32 nPointCount(aSubA.count());
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 			for(sal_uInt32 b(0L); b < nPointCount; b++)
312*cdf0e10cSrcweir 			{
313*cdf0e10cSrcweir 				const basegfx::B3DVector aVA(aSubA.getNormal(b) * fWeightA);
314*cdf0e10cSrcweir 				const basegfx::B3DVector aVB(aSubB.getNormal(b) * fWeightB);
315*cdf0e10cSrcweir 				basegfx::B3DVector aVNew(aVA + aVB);
316*cdf0e10cSrcweir 				aVNew.normalize();
317*cdf0e10cSrcweir 				aSubA.setNormal(b, aVNew);
318*cdf0e10cSrcweir 			}
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 			rPolA.setB3DPolygon(a, aSubA);
321*cdf0e10cSrcweir 		}
322*cdf0e10cSrcweir 	}
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 	bool impHasCutWith(const basegfx::B2DPolygon& rPoly, const basegfx::B2DPoint& rStart, const basegfx::B2DPoint& rEnd)
325*cdf0e10cSrcweir     {
326*cdf0e10cSrcweir         // polygon is closed, one of the points is a member
327*cdf0e10cSrcweir         const sal_uInt32 nPointCount(rPoly.count());
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir         if(nPointCount)
330*cdf0e10cSrcweir         {
331*cdf0e10cSrcweir             basegfx::B2DPoint aCurrent(rPoly.getB2DPoint(0));
332*cdf0e10cSrcweir             const basegfx::B2DVector aVector(rEnd - rStart);
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir             for(sal_uInt32 a(0); a < nPointCount; a++)
335*cdf0e10cSrcweir             {
336*cdf0e10cSrcweir                 const sal_uInt32 nNextIndex((a + 1) % nPointCount);
337*cdf0e10cSrcweir                 const basegfx::B2DPoint aNext(rPoly.getB2DPoint(nNextIndex));
338*cdf0e10cSrcweir                 const basegfx::B2DVector aEdgeVector(aNext - aCurrent);
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir                 if(basegfx::tools::findCut(
341*cdf0e10cSrcweir                     rStart, aVector,
342*cdf0e10cSrcweir                     aCurrent, aEdgeVector))
343*cdf0e10cSrcweir                 {
344*cdf0e10cSrcweir                     return true;
345*cdf0e10cSrcweir                 }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir                 aCurrent = aNext;
348*cdf0e10cSrcweir             }
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         return false;
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir } // end of anonymous namespace
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir namespace drawinglayer
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	namespace primitive3d
360*cdf0e10cSrcweir 	{
361*cdf0e10cSrcweir 		void createLatheSlices(
362*cdf0e10cSrcweir 			Slice3DVector& rSliceVector,
363*cdf0e10cSrcweir 			const basegfx::B2DPolyPolygon& rSource,
364*cdf0e10cSrcweir 			double fBackScale,
365*cdf0e10cSrcweir 			double fDiagonal,
366*cdf0e10cSrcweir 			double fRotation,
367*cdf0e10cSrcweir 			sal_uInt32 nSteps,
368*cdf0e10cSrcweir 			bool bCharacterMode,
369*cdf0e10cSrcweir 			bool bCloseFront,
370*cdf0e10cSrcweir 			bool bCloseBack)
371*cdf0e10cSrcweir 		{
372*cdf0e10cSrcweir 			if(basegfx::fTools::equalZero(fRotation) || 0L == nSteps)
373*cdf0e10cSrcweir 			{
374*cdf0e10cSrcweir 				// no rotation or no steps, just one plane
375*cdf0e10cSrcweir 				rSliceVector.push_back(Slice3D(rSource, basegfx::B3DHomMatrix()));
376*cdf0e10cSrcweir 			}
377*cdf0e10cSrcweir 			else
378*cdf0e10cSrcweir 			{
379*cdf0e10cSrcweir 				const bool bBackScale(!basegfx::fTools::equal(fBackScale, 1.0));
380*cdf0e10cSrcweir 				const bool bClosedRotation(!bBackScale && basegfx::fTools::equal(fRotation, F_2PI));
381*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aFront(rSource);
382*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aBack(rSource);
383*cdf0e10cSrcweir 				basegfx::B3DHomMatrix aTransformBack;
384*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aOuterBack;
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 				if(bClosedRotation)
387*cdf0e10cSrcweir 				{
388*cdf0e10cSrcweir 					bCloseFront = bCloseBack = false;
389*cdf0e10cSrcweir 				}
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 				if(bBackScale)
392*cdf0e10cSrcweir 				{
393*cdf0e10cSrcweir 					// avoid null zoom
394*cdf0e10cSrcweir 					if(basegfx::fTools::equalZero(fBackScale))
395*cdf0e10cSrcweir 					{
396*cdf0e10cSrcweir 						fBackScale = 0.000001;
397*cdf0e10cSrcweir 					}
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 					// back is scaled compared to front, create scaled version
400*cdf0e10cSrcweir 					aBack = impScalePolyPolygonOnCenter(aBack, fBackScale);
401*cdf0e10cSrcweir 				}
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 				if(bCloseFront || bCloseBack)
404*cdf0e10cSrcweir 				{
405*cdf0e10cSrcweir 					const basegfx::B2DRange aBaseRange(basegfx::tools::getRange(aFront));
406*cdf0e10cSrcweir 					const double fOuterLength(aBaseRange.getMaxX() * fRotation);
407*cdf0e10cSrcweir 					const double fInnerLength(aBaseRange.getMinX() * fRotation);
408*cdf0e10cSrcweir 					const double fAverageLength((fOuterLength + fInnerLength) * 0.5);
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 					if(bCloseFront)
411*cdf0e10cSrcweir 					{
412*cdf0e10cSrcweir 						const double fOffsetLen((fAverageLength / 12.0) * fDiagonal);
413*cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aOuterFront;
414*cdf0e10cSrcweir 						impGetOuterPolyPolygon(aFront, aOuterFront, fOffsetLen, bCharacterMode);
415*cdf0e10cSrcweir 						basegfx::B3DHomMatrix aTransform;
416*cdf0e10cSrcweir 						aTransform.translate(0.0, 0.0, fOffsetLen);
417*cdf0e10cSrcweir 						rSliceVector.push_back(Slice3D(aOuterFront, aTransform, SLICETYPE3D_FRONTCAP));
418*cdf0e10cSrcweir 					}
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 					if(bCloseBack)
421*cdf0e10cSrcweir 					{
422*cdf0e10cSrcweir 						const double fOffsetLen((fAverageLength / 12.0) * fDiagonal);
423*cdf0e10cSrcweir 						impGetOuterPolyPolygon(aBack, aOuterBack, fOffsetLen, bCharacterMode);
424*cdf0e10cSrcweir 						aTransformBack.translate(0.0, 0.0, -fOffsetLen);
425*cdf0e10cSrcweir 						aTransformBack.rotate(0.0, fRotation, 0.0);
426*cdf0e10cSrcweir 					}
427*cdf0e10cSrcweir 				}
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 				// add start polygon (a = 0L)
430*cdf0e10cSrcweir 				if(!bClosedRotation)
431*cdf0e10cSrcweir 				{
432*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aFront, basegfx::B3DHomMatrix()));
433*cdf0e10cSrcweir 				}
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 				// create segments (a + 1 .. nSteps)
436*cdf0e10cSrcweir 				const double fStepSize(1.0 / (double)nSteps);
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 				for(sal_uInt32 a(0L); a < nSteps; a++)
439*cdf0e10cSrcweir 				{
440*cdf0e10cSrcweir 					const double fStep((double)(a + 1L) * fStepSize);
441*cdf0e10cSrcweir 					basegfx::B2DPolyPolygon aNewPoly(bBackScale ? basegfx::tools::interpolate(aFront, aBack, fStep) : aFront);
442*cdf0e10cSrcweir 					basegfx::B3DHomMatrix aNewMat;
443*cdf0e10cSrcweir 					aNewMat.rotate(0.0, fRotation * fStep, 0.0);
444*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aNewPoly, aNewMat));
445*cdf0e10cSrcweir 				}
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 				if(bCloseBack)
448*cdf0e10cSrcweir 				{
449*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aOuterBack, aTransformBack, SLICETYPE3D_BACKCAP));
450*cdf0e10cSrcweir 				}
451*cdf0e10cSrcweir 			}
452*cdf0e10cSrcweir 		}
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 		void createExtrudeSlices(
455*cdf0e10cSrcweir 			Slice3DVector& rSliceVector,
456*cdf0e10cSrcweir 			const basegfx::B2DPolyPolygon& rSource,
457*cdf0e10cSrcweir 			double fBackScale,
458*cdf0e10cSrcweir 			double fDiagonal,
459*cdf0e10cSrcweir 			double fDepth,
460*cdf0e10cSrcweir 			bool bCharacterMode,
461*cdf0e10cSrcweir 			bool bCloseFront,
462*cdf0e10cSrcweir 			bool bCloseBack)
463*cdf0e10cSrcweir 		{
464*cdf0e10cSrcweir 			if(basegfx::fTools::equalZero(fDepth))
465*cdf0e10cSrcweir 			{
466*cdf0e10cSrcweir 				// no depth, just one plane
467*cdf0e10cSrcweir 				rSliceVector.push_back(Slice3D(rSource, basegfx::B3DHomMatrix()));
468*cdf0e10cSrcweir 			}
469*cdf0e10cSrcweir 			else
470*cdf0e10cSrcweir 			{
471*cdf0e10cSrcweir 				// there is depth, create Polygons for front,back and their default depth positions
472*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aFront(rSource);
473*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aBack(rSource);
474*cdf0e10cSrcweir 				const bool bBackScale(!basegfx::fTools::equal(fBackScale, 1.0));
475*cdf0e10cSrcweir 				double fZFront(fDepth); // default depth for aFront
476*cdf0e10cSrcweir 				double fZBack(0.0); // default depth for aBack
477*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aOuterBack;
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 				if(bBackScale)
480*cdf0e10cSrcweir 				{
481*cdf0e10cSrcweir 					// avoid null zoom
482*cdf0e10cSrcweir 					if(basegfx::fTools::equalZero(fBackScale))
483*cdf0e10cSrcweir 					{
484*cdf0e10cSrcweir 						fBackScale = 0.000001;
485*cdf0e10cSrcweir 					}
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 					// aFront is scaled compared to aBack, create scaled version
488*cdf0e10cSrcweir 					aFront = impScalePolyPolygonOnCenter(aFront, fBackScale);
489*cdf0e10cSrcweir 				}
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 				if(bCloseFront)
492*cdf0e10cSrcweir 				{
493*cdf0e10cSrcweir 					const double fOffset(fDepth * fDiagonal * 0.5);
494*cdf0e10cSrcweir 					fZFront = fDepth - fOffset;
495*cdf0e10cSrcweir 					basegfx::B2DPolyPolygon aOuterFront;
496*cdf0e10cSrcweir 					impGetOuterPolyPolygon(aFront, aOuterFront, fOffset, bCharacterMode);
497*cdf0e10cSrcweir 					basegfx::B3DHomMatrix aTransformFront;
498*cdf0e10cSrcweir 					aTransformFront.translate(0.0, 0.0, fDepth);
499*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aOuterFront, aTransformFront, SLICETYPE3D_FRONTCAP));
500*cdf0e10cSrcweir 				}
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 				if(bCloseBack)
503*cdf0e10cSrcweir 				{
504*cdf0e10cSrcweir 					const double fOffset(fDepth * fDiagonal * 0.5);
505*cdf0e10cSrcweir 					fZBack = fOffset;
506*cdf0e10cSrcweir 					impGetOuterPolyPolygon(aBack, aOuterBack, fOffset, bCharacterMode);
507*cdf0e10cSrcweir 				}
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 				// add front and back polygons at evtl. changed depths
510*cdf0e10cSrcweir 				{
511*cdf0e10cSrcweir 					basegfx::B3DHomMatrix aTransformA, aTransformB;
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 					aTransformA.translate(0.0, 0.0, fZFront);
514*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aFront, aTransformA));
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 					aTransformB.translate(0.0, 0.0, fZBack);
517*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aBack, aTransformB));
518*cdf0e10cSrcweir 				}
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 				if(bCloseBack)
521*cdf0e10cSrcweir 				{
522*cdf0e10cSrcweir 					rSliceVector.push_back(Slice3D(aOuterBack, basegfx::B3DHomMatrix(), SLICETYPE3D_BACKCAP));
523*cdf0e10cSrcweir 				}
524*cdf0e10cSrcweir 			}
525*cdf0e10cSrcweir 		}
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon extractHorizontalLinesFromSlice(const Slice3DVector& rSliceVector, bool bCloseHorLines)
528*cdf0e10cSrcweir 		{
529*cdf0e10cSrcweir 			basegfx::B3DPolyPolygon aRetval;
530*cdf0e10cSrcweir 			const sal_uInt32 nNumSlices(rSliceVector.size());
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 			if(nNumSlices)
533*cdf0e10cSrcweir 			{
534*cdf0e10cSrcweir 				const sal_uInt32 nSlideSubPolygonCount(rSliceVector[0].getB3DPolyPolygon().count());
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir 				for(sal_uInt32 b(0); b < nSlideSubPolygonCount; b++)
537*cdf0e10cSrcweir 				{
538*cdf0e10cSrcweir 					const sal_uInt32 nSubPolygonPointCount(rSliceVector[0].getB3DPolyPolygon().getB3DPolygon(b).count());
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir 					for(sal_uInt32 c(0); c < nSubPolygonPointCount; c++)
541*cdf0e10cSrcweir 					{
542*cdf0e10cSrcweir 						basegfx::B3DPolygon aNew;
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir 						for(sal_uInt32 d(0); d < nNumSlices; d++)
545*cdf0e10cSrcweir 						{
546*cdf0e10cSrcweir                             OSL_ENSURE(nSlideSubPolygonCount == rSliceVector[d].getB3DPolyPolygon().count(),
547*cdf0e10cSrcweir                                 "Slice PolyPolygon with different Polygon count (!)");
548*cdf0e10cSrcweir                             OSL_ENSURE(nSubPolygonPointCount == rSliceVector[d].getB3DPolyPolygon().getB3DPolygon(b).count(),
549*cdf0e10cSrcweir                                 "Slice Polygon with different point count (!)");
550*cdf0e10cSrcweir 							aNew.append(rSliceVector[d].getB3DPolyPolygon().getB3DPolygon(b).getB3DPoint(c));
551*cdf0e10cSrcweir 						}
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 						aNew.setClosed(bCloseHorLines);
554*cdf0e10cSrcweir 						aRetval.append(aNew);
555*cdf0e10cSrcweir 					}
556*cdf0e10cSrcweir 				}
557*cdf0e10cSrcweir 			}
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 			return aRetval;
560*cdf0e10cSrcweir 		}
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 		basegfx::B3DPolyPolygon  extractVerticalLinesFromSlice(const Slice3DVector& rSliceVector)
563*cdf0e10cSrcweir 		{
564*cdf0e10cSrcweir 			basegfx::B3DPolyPolygon aRetval;
565*cdf0e10cSrcweir 			const sal_uInt32 nNumSlices(rSliceVector.size());
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 		    for(sal_uInt32 a(0L); a < nNumSlices; a++)
568*cdf0e10cSrcweir 		    {
569*cdf0e10cSrcweir 			    aRetval.append(rSliceVector[a].getB3DPolyPolygon());
570*cdf0e10cSrcweir 		    }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 			return aRetval;
573*cdf0e10cSrcweir 		}
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 		void extractPlanesFromSlice(
576*cdf0e10cSrcweir 			::std::vector< basegfx::B3DPolyPolygon >& rFill,
577*cdf0e10cSrcweir 			const Slice3DVector& rSliceVector,
578*cdf0e10cSrcweir 			bool bCreateNormals,
579*cdf0e10cSrcweir 			bool bSmoothHorizontalNormals,
580*cdf0e10cSrcweir 			bool bSmoothNormals,
581*cdf0e10cSrcweir 			bool bSmoothLids,
582*cdf0e10cSrcweir 			bool bClosed,
583*cdf0e10cSrcweir 			double fSmoothNormalsMix,
584*cdf0e10cSrcweir 			double fSmoothLidsMix,
585*cdf0e10cSrcweir 			bool bCreateTextureCoordinates,
586*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTexTransform)
587*cdf0e10cSrcweir 		{
588*cdf0e10cSrcweir 			const sal_uInt32 nNumSlices(rSliceVector.size());
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 			if(nNumSlices)
591*cdf0e10cSrcweir 			{
592*cdf0e10cSrcweir 				// common parameters
593*cdf0e10cSrcweir 				const sal_uInt32 nLoopCount(bClosed ? nNumSlices : nNumSlices - 1L);
594*cdf0e10cSrcweir 				basegfx::B3DPolyPolygon aEdgeRounding;
595*cdf0e10cSrcweir 				sal_uInt32 a;
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 				// tetxture parameters
598*cdf0e10cSrcweir 				double fInvTexHeight(1.0);
599*cdf0e10cSrcweir 				double fTexHeightPos(0.0);
600*cdf0e10cSrcweir 				double fTexStart(0.0);
601*cdf0e10cSrcweir 				double fTexStop(1.0);
602*cdf0e10cSrcweir 				::std::vector<double> aTexHeightArray;
603*cdf0e10cSrcweir 				basegfx::B3DRange aTexRangeFront;
604*cdf0e10cSrcweir 				basegfx::B3DRange aTexRangeBack;
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 				if(bCreateTextureCoordinates)
607*cdf0e10cSrcweir 				{
608*cdf0e10cSrcweir 					aTexRangeFront = basegfx::tools::getRange(rSliceVector[0L].getB3DPolyPolygon());
609*cdf0e10cSrcweir 					aTexRangeBack = basegfx::tools::getRange(rSliceVector[nNumSlices - 1L].getB3DPolyPolygon());
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 					if(aTexRangeBack.getDepth() > aTexRangeBack.getWidth())
612*cdf0e10cSrcweir 					{
613*cdf0e10cSrcweir 						// last polygon is rotated so that depth is bigger than width, exchange X and Z
614*cdf0e10cSrcweir 						// for making applyDefaultTextureCoordinatesParallel use Z instead of X for
615*cdf0e10cSrcweir 						// horizontal texture coordinate
616*cdf0e10cSrcweir 						aTexRangeBack = basegfx::B3DRange(
617*cdf0e10cSrcweir 							aTexRangeBack.getMinZ(), aTexRangeBack.getMinY(), aTexRangeBack.getMinX(),
618*cdf0e10cSrcweir 							aTexRangeBack.getMaxZ(), aTexRangeBack.getMaxY(), aTexRangeBack.getMaxX());
619*cdf0e10cSrcweir 					}
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 					basegfx::B3DPoint aCenter(basegfx::tools::getRange(rSliceVector[0L].getB3DPolyPolygon()).getCenter());
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir 					for(a = 0L; a < nLoopCount; a++)
624*cdf0e10cSrcweir 					{
625*cdf0e10cSrcweir 						const basegfx::B3DPoint aNextCenter(basegfx::tools::getRange(rSliceVector[(a + 1L) % nNumSlices].getB3DPolyPolygon()).getCenter());
626*cdf0e10cSrcweir 						const double fLength(basegfx::B3DVector(aNextCenter - aCenter).getLength());
627*cdf0e10cSrcweir 						aTexHeightArray.push_back(fLength);
628*cdf0e10cSrcweir 						aCenter = aNextCenter;
629*cdf0e10cSrcweir 					}
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir 					const double fTexHeight(::std::accumulate(aTexHeightArray.begin(), aTexHeightArray.end(), 0.0));
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 					if(!basegfx::fTools::equalZero(fTexHeight))
634*cdf0e10cSrcweir 					{
635*cdf0e10cSrcweir 						fInvTexHeight = 1.0 / fTexHeight;
636*cdf0e10cSrcweir 					}
637*cdf0e10cSrcweir 				}
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir                 if(nLoopCount)
640*cdf0e10cSrcweir                 {
641*cdf0e10cSrcweir 				    for(a = 0L; a < nLoopCount; a++)
642*cdf0e10cSrcweir 				    {
643*cdf0e10cSrcweir 					    const Slice3D& rSliceA(rSliceVector[a]);
644*cdf0e10cSrcweir 					    const Slice3D& rSliceB(rSliceVector[(a + 1L) % nNumSlices]);
645*cdf0e10cSrcweir 					    const bool bAcceptPair(SLICETYPE3D_REGULAR == rSliceA.getSliceType() && SLICETYPE3D_REGULAR == rSliceB.getSliceType());
646*cdf0e10cSrcweir 					    basegfx::B3DPolyPolygon aPolA(rSliceA.getB3DPolyPolygon());
647*cdf0e10cSrcweir 					    basegfx::B3DPolyPolygon aPolB(rSliceB.getB3DPolyPolygon());
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir 					    if(bAcceptPair)
650*cdf0e10cSrcweir 					    {
651*cdf0e10cSrcweir 						    if(bCreateNormals)
652*cdf0e10cSrcweir 						    {
653*cdf0e10cSrcweir 							    impCreateInBetweenNormals(aPolB, aPolA, bSmoothHorizontalNormals);
654*cdf0e10cSrcweir 						    }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 						    {
657*cdf0e10cSrcweir 							    const sal_uInt32 nIndPrev((a + nNumSlices - 1L) % nNumSlices);
658*cdf0e10cSrcweir 							    const Slice3D& rSlicePrev(rSliceVector[nIndPrev]);
659*cdf0e10cSrcweir 							    basegfx::B3DPolyPolygon aPrev(rSlicePrev.getB3DPolyPolygon());
660*cdf0e10cSrcweir 							    basegfx::B3DPolyPolygon aPolAA(rSliceA.getB3DPolyPolygon());
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir 							    if(SLICETYPE3D_FRONTCAP == rSlicePrev.getSliceType())
663*cdf0e10cSrcweir 							    {
664*cdf0e10cSrcweir 								    basegfx::B3DPolyPolygon aFront(rSlicePrev.getB3DPolyPolygon());
665*cdf0e10cSrcweir 								    const bool bHasSlant(aPolAA != aPrev);
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir 								    if(bCreateTextureCoordinates)
668*cdf0e10cSrcweir 								    {
669*cdf0e10cSrcweir 									    aFront = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFront, aTexRangeFront);
670*cdf0e10cSrcweir 								    }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 								    if(bCreateNormals)
673*cdf0e10cSrcweir 								    {
674*cdf0e10cSrcweir 									    basegfx::B3DVector aNormal(0.0, 0.0, -1.0);
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir 									    if(aFront.count())
677*cdf0e10cSrcweir 									    {
678*cdf0e10cSrcweir 										    aNormal = -aFront.getB3DPolygon(0L).getNormal();
679*cdf0e10cSrcweir 									    }
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 									    impSetNormal(aFront, aNormal);
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 									    if(bHasSlant)
684*cdf0e10cSrcweir 									    {
685*cdf0e10cSrcweir 										    impCreateInBetweenNormals(aPolAA, aPrev, bSmoothHorizontalNormals);
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 										    if(bSmoothNormals)
688*cdf0e10cSrcweir 										    {
689*cdf0e10cSrcweir 											    // smooth and copy
690*cdf0e10cSrcweir 											    impMixNormals(aPolA, aPolAA, fSmoothNormalsMix);
691*cdf0e10cSrcweir 											    aPolAA = aPolA;
692*cdf0e10cSrcweir 										    }
693*cdf0e10cSrcweir 										    else
694*cdf0e10cSrcweir 										    {
695*cdf0e10cSrcweir 											    // take over from surface
696*cdf0e10cSrcweir 											    aPolAA = aPolA;
697*cdf0e10cSrcweir 										    }
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir 										    if(bSmoothLids)
700*cdf0e10cSrcweir 										    {
701*cdf0e10cSrcweir 											    // smooth and copy
702*cdf0e10cSrcweir 											    impMixNormals(aFront, aPrev, fSmoothLidsMix);
703*cdf0e10cSrcweir 											    aPrev = aFront;
704*cdf0e10cSrcweir 										    }
705*cdf0e10cSrcweir 										    else
706*cdf0e10cSrcweir 										    {
707*cdf0e10cSrcweir 											    // take over from front
708*cdf0e10cSrcweir 											    aPrev = aFront;
709*cdf0e10cSrcweir 										    }
710*cdf0e10cSrcweir 									    }
711*cdf0e10cSrcweir 									    else
712*cdf0e10cSrcweir 									    {
713*cdf0e10cSrcweir 										    if(bSmoothNormals)
714*cdf0e10cSrcweir 										    {
715*cdf0e10cSrcweir 											    // smooth
716*cdf0e10cSrcweir 											    impMixNormals(aPolA, aFront, fSmoothNormalsMix);
717*cdf0e10cSrcweir 										    }
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir 										    if(bSmoothLids)
720*cdf0e10cSrcweir 										    {
721*cdf0e10cSrcweir 											    // smooth and copy
722*cdf0e10cSrcweir 											    impMixNormals(aFront, aPolA, fSmoothLidsMix);
723*cdf0e10cSrcweir 											    aPolA = aFront;
724*cdf0e10cSrcweir 										    }
725*cdf0e10cSrcweir 									    }
726*cdf0e10cSrcweir 								    }
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir 								    if(bHasSlant)
729*cdf0e10cSrcweir 								    {
730*cdf0e10cSrcweir 									    if(bCreateTextureCoordinates)
731*cdf0e10cSrcweir 									    {
732*cdf0e10cSrcweir 										    fTexStart = fTexHeightPos * fInvTexHeight;
733*cdf0e10cSrcweir 										    fTexStop = (fTexHeightPos - aTexHeightArray[(a + nLoopCount - 1L) % nLoopCount]) * fInvTexHeight;
734*cdf0e10cSrcweir 									    }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir 									    impAddInBetweenFill(aEdgeRounding, aPolAA, aPrev, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates);
737*cdf0e10cSrcweir 								    }
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 								    aFront.flip();
740*cdf0e10cSrcweir 								    rFill.push_back(aFront);
741*cdf0e10cSrcweir 							    }
742*cdf0e10cSrcweir 							    else
743*cdf0e10cSrcweir 							    {
744*cdf0e10cSrcweir 								    if(bCreateNormals && bSmoothNormals && (nIndPrev != a + 1L))
745*cdf0e10cSrcweir 								    {
746*cdf0e10cSrcweir 									    impCreateInBetweenNormals(aPolAA, aPrev, bSmoothHorizontalNormals);
747*cdf0e10cSrcweir 									    impMixNormals(aPolA, aPolAA, 0.5);
748*cdf0e10cSrcweir 								    }
749*cdf0e10cSrcweir 							    }
750*cdf0e10cSrcweir 						    }
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir 						    {
753*cdf0e10cSrcweir 							    const sal_uInt32 nIndNext((a + 2L) % nNumSlices);
754*cdf0e10cSrcweir 							    const Slice3D& rSliceNext(rSliceVector[nIndNext]);
755*cdf0e10cSrcweir 							    basegfx::B3DPolyPolygon aNext(rSliceNext.getB3DPolyPolygon());
756*cdf0e10cSrcweir 							    basegfx::B3DPolyPolygon aPolBB(rSliceB.getB3DPolyPolygon());
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir 							    if(SLICETYPE3D_BACKCAP == rSliceNext.getSliceType())
759*cdf0e10cSrcweir 							    {
760*cdf0e10cSrcweir 								    basegfx::B3DPolyPolygon aBack(rSliceNext.getB3DPolyPolygon());
761*cdf0e10cSrcweir 								    const bool bHasSlant(aPolBB != aNext);
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir 								    if(bCreateTextureCoordinates)
764*cdf0e10cSrcweir 								    {
765*cdf0e10cSrcweir 									    aBack = basegfx::tools::applyDefaultTextureCoordinatesParallel(aBack, aTexRangeBack);
766*cdf0e10cSrcweir 								    }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir 								    if(bCreateNormals)
769*cdf0e10cSrcweir 								    {
770*cdf0e10cSrcweir 									    const basegfx::B3DVector aNormal(aBack.count() ? aBack.getB3DPolygon(0L).getNormal() : basegfx::B3DVector(0.0, 0.0, 1.0));
771*cdf0e10cSrcweir 									    impSetNormal(aBack, aNormal);
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir 									    if(bHasSlant)
774*cdf0e10cSrcweir 									    {
775*cdf0e10cSrcweir 										    impCreateInBetweenNormals(aNext, aPolBB, bSmoothHorizontalNormals);
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 										    if(bSmoothNormals)
778*cdf0e10cSrcweir 										    {
779*cdf0e10cSrcweir 											    // smooth and copy
780*cdf0e10cSrcweir 											    impMixNormals(aPolB, aPolBB, fSmoothNormalsMix);
781*cdf0e10cSrcweir 											    aPolBB = aPolB;
782*cdf0e10cSrcweir 										    }
783*cdf0e10cSrcweir 										    else
784*cdf0e10cSrcweir 										    {
785*cdf0e10cSrcweir 											    // take over from surface
786*cdf0e10cSrcweir 											    aPolBB = aPolB;
787*cdf0e10cSrcweir 										    }
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 										    if(bSmoothLids)
790*cdf0e10cSrcweir 										    {
791*cdf0e10cSrcweir 											    // smooth and copy
792*cdf0e10cSrcweir 											    impMixNormals(aBack, aNext, fSmoothLidsMix);
793*cdf0e10cSrcweir 											    aNext = aBack;
794*cdf0e10cSrcweir 										    }
795*cdf0e10cSrcweir 										    else
796*cdf0e10cSrcweir 										    {
797*cdf0e10cSrcweir 											    // take over from back
798*cdf0e10cSrcweir 											    aNext = aBack;
799*cdf0e10cSrcweir 										    }
800*cdf0e10cSrcweir 									    }
801*cdf0e10cSrcweir 									    else
802*cdf0e10cSrcweir 									    {
803*cdf0e10cSrcweir 										    if(bSmoothNormals)
804*cdf0e10cSrcweir 										    {
805*cdf0e10cSrcweir 											    // smooth
806*cdf0e10cSrcweir 											    impMixNormals(aPolB, aBack, fSmoothNormalsMix);
807*cdf0e10cSrcweir 										    }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir 										    if(bSmoothLids)
810*cdf0e10cSrcweir 										    {
811*cdf0e10cSrcweir 											    // smooth and copy
812*cdf0e10cSrcweir 											    impMixNormals(aBack, aPolB, fSmoothLidsMix);
813*cdf0e10cSrcweir 											    aPolB = aBack;
814*cdf0e10cSrcweir 										    }
815*cdf0e10cSrcweir 									    }
816*cdf0e10cSrcweir 								    }
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir 								    if(bHasSlant)
819*cdf0e10cSrcweir 								    {
820*cdf0e10cSrcweir 									    if(bCreateTextureCoordinates)
821*cdf0e10cSrcweir 									    {
822*cdf0e10cSrcweir 										    fTexStart = (fTexHeightPos + aTexHeightArray[a] + aTexHeightArray[(a + 1L) % nLoopCount]) * fInvTexHeight;
823*cdf0e10cSrcweir 										    fTexStop = (fTexHeightPos + aTexHeightArray[a]) * fInvTexHeight;
824*cdf0e10cSrcweir 									    }
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir 									    impAddInBetweenFill(aEdgeRounding, aNext, aPolBB, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates);
827*cdf0e10cSrcweir 								    }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir 								    rFill.push_back(aBack);
830*cdf0e10cSrcweir 							    }
831*cdf0e10cSrcweir 							    else
832*cdf0e10cSrcweir 							    {
833*cdf0e10cSrcweir 								    if(bCreateNormals && bSmoothNormals && (nIndNext != a))
834*cdf0e10cSrcweir 								    {
835*cdf0e10cSrcweir 									    impCreateInBetweenNormals(aNext, aPolBB, bSmoothHorizontalNormals);
836*cdf0e10cSrcweir 									    impMixNormals(aPolB, aPolBB, 0.5);
837*cdf0e10cSrcweir 								    }
838*cdf0e10cSrcweir 							    }
839*cdf0e10cSrcweir 						    }
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir 						    if(bCreateTextureCoordinates)
842*cdf0e10cSrcweir 						    {
843*cdf0e10cSrcweir 							    fTexStart = (fTexHeightPos + aTexHeightArray[a]) * fInvTexHeight;
844*cdf0e10cSrcweir 							    fTexStop = fTexHeightPos * fInvTexHeight;
845*cdf0e10cSrcweir 						    }
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir 						    impAddInBetweenFill(aEdgeRounding, aPolB, aPolA, fTexStart, fTexStop, bCreateNormals, bCreateTextureCoordinates);
848*cdf0e10cSrcweir 					    }
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir 					    if(bCreateTextureCoordinates)
851*cdf0e10cSrcweir 					    {
852*cdf0e10cSrcweir 						    fTexHeightPos += aTexHeightArray[a];
853*cdf0e10cSrcweir 					    }
854*cdf0e10cSrcweir 				    }
855*cdf0e10cSrcweir                 }
856*cdf0e10cSrcweir                 else
857*cdf0e10cSrcweir                 {
858*cdf0e10cSrcweir                     // no loop, but a single slice (1 == nNumSlices), create a filling from the single
859*cdf0e10cSrcweir                     // front plane
860*cdf0e10cSrcweir 				    const Slice3D& rSlice(rSliceVector[0]);
861*cdf0e10cSrcweir                     basegfx::B3DPolyPolygon aFront(rSlice.getB3DPolyPolygon());
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir 				    if(bCreateTextureCoordinates)
864*cdf0e10cSrcweir 				    {
865*cdf0e10cSrcweir 					    aFront = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFront, aTexRangeFront);
866*cdf0e10cSrcweir 				    }
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 				    if(bCreateNormals)
869*cdf0e10cSrcweir 				    {
870*cdf0e10cSrcweir 					    basegfx::B3DVector aNormal(0.0, 0.0, -1.0);
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 					    if(aFront.count())
873*cdf0e10cSrcweir 					    {
874*cdf0e10cSrcweir 						    aNormal = -aFront.getB3DPolygon(0L).getNormal();
875*cdf0e10cSrcweir 					    }
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir 					    impSetNormal(aFront, aNormal);
878*cdf0e10cSrcweir 				    }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 				    aFront.flip();
881*cdf0e10cSrcweir 				    rFill.push_back(aFront);
882*cdf0e10cSrcweir                 }
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir 				if(bCreateTextureCoordinates)
885*cdf0e10cSrcweir 				{
886*cdf0e10cSrcweir 					aEdgeRounding.transformTextureCoordiantes(rTexTransform);
887*cdf0e10cSrcweir 				}
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir 				for(a = 0L; a < aEdgeRounding.count(); a++)
890*cdf0e10cSrcweir 				{
891*cdf0e10cSrcweir 					rFill.push_back(basegfx::B3DPolyPolygon(aEdgeRounding.getB3DPolygon(a)));
892*cdf0e10cSrcweir 				}
893*cdf0e10cSrcweir 			}
894*cdf0e10cSrcweir 		}
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir 		void createReducedOutlines(
897*cdf0e10cSrcweir 			const geometry::ViewInformation3D& rViewInformation,
898*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& rObjectTransform,
899*cdf0e10cSrcweir 			const basegfx::B3DPolygon& rLoopA,
900*cdf0e10cSrcweir 			const basegfx::B3DPolygon& rLoopB,
901*cdf0e10cSrcweir 			basegfx::B3DPolyPolygon& rTarget)
902*cdf0e10cSrcweir 		{
903*cdf0e10cSrcweir 			const sal_uInt32 nPointCount(rLoopA.count());
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir 			// with idetic polygons there are no outlines
906*cdf0e10cSrcweir 			if(rLoopA != rLoopB)
907*cdf0e10cSrcweir 			{
908*cdf0e10cSrcweir 				if(nPointCount && nPointCount == rLoopB.count())
909*cdf0e10cSrcweir 				{
910*cdf0e10cSrcweir 					const basegfx::B3DHomMatrix aObjectTransform(rViewInformation.getObjectToView() * rObjectTransform);
911*cdf0e10cSrcweir 					const basegfx::B2DPolygon a2DLoopA(basegfx::tools::createB2DPolygonFromB3DPolygon(rLoopA, aObjectTransform));
912*cdf0e10cSrcweir 					const basegfx::B2DPolygon a2DLoopB(basegfx::tools::createB2DPolygonFromB3DPolygon(rLoopB, aObjectTransform));
913*cdf0e10cSrcweir 					const basegfx::B2DPoint a2DCenterA(a2DLoopA.getB2DRange().getCenter());
914*cdf0e10cSrcweir 					const basegfx::B2DPoint a2DCenterB(a2DLoopB.getB2DRange().getCenter());
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir 					// without detectable Y-Axis there are no outlines
917*cdf0e10cSrcweir 					if(!a2DCenterA.equal(a2DCenterB))
918*cdf0e10cSrcweir 					{
919*cdf0e10cSrcweir 						// search for outmost left and right inter-loop-edges which do not cut the loops
920*cdf0e10cSrcweir 						const basegfx::B2DPoint aCommonCenter(basegfx::average(a2DCenterA, a2DCenterB));
921*cdf0e10cSrcweir 						const basegfx::B2DVector aAxisVector(a2DCenterA - a2DCenterB);
922*cdf0e10cSrcweir 						double fMaxLeft(0.0);
923*cdf0e10cSrcweir 						double fMaxRight(0.0);
924*cdf0e10cSrcweir 						sal_uInt32 nIndexLeft(0);
925*cdf0e10cSrcweir 						sal_uInt32 nIndexRight(0);
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir 						for(sal_uInt32 a(0); a < nPointCount; a++)
928*cdf0e10cSrcweir 						{
929*cdf0e10cSrcweir 							const basegfx::B2DPoint aStart(a2DLoopA.getB2DPoint(a));
930*cdf0e10cSrcweir 							const basegfx::B2DPoint aEnd(a2DLoopB.getB2DPoint(a));
931*cdf0e10cSrcweir 							const basegfx::B2DPoint aMiddle(basegfx::average(aStart, aEnd));
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir 							if(!basegfx::tools::isInside(a2DLoopA, aMiddle))
934*cdf0e10cSrcweir 							{
935*cdf0e10cSrcweir 								if(!basegfx::tools::isInside(a2DLoopB, aMiddle))
936*cdf0e10cSrcweir 								{
937*cdf0e10cSrcweir 									if(!impHasCutWith(a2DLoopA, aStart, aEnd))
938*cdf0e10cSrcweir 									{
939*cdf0e10cSrcweir 										if(!impHasCutWith(a2DLoopB, aStart, aEnd))
940*cdf0e10cSrcweir 										{
941*cdf0e10cSrcweir 											const basegfx::B2DVector aCandidateVector(aMiddle - aCommonCenter);
942*cdf0e10cSrcweir 											const double fCross(aCandidateVector.cross(aAxisVector));
943*cdf0e10cSrcweir 											const double fDistance(aCandidateVector.getLength());
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 											if(fCross > 0.0)
946*cdf0e10cSrcweir 											{
947*cdf0e10cSrcweir 												if(fDistance > fMaxLeft)
948*cdf0e10cSrcweir 												{
949*cdf0e10cSrcweir 													fMaxLeft = fDistance;
950*cdf0e10cSrcweir 													nIndexLeft = a;
951*cdf0e10cSrcweir 												}
952*cdf0e10cSrcweir 											}
953*cdf0e10cSrcweir 											else if(fCross < 0.0)
954*cdf0e10cSrcweir 											{
955*cdf0e10cSrcweir 												if(fDistance > fMaxRight)
956*cdf0e10cSrcweir 												{
957*cdf0e10cSrcweir 													fMaxRight = fDistance;
958*cdf0e10cSrcweir 													nIndexRight = a;
959*cdf0e10cSrcweir 												}
960*cdf0e10cSrcweir 											}
961*cdf0e10cSrcweir 										}
962*cdf0e10cSrcweir 									}
963*cdf0e10cSrcweir 								}
964*cdf0e10cSrcweir 							}
965*cdf0e10cSrcweir 						}
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir 						if(fMaxLeft != 0.0)
968*cdf0e10cSrcweir 						{
969*cdf0e10cSrcweir 							basegfx::B3DPolygon aToBeAdded;
970*cdf0e10cSrcweir 							aToBeAdded.append(rLoopA.getB3DPoint(nIndexLeft));
971*cdf0e10cSrcweir 							aToBeAdded.append(rLoopB.getB3DPoint(nIndexLeft));
972*cdf0e10cSrcweir 							rTarget.append(aToBeAdded);
973*cdf0e10cSrcweir 						}
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir 						if(fMaxRight != 0.0)
976*cdf0e10cSrcweir 						{
977*cdf0e10cSrcweir 							basegfx::B3DPolygon aToBeAdded;
978*cdf0e10cSrcweir 							aToBeAdded.append(rLoopA.getB3DPoint(nIndexRight));
979*cdf0e10cSrcweir 							aToBeAdded.append(rLoopB.getB3DPoint(nIndexRight));
980*cdf0e10cSrcweir 							rTarget.append(aToBeAdded);
981*cdf0e10cSrcweir 						}
982*cdf0e10cSrcweir 					}
983*cdf0e10cSrcweir 				}
984*cdf0e10cSrcweir 			}
985*cdf0e10cSrcweir 		}
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir 	} // end of namespace primitive3d
988*cdf0e10cSrcweir } // end of namespace drawinglayer
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
991*cdf0e10cSrcweir // eof
992