LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive3d - sdrlatheprimitive3d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 115 134 85.8 %
Date: 2014-11-03 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         192 :         Primitive3DSequence SdrLathePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
      43             :         {
      44         192 :             Primitive3DSequence aRetval;
      45             : 
      46             :             // get slices
      47         192 :             const Slice3DVector& rSliceVector = getSlices();
      48             : 
      49         192 :             if(!rSliceVector.empty())
      50             :             {
      51         192 :                 const bool bBackScale(!basegfx::fTools::equal(getBackScale(), 1.0));
      52         192 :                 const bool bClosedRotation(!bBackScale && getHorizontalSegments() && basegfx::fTools::equal(getRotation(), F_2PI));
      53             :                 sal_uInt32 a;
      54             : 
      55             :                 // decide what to create
      56         192 :                 const ::com::sun::star::drawing::NormalsKind eNormalsKind(getSdr3DObjectAttribute().getNormalsKind());
      57         192 :                 const bool bCreateNormals(::com::sun::star::drawing::NormalsKind_SPECIFIC == eNormalsKind);
      58         192 :                 const bool bCreateTextureCoordiantesX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX());
      59         192 :                 const bool bCreateTextureCoordiantesY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY());
      60         192 :                 basegfx::B2DHomMatrix aTexTransform;
      61             : 
      62         384 :                 if(!getSdrLFSAttribute().getFill().isDefault()
      63         192 :                     && (bCreateTextureCoordiantesX || bCreateTextureCoordiantesY))
      64             :                 {
      65         192 :                     aTexTransform.set(0, 0, 0.0);
      66         192 :                     aTexTransform.set(0, 1, 1.0);
      67         192 :                     aTexTransform.set(1, 0, 1.0);
      68         192 :                     aTexTransform.set(1, 1, 0.0);
      69             : 
      70         192 :                     aTexTransform.translate(0.0, -0.5);
      71         192 :                     aTexTransform.scale(1.0, -1.0);
      72         192 :                     aTexTransform.translate(0.0, 0.5);
      73             :                 }
      74             : 
      75             :                 // create geometry
      76         384 :                 ::std::vector< basegfx::B3DPolyPolygon > aFill;
      77             :                 extractPlanesFromSlice(aFill, rSliceVector,
      78         576 :                     bCreateNormals, getSmoothHorizontalNormals(), getSmoothNormals(), getSmoothLids(), bClosedRotation,
      79         768 :                     0.85, 0.6, bCreateTextureCoordiantesX || bCreateTextureCoordiantesY, aTexTransform);
      80             : 
      81             :                 // get full range
      82         192 :                 const basegfx::B3DRange aRange(getRangeFrom3DGeometry(aFill));
      83             : 
      84             :                 // normal creation
      85         192 :                 if(!getSdrLFSAttribute().getFill().isDefault())
      86             :                 {
      87         192 :                     if(::com::sun::star::drawing::NormalsKind_SPHERE == eNormalsKind)
      88             :                     {
      89           0 :                         applyNormalsKindSphereTo3DGeometry(aFill, aRange);
      90             :                     }
      91         192 :                     else if(::com::sun::star::drawing::NormalsKind_FLAT == eNormalsKind)
      92             :                     {
      93           0 :                         applyNormalsKindFlatTo3DGeometry(aFill);
      94             :                     }
      95             : 
      96         192 :                     if(getSdr3DObjectAttribute().getNormalsInvert())
      97             :                     {
      98           0 :                         applyNormalsInvertTo3DGeometry(aFill);
      99             :                     }
     100             :                 }
     101             : 
     102             :                 // texture coordinates
     103         192 :                 if(!getSdrLFSAttribute().getFill().isDefault())
     104             :                 {
     105             :                     applyTextureTo3DGeometry(
     106             :                         getSdr3DObjectAttribute().getTextureProjectionX(),
     107             :                         getSdr3DObjectAttribute().getTextureProjectionY(),
     108             :                         aFill,
     109             :                         aRange,
     110         192 :                         getTextureSize());
     111             :                 }
     112             : 
     113         192 :                 if(!getSdrLFSAttribute().getFill().isDefault())
     114             :                 {
     115             :                     // add fill
     116         576 :                     aRetval = create3DPolyPolygonFillPrimitives(
     117             :                         aFill,
     118         192 :                         getTransform(),
     119         192 :                         getTextureSize(),
     120             :                         getSdr3DObjectAttribute(),
     121         192 :                         getSdrLFSAttribute().getFill(),
     122         384 :                         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         192 :                 if(!getSdrLFSAttribute().getLine().isDefault())
     136             :                 {
     137          96 :                     if(getSdr3DObjectAttribute().getReducedLineGeometry())
     138             :                     {
     139             :                         // create geometric outlines with reduced line geometry for chart
     140          96 :                         const basegfx::B3DPolyPolygon aHorLine(extractHorizontalLinesFromSlice(rSliceVector, bClosedRotation));
     141          96 :                         const sal_uInt32 nCount(aHorLine.count());
     142         192 :                         basegfx::B3DPolyPolygon aNewLineGeometry;
     143             : 
     144         480 :                         for(a = 1; a < nCount; a++)
     145             :                         {
     146             :                             // for each loop pair create the connection edges
     147             :                             createReducedOutlines(
     148             :                                 rViewInformation,
     149         384 :                                 getTransform(),
     150             :                                 aHorLine.getB3DPolygon(a - 1),
     151             :                                 aHorLine.getB3DPolygon(a),
     152         768 :                                 aNewLineGeometry);
     153             :                         }
     154             : 
     155         576 :                         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         480 :                             basegfx::B3DPolygon aCandidate(aHorLine.getB3DPolygon(a));
     159         480 :                             aCandidate.removeDoublePoints();
     160             : 
     161         480 :                             if(aCandidate.count())
     162             :                             {
     163         480 :                                 aNewLineGeometry.append(aCandidate);
     164             :                             }
     165         480 :                         }
     166             : 
     167          96 :                         if(aNewLineGeometry.count())
     168             :                         {
     169             :                             const Primitive3DSequence aLines(create3DPolyPolygonLinePrimitives(
     170          96 :                                 aNewLineGeometry, getTransform(), getSdrLFSAttribute().getLine()));
     171          96 :                             appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aLines);
     172          96 :                         }
     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         384 :                 if(!getSdrLFSAttribute().getShadow().isDefault()
     194         192 :                     && aRetval.hasElements())
     195             :                 {
     196             :                     const Primitive3DSequence aShadow(createShadowPrimitive3D(
     197           0 :                         aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
     198           0 :                     appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aShadow);
     199         192 :                 }
     200             :             }
     201             : 
     202         192 :             return aRetval;
     203             :         }
     204             : 
     205         120 :         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         120 :             maCorrectedPolyPolygon = basegfx::tools::adaptiveSubdivideByAngle(getPolyPolygon());
     211         120 :             maCorrectedPolyPolygon.removeDoublePoints();
     212         120 :             maCorrectedPolyPolygon = basegfx::tools::correctOrientations(maCorrectedPolyPolygon);
     213         120 :             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         120 :             const basegfx::B2DPolygon aSubCandidate(maCorrectedPolyPolygon.getB2DPolygon(0));
     219         120 :             const sal_uInt32 nSubEdgeCount(aSubCandidate.isClosed() ? aSubCandidate.count() : (aSubCandidate.count() ? aSubCandidate.count() - 1L : 0L));
     220             : 
     221         120 :             if(nSubEdgeCount != getVerticalSegments())
     222             :             {
     223           0 :                 maCorrectedPolyPolygon = basegfx::tools::reSegmentPolyPolygon(maCorrectedPolyPolygon, getVerticalSegments());
     224             :             }
     225             : 
     226             :             // prepare slices as geometry
     227         120 :             createLatheSlices(maSlices, maCorrectedPolyPolygon, getBackScale(), getDiagonal(), getRotation(), getHorizontalSegments(), getCharacterMode(), getCloseFront(), getCloseBack());
     228         120 :         }
     229             : 
     230         680 :         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         680 :             if(getPolyPolygon().count() && !maSlices.size())
     235             :             {
     236         120 :                 const_cast< SdrLathePrimitive3D& >(*this).impCreateSlices();
     237             :             }
     238             : 
     239         680 :             return maSlices;
     240             :         }
     241             : 
     242         392 :         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         392 :             mbCloseBack(bCloseBack)
     275             :         {
     276             :             // make sure Rotation is positive
     277         392 :             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         392 :             if(basegfx::fTools::lessOrEqual(getDiagonal(), 0.0))
     284             :             {
     285           0 :                 mfDiagonal = 0.0;
     286             :             }
     287         392 :             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         392 :             if(getPolyPolygon().count() && !getPolyPolygon().getB2DPolygon(0L).isClosed())
     294             :             {
     295         360 :                 mbCloseFront = mbCloseBack = false;
     296             :             }
     297             : 
     298             :             // no edge rounding when not closing
     299         392 :             if(!getCloseFront() && !getCloseBack())
     300             :             {
     301         360 :                 mfDiagonal = 0.0;
     302             :             }
     303         392 :         }
     304             : 
     305        1176 :         SdrLathePrimitive3D::~SdrLathePrimitive3D()
     306             :         {
     307         392 :             if(mpLastRLGViewInformation)
     308             :             {
     309          96 :                 delete mpLastRLGViewInformation;
     310             :             }
     311         784 :         }
     312             : 
     313         296 :         bool SdrLathePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
     314             :         {
     315         296 :             if(SdrPrimitive3D::operator==(rPrimitive))
     316             :             {
     317         272 :                 const SdrLathePrimitive3D& rCompare = static_cast< const SdrLathePrimitive3D& >(rPrimitive);
     318             : 
     319         272 :                 return (getPolyPolygon() == rCompare.getPolyPolygon()
     320         272 :                     && getHorizontalSegments() == rCompare.getHorizontalSegments()
     321         272 :                     && getVerticalSegments() == rCompare.getVerticalSegments()
     322         272 :                     && getDiagonal() == rCompare.getDiagonal()
     323         272 :                     && getBackScale() == rCompare.getBackScale()
     324         272 :                     && getRotation() == rCompare.getRotation()
     325         272 :                     && getSmoothNormals() == rCompare.getSmoothNormals()
     326         272 :                     && getSmoothHorizontalNormals() == rCompare.getSmoothHorizontalNormals()
     327         272 :                     && getSmoothLids() == rCompare.getSmoothLids()
     328         272 :                     && getCharacterMode() == rCompare.getCharacterMode()
     329         272 :                     && getCloseFront() == rCompare.getCloseFront()
     330         544 :                     && getCloseBack() == rCompare.getCloseBack());
     331             :             }
     332             : 
     333          24 :             return false;
     334             :         }
     335             : 
     336         488 :         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         488 :             return get3DRangeFromSlices(getSlices());
     345             :         }
     346             : 
     347         192 :         Primitive3DSequence SdrLathePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
     348             :         {
     349         192 :             if(getSdr3DObjectAttribute().getReducedLineGeometry())
     350             :             {
     351         480 :                 if(!mpLastRLGViewInformation ||
     352          96 :                     (getBuffered3DDecomposition().hasElements()
     353          96 :                         && *mpLastRLGViewInformation != rViewInformation))
     354             :                 {
     355             :                     // conditions of last local decomposition with reduced lines have changed. Remember
     356             :                     // new one and clear current decompositiopn
     357         192 :                     SdrLathePrimitive3D* pThat = const_cast< SdrLathePrimitive3D* >(this);
     358         192 :                     pThat->setBuffered3DDecomposition(Primitive3DSequence());
     359         192 :                     delete pThat->mpLastRLGViewInformation;
     360         192 :                     pThat->mpLastRLGViewInformation = new geometry::ViewInformation3D(rViewInformation);
     361             :                 }
     362             :             }
     363             : 
     364             :             // no test for buffering needed, call parent
     365         192 :             return SdrPrimitive3D::get3DDecomposition(rViewInformation);
     366             :         }
     367             : 
     368             :         // provide unique ID
     369         784 :         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.10