Debian Codegraph @

src/3rdParty/salomesmesh/inc/SMESH_MAT2d.hxx

raw
1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, 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 : [email protected]
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 #include <gp.hxx> //added for occ6
34
35 #include <vector>
36 #include <map>
37
38 #include <boost/polygon/polygon.hpp>
39 #include <boost/polygon/voronoi.hpp>
40
41 class Adaptor3d_Curve;
42
43 // Medial Axis Transform 2D
44 namespace SMESH_MAT2d
45 {
46 class MedialAxis; // MedialAxis is the entry point
47 class Branch;
48 struct BranchEnd;
49 class Boundary;
50 struct BoundaryPoint;
51
52 typedef boost::polygon::voronoi_diagram<double> TVD;
53 typedef TVD::cell_type TVDCell;
54 typedef TVD::edge_type TVDEdge;
55 typedef TVD::vertex_type TVDVertex;
56
57 //-------------------------------------------------------------------------------------
58 // type of Branch end point
59 enum BranchEndType { BE_UNDEF,
60 BE_ON_VERTEX, // branch ends at a convex VRTEX
61 BE_BRANCH_POINT, // branch meats 2 or more other branches
62 BE_END // branch end equidistant from several adjacent segments
63 };
64 //-------------------------------------------------------------------------------------
65 /*!
66 * \brief End point of MA Branch
67 */
68 struct SMESHUtils_EXPORT BranchEnd
69 {
70 const TVDVertex* _vertex;
71 BranchEndType _type;
72 std::vector< const Branch* > _branches;
73
74 BranchEnd(): _vertex(0), _type( BE_UNDEF ) {}
75 };
76 //-------------------------------------------------------------------------------------
77 /*!
78 * \brief Point on MA Branch
79 */
80 struct SMESHUtils_EXPORT BranchPoint
81 {
82 const Branch* _branch;
83 std::size_t _iEdge; // MA edge index within the branch
84 double _edgeParam; // normalized param within the MA edge
85
86 BranchPoint( const Branch* b = 0, std::size_t e = 0, double u = -1 ):
87 _branch(b), _iEdge(e), _edgeParam(u) {}
88 };
89 //-------------------------------------------------------------------------------------
90 /*!
91 * \brief Branch is a set of MA edges enclosed between branch points and/or MA ends.
92 * It's main feature is to return two BoundaryPoint's per a point on it.
93 * Points on a Branch are defined by [0,1] parameter
94 */
95 class SMESHUtils_EXPORT Branch
96 {
97 public:
98 bool getBoundaryPoints(double param, BoundaryPoint& bp1, BoundaryPoint& bp2 ) const;
99 bool getBoundaryPoints(std::size_t iMAEdge, double maEdgeParam,
100 BoundaryPoint& bp1, BoundaryPoint& bp2 ) const;
101 bool getBoundaryPoints(const BranchPoint& p,
102 BoundaryPoint& bp1, BoundaryPoint& bp2 ) const;
103 bool getParameter(const BranchPoint& p, double & u ) const;
104
105 std::size_t nbEdges() const { return _maEdges.size(); }
106
107 const BranchEnd* getEnd(bool the2nd) const { return & ( the2nd ? _endPoint2 : _endPoint1 ); }
108
109 bool hasEndOfType(BranchEndType type) const;
110
111 void getPoints( std::vector< gp_XY >& points, const double scale[2]) const;
112
113 void getGeomEdges( std::vector< std::size_t >& edgeIDs1,
114 std::vector< std::size_t >& edgeIDs2 ) const;
115
116 void getOppositeGeomEdges( std::vector< std::size_t >& edgeIDs1,
117 std::vector< std::size_t >& edgeIDs2,
118 std::vector< BranchPoint >& divPoints) const;
119
120 bool isRemoved() const { return _proxyPoint._branch; }
121
122 public: // internal: construction
123
124 void init( std::vector<const TVDEdge*>& maEdges,
125 const Boundary* boundary,
126 std::map< const TVDVertex*, BranchEndType > endType);
127 void setBranchesToEnds( const std::vector< Branch >& branches);
128 BranchPoint getPoint( const TVDVertex* vertex ) const;
129 void setRemoved( const BranchPoint& proxyPoint );
130
131 static void setGeomEdge ( std::size_t geomIndex, const TVDEdge* maEdge );
132 static std::size_t getGeomEdge ( const TVDEdge* maEdge );
133 static void setBndSegment( std::size_t segIndex, const TVDEdge* maEdge );
134 static std::size_t getBndSegment( const TVDEdge* maEdge );
135
136 private:
137
138 bool addDivPntForConcaVertex( std::vector< std::size_t >& edgeIDs1,
139 std::vector< std::size_t >& edgeIDs2,
140 std::vector< BranchPoint >& divPoints,
141 const std::vector<const TVDEdge*>& maEdges,
142 const std::vector<const TVDEdge*>& maEdgesTwin,
143 int & i) const;
144
145 // association of _maEdges with boundary segments is stored in this way:
146 // index of an EDGE: TVDEdge->cell()->color()
147 // index of a segment on EDGE: TVDEdge->color()
148 std::vector<const TVDEdge*> _maEdges; // MA edges ending at points located at _params
149 std::vector<double> _params; // params of points on MA, normalized [0;1] within this branch
150 const Boundary* _boundary; // face boundary
151 BranchEnd _endPoint1;
152 BranchEnd _endPoint2;
153 BranchPoint _proxyPoint;
154 };
155
156 //-------------------------------------------------------------------------------------
157 /*!
158 * \brief Data of a discretized EDGE allowing to get a point on MA by a parameter on EDGE
159 */
160 struct BndPoints
161 {
162 std::vector< double > _params; // params of discretization points on an EDGE
163 std::vector< std::pair< const Branch*, int > > _maEdges; /* index of TVDEdge in branch;
164 index sign means orientation;
165 index == Branch->nbEdges() means
166 end point of a Branch */
167 };
168 //-------------------------------------------------------------------------------------
169 /*!
170 * \brief Face boundary is discretized so that each its segment to correspond to
171 * an edge of MA
172 */
173 class SMESHUtils_EXPORT Boundary
174 {
175 public:
176
177 Boundary( std::size_t nbEdges ): _pointsPerEdge( nbEdges ) {}
178 BndPoints& getPoints( std::size_t iEdge ) { return _pointsPerEdge[ iEdge ]; }
179 std::size_t nbEdges() const { return _pointsPerEdge.size(); }
180
181 bool getPoint( std::size_t iEdge, std::size_t iSeg, double u, BoundaryPoint& bp ) const;
182
183 bool getBranchPoint( const std::size_t iEdge, double u, BranchPoint& p ) const;
184
185 bool getBranchPoint( const BoundaryPoint& bp, BranchPoint& p ) const;
186
187 bool isConcaveSegment( std::size_t iEdge, std::size_t iSeg ) const;
188
189 bool moveToClosestEdgeEnd( BoundaryPoint& bp ) const;
190
191 private:
192 std::vector< BndPoints > _pointsPerEdge;
193 };
194
195 //-------------------------------------------------------------------------------------
196 /*!
197 * \brief Point on FACE boundary
198 */
199 struct SMESHUtils_EXPORT BoundaryPoint
200 {
201 std::size_t _edgeIndex; // index of an EDGE in a sequence passed to MedialAxis()
202 double _param; // parameter of this EDGE
203 };
204 //-------------------------------------------------------------------------------------
205 /*!
206 * \brief Medial axis (MA) is defined as the loci of centres of locally
207 * maximal balls inside 2D representation of a face. This class
208 * implements a piecewise approximation of MA.
209 */
210 class SMESHUtils_EXPORT MedialAxis
211 {
212 public:
213 MedialAxis(const TopoDS_Face& face,
214 const std::vector< TopoDS_Edge >& edges,
215 const double minSegLen,
216 const bool ignoreCorners = false );
217 std::size_t nbBranches() const { return _nbBranches; }
218 const Branch* getBranch(size_t i) const;
219 const std::vector< const BranchEnd* >& getBranchPoints() const { return _branchPnt; }
220 const Boundary& getBoundary() const { return _boundary; }
221
222 void getPoints( const Branch* branch, std::vector< gp_XY >& points) const;
223 Adaptor3d_Curve* make3DCurve(const Branch& branch) const;
224
225 private:
226
227 private:
228 TopoDS_Face _face;
229 TVD _vd;
230 std::vector< Branch > _branch;
231 std::size_t _nbBranches; // removed branches ignored
232 std::vector< const BranchEnd* > _branchPnt;
233 Boundary _boundary;
234 double _scale[2];
235 };
236
237 }
238
239 #endif