LCOV - code coverage report
Current view: top level - libreoffice/basegfx/inc/basegfx/raster - rasterconvert3d.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 87 0.0 %
Date: 2012-12-27 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10