1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _BGFX_RASTER_RASTERCONVERT3D_HXX 29*cdf0e10cSrcweir #define _BGFX_RASTER_RASTERCONVERT3D_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sal/types.h> 32*cdf0e10cSrcweir #include <vector> 33*cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx> 34*cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx> 35*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 36*cdf0e10cSrcweir #include <basegfx/vector/b2dvector.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 39*cdf0e10cSrcweir // predeclarations 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace basegfx 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir class B3DPolygon; 44*cdf0e10cSrcweir class B3DPolyPolygon; 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 48*cdf0e10cSrcweir // interpolators for double precision 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace basegfx 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir class ip_single 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir private: 55*cdf0e10cSrcweir double mfVal; 56*cdf0e10cSrcweir double mfInc; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir public: 59*cdf0e10cSrcweir ip_single() 60*cdf0e10cSrcweir : mfVal(0.0), 61*cdf0e10cSrcweir mfInc(0.0) 62*cdf0e10cSrcweir {} 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir ip_single(double fVal, double fInc) 65*cdf0e10cSrcweir : mfVal(fVal), 66*cdf0e10cSrcweir mfInc(fInc) 67*cdf0e10cSrcweir {} 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir double getVal() const { return mfVal; } 70*cdf0e10cSrcweir double getInc() const { return mfInc; } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir void increment(double fStep) { mfVal += fStep * mfInc; } 73*cdf0e10cSrcweir }; 74*cdf0e10cSrcweir } // end of namespace basegfx 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir namespace basegfx 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir class ip_double 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir private: 81*cdf0e10cSrcweir ip_single maX; 82*cdf0e10cSrcweir ip_single maY; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir public: 85*cdf0e10cSrcweir ip_double() 86*cdf0e10cSrcweir : maX(), 87*cdf0e10cSrcweir maY() 88*cdf0e10cSrcweir {} 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir ip_double(double fXVal, double fXInc, double fYVal, double fYInc) 91*cdf0e10cSrcweir : maX(fXVal, fXInc), 92*cdf0e10cSrcweir maY(fYVal, fYInc) 93*cdf0e10cSrcweir {} 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir const ip_single& getX() const { return maX; } 96*cdf0e10cSrcweir const ip_single& getY() const { return maY; } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir void increment(double fStep) { maX.increment(fStep); maY.increment(fStep); } 99*cdf0e10cSrcweir }; 100*cdf0e10cSrcweir } // end of namespace basegfx 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir namespace basegfx 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir class ip_triple 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir private: 107*cdf0e10cSrcweir ip_single maX; 108*cdf0e10cSrcweir ip_single maY; 109*cdf0e10cSrcweir ip_single maZ; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir public: 112*cdf0e10cSrcweir ip_triple() 113*cdf0e10cSrcweir : maX(), 114*cdf0e10cSrcweir maY(), 115*cdf0e10cSrcweir maZ() 116*cdf0e10cSrcweir {} 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir ip_triple(double fXVal, double fXInc, double fYVal, double fYInc, double fZVal, double fZInc) 119*cdf0e10cSrcweir : maX(fXVal, fXInc), 120*cdf0e10cSrcweir maY(fYVal, fYInc), 121*cdf0e10cSrcweir maZ(fZVal, fZInc) 122*cdf0e10cSrcweir {} 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir const ip_single& getX() const { return maX; } 125*cdf0e10cSrcweir const ip_single& getY() const { return maY; } 126*cdf0e10cSrcweir const ip_single& getZ() const { return maZ; } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir void increment(double fStep) { maX.increment(fStep); maY.increment(fStep); maZ.increment(fStep); } 129*cdf0e10cSrcweir }; 130*cdf0e10cSrcweir } // end of namespace basegfx 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 133*cdf0e10cSrcweir // InterpolatorProvider3D to have a common source for allocating interpolators 134*cdf0e10cSrcweir // which may then be addressed using the index to the vectors 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir namespace basegfx 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir #define SCANLINE_EMPTY_INDEX (0xffffffff) 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir class InterpolatorProvider3D 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir private: 143*cdf0e10cSrcweir ::std::vector< ip_triple > maColorInterpolators; 144*cdf0e10cSrcweir ::std::vector< ip_triple > maNormalInterpolators; 145*cdf0e10cSrcweir ::std::vector< ip_double > maTextureInterpolators; 146*cdf0e10cSrcweir ::std::vector< ip_triple > maInverseTextureInterpolators; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir protected: 149*cdf0e10cSrcweir sal_uInt32 addColorInterpolator(const BColor& rA, const BColor& rB, double fInvYDelta) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir B3DVector aDelta(rB.getRed() - rA.getRed(), rB.getGreen() - rA.getGreen(), rB.getBlue() - rA.getBlue()); 152*cdf0e10cSrcweir aDelta *= fInvYDelta; 153*cdf0e10cSrcweir maColorInterpolators.push_back(ip_triple(rA.getRed(), aDelta.getX(), rA.getGreen(), aDelta.getY(), rA.getBlue(), aDelta.getZ())); 154*cdf0e10cSrcweir return (maColorInterpolators.size() - 1L); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir sal_uInt32 addNormalInterpolator(const B3DVector& rA, const B3DVector& rB, double fInvYDelta) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir B3DVector aDelta(rB.getX() - rA.getX(), rB.getY() - rA.getY(), rB.getZ() - rA.getZ()); 160*cdf0e10cSrcweir aDelta *= fInvYDelta; 161*cdf0e10cSrcweir maNormalInterpolators.push_back(ip_triple(rA.getX(), aDelta.getX(), rA.getY(), aDelta.getY(), rA.getZ(), aDelta.getZ())); 162*cdf0e10cSrcweir return (maNormalInterpolators.size() - 1L); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir sal_uInt32 addTextureInterpolator(const B2DPoint& rA, const B2DPoint& rB, double fInvYDelta) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir B2DVector aDelta(rB.getX() - rA.getX(), rB.getY() - rA.getY()); 168*cdf0e10cSrcweir aDelta *= fInvYDelta; 169*cdf0e10cSrcweir maTextureInterpolators.push_back(ip_double(rA.getX(), aDelta.getX(), rA.getY(), aDelta.getY())); 170*cdf0e10cSrcweir return (maTextureInterpolators.size() - 1L); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir sal_uInt32 addInverseTextureInterpolator(const B2DPoint& rA, const B2DPoint& rB, double fZEyeA, double fZEyeB, double fInvYDelta) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir const double fInvZEyeA(fTools::equalZero(fZEyeA) ? fZEyeA : 1.0 / fZEyeA); 176*cdf0e10cSrcweir const double fInvZEyeB(fTools::equalZero(fZEyeB) ? fZEyeB : 1.0 / fZEyeB); 177*cdf0e10cSrcweir const B2DPoint aInvA(rA * fInvZEyeA); 178*cdf0e10cSrcweir const B2DPoint aInvB(rB * fInvZEyeB); 179*cdf0e10cSrcweir double fZDelta(fInvZEyeB - fInvZEyeA); 180*cdf0e10cSrcweir B2DVector aDelta(aInvB.getX() - aInvA.getX(), aInvB.getY() - aInvA.getY()); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir fZDelta *= fInvYDelta; 183*cdf0e10cSrcweir aDelta *= fInvYDelta; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir maInverseTextureInterpolators.push_back(ip_triple(aInvA.getX(), aDelta.getX(), aInvA.getY(), aDelta.getY(), fInvZEyeA, fZDelta)); 186*cdf0e10cSrcweir return (maInverseTextureInterpolators.size() - 1L); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir void reset() 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir maColorInterpolators.clear(); 192*cdf0e10cSrcweir maNormalInterpolators.clear(); 193*cdf0e10cSrcweir maTextureInterpolators.clear(); 194*cdf0e10cSrcweir maInverseTextureInterpolators.clear(); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir public: 198*cdf0e10cSrcweir InterpolatorProvider3D() {} 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir ::std::vector< ip_triple >& getColorInterpolators() { return maColorInterpolators; } 201*cdf0e10cSrcweir ::std::vector< ip_triple >& getNormalInterpolators() { return maNormalInterpolators; } 202*cdf0e10cSrcweir ::std::vector< ip_double >& getTextureInterpolators() { return maTextureInterpolators; } 203*cdf0e10cSrcweir ::std::vector< ip_triple >& getInverseTextureInterpolators() { return maInverseTextureInterpolators; } 204*cdf0e10cSrcweir }; 205*cdf0e10cSrcweir } // end of namespace basegfx 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 208*cdf0e10cSrcweir // RasterConversionLineEntry3D for Raterconversion of 3D PolyPolygons 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir namespace basegfx 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir class RasterConversionLineEntry3D 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir private: 215*cdf0e10cSrcweir ip_single maX; 216*cdf0e10cSrcweir ip_single maZ; 217*cdf0e10cSrcweir sal_Int32 mnY; 218*cdf0e10cSrcweir sal_uInt32 mnCount; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir sal_uInt32 mnColorIndex; 221*cdf0e10cSrcweir sal_uInt32 mnNormalIndex; 222*cdf0e10cSrcweir sal_uInt32 mnTextureIndex; 223*cdf0e10cSrcweir sal_uInt32 mnInverseTextureIndex; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir public: 226*cdf0e10cSrcweir RasterConversionLineEntry3D(const double& rfX, const double& rfDeltaX, const double& rfZ, const double& rfDeltaZ, sal_Int32 nY, sal_uInt32 nCount) 227*cdf0e10cSrcweir : maX(rfX, rfDeltaX), 228*cdf0e10cSrcweir maZ(rfZ, rfDeltaZ), 229*cdf0e10cSrcweir mnY(nY), 230*cdf0e10cSrcweir mnCount(nCount), 231*cdf0e10cSrcweir mnColorIndex(SCANLINE_EMPTY_INDEX), 232*cdf0e10cSrcweir mnNormalIndex(SCANLINE_EMPTY_INDEX), 233*cdf0e10cSrcweir mnTextureIndex(SCANLINE_EMPTY_INDEX), 234*cdf0e10cSrcweir mnInverseTextureIndex(SCANLINE_EMPTY_INDEX) 235*cdf0e10cSrcweir {} 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir void setColorIndex(sal_uInt32 nIndex) { mnColorIndex = nIndex; } 238*cdf0e10cSrcweir void setNormalIndex(sal_uInt32 nIndex) { mnNormalIndex = nIndex; } 239*cdf0e10cSrcweir void setTextureIndex(sal_uInt32 nIndex) { mnTextureIndex = nIndex; } 240*cdf0e10cSrcweir void setInverseTextureIndex(sal_uInt32 nIndex) { mnInverseTextureIndex = nIndex; } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir bool operator<(const RasterConversionLineEntry3D& rComp) const 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir if(mnY == rComp.mnY) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir return maX.getVal() < rComp.maX.getVal(); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir return mnY < rComp.mnY; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir bool decrementRasterConversionLineEntry3D(sal_uInt32 nStep) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir if(nStep >= mnCount) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir return false; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir else 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir mnCount -= nStep; 261*cdf0e10cSrcweir return true; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void incrementRasterConversionLineEntry3D(sal_uInt32 nStep, InterpolatorProvider3D& rProvider) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir const double fStep((double)nStep); 268*cdf0e10cSrcweir maX.increment(fStep); 269*cdf0e10cSrcweir maZ.increment(fStep); 270*cdf0e10cSrcweir mnY += nStep; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if(SCANLINE_EMPTY_INDEX != mnColorIndex) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir rProvider.getColorInterpolators()[mnColorIndex].increment(fStep); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir if(SCANLINE_EMPTY_INDEX != mnNormalIndex) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir rProvider.getNormalInterpolators()[mnNormalIndex].increment(fStep); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if(SCANLINE_EMPTY_INDEX != mnTextureIndex) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir rProvider.getTextureInterpolators()[mnTextureIndex].increment(fStep); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir if(SCANLINE_EMPTY_INDEX != mnInverseTextureIndex) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir rProvider.getInverseTextureInterpolators()[mnInverseTextureIndex].increment(fStep); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir // data read access 294*cdf0e10cSrcweir const ip_single& getX() const { return maX; } 295*cdf0e10cSrcweir sal_Int32 getY() const { return mnY; } 296*cdf0e10cSrcweir const ip_single& getZ() const { return maZ; } 297*cdf0e10cSrcweir sal_uInt32 getColorIndex() const { return mnColorIndex; } 298*cdf0e10cSrcweir sal_uInt32 getNormalIndex() const { return mnNormalIndex; } 299*cdf0e10cSrcweir sal_uInt32 getTextureIndex() const { return mnTextureIndex; } 300*cdf0e10cSrcweir sal_uInt32 getInverseTextureIndex() const { return mnInverseTextureIndex; } 301*cdf0e10cSrcweir }; 302*cdf0e10cSrcweir } // end of namespace basegfx 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 305*cdf0e10cSrcweir // the basic RaterConverter itself. Only one method needs to be overloaded. The 306*cdf0e10cSrcweir // class itself is strictly virtual 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir namespace basegfx 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir class RasterConverter3D : public InterpolatorProvider3D 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir private: 313*cdf0e10cSrcweir // the line entries for an area conversion run 314*cdf0e10cSrcweir ::std::vector< RasterConversionLineEntry3D > maLineEntries; 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir struct lineComparator 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir bool operator()(const RasterConversionLineEntry3D* pA, const RasterConversionLineEntry3D* pB) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir OSL_ENSURE(pA && pB, "lineComparator: empty pointer (!)"); 321*cdf0e10cSrcweir return pA->getX().getVal() < pB->getX().getVal(); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir }; 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir void addArea(const B3DPolygon& rFill, const B3DHomMatrix* pViewToEye); 326*cdf0e10cSrcweir void addArea(const B3DPolyPolygon& rFill, const B3DHomMatrix* pViewToEye); 327*cdf0e10cSrcweir void addEdge(const B3DPolygon& rFill, sal_uInt32 a, sal_uInt32 b, const B3DHomMatrix* pViewToEye); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir void rasterconvertB3DArea(sal_Int32 nStartLine, sal_Int32 nStopLine); 330*cdf0e10cSrcweir void rasterconvertB3DEdge(const B3DPolygon& rLine, sal_uInt32 nA, sal_uInt32 nB, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir virtual void processLineSpan(const RasterConversionLineEntry3D& rA, const RasterConversionLineEntry3D& rB, sal_Int32 nLine, sal_uInt32 nSpanCount) = 0; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir public: 335*cdf0e10cSrcweir RasterConverter3D(); 336*cdf0e10cSrcweir virtual ~RasterConverter3D(); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir void rasterconvertB3DPolyPolygon(const B3DPolyPolygon& rFill, const B3DHomMatrix* pViewToEye, sal_Int32 nStartLine, sal_Int32 nStopLine); 339*cdf0e10cSrcweir void rasterconvertB3DPolygon(const B3DPolygon& rLine, sal_Int32 nStartLine, sal_Int32 nStopLine, sal_uInt16 nLineWidth); 340*cdf0e10cSrcweir }; 341*cdf0e10cSrcweir } // end of namespace basegfx 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir #endif /* _BGFX_RASTER_RASTERCONVERT3D_HXX */ 346