Back to home page

EIC code displayed by LXR

 
 

    


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

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