File indexing completed on 2025-01-18 10:04:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0031 class RWMesh_FaceIterator
0032 {
0033 public:
0034
0035
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
0042 Standard_EXPORT RWMesh_FaceIterator (const TopoDS_Shape& theShape,
0043 const XCAFPrs_Style& theStyle = XCAFPrs_Style());
0044
0045
0046 const TopoDS_Shape& ExploredShape() const { return myFaceIter.ExploredShape(); }
0047
0048
0049 bool More() const { return !myPolyTriang.IsNull(); }
0050
0051
0052 Standard_EXPORT void Next();
0053
0054
0055 const TopoDS_Face& Face() const { return myFace; }
0056
0057
0058 const Handle(Poly_Triangulation)& Triangulation() const { return myPolyTriang; }
0059
0060
0061 bool IsEmptyMesh() const
0062 {
0063 return myPolyTriang.IsNull()
0064 || (myPolyTriang->NbNodes() < 1 && myPolyTriang->NbTriangles() < 1);
0065 }
0066
0067 public:
0068
0069
0070 const XCAFPrs_Style& FaceStyle() const { return myFaceStyle; }
0071
0072
0073 bool HasFaceColor() const { return myHasFaceColor; }
0074
0075
0076 const Quantity_ColorRGBA& FaceColor() const { return myFaceColor; }
0077
0078 public:
0079
0080
0081 Standard_Integer NbTriangles() const { return myPolyTriang->NbTriangles(); }
0082
0083
0084 Standard_Integer ElemLower() const { return 1; }
0085
0086
0087 Standard_Integer ElemUpper() const { return myPolyTriang->NbTriangles(); }
0088
0089
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
0103 bool HasNormals() const { return myHasNormals; }
0104
0105
0106 bool HasTexCoords() const { return !myPolyTriang.IsNull() && myPolyTriang->HasUVNodes(); }
0107
0108
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
0124 Standard_Integer NbNodes() const
0125 {
0126 return !myPolyTriang.IsNull()
0127 ? myPolyTriang->NbNodes()
0128 : 0;
0129 }
0130
0131
0132 Standard_Integer NodeLower() const { return 1; }
0133
0134
0135 Standard_Integer NodeUpper() const { return myPolyTriang->NbNodes(); }
0136
0137
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
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
0154 gp_Pnt node (const Standard_Integer theNode) const { return myPolyTriang->Node (theNode); }
0155
0156
0157 Standard_EXPORT gp_Dir normal (Standard_Integer theNode) const;
0158
0159
0160 Poly_Triangle triangle (Standard_Integer theElemIndex) const { return myPolyTriang->Triangle (theElemIndex); }
0161
0162 private:
0163
0164
0165 void dispatchStyles (const TDF_Label& theLabel,
0166 const TopLoc_Location& theLocation,
0167 const XCAFPrs_Style& theStyle);
0168
0169
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
0181 void initFace();
0182
0183 private:
0184
0185 NCollection_DataMap<TopoDS_Shape, XCAFPrs_Style, TopTools_ShapeMapHasher>
0186 myStyles;
0187 XCAFPrs_Style myDefStyle;
0188 Standard_Boolean myToMapColors;
0189
0190 TopExp_Explorer myFaceIter;
0191 TopoDS_Face myFace;
0192 Handle(Poly_Triangulation) myPolyTriang;
0193 TopLoc_Location myFaceLocation;
0194 mutable BRepLProp_SLProps mySLTool;
0195 BRepAdaptor_Surface myFaceAdaptor;
0196 Standard_Boolean myHasNormals;
0197 gp_Trsf myTrsf;
0198 Standard_Boolean myIsMirrored;
0199 XCAFPrs_Style myFaceStyle;
0200 Quantity_ColorRGBA myFaceColor;
0201 Standard_Boolean myHasFaceColor;
0202
0203 };
0204
0205 #endif