Back to index

salome-smesh  6.5.0
StdMeshers_Prism_3D.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : StdMeshers_Prism_3D.hxx
00025 //  Module : SMESH
00026 //
00027 #ifndef _SMESH_Prism_3D_HXX_
00028 #define _SMESH_Prism_3D_HXX_
00029 
00030 #include "SMESH_StdMeshers.hxx"
00031 
00032 #include "SMESH_3D_Algo.hxx"
00033 #include "SMDS_TypeOfPosition.hxx"
00034 #include "SMDS_MeshNode.hxx"
00035 #include "SMESH_Block.hxx"
00036 #include "SMESH_Mesh.hxx"
00037 #include "SMESHDS_Mesh.hxx"
00038 #include "SMESH_subMesh.hxx"
00039 #include "SMESH_MesherHelper.hxx"
00040 #include "SMESH_Comment.hxx"
00041 
00042 #include <vector>
00043 
00044 #include <Adaptor3d_Curve.hxx>
00045 #include <Adaptor3d_Surface.hxx>
00046 #include <Adaptor2d_Curve2d.hxx>
00047 #include <BRepAdaptor_Surface.hxx>
00048 #include <TopTools_IndexedMapOfOrientedShape.hxx>
00049 #include <gp_XYZ.hxx>
00050 #include <gp_Trsf.hxx>
00051 
00052 
00053 class SMESHDS_SubMesh;
00054 class TopoDS_Edge;
00055 class TopoDS_Faces;
00056 struct TNode;
00057 
00058 //typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
00059 typedef std::vector<const SMDS_MeshNode* > TNodeColumn;
00060 
00061 // map of bottom nodes to the column of nodes above them
00062 // (the column includes the bottom nodes)
00063 typedef std::map< TNode, TNodeColumn >  TNode2ColumnMap;
00064 typedef std::map< double, TNodeColumn > TParam2ColumnMap;
00065 typedef std::map< double, TNodeColumn >::const_iterator TParam2ColumnIt;
00066 
00067 typedef TopTools_IndexedMapOfOrientedShape TBlockShapes;
00068 
00069 // ===============================================
00073 // ===============================================
00074 
00075 struct TNode
00076 {
00077   const SMDS_MeshNode* myNode;
00078   mutable gp_XYZ       myParams;
00079 
00080   gp_XYZ GetCoords() const { return gp_XYZ( myNode->X(), myNode->Y(), myNode->Z() ); }
00081   gp_XYZ GetParams() const { return myParams; }
00082   gp_XYZ& ChangeParams() const { return myParams; }
00083   bool HasParams() const { return myParams.X() >= 0.0; }
00084   SMDS_TypeOfPosition GetPositionType() const
00085   { return myNode ? myNode->GetPosition()->GetTypeOfPosition() : SMDS_TOP_UNSPEC; }
00086   bool IsNeighbor( const TNode& other ) const;
00087 
00088   TNode(const SMDS_MeshNode* node = 0): myNode(node), myParams(-1,-1,-1) {}
00089   bool operator < (const TNode& other) const { return myNode->GetID() < other.myNode->GetID(); }
00090 };
00091 
00092 // ===============================================================
00099 // ===============================================================
00100 
00101 class STDMESHERS_EXPORT StdMeshers_PrismAsBlock: public SMESH_Block
00102 {
00103 public:
00107   StdMeshers_PrismAsBlock();
00108 
00109   ~StdMeshers_PrismAsBlock();
00110 
00120   bool Init(SMESH_MesherHelper* helper, const TopoDS_Shape& shape3D);
00121 
00125   SMESH_ComputeErrorPtr GetError() const { return myError; }
00126 
00130   void Clear();
00131 
00136   int VerticalSize() const { return myParam2ColumnMaps[0].begin()->second.size(); }
00137 
00138   bool HasNotQuadElemOnTop() const { return myNotQuadOnTop; }
00139 
00145   const TNodeColumn* GetNodeColumn(const SMDS_MeshNode* node) const;
00146 
00153   const TParam2ColumnMap* GetParam2ColumnMap(const int baseEdgeID,
00154                                              bool &    isReverse) const
00155   {
00156     std::map< int, std::pair< TParam2ColumnMap*, bool > >::const_iterator i_mo =
00157       myShapeIndex2ColumnMap.find( baseEdgeID );
00158     if ( i_mo == myShapeIndex2ColumnMap.end() ) return 0;
00159 
00160     const std::pair< TParam2ColumnMap*, bool >& col_frw = i_mo->second;
00161     isReverse = !col_frw.second;
00162     return col_frw.first;
00163   }
00164 
00170   bool GetLayersTransformation(std::vector<gp_Trsf> & trsf) const;
00171   
00176   SMESH_Mesh* Mesh() const { return myHelper->GetMesh(); }
00177 
00182   SMESHDS_Mesh* MeshDS() const { return Mesh()->GetMeshDS(); }
00183 
00189   SMESH_subMesh* SubMesh(const int shapeID) const
00190   { return Mesh()->GetSubMesh( Shape( shapeID )); }
00191 
00197   SMESHDS_SubMesh* SubMeshDS(const int shapeID) const
00198   { return SubMesh(shapeID)->GetSubMeshDS(); }
00199 
00205   const TopoDS_Shape& Shape(const int shapeID) const
00206   { return myShapeIDMap( shapeID ); }
00207 
00213   int ShapeID(const TopoDS_Shape& shape) const
00214   { return myShapeIDMap.FindIndex( shape ); }
00215 
00224   static bool IsForwardEdge(SMESHDS_Mesh*           meshDS,
00225                             const TParam2ColumnMap& columnsMap,
00226                             const TopoDS_Edge &     bottomEdge,
00227                             const int               sideFaceID);
00236   bool GetWallFaces( SMESH_Mesh*               mesh,
00237                      const TopoDS_Shape &      mainShape,
00238                      const TopoDS_Shape &      bottomFace,
00239                      std::list< TopoDS_Edge >& bottomEdges,
00240                      std::list< int > &        nbEInW,
00241                      std::list< TopoDS_Face >& wallFaces);
00242 
00243 private:
00244 
00245   // --------------------------------------------------------------------
00253   // --------------------------------------------------------------------
00254   class TSideFace: public Adaptor3d_Surface
00255   {
00256     int                             myID; 
00257     // map used to find out real UV by it's normalized UV
00258     TParam2ColumnMap*               myParamToColumnMap;
00259     BRepAdaptor_Surface             mySurface;
00260     TopoDS_Edge                     myBaseEdge;
00261     // first and last normalized params and orientaion for each component or it-self
00262     std::vector< std::pair< double, double> > myParams;
00263     bool                            myIsForward;
00264     std::vector< TSideFace* >       myComponents;
00265     SMESH_MesherHelper *            myHelper;
00266   public:
00267     TSideFace( SMESH_MesherHelper* helper,
00268                const int           faceID,
00269                const TopoDS_Face&  face,
00270                const TopoDS_Edge&  baseEdge,
00271                TParam2ColumnMap*   columnsMap,
00272                const double        first = 0.0,
00273                const double        last = 1.0);
00274     TSideFace( const std::vector< TSideFace* >&             components,
00275                const std::vector< std::pair< double, double> > & params);
00276     TSideFace( const TSideFace& other );
00277     ~TSideFace();
00278     bool IsComplex() const
00279     { return ( NbComponents() > 0 || myParams[0].first != 0. || myParams[0].second != 1. ); }
00280     int FaceID() const { return myID; }
00281     TParam2ColumnMap* GetColumns() const { return myParamToColumnMap; }
00282     gp_XY GetNodeUV(const TopoDS_Face& F, const SMDS_MeshNode* n) const
00283     { return myHelper->GetNodeUV( F, n ); }
00284     const TopoDS_Edge & BaseEdge() const { return myBaseEdge; }
00285     int ColumnHeight() const {
00286       if ( NbComponents() ) return GetComponent(0)->GetColumns()->begin()->second.size();
00287       else                  return GetColumns()->begin()->second.size(); }
00288     double GetColumns(const double U, TParam2ColumnIt & col1, TParam2ColumnIt& col2 ) const;
00289     int NbComponents() const { return myComponents.size(); }
00290     TSideFace* GetComponent(const int i) const { return myComponents.at( i ); }
00291     void SetComponent(const int i, TSideFace* c)
00292     { if ( myComponents[i] ) delete myComponents[i]; myComponents[i]=c; }
00293     TSideFace* GetComponent(const double U, double& localU) const;
00294     bool IsForward() const { return myIsForward; }
00295     // boundary geometry for a face
00296     Adaptor3d_Surface* Surface() const { return new TSideFace( *this ); }
00297     bool GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const;
00298     Adaptor2d_Curve2d* HorizPCurve(const bool isTop, const TopoDS_Face& horFace) const;
00299     Adaptor3d_Curve* HorizCurve(const bool isTop) const;
00300     Adaptor3d_Curve* VertiCurve(const bool isMax) const;
00301     TopoDS_Edge GetEdge( const int edge ) const;
00302     int InsertSubShapes( TBlockShapes& shapeMap ) const;
00303     // redefine Adaptor methods
00304     gp_Pnt Value(const Standard_Real U,const Standard_Real V) const;
00305     // debug
00306     void dumpNodes(int nbNodes) const;
00307   };
00308 
00309   // --------------------------------------------------------------------
00313   // --------------------------------------------------------------------
00314   class STDMESHERS_EXPORT TVerticalEdgeAdaptor: public Adaptor3d_Curve
00315   {
00316     const TNodeColumn* myNodeColumn;
00317   public:
00318     TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter );
00319     gp_Pnt Value(const Standard_Real U) const;
00320     Standard_Real FirstParameter() const { return 0; }
00321     Standard_Real LastParameter() const { return 1; }
00322     // debug
00323     void dumpNodes(int nbNodes) const;
00324   };
00325 
00326   // --------------------------------------------------------------------
00330   // --------------------------------------------------------------------
00331   class STDMESHERS_EXPORT THorizontalEdgeAdaptor: public Adaptor3d_Curve
00332   {
00333     const TSideFace* mySide;
00334     double           myV;
00335   public:
00336     THorizontalEdgeAdaptor( const TSideFace* sideFace, const bool isTop)
00337       :mySide(sideFace), myV( isTop ? 1.0 : 0.0 ) {}
00338     gp_Pnt Value(const Standard_Real U) const;
00339     Standard_Real FirstParameter() const { return 0; }
00340     Standard_Real LastParameter() const { return 1; }
00341     // debug
00342     void dumpNodes(int nbNodes) const;
00343   };
00344 
00345   // --------------------------------------------------------------------
00349   // --------------------------------------------------------------------
00350   class STDMESHERS_EXPORT TPCurveOnHorFaceAdaptor: public Adaptor2d_Curve2d
00351   {
00352     const TSideFace*  mySide;
00353     int               myZ;
00354     TopoDS_Face       myFace;
00355   public:
00356     TPCurveOnHorFaceAdaptor( const TSideFace*   sideFace,
00357                              const bool         isTop,
00358                              const TopoDS_Face& horFace)
00359       : mySide(sideFace), myFace(horFace), myZ(isTop ? mySide->ColumnHeight() - 1 : 0 ) {}
00360     gp_Pnt2d Value(const Standard_Real U) const;
00361     Standard_Real FirstParameter() const { return 0; }
00362     Standard_Real LastParameter() const { return 1; }
00363   };
00364 
00365   bool                  myNotQuadOnTop;
00366   SMESH_MesherHelper*   myHelper;
00367   TBlockShapes          myShapeIDMap;
00368   SMESH_ComputeErrorPtr myError;
00369 
00370   // container of 4 side faces
00371   TSideFace*            mySide; 
00372   // node columns for each base edge
00373   std::vector< TParam2ColumnMap >                       myParam2ColumnMaps;
00374   // to find a column for a node by edge SMESHDS Index
00375   std::map< int, std::pair< TParam2ColumnMap*, bool > > myShapeIndex2ColumnMap;
00376 
00380   bool error(int error, const SMESH_Comment& comment = "") {
00381     myError = SMESH_ComputeError::New(error,comment);
00382     return myError->IsOK();
00383   }
00384 };
00385 
00386 // =============================================
00390 // =============================================
00391 
00392 class STDMESHERS_EXPORT StdMeshers_Prism_3D: public SMESH_3D_Algo
00393 {
00394 public:
00395   StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen);
00396   virtual ~StdMeshers_Prism_3D();
00397 
00398   virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
00399                                const TopoDS_Shape&                  aShape,
00400                                SMESH_Hypothesis::Hypothesis_Status& aStatus);
00401 
00402   virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
00403 
00404   virtual bool Evaluate(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape,
00405                         MapShapeNbElems& aResMap);
00406 
00415   void ProjectTriangles() { myProjectTriangles = true; }
00416 
00422   static void AddPrisms( std::vector<const TNodeColumn*> & nodeColumns,
00423                          SMESH_MesherHelper*          helper);
00424 
00425 private:
00426 
00433   bool assocOrProjBottom2Top();
00434 
00440   bool projectBottomToTop();
00441 
00448   bool setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z );
00449 
00450 private:
00451 
00452   bool myProjectTriangles;
00453 
00454   StdMeshers_PrismAsBlock myBlock;
00455   SMESH_MesherHelper*     myHelper;
00456 
00457   std::vector<gp_XYZ>     myShapeXYZ; // point on each sub-shape of the block
00458 
00459   // map of bottom nodes to the column of nodes above them
00460   // (the column includes the bottom node)
00461   TNode2ColumnMap         myBotToColumnMap;
00462 };
00463 
00464 #endif