LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive3d - sdrlatheprimitive3d.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 115 134 85.8 %
Date: 2015-06-13 12:38:46 Functions: 10 10 100.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/sdrlatheprimitive3d.hxx>
      21             : #include <basegfx/matrix/b2dhommatrix.hxx>
      22             : #include <basegfx/polygon/b2dpolygontools.hxx>
      23             : #include <basegfx/polygon/b3dpolypolygontools.hxx>
      24             : #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
      25             : #include <basegfx/tools/canvastools.hxx>
      26             : #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
      27             : #include <drawinglayer/geometry/viewinformation3d.hxx>
      28             : #include <drawinglayer/attribute/sdrfillattribute.hxx>
      29             : #include <drawinglayer/attribute/sdrlineattribute.hxx>
      30             : #include <drawinglayer/attribute/sdrshadowattribute.hxx>
      31             : 
      32             : 
      33             : 
      34             : using namespace com::sun::star;
      35             : 
      36             : 
      37             : 
      38             : namespace drawinglayer
      39             : {
      40             :     namespace primitive3d
      41             :     {
      42          96 :         Primitive3DSequence SdrLathePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
      43             :         {
      44          96 :             Primitive3DSequence aRetval;
      45             : 
      46             :             // get slices
      47          96 :             const Slice3DVector& rSliceVector = getSlices();
      48             : 
      49          96 :             if(!rSliceVector.empty())
      50             :             {
      51          96 :                 const bool bBackScale(!basegfx::fTools::equal(getBackScale(), 1.0));
      52          96 :                 const bool bClosedRotation(!bBackScale && getHorizontalSegments() && basegfx::fTools::equal(getRotation(), F_2PI));
      53             :                 sal_uInt32 a;
      54             : 
      55             :                 // decide what to create
      56          96 :                 const ::com::sun::star::drawing::NormalsKind eNormalsKind(getSdr3DObjectAttribute().getNormalsKind());
      57          96 :                 const bool bCreateNormals(::com::sun::star::drawing::NormalsKind_SPECIFIC == eNormalsKind);
      58          96 :                 const bool bCreateTextureCoordiantesX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX());
      59          96 :                 const bool bCreateTextureCoordiantesY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY());
      60          96 :                 basegfx::B2DHomMatrix aTexTransform;
      61             : 
      62         192 :                 if(!getSdrLFSAttribute().getFill().isDefault()
      63          96 :                     && (bCreateTextureCoordiantesX || bCreateTextureCoordiantesY))
      64             :                 {
      65          96 :                     aTexTransform.set(0, 0, 0.0);
      66          96 :                     aTexTransform.set(0, 1, 1.0);
      67          96 :                     aTexTransform.set(1, 0, 1.0);
      68          96 :                     aTexTransform.set(1, 1, 0.0);
      69             : 
      70          96 :                     aTexTransform.translate(0.0, -0.5);
      71          96 :                     aTexTransform.scale(1.0, -1.0);
      72          96 :                     aTexTransform.translate(0.0, 0.5);
      73             :                 }
      74             : 
      75             :                 // create geometry
      76         192 :                 ::std::vector< basegfx::B3DPolyPolygon > aFill;
      77             :                 extractPlanesFromSlice(aFill, rSliceVector,
      78         288 :                     bCreateNormals, getSmoothHorizontalNormals(), getSmoothNormals(), getSmoothLids(), bClosedRotation,
      79         384 :                     0.85, 0.6, bCreateTextureCoordiantesX || bCreateTextureCoordiantesY, aTexTransform);
      80             : 
      81             :                 // get full range
      82          96 :                 const basegfx::B3DRange aRange(getRangeFrom3DGeometry(aFill));
      83             : 
      84             :                 // normal creation
      85          96 :                 if(!getSdrLFSAttribute().getFill().isDefault())
      86             :                 {
      87          96 :                     if(::com::sun::star::drawing::NormalsKind_SPHERE == eNormalsKind)
      88             :                     {
      89           0 :                         applyNormalsKindSphereTo3DGeometry(aFill, aRange);
      90             :                     }
      91          96 :                     else if(::com::sun::star::drawing::NormalsKind_FLAT == eNormalsKind)
      92             :                     {
      93           0 :                         applyNormalsKindFlatTo3DGeometry(aFill);
      94             :                     }
      95             : 
      96          96 :                     if(getSdr3DObjectAttribute().getNormalsInvert())
      97             :                     {
      98           0 :                         applyNormalsInvertTo3DGeometry(aFill);
      99             :                     }
     100             :                 }
     101             : 
     102             :                 // texture coordinates
     103          96 :                 if(!getSdrLFSAttribute().getFill().isDefault())
     104             :                 {
     105             :                     applyTextureTo3DGeometry(
     106             :                         getSdr3DObjectAttribute().getTextureProjectionX(),
     107             :                         getSdr3DObjectAttribute().getTextureProjectionY(),
     108             :                         aFill,
     109             :                         aRange,
     110          96 :                         getTextureSize());
     111             :                 }
     112             : 
     113          96 :                 if(!getSdrLFSAttribute().getFill().isDefault())
     114             :                 {
     115             :                     // add fill
     116         288 :                     aRetval = create3DPolyPolygonFillPrimitives(
     117             :                         aFill,
     118          96 :                         getTransform(),
     119          96 :                         getTextureSize(),
     120             :                         getSdr3DObjectAttribute(),
     121          96 :                         getSdrLFSAttribute().getFill(),
     122         192 :                         getSdrLFSAttribute().getFillFloatTransGradient());
     123             :                 }
     124             :                 else
     125             :                 {
     126             :                     // create simplified 3d hit test geometry
     127           0 :                     aRetval = createHiddenGeometryPrimitives3D(
     128             :                         aFill,
     129           0 :                         getTransform(),
     130           0 :                         getTextureSize(),
     131           0 :                         getSdr3DObjectAttribute());
     132             :                 }
     133             : 
     134             :                 // add line
     135          96 :                 if(!getSdrLFSAttribute().getLine().isDefault())
     136             :                 {
     137          48 :                     if(getSdr3DObjectAttribute().getReducedLineGeometry())
     138             :                     {
     139             :                         // create geometric outlines with reduced line geometry for chart
     140          48 :                         const basegfx::B3DPolyPolygon aHorLine(extractHorizontalLinesFromSlice(rSliceVector, bClosedRotation));
     141          48 :                         const sal_uInt32 nCount(aHorLine.count());
     142          96 :                         basegfx::B3DPolyPolygon aNewLineGeometry;
     143             : 
     144         240 :                         for(a = 1; a < nCount; a++)
     145             :                         {
     146             :                             // for each loop pair create the connection edges
     147             :                             createReducedOutlines(
     148             :                                 rViewInformation,
     149         192 :                                 getTransform(),
     150             :                                 aHorLine.getB3DPolygon(a - 1),
     151             :                                 aHorLine.getB3DPolygon(a),
     152         384 :                                 aNewLineGeometry);
     153             :                         }
     154             : 
     155         288 :                         for(a = 0; a < nCount; a++)
     156             :                         {
     157             :                             // filter hor lines for empty loops (those who have their defining point on the Y-Axis)
     158         240 :                             basegfx::B3DPolygon aCandidate(aHorLine.getB3DPolygon(a));
     159         240 :                             aCandidate.removeDoublePoints();
     160             : 
     161         240 :                             if(aCandidate.count())
     162             :                             {
     163         240 :                                 aNewLineGeometry.append(aCandidate);
     164             :                             }
     165         240 :                         }
     166             : 
     167          48 :                         if(aNewLineGeometry.count())
     168             :                         {
     169             :                             const Primitive3DSequence aLines(create3DPolyPolygonLinePrimitives(
     170          48 :                                 aNewLineGeometry, getTransform(), getSdrLFSAttribute().getLine()));
     171          48 :                             appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aLines);
     172          48 :                         }
     173             :                     }
     174             :                     else
     175             :                     {
     176             :                         // extract line geometry from slices
     177           0 :                         const basegfx::B3DPolyPolygon aHorLine(extractHorizontalLinesFromSlice(rSliceVector, bClosedRotation));
     178           0 :                         const basegfx::B3DPolyPolygon aVerLine(extractVerticalLinesFromSlice(rSliceVector));
     179             : 
     180             :                         // add horizontal lines
     181             :                         const Primitive3DSequence aHorLines(create3DPolyPolygonLinePrimitives(
     182           0 :                             aHorLine, getTransform(), getSdrLFSAttribute().getLine()));
     183           0 :                         appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aHorLines);
     184             : 
     185             :                         // add vertical lines
     186             :                         const Primitive3DSequence aVerLines(create3DPolyPolygonLinePrimitives(
     187           0 :                             aVerLine, getTransform(), getSdrLFSAttribute().getLine()));
     188           0 :                         appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aVerLines);
     189             :                     }
     190             :                 }
     191             : 
     192             :                 // add shadow
     193         192 :                 if(!getSdrLFSAttribute().getShadow().isDefault()
     194          96 :                     && aRetval.hasElements())
     195             :                 {
     196             :                     const Primitive3DSequence aShadow(createShadowPrimitive3D(
     197           0 :                         aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
     198           0 :                     appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aShadow);
     199          96 :                 }
     200             :             }
     201             : 
     202          96 :             return aRetval;
     203             :         }
     204             : 
     205         183 :         void SdrLathePrimitive3D::impCreateSlices()
     206             :         {
     207             :             // prepare the polygon. No double points, correct orientations and a correct
     208             :             // outmost polygon are needed
     209             :             // Also important: subdivide here to ensure equal point count for all slices (!)
     210         183 :             maCorrectedPolyPolygon = basegfx::tools::adaptiveSubdivideByAngle(getPolyPolygon());
     211         183 :             maCorrectedPolyPolygon.removeDoublePoints();
     212         183 :             maCorrectedPolyPolygon = basegfx::tools::correctOrientations(maCorrectedPolyPolygon);
     213         183 :             maCorrectedPolyPolygon = basegfx::tools::correctOutmostPolygon(maCorrectedPolyPolygon);
     214             : 
     215             :             // check edge count of first sub-polygon. If different, reSegment polyPolygon. This ensures
     216             :             // that for polyPolygons, the subPolys 1..n only get reSegmented when polygon 0L is different
     217             :             // at all (and not always)
     218         183 :             const basegfx::B2DPolygon aSubCandidate(maCorrectedPolyPolygon.getB2DPolygon(0));
     219         183 :             const sal_uInt32 nSubEdgeCount(aSubCandidate.isClosed() ? aSubCandidate.count() : (aSubCandidate.count() ? aSubCandidate.count() - 1L : 0L));
     220             : 
     221         183 :             if(nSubEdgeCount != getVerticalSegments())
     222             :             {
     223           0 :                 maCorrectedPolyPolygon = basegfx::tools::reSegmentPolyPolygon(maCorrectedPolyPolygon, getVerticalSegments());
     224             :             }
     225             : 
     226             :             // prepare slices as geometry
     227         183 :             createLatheSlices(maSlices, maCorrectedPolyPolygon, getBackScale(), getDiagonal(), getRotation(), getHorizontalSegments(), getCharacterMode(), getCloseFront(), getCloseBack());
     228         183 :         }
     229             : 
     230         708 :         const Slice3DVector& SdrLathePrimitive3D::getSlices() const
     231             :         {
     232             :             // This can be made dependent of  getSdrLFSAttribute().getFill() and getSdrLFSAttribute().getLine()
     233             :             // again when no longer geometry is needed for non-visible 3D objects as it is now for chart
     234         708 :             if(getPolyPolygon().count() && !maSlices.size())
     235             :             {
     236         183 :                 const_cast< SdrLathePrimitive3D& >(*this).impCreateSlices();
     237             :             }
     238             : 
     239         708 :             return maSlices;
     240             :         }
     241             : 
     242         564 :         SdrLathePrimitive3D::SdrLathePrimitive3D(
     243             :             const basegfx::B3DHomMatrix& rTransform,
     244             :             const basegfx::B2DVector& rTextureSize,
     245             :             const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
     246             :             const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute,
     247             :             const basegfx::B2DPolyPolygon& rPolyPolygon,
     248             :             sal_uInt32 nHorizontalSegments,
     249             :             sal_uInt32 nVerticalSegments,
     250             :             double fDiagonal,
     251             :             double fBackScale,
     252             :             double fRotation,
     253             :             bool bSmoothNormals,
     254             :             bool bSmoothHorizontalNormals,
     255             :             bool bSmoothLids,
     256             :             bool bCharacterMode,
     257             :             bool bCloseFront,
     258             :             bool bCloseBack)
     259             :         :   SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute),
     260             :             maCorrectedPolyPolygon(),
     261             :             maSlices(),
     262             :             maPolyPolygon(rPolyPolygon),
     263             :             mnHorizontalSegments(nHorizontalSegments),
     264             :             mnVerticalSegments(nVerticalSegments),
     265             :             mfDiagonal(fDiagonal),
     266             :             mfBackScale(fBackScale),
     267             :             mfRotation(fRotation),
     268             :             mpLastRLGViewInformation(0),
     269             :             mbSmoothNormals(bSmoothNormals),
     270             :             mbSmoothHorizontalNormals(bSmoothHorizontalNormals),
     271             :             mbSmoothLids(bSmoothLids),
     272             :             mbCharacterMode(bCharacterMode),
     273             :             mbCloseFront(bCloseFront),
     274         564 :             mbCloseBack(bCloseBack)
     275             :         {
     276             :             // make sure Rotation is positive
     277         564 :             if(basegfx::fTools::lessOrEqual(getRotation(), 0.0))
     278             :             {
     279           0 :                 mfRotation = 0.0;
     280             :             }
     281             : 
     282             :             // make sure the percentage value getDiagonal() is between 0.0 and 1.0
     283         564 :             if(basegfx::fTools::lessOrEqual(getDiagonal(), 0.0))
     284             :             {
     285           0 :                 mfDiagonal = 0.0;
     286             :             }
     287         564 :             else if(basegfx::fTools::moreOrEqual(getDiagonal(), 1.0))
     288             :             {
     289           0 :                 mfDiagonal = 1.0;
     290             :             }
     291             : 
     292             :             // no close front/back when polygon is not closed
     293         564 :             if(getPolyPolygon().count() && !getPolyPolygon().getB2DPolygon(0L).isClosed())
     294             :             {
     295         471 :                 mbCloseFront = mbCloseBack = false;
     296             :             }
     297             : 
     298             :             // no edge rounding when not closing
     299         564 :             if(!getCloseFront() && !getCloseBack())
     300             :             {
     301         471 :                 mfDiagonal = 0.0;
     302             :             }
     303         564 :         }
     304             : 
     305        1692 :         SdrLathePrimitive3D::~SdrLathePrimitive3D()
     306             :         {
     307         564 :             if(mpLastRLGViewInformation)
     308             :             {
     309          48 :                 delete mpLastRLGViewInformation;
     310             :             }
     311        1128 :         }
     312             : 
     313         431 :         bool SdrLathePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
     314             :         {
     315         431 :             if(SdrPrimitive3D::operator==(rPrimitive))
     316             :             {
     317         381 :                 const SdrLathePrimitive3D& rCompare = static_cast< const SdrLathePrimitive3D& >(rPrimitive);
     318             : 
     319         381 :                 return (getPolyPolygon() == rCompare.getPolyPolygon()
     320         381 :                     && getHorizontalSegments() == rCompare.getHorizontalSegments()
     321         381 :                     && getVerticalSegments() == rCompare.getVerticalSegments()
     322         381 :                     && getDiagonal() == rCompare.getDiagonal()
     323         381 :                     && getBackScale() == rCompare.getBackScale()
     324         381 :                     && getRotation() == rCompare.getRotation()
     325         381 :                     && getSmoothNormals() == rCompare.getSmoothNormals()
     326         381 :                     && getSmoothHorizontalNormals() == rCompare.getSmoothHorizontalNormals()
     327         381 :                     && getSmoothLids() == rCompare.getSmoothLids()
     328         381 :                     && getCharacterMode() == rCompare.getCharacterMode()
     329         381 :                     && getCloseFront() == rCompare.getCloseFront()
     330         762 :                     && getCloseBack() == rCompare.getCloseBack());
     331             :             }
     332             : 
     333          50 :             return false;
     334             :         }
     335             : 
     336         612 :         basegfx::B3DRange SdrLathePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
     337             :         {
     338             :             // use default from sdrPrimitive3D which uses transformation expanded by line width/2
     339             :             // The parent implementation which uses the ranges of the decomposition would be more
     340             :             // correct, but for historical reasons it is necessary to do the old method: To get
     341             :             // the range of the non-transformed geometry and transform it then. This leads to different
     342             :             // ranges where the new method is more correct, but the need to keep the old behaviour
     343             :             // has priority here.
     344         612 :             return get3DRangeFromSlices(getSlices());
     345             :         }
     346             : 
     347          96 :         Primitive3DSequence SdrLathePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
     348             :         {
     349          96 :             if(getSdr3DObjectAttribute().getReducedLineGeometry())
     350             :             {
     351         240 :                 if(!mpLastRLGViewInformation ||
     352          48 :                     (getBuffered3DDecomposition().hasElements()
     353          48 :                         && *mpLastRLGViewInformation != rViewInformation))
     354             :                 {
     355             :                     // conditions of last local decomposition with reduced lines have changed. Remember
     356             :                     // new one and clear current decompositiopn
     357          96 :                     SdrLathePrimitive3D* pThat = const_cast< SdrLathePrimitive3D* >(this);
     358          96 :                     pThat->setBuffered3DDecomposition(Primitive3DSequence());
     359          96 :                     delete pThat->mpLastRLGViewInformation;
     360          96 :                     pThat->mpLastRLGViewInformation = new geometry::ViewInformation3D(rViewInformation);
     361             :                 }
     362             :             }
     363             : 
     364             :             // no test for buffering needed, call parent
     365          96 :             return SdrPrimitive3D::get3DDecomposition(rViewInformation);
     366             :         }
     367             : 
     368             :         // provide unique ID
     369         958 :         ImplPrimitive3DIDBlock(SdrLathePrimitive3D, PRIMITIVE3D_ID_SDRLATHEPRIMITIVE3D)
     370             : 
     371             :     } // end of namespace primitive3d
     372             : } // end of namespace drawinglayer
     373             : 
     374             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11