Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:43

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 <BRepLProp_SLProps.hxx>
0018 #include <gp_Trsf.hxx>
0019 #include <NCollection_DataMap.hxx>
0020 #include <Poly_Triangulation.hxx>
0021 #include <TopExp_Explorer.hxx>
0022 #include <TopoDS_Face.hxx>
0023 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
0024 #include <XCAFPrs_Style.hxx>
0025 
0026 #include <algorithm>
0027 
0028 class TDF_Label;
0029 
0030 //! Auxiliary class to iterate through triangulated faces.
0031 class RWMesh_FaceIterator
0032 {
0033 public:
0034 
0035   //! Main constructor.
0036   Standard_EXPORT RWMesh_FaceIterator (const TDF_Label&       theLabel,
0037                                        const TopLoc_Location& theLocation,
0038                                        const Standard_Boolean theToMapColors = false,
0039                                        const XCAFPrs_Style&   theStyle = XCAFPrs_Style());
0040 
0041   //! Auxiliary constructor.
0042   Standard_EXPORT RWMesh_FaceIterator (const TopoDS_Shape&  theShape,
0043                                        const XCAFPrs_Style& theStyle = XCAFPrs_Style());
0044 
0045   //! Return explored shape.
0046   const TopoDS_Shape& ExploredShape() const { return myFaceIter.ExploredShape(); }
0047 
0048   //! Return true if iterator points to the valid triangulation.
0049   bool More() const { return !myPolyTriang.IsNull(); }
0050 
0051   //! Find next value.
0052   Standard_EXPORT void Next();
0053 
0054   //! Return current face.
0055   const TopoDS_Face& Face() const { return myFace; }
0056 
0057   //! Return current face triangulation.
0058   const Handle(Poly_Triangulation)& Triangulation() const { return myPolyTriang; }
0059 
0060   //! Return true if mesh data is defined.
0061   bool IsEmptyMesh() const
0062   {
0063     return myPolyTriang.IsNull()
0064        || (myPolyTriang->NbNodes() < 1 && myPolyTriang->NbTriangles() < 1);
0065   }
0066 
0067 public:
0068 
0069   //! Return face material.
0070   const XCAFPrs_Style& FaceStyle() const { return myFaceStyle; }
0071 
0072   //! Return TRUE if face color is set.
0073   bool HasFaceColor() const { return myHasFaceColor; }
0074 
0075   //! Return face color.
0076   const Quantity_ColorRGBA& FaceColor() const { return myFaceColor; }
0077 
0078 public:
0079 
0080   //! Return number of elements of specific type for the current face.
0081   Standard_Integer NbTriangles() const { return myPolyTriang->NbTriangles(); }
0082 
0083   //! Lower element index in current triangulation.
0084   Standard_Integer ElemLower() const { return 1; }
0085 
0086   //! Upper element index in current triangulation.
0087   Standard_Integer ElemUpper() const { return myPolyTriang->NbTriangles(); }
0088 
0089   //! Return triangle with specified index with applied Face orientation.
0090   Poly_Triangle TriangleOriented (Standard_Integer theElemIndex) const
0091   {
0092     Poly_Triangle aTri = triangle (theElemIndex);
0093     if ((myFace.Orientation() == TopAbs_REVERSED) ^ myIsMirrored)
0094     {
0095       return Poly_Triangle (aTri.Value (1), aTri.Value (3), aTri.Value (2));
0096     }
0097     return aTri;
0098   }
0099 
0100 public:
0101 
0102   //! Return true if triangulation has defined normals.
0103   bool HasNormals() const { return myHasNormals; }
0104 
0105   //! Return true if triangulation has defined normals.
0106   bool HasTexCoords() const { return !myPolyTriang.IsNull() && myPolyTriang->HasUVNodes(); }
0107 
0108   //! Return normal at specified node index with face transformation applied and face orientation applied.
0109   gp_Dir NormalTransformed (Standard_Integer theNode) const
0110   {
0111     gp_Dir aNorm = normal (theNode);
0112     if (myTrsf.Form() != gp_Identity)
0113     {
0114       aNorm.Transform (myTrsf);
0115     }
0116     if (myFace.Orientation() == TopAbs_REVERSED)
0117     {
0118       aNorm.Reverse();
0119     }
0120     return aNorm;
0121   }
0122 
0123   //! Return number of nodes for the current face.
0124   Standard_Integer NbNodes() const
0125   {
0126     return !myPolyTriang.IsNull()
0127           ? myPolyTriang->NbNodes()
0128           : 0;
0129   }
0130 
0131   //! Lower node index in current triangulation.
0132   Standard_Integer NodeLower() const { return 1; }
0133 
0134   //! Upper node index in current triangulation.
0135   Standard_Integer NodeUpper() const { return myPolyTriang->NbNodes(); }
0136 
0137   //! Return the node with specified index with applied transformation.
0138   gp_Pnt NodeTransformed (const Standard_Integer theNode) const
0139   {
0140     gp_Pnt aNode = node (theNode);
0141     aNode.Transform (myTrsf);
0142     return aNode;
0143   }
0144 
0145   //! Return texture coordinates for the node.
0146   gp_Pnt2d NodeTexCoord (const Standard_Integer theNode) const
0147   {
0148     return myPolyTriang->HasUVNodes() ? myPolyTriang->UVNode (theNode) : gp_Pnt2d();
0149   }
0150 
0151 public:
0152 
0153   //! Return the node with specified index with applied transformation.
0154   gp_Pnt node (const Standard_Integer theNode) const { return myPolyTriang->Node (theNode); }
0155 
0156   //! Return normal at specified node index without face transformation applied.
0157   Standard_EXPORT gp_Dir normal (Standard_Integer theNode) const;
0158 
0159   //! Return triangle with specified index.
0160   Poly_Triangle triangle (Standard_Integer theElemIndex) const { return myPolyTriang->Triangle (theElemIndex); }
0161 
0162 private:
0163 
0164   //! Dispatch face styles.
0165   void dispatchStyles (const TDF_Label&       theLabel,
0166                        const TopLoc_Location& theLocation,
0167                        const XCAFPrs_Style&   theStyle);
0168 
0169   //! Reset information for current face.
0170   void resetFace()
0171   {
0172     myPolyTriang.Nullify();
0173     myFace.Nullify();
0174     myHasNormals = false;
0175     myHasFaceColor = false;
0176     myFaceColor = Quantity_ColorRGBA();
0177     myFaceStyle = XCAFPrs_Style();
0178   }
0179 
0180   //! Initialize face properties.
0181   void initFace();
0182 
0183 private:
0184 
0185   NCollection_DataMap<TopoDS_Shape, XCAFPrs_Style, TopTools_ShapeMapHasher>
0186                                   myStyles;       //!< Face -> Style map
0187   XCAFPrs_Style                   myDefStyle;     //!< default style for faces without dedicated style
0188   Standard_Boolean                myToMapColors;  //!< flag to dispatch styles
0189 
0190   TopExp_Explorer                 myFaceIter;     //!< face explorer
0191   TopoDS_Face                     myFace;         //!< current face
0192   Handle(Poly_Triangulation)      myPolyTriang;   //!< triangulation of current face
0193   TopLoc_Location                 myFaceLocation; //!< current face location
0194   mutable BRepLProp_SLProps       mySLTool;       //!< auxiliary tool for fetching normals from surface
0195   BRepAdaptor_Surface             myFaceAdaptor;  //!< surface adaptor for fetching normals from surface
0196   Standard_Boolean                myHasNormals;   //!< flag indicating that current face has normals
0197   gp_Trsf                         myTrsf;         //!< current face transformation
0198   Standard_Boolean                myIsMirrored;   //!< flag indicating that face triangles should be mirrored
0199   XCAFPrs_Style                   myFaceStyle;    //!< current face style
0200   Quantity_ColorRGBA              myFaceColor;    //!< current face color
0201   Standard_Boolean                myHasFaceColor; //!< flag indicating that current face has assigned color
0202 
0203 };
0204 
0205 #endif // _RWMesh_FaceIterator_HeaderFile