LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/primitive3d - hatchtextureprimitive3d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 128 0.0 %
Date: 2012-12-27 Functions: 0 5 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             : #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
      21             : #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
      22             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      23             : #include <basegfx/polygon/b3dpolygon.hxx>
      24             : #include <basegfx/polygon/b2dpolygon.hxx>
      25             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      26             : #include <basegfx/range/b2drange.hxx>
      27             : #include <drawinglayer/texture/texture.hxx>
      28             : #include <basegfx/polygon/b2dpolygonclipper.hxx>
      29             : #include <basegfx/matrix/b3dhommatrix.hxx>
      30             : #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
      31             : #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
      32             : 
      33             : //////////////////////////////////////////////////////////////////////////////
      34             : 
      35             : using namespace com::sun::star;
      36             : 
      37             : //////////////////////////////////////////////////////////////////////////////
      38             : 
      39             : namespace drawinglayer
      40             : {
      41             :     namespace primitive3d
      42             :     {
      43           0 :         Primitive3DSequence HatchTexturePrimitive3D::impCreate3DDecomposition() const
      44             :         {
      45           0 :             Primitive3DSequence aRetval;
      46             : 
      47           0 :             if(getChildren().hasElements())
      48             :             {
      49           0 :                 const Primitive3DSequence aSource(getChildren());
      50           0 :                 const sal_uInt32 nSourceCount(aSource.getLength());
      51           0 :                 std::vector< Primitive3DReference > aDestination;
      52             : 
      53           0 :                 for(sal_uInt32 a(0); a < nSourceCount; a++)
      54             :                 {
      55             :                     // get reference
      56           0 :                     const Primitive3DReference xReference(aSource[a]);
      57             : 
      58           0 :                     if(xReference.is())
      59             :                     {
      60             :                         // try to cast to BasePrimitive2D implementation
      61           0 :                         const BasePrimitive3D* pBasePrimitive = dynamic_cast< const BasePrimitive3D* >(xReference.get());
      62             : 
      63           0 :                         if(pBasePrimitive)
      64             :                         {
      65             :                             // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
      66             :                             // not all content is needed, remove transparencies and ModifiedColorPrimitives
      67           0 :                             switch(pBasePrimitive->getPrimitive3DID())
      68             :                             {
      69             :                                 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
      70             :                                 {
      71             :                                     // polyPolygonMaterialPrimitive3D, check texturing and hatching
      72           0 :                                     const PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const PolyPolygonMaterialPrimitive3D& >(*pBasePrimitive);
      73           0 :                                     const basegfx::B3DPolyPolygon aFillPolyPolygon(rPrimitive.getB3DPolyPolygon());
      74             : 
      75           0 :                                     if(maHatch.isFillBackground())
      76             :                                     {
      77             :                                         // add original primitive for background
      78           0 :                                         aDestination.push_back(xReference);
      79             :                                     }
      80             : 
      81           0 :                                     if(aFillPolyPolygon.areTextureCoordinatesUsed())
      82             :                                     {
      83           0 :                                         const sal_uInt32 nPolyCount(aFillPolyPolygon.count());
      84           0 :                                         basegfx::B2DPolyPolygon aTexPolyPolygon;
      85           0 :                                         basegfx::B2DPoint a2N;
      86           0 :                                         basegfx::B2DVector a2X, a2Y;
      87           0 :                                         basegfx::B3DPoint a3N;
      88           0 :                                         basegfx::B3DVector a3X, a3Y;
      89           0 :                                         bool b2N(false), b2X(false), b2Y(false);
      90             : 
      91           0 :                                         for(sal_uInt32 b(0); b < nPolyCount; b++)
      92             :                                         {
      93           0 :                                             const basegfx::B3DPolygon aPartPoly(aFillPolyPolygon.getB3DPolygon(b));
      94           0 :                                             const sal_uInt32 nPointCount(aPartPoly.count());
      95           0 :                                             basegfx::B2DPolygon aTexPolygon;
      96             : 
      97           0 :                                             for(sal_uInt32 c(0); c < nPointCount; c++)
      98             :                                             {
      99           0 :                                                 const basegfx::B2DPoint a2Candidate(aPartPoly.getTextureCoordinate(c));
     100             : 
     101           0 :                                                 if(!b2N)
     102             :                                                 {
     103           0 :                                                     a2N = a2Candidate;
     104           0 :                                                     a3N = aPartPoly.getB3DPoint(c);
     105           0 :                                                     b2N = true;
     106             :                                                 }
     107           0 :                                                 else if(!b2X && !a2N.equal(a2Candidate))
     108             :                                                 {
     109           0 :                                                     a2X = a2Candidate - a2N;
     110           0 :                                                     a3X = aPartPoly.getB3DPoint(c) - a3N;
     111           0 :                                                     b2X = true;
     112             :                                                 }
     113           0 :                                                 else if(!b2Y && !a2N.equal(a2Candidate) && !a2X.equal(a2Candidate))
     114             :                                                 {
     115           0 :                                                     a2Y = a2Candidate - a2N;
     116             : 
     117           0 :                                                     const double fCross(a2X.cross(a2Y));
     118             : 
     119           0 :                                                     if(!basegfx::fTools::equalZero(fCross))
     120             :                                                     {
     121           0 :                                                         a3Y = aPartPoly.getB3DPoint(c) - a3N;
     122           0 :                                                         b2Y = true;
     123             :                                                     }
     124             :                                                 }
     125             : 
     126           0 :                                                 aTexPolygon.append(a2Candidate);
     127           0 :                                             }
     128             : 
     129           0 :                                             aTexPolygon.setClosed(true);
     130           0 :                                             aTexPolyPolygon.append(aTexPolygon);
     131           0 :                                         }
     132             : 
     133           0 :                                         if(b2N && b2X && b2Y)
     134             :                                         {
     135             :                                             // found two linearly independent 2D vectors
     136             :                                             // get 2d range of texture coordinates
     137           0 :                                             const basegfx::B2DRange aOutlineRange(basegfx::tools::getRange(aTexPolyPolygon));
     138           0 :                                             const basegfx::BColor aHatchColor(getHatch().getColor());
     139           0 :                                             const double fAngle(getHatch().getAngle());
     140           0 :                                             ::std::vector< basegfx::B2DHomMatrix > aMatrices;
     141             : 
     142             :                                             // get hatch transformations
     143           0 :                                             switch(getHatch().getStyle())
     144             :                                             {
     145             :                                                 case attribute::HATCHSTYLE_TRIPLE:
     146             :                                                 {
     147             :                                                     // rotated 45 degrees
     148           0 :                                                     texture::GeoTexSvxHatch aHatch(aOutlineRange, getHatch().getDistance(), fAngle - F_PI4);
     149           0 :                                                     aHatch.appendTransformations(aMatrices);
     150             :                                                 }
     151             :                                                 case attribute::HATCHSTYLE_DOUBLE:
     152             :                                                 {
     153             :                                                     // rotated 90 degrees
     154           0 :                                                     texture::GeoTexSvxHatch aHatch(aOutlineRange, getHatch().getDistance(), fAngle - F_PI2);
     155           0 :                                                     aHatch.appendTransformations(aMatrices);
     156             :                                                 }
     157             :                                                 case attribute::HATCHSTYLE_SINGLE:
     158             :                                                 {
     159             :                                                     // angle as given
     160           0 :                                                     texture::GeoTexSvxHatch aHatch(aOutlineRange, getHatch().getDistance(), fAngle);
     161           0 :                                                     aHatch.appendTransformations(aMatrices);
     162             :                                                 }
     163             :                                             }
     164             : 
     165             :                                             // create geometry from unit line
     166           0 :                                             basegfx::B2DPolyPolygon a2DHatchLines;
     167           0 :                                             basegfx::B2DPolygon a2DUnitLine;
     168           0 :                                             a2DUnitLine.append(basegfx::B2DPoint(0.0, 0.0));
     169           0 :                                             a2DUnitLine.append(basegfx::B2DPoint(1.0, 0.0));
     170             : 
     171           0 :                                             for(sal_uInt32 c(0); c < aMatrices.size(); c++)
     172             :                                             {
     173           0 :                                                 const basegfx::B2DHomMatrix& rMatrix = aMatrices[c];
     174           0 :                                                 basegfx::B2DPolygon aNewLine(a2DUnitLine);
     175           0 :                                                 aNewLine.transform(rMatrix);
     176           0 :                                                 a2DHatchLines.append(aNewLine);
     177           0 :                                             }
     178             : 
     179           0 :                                             if(a2DHatchLines.count())
     180             :                                             {
     181             :                                                 // clip against texture polygon
     182           0 :                                                 a2DHatchLines = basegfx::tools::clipPolyPolygonOnPolyPolygon(a2DHatchLines, aTexPolyPolygon, true, true);
     183             :                                             }
     184             : 
     185           0 :                                             if(a2DHatchLines.count())
     186             :                                             {
     187             :                                                 // create 2d matrix with 2d vectors as column vectors and 2d point as offset, this represents
     188             :                                                 // a coordinate system transformation from unit coordinates to the new coordinate system
     189           0 :                                                 basegfx::B2DHomMatrix a2D;
     190           0 :                                                 a2D.set(0, 0, a2X.getX());
     191           0 :                                                 a2D.set(1, 0, a2X.getY());
     192           0 :                                                 a2D.set(0, 1, a2Y.getX());
     193           0 :                                                 a2D.set(1, 1, a2Y.getY());
     194           0 :                                                 a2D.set(0, 2, a2N.getX());
     195           0 :                                                 a2D.set(1, 2, a2N.getY());
     196             : 
     197             :                                                 // invert that transformation, so we have a back-transformation from texture coordinates
     198             :                                                 // to unit coordinates
     199           0 :                                                 a2D.invert();
     200           0 :                                                 a2DHatchLines.transform(a2D);
     201             : 
     202             :                                                 // expand back-transformated geometry tpo 3D
     203           0 :                                                 basegfx::B3DPolyPolygon a3DHatchLines(basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(a2DHatchLines, 0.0));
     204             : 
     205             :                                                 // create 3d matrix with 3d vectors as column vectors (0,0,1 as Z) and 3d point as offset, this represents
     206             :                                                 // a coordinate system transformation from unit coordinates to the object's 3d coordinate system
     207           0 :                                                 basegfx::B3DHomMatrix a3D;
     208           0 :                                                 a3D.set(0, 0, a3X.getX());
     209           0 :                                                 a3D.set(1, 0, a3X.getY());
     210           0 :                                                 a3D.set(2, 0, a3X.getZ());
     211           0 :                                                 a3D.set(0, 1, a3Y.getX());
     212           0 :                                                 a3D.set(1, 1, a3Y.getY());
     213           0 :                                                 a3D.set(2, 1, a3Y.getZ());
     214           0 :                                                 a3D.set(0, 3, a3N.getX());
     215           0 :                                                 a3D.set(1, 3, a3N.getY());
     216           0 :                                                 a3D.set(2, 3, a3N.getZ());
     217             : 
     218             :                                                 // transform hatch lines to 3D object coordinates
     219           0 :                                                 a3DHatchLines.transform(a3D);
     220             : 
     221             :                                                 // build primitives from this geometry
     222           0 :                                                 const sal_uInt32 nHatchLines(a3DHatchLines.count());
     223             : 
     224           0 :                                                 for(sal_uInt32 d(0); d < nHatchLines; d++)
     225             :                                                 {
     226           0 :                                                     const Primitive3DReference xRef(new PolygonHairlinePrimitive3D(a3DHatchLines.getB3DPolygon(d), aHatchColor));
     227           0 :                                                     aDestination.push_back(xRef);
     228           0 :                                                 }
     229           0 :                                             }
     230           0 :                                         }
     231             :                                     }
     232             : 
     233           0 :                                     break;
     234             :                                 }
     235             :                                 default :
     236             :                                 {
     237             :                                     // add reference to result
     238           0 :                                     aDestination.push_back(xReference);
     239           0 :                                     break;
     240             :                                 }
     241             :                             }
     242             :                         }
     243             :                         else
     244             :                         {
     245             :                             // unknown implementation, add to result
     246           0 :                             aDestination.push_back(xReference);
     247             :                         }
     248             :                     }
     249           0 :                 }
     250             : 
     251             :                 // prepare return value
     252           0 :                 const sal_uInt32 nDestSize(aDestination.size());
     253           0 :                 aRetval.realloc(nDestSize);
     254             : 
     255           0 :                 for(sal_uInt32 b(0); b < nDestSize; b++)
     256             :                 {
     257           0 :                     aRetval[b] = aDestination[b];
     258           0 :                 }
     259             :             }
     260             : 
     261           0 :             return aRetval;
     262             :         }
     263             : 
     264           0 :         HatchTexturePrimitive3D::HatchTexturePrimitive3D(
     265             :             const attribute::FillHatchAttribute& rHatch,
     266             :             const Primitive3DSequence& rChildren,
     267             :             const basegfx::B2DVector& rTextureSize,
     268             :             bool bModulate,
     269             :             bool bFilter)
     270             :         :   TexturePrimitive3D(rChildren, rTextureSize, bModulate, bFilter),
     271             :             maHatch(rHatch),
     272           0 :             maBuffered3DDecomposition()
     273             :         {
     274           0 :         }
     275             : 
     276           0 :         bool HatchTexturePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
     277             :         {
     278           0 :             if(TexturePrimitive3D::operator==(rPrimitive))
     279             :             {
     280           0 :                 const HatchTexturePrimitive3D& rCompare = (HatchTexturePrimitive3D&)rPrimitive;
     281             : 
     282           0 :                 return (getHatch() == rCompare.getHatch());
     283             :             }
     284             : 
     285           0 :             return false;
     286             :         }
     287             : 
     288           0 :         Primitive3DSequence HatchTexturePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
     289             :         {
     290           0 :             ::osl::MutexGuard aGuard( m_aMutex );
     291             : 
     292           0 :             if(!getBuffered3DDecomposition().hasElements())
     293             :             {
     294           0 :                 const Primitive3DSequence aNewSequence(impCreate3DDecomposition());
     295           0 :                 const_cast< HatchTexturePrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
     296             :             }
     297             : 
     298           0 :             return getBuffered3DDecomposition();
     299             :         }
     300             : 
     301             :         // provide unique ID
     302           0 :         ImplPrimitrive3DIDBlock(HatchTexturePrimitive3D, PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D)
     303             : 
     304             :     } // end of namespace primitive3d
     305             : } // end of namespace drawinglayer
     306             : 
     307             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10