From 00540d7d380deb9e29fe10a1995eb1dd9099a4dc Mon Sep 17 00:00:00 2001 From: rnc Date: Tue, 25 Jun 2013 16:32:30 +0000 Subject: [PATCH] Hexotic size maps: size maps writing in DriverGMF has been rewritten to use a vector of points as input instead of a mesh. --- src/DriverGMF/DriverGMF_Write.cxx | 119 ++++++++++++++++++++++-------- src/DriverGMF/DriverGMF_Write.hxx | 51 ++++++++++++- 2 files changed, 138 insertions(+), 32 deletions(-) diff --git a/src/DriverGMF/DriverGMF_Write.cxx b/src/DriverGMF/DriverGMF_Write.cxx index 691405f3b..54d179a36 100644 --- a/src/DriverGMF/DriverGMF_Write.cxx +++ b/src/DriverGMF/DriverGMF_Write.cxx @@ -32,6 +32,8 @@ #include +#include "utilities.h" + extern "C" { #include "libmesh5.h" @@ -76,10 +78,10 @@ extern "C" #define END_EXTRA_VERTICES_WRITE() \ ); \ }}}} - - + + DriverGMF_Write::DriverGMF_Write(): - Driver_SMESHDS_Mesh(), _exportRequiredGroups( true ), mySizeMapVerticesNumber( 0 ), mySizeMapMeshes(), myLocalSizes() + Driver_SMESHDS_Mesh(), _exportRequiredGroups( true ), mySizeMapVerticesNumber( 0 ), mySizeMapMeshes(), myLocalSizes()//, mySizeMaps() { } DriverGMF_Write::~DriverGMF_Write() @@ -387,51 +389,110 @@ void DriverGMF_Write::AddSizeMapFromMesh( SMESHDS_Mesh* mesh, double size) myLocalSizes.push_back(TLocalSize(mesh->NbNodes(), size)); } +void DriverGMF_Write::AddSizeMap( const std::vector& points, double size ) +{ +// TSizeMap aMap( points, size ); +// mySizeMaps.push_back( aMap ); + std::vector::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() { - // Open file - const int dim = 3, version = sizeof(long) == 4 ? 2 : 3; - int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim ); +// 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( meshID, GmfVertices, mySizeMapVerticesNumber ); - double xyz[3]; - std::vector::iterator meshes_it; - SMESHDS_Mesh* aMesh; + GmfSetKwd( verticesFileID, GmfVertices, mySizeMapVerticesNumber ); - // Iterate on size map meshes - for (meshes_it = mySizeMapMeshes.begin(); meshes_it != mySizeMapMeshes.end(); meshes_it++ ) + std::vector::iterator points_it; + // Iterate on sizeMaps + for (points_it = myPoints.begin(); points_it != myPoints.end(); points_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( meshID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() ); - } +// MESSAGE("Point : X = "<X()<<", Y ="<Y()<<", Z = "<Z()) + GmfSetLin( verticesFileID, GmfVertices, points_it->X(), points_it->Y(), points_it->Z(), 0 ); } - + // SolAtVertices Keyword int TypTab[] = {GmfSca}; - GmfSetKwd(meshID, GmfSolAtVertices, mySizeMapVerticesNumber, 1, TypTab); - + GmfSetKwd(solFileID, GmfSolAtVertices, mySizeMapVerticesNumber, 1, TypTab); std::vector::iterator sizes_it; for ( sizes_it = myLocalSizes.begin(); sizes_it != myLocalSizes.end(); sizes_it++ ) { - for ( int i = 1; i <= sizes_it->nbNodes; i++ ) + for ( int i = 1; i <= sizes_it->nbPoints ; i++ ) { double ValTab[] = {sizes_it->size}; - GmfSetLin( meshID, GmfSolAtVertices, ValTab); + GmfSetLin( solFileID, GmfSolAtVertices, ValTab); } } - // Close File - GmfCloseMesh( meshID ); + // 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::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::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 diff --git a/src/DriverGMF/DriverGMF_Write.hxx b/src/DriverGMF/DriverGMF_Write.hxx index 36d3b230a..e647c3898 100644 --- a/src/DriverGMF/DriverGMF_Write.hxx +++ b/src/DriverGMF/DriverGMF_Write.hxx @@ -33,17 +33,54 @@ #include "SMDSAbs_ElementType.hxx" #include "SMDS_ElemIterator.hxx" +#include + struct TLocalSize { - TLocalSize( int theNbNodes, double theSize) + TLocalSize( int theNbPoints, double theSize) { - nbNodes = theNbNodes; + nbPoints = theNbPoints; size = theSize; } - int nbNodes; + int nbPoints; 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& thePoints, double theSize ) +// { +// points = thePoints; +// size = theSize; +// }; +// +// double GetSize(){ return size; }; +// std::vector GetPoints(){ return points; }; +// +// private: +// std::vector points; +// double size; +// }; + /*! * \brief Driver Writing a mesh into a GMF file. */ @@ -62,6 +99,11 @@ public: virtual Status Perform(); Status PerformSizeMap(); void AddSizeMapFromMesh( SMESHDS_Mesh* mesh, double size); + void AddSizeMap( const std::vector& points, double size ); + void SetSizeMapPrefix( std::string prefix ) + { + mySizeMapPrefix = prefix; + }; // void WriteSizeMapFromMesh( double size ); // void AddSizeMapSection( int meshID, int nbControlPoints ); // void AppendSize( int meshID, double size ); @@ -77,8 +119,11 @@ public: bool _exportRequiredGroups; int mySizeMapVerticesNumber; + std::string mySizeMapPrefix; std::vector mySizeMapMeshes; std::vector myLocalSizes; + std::vector myPoints; +// std::vector mySizeMaps; }; #endif -- 2.39.2