Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:17:51

0001 // Copyright (c) 2014 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_ZLayerSettings_HeaderFile
0015 #define _Graphic3d_ZLayerSettings_HeaderFile
0016 
0017 #include <gp_XYZ.hxx>
0018 #include <TopLoc_Datum3D.hxx>
0019 #include <Graphic3d_LightSet.hxx>
0020 #include <Graphic3d_PolygonOffset.hxx>
0021 #include <Precision.hxx>
0022 #include <Standard_Dump.hxx>
0023 #include <TCollection_AsciiString.hxx>
0024 
0025 //! Structure defines list of ZLayer properties.
0026 struct Graphic3d_ZLayerSettings
0027 {
0028 
0029   //! Default settings.
0030   Graphic3d_ZLayerSettings()
0031       : myCullingDistance(Precision::Infinite()),
0032         myCullingSize(Precision::Infinite()),
0033         myIsImmediate(false),
0034         myToRaytrace(true),
0035         myUseEnvironmentTexture(true),
0036         myToEnableDepthTest(true),
0037         myToEnableDepthWrite(true),
0038         myToClearDepth(true),
0039         myToRenderInDepthPrepass(true)
0040   {
0041   }
0042 
0043   //! Return user-provided name.
0044   const TCollection_AsciiString& Name() const { return myName; }
0045 
0046   //! Set custom name.
0047   void SetName(const TCollection_AsciiString& theName) { myName = theName; }
0048 
0049   //! Return lights list to be used for rendering presentations within this Z-Layer; NULL by
0050   //! default. NULL list (but not empty list!) means that default lights assigned to the View should
0051   //! be used instead of per-layer lights.
0052   const occ::handle<Graphic3d_LightSet>& Lights() const { return myLights; }
0053 
0054   //! Assign lights list to be used.
0055   void SetLights(const occ::handle<Graphic3d_LightSet>& theLights) { myLights = theLights; }
0056 
0057   //! Return the origin of all objects within the layer.
0058   const gp_XYZ& Origin() const { return myOrigin; }
0059 
0060   //! Return the transformation to the origin.
0061   const occ::handle<TopLoc_Datum3D>& OriginTransformation() const { return myOriginTrsf; }
0062 
0063   //! Set the origin of all objects within the layer.
0064   void SetOrigin(const gp_XYZ& theOrigin)
0065   {
0066     myOrigin = theOrigin;
0067     myOriginTrsf.Nullify();
0068     if (!theOrigin.IsEqual(gp_XYZ(0.0, 0.0, 0.0), gp::Resolution()))
0069     {
0070       gp_Trsf aTrsf;
0071       aTrsf.SetTranslation(theOrigin);
0072       myOriginTrsf = new TopLoc_Datum3D(aTrsf);
0073     }
0074   }
0075 
0076   //! Return TRUE, if culling of distant objects (distance culling) should be performed; FALSE by
0077   //! default.
0078   //! @sa CullingDistance()
0079   bool HasCullingDistance() const
0080   {
0081     return !Precision::IsInfinite(myCullingDistance) && myCullingDistance > 0.0;
0082   }
0083 
0084   //! Return the distance to discard drawing of distant objects (distance from camera Eye point); by
0085   //! default it is Infinite (distance culling is disabled). Since camera eye definition has no
0086   //! strong meaning within orthographic projection, option is considered only within perspective
0087   //! projection. Note also that this option has effect only when frustum culling is enabled.
0088   double CullingDistance() const { return myCullingDistance; }
0089 
0090   //! Set the distance to discard drawing objects.
0091   void SetCullingDistance(double theDistance) { myCullingDistance = theDistance; }
0092 
0093   //! Return TRUE, if culling of small objects (size culling) should be performed; FALSE by default.
0094   //! @sa CullingSize()
0095   bool HasCullingSize() const
0096   {
0097     return !Precision::IsInfinite(myCullingSize) && myCullingSize > 0.0;
0098   }
0099 
0100   //! Return the size to discard drawing of small objects; by default it is Infinite (size culling
0101   //! is disabled). Current implementation checks the length of projected diagonal of bounding box
0102   //! in pixels for discarding. Note that this option has effect only when frustum culling is
0103   //! enabled.
0104   double CullingSize() const { return myCullingSize; }
0105 
0106   //! Set the distance to discard drawing objects.
0107   void SetCullingSize(double theSize) { myCullingSize = theSize; }
0108 
0109   //! Return true if this layer should be drawn after all normal (non-immediate) layers.
0110   bool IsImmediate() const { return myIsImmediate; }
0111 
0112   //! Set the flag indicating the immediate layer, which should be drawn after all normal
0113   //! (non-immediate) layers.
0114   void SetImmediate(const bool theValue) { myIsImmediate = theValue; }
0115 
0116   //! Returns TRUE if layer should be processed by ray-tracing renderer; TRUE by default.
0117   //! Note that this flag is IGNORED for layers with IsImmediate() flag.
0118   bool IsRaytracable() const { return myToRaytrace; }
0119 
0120   //! Sets if layer should be processed by ray-tracing renderer.
0121   void SetRaytracable(bool theToRaytrace) { myToRaytrace = theToRaytrace; }
0122 
0123   //! Return flag to allow/prevent environment texture mapping usage for specific layer.
0124   bool UseEnvironmentTexture() const { return myUseEnvironmentTexture; }
0125 
0126   //! Set the flag to allow/prevent environment texture mapping usage for specific layer.
0127   void SetEnvironmentTexture(const bool theValue) { myUseEnvironmentTexture = theValue; }
0128 
0129   //! Return true if depth test should be enabled.
0130   bool ToEnableDepthTest() const { return myToEnableDepthTest; }
0131 
0132   //! Set if depth test should be enabled.
0133   void SetEnableDepthTest(const bool theValue) { myToEnableDepthTest = theValue; }
0134 
0135   //! Return true depth values should be written during rendering.
0136   bool ToEnableDepthWrite() const { return myToEnableDepthWrite; }
0137 
0138   //! Set if depth values should be written during rendering.
0139   void SetEnableDepthWrite(const bool theValue) { myToEnableDepthWrite = theValue; }
0140 
0141   //! Return true if depth values should be cleared before drawing the layer.
0142   bool ToClearDepth() const { return myToClearDepth; }
0143 
0144   //! Set if depth values should be cleared before drawing the layer.
0145   void SetClearDepth(const bool theValue) { myToClearDepth = theValue; }
0146 
0147   //! Return TRUE if layer should be rendered within depth pre-pass; TRUE by default.
0148   bool ToRenderInDepthPrepass() const { return myToRenderInDepthPrepass; }
0149 
0150   //! Set if layer should be rendered within depth pre-pass.
0151   void SetRenderInDepthPrepass(bool theToRender) { myToRenderInDepthPrepass = theToRender; }
0152 
0153   //! Return glPolygonOffset() arguments.
0154   const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
0155 
0156   //! Setup glPolygonOffset() arguments.
0157   void SetPolygonOffset(const Graphic3d_PolygonOffset& theParams) { myPolygonOffset = theParams; }
0158 
0159   //! Modify glPolygonOffset() arguments.
0160   Graphic3d_PolygonOffset& ChangePolygonOffset() { return myPolygonOffset; }
0161 
0162   //! Sets minimal possible positive depth offset.
0163   void SetDepthOffsetPositive()
0164   {
0165     myPolygonOffset.Mode   = Aspect_POM_Fill;
0166     myPolygonOffset.Factor = 1.0f;
0167     myPolygonOffset.Units  = 1.0f;
0168   }
0169 
0170   //! Sets minimal possible negative depth offset.
0171   void SetDepthOffsetNegative()
0172   {
0173     myPolygonOffset.Mode   = Aspect_POM_Fill;
0174     myPolygonOffset.Factor = 1.0f;
0175     myPolygonOffset.Units  = -1.0f;
0176   }
0177 
0178   //! Dumps the content of me into the stream
0179   void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const
0180   {
0181     OCCT_DUMP_CLASS_BEGIN(theOStream, Graphic3d_ZLayerSettings)
0182 
0183     OCCT_DUMP_FIELD_VALUE_STRING(theOStream, myName)
0184     OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, myOriginTrsf.get())
0185     OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myOrigin)
0186 
0187     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myCullingDistance)
0188     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myCullingSize)
0189 
0190     OCCT_DUMP_FIELD_VALUES_DUMPED(theOStream, theDepth, &myPolygonOffset)
0191 
0192     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myIsImmediate)
0193     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myToRaytrace)
0194     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myUseEnvironmentTexture)
0195     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myToEnableDepthTest)
0196     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myToEnableDepthWrite)
0197     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myToClearDepth)
0198     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myToRenderInDepthPrepass)
0199   }
0200 
0201 protected:
0202   TCollection_AsciiString         myName;       //!< user-provided name
0203   occ::handle<Graphic3d_LightSet> myLights;     //!< lights list
0204   occ::handle<TopLoc_Datum3D>     myOriginTrsf; //!< transformation to the origin
0205   // clang-format off
0206   gp_XYZ                      myOrigin;                //!< the origin of all objects within the layer
0207   double               myCullingDistance;       //!< distance to discard objects
0208   double               myCullingSize;           //!< size to discard objects
0209   Graphic3d_PolygonOffset     myPolygonOffset;         //!< glPolygonOffset() arguments
0210   bool            myIsImmediate;           //!< immediate layer will be drawn after all normal layers
0211   bool            myToRaytrace;            //!< option to render layer within ray-tracing engine
0212   bool            myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer
0213   bool            myToEnableDepthTest;     //!< option to enable depth test
0214   bool            myToEnableDepthWrite;    //!< option to enable write depth values
0215   bool            myToClearDepth;          //!< option to clear depth values before drawing the layer
0216   bool            myToRenderInDepthPrepass;//!< option to render layer within depth pre-pass
0217   // clang-format on
0218 };
0219 
0220 #endif // _Graphic3d_ZLayerSettings_HeaderFile