LCOV - code coverage report
Current view: top level - basegfx/inc/basegfx/raster - rasterconvert3d.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 87 77.0 %
Date: 2012-08-25 Functions: 23 31 74.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 30 56.7 %

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

Generated by: LCOV version 1.10