Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-14 08:30:41

0001 // Copyright (c) 2017-2019 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 _RWMesh_FaceIterator_HeaderFile
0015 #define _RWMesh_FaceIterator_HeaderFile
0016 
0017 #include <RWMesh_ShapeIterator.hxx>
0018 
0019 #include <BRepLProp_SLProps.hxx>
0020 #include <Poly_Triangulation.hxx>
0021 #include <TopoDS_Face.hxx>
0022 
0023 #include <algorithm>
0024 
0025 class TDF_Label;
0026 
0027 //! Auxiliary class to iterate through triangulated faces.
0028 //! Class is designed to provide an interface for iterating over the faces
0029 //! of a shape, specifically focusing on triangulated faces.
0030 //! It inherits from the `RWMesh_ShapeIterator` base class and
0031 //! extends its functionality to handle faces with triangulation data.
0032 class RWMesh_FaceIterator : public RWMesh_ShapeIterator
0033 {
0034 public:
0035   //! Main constructor.
0036   //! @param[in] theLabel Label containing the face data
0037   //! @param[in] theLocation Location of the face
0038   //! @param[in] theToMapColors Flag to indicate if colors should be mapped
0039   //! @param[in] theStyle Style information for the face
0040   Standard_EXPORT RWMesh_FaceIterator(const TDF_Label&       theLabel,
0041                                       const TopLoc_Location& theLocation,
0042                                       const Standard_Boolean theToMapColors = false,
0043                                       const XCAFPrs_Style&   theStyle       = XCAFPrs_Style());
0044 
0045   //! Auxiliary constructor.
0046   //! @param[in] theShape Shape containing the face data
0047   //! @param[in] theStyle Style information for the face
0048   Standard_EXPORT RWMesh_FaceIterator(const TopoDS_Shape&  theShape,
0049                                       const XCAFPrs_Style& theStyle = XCAFPrs_Style());
0050 
0051   //! Return true if iterator points to the valid triangulation.
0052   bool More() const Standard_OVERRIDE { return !myPolyTriang.IsNull(); }
0053 
0054   //! Find next value.
0055   Standard_EXPORT void Next() Standard_OVERRIDE;
0056 
0057   //! Return current face.
0058   const TopoDS_Face& Face() const { return myFace; }
0059 
0060   //! Return current face.
0061   const TopoDS_Shape& Shape() const Standard_OVERRIDE { return myFace; }
0062 
0063   //! Return current face triangulation.
0064   const Handle(Poly_Triangulation)& Triangulation() const { return myPolyTriang; }
0065 
0066   //! Return true if mesh data is defined.
0067   bool IsEmptyMesh() const { return IsEmpty(); }
0068 
0069   //! Return true if mesh data is defined.
0070   bool IsEmpty() const Standard_OVERRIDE
0071   {
0072     return myPolyTriang.IsNull()
0073            || (myPolyTriang->NbNodes() < 1 && myPolyTriang->NbTriangles() < 1);
0074   }
0075 
0076 public:
0077   //! Return face material.
0078   const XCAFPrs_Style& FaceStyle() const { return myStyle; }
0079 
0080   //! Return TRUE if face color is set.
0081   bool HasFaceColor() const { return myHasColor; }
0082 
0083   //! Return face color.
0084   const Quantity_ColorRGBA& FaceColor() const { return myColor; }
0085 
0086 public:
0087   //! Return number of elements of specific type for the current face.
0088   Standard_Integer NbTriangles() const { return myPolyTriang->NbTriangles(); }
0089 
0090   //! Lower element index in current triangulation.
0091   Standard_Integer ElemLower() const Standard_OVERRIDE { return 1; }
0092 
0093   //! Upper element index in current triangulation.
0094   Standard_Integer ElemUpper() const Standard_OVERRIDE { return myPolyTriang->NbTriangles(); }
0095 
0096   //! Return triangle with specified index with applied Face orientation.
0097   Poly_Triangle TriangleOriented(Standard_Integer theElemIndex) const
0098   {
0099     Poly_Triangle aTri = triangle(theElemIndex);
0100     if ((myFace.Orientation() == TopAbs_REVERSED) ^ myIsMirrored)
0101     {
0102       return Poly_Triangle(aTri.Value(1), aTri.Value(3), aTri.Value(2));
0103     }
0104     return aTri;
0105   }
0106 
0107 public:
0108   //! Return true if triangulation has defined normals.
0109   bool HasNormals() const { return myHasNormals; }
0110 
0111   //! Return true if triangulation has defined normals.
0112   bool HasTexCoords() const { return !myPolyTriang.IsNull() && myPolyTriang->HasUVNodes(); }
0113 
0114   //! Return normal at specified node index with face transformation applied and face orientation
0115   //! applied.
0116   gp_Dir NormalTransformed(Standard_Integer theNode) const
0117   {
0118     gp_Dir aNorm = normal(theNode);
0119     if (myTrsf.Form() != gp_Identity)
0120     {
0121       aNorm.Transform(myTrsf);
0122     }
0123     if (myFace.Orientation() == TopAbs_REVERSED)
0124     {
0125       aNorm.Reverse();
0126     }
0127     return aNorm;
0128   }
0129 
0130   //! Return number of nodes for the current face.
0131   Standard_Integer NbNodes() const Standard_OVERRIDE
0132   {
0133     return !myPolyTriang.IsNull() ? myPolyTriang->NbNodes() : 0;
0134   }
0135 
0136   //! Lower node index in current triangulation.
0137   Standard_Integer NodeLower() const Standard_OVERRIDE { return 1; }
0138 
0139   //! Upper node index in current triangulation.
0140   Standard_Integer NodeUpper() const Standard_OVERRIDE { return myPolyTriang->NbNodes(); }
0141 
0142   //! Return texture coordinates for the node.
0143   gp_Pnt2d NodeTexCoord(const Standard_Integer theNode) const
0144   {
0145     return myPolyTriang->HasUVNodes() ? myPolyTriang->UVNode(theNode) : gp_Pnt2d();
0146   }
0147 
0148 public:
0149   //! Return the node with specified index with applied transformation.
0150   gp_Pnt node(const Standard_Integer theNode) const Standard_OVERRIDE
0151   {
0152     return myPolyTriang->Node(theNode);
0153   }
0154 
0155   //! Return normal at specified node index without face transformation applied.
0156   Standard_EXPORT gp_Dir normal(Standard_Integer theNode) const;
0157 
0158   //! Return triangle with specified index.
0159   Poly_Triangle triangle(Standard_Integer theElemIndex) const
0160   {
0161     return myPolyTriang->Triangle(theElemIndex);
0162   }
0163 
0164 private:
0165   //! Reset information for current face.
0166   void resetFace()
0167   {
0168     myPolyTriang.Nullify();
0169     myFace.Nullify();
0170     myHasNormals = false;
0171     resetShape();
0172   }
0173 
0174   //! Initialize face properties.
0175   void initFace();
0176 
0177 private:
0178   // clang-format off
0179   TopoDS_Face                myFace;        //!< current face
0180   Handle(Poly_Triangulation) myPolyTriang;  //!< triangulation of current face
0181   mutable BRepLProp_SLProps  mySLTool;      //!< auxiliary tool for fetching normals from surface
0182   BRepAdaptor_Surface        myFaceAdaptor; //!< surface adaptor for fetching normals from surface
0183   Standard_Boolean           myHasNormals;  //!< flag indicating that current face has normals
0184   Standard_Boolean           myIsMirrored;  //!< flag indicating that face triangles should be mirrored
0185   // clang-format on
0186 };
0187 
0188 #endif // _RWMesh_FaceIterator_HeaderFile