LCOV - code coverage report
Current view: top level - drawinglayer/source/attribute - sdrlightingattribute3d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 55 87.3 %
Date: 2014-11-03 Functions: 16 16 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/attribute/sdrlightingattribute3d.hxx>
      21             : #include <basegfx/color/bcolor.hxx>
      22             : #include <basegfx/vector/b3dvector.hxx>
      23             : #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
      24             : #include <rtl/instance.hxx>
      25             : 
      26             : 
      27             : 
      28             : namespace drawinglayer
      29             : {
      30             :     namespace attribute
      31             :     {
      32          87 :         class ImpSdrLightingAttribute
      33             :         {
      34             :         public:
      35             :             // 3D light attribute definitions
      36             :             basegfx::BColor                         maAmbientLight;
      37             :             ::std::vector< Sdr3DLightAttribute >    maLightVector;
      38             : 
      39          27 :             ImpSdrLightingAttribute(
      40             :                 const basegfx::BColor& rAmbientLight,
      41             :                 const ::std::vector< Sdr3DLightAttribute >& rLightVector)
      42             :             :   maAmbientLight(rAmbientLight),
      43          27 :                 maLightVector(rLightVector)
      44             :             {
      45          27 :             }
      46             : 
      47           6 :             ImpSdrLightingAttribute()
      48             :             :   maAmbientLight(basegfx::BColor()),
      49           6 :                 maLightVector(std::vector< Sdr3DLightAttribute >())
      50             :             {
      51           6 :             }
      52             : 
      53             :             // data read access
      54       37562 :             const basegfx::BColor& getAmbientLight() const { return maAmbientLight; }
      55       74916 :             const ::std::vector< Sdr3DLightAttribute >& getLightVector() const { return maLightVector; }
      56             : 
      57           8 :             bool operator==(const ImpSdrLightingAttribute& rCandidate) const
      58             :             {
      59           8 :                 return (getAmbientLight() == rCandidate.getAmbientLight()
      60           8 :                     && getLightVector() == rCandidate.getLightVector());
      61             :             }
      62             :         };
      63             : 
      64             :         namespace
      65             :         {
      66             :             struct theGlobalDefault :
      67             :                 public rtl::Static< SdrLightingAttribute::ImplType, theGlobalDefault > {};
      68             :         }
      69             : 
      70          27 :         SdrLightingAttribute::SdrLightingAttribute(
      71             :             const basegfx::BColor& rAmbientLight,
      72             :             const ::std::vector< Sdr3DLightAttribute >& rLightVector)
      73             :         :   mpSdrLightingAttribute(ImpSdrLightingAttribute(
      74          27 :                 rAmbientLight, rLightVector))
      75             :         {
      76          27 :         }
      77             : 
      78        7872 :         SdrLightingAttribute::SdrLightingAttribute()
      79        7872 :         :   mpSdrLightingAttribute(theGlobalDefault::get())
      80             :         {
      81        7872 :         }
      82             : 
      83          36 :         SdrLightingAttribute::SdrLightingAttribute(const SdrLightingAttribute& rCandidate)
      84          36 :         :   mpSdrLightingAttribute(rCandidate.mpSdrLightingAttribute)
      85             :         {
      86          36 :         }
      87             : 
      88        7935 :         SdrLightingAttribute::~SdrLightingAttribute()
      89             :         {
      90        7935 :         }
      91             : 
      92          36 :         bool SdrLightingAttribute::isDefault() const
      93             :         {
      94          36 :             return mpSdrLightingAttribute.same_object(theGlobalDefault::get());
      95             :         }
      96             : 
      97        6493 :         SdrLightingAttribute& SdrLightingAttribute::operator=(const SdrLightingAttribute& rCandidate)
      98             :         {
      99        6493 :             mpSdrLightingAttribute = rCandidate.mpSdrLightingAttribute;
     100        6493 :             return *this;
     101             :         }
     102             : 
     103          60 :         bool SdrLightingAttribute::operator==(const SdrLightingAttribute& rCandidate) const
     104             :         {
     105          60 :             return rCandidate.mpSdrLightingAttribute == mpSdrLightingAttribute;
     106             :         }
     107             : 
     108          46 :         const ::std::vector< Sdr3DLightAttribute >& SdrLightingAttribute::getLightVector() const
     109             :         {
     110          46 :             return mpSdrLightingAttribute->getLightVector();
     111             :         }
     112             : 
     113             :         // color model solver
     114       37546 :         basegfx::BColor SdrLightingAttribute::solveColorModel(
     115             :             const basegfx::B3DVector& rNormalInEyeCoordinates,
     116             :             const basegfx::BColor& rColor, const basegfx::BColor& rSpecular,
     117             :             const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) const
     118             :         {
     119             :             // initialize with emissive color
     120       37546 :             basegfx::BColor aRetval(rEmission);
     121             : 
     122             :             // take care of global ambient light
     123       37546 :             aRetval += mpSdrLightingAttribute->getAmbientLight() * rColor;
     124             : 
     125             :             // prepare light access. Is there a light?
     126       37546 :             const sal_uInt32 nLightCount(mpSdrLightingAttribute->getLightVector().size());
     127             : 
     128       37546 :             if(nLightCount && !rNormalInEyeCoordinates.equalZero())
     129             :             {
     130             :                 // prepare normal
     131       37308 :                 basegfx::B3DVector aEyeNormal(rNormalInEyeCoordinates);
     132       37308 :                 aEyeNormal.normalize();
     133             : 
     134       74616 :                 for(sal_uInt32 a(0L); a < nLightCount; a++)
     135             :                 {
     136       37308 :                     const Sdr3DLightAttribute& rLight(mpSdrLightingAttribute->getLightVector()[a]);
     137       37308 :                     const double fCosFac(rLight.getDirection().scalar(aEyeNormal));
     138             : 
     139       37308 :                     if(basegfx::fTools::more(fCosFac, 0.0))
     140             :                     {
     141       31020 :                         aRetval += ((rLight.getColor() * rColor) * fCosFac);
     142             : 
     143       31020 :                         if(rLight.getSpecular())
     144             :                         {
     145             :                             // expand by (0.0, 0.0, 1.0) in Z
     146           0 :                             basegfx::B3DVector aSpecularNormal(rLight.getDirection().getX(), rLight.getDirection().getY(), rLight.getDirection().getZ() + 1.0);
     147           0 :                             aSpecularNormal.normalize();
     148           0 :                             double fCosFac2(aSpecularNormal.scalar(aEyeNormal));
     149             : 
     150           0 :                             if(basegfx::fTools::more(fCosFac2, 0.0))
     151             :                             {
     152           0 :                                 fCosFac2 = pow(fCosFac2, (double)nSpecularIntensity);
     153           0 :                                 aRetval += (rSpecular * fCosFac2);
     154           0 :                             }
     155             :                         }
     156             :                     }
     157       37308 :                 }
     158             :             }
     159             : 
     160             :             // clamp to color space before usage
     161       37546 :             aRetval.clamp();
     162             : 
     163       37546 :             return aRetval;
     164             :         }
     165             :     } // end of namespace attribute
     166             : } // end of namespace drawinglayer
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10