1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
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>
52 class SMESHDS_SubMesh;
57 //typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
58 typedef std::vector<const SMDS_MeshNode* > TNodeColumn;
60 // map of bottom nodes to the column of nodes above them
61 // (the column includes the bottom nodes)
62 typedef std::map< TNode, TNodeColumn > TNode2ColumnMap;
63 typedef std::map< double, TNodeColumn > TParam2ColumnMap;
64 typedef std::map< double, TNodeColumn >::const_iterator TParam2ColumnIt;
66 typedef TopTools_IndexedMapOfOrientedShape TBlockShapes;
68 // ===============================================
70 * \brief Structure containing node relative data
72 // ===============================================
76 const SMDS_MeshNode* myNode;
79 gp_XYZ GetCoords() const { return gp_XYZ( myNode->X(), myNode->Y(), myNode->Z() ); }
80 gp_XYZ GetParams() const { return myParams; }
81 gp_XYZ& ChangeParams() { return myParams; }
82 bool HasParams() const { return myParams.X() >= 0.0; }
83 SMDS_TypeOfPosition GetPositionType() const
84 { return myNode ? myNode->GetPosition()->GetTypeOfPosition() : SMDS_TOP_UNSPEC; }
85 bool IsNeighbor( const TNode& other ) const;
87 TNode(const SMDS_MeshNode* node = 0): myNode(node), myParams(-1,-1,-1) {}
88 bool operator < (const TNode& other) const { return myNode < other.myNode; }
91 // ===============================================================
93 * \brief Tool analyzing and giving access to a prism geometry
94 * treating it like a block, i.e. the four side faces are
95 * emulated by division/uniting of missing/excess faces.
96 * It also manage associations between block subshapes and a mesh.
98 // ===============================================================
100 class STDMESHERS_EXPORT StdMeshers_PrismAsBlock: public SMESH_Block
104 * \brief Constructor. Initialization is needed
106 StdMeshers_PrismAsBlock();
108 ~StdMeshers_PrismAsBlock();
111 * \brief Initialization.
112 * \param helper - helper loaded with mesh and 3D shape
113 * \param shape3D - a closed shell or solid
114 * \retval bool - false if a mesh or a shape are KO
116 * Analyse shape geometry and mesh.
117 * If there are triangles on one of faces, it becomes 'bottom'
119 bool Init(SMESH_MesherHelper* helper, const TopoDS_Shape& shape3D);
122 * \brief Return problem description
124 SMESH_ComputeErrorPtr GetError() const { return myError; }
127 * \brief Return number of nodes on every vertical edge
128 * \retval int - number of nodes including end nodes
130 int VerticalSize() const { return myParam2ColumnMaps[0].begin()->second.size(); }
132 bool HasNotQuadElemOnTop() const { return myNotQuadOnTop; }
135 * \brief Return pointer to column of nodes
136 * \param node - bottom node from which the returned column goes up
137 * \retval const TNodeColumn* - the found column
139 const TNodeColumn* GetNodeColumn(const SMDS_MeshNode* node) const;
142 * \brief Return TParam2ColumnMap for a base edge
143 * \param baseEdgeID - base edge SMESHDS Index
144 * \param isReverse - columns in-block orientation
145 * \retval const TParam2ColumnMap& - map
147 const TParam2ColumnMap& GetParam2ColumnMap(const int baseEdgeID,
150 std::pair< TParam2ColumnMap*, bool > & col_frw =
151 myShapeIndex2ColumnMap[ baseEdgeID ];
152 isReverse = !col_frw.second;
153 return * col_frw.first;
157 * \brief Return pointer to mesh
158 * \retval SMESH_Mesh - mesh
160 SMESH_Mesh* Mesh() const { return myHelper->GetMesh(); }
163 * \brief Return pointer to mesh DS
164 * \retval SMESHDS_Mesh - mesh DS
166 SMESHDS_Mesh* MeshDS() const { return Mesh()->GetMeshDS(); }
169 * \brief Return submesh of a shape
170 * \param shapeID - shape given by in-block index
171 * \retval SMESH_subMesh* - found submesh
173 SMESH_subMesh* SubMesh(const int shapeID) const
174 { return Mesh()->GetSubMesh( Shape( shapeID )); }
177 * \brief Return submesh DS of a shape
178 * \param shapeID - shape given by in-block index
179 * \retval SMESHDS_SubMesh* - found submesh DS
181 SMESHDS_SubMesh* SubMeshDS(const int shapeID) const
182 { return SubMesh(shapeID)->GetSubMeshDS(); }
185 * \brief Return a in-block shape
186 * \param shapeID - shape given by in-block index
187 * \retval SMESHDS_SubMesh* - found submesh
189 const TopoDS_Shape& Shape(const int shapeID) const
190 { return myShapeIDMap( shapeID ); }
193 * \brief Return in-block ID of a shape
194 * \param shape - block subshape
195 * \retval int - ID or zero if the shape has no ID
197 int ShapeID(const TopoDS_Shape& shape) const
198 { return myShapeIDMap.FindIndex( shape ); }
201 * \brief Check curve orientation of a bootom edge
202 * \param meshDS - mesh DS
203 * \param columnsMap - node columns map of side face
204 * \param bottomEdge - the bootom edge
205 * \param sideFaceID - side face in-block ID
206 * \retval bool - true if orienation coinside with in-block froward orienation
208 static bool IsForwardEdge(SMESHDS_Mesh* meshDS,
209 const TParam2ColumnMap& columnsMap,
210 const TopoDS_Edge & bottomEdge,
211 const int sideFaceID);
213 * \brief Find wall faces by bottom edges
214 * \param mesh - the mesh
215 * \param mainShape - the prism
216 * \param bottomFace - the bottom face
217 * \param bottomEdges - edges bounding the bottom face
218 * \param wallFaces - faces list to fill in
220 static bool GetWallFaces( SMESH_Mesh* mesh,
221 const TopoDS_Shape & mainShape,
222 const TopoDS_Shape & bottomFace,
223 const std::list< TopoDS_Edge >& bottomEdges,
224 std::list< TopoDS_Face >& wallFaces);
228 // --------------------------------------------------------------------
230 * \brief Class representing a part of a geom face or
231 * a union of seleral faces. Or just an ordinary geom face
233 * It's parametrization is within [0,1] range.
234 * It redefines Adaptor3d_Surface::Value(U,V) where U and V are within [0,1]
236 // --------------------------------------------------------------------
237 class TSideFace: public Adaptor3d_Surface
239 int myID; //!< in-block ID
240 // map used to find out real UV by it's normalized UV
241 TParam2ColumnMap* myParamToColumnMap;
242 BRepAdaptor_Surface mySurface;
243 TopoDS_Edge myBaseEdge;
244 // first and last normalized params and orientaion for each component or it-self
245 std::vector< std::pair< double, double> > myParams;
247 std::vector< TSideFace* > myComponents;
248 SMESH_MesherHelper * myHelper;
250 TSideFace( SMESH_MesherHelper* helper,
252 const TopoDS_Face& face,
253 const TopoDS_Edge& baseEdge,
254 TParam2ColumnMap* columnsMap,
255 const double first = 0.0,
256 const double last = 1.0);
257 TSideFace( const std::vector< TSideFace* >& components,
258 const std::vector< std::pair< double, double> > & params);
259 TSideFace( const TSideFace& other );
261 bool IsComplex() const
262 { return ( NbComponents() > 0 || myParams[0].first != 0. || myParams[0].second != 1. ); }
263 int FaceID() const { return myID; }
264 TParam2ColumnMap* GetColumns() const { return myParamToColumnMap; }
265 gp_XY GetNodeUV(const TopoDS_Face& F, const SMDS_MeshNode* n) const
266 { return myHelper->GetNodeUV( F, n ); }
267 const TopoDS_Edge & BaseEdge() const { return myBaseEdge; }
268 int ColumnHeight() const {
269 if ( NbComponents() ) return GetComponent(0)->GetColumns()->begin()->second.size();
270 else return GetColumns()->begin()->second.size(); }
271 double GetColumns(const double U, TParam2ColumnIt & col1, TParam2ColumnIt& col2 ) const;
272 int NbComponents() const { return myComponents.size(); }
273 TSideFace* GetComponent(const int i) const { return myComponents.at( i ); }
274 void SetComponent(const int i, TSideFace* c)
275 { if ( myComponents[i] ) delete myComponents[i]; myComponents[i]=c; }
276 TSideFace* GetComponent(const double U, double& localU) const;
277 bool IsForward() const { return myIsForward; }
278 // boundary geometry for a face
279 Adaptor3d_Surface* Surface() const { return new TSideFace( *this ); }
280 bool GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const;
281 Adaptor2d_Curve2d* HorizPCurve(const bool isTop, const TopoDS_Face& horFace) const;
282 Adaptor3d_Curve* HorizCurve(const bool isTop) const;
283 Adaptor3d_Curve* VertiCurve(const bool isMax) const;
284 TopoDS_Edge GetEdge( const int edge ) const;
285 int InsertSubShapes( TBlockShapes& shapeMap ) const;
286 // redefine Adaptor methods
287 gp_Pnt Value(const Standard_Real U,const Standard_Real V) const;
290 // --------------------------------------------------------------------
292 * \brief Class emulating geometry of a vertical edge
294 // --------------------------------------------------------------------
295 class STDMESHERS_EXPORT TVerticalEdgeAdaptor: public Adaptor3d_Curve
297 const TNodeColumn* myNodeColumn;
299 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter );
300 gp_Pnt Value(const Standard_Real U) const;
301 Standard_Real FirstParameter() const { return 0; }
302 Standard_Real LastParameter() const { return 1; }
305 // --------------------------------------------------------------------
307 * \brief Class emulating geometry of a hirizontal edge
309 // --------------------------------------------------------------------
310 class STDMESHERS_EXPORT THorizontalEdgeAdaptor: public Adaptor3d_Curve
312 const TSideFace* mySide;
315 THorizontalEdgeAdaptor( const TSideFace* sideFace, const bool isTop)
316 :mySide(sideFace), myV( isTop ? 1.0 : 0.0 ) {}
317 gp_Pnt Value(const Standard_Real U) const;
318 Standard_Real FirstParameter() const { return 0; }
319 Standard_Real LastParameter() const { return 1; }
322 // --------------------------------------------------------------------
324 * \brief Class emulating pcurve on a hirizontal face
326 // --------------------------------------------------------------------
327 class STDMESHERS_EXPORT TPCurveOnHorFaceAdaptor: public Adaptor2d_Curve2d
329 const TSideFace* mySide;
333 TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
335 const TopoDS_Face& horFace)
336 : mySide(sideFace), myFace(horFace), myZ(isTop ? mySide->ColumnHeight() - 1 : 0 ) {}
337 gp_Pnt2d Value(const Standard_Real U) const;
338 Standard_Real FirstParameter() const { return 0; }
339 Standard_Real LastParameter() const { return 1; }
341 // --------------------------------------------------------------------
344 SMESH_MesherHelper* myHelper;
345 TBlockShapes myShapeIDMap;
347 // container of 4 side faces
349 // node columns for each base edge
350 std::vector< TParam2ColumnMap > myParam2ColumnMaps;
351 // to find a column for a node by edge SMESHDS Index
352 std::map< int, std::pair< TParam2ColumnMap*, bool > > myShapeIndex2ColumnMap;
354 SMESH_ComputeErrorPtr myError;
356 * \brief store error and comment and then return ( error == COMPERR_OK )
358 bool error(int error, const SMESH_Comment& comment = "") {
359 myError = SMESH_ComputeError::New(error,comment);
360 return myError->IsOK();
362 //std::vector< SMESH_subMesh* > mySubMeshesVec; // submesh by in-block id
365 // =============================================
367 * \brief Algo building prisms on a prism shape
369 // =============================================
371 class STDMESHERS_EXPORT StdMeshers_Prism_3D: public SMESH_3D_Algo
374 StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen);
375 virtual ~StdMeshers_Prism_3D();
377 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
378 const TopoDS_Shape& aShape,
379 SMESH_Hypothesis::Hypothesis_Status& aStatus);
381 virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
384 * \brief Enable removal of quadrangles from the bottom face and
385 * triangles creation there by projection from the top
386 * (sole face meshed with triangles is considered to be a bottom one).
387 * If there are two faces with triangles, triangles must
388 * be of the same topology, else the algo fails.
389 * The method must be called before Compute()
391 void ProjectTriangles() { myProjectTriangles = true; }
394 * \brief Create prisms
395 * \param nodeColumns - columns of nodes generated from nodes of a mesh face
396 * \param helper - helper initialized by mesh and shape to add prisms to
398 static void AddPrisms( std::vector<const TNodeColumn*> & nodeColumns,
399 SMESH_MesherHelper* helper);
404 * \brief Find correspondence between bottom and top nodes.
405 * If elements on the bottom and top faces are topologically different,
406 * and projection is possible and allowed, perform the projection
407 * \retval bool - is a success or not
409 bool assocOrProjBottom2Top();
412 * \brief Remove quadrangles from the top face and
413 * create triangles there by projection from the bottom
414 * \retval bool - a success or not
416 bool projectBottomToTop();
419 * \brief Set projection coordinates of a node to a face and it's subshapes
420 * \param faceID - the face given by in-block ID
421 * \param params - node normalized parameters
422 * \retval bool - is a success
424 bool setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z );
428 bool myProjectTriangles;
430 StdMeshers_PrismAsBlock myBlock;
431 SMESH_MesherHelper* myHelper;
433 std::vector<gp_XYZ> myShapeXYZ; // point on each sub-shape
435 // map of bottom nodes to the column of nodes above them
436 // (the column includes the bottom node)
437 typedef std::map< TNode, TNodeColumn > TNode2ColumnMap;
438 TNode2ColumnMap myBotToColumnMap;