LCOV - code coverage report
Current view: top level - drawinglayer/source/attribute - sdrlightingattribute3d.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 55 0.0 %
Date: 2014-04-14 Functions: 0 16 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/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           0 :         class ImpSdrLightingAttribute
      33             :         {
      34             :         public:
      35             :             // 3D light attribute definitions
      36             :             basegfx::BColor                         maAmbientLight;
      37             :             ::std::vector< Sdr3DLightAttribute >    maLightVector;
      38             : 
      39           0 :             ImpSdrLightingAttribute(
      40             :                 const basegfx::BColor& rAmbientLight,
      41             :                 const ::std::vector< Sdr3DLightAttribute >& rLightVector)
      42             :             :   maAmbientLight(rAmbientLight),
      43           0 :                 maLightVector(rLightVector)
      44             :             {
      45           0 :             }
      46             : 
      47           0 :             ImpSdrLightingAttribute()
      48             :             :   maAmbientLight(basegfx::BColor()),
      49           0 :                 maLightVector(std::vector< Sdr3DLightAttribute >())
      50             :             {
      51           0 :             }
      52             : 
      53             :             // data read access
      54           0 :             const basegfx::BColor& getAmbientLight() const { return maAmbientLight; }
      55           0 :             const ::std::vector< Sdr3DLightAttribute >& getLightVector() const { return maLightVector; }
      56             : 
      57           0 :             bool operator==(const ImpSdrLightingAttribute& rCandidate) const
      58             :             {
      59           0 :                 return (getAmbientLight() == rCandidate.getAmbientLight()
      60           0 :                     && getLightVector() == rCandidate.getLightVector());
      61             :             }
      62             :         };
      63             : 
      64             :         namespace
      65             :         {
      66             :             struct theGlobalDefault :
      67             :                 public rtl::Static< SdrLightingAttribute::ImplType, theGlobalDefault > {};
      68             :         }
      69             : 
      70           0 :         SdrLightingAttribute::SdrLightingAttribute(
      71             :             const basegfx::BColor& rAmbientLight,
      72             :             const ::std::vector< Sdr3DLightAttribute >& rLightVector)
      73             :         :   mpSdrLightingAttribute(ImpSdrLightingAttribute(
      74           0 :                 rAmbientLight, rLightVector))
      75             :         {
      76           0 :         }
      77             : 
      78           0 :         SdrLightingAttribute::SdrLightingAttribute()
      79           0 :         :   mpSdrLightingAttribute(theGlobalDefault::get())
      80             :         {
      81           0 :         }
      82             : 
      83           0 :         SdrLightingAttribute::SdrLightingAttribute(const SdrLightingAttribute& rCandidate)
      84           0 :         :   mpSdrLightingAttribute(rCandidate.mpSdrLightingAttribute)
      85             :         {
      86           0 :         }
      87             : 
      88           0 :         SdrLightingAttribute::~SdrLightingAttribute()
      89             :         {
      90           0 :         }
      91             : 
      92           0 :         bool SdrLightingAttribute::isDefault() const
      93             :         {
      94           0 :             return mpSdrLightingAttribute.same_object(theGlobalDefault::get());
      95             :         }
      96             : 
      97           0 :         SdrLightingAttribute& SdrLightingAttribute::operator=(const SdrLightingAttribute& rCandidate)
      98             :         {
      99           0 :             mpSdrLightingAttribute = rCandidate.mpSdrLightingAttribute;
     100           0 :             return *this;
     101             :         }
     102             : 
     103           0 :         bool SdrLightingAttribute::operator==(const SdrLightingAttribute& rCandidate) const
     104             :         {
     105           0 :             return rCandidate.mpSdrLightingAttribute == mpSdrLightingAttribute;
     106             :         }
     107             : 
     108           0 :         const ::std::vector< Sdr3DLightAttribute >& SdrLightingAttribute::getLightVector() const
     109             :         {
     110           0 :             return mpSdrLightingAttribute->getLightVector();
     111             :         }
     112             : 
     113             :         // color model solver
     114           0 :         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           0 :             basegfx::BColor aRetval(rEmission);
     121             : 
     122             :             // take care of global ambient light
     123           0 :             aRetval += mpSdrLightingAttribute->getAmbientLight() * rColor;
     124             : 
     125             :             // prepare light access. Is there a light?
     126           0 :             const sal_uInt32 nLightCount(mpSdrLightingAttribute->getLightVector().size());
     127             : 
     128           0 :             if(nLightCount && !rNormalInEyeCoordinates.equalZero())
     129             :             {
     130             :                 // prepare normal
     131           0 :                 basegfx::B3DVector aEyeNormal(rNormalInEyeCoordinates);
     132           0 :                 aEyeNormal.normalize();
     133             : 
     134           0 :                 for(sal_uInt32 a(0L); a < nLightCount; a++)
     135             :                 {
     136           0 :                     const Sdr3DLightAttribute& rLight(mpSdrLightingAttribute->getLightVector()[a]);
     137           0 :                     const double fCosFac(rLight.getDirection().scalar(aEyeNormal));
     138             : 
     139           0 :                     if(basegfx::fTools::more(fCosFac, 0.0))
     140             :                     {
     141           0 :                         aRetval += ((rLight.getColor() * rColor) * fCosFac);
     142             : 
     143           0 :                         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           0 :                 }
     158             :             }
     159             : 
     160             :             // clamp to color space before usage
     161           0 :             aRetval.clamp();
     162             : 
     163           0 :             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