From: nge Date: Fri, 10 Jul 2009 11:40:34 +0000 (+0000) Subject: Last developments update. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b815762a10a0a430306f75209173cf83e8646486;p=plugins%2Fghs3dplugin.git Last developments update. Some bugs leading to SIGSEGV must be solved (in particular, GHS3D algorithm without hypothesis does not work anymore) --- diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index 9506322..292d192 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -28,6 +28,9 @@ using namespace std; #include "GHS3DPlugin_GHS3D.hxx" #include "GHS3DPlugin_Hypothesis.hxx" +#include +#include +#include #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" @@ -243,10 +246,10 @@ static bool writeFaces (ofstream & theFile, 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++ ) { @@ -292,7 +295,7 @@ static bool writeFaces (ofstream & theFile, for ( int j=0; j<=nbNodes; j++) theFile << space << dummyint; - theFile << endl; + theFile << std::endl; } } } @@ -343,10 +346,10 @@ static bool writeFaces (ofstream & theFile, 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 @@ -374,7 +377,7 @@ static bool writeFaces (ofstream & theFile, for ( int i=0; i<=nbNodes; i++) theFile << space << dummyint; - theFile << endl; + theFile << std::endl; } // put nodes to theNodeByGhs3dId vector @@ -404,28 +407,10 @@ static bool writePoints (ofstream & theFile, // NB_NODES // Loop from 1 to NB_NODES // X Y Z DUMMY_INT - - // Iterate over the enforced verteces - map 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 = " "; @@ -433,65 +418,69 @@ static bool writePoints (ofstream & theFile, 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 ::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; } @@ -506,12 +495,13 @@ static bool writePoints (ofstream & theFile, const vector & theNodeByGhs3dId, GHS3DPlugin_Hypothesis::TSizeMapVertexValues & theEnforcedVerteces) { + std::cout << "writePoints(ofstream &,SMESHDS_Mesh *,const vector &,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 ) @@ -525,11 +515,13 @@ static bool writePoints (ofstream & theFile, 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 @@ -541,32 +533,32 @@ static bool writePoints (ofstream & theFile, // 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; } @@ -696,7 +688,8 @@ static bool readResultFile(const int fileOpen, double** tabBox, const int nbShape, map & theGhs3dIdToNodeMap, - bool toMeshHoles) + bool toMeshHoles, + int nbEnforcedVerteces) { struct stat status; size_t length; @@ -763,7 +756,7 @@ static bool readResultFile(const int fileOpen, 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 )); @@ -907,7 +900,8 @@ static bool readResultFile(const int fileOpen, static bool readResultFile(const int fileOpen, SMESHDS_Mesh* theMeshDS, TopoDS_Shape aSolid, - vector & theNodeByGhs3dId) { + vector & theNodeByGhs3dId, + int nbEnforcedVerteces) { struct stat status; size_t length; @@ -960,7 +954,7 @@ static bool readResultFile(const int fileOpen, 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; @@ -1069,6 +1063,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, map aGhs3dIdToNodeMap; GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); + int nbEnforcedVerteces = enforcedVerteces.size(); Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, enforcedVerteces) && writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap ); @@ -1120,7 +1115,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, bool toMeshHoles = _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles(); Ok = readResultFile( fileOpen, theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, - toMeshHoles ); + toMeshHoles, nbEnforcedVerteces ); } // --------------------- @@ -1210,6 +1205,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return error( SMESH_Comment("Can't write into ") << aPointsFileName); GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); + int nbEnforcedVerteces = enforcedVerteces.size(); vector aNodeByGhs3dId; Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) && @@ -1251,7 +1247,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = false; } else { - Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId ); + Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId, nbEnforcedVerteces ); } // --------------------- diff --git a/src/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin_Hypothesis.cxx index 97af83e..aadb51c 100644 --- a/src/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin_Hypothesis.cxx @@ -308,7 +308,7 @@ double GHS3DPlugin_Hypothesis::GetSizeMapVertex(double x, double y, double z) void GHS3DPlugin_Hypothesis::ClearSizeMapVerteces() { mySizeMapVerteces.clear(); -// mySizeMapVerteces = DefaultSizeMapVerteces(); + NotifySubMeshesHypothesisModification(); } //======================================================================= diff --git a/src/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin_Hypothesis.hxx index f9cdca6..683402f 100644 --- a/src/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin_Hypothesis.hxx @@ -109,7 +109,6 @@ public: } GHS3DSizeMapVertex; typedef std::map TSizeMapVertexValues; -// typedef std::map TSizeMapVertexValues; void SetSizeMapVertex(double x, double y, double z, double size); double GetSizeMapVertex(double x, double y, double z) throw (std::invalid_argument); const TSizeMapVertexValues GetSizeMapVerteces() const { return mySizeMapVerteces; } diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index 05ed3dd..b88a820 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -113,6 +113,10 @@ namespace { } } +// +// BEGIN DoubleLineEditDelegate +// + DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent) : QItemDelegate(parent) { @@ -157,6 +161,9 @@ void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor, editor->setGeometry(option.rect); } +// +// END DoubleLineEditDelegate +// GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType ) : SMESHGUI_GenericHypothesisCreator( theHypType ) @@ -334,13 +341,13 @@ bool GHS3DPluginGUI_HypothesisCreator::smpVertexExists(double x, double y, doubl if (myX == x) { std::cout << "Found x value " << x << " at row " << i << std::endl; double myY = mySmpModel->data(mySmpModel->index(i, SMP_Y_COLUMN)).toDouble(); - double myZ = mySmpModel->data(mySmpModel->index(i, SMP_Z_COLUMN)).toDouble(); - std::cout << "y: " << myY << std::endl; - std::cout << "z: " << myY << std::endl; - if ((myY == y) and (myZ == z) ) { - std::cout << "Found y value " << y << " at row " << i << std::endl; + if (myY == y) { + std::cout << "Found y value " << y << " at row " << i << std::endl; + double myZ = mySmpModel->data(mySmpModel->index(i, SMP_Z_COLUMN)).toDouble(); + if (myZ == z) { std::cout << "Found z value " << z << " at row " << i << std::endl; return true; + } } } } @@ -606,7 +613,11 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD h->SetTextOption ( h_data.myTextOption.toLatin1().constData() ); std::cout << "Store params for size maps: " << (int) h_data.mySizeMapVerteces.size() << " enforced verteces" << std::endl; TSizeMapVertexValues::const_iterator it; - h->ClearSizeMapVerteces(); + if (h_data.mySizeMapVerteces.size() == 0) + if (h->GetSizeMapVerteces()->length() > 0) + h->ClearSizeMapVerteces(); + else + h->ClearSizeMapVerteces(); for(it = h_data.mySizeMapVerteces.begin() ; it != h_data.mySizeMapVerteces.end(); it++ ) { double x = it->first->x; double y = it->first->y;