Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:48

0001 // Copyright (c) 2017 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Graphic3d_LightSet_HeaderFile
0015 #define _Graphic3d_LightSet_HeaderFile
0016 
0017 #include <Graphic3d_CLight.hxx>
0018 
0019 //! Class defining the set of light sources.
0020 class Graphic3d_LightSet : public Standard_Transient
0021 {
0022   DEFINE_STANDARD_RTTIEXT(Graphic3d_LightSet, Standard_Transient)
0023 public:
0024 
0025   //! Iteration filter flags.
0026   enum IterationFilter
0027   {
0028     IterationFilter_None            = 0x0000, //!< no filter
0029     IterationFilter_ExcludeAmbient  = 0x0002, //!< exclude ambient  light sources
0030     IterationFilter_ExcludeDisabled = 0x0004, //!< exclude disabled light sources
0031     IterationFilter_ExcludeNoShadow = 0x0008, //!< exclude light sources not casting shadow
0032     IterationFilter_ExcludeDisabledAndAmbient = IterationFilter_ExcludeAmbient | IterationFilter_ExcludeDisabled,
0033     IterationFilter_ActiveShadowCasters = IterationFilter_ExcludeDisabledAndAmbient | IterationFilter_ExcludeNoShadow,
0034   };
0035 
0036   //! Iterator through light sources.
0037   class Iterator
0038   {
0039   public:
0040     //! Empty constructor.
0041     Iterator() : myFilter (0) {}
0042 
0043     //! Constructor with initialization.
0044     Iterator (const Graphic3d_LightSet& theSet,
0045               IterationFilter theFilter = IterationFilter_None)
0046     : myIter (theSet.myLights),
0047       myFilter (theFilter)
0048     {
0049       skipFiltered();
0050     }
0051 
0052     //! Constructor with initialization.
0053     Iterator (const Handle(Graphic3d_LightSet)& theSet,
0054               IterationFilter theFilter = IterationFilter_None)
0055     : myFilter (theFilter)
0056     {
0057       if (!theSet.IsNull())
0058       {
0059         myIter = NCollection_IndexedDataMap<Handle(Graphic3d_CLight), Standard_Size>::Iterator (theSet->myLights);
0060         skipFiltered();
0061       }
0062     }
0063 
0064     //! Returns TRUE if iterator points to a valid item.
0065     Standard_Boolean More() const { return myIter.More(); }
0066 
0067     //! Returns current item.
0068     const Handle(Graphic3d_CLight)& Value() const { return myIter.Key(); }
0069 
0070     //! Moves to the next item.
0071     void Next()
0072     {
0073       myIter.Next();
0074       skipFiltered();
0075     }
0076 
0077   protected:
0078 
0079     //! Skip filtered items.
0080     void skipFiltered()
0081     {
0082       if (myFilter == 0)
0083       {
0084         return;
0085       }
0086 
0087       for (; myIter.More(); myIter.Next())
0088       {
0089         if ((myFilter & IterationFilter_ExcludeAmbient) != 0
0090          && myIter.Key()->Type() == Graphic3d_TypeOfLightSource_Ambient)
0091         {
0092           continue;
0093         }
0094         else if ((myFilter & IterationFilter_ExcludeDisabled) != 0
0095               && !myIter.Key()->IsEnabled())
0096         {
0097           continue;
0098         }
0099         else if ((myFilter & IterationFilter_ExcludeNoShadow) != 0
0100               && !myIter.Key()->ToCastShadows())
0101         {
0102           continue;
0103         }
0104 
0105         break;
0106       }
0107     }
0108 
0109   protected:
0110     NCollection_IndexedDataMap<Handle(Graphic3d_CLight), Standard_Size>::Iterator myIter;
0111     Standard_Integer myFilter;
0112   };
0113 
0114 public:
0115 
0116   //! Empty constructor.
0117   Standard_EXPORT Graphic3d_LightSet();
0118 
0119   //! Return lower light index.
0120   Standard_Integer Lower() const { return 1; }
0121 
0122   //! Return upper light index.
0123   Standard_Integer Upper() const { return myLights.Extent(); }
0124 
0125   //! Return TRUE if lights list is empty.
0126   Standard_Boolean IsEmpty() const { return myLights.IsEmpty(); }
0127 
0128   //! Return number of light sources.
0129   Standard_Integer Extent() const { return myLights.Extent(); }
0130 
0131   //! Return the light source for specified index within range [Lower(), Upper()].
0132   const Handle(Graphic3d_CLight)& Value (Standard_Integer theIndex) const { return myLights.FindKey (theIndex); }
0133 
0134   //! Return TRUE if light source is defined in this set.
0135   Standard_Boolean Contains (const Handle(Graphic3d_CLight)& theLight) const { return myLights.Contains (theLight); }
0136 
0137   //! Append new light source.
0138   Standard_EXPORT Standard_Boolean Add (const Handle(Graphic3d_CLight)& theLight);
0139 
0140   //! Remove light source.
0141   Standard_EXPORT Standard_Boolean Remove (const Handle(Graphic3d_CLight)& theLight);
0142 
0143   //! Returns total amount of lights of specified type.
0144   Standard_Integer NbLightsOfType (Graphic3d_TypeOfLightSource theType) const { return myLightTypes[theType]; }
0145 
0146 //! @name cached state of lights set updated by UpdateRevision()
0147 public:
0148 
0149   //! Update light sources revision.
0150   Standard_EXPORT Standard_Size UpdateRevision();
0151 
0152   //! Return light sources revision.
0153   //! @sa UpdateRevision()
0154   Standard_Size Revision() const { return myRevision; }
0155 
0156   //! Returns total amount of enabled lights EXCLUDING ambient.
0157   //! @sa UpdateRevision()
0158   Standard_Integer NbEnabled() const { return myNbEnabled; }
0159 
0160   //! Returns total amount of enabled lights of specified type.
0161   //! @sa UpdateRevision()
0162   Standard_Integer NbEnabledLightsOfType (Graphic3d_TypeOfLightSource theType) const { return myLightTypesEnabled[theType]; }
0163 
0164   //! Returns total amount of enabled lights castings shadows.
0165   //! @sa UpdateRevision()
0166   Standard_Integer NbCastShadows() const { return myNbCastShadows; }
0167 
0168   //! Returns cumulative ambient color, which is computed as sum of all enabled ambient light sources.
0169   //! Values are NOT clamped (can be greater than 1.0f) and alpha component is fixed to 1.0f.
0170   //! @sa UpdateRevision()
0171   const Graphic3d_Vec4& AmbientColor() const { return myAmbient; }
0172 
0173   //! Returns a string defining a list of enabled light sources as concatenation of letters 'd' (Directional), 'p' (Point), 's' (Spot)
0174   //! depending on the type of light source in the list.
0175   //! Example: "dppp".
0176   //! @sa UpdateRevision()
0177   const TCollection_AsciiString& KeyEnabledLong() const { return myKeyEnabledLong; }
0178 
0179   //! Returns a string defining a list of enabled light sources as concatenation of letters 'd' (Directional), 'p' (Point), 's' (Spot)
0180   //! depending on the type of light source in the list, specified only once.
0181   //! Example: "dp".
0182   //! @sa UpdateRevision()
0183   const TCollection_AsciiString& KeyEnabledShort() const { return myKeyEnabledShort; }
0184 
0185 protected:
0186   NCollection_IndexedDataMap<Handle(Graphic3d_CLight), Standard_Size>
0187                           myLights;                 //!< list of light sources with their cached state (revision)
0188   Graphic3d_Vec4          myAmbient;                //!< cached value of cumulative ambient color
0189   TCollection_AsciiString myKeyEnabledLong;         //!< key identifying the list of enabled light sources by their type
0190   TCollection_AsciiString myKeyEnabledShort;        //!< key identifying the list of enabled light sources by the number of sources of each type
0191   Standard_Integer        myLightTypes       [Graphic3d_TypeOfLightSource_NB]; //!< counters per each light source type defined in the list
0192   Standard_Integer        myLightTypesEnabled[Graphic3d_TypeOfLightSource_NB]; //!< counters per each light source type enabled in the list
0193   Standard_Integer        myNbEnabled;              //!< number of enabled light sources, excluding ambient
0194   Standard_Integer        myNbCastShadows;          //!< number of enabled light sources casting shadows
0195   Standard_Size           myRevision;               //!< current revision of light source set
0196   Standard_Size           myCacheRevision;          //!< revision of cached state
0197 };
0198 
0199 DEFINE_STANDARD_HANDLE(Graphic3d_LightSet, Standard_Transient)
0200 
0201 #endif // _Graphic3d_LightSet_HeaderFile