Salome HOME
REG: SMESH/DriverGMF: Great simplification of the size maps files writing for Hexotic...
authorrnc <rnc@opencascade.com>
Wed, 10 Jul 2013 14:12:56 +0000 (14:12 +0000)
committerrnc <rnc@opencascade.com>
Wed, 10 Jul 2013 14:12:56 +0000 (14:12 +0000)
A class Control_Pnt which inherits from gp_Pnt has been introduced to simplify the internal data structure of size maps.

src/DriverGMF/DriverGMF_Write.cxx
src/DriverGMF/DriverGMF_Write.hxx

index 54d179a3668b5c79df5df849b2b13e14f556f18e..49f3ff00ca1483e60a817797b7ece81d0fc5be57 100644 (file)
@@ -79,9 +79,32 @@ extern "C"
   );                                         \
   }}}}
   
-  
+
+Control_Pnt::Control_Pnt(): gp_Pnt()
+{
+  size=0;
+}
+Control_Pnt::Control_Pnt( const gp_Pnt& aPnt, 
+                          double theSize): gp_Pnt( aPnt )
+{
+  size=theSize;
+}
+Control_Pnt::Control_Pnt(double theX, 
+                         double theY, 
+                         double theZ): gp_Pnt(theX, theY, theZ)
+{
+  size=0;
+}
+Control_Pnt::Control_Pnt(double theX, 
+                         double theY, 
+                         double theZ, 
+                         double theSize): gp_Pnt(theX, theY, theZ)
+{
+  size=theSize;
+}
+
 DriverGMF_Write::DriverGMF_Write():
-  Driver_SMESHDS_Mesh(), _exportRequiredGroups( true ), mySizeMapVerticesNumber( 0 ), mySizeMapMeshes(), myLocalSizes()//, mySizeMaps()
+  Driver_SMESHDS_Mesh(), _exportRequiredGroups( true )
 {
 }
 DriverGMF_Write::~DriverGMF_Write()
@@ -342,67 +365,7 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
   return DRS_OK;
 }
 
-// void DriverGMF_Write::AddSizeMapSection(int meshID, int nbControlPoints)
-// {
-// //   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
-// //   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
-//   int TypTab[] = {GmfSca};
-//   GmfSetKwd(meshID, GmfSolAtVertices, nbControlPoints, 1, TypTab);
-// //   GmfCloseMesh(meshID);
-// //   return DRS_OK;
-// }
-// 
-// void DriverGMF_Write::AppendSize(int meshID, double size)
-// {
-// //   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
-// //   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
-// //   int nbPoints = GmfStatKwd( meshID, GmfSolAtVertices);
-// //   GmfSetKwd( meshID, GmfSolAtVertices, nbPoints+1, 1, 1 );
-//   double ValTab[] = {size};
-//   GmfSetLin( meshID, GmfSolAtVertices, ValTab);
-// //   return DRS_OK;
-// }
-// 
-// int DriverGMF_Write::NbVerticesInFile()
-// {
-//   int dim, version;
-//   // open the file
-//   int meshID = GmfOpenMesh( myFile.c_str(), GmfRead, &version, &dim );
-//   int nbVertices = GmfStatKwd( meshID, GmfVertices);
-//   return nbVertices;
-// }
-// 
-// int DriverGMF_Write::BeginSizeMap()
-// {
-//   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
-//   myGmfID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
-// }
-//  
-// void DriverGMF_Write::EndSizeMap()
-// {
-//   GmfCloseMesh( myGmfID );
-// }
-void DriverGMF_Write::AddSizeMapFromMesh( SMESHDS_Mesh* mesh, double size)
-{
-  mySizeMapMeshes.push_back( mesh );
-  mySizeMapVerticesNumber += mesh->NbNodes();
-  myLocalSizes.push_back(TLocalSize(mesh->NbNodes(), size));
-}
-
-void DriverGMF_Write::AddSizeMap( const std::vector<gp_Pnt>& points, double size )
-{
-//   TSizeMap aMap( points, size );
-//   mySizeMaps.push_back( aMap );
-  std::vector<gp_Pnt>::const_iterator it;
-  for( it = points.begin(); it != points.end(); it++)
-  {
-    myPoints.push_back( *it );
-  }
-  mySizeMapVerticesNumber += points.size();
-  myLocalSizes.push_back(TLocalSize(points.size(), size));
-}
-
-Driver_Mesh::Status DriverGMF_Write::PerformSizeMap()
+Driver_Mesh::Status DriverGMF_Write::PerformSizeMap( const std::vector<Control_Pnt>& points )
 {
 //   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
   const int dim = 3, version = 2; // Version 3 not supported by mg-hexa
@@ -413,117 +376,28 @@ Driver_Mesh::Status DriverGMF_Write::PerformSizeMap()
   int verticesFileID = GmfOpenMesh( aVerticesFile.c_str(), GmfWrite, version, dim );  
   int solFileID = GmfOpenMesh( aSolFile.c_str(), GmfWrite, version, dim );
   
-  // Vertices Keyword
-  GmfSetKwd( verticesFileID, GmfVertices, mySizeMapVerticesNumber );
-  
-  std::vector<gp_Pnt>::iterator points_it;
-  // Iterate on sizeMaps
-  for (points_it = myPoints.begin(); points_it != myPoints.end(); points_it++ )
-  {
-//     MESSAGE("Point : X = "<<points_it->X()<<", Y ="<<points_it->Y()<<", Z = "<<points_it->Z())
-    GmfSetLin( verticesFileID, GmfVertices, points_it->X(), points_it->Y(), points_it->Z(), 0 );
-  }
+  int pointsNumber = points.size();
   
+  // Vertices Keyword
+  GmfSetKwd( verticesFileID, GmfVertices, pointsNumber );
   // SolAtVertices Keyword
   int TypTab[] = {GmfSca};
-  GmfSetKwd(solFileID, GmfSolAtVertices, mySizeMapVerticesNumber, 1, TypTab);
-  std::vector<TLocalSize>::iterator sizes_it; 
-  for ( sizes_it = myLocalSizes.begin(); sizes_it != myLocalSizes.end(); sizes_it++ )
+  GmfSetKwd(solFileID, GmfSolAtVertices, pointsNumber, 1, TypTab);
+  
+  // Read the control points information from the vector and write it into the files
+  std::vector<Control_Pnt>::const_iterator points_it;
+  for (points_it = points.begin(); points_it != points.end(); points_it++ )
   {
-    for ( int i = 1; i <= sizes_it->nbPoints ; i++ )
-    {
-      double ValTab[] = {sizes_it->size};
-      GmfSetLin( solFileID, GmfSolAtVertices, ValTab);
-    }
-  }
+    GmfSetLin( verticesFileID, GmfVertices, points_it->X(), points_it->Y(), points_it->Z(), 0 );
+    double ValTab[] = {points_it->Size()};
+    GmfSetLin( solFileID, GmfSolAtVertices, ValTab);
+  } 
   
   // Close Files
   GmfCloseMesh( verticesFileID );
   GmfCloseMesh( solFileID );
 }
 
-// Driver_Mesh::Status DriverGMF_Write::PerformSizeMap()
-// {
-// //   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
-//   const int dim = 3, version = 2; // Version 3 not supported by mg-hexa
-//   std::string aVerticesFile = mySizeMapPrefix + ".mesh";
-//   std::string aSolFile = mySizeMapPrefix + ".sol";
-//   
-//   // Open files
-//   int verticesFileID = GmfOpenMesh( aVerticesFile.c_str(), GmfWrite, version, dim );  
-//   int solFileID = GmfOpenMesh( aSolFile.c_str(), GmfWrite, version, dim );
-//   
-//   // Vertices Keyword
-//   GmfSetKwd( verticesFileID, GmfVertices, mySizeMapVerticesNumber );
-//   double xyz[3];
-//   std::vector<SMESHDS_Mesh*>::iterator meshes_it;
-//   SMESHDS_Mesh* aMesh;
-//   
-//   // Iterate on size map meshes
-//   for (meshes_it = mySizeMapMeshes.begin(); meshes_it != mySizeMapMeshes.end(); meshes_it++ )
-//   {
-//     aMesh= *meshes_it;
-//     SMDS_NodeIteratorPtr nodeIt = aMesh->nodesIterator();
-//     
-//     // Iterate on the nodes of the mesh and write their coordinates under the GmfVertices keyword
-//     while ( nodeIt->more() )
-//     {
-//       const SMDS_MeshNode* n = nodeIt->next();
-//       n->GetXYZ( xyz );
-//       GmfSetLin( verticesFileID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() );
-//     }
-//   }
-//  
-//   // SolAtVertices Keyword
-//   int TypTab[] = {GmfSca};
-//   GmfSetKwd(solFileID, GmfSolAtVertices, mySizeMapVerticesNumber, 1, TypTab);
-//   
-//   std::vector<TLocalSize>::iterator sizes_it; 
-//   for ( sizes_it = myLocalSizes.begin(); sizes_it != myLocalSizes.end(); sizes_it++ )
-//   {
-//     for ( int i = 1; i <= sizes_it->nbNodes; i++ )
-//     {
-//       double ValTab[] = {sizes_it->size};
-//       GmfSetLin( solFileID, GmfSolAtVertices, ValTab);
-//     }
-//   }
-//   
-//   // Close Files
-//   GmfCloseMesh( verticesFileID );
-//   GmfCloseMesh( solFileID );
-// }
-
-// void DriverGMF_Write::WriteSizeMapFromMesh( double size )
-// {
-//   // Open file
-//   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
-//   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );  
-//   
-//   // Vertices Keyword
-//   int iN = 0, nbNodes = myMesh->NbNodes();
-//   GmfSetKwd( meshID, GmfVertices, nbNodes );
-//   double xyz[3];
-//   SMDS_NodeIteratorPtr nodeIt = myMesh->nodesIterator();
-//   while ( nodeIt->more() )
-//   {
-//     const SMDS_MeshNode* n = nodeIt->next();
-//     n->GetXYZ( xyz );
-//     GmfSetLin( meshID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() );
-//   }
-//   
-//   // solAtVertices Keyword
-//   int TypTab[] = {GmfSca};
-//   GmfSetKwd(meshID, GmfSolAtVertices, nbNodes, 1, TypTab);
-//   for ( int i=1; i<= nbNodes; i++)
-//   {
-//     double ValTab[] = {size};
-//     GmfSetLin( meshID, GmfSolAtVertices, ValTab);
-//   }
-//   
-//   // Close File
-//   GmfCloseMesh( meshID );
-// }
-
 //================================================================================
 /*!
  * \brief Returns an iterator on elements of a certain type
index e647c38989bf21893bbf0e55bfc47d69ee9d18ef..f92f1706a5de151e6a3d91aae0cc7e9db7afabff 100644 (file)
 
 #include <gp_Pnt.hxx>
 
-struct TLocalSize
+/*!
+ * \brief Class for storing control points for writing GMF size maps
+ */
+class Control_Pnt : public gp_Pnt
 {
-  TLocalSize( int theNbPoints, double theSize)
-  {
-    nbPoints = theNbPoints;
-    size = theSize;
-  }
-  int nbPoints;
+public:
+  Control_Pnt();
+  Control_Pnt(const gp_Pnt& aPnt, double theSize);
+  Control_Pnt(double x, double y, double z);
+  Control_Pnt(double x, double y, double z, double size);
+
+  double Size() const { return size; };
+  void SetSize( double theSize ) { size = theSize; };
+  
+private:
   double size;
 };
 
-// struct gp_Pnt
-// {
-//   gp_Pnt( double theX, double theY, double theZ )
-//   {
-//     x = theX;
-//     y = theY;
-//     z = theZ; 
-//   };
-//   double x;
-//   double y;
-//   double z;
-// };
-
-// class TSizeMap
-// { 
-// public:
-//   TSizeMap():
-//     points(), size(0.0)
-//   {
-//   };
-// 
-//   TSizeMap(const std::vector<gp_Pnt>& thePoints, double theSize )
-//   {
-//     points = thePoints;
-//     size = theSize;
-//   };
-//   
-//   double GetSize(){ return size; };
-//   std::vector<gp_Pnt> GetPoints(){ return points; };
-//   
-// private:
-//   std::vector<gp_Pnt> points;
-//   double              size;
-// };
-
 /*!
  * \brief Driver Writing a mesh into a GMF file.
  */
@@ -97,19 +69,13 @@ public:
   }
    
   virtual Status Perform();
-  Status PerformSizeMap();
-  void AddSizeMapFromMesh( SMESHDS_Mesh* mesh, double size);
-  void AddSizeMap( const std::vector<gp_Pnt>& points, double size );
+  
+  // Size Maps
+  Status PerformSizeMap( const std::vector<Control_Pnt>& points );
   void SetSizeMapPrefix( std::string prefix )
   {
     mySizeMapPrefix = prefix;
   };
-//   void WriteSizeMapFromMesh( double size );
-//   void AddSizeMapSection( int meshID, int nbControlPoints );
-//   void AppendSize( int meshID, double size );
-//   int NbVerticesInFile();
-//   int OpenFileToWrite();
-//   void CloseFile( int );
 
  private:
 
@@ -118,12 +84,7 @@ public:
   SMDS_ElemIteratorPtr elementIterator(SMDSAbs_GeometryType type);
 
   bool _exportRequiredGroups;
-  int mySizeMapVerticesNumber;
   std::string mySizeMapPrefix;
-  std::vector<SMESHDS_Mesh*> mySizeMapMeshes;
-  std::vector<TLocalSize> myLocalSizes;
-  std::vector<gp_Pnt> myPoints;
-//   std::vector<TSizeMap> mySizeMaps;
 };
 
 #endif