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