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