0023106: BRepMesh_IncrementalMesh returns wrong status
[occt.git] / src / BRepMesh / BRepMesh_WireChecker.hxx
1 // Created on: 2014-06-03
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _BRepMesh_WireChecker_HeaderFile
18 #define _BRepMesh_WireChecker_HeaderFile
19
20 #include <Standard.hxx>
21 #include <TopoDS_Face.hxx>
22 #include <BRepMesh_Status.hxx>
23 #include <BRepMesh_DataStructureOfDelaun.hxx>
24 #include <BRepMesh_Collections.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <Bnd_Box2d.hxx>
27 #include <gp_Pnt2d.hxx>
28 #include <gp_XY.hxx>
29
30 #include <vector>
31
32 class BRepMesh_DataMapOfShapePairOfPolygon;
33 class TColStd_IndexedMapOfInteger;
34
35 //! Auxilary class intended to check correctness of discretized face.
36 //! In particular, checks boundaries of discretized face for self 
37 //! intersections and gaps.
38 class BRepMesh_WireChecker
39 {
40 public:
41
42   //! Selector.
43   //! Used to identify segments with overlapped bounding boxes.
44   //! Note that instance of selector can be used only once due to
45   //! unextentable array of indices.
46   class BndBox2dTreeSelector : public BRepMeshCol::BndBox2dTree::Selector
47   {
48     public:
49       Standard_EXPORT BndBox2dTreeSelector(const Standard_Integer theReservedSize);
50       Standard_EXPORT virtual Standard_Boolean Reject(const Bnd_Box2d& theBox2D) const;
51       Standard_EXPORT virtual Standard_Boolean Accept(const Standard_Integer& theIndex);
52       
53       Standard_EXPORT void Clear();
54       Standard_EXPORT void SetBox(const Bnd_Box2d& theBox2D);
55       Standard_EXPORT void SetSkippedIndex(const Standard_Integer theIndex);
56       Standard_EXPORT const BRepMeshCol::Array1OfInteger& Indices() const;
57       Standard_EXPORT Standard_Integer IndicesNb() const;
58
59     protected:
60       Bnd_Box2d                     myBox2D;
61       Standard_Integer              mySkippedIndex;
62       BRepMeshCol::Array1OfInteger  myIndices;
63       Standard_Integer              myIndicesNb;
64   };
65
66 private:
67
68   typedef NCollection_List<TopoDS_Edge>                           ListOfEdges;
69   typedef std::vector<ListOfEdges>                                SeqOfWireEdges;
70   typedef NCollection_Sequence<gp_Pnt2d>                          SeqOfPnt2d;
71   typedef std::vector<SeqOfPnt2d>                                 SeqOfDWires;
72   typedef NCollection_DataMap<Standard_Integer, Standard_Integer> DataMapIntInt;
73   typedef std::pair<Standard_Integer, gp_XY>                      PairIntPnt;
74
75 public:
76
77   //! Constructor.
78   //! \param theFace Face to be checked.
79   //! \param theTolUV Tolerance to be used for calculations in parametric space.
80   //! \param theEdges Map of edges with associated polygon on triangulation.
81   //! \param theVertexMap Map of face vertices.
82   //! \param theStructure Discretized representation of face in parametric space.
83   //! \param theUmin Lower U boundary of the face in parametric space.
84   //! \param theUmax Upper U boundary of the face in parametric space.
85   //! \param theVmin Lower V boundary of the face in parametric space.
86   //! \param theVmax Upper V boundary of the face in parametric space.
87   Standard_EXPORT BRepMesh_WireChecker(
88     const TopoDS_Face&                            theFace,
89     const Standard_Real                           theTolUV,
90     const BRepMeshCol::HDMapOfShapePairOfPolygon& theEdges,
91     const BRepMeshCol::HIMapOfInteger&            theVertexMap,
92     const Handle(BRepMesh_DataStructureOfDelaun)& theStructure,
93     const Standard_Real                           theUmin,
94     const Standard_Real                           theUmax,
95     const Standard_Real                           theVmin,
96     const Standard_Real                           theVmax,
97     const Standard_Boolean                        isInParallel);
98
99   //! Recompute data using parameters passed in constructor.
100   //! \param[out] theClassifier Classifier to be updated using calculated data.
101   Standard_EXPORT void ReCompute(BRepMeshCol::HClassifier& theClassifier);
102
103   //! Returns status of the check.
104   inline BRepMesh_Status Status() const
105   {
106     return myStatus;
107   }
108
109 private:
110
111   //! Collects disñrete wires.
112   //! \param[out] theDWires sequence of discretized wires to be filled.
113   //! \return TRUE on success, FALSE in case of open wire.
114   Standard_Boolean collectDiscretizedWires(SeqOfDWires& theDWires);
115
116   //! Fills array of BiPoints for corresponding wire.
117   //! \param theDWires Sequence of wires to be processed.
118   //! \param theWiresSegmentsTree Array of segments with corresponding 
119   //! bounding boxes trees to be filled.
120   void fillSegmentsTree(
121     const SeqOfDWires&                 theDWires, 
122     BRepMeshCol::Array1OfSegmentsTree& theWiresSegmentsTree);
123
124   //! Assignment operator.
125   void operator =(BRepMesh_WireChecker& /*theOther*/)
126   {
127   }
128
129 private:
130
131   const Standard_Real                           myTolUV;
132   const BRepMeshCol::HDMapOfShapePairOfPolygon& myEdges;
133   const BRepMeshCol::HIMapOfInteger&            myVertexMap;
134   const Handle(BRepMesh_DataStructureOfDelaun)& myStructure;
135   const Standard_Real                           myUmin;
136   const Standard_Real                           myUmax;
137   const Standard_Real                           myVmin;
138   const Standard_Real                           myVmax;
139   BRepMesh_Status                               myStatus;
140   SeqOfWireEdges                                myWiresEdges;
141   Standard_Boolean                              myIsInParallel;
142 };
143
144 #endif