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
32 #include <TopoDS_Shape.hxx>
33 //#include <TopTools_IndexedMapOfShape.hxx>
34 #include <TopTools_IndexedMapOfOrientedShape.hxx>
46 // Class allowing meshing by mapping of pre-defined patterns: it generates
47 // a 2D mesh on a geometrical face or a 3D mesh inside a geometrical block
59 bool Load (const char* theFileContents);
60 // Load a pattern from <theFile>
62 bool Load (SMESH_Mesh* theMesh,
63 const TopoDS_Face& theFace,
65 // Create a pattern from the mesh built on <theFace>.
66 // <theProject>==true makes override nodes positions
67 // on <theFace> computed by mesher
69 bool Load (SMESH_Mesh* theMesh,
70 const TopoDS_Shell& theBlock);
71 // Create a pattern from the mesh built on <theBlock>
73 bool Save (std::ostream& theFile);
74 // Save the loaded pattern into theFile
76 bool Apply (const TopoDS_Face& theFace,
77 const TopoDS_Vertex& theVertexOnKeyPoint1,
78 const bool theReverse);
79 // Compute nodes coordinates applying
80 // the loaded pattern to <theFace>. The first key-point
81 // will be mapped into <theVertexOnKeyPoint1>, which must
82 // be in the outer wire of theFace
84 bool Apply (const TopoDS_Shell& theBlock,
85 const TopoDS_Vertex& theVertex000,
86 const TopoDS_Vertex& theVertex001);
87 // Compute nodes coordinates applying
88 // the loaded pattern to <theBlock>. The (0,0,0) key-point
89 // will be mapped into <theVertex000>. The
90 // (0,0,1) key-point will be mapped into <theVertex001>.
92 bool GetMappedPoints ( std::list<const gp_XYZ *> & thePoints );
93 // Return nodes coordinates computed by Apply() method
95 bool MakeMesh(SMESH_Mesh* theMesh);
96 // Create nodes and elements in <theMesh> using nodes
97 // coordinates computed by either of Apply...() methods
105 ERR_READ_NB_POINTS, // couldn't read nb of points
106 ERR_READ_POINT_COORDS, // invalid nb of point coordinates
107 ERR_READ_TOO_FEW_POINTS, // too few points in a pattern
108 ERR_READ_3D_COORD, // coordinate of 3D point out of [0,1] range
109 ERR_READ_NO_KEYPOINT, // no key-points in 2D pattern
110 ERR_READ_BAD_INDEX, // invalid point index
111 ERR_READ_ELEM_POINTS, // invalid nb of points in element
112 ERR_READ_NO_ELEMS, // no elements in a pattern
113 ERR_READ_BAD_KEY_POINT, // a key-point not on a boundary
115 ERR_SAVE_NOT_LOADED, // pattern was not loaded
117 ERR_LOAD_EMPTY_SUBMESH, // no elements to load
119 ERR_LOADF_NARROW_FACE, // too narrow face
120 ERR_LOADF_CLOSED_FACE, // closed face
122 ERR_LOADV_BAD_SHAPE, // volume is not a brick of 6 faces
123 ERR_LOADV_COMPUTE_PARAMS, // cant compute point parameters
125 ERR_APPL_NOT_COMPUTED, // mapping failed
126 ERR_APPL_NOT_LOADED, // pattern was not loaded
127 ERR_APPL_BAD_DIMENTION, // wrong shape dimention
128 ERR_APPL_BAD_NB_VERTICES, // keypoints - vertices mismatch
130 ERR_APPLF_BAD_TOPOLOGY, // bad pattern topology
131 ERR_APPLF_BAD_VERTEX, // first vertex not on an outer face boundary
132 ERR_APPLF_INTERNAL_EEROR, // program error
134 ERR_APPLV_BAD_SHAPE, // volume is not a brick of 6 faces
136 ERR_MAKEM_NOT_COMPUTED // mapping failed
139 ErrorCode GetErrorCode() const { return myErrorCode; }
140 // return ErrorCode of the last operation
142 bool IsLoaded() const { return !myPoints.empty() && !myElemPointIDs.empty(); }
143 // Return true if a pattern was successfully loaded
145 bool Is2D() const { return myIs2D; }
146 // Return true if the loaded pattern is a 2D one
148 bool GetPoints ( std::list<const gp_XYZ *> & thePoints ) const;
149 // Return nodes coordinates of the pattern
151 const std::list< int > & GetKeyPointIDs () const { return myKeyPointIDs; }
152 // Return indices of key-points within the sequences returned by
153 // GetPoints() and GetMappedPoints()
155 const std::list< std::list< int > >& GetElementPointIDs () const
156 { return myElemPointIDs; }
157 // Return nodal connectivity of the elements of the pattern
159 void DumpPoints() const;
167 gp_XYZ myInitXYZ; // loaded postion
169 double myInitU; // [0,1]
170 gp_Pnt myXYZ; // position to compute
175 friend std::ostream & operator <<(std::ostream & OS, const TPoint& p);
177 bool setErrorCode( const ErrorCode theErrorCode )
178 { myErrorCode = theErrorCode; return myErrorCode == ERR_OK; }
179 // set ErrorCode and return true if it is Ok
181 bool setShapeToMesh(const TopoDS_Shape& theShape);
182 // Set a shape to be meshed. Return True if meshing is possible
184 list< TPoint* > & getShapePoints(const TopoDS_Shape& theShape);
185 // Return list of points located on theShape.
186 // A list of edge-points include vertex-points (for 2D pattern only).
187 // A list of face-points doesnt include edge-points.
188 // A list of volume-points doesnt include face-points.
190 list< TPoint* > & getShapePoints(const int theShapeID);
191 // Return list of points located on the shape
193 bool findBoundaryPoints();
194 // If loaded from file, find points to map on edges and faces and
195 // compute their parameters
197 void arrangeBoundaries (list< list< TPoint* > >& boundaryPoints);
198 // if there are several wires, arrange boundaryPoints so that
199 // the outer wire goes first and fix inner wires orientation;
200 // update myKeyPointIDs to correspond to the order of key-points
201 // in boundaries; sort internal boundaries by the nb of key-points
203 void computeUVOnEdge( const TopoDS_Edge& theEdge, const list< TPoint* > & ePoints );
204 // compute coordinates of points on theEdge
206 bool compUVByIsoIntersection (const list< list< TPoint* > >& boundaryPoints,
207 const gp_XY& theInitUV,
209 bool & theIsDeformed);
210 // compute UV by intersection of iso-lines found by points on edges
212 bool compUVByElasticIsolines(const list< list< TPoint* > >& boundaryPoints,
213 const list< TPoint* >& pointsToCompute);
214 // compute UV as nodes of iso-poly-lines consisting of
215 // segments keeping relative size as in the pattern
217 double setFirstEdge (list< TopoDS_Edge > & theWire, int theFirstEdgeID);
218 // choose the best first edge of theWire; return the summary distance
219 // between point UV computed by isolines intersection and
220 // eventual UV got from edge p-curves
222 typedef list< list< TopoDS_Edge > > TListOfEdgesList;
224 bool sortSameSizeWires (TListOfEdgesList & theWireList,
225 const TListOfEdgesList::iterator& theFromWire,
226 const TListOfEdgesList::iterator& theToWire,
227 const int theFirstEdgeID,
228 list< list< TPoint* > >& theEdgesPointsList );
229 // sort wires in theWireList from theFromWire until theToWire,
230 // the wires are set in the order to correspond to the order
231 // of boundaries; after sorting, edges in the wires are put
232 // in a good order, point UVs on edges are computed and points
233 // are appended to theEdgesPointsList
239 std::vector< TPoint > myPoints;
240 std::list< int > myKeyPointIDs;
241 std::list< std::list< int > > myElemPointIDs;
243 ErrorCode myErrorCode;
245 bool myIsBoundaryPointsFound;
247 TopoDS_Shape myShape;
248 // all functions assure that shapes are indexed so that first go
249 // ordered vertices, then ordered edge, then faces and a shell
250 TopTools_IndexedMapOfOrientedShape myShapeIDMap;
251 //TopTools_IndexedMapOfShape myShapeIDMap;
252 std::map< int, list< TPoint* > > myShapeIDToPointsMap;
254 std::list< int > myNbKeyPntInBoundary; //for the 2d case