LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/primitive3d - sdrlatheprimitive3d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 133 0.0 %
Date: 2012-12-27 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             :                     && (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             :                     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             :                     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 :                 ::osl::Mutex m_mutex;
     237           0 :                 const_cast< SdrLathePrimitive3D& >(*this).impCreateSlices();
     238             :             }
     239             : 
     240           0 :             return maSlices;
     241             :         }
     242             : 
     243           0 :         SdrLathePrimitive3D::SdrLathePrimitive3D(
     244             :             const basegfx::B3DHomMatrix& rTransform,
     245             :             const basegfx::B2DVector& rTextureSize,
     246             :             const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
     247             :             const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute,
     248             :             const basegfx::B2DPolyPolygon& rPolyPolygon,
     249             :             sal_uInt32 nHorizontalSegments,
     250             :             sal_uInt32 nVerticalSegments,
     251             :             double fDiagonal,
     252             :             double fBackScale,
     253             :             double fRotation,
     254             :             bool bSmoothNormals,
     255             :             bool bSmoothHorizontalNormals,
     256             :             bool bSmoothLids,
     257             :             bool bCharacterMode,
     258             :             bool bCloseFront,
     259             :             bool bCloseBack)
     260             :         :   SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute),
     261             :             maCorrectedPolyPolygon(),
     262             :             maSlices(),
     263             :             maPolyPolygon(rPolyPolygon),
     264             :             mnHorizontalSegments(nHorizontalSegments),
     265             :             mnVerticalSegments(nVerticalSegments),
     266             :             mfDiagonal(fDiagonal),
     267             :             mfBackScale(fBackScale),
     268             :             mfRotation(fRotation),
     269             :             mpLastRLGViewInformation(0),
     270             :             mbSmoothNormals(bSmoothNormals),
     271             :             mbSmoothHorizontalNormals(bSmoothHorizontalNormals),
     272             :             mbSmoothLids(bSmoothLids),
     273             :             mbCharacterMode(bCharacterMode),
     274             :             mbCloseFront(bCloseFront),
     275           0 :             mbCloseBack(bCloseBack)
     276             :         {
     277             :             // make sure Rotation is positive
     278           0 :             if(basegfx::fTools::lessOrEqual(getRotation(), 0.0))
     279             :             {
     280           0 :                 mfRotation = 0.0;
     281             :             }
     282             : 
     283             :             // make sure the percentage value getDiagonal() is between 0.0 and 1.0
     284           0 :             if(basegfx::fTools::lessOrEqual(getDiagonal(), 0.0))
     285             :             {
     286           0 :                 mfDiagonal = 0.0;
     287             :             }
     288           0 :             else if(basegfx::fTools::moreOrEqual(getDiagonal(), 1.0))
     289             :             {
     290           0 :                 mfDiagonal = 1.0;
     291             :             }
     292             : 
     293             :             // no close front/back when polygon is not closed
     294           0 :             if(getPolyPolygon().count() && !getPolyPolygon().getB2DPolygon(0L).isClosed())
     295             :             {
     296           0 :                 mbCloseFront = mbCloseBack = false;
     297             :             }
     298             : 
     299             :             // no edge rounding when not closing
     300           0 :             if(!getCloseFront() && !getCloseBack())
     301             :             {
     302           0 :                 mfDiagonal = 0.0;
     303             :             }
     304           0 :         }
     305             : 
     306           0 :         SdrLathePrimitive3D::~SdrLathePrimitive3D()
     307             :         {
     308           0 :             if(mpLastRLGViewInformation)
     309             :             {
     310           0 :                 delete mpLastRLGViewInformation;
     311             :             }
     312           0 :         }
     313             : 
     314           0 :         bool SdrLathePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
     315             :         {
     316           0 :             if(SdrPrimitive3D::operator==(rPrimitive))
     317             :             {
     318           0 :                 const SdrLathePrimitive3D& rCompare = static_cast< const SdrLathePrimitive3D& >(rPrimitive);
     319             : 
     320           0 :                 return (getPolyPolygon() == rCompare.getPolyPolygon()
     321           0 :                     && getHorizontalSegments() == rCompare.getHorizontalSegments()
     322           0 :                     && getVerticalSegments() == rCompare.getVerticalSegments()
     323           0 :                     && getDiagonal() == rCompare.getDiagonal()
     324           0 :                     && getBackScale() == rCompare.getBackScale()
     325           0 :                     && getRotation() == rCompare.getRotation()
     326           0 :                     && getSmoothNormals() == rCompare.getSmoothNormals()
     327           0 :                     && getSmoothHorizontalNormals() == rCompare.getSmoothHorizontalNormals()
     328           0 :                     && getSmoothLids() == rCompare.getSmoothLids()
     329           0 :                     && getCharacterMode() == rCompare.getCharacterMode()
     330           0 :                     && getCloseFront() == rCompare.getCloseFront()
     331           0 :                     && getCloseBack() == rCompare.getCloseBack());
     332             :             }
     333             : 
     334           0 :             return false;
     335             :         }
     336             : 
     337           0 :         basegfx::B3DRange SdrLathePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
     338             :         {
     339             :             // use defaut from sdrPrimitive3D which uses transformation expanded by line width/2
     340             :             // The parent implementation which uses the ranges of the decomposition would be more
     341             :             // corrcet, but for historical reasons it is necessary to do the old method: To get
     342             :             // the range of the non-transformed geometry and transform it then. This leads to different
     343             :             // ranges where the new method is more correct, but the need to keep the old behaviour
     344             :             // has priority here.
     345           0 :             return get3DRangeFromSlices(getSlices());
     346             :         }
     347             : 
     348           0 :         Primitive3DSequence SdrLathePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
     349             :         {
     350           0 :             if(getSdr3DObjectAttribute().getReducedLineGeometry())
     351             :             {
     352           0 :                 if(!mpLastRLGViewInformation ||
     353           0 :                     (getBuffered3DDecomposition().hasElements()
     354           0 :                         && *mpLastRLGViewInformation != rViewInformation))
     355             :                 {
     356             :                     // conditions of last local decomposition with reduced lines have changed. Remember
     357             :                     // new one and clear current decompositiopn
     358           0 :                     ::osl::Mutex m_mutex;
     359           0 :                     SdrLathePrimitive3D* pThat = const_cast< SdrLathePrimitive3D* >(this);
     360           0 :                     pThat->setBuffered3DDecomposition(Primitive3DSequence());
     361           0 :                     delete pThat->mpLastRLGViewInformation;
     362           0 :                     pThat->mpLastRLGViewInformation = new geometry::ViewInformation3D(rViewInformation);
     363             :                 }
     364             :             }
     365             : 
     366             :             // no test for buffering needed, call parent
     367           0 :             return SdrPrimitive3D::get3DDecomposition(rViewInformation);
     368             :         }
     369             : 
     370             :         // provide unique ID
     371           0 :         ImplPrimitrive3DIDBlock(SdrLathePrimitive3D, PRIMITIVE3D_ID_SDRLATHEPRIMITIVE3D)
     372             : 
     373             :     } // end of namespace primitive3d
     374             : } // end of namespace drawinglayer
     375             : 
     376             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10