Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created by: NW,JPB,CAL
0002 // Copyright (c) 1991-1999 Matra Datavision
0003 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Graphic3d_MaterialAspect_HeaderFile
0017 #define _Graphic3d_MaterialAspect_HeaderFile
0018 
0019 #include <Graphic3d_BSDF.hxx>
0020 #include <Graphic3d_PBRMaterial.hxx>
0021 #include <Graphic3d_NameOfMaterial.hxx>
0022 #include <Graphic3d_TypeOfMaterial.hxx>
0023 #include <Graphic3d_TypeOfReflection.hxx>
0024 #include <TCollection_AsciiString.hxx>
0025 #include <Quantity_Color.hxx>
0026 
0027 //! This class allows the definition of the type of a surface.
0028 //! Aspect attributes of a 3d face.
0029 //! Keywords: Material, FillArea, Shininess, Ambient, Color, Diffuse,
0030 //! Specular, Transparency, Emissive, ReflectionMode,
0031 //! BackFace, FrontFace, Reflection, Absorption
0032 class Graphic3d_MaterialAspect 
0033 {
0034 public:
0035   DEFINE_STANDARD_ALLOC
0036 
0037   //! Returns the number of predefined textures.
0038   static Standard_Integer NumberOfMaterials() { return Graphic3d_NameOfMaterial_DEFAULT; }
0039 
0040   //! Returns the name of the predefined material of specified rank within range [1, NumberOfMaterials()].
0041   Standard_EXPORT static Standard_CString MaterialName (const Standard_Integer theRank);
0042 
0043   //! Returns the type of the predefined material of specified rank within range [1, NumberOfMaterials()].
0044   Standard_EXPORT static Graphic3d_TypeOfMaterial MaterialType (const Standard_Integer theRank);
0045 
0046   //! Finds the material for specified name.
0047   //! @param theName [in]  name to find
0048   //! @param theMat  [out] found material
0049   //! @return FALSE if name was unrecognized
0050   Standard_EXPORT static Standard_Boolean MaterialFromName (const Standard_CString theName,
0051                                                             Graphic3d_NameOfMaterial& theMat);
0052 
0053   //! Returns the material for specified name or Graphic3d_NameOfMaterial_DEFAULT if name is unknown.
0054   static Graphic3d_NameOfMaterial MaterialFromName (const Standard_CString theName)
0055   {
0056     Graphic3d_NameOfMaterial aMat = Graphic3d_NameOfMaterial_DEFAULT;
0057     MaterialFromName (theName, aMat);
0058     return aMat;
0059   }
0060 
0061 public:
0062 
0063   //! Creates a material from default values.
0064   Standard_EXPORT Graphic3d_MaterialAspect();
0065 
0066   //! Creates a generic material.
0067   Standard_EXPORT Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial theName);
0068 
0069   //! Returns the material name (within predefined enumeration).
0070   Graphic3d_NameOfMaterial Name() const { return myMaterialName; }
0071 
0072   //! Returns the material name within predefined enumeration which has been requested (before modifications).
0073   Graphic3d_NameOfMaterial RequestedName() const { return myRequestedMaterialName; }
0074 
0075   //! Returns the given name of this material. This might be:
0076   //! - given name set by method ::SetMaterialName()
0077   //! - standard name for a material within enumeration
0078   //! - "UserDefined" for non-standard material without name specified externally.
0079   const TCollection_AsciiString& StringName() const { return myStringName; }
0080 
0081   //! Returns the given name of this material. This might be:
0082   Standard_CString MaterialName() const { return myStringName.ToCString(); }
0083 
0084   //! The current material become a "UserDefined" material.
0085   //! Set the name of the "UserDefined" material.
0086   void SetMaterialName (const TCollection_AsciiString& theName)
0087   {
0088     // if a component of a "standard" material change, the
0089     // result is no more standard (a blue gold is not a gold)
0090     myMaterialName = Graphic3d_NameOfMaterial_UserDefined;
0091     myStringName   = theName;
0092   }
0093 
0094   //! Resets the material with the original values according to
0095   //! the material name but leave the current color values untouched
0096   //! for the material of type ASPECT.
0097   void Reset()
0098   {
0099     init (myRequestedMaterialName);
0100   }
0101 
0102   //! Returns the diffuse color of the surface.
0103   //! WARNING! This method does NOT return color for Graphic3d_MATERIAL_ASPECT material (color is defined by Graphic3d_Aspects::InteriorColor()).
0104   const Quantity_Color& Color() const { return myColors[Graphic3d_TOR_DIFFUSE]; }
0105 
0106   //! Modifies the ambient and diffuse color of the surface.
0107   //! WARNING! Has no effect for Graphic3d_MATERIAL_ASPECT material (color should be set to Graphic3d_Aspects::SetInteriorColor()).
0108   Standard_EXPORT void SetColor (const Quantity_Color& theColor);
0109 
0110   //! Returns the transparency coefficient of the surface (1.0 - Alpha); 0.0 means opaque.
0111   Standard_ShortReal Transparency() const { return myTransparencyCoef; }
0112 
0113   //! Returns the alpha coefficient of the surface (1.0 - Transparency); 1.0 means opaque.
0114   Standard_ShortReal Alpha() const { return 1.0f - myTransparencyCoef; }
0115 
0116   //! Modifies the transparency coefficient of the surface, where 0 is opaque and 1 is fully transparent.
0117   //! Transparency is applicable to materials that have at least one of reflection modes (ambient, diffuse, specular or emissive) enabled.
0118   //! See also SetReflectionModeOn() and SetReflectionModeOff() methods.
0119   //!
0120   //! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0.
0121   Standard_EXPORT void SetTransparency (const Standard_ShortReal theValue);
0122 
0123   //! Modifies the alpha coefficient of the surface, where 1.0 is opaque and 0.0 is fully transparent.
0124   void SetAlpha (Standard_ShortReal theValue) { SetTransparency (1.0f - theValue); }
0125 
0126   //! Returns the ambient color of the surface.
0127   const Quantity_Color& AmbientColor() const { return myColors[Graphic3d_TOR_AMBIENT]; }
0128 
0129   //! Modifies the ambient color of the surface.
0130   Standard_EXPORT void SetAmbientColor (const Quantity_Color& theColor);
0131 
0132   //! Returns the diffuse color of the surface.
0133   const Quantity_Color& DiffuseColor() const { return myColors[Graphic3d_TOR_DIFFUSE]; }
0134 
0135   //! Modifies the diffuse color of the surface.
0136   Standard_EXPORT void SetDiffuseColor (const Quantity_Color& theColor);
0137 
0138   //! Returns the specular color of the surface.
0139   const Quantity_Color& SpecularColor() const { return myColors[Graphic3d_TOR_SPECULAR]; }
0140 
0141   //! Modifies the specular color of the surface.
0142   Standard_EXPORT void SetSpecularColor (const Quantity_Color& theColor);
0143 
0144   //! Returns the emissive color of the surface.
0145   const Quantity_Color& EmissiveColor() const { return myColors[Graphic3d_TOR_EMISSION]; }
0146 
0147   //! Modifies the emissive color of the surface.
0148   Standard_EXPORT void SetEmissiveColor (const Quantity_Color& theColor);
0149 
0150   //! Returns the luminosity of the surface.
0151   Standard_ShortReal Shininess() const { return myShininess; }
0152 
0153   //! Modifies the luminosity of the surface.
0154   //! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0.
0155   Standard_EXPORT void SetShininess (const Standard_ShortReal theValue);
0156 
0157   //! Increases or decreases the luminosity.
0158   //! @param theDelta a signed percentage
0159   Standard_EXPORT void IncreaseShine (const Standard_ShortReal theDelta);
0160 
0161   //! Returns the refraction index of the material
0162   Standard_ShortReal RefractionIndex() const { return myRefractionIndex; }
0163 
0164   //! Modifies the refraction index of the material.
0165   //! Warning: Raises MaterialDefinitionError if given value is a lesser than 1.0.
0166   Standard_EXPORT void SetRefractionIndex (const Standard_ShortReal theValue);
0167 
0168   //! Returns BSDF (bidirectional scattering distribution function).
0169   const Graphic3d_BSDF& BSDF() const { return myBSDF; }
0170 
0171   //! Modifies the BSDF (bidirectional scattering distribution function).
0172   void SetBSDF (const Graphic3d_BSDF& theBSDF) { myBSDF = theBSDF; }
0173 
0174   //! Returns physically based representation of material
0175   const Graphic3d_PBRMaterial& PBRMaterial () const { return myPBRMaterial; }
0176 
0177   //! Modifies the physically based representation of material
0178   void SetPBRMaterial (const Graphic3d_PBRMaterial& thePBRMaterial) { myPBRMaterial = thePBRMaterial; }
0179 
0180   //! Returns TRUE if the reflection mode is active, FALSE otherwise.
0181   Standard_Boolean ReflectionMode (const Graphic3d_TypeOfReflection theType) const
0182   {
0183     return !myColors[theType].IsEqual (Quantity_NOC_BLACK);
0184   }
0185 
0186   //! Returns material type.
0187   Graphic3d_TypeOfMaterial MaterialType() const { return myMaterialType; }
0188 
0189   //! Returns TRUE if type of this material is equal to specified type.
0190   Standard_Boolean MaterialType (const Graphic3d_TypeOfMaterial theType) const { return myMaterialType == theType; }
0191 
0192   //! Set material type.
0193   Standard_EXPORT void SetMaterialType (const Graphic3d_TypeOfMaterial theType);
0194 
0195   //! Returns TRUE if this material differs from specified one.
0196   Standard_Boolean IsDifferent (const Graphic3d_MaterialAspect& theOther) const { return !IsEqual (theOther); }
0197 
0198   //! Returns TRUE if this material differs from specified one.
0199   Standard_Boolean operator!= (const Graphic3d_MaterialAspect& theOther) const { return IsDifferent (theOther); }
0200   
0201   //! Returns TRUE if this material is identical to specified one.
0202   Standard_Boolean IsEqual (const Graphic3d_MaterialAspect& theOther) const
0203   {
0204     return myTransparencyCoef == theOther.myTransparencyCoef
0205         && myRefractionIndex  == theOther.myRefractionIndex
0206         && myBSDF             == theOther.myBSDF
0207         && myPBRMaterial      == theOther.myPBRMaterial
0208         && myShininess        == theOther.myShininess
0209         && myColors[Graphic3d_TOR_AMBIENT]  == theOther.myColors[Graphic3d_TOR_AMBIENT]
0210         && myColors[Graphic3d_TOR_DIFFUSE]  == theOther.myColors[Graphic3d_TOR_DIFFUSE]
0211         && myColors[Graphic3d_TOR_SPECULAR] == theOther.myColors[Graphic3d_TOR_SPECULAR]
0212         && myColors[Graphic3d_TOR_EMISSION] == theOther.myColors[Graphic3d_TOR_EMISSION];
0213   }
0214 
0215   //! Returns TRUE if this material is identical to specified one.
0216   Standard_Boolean operator== (const Graphic3d_MaterialAspect& theOther) const { return IsEqual (theOther); }
0217 
0218   //! Dumps the content of me into the stream
0219   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0220 
0221 public:
0222 
0223   //! Deactivates the reflective properties of the surface with specified reflection type.
0224   Standard_DEPRECATED("Deprecated method, specific material component should be zerroed instead")
0225   void SetReflectionModeOff (const Graphic3d_TypeOfReflection theType)
0226   {
0227     if (!ReflectionMode (theType))
0228     {
0229       return;
0230     }
0231 
0232     switch (theType)
0233     {
0234       case Graphic3d_TOR_AMBIENT:  SetAmbientColor (Quantity_NOC_BLACK); break;
0235       case Graphic3d_TOR_DIFFUSE:  SetDiffuseColor (Quantity_NOC_BLACK); break;
0236       case Graphic3d_TOR_SPECULAR: SetSpecularColor(Quantity_NOC_BLACK); break;
0237       case Graphic3d_TOR_EMISSION: SetEmissiveColor(Quantity_NOC_BLACK); break;
0238     }
0239   }
0240 
0241 private:
0242 
0243   //! Initialize the standard material.
0244   Standard_EXPORT void init (const Graphic3d_NameOfMaterial theName);
0245 
0246   //! Mark material as user defined.
0247   void setUserMaterial()
0248   {
0249     // if a component of a "standard" material change, the
0250     // result is no more standard (a blue gold is not a gold)
0251     if (myMaterialName != Graphic3d_NameOfMaterial_UserDefined)
0252     {
0253       myMaterialName = Graphic3d_NameOfMaterial_UserDefined;
0254       myStringName   = "UserDefined";
0255     }
0256   }
0257 
0258 private:
0259 
0260   Graphic3d_BSDF           myBSDF;
0261   Graphic3d_PBRMaterial    myPBRMaterial;
0262   TCollection_AsciiString  myStringName;
0263   Quantity_Color           myColors[Graphic3d_TypeOfReflection_NB];
0264   Standard_ShortReal       myTransparencyCoef;
0265   Standard_ShortReal       myRefractionIndex;
0266   Standard_ShortReal       myShininess;
0267 
0268   Graphic3d_TypeOfMaterial myMaterialType;
0269   Graphic3d_NameOfMaterial myMaterialName;
0270   Graphic3d_NameOfMaterial myRequestedMaterialName;
0271 
0272 };
0273 
0274 #endif // _Graphic3d_MaterialAspect_HeaderFile