1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_Prism_3D.hxx
27 #ifndef _SMESH_Prism_3D_HXX_
28 #define _SMESH_Prism_3D_HXX_
30 #include "SMESH_StdMeshers.hxx"
32 #include "SMESH_3D_Algo.hxx"
33 #include "SMDS_TypeOfPosition.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMESH_Block.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESHDS_Mesh.hxx"
38 #include "SMESH_subMesh.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_Comment.hxx"
44 #include <Adaptor3d_Curve.hxx>
45 #include <Adaptor3d_Surface.hxx>
46 #include <Adaptor2d_Curve2d.hxx>
47 #include <BRepAdaptor_Surface.hxx>
48 #include <TopTools_IndexedMapOfOrientedShape.hxx>
50 #include <gp_Trsf.hxx>
53 class SMESHDS_SubMesh;
58 //typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
59 typedef std::vector<const SMDS_MeshNode* > TNodeColumn;
61 // map of bottom nodes to the column of nodes above them
62 // (the column includes the bottom nodes)
63 typedef std::map< TNode, TNodeColumn > TNode2ColumnMap;
64 typedef std::map< double, TNodeColumn > TParam2ColumnMap;
65 typedef std::map< double, TNodeColumn >::const_iterator TParam2ColumnIt;
67 typedef TopTools_IndexedMapOfOrientedShape TBlockShapes;
69 // ===============================================
71 * \brief Structure containing node relative data
73 // ===============================================
77 const SMDS_MeshNode* myNode;
78 mutable gp_XYZ myParams;
80 gp_XYZ GetCoords() const { return gp_XYZ( myNode->X(), myNode->Y(), myNode->Z() ); }
81 gp_XYZ GetParams() const { return myParams; }
82 gp_XYZ& ChangeParams() const { return myParams; }
83 bool HasParams() const { return myParams.X() >= 0.0; }
84 SMDS_TypeOfPosition GetPositionType() const
85 { return myNode ? myNode->GetPosition()->GetTypeOfPosition() : SMDS_TOP_UNSPEC; }
86 bool IsNeighbor( const TNode& other ) const;
88 TNode(const SMDS_MeshNode* node = 0): myNode(node), myParams(-1,-1,-1) {}
89 bool operator < (const TNode& other) const { return myNode->GetID() < other.myNode->GetID(); }
92 // ===============================================================
94 * \brief Tool analyzing and giving access to a prism geometry
95 * treating it like a block, i.e. the four side faces are
96 * emulated by division/uniting of missing/excess faces.
97 * It also manage associations between block sub-shapes and a mesh.
99 // ===============================================================
101 class STDMESHERS_EXPORT StdMeshers_PrismAsBlock: public SMESH_Block
105 * \brief Constructor. Initialization is needed
107 StdMeshers_PrismAsBlock();
109 ~StdMeshers_PrismAsBlock();
112 * \brief Initialization.
113 * \param helper - helper loaded with mesh and 3D shape
114 * \param shape3D - a closed shell or solid
115 * \retval bool - false if a mesh or a shape are KO
117 * Analyse shape geometry and mesh.
118 * If there are triangles on one of faces, it becomes 'bottom'
120 bool Init(SMESH_MesherHelper* helper, const TopoDS_Shape& shape3D);
123 * \brief Return problem description
125 SMESH_ComputeErrorPtr GetError() const { return myError; }
128 * \brief Free allocated memory
133 * \brief Return number of nodes on every vertical edge
134 * \retval int - number of nodes including end nodes
136 int VerticalSize() const { return myParam2ColumnMaps[0].begin()->second.size(); }
138 bool HasNotQuadElemOnTop() const { return myNotQuadOnTop; }
141 * \brief Return pointer to column of nodes
142 * \param node - bottom node from which the returned column goes up
143 * \retval const TNodeColumn* - the found column
145 const TNodeColumn* GetNodeColumn(const SMDS_MeshNode* node) const;
148 * \brief Return TParam2ColumnMap for a base edge
149 * \param baseEdgeID - base edge SMESHDS Index
150 * \param isReverse - columns in-block orientation
151 * \retval const TParam2ColumnMap* - map
153 const TParam2ColumnMap* GetParam2ColumnMap(const int baseEdgeID,
154 bool & isReverse) const
156 std::map< int, std::pair< TParam2ColumnMap*, bool > >::const_iterator i_mo =
157 myShapeIndex2ColumnMap.find( baseEdgeID );
158 if ( i_mo == myShapeIndex2ColumnMap.end() ) return 0;
160 const std::pair< TParam2ColumnMap*, bool >& col_frw = i_mo->second;
161 isReverse = !col_frw.second;
162 return col_frw.first;
166 * \brief Return transformations to get coordinates of nodes of each internal layer
167 * by nodes of the bottom. Layer is a set of nodes at a certain step
168 * from bottom to top.
170 bool GetLayersTransformation(std::vector<gp_Trsf> & trsf) const;
173 * \brief Return pointer to mesh
174 * \retval SMESH_Mesh - mesh
176 SMESH_Mesh* Mesh() const { return myHelper->GetMesh(); }
179 * \brief Return pointer to mesh DS
180 * \retval SMESHDS_Mesh - mesh DS
182 SMESHDS_Mesh* MeshDS() const { return Mesh()->GetMeshDS(); }
185 * \brief Return submesh of a shape
186 * \param shapeID - shape given by in-block index
187 * \retval SMESH_subMesh* - found submesh
189 SMESH_subMesh* SubMesh(const int shapeID) const
190 { return Mesh()->GetSubMesh( Shape( shapeID )); }
193 * \brief Return submesh DS of a shape
194 * \param shapeID - shape given by in-block index
195 * \retval SMESHDS_SubMesh* - found submesh DS
197 SMESHDS_SubMesh* SubMeshDS(const int shapeID) const
198 { return SubMesh(shapeID)->GetSubMeshDS(); }
201 * \brief Return a in-block shape
202 * \param shapeID - shape given by in-block index
203 * \retval SMESHDS_SubMesh* - found submesh
205 const TopoDS_Shape& Shape(const int shapeID) const
206 { return myShapeIDMap( shapeID ); }
209 * \brief Return in-block ID of a shape
210 * \param shape - block sub-shape
211 * \retval int - ID or zero if the shape has no ID
213 int ShapeID(const TopoDS_Shape& shape) const
214 { return myShapeIDMap.FindIndex( shape ); }
217 * \brief Check curve orientation of a bootom edge
218 * \param meshDS - mesh DS
219 * \param columnsMap - node columns map of side face
220 * \param bottomEdge - the bootom edge
221 * \param sideFaceID - side face in-block ID
222 * \retval bool - true if orienation coinside with in-block froward orienation
224 static bool IsForwardEdge(SMESHDS_Mesh* meshDS,
225 const TParam2ColumnMap& columnsMap,
226 const TopoDS_Edge & bottomEdge,
227 const int sideFaceID);
229 * \brief Find wall faces by bottom edges
230 * \param mesh - the mesh
231 * \param mainShape - the prism
232 * \param bottomFace - the bottom face
233 * \param bottomEdges - edges bounding the bottom face
234 * \param wallFaces - faces list to fill in
236 bool GetWallFaces( SMESH_Mesh* mesh,
237 const TopoDS_Shape & mainShape,
238 const TopoDS_Shape & bottomFace,
239 std::list< TopoDS_Edge >& bottomEdges,
240 std::list< int > & nbEInW,
241 std::list< TopoDS_Face >& wallFaces);
245 // --------------------------------------------------------------------
247 * \brief Class representing a part of a geom face or
248 * a union of seleral faces. Or just an ordinary geom face
250 * It's parametrization is within [0,1] range.
251 * It redefines Adaptor3d_Surface::Value(U,V) where U and V are within [0,1]
253 // --------------------------------------------------------------------
254 class TSideFace: public Adaptor3d_Surface
256 int myID; //!< in-block ID
257 // map used to find out real UV by it's normalized UV
258 TParam2ColumnMap* myParamToColumnMap;
259 BRepAdaptor_Surface mySurface;
260 TopoDS_Edge myBaseEdge;
261 // first and last normalized params and orientaion for each component or it-self
262 std::vector< std::pair< double, double> > myParams;
264 std::vector< TSideFace* > myComponents;
265 SMESH_MesherHelper * myHelper;
267 TSideFace( SMESH_MesherHelper* helper,
269 const TopoDS_Face& face,
270 const TopoDS_Edge& baseEdge,
271 TParam2ColumnMap* columnsMap,
272 const double first = 0.0,
273 const double last = 1.0);
274 TSideFace( const std::vector< TSideFace* >& components,
275 const std::vector< std::pair< double, double> > & params);
276 TSideFace( const TSideFace& other );
278 bool IsComplex() const
279 { return ( NbComponents() > 0 || myParams[0].first != 0. || myParams[0].second != 1. ); }
280 int FaceID() const { return myID; }
281 TParam2ColumnMap* GetColumns() const { return myParamToColumnMap; }
282 gp_XY GetNodeUV(const TopoDS_Face& F, const SMDS_MeshNode* n) const
283 { return myHelper->GetNodeUV( F, n ); }
284 const TopoDS_Edge & BaseEdge() const { return myBaseEdge; }
285 int ColumnHeight() const {
286 if ( NbComponents() ) return GetComponent(0)->GetColumns()->begin()->second.size();
287 else return GetColumns()->begin()->second.size(); }
288 double GetColumns(const double U, TParam2ColumnIt & col1, TParam2ColumnIt& col2 ) const;
289 int NbComponents() const { return myComponents.size(); }
290 TSideFace* GetComponent(const int i) const { return myComponents.at( i ); }
291 void SetComponent(const int i, TSideFace* c)
292 { if ( myComponents[i] ) delete myComponents[i]; myComponents[i]=c; }
293 TSideFace* GetComponent(const double U, double& localU) const;
294 bool IsForward() const { return myIsForward; }
295 // boundary geometry for a face
296 Adaptor3d_Surface* Surface() const { return new TSideFace( *this ); }
297 bool GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const;
298 Adaptor2d_Curve2d* HorizPCurve(const bool isTop, const TopoDS_Face& horFace) const;
299 Adaptor3d_Curve* HorizCurve(const bool isTop) const;
300 Adaptor3d_Curve* VertiCurve(const bool isMax) const;
301 TopoDS_Edge GetEdge( const int edge ) const;
302 int InsertSubShapes( TBlockShapes& shapeMap ) const;
303 // redefine Adaptor methods
304 gp_Pnt Value(const Standard_Real U,const Standard_Real V) const;
306 void dumpNodes(int nbNodes) const;
309 // --------------------------------------------------------------------
311 * \brief Class emulating geometry of a vertical edge
313 // --------------------------------------------------------------------
314 class STDMESHERS_EXPORT TVerticalEdgeAdaptor: public Adaptor3d_Curve
316 const TNodeColumn* myNodeColumn;
318 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter );
319 gp_Pnt Value(const Standard_Real U) const;
320 Standard_Real FirstParameter() const { return 0; }
321 Standard_Real LastParameter() const { return 1; }
323 void dumpNodes(int nbNodes) const;
326 // --------------------------------------------------------------------
328 * \brief Class emulating geometry of a hirizontal edge
330 // --------------------------------------------------------------------
331 class STDMESHERS_EXPORT THorizontalEdgeAdaptor: public Adaptor3d_Curve
333 const TSideFace* mySide;
336 THorizontalEdgeAdaptor( const TSideFace* sideFace, const bool isTop)
337 :mySide(sideFace), myV( isTop ? 1.0 : 0.0 ) {}
338 gp_Pnt Value(const Standard_Real U) const;
339 Standard_Real FirstParameter() const { return 0; }
340 Standard_Real LastParameter() const { return 1; }
342 void dumpNodes(int nbNodes) const;
345 // --------------------------------------------------------------------
347 * \brief Class emulating pcurve on a hirizontal face
349 // --------------------------------------------------------------------
350 class STDMESHERS_EXPORT TPCurveOnHorFaceAdaptor: public Adaptor2d_Curve2d
352 const TSideFace* mySide;
356 TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
358 const TopoDS_Face& horFace)
359 : mySide(sideFace), myFace(horFace), myZ(isTop ? mySide->ColumnHeight() - 1 : 0 ) {}
360 gp_Pnt2d Value(const Standard_Real U) const;
361 Standard_Real FirstParameter() const { return 0; }
362 Standard_Real LastParameter() const { return 1; }
366 SMESH_MesherHelper* myHelper;
367 TBlockShapes myShapeIDMap;
368 SMESH_ComputeErrorPtr myError;
370 // container of 4 side faces
372 // node columns for each base edge
373 std::vector< TParam2ColumnMap > myParam2ColumnMaps;
374 // to find a column for a node by edge SMESHDS Index
375 std::map< int, std::pair< TParam2ColumnMap*, bool > > myShapeIndex2ColumnMap;
378 * \brief store error and comment and then return ( error == COMPERR_OK )
380 bool error(int error, const SMESH_Comment& comment = "") {
381 myError = SMESH_ComputeError::New(error,comment);
382 return myError->IsOK();
386 // =============================================
388 * \brief Algo building prisms on a prism shape
390 // =============================================
392 class STDMESHERS_EXPORT StdMeshers_Prism_3D: public SMESH_3D_Algo
395 StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen);
396 virtual ~StdMeshers_Prism_3D();
398 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
399 const TopoDS_Shape& aShape,
400 SMESH_Hypothesis::Hypothesis_Status& aStatus);
402 virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
404 virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
405 MapShapeNbElems& aResMap);
408 * \brief Enable removal of quadrangles from the bottom face and
409 * triangles creation there by projection from the top
410 * (sole face meshed with triangles is considered to be a bottom one).
411 * If there are two faces with triangles, triangles must
412 * be of the same topology, else the algo fails.
413 * The method must be called before Compute()
415 void ProjectTriangles() { myProjectTriangles = true; }
418 * \brief Create prisms
419 * \param nodeColumns - columns of nodes generated from nodes of a mesh face
420 * \param helper - helper initialized by mesh and shape to add prisms to
422 static void AddPrisms( std::vector<const TNodeColumn*> & nodeColumns,
423 SMESH_MesherHelper* helper);
428 * \brief Find correspondence between bottom and top nodes.
429 * If elements on the bottom and top faces are topologically different,
430 * and projection is possible and allowed, perform the projection
431 * \retval bool - is a success or not
433 bool assocOrProjBottom2Top();
436 * \brief Remove quadrangles from the top face and
437 * create triangles there by projection from the bottom
438 * \retval bool - a success or not
440 bool projectBottomToTop();
443 * \brief Set projection coordinates of a node to a face and it's sub-shapes
444 * \param faceID - the face given by in-block ID
445 * \param params - node normalized parameters
446 * \retval bool - is a success
448 bool setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z );
452 bool myProjectTriangles;
454 StdMeshers_PrismAsBlock myBlock;
455 SMESH_MesherHelper* myHelper;
457 std::vector<gp_XYZ> myShapeXYZ; // point on each sub-shape of the block
459 // map of bottom nodes to the column of nodes above them
460 // (the column includes the bottom node)
461 TNode2ColumnMap myBotToColumnMap;