#include "GHS3DPlugin_GHS3D.hxx"
#include "GHS3DPlugin_Hypothesis.hxx"
+#include <gp_Pnt.hxx>
+#include <TopAbs_State.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
#include "SMESH_Gen.hxx"
#include "SMESH_Mesh.hxx"
int shapeID, nbNodes, aSmdsID;
bool idFound;
- cout << " " << theMesh->NbFaces() << " shapes of 2D dimension" << endl;
- cout << endl;
+ std::cout << " " << theMesh->NbFaces() << " shapes of 2D dimension" << std::endl;
+ std::cout << std::endl;
- theFile << space << theMesh->NbFaces() << space << dummyint << endl;
+ theFile << space << theMesh->NbFaces() << space << dummyint << std::endl;
TopExp_Explorer expface( theMesh->ShapeToMesh(), TopAbs_FACE );
for ( int i = 0; expface.More(); expface.Next(), i++ ) {
for ( int j=0; j<=nbNodes; j++)
theFile << space << dummyint;
- theFile << endl;
+ theFile << std::endl;
}
}
}
if ( nbFaces == 0 )
return false;
- cout << "The initial 2D mesh contains " << nbFaces << " faces and ";
+ std::cout << "The initial 2D mesh contains " << nbFaces << " faces and ";
// NB_ELEMS DUMMY_INT
- theFile << space << nbFaces << space << dummyint << endl;
+ theFile << space << nbFaces << space << dummyint << std::endl;
// Loop from 1 to NB_ELEMS
for ( int i=0; i<=nbNodes; i++)
theFile << space << dummyint;
- theFile << endl;
+ theFile << std::endl;
}
// put nodes to theNodeByGhs3dId vector
// NB_NODES
// Loop from 1 to NB_NODES
// X Y Z DUMMY_INT
-
- // Iterate over the enforced verteces
- map<int,double> theEnforcedNodesIdSizeMap;
- double x,y,z,size;
- const SMDS_MeshNode* node;
- int nodeId;
-
- GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexIt;
- for(vertexIt = theEnforcedVerteces.begin() ; vertexIt != theEnforcedVerteces.end() ; ++vertexIt) {
- x = vertexIt->first->x;
- y = vertexIt->first->y;
- z = vertexIt->first->z;
- size = vertexIt->second;
- node = theMesh->AddNode( x,y,z );
- theEnforcedNodesIdSizeMap.insert( make_pair( node->GetID(), size));
- std::cout << "Creating node at " << node->X() << "," << node->Y() <<"," << node-> Z() << std::endl;
- }
int nbNodes = theMesh->NbNodes();
if ( nbNodes == 0 )
return false;
-
int nbEnforcedVerteces = theEnforcedVerteces.size();
const char* space = " ";
int aGhs3dID = 1;
SMDS_NodeIteratorPtr it = theMesh->nodesIterator();
-// const SMDS_MeshNode* node;
+ const SMDS_MeshNode* node;
// NB_NODES
std::cout << std::endl;
std::cout << "The initial 2D mesh contains :" << std::endl;
std::cout << " " << nbNodes << " nodes" << std::endl;
- std::cout << " " << nbEnforcedVerteces << " enforced vertices" << std::endl;
+ if (nbEnforcedVerteces > 0) {
+ std::cout << " " << nbEnforcedVerteces << " enforced vertices" << std::endl;
+ }
std::cout << std::endl;
std::cout << "Start writing in 'points' file ..." << std::endl;
- theFile << space << nbNodes - nbEnforcedVerteces << std::endl;
+// theFile << space << nbNodes - nbEnforcedVerteces << std::endl;
+ theFile << space << nbNodes << std::endl;
// Loop from 1 to NB_NODES
while ( it->more() )
{
node = it->next();
- if (theEnforcedNodesIdSizeMap.find(node->GetID()) == theEnforcedNodesIdSizeMap.end()) {
- theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
- theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
- aGhs3dID++;
-
- // X Y Z DUMMY_INT
- theFile
- << space << node->X()
- << space << node->Y()
- << space << node->Z()
- << space << dummyint;
-
- theFile << endl;
- }
- else {
- std::cout << "While iterating in nodes, do not add node (" << node->X() << "," << node->Y() <<"," << node-> Z() << ")" << std::endl;
- }
- }
-
- // Iterate over the enforced verteces
- map <int,double>::const_iterator theEnforcedNodesIdSizeMapIt;
-
- for(theEnforcedNodesIdSizeMapIt = theEnforcedNodesIdSizeMap.begin() ;
- theEnforcedNodesIdSizeMapIt != theEnforcedNodesIdSizeMap.end() ; ++theEnforcedNodesIdSizeMapIt) {
- nodeId = theEnforcedNodesIdSizeMapIt->first;
- node = theMesh->FindNode(nodeId);
- size = theEnforcedNodesIdSizeMapIt->second;
- theSmdsToGhs3dIdMap.insert(theSmdsToGhs3dIdMap.end(), make_pair( nodeId, aGhs3dID ));
- theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( aGhs3dID, node ));
+ theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
+ theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
aGhs3dID++;
- // X Y Z PHY_SIZE DUMMY_INT
+ // X Y Z DUMMY_INT
theFile
<< space << node->X()
<< space << node->Y()
<< space << node->Z()
- << space << size
<< space << dummyint;
- theFile << endl;
+ theFile << std::endl;
+
}
- cout << endl;
- cout << "End writing in 'points' file." << endl;
+
+ // Iterate over the enforced verteces
+ GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexIt;
+ const TopoDS_Shape shapeToMesh = theMesh->ShapeToMesh();
+ for(vertexIt = theEnforcedVerteces.begin() ; vertexIt != theEnforcedVerteces.end() ; ++vertexIt) {
+ double x = vertexIt->first->x;
+ double y = vertexIt->first->y;
+ double z = vertexIt->first->z;
+ // Test if point is inside shape to mesh
+ gp_Pnt myPoint(x,y,z);
+ BRepClass3d_SolidClassifier scl(shapeToMesh);
+ scl.Perform(myPoint, 1e-7);
+ TopAbs_State result = scl.State();
+ if ( result == TopAbs_IN ) {
+ std::cout << "Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second << std::endl;
+ // X Y Z PHY_SIZE DUMMY_INT
+ theFile
+ << space << x
+ << space << y
+ << space << z
+ << space << vertexIt->second
+ << space << dummyint;
+
+ theFile << std::endl;
+ }
+ else
+ std::cout << "Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added " << std::endl;
+ }
+ std::cout << std::endl;
+ std::cout << "End writing in 'points' file." << std::endl;
return true;
}
const vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
GHS3DPlugin_Hypothesis::TSizeMapVertexValues & theEnforcedVerteces)
{
+ std::cout << "writePoints(ofstream &,SMESHDS_Mesh *,const vector <const SMDS_MeshNode*> &,GHS3DPlugin_Hypothesis::TSizeMapVertexValues &)" << std::endl;
// record structure:
//
// NB_NODES
// Loop from 1 to NB_NODES
// X Y Z DUMMY_INT
-
+
//int nbNodes = theMesh->NbNodes();
int nbNodes = theNodeByGhs3dId.size();
if ( nbNodes == 0 )
const SMDS_MeshNode* node;
// NB_NODES
- theFile << space << nbNodes << endl;
cout << endl;
cout << "The initial 2D mesh contains :" << endl;
cout << " " << nbNodes << " nodes" << endl;
cout << " " << nbEnforcedVerteces << " enforced vertices" << endl;
+ std::cout << std::endl;
+ std::cout << "Start writing in 'points' file ..." << std::endl;
+ theFile << space << nbNodes << std::endl;
// Loop from 1 to NB_NODES
// X Y Z DUMMY_INT
theFile
- << space << node->X()
- << space << node->Y()
- << space << node->Z()
- << space << dummyint;
+ << space << node->X()
+ << space << node->Y()
+ << space << node->Z()
+ << space << dummyint;
theFile << endl;
+
}
- GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator it;
- for(it = theEnforcedVerteces.begin() ; it != theEnforcedVerteces.end() ; ++it) {
- double x = it->first->x;
- double y = it->first->y;
- double z = it->first->z;
- double size = it->second;
- SMDS_MeshNode* myNode = theMesh->AddNode( x,y,z );
+ // Iterate over the enforced verteces
+ GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexIt;
+ for(vertexIt = theEnforcedVerteces.begin() ; vertexIt != theEnforcedVerteces.end() ; ++vertexIt) {
+ std::cout << "Adding enforced vertex (" << vertexIt->first->x << "," << vertexIt->first->y <<"," << vertexIt->first->z << ") = " << vertexIt->second << std::endl;
// X Y Z PHY_SIZE DUMMY_INT
theFile
- << space << myNode->X()
- << space << myNode->Y()
- << space << myNode->Z()
- << space << size
+ << space << vertexIt->first->x
+ << space << vertexIt->first->y
+ << space << vertexIt->first->z
+ << space << vertexIt->second
<< space << dummyint;
- theFile << endl;
+ theFile << std::endl;
}
+ std::cout << endl;
+ std::cout << "End writing in 'points' file." << std::endl;
return true;
}
double** tabBox,
const int nbShape,
map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
- bool toMeshHoles)
+ bool toMeshHoles,
+ int nbEnforcedVerteces)
{
struct stat status;
size_t length;
for (int iCoor=0; iCoor < 3; iCoor++)
coord[ iCoor ] = strtod(ptr, &ptr);
nodeAssigne[ iNode ] = 1;
- if ( iNode > nbInputNodes ) {
+ if ( iNode > (nbInputNodes-nbEnforcedVerteces) ) {
nodeAssigne[ iNode ] = 0;
aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( iNode, aNewNode ));
static bool readResultFile(const int fileOpen,
SMESHDS_Mesh* theMeshDS,
TopoDS_Shape aSolid,
- vector <const SMDS_MeshNode*>& theNodeByGhs3dId) {
+ vector <const SMDS_MeshNode*>& theNodeByGhs3dId,
+ int nbEnforcedVerteces) {
struct stat status;
size_t length;
for (int iNode=0; iNode < nbNodes; iNode++) {
for (int iCoor=0; iCoor < 3; iCoor++)
coord[ iCoor ] = strtod(ptr, &ptr);
- if ((iNode+1) > nbInputNodes) {
+ if ((iNode+1) > (nbInputNodes-nbEnforcedVerteces)) {
aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
theMeshDS->SetNodeInVolume( aNewNode, shapeID );
theNodeByGhs3dId[ iNode ] = aNewNode;
map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp);
+ int nbEnforcedVerteces = enforcedVerteces.size();
Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, enforcedVerteces) &&
writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap );
bool toMeshHoles =
_hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
Ok = readResultFile( fileOpen, theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap,
- toMeshHoles );
+ toMeshHoles, nbEnforcedVerteces );
}
// ---------------------
return error( SMESH_Comment("Can't write into ") << aPointsFileName);
GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp);
+ int nbEnforcedVerteces = enforcedVerteces.size();
vector <const SMDS_MeshNode*> aNodeByGhs3dId;
Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) &&
Ok = false;
}
else {
- Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId );
+ Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId, nbEnforcedVerteces );
}
// ---------------------