109dbbe93SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 309dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 409dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file 509dbbe93SAndrew Rist * distributed with this work for additional information 609dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file 709dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the 809dbbe93SAndrew Rist * "License"); you may not use this file except in compliance 909dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1109dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1309dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing, 1409dbbe93SAndrew Rist * software distributed under the License is distributed on an 1509dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1609dbbe93SAndrew Rist * KIND, either express or implied. See the License for the 1709dbbe93SAndrew Rist * specific language governing permissions and limitations 1809dbbe93SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2009dbbe93SAndrew Rist *************************************************************/ 2109dbbe93SAndrew Rist 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 241f882ec4SArmin Le Grand 25cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx> 26cdf0e10cSrcweir #include <basegfx/range/b3drange.hxx> 27cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygon.hxx> 28cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx> 29cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygontools.hxx> 30cdf0e10cSrcweir #include <numeric> 31cdf0e10cSrcweir #include <basegfx/matrix/b3dhommatrix.hxx> 32cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 33cdf0e10cSrcweir #include <osl/mutex.hxx> 341f882ec4SArmin Le Grand #include <com/sun/star/drawing/DoubleSequence.hpp> 35cdf0e10cSrcweir 365aaf853bSArmin Le Grand // predefines 375aaf853bSArmin Le Grand #define nMinSegments sal_uInt32(1) 385aaf853bSArmin Le Grand #define nMaxSegments sal_uInt32(512) 395aaf853bSArmin Le Grand 40cdf0e10cSrcweir namespace basegfx 41cdf0e10cSrcweir { 42cdf0e10cSrcweir namespace tools 43cdf0e10cSrcweir { 44cdf0e10cSrcweir // B3DPolyPolygon tools getRange(const B3DPolyPolygon & rCandidate)45cdf0e10cSrcweir B3DRange getRange(const B3DPolyPolygon& rCandidate) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir B3DRange aRetval; 48cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 49cdf0e10cSrcweir 50cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); 53cdf0e10cSrcweir aRetval.expand(getRange(aCandidate)); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir return aRetval; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir applyLineDashing(const B3DPolyPolygon & rCandidate,const::std::vector<double> & rDotDashArray,B3DPolyPolygon * pLineTarget,B3DPolyPolygon * pGapTarget,double fFullDashDotLen)59cdf0e10cSrcweir void applyLineDashing(const B3DPolyPolygon& rCandidate, const ::std::vector<double>& rDotDashArray, B3DPolyPolygon* pLineTarget, B3DPolyPolygon* pGapTarget, double fFullDashDotLen) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir if(0.0 == fFullDashDotLen && rDotDashArray.size()) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir // calculate fFullDashDotLen from rDotDashArray 64cdf0e10cSrcweir fFullDashDotLen = ::std::accumulate(rDotDashArray.begin(), rDotDashArray.end(), 0.0); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir if(rCandidate.count() && fFullDashDotLen > 0.0) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir B3DPolyPolygon aLineTarget, aGapTarget; 70cdf0e10cSrcweir 71cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir const B3DPolygon aCandidate(rCandidate.getB3DPolygon(a)); 74cdf0e10cSrcweir 75cdf0e10cSrcweir applyLineDashing( 76cdf0e10cSrcweir aCandidate, 77cdf0e10cSrcweir rDotDashArray, 78cdf0e10cSrcweir pLineTarget ? &aLineTarget : 0, 79cdf0e10cSrcweir pGapTarget ? &aGapTarget : 0, 80cdf0e10cSrcweir fFullDashDotLen); 81cdf0e10cSrcweir 82cdf0e10cSrcweir if(pLineTarget) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir pLineTarget->append(aLineTarget); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir if(pGapTarget) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir pGapTarget->append(aGapTarget); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir createUnitCubePolyPolygon()95cdf0e10cSrcweir B3DPolyPolygon createUnitCubePolyPolygon() 96cdf0e10cSrcweir { 97cdf0e10cSrcweir static B3DPolyPolygon aRetval; 98cdf0e10cSrcweir ::osl::Mutex m_mutex; 99cdf0e10cSrcweir 100cdf0e10cSrcweir if(!aRetval.count()) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir B3DPolygon aTemp; 103cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 0.0, 1.0)); 104cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 1.0, 1.0)); 105cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 1.0, 1.0)); 106cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 0.0, 1.0)); 107cdf0e10cSrcweir aTemp.setClosed(true); 108cdf0e10cSrcweir aRetval.append(aTemp); 109cdf0e10cSrcweir 110cdf0e10cSrcweir aTemp.clear(); 111cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 0.0, 0.0)); 112cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 1.0, 0.0)); 113cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 1.0, 0.0)); 114cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 0.0, 0.0)); 115cdf0e10cSrcweir aTemp.setClosed(true); 116cdf0e10cSrcweir aRetval.append(aTemp); 117cdf0e10cSrcweir 118cdf0e10cSrcweir aTemp.clear(); 119cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 0.0, 0.0)); 120cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 0.0, 1.0)); 121cdf0e10cSrcweir aRetval.append(aTemp); 122cdf0e10cSrcweir 123cdf0e10cSrcweir aTemp.clear(); 124cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 1.0, 0.0)); 125cdf0e10cSrcweir aTemp.append(B3DPoint(0.0, 1.0, 1.0)); 126cdf0e10cSrcweir aRetval.append(aTemp); 127cdf0e10cSrcweir 128cdf0e10cSrcweir aTemp.clear(); 129cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 1.0, 0.0)); 130cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 1.0, 1.0)); 131cdf0e10cSrcweir aRetval.append(aTemp); 132cdf0e10cSrcweir 133cdf0e10cSrcweir aTemp.clear(); 134cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 0.0, 0.0)); 135cdf0e10cSrcweir aTemp.append(B3DPoint(1.0, 0.0, 1.0)); 136cdf0e10cSrcweir aRetval.append(aTemp); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir return aRetval; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir createUnitCubeFillPolyPolygon()142cdf0e10cSrcweir B3DPolyPolygon createUnitCubeFillPolyPolygon() 143cdf0e10cSrcweir { 144cdf0e10cSrcweir static B3DPolyPolygon aRetval; 145cdf0e10cSrcweir ::osl::Mutex m_mutex; 146cdf0e10cSrcweir 147cdf0e10cSrcweir if(!aRetval.count()) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir B3DPolygon aTemp; 150cdf0e10cSrcweir 151cdf0e10cSrcweir // all points 152cdf0e10cSrcweir const B3DPoint A(0.0, 0.0, 0.0); 153cdf0e10cSrcweir const B3DPoint B(0.0, 1.0, 0.0); 154cdf0e10cSrcweir const B3DPoint C(1.0, 1.0, 0.0); 155cdf0e10cSrcweir const B3DPoint D(1.0, 0.0, 0.0); 156cdf0e10cSrcweir const B3DPoint E(0.0, 0.0, 1.0); 157cdf0e10cSrcweir const B3DPoint F(0.0, 1.0, 1.0); 158cdf0e10cSrcweir const B3DPoint G(1.0, 1.0, 1.0); 159cdf0e10cSrcweir const B3DPoint H(1.0, 0.0, 1.0); 160cdf0e10cSrcweir 161cdf0e10cSrcweir // create bottom 162cdf0e10cSrcweir aTemp.append(D); 163cdf0e10cSrcweir aTemp.append(A); 164cdf0e10cSrcweir aTemp.append(E); 165cdf0e10cSrcweir aTemp.append(H); 166cdf0e10cSrcweir aTemp.setClosed(true); 167cdf0e10cSrcweir aRetval.append(aTemp); 168cdf0e10cSrcweir 169cdf0e10cSrcweir // create front 170cdf0e10cSrcweir aTemp.clear(); 171cdf0e10cSrcweir aTemp.append(B); 172cdf0e10cSrcweir aTemp.append(A); 173cdf0e10cSrcweir aTemp.append(D); 174cdf0e10cSrcweir aTemp.append(C); 175cdf0e10cSrcweir aTemp.setClosed(true); 176cdf0e10cSrcweir aRetval.append(aTemp); 177cdf0e10cSrcweir 178cdf0e10cSrcweir // create left 179cdf0e10cSrcweir aTemp.clear(); 180cdf0e10cSrcweir aTemp.append(E); 181cdf0e10cSrcweir aTemp.append(A); 182cdf0e10cSrcweir aTemp.append(B); 183cdf0e10cSrcweir aTemp.append(F); 184cdf0e10cSrcweir aTemp.setClosed(true); 185cdf0e10cSrcweir aRetval.append(aTemp); 186cdf0e10cSrcweir 187cdf0e10cSrcweir // create top 188cdf0e10cSrcweir aTemp.clear(); 189cdf0e10cSrcweir aTemp.append(C); 190cdf0e10cSrcweir aTemp.append(G); 191cdf0e10cSrcweir aTemp.append(F); 192cdf0e10cSrcweir aTemp.append(B); 193cdf0e10cSrcweir aTemp.setClosed(true); 194cdf0e10cSrcweir aRetval.append(aTemp); 195cdf0e10cSrcweir 196cdf0e10cSrcweir // create right 197cdf0e10cSrcweir aTemp.clear(); 198cdf0e10cSrcweir aTemp.append(H); 199cdf0e10cSrcweir aTemp.append(G); 200cdf0e10cSrcweir aTemp.append(C); 201cdf0e10cSrcweir aTemp.append(D); 202cdf0e10cSrcweir aTemp.setClosed(true); 203cdf0e10cSrcweir aRetval.append(aTemp); 204cdf0e10cSrcweir 205cdf0e10cSrcweir // create back 206cdf0e10cSrcweir aTemp.clear(); 207cdf0e10cSrcweir aTemp.append(F); 208cdf0e10cSrcweir aTemp.append(G); 209cdf0e10cSrcweir aTemp.append(H); 210cdf0e10cSrcweir aTemp.append(E); 211cdf0e10cSrcweir aTemp.setClosed(true); 212cdf0e10cSrcweir aRetval.append(aTemp); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir return aRetval; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir createCubePolyPolygonFromB3DRange(const B3DRange & rRange)218cdf0e10cSrcweir B3DPolyPolygon createCubePolyPolygonFromB3DRange( const B3DRange& rRange) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir B3DPolyPolygon aRetval; 221cdf0e10cSrcweir 222cdf0e10cSrcweir if(!rRange.isEmpty()) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir aRetval = createUnitCubePolyPolygon(); 225cdf0e10cSrcweir B3DHomMatrix aTrans; 226cdf0e10cSrcweir aTrans.scale(rRange.getWidth(), rRange.getHeight(), rRange.getDepth()); 227cdf0e10cSrcweir aTrans.translate(rRange.getMinX(), rRange.getMinY(), rRange.getMinZ()); 228cdf0e10cSrcweir aRetval.transform(aTrans); 229cdf0e10cSrcweir aRetval.removeDoublePoints(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir return aRetval; 233cdf0e10cSrcweir } 234cdf0e10cSrcweir createCubeFillPolyPolygonFromB3DRange(const B3DRange & rRange)235cdf0e10cSrcweir B3DPolyPolygon createCubeFillPolyPolygonFromB3DRange( const B3DRange& rRange) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir B3DPolyPolygon aRetval; 238cdf0e10cSrcweir 239cdf0e10cSrcweir if(!rRange.isEmpty()) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir aRetval = createUnitCubeFillPolyPolygon(); 242cdf0e10cSrcweir B3DHomMatrix aTrans; 243cdf0e10cSrcweir aTrans.scale(rRange.getWidth(), rRange.getHeight(), rRange.getDepth()); 244cdf0e10cSrcweir aTrans.translate(rRange.getMinX(), rRange.getMinY(), rRange.getMinZ()); 245cdf0e10cSrcweir aRetval.transform(aTrans); 246cdf0e10cSrcweir aRetval.removeDoublePoints(); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir return aRetval; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252*1fd21976Smseidel // helper for getting the 3D Point from given cartesian coordinates. fVer is defined from 253cdf0e10cSrcweir // [F_PI2 .. -F_PI2], fHor from [0.0 .. F_2PI] getPointFromCartesian(double fVer,double fHor)254cdf0e10cSrcweir inline B3DPoint getPointFromCartesian(double fVer, double fHor) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir const double fCosHor(cos(fHor)); 257cdf0e10cSrcweir return B3DPoint(fCosHor * cos(fVer), sin(fHor), fCosHor * -sin(fVer)); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir createUnitSpherePolyPolygon(sal_uInt32 nHorSeg,sal_uInt32 nVerSeg,double fVerStart,double fVerStop,double fHorStart,double fHorStop)260cdf0e10cSrcweir B3DPolyPolygon createUnitSpherePolyPolygon( 261cdf0e10cSrcweir sal_uInt32 nHorSeg, sal_uInt32 nVerSeg, 262cdf0e10cSrcweir double fVerStart, double fVerStop, 263cdf0e10cSrcweir double fHorStart, double fHorStop) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir B3DPolyPolygon aRetval; 266cdf0e10cSrcweir sal_uInt32 a, b; 267cdf0e10cSrcweir 268cdf0e10cSrcweir if(!nHorSeg) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir nHorSeg = fround(fabs(fHorStop - fHorStart) / (F_2PI / 24.0)); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 2735aaf853bSArmin Le Grand // min/max limitations 2745aaf853bSArmin Le Grand nHorSeg = ::std::min(nMaxSegments, ::std::max(nMinSegments, nHorSeg)); 275cdf0e10cSrcweir 276cdf0e10cSrcweir if(!nVerSeg) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir nVerSeg = fround(fabs(fVerStop - fVerStart) / (F_2PI / 24.0)); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 2815aaf853bSArmin Le Grand // min/max limitations 2825aaf853bSArmin Le Grand nVerSeg = ::std::min(nMaxSegments, ::std::max(nMinSegments, nVerSeg)); 283cdf0e10cSrcweir 284cdf0e10cSrcweir // create constants 285cdf0e10cSrcweir const double fVerDiffPerStep((fVerStop - fVerStart) / (double)nVerSeg); 286cdf0e10cSrcweir const double fHorDiffPerStep((fHorStop - fHorStart) / (double)nHorSeg); 287cdf0e10cSrcweir bool bHorClosed(fTools::equal(fHorStop - fHorStart, F_2PI)); 288cdf0e10cSrcweir bool bVerFromTop(fTools::equal(fVerStart, F_PI2)); 289cdf0e10cSrcweir bool bVerToBottom(fTools::equal(fVerStop, -F_PI2)); 290cdf0e10cSrcweir 291cdf0e10cSrcweir // create horizontal rings 292cdf0e10cSrcweir const sal_uInt32 nLoopVerInit(bVerFromTop ? 1L : 0L); 293cdf0e10cSrcweir const sal_uInt32 nLoopVerLimit(bVerToBottom ? nVerSeg : nVerSeg + 1L); 294cdf0e10cSrcweir const sal_uInt32 nLoopHorLimit(bHorClosed ? nHorSeg : nHorSeg + 1L); 295cdf0e10cSrcweir 296cdf0e10cSrcweir for(a = nLoopVerInit; a < nLoopVerLimit; a++) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir const double fVer(fVerStart + ((double)(a) * fVerDiffPerStep)); 299cdf0e10cSrcweir B3DPolygon aNew; 300cdf0e10cSrcweir 301cdf0e10cSrcweir for(b = 0L; b < nLoopHorLimit; b++) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir const double fHor(fHorStart + ((double)(b) * fHorDiffPerStep)); 304cdf0e10cSrcweir aNew.append(getPointFromCartesian(fHor, fVer)); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir aNew.setClosed(bHorClosed); 308cdf0e10cSrcweir aRetval.append(aNew); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir // create vertical half-rings 312cdf0e10cSrcweir for(a = 0L; a < nLoopHorLimit; a++) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir const double fHor(fHorStart + ((double)(a) * fHorDiffPerStep)); 315cdf0e10cSrcweir B3DPolygon aNew; 316cdf0e10cSrcweir 317cdf0e10cSrcweir if(bVerFromTop) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir aNew.append(B3DPoint(0.0, 1.0, 0.0)); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir for(b = nLoopVerInit; b < nLoopVerLimit; b++) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir const double fVer(fVerStart + ((double)(b) * fVerDiffPerStep)); 325cdf0e10cSrcweir aNew.append(getPointFromCartesian(fHor, fVer)); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir if(bVerToBottom) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir aNew.append(B3DPoint(0.0, -1.0, 0.0)); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir aRetval.append(aNew); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir return aRetval; 337cdf0e10cSrcweir } 338cdf0e10cSrcweir createSpherePolyPolygonFromB3DRange(const B3DRange & rRange,sal_uInt32 nHorSeg,sal_uInt32 nVerSeg,double fVerStart,double fVerStop,double fHorStart,double fHorStop)339cdf0e10cSrcweir B3DPolyPolygon createSpherePolyPolygonFromB3DRange( const B3DRange& rRange, 340cdf0e10cSrcweir sal_uInt32 nHorSeg, sal_uInt32 nVerSeg, 341cdf0e10cSrcweir double fVerStart, double fVerStop, 342cdf0e10cSrcweir double fHorStart, double fHorStop) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir B3DPolyPolygon aRetval(createUnitSpherePolyPolygon(nHorSeg, nVerSeg, fVerStart, fVerStop, fHorStart, fHorStop)); 345cdf0e10cSrcweir 346cdf0e10cSrcweir if(aRetval.count()) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir // move and scale whole construct which is now in [-1.0 .. 1.0] in all directions 349cdf0e10cSrcweir B3DHomMatrix aTrans; 350cdf0e10cSrcweir aTrans.translate(1.0, 1.0, 1.0); 351cdf0e10cSrcweir aTrans.scale(rRange.getWidth() / 2.0, rRange.getHeight() / 2.0, rRange.getDepth() / 2.0); 352cdf0e10cSrcweir aTrans.translate(rRange.getMinX(), rRange.getMinY(), rRange.getMinZ()); 353cdf0e10cSrcweir aRetval.transform(aTrans); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir return aRetval; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir createUnitSphereFillPolyPolygon(sal_uInt32 nHorSeg,sal_uInt32 nVerSeg,bool bNormals,double fVerStart,double fVerStop,double fHorStart,double fHorStop)359cdf0e10cSrcweir B3DPolyPolygon createUnitSphereFillPolyPolygon( 360cdf0e10cSrcweir sal_uInt32 nHorSeg, sal_uInt32 nVerSeg, 361cdf0e10cSrcweir bool bNormals, 362cdf0e10cSrcweir double fVerStart, double fVerStop, 363cdf0e10cSrcweir double fHorStart, double fHorStop) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir B3DPolyPolygon aRetval; 366cdf0e10cSrcweir 367cdf0e10cSrcweir if(!nHorSeg) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir nHorSeg = fround(fabs(fHorStop - fHorStart) / (F_2PI / 24.0)); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 3725aaf853bSArmin Le Grand // min/max limitations 3735aaf853bSArmin Le Grand nHorSeg = ::std::min(nMaxSegments, ::std::max(nMinSegments, nHorSeg)); 374cdf0e10cSrcweir 375cdf0e10cSrcweir if(!nVerSeg) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir nVerSeg = fround(fabs(fVerStop - fVerStart) / (F_2PI / 24.0)); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 3805aaf853bSArmin Le Grand // min/max limitations 3815aaf853bSArmin Le Grand nVerSeg = ::std::min(nMaxSegments, ::std::max(nMinSegments, nVerSeg)); 382cdf0e10cSrcweir 383cdf0e10cSrcweir // vertical loop 384cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nVerSeg; a++) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir const double fVer(fVerStart + (((fVerStop - fVerStart) * a) / nVerSeg)); 387cdf0e10cSrcweir const double fVer2(fVerStart + (((fVerStop - fVerStart) * (a + 1)) / nVerSeg)); 388cdf0e10cSrcweir 389cdf0e10cSrcweir // horizontal loop 390cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nHorSeg; b++) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir const double fHor(fHorStart + (((fHorStop - fHorStart) * b) / nHorSeg)); 393cdf0e10cSrcweir const double fHor2(fHorStart + (((fHorStop - fHorStart) * (b + 1)) / nHorSeg)); 394cdf0e10cSrcweir B3DPolygon aNew; 395cdf0e10cSrcweir 396cdf0e10cSrcweir aNew.append(getPointFromCartesian(fHor, fVer)); 397cdf0e10cSrcweir aNew.append(getPointFromCartesian(fHor2, fVer)); 398cdf0e10cSrcweir aNew.append(getPointFromCartesian(fHor2, fVer2)); 399cdf0e10cSrcweir aNew.append(getPointFromCartesian(fHor, fVer2)); 400cdf0e10cSrcweir 401cdf0e10cSrcweir if(bNormals) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir for(sal_uInt32 c(0L); c < aNew.count(); c++) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir aNew.setNormal(c, ::basegfx::B3DVector(aNew.getB3DPoint(c))); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir aNew.setClosed(true); 410cdf0e10cSrcweir aRetval.append(aNew); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir return aRetval; 415cdf0e10cSrcweir } 416cdf0e10cSrcweir createSphereFillPolyPolygonFromB3DRange(const B3DRange & rRange,sal_uInt32 nHorSeg,sal_uInt32 nVerSeg,bool bNormals,double fVerStart,double fVerStop,double fHorStart,double fHorStop)417cdf0e10cSrcweir B3DPolyPolygon createSphereFillPolyPolygonFromB3DRange( const B3DRange& rRange, 418cdf0e10cSrcweir sal_uInt32 nHorSeg, sal_uInt32 nVerSeg, 419cdf0e10cSrcweir bool bNormals, 420cdf0e10cSrcweir double fVerStart, double fVerStop, 421cdf0e10cSrcweir double fHorStart, double fHorStop) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir B3DPolyPolygon aRetval(createUnitSphereFillPolyPolygon(nHorSeg, nVerSeg, bNormals, fVerStart, fVerStop, fHorStart, fHorStop)); 424cdf0e10cSrcweir 425cdf0e10cSrcweir if(aRetval.count()) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir // move and scale whole construct which is now in [-1.0 .. 1.0] in all directions 428cdf0e10cSrcweir B3DHomMatrix aTrans; 429cdf0e10cSrcweir aTrans.translate(1.0, 1.0, 1.0); 430cdf0e10cSrcweir aTrans.scale(rRange.getWidth() / 2.0, rRange.getHeight() / 2.0, rRange.getDepth() / 2.0); 431cdf0e10cSrcweir aTrans.translate(rRange.getMinX(), rRange.getMinY(), rRange.getMinZ()); 432cdf0e10cSrcweir aRetval.transform(aTrans); 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir return aRetval; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir applyDefaultNormalsSphere(const B3DPolyPolygon & rCandidate,const B3DPoint & rCenter)438cdf0e10cSrcweir B3DPolyPolygon applyDefaultNormalsSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter) 439cdf0e10cSrcweir { 440cdf0e10cSrcweir B3DPolyPolygon aRetval; 441cdf0e10cSrcweir 442cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir aRetval.append(applyDefaultNormalsSphere(rCandidate.getB3DPolygon(a), rCenter)); 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir return aRetval; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir invertNormals(const B3DPolyPolygon & rCandidate)450cdf0e10cSrcweir B3DPolyPolygon invertNormals( const B3DPolyPolygon& rCandidate) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir B3DPolyPolygon aRetval; 453cdf0e10cSrcweir 454cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir aRetval.append(invertNormals(rCandidate.getB3DPolygon(a))); 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir return aRetval; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir applyDefaultTextureCoordinatesParallel(const B3DPolyPolygon & rCandidate,const B3DRange & rRange,bool bChangeX,bool bChangeY)462cdf0e10cSrcweir B3DPolyPolygon applyDefaultTextureCoordinatesParallel( const B3DPolyPolygon& rCandidate, const B3DRange& rRange, bool bChangeX, bool bChangeY) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir B3DPolyPolygon aRetval; 465cdf0e10cSrcweir 466cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir aRetval.append(applyDefaultTextureCoordinatesParallel(rCandidate.getB3DPolygon(a), rRange, bChangeX, bChangeY)); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir return aRetval; 472cdf0e10cSrcweir } 473cdf0e10cSrcweir applyDefaultTextureCoordinatesSphere(const B3DPolyPolygon & rCandidate,const B3DPoint & rCenter,bool bChangeX,bool bChangeY)474cdf0e10cSrcweir B3DPolyPolygon applyDefaultTextureCoordinatesSphere( const B3DPolyPolygon& rCandidate, const B3DPoint& rCenter, bool bChangeX, bool bChangeY) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir B3DPolyPolygon aRetval; 477cdf0e10cSrcweir 478cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir aRetval.append(applyDefaultTextureCoordinatesSphere(rCandidate.getB3DPolygon(a), rCenter, bChangeX, bChangeY)); 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir return aRetval; 484cdf0e10cSrcweir } 485cdf0e10cSrcweir isInside(const B3DPolyPolygon & rCandidate,const B3DPoint & rPoint,bool bWithBorder)486cdf0e10cSrcweir bool isInside(const B3DPolyPolygon& rCandidate, const B3DPoint& rPoint, bool bWithBorder) 487cdf0e10cSrcweir { 488cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 489cdf0e10cSrcweir 490cdf0e10cSrcweir if(1L == nPolygonCount) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir return isInside(rCandidate.getB3DPolygon(0), rPoint, bWithBorder); 493cdf0e10cSrcweir } 494cdf0e10cSrcweir else 495cdf0e10cSrcweir { 496cdf0e10cSrcweir sal_Int32 nInsideCount(0); 497cdf0e10cSrcweir 498cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPolygonCount; a++) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir const B3DPolygon aPolygon(rCandidate.getB3DPolygon(a)); 501cdf0e10cSrcweir const bool bInside(isInside(aPolygon, rPoint, bWithBorder)); 502cdf0e10cSrcweir 503cdf0e10cSrcweir if(bInside) 504cdf0e10cSrcweir { 505cdf0e10cSrcweir nInsideCount++; 506cdf0e10cSrcweir } 507cdf0e10cSrcweir } 508cdf0e10cSrcweir 509cdf0e10cSrcweir return (nInsideCount % 2L); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir // comparators with tolerance for 3D PolyPolygons 514cdf0e10cSrcweir equal(const B3DPolyPolygon & rCandidateA,const B3DPolyPolygon & rCandidateB,const double & rfSmallValue)515cdf0e10cSrcweir bool equal(const B3DPolyPolygon& rCandidateA, const B3DPolyPolygon& rCandidateB, const double& rfSmallValue) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidateA.count()); 518cdf0e10cSrcweir 519cdf0e10cSrcweir if(nPolygonCount != rCandidateB.count()) 520cdf0e10cSrcweir return false; 521cdf0e10cSrcweir 522cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPolygonCount; a++) 523cdf0e10cSrcweir { 524cdf0e10cSrcweir const B3DPolygon aCandidate(rCandidateA.getB3DPolygon(a)); 525cdf0e10cSrcweir 526cdf0e10cSrcweir if(!equal(aCandidate, rCandidateB.getB3DPolygon(a), rfSmallValue)) 527cdf0e10cSrcweir return false; 528cdf0e10cSrcweir } 529cdf0e10cSrcweir 530cdf0e10cSrcweir return true; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir equal(const B3DPolyPolygon & rCandidateA,const B3DPolyPolygon & rCandidateB)533cdf0e10cSrcweir bool equal(const B3DPolyPolygon& rCandidateA, const B3DPolyPolygon& rCandidateB) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir const double fSmallValue(fTools::getSmallValue()); 536cdf0e10cSrcweir 537cdf0e10cSrcweir return equal(rCandidateA, rCandidateB, fSmallValue); 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540*1fd21976Smseidel // converters for com::sun::star::drawing::PolyPolygonShape3D UnoPolyPolygonShape3DToB3DPolyPolygon(const com::sun::star::drawing::PolyPolygonShape3D & rPolyPolygonShape3DSource,bool bCheckClosed)5411f882ec4SArmin Le Grand B3DPolyPolygon UnoPolyPolygonShape3DToB3DPolyPolygon( 5421f882ec4SArmin Le Grand const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygonShape3DSource, 5431f882ec4SArmin Le Grand bool bCheckClosed) 5441f882ec4SArmin Le Grand { 5451f882ec4SArmin Le Grand B3DPolyPolygon aRetval; 5461f882ec4SArmin Le Grand const sal_Int32 nOuterSequenceCount(rPolyPolygonShape3DSource.SequenceX.getLength()); 5471f882ec4SArmin Le Grand 5481f882ec4SArmin Le Grand if(nOuterSequenceCount) 5491f882ec4SArmin Le Grand { 5501f882ec4SArmin Le Grand OSL_ENSURE(nOuterSequenceCount == rPolyPolygonShape3DSource.SequenceY.getLength() 5511f882ec4SArmin Le Grand && nOuterSequenceCount == rPolyPolygonShape3DSource.SequenceZ.getLength(), 5521f882ec4SArmin Le Grand "UnoPolyPolygonShape3DToB3DPolygon: Not all double sequences have the same length (!)"); 5531f882ec4SArmin Le Grand 5541f882ec4SArmin Le Grand const com::sun::star::drawing::DoubleSequence* pInnerSequenceX = rPolyPolygonShape3DSource.SequenceX.getConstArray(); 5551f882ec4SArmin Le Grand const com::sun::star::drawing::DoubleSequence* pInnerSequenceY = rPolyPolygonShape3DSource.SequenceY.getConstArray(); 5561f882ec4SArmin Le Grand const com::sun::star::drawing::DoubleSequence* pInnerSequenceZ = rPolyPolygonShape3DSource.SequenceZ.getConstArray(); 5571f882ec4SArmin Le Grand 5581f882ec4SArmin Le Grand for(sal_Int32 a(0); a < nOuterSequenceCount; a++) 5591f882ec4SArmin Le Grand { 5601f882ec4SArmin Le Grand basegfx::B3DPolygon aNewPolygon; 5611f882ec4SArmin Le Grand const sal_Int32 nInnerSequenceCount(pInnerSequenceX->getLength()); 5621f882ec4SArmin Le Grand OSL_ENSURE(nInnerSequenceCount == pInnerSequenceY->getLength() 5631f882ec4SArmin Le Grand && nInnerSequenceCount == pInnerSequenceZ->getLength(), 5641f882ec4SArmin Le Grand "UnoPolyPolygonShape3DToB3DPolygon: Not all double sequences have the same length (!)"); 5651f882ec4SArmin Le Grand 5661f882ec4SArmin Le Grand const double* pArrayX = pInnerSequenceX->getConstArray(); 5671f882ec4SArmin Le Grand const double* pArrayY = pInnerSequenceY->getConstArray(); 5681f882ec4SArmin Le Grand const double* pArrayZ = pInnerSequenceZ->getConstArray(); 5691f882ec4SArmin Le Grand 5701f882ec4SArmin Le Grand for(sal_Int32 b(0); b < nInnerSequenceCount; b++) 5711f882ec4SArmin Le Grand { 5721f882ec4SArmin Le Grand aNewPolygon.append(basegfx::B3DPoint(*pArrayX++,*pArrayY++,*pArrayZ++)); 5731f882ec4SArmin Le Grand } 5741f882ec4SArmin Le Grand 5751f882ec4SArmin Le Grand pInnerSequenceX++; 5761f882ec4SArmin Le Grand pInnerSequenceY++; 5771f882ec4SArmin Le Grand pInnerSequenceZ++; 5781f882ec4SArmin Le Grand 5791f882ec4SArmin Le Grand // #i101520# correction is needed for imported polygons of old format, 5801f882ec4SArmin Le Grand // see callers 5811f882ec4SArmin Le Grand if(bCheckClosed) 5821f882ec4SArmin Le Grand { 5831f882ec4SArmin Le Grand basegfx::tools::checkClosed(aNewPolygon); 5841f882ec4SArmin Le Grand } 5851f882ec4SArmin Le Grand 5861f882ec4SArmin Le Grand aRetval.append(aNewPolygon); 5871f882ec4SArmin Le Grand } 5881f882ec4SArmin Le Grand } 5891f882ec4SArmin Le Grand 5901f882ec4SArmin Le Grand return aRetval; 5911f882ec4SArmin Le Grand } 5921f882ec4SArmin Le Grand B3DPolyPolygonToUnoPolyPolygonShape3D(const B3DPolyPolygon & rPolyPolygonSource,com::sun::star::drawing::PolyPolygonShape3D & rPolyPolygonShape3DRetval)5931f882ec4SArmin Le Grand void B3DPolyPolygonToUnoPolyPolygonShape3D( 5941f882ec4SArmin Le Grand const B3DPolyPolygon& rPolyPolygonSource, 5951f882ec4SArmin Le Grand com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygonShape3DRetval) 5961f882ec4SArmin Le Grand { 5971f882ec4SArmin Le Grand const sal_uInt32 nPolygonCount(rPolyPolygonSource.count()); 5981f882ec4SArmin Le Grand 5991f882ec4SArmin Le Grand if(nPolygonCount) 6001f882ec4SArmin Le Grand { 6011f882ec4SArmin Le Grand rPolyPolygonShape3DRetval.SequenceX.realloc(nPolygonCount); 6021f882ec4SArmin Le Grand rPolyPolygonShape3DRetval.SequenceY.realloc(nPolygonCount); 6031f882ec4SArmin Le Grand rPolyPolygonShape3DRetval.SequenceZ.realloc(nPolygonCount); 6041f882ec4SArmin Le Grand 6051f882ec4SArmin Le Grand com::sun::star::drawing::DoubleSequence* pOuterSequenceX = rPolyPolygonShape3DRetval.SequenceX.getArray(); 6061f882ec4SArmin Le Grand com::sun::star::drawing::DoubleSequence* pOuterSequenceY = rPolyPolygonShape3DRetval.SequenceY.getArray(); 6071f882ec4SArmin Le Grand com::sun::star::drawing::DoubleSequence* pOuterSequenceZ = rPolyPolygonShape3DRetval.SequenceZ.getArray(); 6081f882ec4SArmin Le Grand 6091f882ec4SArmin Le Grand for(sal_uInt32 a(0); a < nPolygonCount; a++) 6101f882ec4SArmin Le Grand { 6111f882ec4SArmin Le Grand const basegfx::B3DPolygon aPoly(rPolyPolygonSource.getB3DPolygon(a)); 6121f882ec4SArmin Le Grand const sal_uInt32 nPointCount(aPoly.count()); 6131f882ec4SArmin Le Grand 6141f882ec4SArmin Le Grand if(nPointCount) 6151f882ec4SArmin Le Grand { 6161f882ec4SArmin Le Grand const bool bIsClosed(aPoly.isClosed()); 6171f882ec4SArmin Le Grand const sal_uInt32 nTargetCount(bIsClosed ? nPointCount + 1 : nPointCount); 6181f882ec4SArmin Le Grand pOuterSequenceX->realloc(nTargetCount); 6191f882ec4SArmin Le Grand pOuterSequenceY->realloc(nTargetCount); 6201f882ec4SArmin Le Grand pOuterSequenceZ->realloc(nTargetCount); 6211f882ec4SArmin Le Grand 6221f882ec4SArmin Le Grand double* pInnerSequenceX = pOuterSequenceX->getArray(); 6231f882ec4SArmin Le Grand double* pInnerSequenceY = pOuterSequenceY->getArray(); 6241f882ec4SArmin Le Grand double* pInnerSequenceZ = pOuterSequenceZ->getArray(); 6251f882ec4SArmin Le Grand 6261f882ec4SArmin Le Grand for(sal_uInt32 b(0); b < nPointCount; b++) 6271f882ec4SArmin Le Grand { 6281f882ec4SArmin Le Grand const basegfx::B3DPoint aPoint(aPoly.getB3DPoint(b)); 6291f882ec4SArmin Le Grand 6301f882ec4SArmin Le Grand *pInnerSequenceX++ = aPoint.getX(); 6311f882ec4SArmin Le Grand *pInnerSequenceY++ = aPoint.getY(); 6321f882ec4SArmin Le Grand *pInnerSequenceZ++ = aPoint.getZ(); 6331f882ec4SArmin Le Grand } 6341f882ec4SArmin Le Grand 6351f882ec4SArmin Le Grand if(bIsClosed) 6361f882ec4SArmin Le Grand { 6371f882ec4SArmin Le Grand const basegfx::B3DPoint aPoint(aPoly.getB3DPoint(0)); 6381f882ec4SArmin Le Grand 6391f882ec4SArmin Le Grand *pInnerSequenceX++ = aPoint.getX(); 6401f882ec4SArmin Le Grand *pInnerSequenceY++ = aPoint.getY(); 6411f882ec4SArmin Le Grand *pInnerSequenceZ++ = aPoint.getZ(); 6421f882ec4SArmin Le Grand } 6431f882ec4SArmin Le Grand } 6441f882ec4SArmin Le Grand else 6451f882ec4SArmin Le Grand { 6461f882ec4SArmin Le Grand pOuterSequenceX->realloc(0); 6471f882ec4SArmin Le Grand pOuterSequenceY->realloc(0); 6481f882ec4SArmin Le Grand pOuterSequenceZ->realloc(0); 6491f882ec4SArmin Le Grand } 6501f882ec4SArmin Le Grand 6511f882ec4SArmin Le Grand pOuterSequenceX++; 6521f882ec4SArmin Le Grand pOuterSequenceY++; 6531f882ec4SArmin Le Grand pOuterSequenceZ++; 6541f882ec4SArmin Le Grand } 6551f882ec4SArmin Le Grand } 6561f882ec4SArmin Le Grand else 6571f882ec4SArmin Le Grand { 6581f882ec4SArmin Le Grand rPolyPolygonShape3DRetval.SequenceX.realloc(0); 6591f882ec4SArmin Le Grand rPolyPolygonShape3DRetval.SequenceY.realloc(0); 6601f882ec4SArmin Le Grand rPolyPolygonShape3DRetval.SequenceZ.realloc(0); 6611f882ec4SArmin Le Grand } 6621f882ec4SArmin Le Grand } 6631f882ec4SArmin Le Grand 664cdf0e10cSrcweir } // end of namespace tools 665cdf0e10cSrcweir } // end of namespace basegfx 666cdf0e10cSrcweir 667*1fd21976Smseidel /* vim: set noet sw=4 ts=4: */ 668