1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 // File : SMESH_Pattern.hxx
21 // Created : Mon Aug 2 10:30:00 2004
22 // Author : Edward AGAPOV (eap)
24 #ifndef SMESH_Pattern_HeaderFile
25 #define SMESH_Pattern_HeaderFile
33 #include <TopoDS_Shape.hxx>
34 #include <TopTools_IndexedMapOfOrientedShape.hxx>
39 class SMDS_MeshElement;
41 class SMDS_MeshVolume;
50 // Class allowing meshing by mapping of pre-defined patterns: it generates
51 // a 2D mesh on a geometrical face or a 3D mesh inside a geometrical block
63 bool Load (const char* theFileContents);
64 // Load a pattern from <theFileContents>
66 bool Load (SMESH_Mesh* theMesh,
67 const TopoDS_Face& theFace,
69 // Create a pattern from the mesh built on <theFace>.
70 // <theProject>==true makes override nodes positions
71 // on <theFace> computed by mesher
73 bool Load (SMESH_Mesh* theMesh,
74 const TopoDS_Shell& theBlock);
75 // Create a pattern from the mesh built on <theBlock>
77 bool Save (std::ostream& theFile);
78 // Save the loaded pattern into theFile
80 bool Apply (const TopoDS_Face& theFace,
81 const TopoDS_Vertex& theVertexOnKeyPoint1,
82 const bool theReverse);
83 // Compute nodes coordinates applying
84 // the loaded pattern to <theFace>. The first key-point
85 // will be mapped into <theVertexOnKeyPoint1>, which must
86 // be in the outer wire of theFace
88 bool Apply (const TopoDS_Shell& theBlock,
89 const TopoDS_Vertex& theVertex000,
90 const TopoDS_Vertex& theVertex001);
91 // Compute nodes coordinates applying
92 // the loaded pattern to <theBlock>. The (0,0,0) key-point
93 // will be mapped into <theVertex000>. The
94 // (0,0,1) key-point will be mapped into <theVertex001>.
96 bool Apply (const SMDS_MeshFace* theFace,
97 const int theNodeIndexOnKeyPoint1,
98 const bool theReverse);
99 // Compute nodes coordinates applying
100 // the loaded pattern to <theFace>. The first key-point
101 // will be mapped into <theNodeIndexOnKeyPoint1>-th node
103 bool Apply (std::set<const SMDS_MeshFace*> theFaces,
104 const int theNodeIndexOnKeyPoint1,
105 const bool theReverse);
106 // Compute nodes coordinates applying
107 // the loaded pattern to <theFaces>. The first key-point
108 // will be mapped into <theNodeIndexOnKeyPoint1>-th node
110 bool Apply (const SMDS_MeshVolume* theVolume,
111 const int theNode000Index,
112 const int theNode001Index);
113 // Compute nodes coordinates applying
114 // the loaded pattern to <theVolume>. The (0,0,0) key-point
115 // will be mapped into <theNode000Index>-th node. The
116 // (0,0,1) key-point will be mapped into <theNode000Index>-th
119 bool Apply (std::set<const SMDS_MeshVolume*> theVolumes,
120 const int theNode000Index,
121 const int theNode001Index);
122 // Compute nodes coordinates applying
123 // the loaded pattern to <theVolumes>. The (0,0,0) key-point
124 // will be mapped into <theNode000Index>-th node. The
125 // (0,0,1) key-point will be mapped into <theNode000Index>-th
128 bool GetMappedPoints ( std::list<const gp_XYZ *> & thePoints ) const;
129 // Return nodes coordinates computed by Apply() method
131 bool MakeMesh(SMESH_Mesh* theMesh);
132 // Create nodes and elements in <theMesh> using nodes
133 // coordinates computed by either of Apply...() methods
141 ERR_READ_NB_POINTS, // couldn't read nb of points
142 ERR_READ_POINT_COORDS, // invalid nb of point coordinates
143 ERR_READ_TOO_FEW_POINTS, // too few points in a pattern
144 ERR_READ_3D_COORD, // coordinate of 3D point out of [0,1] range
145 ERR_READ_NO_KEYPOINT, // no key-points in 2D pattern
146 ERR_READ_BAD_INDEX, // invalid point index
147 ERR_READ_ELEM_POINTS, // invalid nb of points in element
148 ERR_READ_NO_ELEMS, // no elements in a pattern
149 ERR_READ_BAD_KEY_POINT, // a key-point not on a boundary
151 ERR_SAVE_NOT_LOADED, // pattern was not loaded
153 ERR_LOAD_EMPTY_SUBMESH, // no elements to load
155 ERR_LOADF_NARROW_FACE, // too narrow face
156 ERR_LOADF_CLOSED_FACE, // closed face
158 ERR_LOADV_BAD_SHAPE, // volume is not a brick of 6 faces
159 ERR_LOADV_COMPUTE_PARAMS, // cant compute point parameters
161 ERR_APPL_NOT_COMPUTED, // mapping failed
162 ERR_APPL_NOT_LOADED, // pattern was not loaded
163 ERR_APPL_BAD_DIMENTION, // wrong shape dimention
164 ERR_APPL_BAD_NB_VERTICES, // keypoints - vertices mismatch
166 ERR_APPLF_BAD_TOPOLOGY, // bad pattern topology
167 ERR_APPLF_BAD_VERTEX, // first vertex not on an outer face boundary
168 ERR_APPLF_INTERNAL_EEROR, // program error
170 ERR_APPLV_BAD_SHAPE, // volume is not a brick of 6 faces
172 ERR_APPLF_BAD_FACE_GEOM, // bad face geometry
174 ERR_MAKEM_NOT_COMPUTED // mapping failed
177 ErrorCode GetErrorCode() const { return myErrorCode; }
178 // return ErrorCode of the last operation
180 bool IsLoaded() const { return !myPoints.empty() && !myElemPointIDs.empty(); }
181 // Return true if a pattern was successfully loaded
183 bool Is2D() const { return myIs2D; }
184 // Return true if the loaded pattern is a 2D one
186 bool GetPoints ( std::list<const gp_XYZ *> & thePoints ) const;
187 // Return nodes coordinates of the pattern
189 const std::list< int > & GetKeyPointIDs () const { return myKeyPointIDs; }
190 // Return indices of key-points within the sequences returned by
191 // GetPoints() and GetMappedPoints()
193 const std::list< std::list< int > >& GetElementPointIDs () const
194 { return myElemXYZIDs.empty() ? myElemPointIDs : myElemXYZIDs; }
195 // Return nodal connectivity of the elements of the pattern
197 void DumpPoints() const;
205 gp_XYZ myInitXYZ; // loaded postion
207 double myInitU; // [0,1]
208 gp_Pnt myXYZ; // position to compute
213 friend std::ostream & operator <<(std::ostream & OS, const TPoint& p);
215 bool setErrorCode( const ErrorCode theErrorCode )
216 { myErrorCode = theErrorCode; return myErrorCode == ERR_OK; }
217 // set ErrorCode and return true if it is Ok
219 bool setShapeToMesh(const TopoDS_Shape& theShape);
220 // Set a shape to be meshed. Return True if meshing is possible
222 list< TPoint* > & getShapePoints(const TopoDS_Shape& theShape);
223 // Return list of points located on theShape.
224 // A list of edge-points include vertex-points (for 2D pattern only).
225 // A list of face-points doesnt include edge-points.
226 // A list of volume-points doesnt include face-points.
228 list< TPoint* > & getShapePoints(const int theShapeID);
229 // Return list of points located on the shape
231 bool findBoundaryPoints();
232 // If loaded from file, find points to map on edges and faces and
233 // compute their parameters
235 void arrangeBoundaries (list< list< TPoint* > >& boundaryPoints);
236 // if there are several wires, arrange boundaryPoints so that
237 // the outer wire goes first and fix inner wires orientation;
238 // update myKeyPointIDs to correspond to the order of key-points
239 // in boundaries; sort internal boundaries by the nb of key-points
241 void computeUVOnEdge( const TopoDS_Edge& theEdge, const list< TPoint* > & ePoints );
242 // compute coordinates of points on theEdge
244 bool compUVByIsoIntersection (const list< list< TPoint* > >& boundaryPoints,
245 const gp_XY& theInitUV,
247 bool & theIsDeformed);
248 // compute UV by intersection of iso-lines found by points on edges
250 bool compUVByElasticIsolines(const list< list< TPoint* > >& boundaryPoints,
251 const list< TPoint* >& pointsToCompute);
252 // compute UV as nodes of iso-poly-lines consisting of
253 // segments keeping relative size as in the pattern
255 double setFirstEdge (list< TopoDS_Edge > & theWire, int theFirstEdgeID);
256 // choose the best first edge of theWire; return the summary distance
257 // between point UV computed by isolines intersection and
258 // eventual UV got from edge p-curves
260 typedef list< list< TopoDS_Edge > > TListOfEdgesList;
262 bool sortSameSizeWires (TListOfEdgesList & theWireList,
263 const TListOfEdgesList::iterator& theFromWire,
264 const TListOfEdgesList::iterator& theToWire,
265 const int theFirstEdgeID,
266 list< list< TPoint* > >& theEdgesPointsList );
267 // sort wires in theWireList from theFromWire until theToWire,
268 // the wires are set in the order to correspond to the order
269 // of boundaries; after sorting, edges in the wires are put
270 // in a good order, point UVs on edges are computed and points
271 // are appended to theEdgesPointsList
273 typedef std::set<const SMDS_MeshNode*> TNodeSet;
274 void mergePoints (std::map<TNodeSet,std::list<std::list<int> > >& xyzIndGroups,
275 std::map< int, std::list< std::list< int >* > >& reverseConnectivity);
276 // Look for coincident points between myXYZs indexed with
277 // list<int> of each element of xyzIndGroups. Coincident indices
278 // are merged in myElemXYZIDs using reverseConnectivity.
284 std::vector< TPoint > myPoints;
285 std::list< int > myKeyPointIDs;
286 std::list< std::list< int > > myElemPointIDs;
288 ErrorCode myErrorCode;
290 bool myIsBoundaryPointsFound;
292 TopoDS_Shape myShape;
293 // all functions assure that shapes are indexed so that first go
294 // ordered vertices, then ordered edge, then faces and maybe a shell
295 TopTools_IndexedMapOfOrientedShape myShapeIDMap;
296 //TopTools_IndexedMapOfShape myShapeIDMap;
297 std::map< int, list< TPoint* > > myShapeIDToPointsMap;
300 // nb of key-points in each of pattern boundaries
301 std::list< int > myNbKeyPntInBoundary;
303 // to compute while applying to mesh elements, not to shapes
304 std::vector<gp_XYZ> myXYZ;
305 std::list< std::list< int > > myElemXYZIDs;
306 std::map< int, const SMDS_MeshNode*> myXYZIdToNodeMap; // map id to node of a refined element
307 std::vector<const SMDS_MeshElement*> myElements; // refined elements
308 std::vector<const SMDS_MeshNode*> myOrderedNodes;