Version: 9.12.0
SMESH_MAT2d.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File : SMESH_MAT2d.hxx
23 // Created : Thu May 28 17:49:53 2015
24 // Author : Edward AGAPOV (eap)
25 
26 #ifndef __SMESH_MAT2d_HXX__
27 #define __SMESH_MAT2d_HXX__
28 
29 #include "SMESH_Utils.hxx"
30 
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Edge.hxx>
33 
34 #include <vector>
35 #include <map>
36 
37 #include <boost/polygon/polygon.hpp>
38 #include <boost/polygon/voronoi.hpp>
39 
40 class Adaptor3d_Curve;
41 
42 // Medial Axis Transform 2D
43 namespace SMESH_MAT2d
44 {
45  class MedialAxis; // MedialAxis is the entry point
46  class Branch;
47  class BranchEnd;
48  class Boundary;
49  struct BoundaryPoint;
50 
51  typedef boost::polygon::voronoi_diagram<double> TVD;
52  typedef TVD::cell_type TVDCell;
53  typedef TVD::edge_type TVDEdge;
54  typedef TVD::vertex_type TVDVertex;
55 
56  //-------------------------------------------------------------------------------------
57  // type of Branch end point
59  BE_ON_VERTEX, // branch ends at a convex VERTEX
60  BE_BRANCH_POINT, // branch meats 2 or more other branches
61  BE_END // branch end equidistant from several adjacent segments
62  };
63  //-------------------------------------------------------------------------------------
68  {
71  std::vector< const Branch* > _branches;
72 
73  BranchEnd(): _vertex(0), _type( BE_UNDEF ) {}
74  };
75  //-------------------------------------------------------------------------------------
80  {
81  const Branch* _branch;
82  std::size_t _iEdge; // MA edge index within the branch
83  double _edgeParam; // normalized param within the MA edge
84 
85  BranchPoint( const Branch* b = 0, std::size_t e = 0, double u = -1 ):
86  _branch(b), _iEdge(e), _edgeParam(u) {}
87  };
88  //-------------------------------------------------------------------------------------
95  {
96  public:
97  bool getBoundaryPoints(double param, BoundaryPoint& bp1, BoundaryPoint& bp2 ) const;
98  bool getBoundaryPoints(std::size_t iMAEdge, double maEdgeParam,
99  BoundaryPoint& bp1, BoundaryPoint& bp2 ) const;
100  bool getBoundaryPoints(const BranchPoint& p,
101  BoundaryPoint& bp1, BoundaryPoint& bp2 ) const;
102  bool getParameter(const BranchPoint& p, double & u ) const;
103 
104  std::size_t nbEdges() const { return _maEdges.size(); }
105 
106  const BranchEnd* getEnd(bool the2nd) const { return & ( the2nd ? _endPoint2 : _endPoint1 ); }
107 
108  bool hasEndOfType(BranchEndType type) const;
109 
110  void getPoints( std::vector< gp_XY >& points, const double scale[2]) const;
111 
112  void getGeomEdges( std::vector< std::size_t >& edgeIDs1,
113  std::vector< std::size_t >& edgeIDs2 ) const;
114 
115  void getOppositeGeomEdges( std::vector< std::size_t >& edgeIDs1,
116  std::vector< std::size_t >& edgeIDs2,
117  std::vector< BranchPoint >& divPoints) const;
118 
119  bool isRemoved() const { return _proxyPoint._branch; }
120 
121  public: // internal: construction
122 
123  void init( std::vector<const TVDEdge*>& maEdges,
124  const Boundary* boundary,
125  std::map< const TVDVertex*, BranchEndType >& endType);
126  void setBranchesToEnds( const std::vector< Branch >& branches);
127  BranchPoint getPoint( const TVDVertex* vertex ) const;
128  void setRemoved( const BranchPoint& proxyPoint );
129 
130  static void setGeomEdge ( std::size_t geomIndex, const TVDEdge* maEdge );
131  static std::size_t getGeomEdge ( const TVDEdge* maEdge );
132  static void setBndSegment( std::size_t segIndex, const TVDEdge* maEdge );
133  static std::size_t getBndSegment( const TVDEdge* maEdge );
134 
135  private:
136 
137  bool addDivPntForConcaVertex( std::vector< std::size_t >& edgeIDs1,
138  std::vector< std::size_t >& edgeIDs2,
139  std::vector< BranchPoint >& divPoints,
140  const std::vector<const TVDEdge*>& maEdges,
141  const std::vector<const TVDEdge*>& maEdgesTwin,
142  int & i) const;
143 
144  // association of _maEdges with boundary segments is stored in this way:
145  // index of an EDGE: TVDEdge->cell()->color()
146  // index of a segment on EDGE: TVDEdge->color()
147  std::vector<const TVDEdge*> _maEdges; // MA edges ending at points located at _params
148  std::vector<double> _params; // params of points on MA, normalized [0;1] within this branch
149  const Boundary* _boundary; // face boundary
153  };
154 
155  //-------------------------------------------------------------------------------------
159  struct BndPoints
160  {
161  std::vector< double > _params; // params of discretization points on an EDGE
162  std::vector< std::pair< const Branch*, int > > _maEdges; /* index of TVDEdge in branch;
163  index sign means orientation;
164  index == Branch->nbEdges() means
165  end point of a Branch */
166  };
167  //-------------------------------------------------------------------------------------
173  {
174  public:
175 
176  Boundary( std::size_t nbEdges ): _pointsPerEdge( nbEdges ) {}
177  BndPoints& getPoints( std::size_t iEdge ) { return _pointsPerEdge[ iEdge ]; }
178  std::size_t nbEdges() const { return _pointsPerEdge.size(); }
179 
180  bool getPoint( std::size_t iEdge, std::size_t iSeg, double u, BoundaryPoint& bp ) const;
181 
182  bool getBranchPoint( const std::size_t iEdge, double u, BranchPoint& p ) const;
183 
184  bool getBranchPoint( const BoundaryPoint& bp, BranchPoint& p ) const;
185 
186  bool isConcaveSegment( std::size_t iEdge, std::size_t iSeg ) const;
187 
188  bool moveToClosestEdgeEnd( BoundaryPoint& bp ) const;
189 
190  private:
191  std::vector< BndPoints > _pointsPerEdge;
192  };
193 
194  //-------------------------------------------------------------------------------------
199  {
200  std::size_t _edgeIndex; // index of an EDGE in a sequence passed to MedialAxis()
201  double _param; // parameter of this EDGE
202  };
203  //-------------------------------------------------------------------------------------
210  {
211  public:
212  MedialAxis(const TopoDS_Face& face,
213  const std::vector< TopoDS_Edge >& edges,
214  const double minSegLen,
215  const bool ignoreCorners = false );
216  std::size_t nbBranches() const { return _nbBranches; }
217  const Branch* getBranch(size_t i) const;
218  const std::vector< const BranchEnd* >& getBranchPoints() const { return _branchPnt; }
219  const Boundary& getBoundary() const { return _boundary; }
220 
221  void getPoints( const Branch* branch, std::vector< gp_XY >& points) const;
222  Adaptor3d_Curve* make3DCurve(const Branch& branch) const;
223 
224  private:
225 
226  private:
227  TopoDS_Face _face;
229  std::vector< Branch > _branch;
230  std::size_t _nbBranches; // removed branches ignored
231  std::vector< const BranchEnd* > _branchPnt;
233  double _scale[2];
234  };
235 
236 }
237 
238 #endif
#define SMESHUtils_EXPORT
Definition: SMESH_Utils.hxx:37
Face boundary is discretized so that each its segment to correspond to an edge of MA.
Definition: SMESH_MAT2d.hxx:173
Boundary(std::size_t nbEdges)
Definition: SMESH_MAT2d.hxx:176
std::vector< BndPoints > _pointsPerEdge
Definition: SMESH_MAT2d.hxx:191
BndPoints & getPoints(std::size_t iEdge)
Definition: SMESH_MAT2d.hxx:177
std::size_t nbEdges() const
Definition: SMESH_MAT2d.hxx:178
Branch is a set of MA edges enclosed between branch points and/or MA ends.
Definition: SMESH_MAT2d.hxx:95
BranchEnd _endPoint2
Definition: SMESH_MAT2d.hxx:151
const Boundary * _boundary
Definition: SMESH_MAT2d.hxx:149
const BranchEnd * getEnd(bool the2nd) const
Definition: SMESH_MAT2d.hxx:106
BranchEnd _endPoint1
Definition: SMESH_MAT2d.hxx:150
std::vector< double > _params
Definition: SMESH_MAT2d.hxx:148
bool isRemoved() const
Definition: SMESH_MAT2d.hxx:119
BranchPoint _proxyPoint
Definition: SMESH_MAT2d.hxx:152
std::vector< const TVDEdge * > _maEdges
Definition: SMESH_MAT2d.hxx:147
std::size_t nbEdges() const
Definition: SMESH_MAT2d.hxx:104
Medial axis (MA) is defined as the loci of centres of locally maximal balls inside 2D representation ...
Definition: SMESH_MAT2d.hxx:210
std::size_t nbBranches() const
Definition: SMESH_MAT2d.hxx:216
Boundary _boundary
Definition: SMESH_MAT2d.hxx:232
TopoDS_Face _face
Definition: SMESH_MAT2d.hxx:227
std::vector< Branch > _branch
Definition: SMESH_MAT2d.hxx:229
std::vector< const BranchEnd * > _branchPnt
Definition: SMESH_MAT2d.hxx:231
TVD _vd
Definition: SMESH_MAT2d.hxx:228
std::size_t _nbBranches
Definition: SMESH_MAT2d.hxx:230
const Boundary & getBoundary() const
Definition: SMESH_MAT2d.hxx:219
const std::vector< const BranchEnd * > & getBranchPoints() const
Definition: SMESH_MAT2d.hxx:218
Definition: SMESH_MAT2d.hxx:44
boost::polygon::voronoi_diagram< double > TVD
Definition: SMESH_MAT2d.hxx:49
BranchEndType
Definition: SMESH_MAT2d.hxx:58
@ BE_END
Definition: SMESH_MAT2d.hxx:61
@ BE_UNDEF
Definition: SMESH_MAT2d.hxx:58
@ BE_ON_VERTEX
Definition: SMESH_MAT2d.hxx:59
@ BE_BRANCH_POINT
Definition: SMESH_MAT2d.hxx:60
TVD::vertex_type TVDVertex
Definition: SMESH_MAT2d.hxx:54
TVD::edge_type TVDEdge
Definition: SMESH_MAT2d.hxx:53
TVD::cell_type TVDCell
Definition: SMESH_MAT2d.hxx:52
Data of a discretized EDGE allowing to get a point on MA by a parameter on EDGE.
Definition: SMESH_MAT2d.hxx:160
std::vector< std::pair< const Branch *, int > > _maEdges
Definition: SMESH_MAT2d.hxx:162
std::vector< double > _params
Definition: SMESH_MAT2d.hxx:161
Point on FACE boundary.
Definition: SMESH_MAT2d.hxx:199
double _param
Definition: SMESH_MAT2d.hxx:201
std::size_t _edgeIndex
Definition: SMESH_MAT2d.hxx:200
End point of MA Branch.
Definition: SMESH_MAT2d.hxx:68
BranchEnd()
Definition: SMESH_MAT2d.hxx:73
const TVDVertex * _vertex
Definition: SMESH_MAT2d.hxx:69
BranchEndType _type
Definition: SMESH_MAT2d.hxx:70
std::vector< const Branch * > _branches
Definition: SMESH_MAT2d.hxx:71
Point on MA Branch.
Definition: SMESH_MAT2d.hxx:80
BranchPoint(const Branch *b=0, std::size_t e=0, double u=-1)
Definition: SMESH_MAT2d.hxx:85
const Branch * _branch
Definition: SMESH_MAT2d.hxx:81
std::size_t _iEdge
Definition: SMESH_MAT2d.hxx:82
double _edgeParam
Definition: SMESH_MAT2d.hxx:83