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