X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYBRIDPlugin%2FHYBRIDPlugin_HYBRID.cxx;h=6cc4efbbf6636ffc41ab79d528ffb157ddc7cae7;hb=db577540df5e6802a2028d44d8290f5824a50eb3;hp=02b9e78c3d4c2065d70a7e6c228c1608c6c16e77;hpb=b29ad43bc8f527208b97548dbc42ba1174988ee9;p=plugins%2Fhybridplugin.git diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx index 02b9e78..6cc4efb 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -41,8 +41,6 @@ #include #include #include -// #include -// #include #include #include @@ -87,13 +85,13 @@ typedef const std::list TTriaList; static const char theDomainGroupNamePrefix[] = "Domain_"; -static void removeFile( const TCollection_AsciiString& fileName ) +static void removeFile( const std::string& fileName ) { try { - SMESH_File( fileName.ToCString() ).remove(); + SMESH_File( fileName ).remove(); } catch ( ... ) { - MESSAGE("Can't remove file: " << fileName.ToCString() << " ; file does not exist or permission denied"); + MESSAGE("Can't remove file: " << fileName << " ; file does not exist or permission denied"); } } @@ -103,30 +101,16 @@ static void removeFile( const TCollection_AsciiString& fileName ) */ //============================================================================= -HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_3D_Algo(hypId, studyId, gen) +HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, SMESH_Gen* gen) + : SMESH_3D_Algo(hypId, gen) { - MESSAGE("HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID"); _name = Name(); _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type _onlyUnaryInput = true; // Compute() will be called on each solid _iShape=0; _nbShape=0; _compatibleHypothesis.push_back( HYBRIDPlugin_Hypothesis::GetHypType()); - //_compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() ); - _requireShape = false; // can work without shape_studyId - - smeshGen_i = SMESH_Gen_i::GetSMESHGen(); - CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject); - - MESSAGE("studyid = " << _studyId); - - myStudy = NULL; - myStudy = aStudyMgr->GetStudyByID(_studyId); - if (!myStudy->_is_nil()) - MESSAGE("myStudy->StudyId() = " << myStudy->StudyId()); - + _requireShape = false; // can work without shape _computeCanceled = false; } @@ -138,7 +122,6 @@ HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, int studyId, SMESH_Gen* gen) HYBRIDPlugin_HYBRID::~HYBRIDPlugin_HYBRID() { - MESSAGE("HYBRIDPlugin_HYBRID::~HYBRIDPlugin_HYBRID"); } //============================================================================= @@ -154,7 +137,6 @@ bool HYBRIDPlugin_HYBRID::CheckHypothesis ( SMESH_Mesh& aMesh, aStatus = SMESH_Hypothesis::HYP_OK; _hyp = 0; - //_viscousLayersHyp = 0; _keepFiles = false; _removeLogOnSuccess = true; _logInStandardOutput = false; @@ -166,8 +148,6 @@ bool HYBRIDPlugin_HYBRID::CheckHypothesis ( SMESH_Mesh& aMesh, { if ( !_hyp ) _hyp = dynamic_cast< const HYBRIDPlugin_Hypothesis*> ( *h ); - // if ( !_viscousLayersHyp ) - // _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h ); } if ( _hyp ) { @@ -187,276 +167,21 @@ bool HYBRIDPlugin_HYBRID::CheckHypothesis ( SMESH_Mesh& aMesh, TopoDS_Shape HYBRIDPlugin_HYBRID::entryToShape(std::string entry) { - MESSAGE("HYBRIDPlugin_HYBRID::entryToShape "<_is_nil() ) + if ( SMESH_Gen_i::getStudyServant()->_is_nil() ) throw SALOME_Exception("MG-HYBRID plugin can't work w/o publishing in the study"); GEOM::GEOM_Object_var aGeomObj; TopoDS_Shape S = TopoDS_Shape(); - SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() ); + SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() ); if (!aSObj->_is_nil() ) { CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); aSObj->UnRegister(); } if ( !aGeomObj->_is_nil() ) - S = smeshGen_i->GeomObjectToShape( aGeomObj.in() ); + S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() ); return S; } -//======================================================================= -//function : findShape -//purpose : -//======================================================================= - -// static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[], -// TopoDS_Shape aShape, -// const TopoDS_Shape shape[], -// double** box, -// const int nShape, -// TopAbs_State * state = 0) -// { -// gp_XYZ aPnt(0,0,0); -// int j, iShape, nbNode = 4; - -// for ( j=0; jX(), aNode[j]->Y(), aNode[j]->Z() ); -// if ( aNode[j]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE ) { -// aPnt = p; -// break; -// } -// aPnt += p / nbNode; -// } - -// BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion()); -// if (state) *state = SC.State(); -// if ( SC.State() != TopAbs_IN || aShape.IsNull() || aShape.ShapeType() != TopAbs_SOLID) { -// for (iShape = 0; iShape < nShape; iShape++) { -// aShape = shape[iShape]; -// if ( !( aPnt.X() < box[iShape][0] || box[iShape][1] < aPnt.X() || -// aPnt.Y() < box[iShape][2] || box[iShape][3] < aPnt.Y() || -// aPnt.Z() < box[iShape][4] || box[iShape][5] < aPnt.Z()) ) { -// BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion()); -// if (state) *state = SC.State(); -// if (SC.State() == TopAbs_IN) -// break; -// } -// } -// } -// return aShape; -// } - -//======================================================================= -//function : readMapIntLine -//purpose : -//======================================================================= - -// static char* readMapIntLine(char* ptr, int tab[]) { -// long int intVal; -// std::cout << std::endl; - -// for ( int i=0; i<17; i++ ) { -// intVal = strtol(ptr, &ptr, 10); -// if ( i < 3 ) -// tab[i] = intVal; -// } -// return ptr; -// } - -//================================================================================ -/*! - * \brief returns true if a triangle defined by the nodes is a temporary face on a - * side facet of pyramid and defines sub-domain inside the pyramid - */ -//================================================================================ - -// static bool isTmpFace(const SMDS_MeshNode* node1, -// const SMDS_MeshNode* node2, -// const SMDS_MeshNode* node3) -// { -// // find a pyramid sharing the 3 nodes -// //const SMDS_MeshElement* pyram = 0; -// SMDS_ElemIteratorPtr vIt1 = node1->GetInverseElementIterator(SMDSAbs_Volume); -// while ( vIt1->more() ) -// { -// const SMDS_MeshElement* pyram = vIt1->next(); -// if ( pyram->NbCornerNodes() != 5 ) continue; -// int i2, i3; -// if ( (i2 = pyram->GetNodeIndex( node2 )) >= 0 && -// (i3 = pyram->GetNodeIndex( node3 )) >= 0 ) -// { -// // Triangle defines sub-domian inside the pyramid if it's -// // normal points out of the pyram - -// // make i2 and i3 hold indices of base nodes of the pyram while -// // keeping the nodes order in the triangle -// const int iApex = 4; -// if ( i2 == iApex ) -// i2 = i3, i3 = pyram->GetNodeIndex( node1 ); -// else if ( i3 == iApex ) -// i3 = i2, i2 = pyram->GetNodeIndex( node1 ); - -// int i3base = (i2+1) % 4; // next index after i2 within the pyramid base -// return ( i3base != i3 ); -// } -// } -// return false; -// } - -//======================================================================= -//function : findShapeID -//purpose : find the solid corresponding to HYBRID sub-domain following -// the technique proposed in GHS3D manual (available within -// ghs3d installation) in chapter "B.4 Subdomain (sub-region) assignment". -// In brief: normal of the triangle defined by the given nodes -// points out of the domain it is associated to -//======================================================================= - -// static int findShapeID(SMESH_Mesh& mesh, -// const SMDS_MeshNode* node1, -// const SMDS_MeshNode* node2, -// const SMDS_MeshNode* node3, -// const bool toMeshHoles) -// { -// const int invalidID = 0; -// SMESHDS_Mesh* meshDS = mesh.GetMeshDS(); - -// // face the nodes belong to -// std::vector nodes(3); -// nodes[0] = node1; -// nodes[1] = node2; -// nodes[2] = node3; -// const SMDS_MeshElement * face = meshDS->FindElement( nodes, SMDSAbs_Face, /*noMedium=*/true); -// if ( !face ) -// return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID; -// #ifdef _DEBUG_ -// std::cout << "bnd face " << face->GetID() << " - "; -// #endif -// // geom face the face assigned to -// SMESH_MeshEditor editor(&mesh); -// int geomFaceID = editor.FindShape( face ); -// if ( !geomFaceID ) -// return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID; -// TopoDS_Shape shape = meshDS->IndexToShape( geomFaceID ); -// if ( shape.IsNull() || shape.ShapeType() != TopAbs_FACE ) -// return invalidID; -// TopoDS_Face geomFace = TopoDS::Face( shape ); - -// // solids bounded by geom face -// TopTools_IndexedMapOfShape solids, shells; -// TopTools_ListIteratorOfListOfShape ansIt = mesh.GetAncestors(geomFace); -// for ( ; ansIt.More(); ansIt.Next() ) { -// switch ( ansIt.Value().ShapeType() ) { -// case TopAbs_SOLID: -// solids.Add( ansIt.Value() ); break; -// case TopAbs_SHELL: -// shells.Add( ansIt.Value() ); break; -// default:; -// } -// } -// // analyse found solids -// if ( solids.Extent() == 0 || shells.Extent() == 0) -// return invalidID; - -// const TopoDS_Solid& solid1 = TopoDS::Solid( solids(1) ); -// if ( solids.Extent() == 1 ) -// { -// if ( toMeshHoles ) -// return meshDS->ShapeToIndex( solid1 ); - -// // - Are we at a hole boundary face? -// if ( shells(1).IsSame( BRepClass3d::OuterShell( solid1 )) ) -// { // - No, but maybe a hole is bound by two shapes? Does shells(1) touches another shell? -// bool touch = false; -// TopExp_Explorer eExp( shells(1), TopAbs_EDGE ); -// // check if any edge of shells(1) belongs to another shell -// for ( ; eExp.More() && !touch; eExp.Next() ) { -// ansIt = mesh.GetAncestors( eExp.Current() ); -// for ( ; ansIt.More() && !touch; ansIt.Next() ) { -// if ( ansIt.Value().ShapeType() == TopAbs_SHELL ) -// touch = ( !ansIt.Value().IsSame( shells(1) )); -// } -// } -// if (!touch) -// return meshDS->ShapeToIndex( solid1 ); -// } -// } -// // find orientation of geom face within the first solid -// TopExp_Explorer fExp( solid1, TopAbs_FACE ); -// for ( ; fExp.More(); fExp.Next() ) -// if ( geomFace.IsSame( fExp.Current() )) { -// geomFace = TopoDS::Face( fExp.Current() ); -// break; -// } -// if ( !fExp.More() ) -// return invalidID; // face not found - -// // normale to triangle -// gp_Pnt node1Pnt ( node1->X(), node1->Y(), node1->Z() ); -// gp_Pnt node2Pnt ( node2->X(), node2->Y(), node2->Z() ); -// gp_Pnt node3Pnt ( node3->X(), node3->Y(), node3->Z() ); -// gp_Vec vec12( node1Pnt, node2Pnt ); -// gp_Vec vec13( node1Pnt, node3Pnt ); -// gp_Vec meshNormal = vec12 ^ vec13; -// if ( meshNormal.SquareMagnitude() < DBL_MIN ) -// return invalidID; - -// // get normale to geomFace at any node -// bool geomNormalOK = false; -// gp_Vec geomNormal; -// SMESH_MesherHelper helper( mesh ); helper.SetSubShape( geomFace ); -// for ( int i = 0; !geomNormalOK && i < 3; ++i ) -// { -// // find UV of i-th node on geomFace -// const SMDS_MeshNode* nNotOnSeamEdge = 0; -// if ( helper.IsSeamShape( nodes[i]->getshapeId() )) { -// if ( helper.IsSeamShape( nodes[(i+1)%3]->getshapeId() )) -// nNotOnSeamEdge = nodes[(i+2)%3]; -// else -// nNotOnSeamEdge = nodes[(i+1)%3]; -// } -// bool uvOK; -// gp_XY uv = helper.GetNodeUV( geomFace, nodes[i], nNotOnSeamEdge, &uvOK ); -// // check that uv is correct -// if (uvOK) { -// double tol = 1e-6; -// TopoDS_Shape nodeShape = helper.GetSubShapeByNode( nodes[i], meshDS ); -// if ( !nodeShape.IsNull() ) -// switch ( nodeShape.ShapeType() ) -// { -// case TopAbs_FACE: tol = BRep_Tool::Tolerance( TopoDS::Face( nodeShape )); break; -// case TopAbs_EDGE: tol = BRep_Tool::Tolerance( TopoDS::Edge( nodeShape )); break; -// case TopAbs_VERTEX: tol = BRep_Tool::Tolerance( TopoDS::Vertex( nodeShape )); break; -// default:; -// } -// gp_Pnt nodePnt ( nodes[i]->X(), nodes[i]->Y(), nodes[i]->Z() ); -// BRepAdaptor_Surface surface( geomFace ); -// uvOK = ( nodePnt.Distance( surface.Value( uv.X(), uv.Y() )) < 2 * tol ); -// if ( uvOK ) { -// // normale to geomFace at UV -// gp_Vec du, dv; -// surface.D1( uv.X(), uv.Y(), nodePnt, du, dv ); -// geomNormal = du ^ dv; -// if ( geomFace.Orientation() == TopAbs_REVERSED ) -// geomNormal.Reverse(); -// geomNormalOK = ( geomNormal.SquareMagnitude() > DBL_MIN * 1e3 ); -// } -// } -// } -// if ( !geomNormalOK) -// return invalidID; - -// // compare normals -// bool isReverse = ( meshNormal * geomNormal ) < 0; -// if ( !isReverse ) -// return meshDS->ShapeToIndex( solid1 ); - -// if ( solids.Extent() == 1 ) -// return HOLE_ID; // we are inside a hole - -// return meshDS->ShapeToIndex( solids(2) ); -// } - - //======================================================================= //function : addElemInMeshGroup //purpose : Update or create groups in mesh @@ -480,19 +205,16 @@ static void addElemInMeshGroup(SMESH_Mesh* theMesh, SMESHDS_Group* aGroupDS = static_cast( groupDS ); aGroupDS->SMDSGroup().Add(anElem); groupDone = true; -// MESSAGE("Successfully added enforced element to existing group " << groupName); break; } } if (!groupDone) { - int groupId; - SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId); + SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str()); aGroup->SetName( groupName.c_str() ); SMESHDS_Group* aGroupDS = static_cast( aGroup->GetGroupDS() ); aGroupDS->SMDSGroup().Add(anElem); -// MESSAGE("Successfully created enforced vertex group " << groupName); groupDone = true; } if (!groupDone) @@ -516,7 +238,6 @@ static void updateMeshGroups(SMESH_Mesh* theMesh, std::set groupsTo std::string currentGroupName = (std::string)group->GetName(); if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) { // Previous group created by enforced elements - MESSAGE("Delete previous group created by removed enforced elements: " << group->GetName()) theMesh->RemoveGroup(groupDS->GetID()); } } @@ -563,11 +284,6 @@ static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh, static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* > >& elemsOfDomain, SMESH_MesherHelper* theHelper) { - // int nbDomains = 0; - // for ( size_t i = 0; i < elemsOfDomain.size(); ++i ) - // nbDomains += ( elemsOfDomain[i].size() > 0 ); - - // if ( nbDomains > 1 ) for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain ) { std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ]; @@ -586,13 +302,12 @@ static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* } // create and fill the groups size_t iElem = 0; - int groupID; do { SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ]; if ( !group ) group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(), - domainName.c_str(), groupID ); + domainName.c_str() ); SMDS_MeshGroup& groupDS = static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup(); @@ -608,38 +323,75 @@ static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* //purpose : read GMF file w/o geometry associated to mesh //======================================================================= -static bool readGMFFile(MG_HYBRID_API* MGOutput, - const char* theFile, - HYBRIDPlugin_HYBRID* theAlgo, - SMESH_MesherHelper* theHelper, +static bool readGMFFile(MG_HYBRID_API* MGOutput, + const char* theFile, + HYBRIDPlugin_HYBRID* theAlgo, + SMESH_MesherHelper* theHelper, std::vector & theNodeByHybridId, std::vector & theFaceByHybridId, - std::map & theNodeToHybridIdMap, - std::vector & aNodeGroupByHybridId, - std::vector & anEdgeGroupByHybridId, - std::vector & aFaceGroupByHybridId, - std::set & groupsToRemove, - bool toMakeGroupsOfDomains=false, - bool toMeshHoles=true) + std::map & theNodeToHybridIdMap, + std::vector & aNodeGroupByHybridId, + std::vector & anEdgeGroupByHybridId, + std::vector & aFaceGroupByHybridId, + std::set & groupsToRemove, + bool toMakeGroupsOfDomains=false, + bool toMeshHoles=true) { std::string tmpStr; SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS(); const bool hasGeom = ( theHelper->GetMesh()->HasShapeToMesh() ); - int nbInitialNodes = theNodeByHybridId.size(); + // if imprinting, the original mesh faces are modified + // => we clear all the faces to retrieve them from Hybrid output mesh. + std::vector facesWithImprinting; + if (theAlgo->getHyp()) + facesWithImprinting = theAlgo->getHyp()->GetFacesWithImprinting(); + + if ( ! facesWithImprinting.empty() ) { +#ifdef _DEBUG_ + std::cout << "Imprinting => Clear original mesh" << std::endl; +#endif + SMESH_subMesh* smOfSolid = + theHelper->GetMesh()->GetSubMesh( theHelper->GetSubShape() ); + SMESH_subMeshIteratorPtr smIt = + smOfSolid->getDependsOnIterator(/*includeSelf=*/false, /*complexShapeFirst=*/true); + while ( smIt->more() ) + { + SMESH_subMesh* sm = smIt->next(); + if ( SMESHDS_SubMesh * smDS = sm->GetSubMeshDS() ) + { + SMDS_ElemIteratorPtr eIt = smDS->GetElements(); + while( eIt->more() ) + { + theMeshDS->RemoveFreeElement( eIt->next(), smDS ); + } + SMDS_NodeIteratorPtr nIt = smDS->GetNodes(); + while ( nIt->more() ) + { + const SMDS_MeshNode* n = nIt->next(); + if ( n->NbInverseElements() == 0 ) + theMeshDS->RemoveFreeNode( n, smDS ); + } + } + } + theNodeByHybridId.clear(); + theFaceByHybridId.clear(); + } + int nbMeshNodes = theMeshDS->NbNodes(); - - const bool isQuadMesh = + int nbInitialNodes = theNodeByHybridId.size(); + + const bool isQuadMesh = theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) || theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) || theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC ); - + #ifdef _DEBUG_ std::cout << "theNodeByHybridId.size(): " << nbInitialNodes << std::endl; std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl; std::cout << "isQuadMesh: " << isQuadMesh << std::endl; #endif - + // --------------------------------- // Read generated elements and nodes // --------------------------------- @@ -661,15 +413,14 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, tabRef[GmfTriangles] = 3; // for enforced faces tabRef[GmfQuadrilaterals] = 4; tabRef[GmfTetrahedra] = 4; // for new tetras + tabRef[GmfPyramids] = 5; // for new pyramids tabRef[GmfPrisms] = 6; // for new prisms tabRef[GmfHexahedra] = 8; int ver, dim; - MESSAGE("Read " << theFile << " file"); int InpMsh = MGOutput->GmfOpenMesh(theFile, GmfRead, &ver, &dim); if (!InpMsh) return false; - MESSAGE("Done "); // Hybrid is not multi-domain => We can't (and don't need to) read ids of domains in ouput file like in GHS3DPlugin // We just need to get the id of the one and only solid @@ -788,10 +539,15 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]); #ifdef _DEBUG_ subdomainId2tetraId[dummy].insert(iElem+1); -// MESSAGE("subdomainId2tetraId["< 0) { + (nbElem <= 1) ? tmpStr = " Pyramid" : tmpStr = " Pyramids"; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], + &id[iElem*tabRef[token]+4], &domainID[iElem]); + } else if (token == GmfPrisms && nbElem > 0) { (nbElem <= 1) ? tmpStr = " Prism" : tmpStr = " Prisms"; for ( int iElem = 0; iElem < nbElem; iElem++ ) @@ -814,6 +570,7 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, case GmfTriangles: case GmfQuadrilaterals: case GmfTetrahedra: + case GmfPyramids: case GmfPrisms: case GmfHexahedra: { @@ -852,20 +609,38 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, case GmfEdges: if (fullyCreatedElement) { aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d ); - if (anEdgeGroupByHybridId.size() && !anEdgeGroupByHybridId[iElem].empty()) + if ( !anEdgeGroupByHybridId.empty() && !anEdgeGroupByHybridId[iElem].empty()) addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByHybridId[iElem], groupsToRemove); } break; case GmfTriangles: if (fullyCreatedElement) { aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d ); - if (aFaceGroupByHybridId.size() && !aFaceGroupByHybridId[iElem].empty()) + // add iElem < aFaceGroupByHybridId.size() to avoid crash if imprinting with hexa core with MeshGems <= 2.4-5 + if ( iElem < (int)aFaceGroupByHybridId.size() && !aFaceGroupByHybridId[iElem].empty() ) { addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByHybridId[iElem], groupsToRemove); + } + // add element in shape for groups on geom to work + if ( domainID[iElem] > 0 ) + { + theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] ); + for ( int iN = 0; iN < 3; ++iN ) + if ( node[iN]->getshapeId() < 1 ) + theMeshDS->SetNodeOnFace( node[iN], domainID[iElem] ); + } } break; case GmfQuadrilaterals: if (fullyCreatedElement) { aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d ); + // add element in shape for groups on geom to work + if ( domainID[iElem] > 0 ) + { + theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] ); + for ( int iN = 0; iN < 3; ++iN ) + if ( node[iN]->getshapeId() < 1 ) + theMeshDS->SetNodeOnFace( node[iN], domainID[iElem] ); + } } break; case GmfTetrahedra: @@ -899,6 +674,40 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, noID, force3d ); } break; + case GmfPyramids: + if ( hasGeom ) + { + if ( solidID != HOLE_ID ) + { + aCreatedElem = theHelper->AddVolume( node[3], node[2], node[1], + node[0], node[4], + noID, force3d ); + theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID ); + for ( int iN = 0; iN < 5; ++iN ) + if ( node[iN]->getshapeId() < 1 ) + theMeshDS->SetNodeInVolume( node[iN], solidID ); + } + } + else + { + if ( elemSearcher ) { + // Issue 0020682. Avoid creating nodes and tetras at place where + // volumic elements already exist + if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] ) + continue; + if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) + + SMESH_TNodeXYZ(node[1]) + + SMESH_TNodeXYZ(node[2]) + + SMESH_TNodeXYZ(node[3]) + + SMESH_TNodeXYZ(node[4])) / 5., + SMDSAbs_Volume, foundVolumes )) + break; + } + aCreatedElem = theHelper->AddVolume( node[3], node[2], node[1], + node[0], node[4], + noID, force3d ); + } + break; case GmfPrisms: if ( hasGeom ) { @@ -1003,17 +812,15 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, makeDomainGroups( elemsOfDomain, theHelper ); #ifdef _DEBUG_ - MESSAGE("Nb subdomains " << subdomainId2tetraId.size()); std::map >::const_iterator subdomainIt = subdomainId2tetraId.begin(); - TCollection_AsciiString aSubdomainFileName = theFile; + std::string aSubdomainFileName = theFile; aSubdomainFileName = aSubdomainFileName + ".subdomain"; - ofstream aSubdomainFile ( aSubdomainFileName.ToCString() , ios::out); + ofstream aSubdomainFile ( aSubdomainFileName , ios::out); aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl; for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) { int subdomainId = subdomainIt->first; std::set tetraIds = subdomainIt->second; - MESSAGE("Subdomain #"<::const_iterator tetraIdsIt = tetraIds.begin(); aSubdomainFile << subdomainId << std::endl; for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) { @@ -1046,8 +853,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput std::map, std::string> & enfVerticesWithGroup, HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues & theEnforcedVertices) { - //MESSAGE("writeGMFFile w/o geometry"); - std::cout << "!!!!!!!!!!!writeGMFFile w/o geometry for HYBRIDPLUGIN..." << std::endl; std::string tmpStr; int idx, idxRequired = 0, idxSol = 0; //tabg each dummyint @@ -1056,12 +861,12 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput const int dummyint2 = 2; const int dummyint3 = 3; const int dummyint4 = 4; - const int dummyint5 = 5; - const int dummyint6 = 6; //are interesting for layers + const int enforcedTag = HYBRIDPlugin_Hypothesis::EnforcedTag(); + //const int dummyint6 = 6; //are interesting for layers HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues::const_iterator vertexIt; std::vector enfVertexSizes; const SMDS_MeshElement* elem; - TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles; + TIDSortedElemSet anElemSetTri, anElemSetQuad, theKeptEnforcedEdges, theKeptEnforcedTriangles; SMDS_ElemIteratorPtr nodeIt; std::vector theEnforcedNodeByHybridId; std::map anEnforcedNodeToHybridIdMap, anExistingEnforcedNodeToHybridIdMap; @@ -1101,9 +906,17 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput while ( eIt->more() ) { elem = eIt->next(); - anElemSet.insert(elem); nodeIt = elem->nodesIterator(); nbNodes = elem->NbCornerNodes(); + if (nbNodes == 3) + anElemSetTri.insert(elem); + else if (nbNodes == 4) + anElemSetQuad.insert(elem); + else + { + std::cout << "Unexpected number of nodes: " << nbNodes << std::endl; + throw ("Unexpected number of nodes" ); + } while ( nodeIt->more() && nbNodes--) { // find HYBRID ID @@ -1299,22 +1112,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput continue; } -// gp_Pnt myPoint(node->X(),node->Y(),node->Z()); -// nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems); -// if (nbFoundElems ==0) { -// std::cout << " not found" << std::endl; -// if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) { -// nodesCoords.insert(coords); -// theOrderedNodes.push_back(node); -// } -// } -// else { -// std::cout << " found in initial mesh" << std::endl; -// const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0); -// nodesCoords.insert(coords); -// theOrderedNodes.push_back(existingNode); -// } - #ifdef _DEBUG_ std::cout << " not found" << std::endl; #endif @@ -1365,29 +1162,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput continue; } -// nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems); -// if (nbFoundElems ==0) { -// std::cout << " not found" << std::endl; -// if (result == TopAbs_IN) { -// nodesCoords.insert(coords); -// theRequiredNodes.push_back(node); -// } -// } -// else { -// std::cout << " found in initial mesh" << std::endl; -// const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0); -// // nodesCoords.insert(coords); -// theRequiredNodes.push_back(existingNode); -// } -// -// -// -// if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0) -// continue; - -// if ( result != TopAbs_IN ) -// continue; - #ifdef _DEBUG_ std::cout << " not found" << std::endl; #endif @@ -1400,7 +1174,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput int solSize = 0; std::vector > ReqVerTab; if (nbEnforcedVertices) { -// ReqVerTab.clear(); (nbEnforcedVertices <= 1) ? tmpStr = " node" : " nodes"; std::cout << nbEnforcedVertices << tmpStr << " from enforced vertices ..." << std::endl; // Iterate over the enforced vertices @@ -1413,11 +1186,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput TopAbs_State result = pntCls->GetPointState( myPoint ); if ( result == TopAbs_OUT ) continue; - //if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0) - //continue; - -// if ( result != TopAbs_IN ) -// continue; std::vector coords; coords.push_back(x); coords.push_back(y); @@ -1432,7 +1200,7 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput // GmfVertices std::cout << "Begin writing required nodes in GmfVertices" << std::endl; std::cout << "Nb vertices: " << theOrderedNodes.size() << std::endl; - MGInput->GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()); //theOrderedNodes.size()+solSize) + MGInput->GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()); for (hybridNodeIt = theOrderedNodes.begin();hybridNodeIt != theOrderedNodes.end();++hybridNodeIt) { MGInput->GmfSetLin(idx, GmfVertices, (*hybridNodeIt)->X(), (*hybridNodeIt)->Y(), (*hybridNodeIt)->Z(), dummyint1); } @@ -1458,8 +1226,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput double ValTab[] = {0.0}; MGInput->GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize); MGInput->GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab); -// int usedEnforcedNodes = 0; -// std::string gn = ""; for (hybridNodeIt = theRequiredNodes.begin();hybridNodeIt != theRequiredNodes.end();++hybridNodeIt) { MGInput->GmfSetLin(idxRequired, GmfVertices, (*hybridNodeIt)->X(), (*hybridNodeIt)->Y(), (*hybridNodeIt)->Z(), dummyint2); MGInput->GmfSetLin(idxSol, GmfSolAtVertices, ValTab); @@ -1486,17 +1252,13 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput std::cout << "End writing in req and sol file" << std::endl; } - int nedge[2], ntri[3]; + int nedge[2], ntri[3], nquad[4]; // GmfEdges int usedEnforcedEdges = 0; if (theKeptEnforcedEdges.size()) { anEdgeGroupByHybridId.resize( theKeptEnforcedEdges.size() ); -// idxRequired = MGInput->GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION); -// if (!idxRequired) -// return false; MGInput->GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size()); -// MGInput->GmfSetKwd(idxRequired, GmfEdges, theKeptEnforcedEdges.size()); for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) { elem = (*elemSetIt); nodeIt = elem->nodesIterator(); @@ -1515,10 +1277,8 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput } MGInput->GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint4); anEdgeGroupByHybridId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second; -// MGInput->GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint); usedEnforcedEdges++; } -// MGInput->GmfCloseMesh(idxRequired); } @@ -1531,16 +1291,19 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput // GmfTriangles int usedEnforcedTriangles = 0; - if (anElemSet.size()+theKeptEnforcedTriangles.size()) { - aFaceGroupByHybridId.resize( anElemSet.size()+theKeptEnforcedTriangles.size() ); - MGInput->GmfSetKwd(idx, GmfTriangles, anElemSet.size()+theKeptEnforcedTriangles.size()); + if (anElemSetTri.size()+theKeptEnforcedTriangles.size()) + { + aFaceGroupByHybridId.resize( anElemSetTri.size()+theKeptEnforcedTriangles.size() ); + MGInput->GmfSetKwd(idx, GmfTriangles, anElemSetTri.size()+theKeptEnforcedTriangles.size()); int k=0; - for(elemSetIt = anElemSet.begin() ; elemSetIt != anElemSet.end() ; ++elemSetIt,++k) { + for(elemSetIt = anElemSetTri.begin() ; elemSetIt != anElemSetTri.end() ; ++elemSetIt,++k) + { elem = (*elemSetIt); theFaceByHybridId.push_back( elem ); nodeIt = elem->nodesIterator(); int index=0; - for ( int j = 0; j < 3; ++j ) { + for ( int j = 0; j < 3; ++j ) + { // find HYBRID ID const SMDS_MeshNode* node = castToNode( nodeIt->next() ); std::map< const SMDS_MeshNode*,int >::iterator it = aNodeToHybridIdMap.find(node); @@ -1549,22 +1312,26 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput ntri[index] = it->second; index++; } - MGInput->GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint5); + MGInput->GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], /*tag=*/elem->getshapeId() ); aFaceGroupByHybridId[k] = ""; } if ( !theHelper.GetMesh()->HasShapeToMesh() ) SMESHUtils::FreeVector( theFaceByHybridId ); std::cout << "Enforced triangles size " << theKeptEnforcedTriangles.size() << std::endl; - if (theKeptEnforcedTriangles.size()) { - for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) { + if (theKeptEnforcedTriangles.size()) + { + for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) + { elem = (*elemSetIt); nodeIt = elem->nodesIterator(); int index=0; - for ( int j = 0; j < 3; ++j ) { + for ( int j = 0; j < 3; ++j ) + { // find HYBRID ID const SMDS_MeshNode* node = castToNode( nodeIt->next() ); std::map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToHybridIdMap.find(node); - if (it == anEnforcedNodeToHybridIdMap.end()) { + if (it == anEnforcedNodeToHybridIdMap.end()) + { it = anExistingEnforcedNodeToHybridIdMap.find(node); if (it == anEnforcedNodeToHybridIdMap.end()) throw "Node not found"; @@ -1572,7 +1339,7 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput ntri[index] = it->second; index++; } - MGInput->GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint6); + MGInput->GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], enforcedTag); aFaceGroupByHybridId[k] = theEnforcedTriangles.find(elem)->second; usedEnforcedTriangles++; } @@ -1580,10 +1347,38 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput } - if (usedEnforcedTriangles) { + if (usedEnforcedTriangles) + { MGInput->GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles); for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++) - MGInput->GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID); + MGInput->GmfSetLin(idx, GmfRequiredTriangles, anElemSetTri.size()+enfID); + } + + if (anElemSetQuad.size()) + { + MGInput->GmfSetKwd(idx, GmfQuadrilaterals, anElemSetQuad.size()); + int k=0; + for(elemSetIt = anElemSetQuad.begin() ; elemSetIt != anElemSetQuad.end() ; ++elemSetIt,++k) + { + elem = (*elemSetIt); + theFaceByHybridId.push_back( elem ); + nodeIt = elem->nodesIterator(); + int index=0; + for ( int j = 0; j < 4; ++j ) + { + // find HYBRID ID + const SMDS_MeshNode* node = castToNode( nodeIt->next() ); + std::map< const SMDS_MeshNode*,int >::iterator it = aNodeToHybridIdMap.find(node); + if (it == aNodeToHybridIdMap.end()) + throw "Node not found"; + nquad[index] = it->second; + index++; + } + MGInput->GmfSetLin(idx, GmfQuadrilaterals, nquad[0], nquad[1], nquad[2], nquad[3], + /*tag=*/elem->getshapeId() ); + // _CEA_cbo what is it for??? + //aFaceGroupByHybridId[k] = ""; + } } MGInput->GmfCloseMesh(idx); @@ -1596,1217 +1391,6 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput } -// static bool writeGMFFile(const char* theMeshFileName, -// const char* theRequiredFileName, -// const char* theSolFileName, -// SMESH_MesherHelper& theHelper, -// const SMESH_ProxyMesh& theProxyMesh, -// std::map & theNodeId2NodeIndexMap, -// std::map & theSmdsToHybridIdMap, -// std::map & theHybridIdToNodeMap, -// TIDSortedNodeSet & theEnforcedNodes, -// TIDSortedElemSet & theEnforcedEdges, -// TIDSortedElemSet & theEnforcedTriangles, -// // TIDSortedElemSet & theEnforcedQuadrangles, -// HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues & theEnforcedVertices) -// { -// MESSAGE("writeGMFFile with geometry"); -// int idx, idxRequired, idxSol; -// int nbv, nbev, nben, aHybridID = 0; -// const int dummyint = 0; -// HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues::const_iterator vertexIt; -// std::vector enfVertexSizes; -// TIDSortedNodeSet::const_iterator enfNodeIt; -// const SMDS_MeshNode* node; -// SMDS_NodeIteratorPtr nodeIt; -// -// idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION); -// if (!idx) -// return false; -// -// SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS(); -// -// /* ========================== NODES ========================== */ -// // NB_NODES -// nbv = theMeshDS->NbNodes(); -// if ( nbv == 0 ) -// return false; -// nbev = theEnforcedVertices.size(); -// nben = theEnforcedNodes.size(); -// -// // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by HYBRID -// // The problem is in nodes on degenerated edges, we need to skip nodes which are free -// // and replace not-free nodes on edges by the node on vertex -// TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex -// TNodeNodeMap::iterator n2nDegenIt; -// if ( theHelper.HasDegeneratedEdges() ) -// { -// set checkedSM; -// for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next()) -// { -// SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() ); -// if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() )) -// { -// if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) -// { -// TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value(); -// const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS); -// { -// SMDS_NodeIteratorPtr nIt = smDS->GetNodes(); -// while ( nIt->more() ) -// n2nDegen.insert( std::make_pair( nIt->next(), vNode )); -// } -// } -// } -// } -// } -// -// const bool isQuadMesh = -// theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) || -// theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) || -// theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC ); -// -// std::vector > VerTab; -// std::set > VerMap; -// VerTab.clear(); -// std::vector aVerTab; -// // Loop from 1 to NB_NODES -// -// nodeIt = theMeshDS->nodesIterator(); -// -// while ( nodeIt->more() ) -// { -// node = nodeIt->next(); -// if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238 -// continue; -// if ( n2nDegen.count( node ) ) // Issue 0020674 -// continue; -// -// std::vector coords; -// coords.push_back(node->X()); -// coords.push_back(node->Y()); -// coords.push_back(node->Z()); -// if (VerMap.find(coords) != VerMap.end()) { -// aHybridID = theSmdsToHybridIdMap[node->GetID()]; -// theHybridIdToNodeMap[theSmdsToHybridIdMap[node->GetID()]] = node; -// continue; -// } -// VerTab.push_back(coords); -// VerMap.insert(coords); -// aHybridID++; -// theSmdsToHybridIdMap.insert( std::make_pair( node->GetID(), aHybridID )); -// theHybridIdToNodeMap.insert( std::make_pair( aHybridID, node )); -// } -// -// -// /* ENFORCED NODES ========================== */ -// if (nben) { -// std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl; -// for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) { -// double x = (*enfNodeIt)->X(); -// double y = (*enfNodeIt)->Y(); -// double z = (*enfNodeIt)->Z(); -// // Test if point is inside shape to mesh -// gp_Pnt myPoint(x,y,z); -// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); -// scl.Perform(myPoint, 1e-7); -// TopAbs_State result = scl.State(); -// if ( result != TopAbs_IN ) -// continue; -// std::vector coords; -// coords.push_back(x); -// coords.push_back(y); -// coords.push_back(z); -// if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) -// continue; -// if (VerMap.find(coords) != VerMap.end()) -// continue; -// VerTab.push_back(coords); -// VerMap.insert(coords); -// aHybridID++; -// theNodeId2NodeIndexMap.insert( std::make_pair( (*enfNodeIt)->GetID(), aHybridID )); -// } -// } -// -// -// /* ENFORCED VERTICES ========================== */ -// int solSize = 0; -// std::vector > ReqVerTab; -// ReqVerTab.clear(); -// if (nbev) { -// std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl; -// for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { -// double x = vertexIt->first[0]; -// double y = vertexIt->first[1]; -// double z = vertexIt->first[2]; -// // Test if point is inside shape to mesh -// gp_Pnt myPoint(x,y,z); -// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); -// scl.Perform(myPoint, 1e-7); -// TopAbs_State result = scl.State(); -// if ( result != TopAbs_IN ) -// continue; -// enfVertexSizes.push_back(vertexIt->second); -// std::vector coords; -// coords.push_back(x); -// coords.push_back(y); -// coords.push_back(z); -// if (VerMap.find(coords) != VerMap.end()) -// continue; -// ReqVerTab.push_back(coords); -// VerMap.insert(coords); -// solSize++; -// } -// } -// -// -// /* ========================== FACES ========================== */ -// -// int nbTriangles = 0/*, nbQuadrangles = 0*/, aSmdsID; -// TopTools_IndexedMapOfShape facesMap, trianglesMap/*, quadranglesMap*/; -// TIDSortedElemSet::const_iterator elemIt; -// const SMESHDS_SubMesh* theSubMesh; -// TopoDS_Shape aShape; -// SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace; -// const SMDS_MeshElement* aFace; -// map::const_iterator itOnMap; -// std::vector > tt, qt,et; -// tt.clear(); -// qt.clear(); -// et.clear(); -// std::vector att, aqt, aet; -// -// TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap ); -// -// for ( int i = 1; i <= facesMap.Extent(); ++i ) -// if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i)))) -// { -// SMDS_ElemIteratorPtr it = theSubMesh->GetElements(); -// while (it->more()) -// { -// const SMDS_MeshElement *elem = it->next(); -// int nbCornerNodes = elem->NbCornerNodes(); -// if (nbCornerNodes == 3) -// { -// trianglesMap.Add(facesMap(i)); -// nbTriangles ++; -// } -// // else if (nbCornerNodes == 4) -// // { -// // quadranglesMap.Add(facesMap(i)); -// // nbQuadrangles ++; -// // } -// } -// } -// -// /* TRIANGLES ========================== */ -// if (nbTriangles) { -// for ( int i = 1; i <= trianglesMap.Extent(); i++ ) -// { -// aShape = trianglesMap(i); -// theSubMesh = theProxyMesh.GetSubMesh(aShape); -// if ( !theSubMesh ) continue; -// itOnSubMesh = theSubMesh->GetElements(); -// while ( itOnSubMesh->more() ) -// { -// aFace = itOnSubMesh->next(); -// itOnSubFace = aFace->nodesIterator(); -// att.clear(); -// for ( int j = 0; j < 3; ++j ) { -// // find HYBRID ID -// node = castToNode( itOnSubFace->next() ); -// if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) -// node = n2nDegenIt->second; -// aSmdsID = node->GetID(); -// itOnMap = theSmdsToHybridIdMap.find( aSmdsID ); -// ASSERT( itOnMap != theSmdsToHybridIdMap.end() ); -// att.push_back((*itOnMap).second); -// } -// tt.push_back(att); -// } -// } -// } -// -// if (theEnforcedTriangles.size()) { -// std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl; -// // Iterate over the enforced triangles -// for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { -// aFace = (*elemIt); -// itOnSubFace = aFace->nodesIterator(); -// bool isOK = true; -// att.clear(); -// -// for ( int j = 0; j < 3; ++j ) { -// node = castToNode( itOnSubFace->next() ); -// if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) -// node = n2nDegenIt->second; -// // std::cout << node; -// double x = node->X(); -// double y = node->Y(); -// double z = node->Z(); -// // Test if point is inside shape to mesh -// gp_Pnt myPoint(x,y,z); -// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); -// scl.Perform(myPoint, 1e-7); -// TopAbs_State result = scl.State(); -// if ( result != TopAbs_IN ) { -// isOK = false; -// theEnforcedTriangles.erase(elemIt); -// continue; -// } -// std::vector coords; -// coords.push_back(x); -// coords.push_back(y); -// coords.push_back(z); -// if (VerMap.find(coords) != VerMap.end()) { -// att.push_back(theNodeId2NodeIndexMap[node->GetID()]); -// continue; -// } -// VerTab.push_back(coords); -// VerMap.insert(coords); -// aHybridID++; -// theNodeId2NodeIndexMap.insert( std::make_pair( node->GetID(), aHybridID )); -// att.push_back(aHybridID); -// } -// if (isOK) -// tt.push_back(att); -// } -// } -// -// -// /* ========================== EDGES ========================== */ -// -// if (theEnforcedEdges.size()) { -// // Iterate over the enforced edges -// std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl; -// for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { -// aFace = (*elemIt); -// bool isOK = true; -// itOnSubFace = aFace->nodesIterator(); -// aet.clear(); -// for ( int j = 0; j < 2; ++j ) { -// node = castToNode( itOnSubFace->next() ); -// if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) -// node = n2nDegenIt->second; -// double x = node->X(); -// double y = node->Y(); -// double z = node->Z(); -// // Test if point is inside shape to mesh -// gp_Pnt myPoint(x,y,z); -// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); -// scl.Perform(myPoint, 1e-7); -// TopAbs_State result = scl.State(); -// if ( result != TopAbs_IN ) { -// isOK = false; -// theEnforcedEdges.erase(elemIt); -// continue; -// } -// std::vector coords; -// coords.push_back(x); -// coords.push_back(y); -// coords.push_back(z); -// if (VerMap.find(coords) != VerMap.end()) { -// aet.push_back(theNodeId2NodeIndexMap[node->GetID()]); -// continue; -// } -// VerTab.push_back(coords); -// VerMap.insert(coords); -// -// aHybridID++; -// theNodeId2NodeIndexMap.insert( std::make_pair( node->GetID(), aHybridID )); -// aet.push_back(aHybridID); -// } -// if (isOK) -// et.push_back(aet); -// } -// } -// -// -// /* Write vertices number */ -// MESSAGE("Number of vertices: "<GetElements(); -// // for ( int j = 0; j < 4; ++j ) -// // { -// // aFace = itOnSubMesh->next(); -// // itOnSubFace = aFace->nodesIterator(); -// // aqt.clear(); -// // while ( itOnSubFace->more() ) { -// // // find HYBRID ID -// // aSmdsID = itOnSubFace->next()->GetID(); -// // itOnMap = theSmdsToHybridIdMap.find( aSmdsID ); -// // ASSERT( itOnMap != theSmdsToHybridIdMap.end() ); -// // aqt.push_back((*itOnMap).second); -// // } -// // qt.push_back(aqt); -// // } -// // } -// // } -// // -// // if (theEnforcedQuadrangles.size()) { -// // // Iterate over the enforced triangles -// // for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) { -// // aFace = (*elemIt); -// // bool isOK = true; -// // itOnSubFace = aFace->nodesIterator(); -// // aqt.clear(); -// // for ( int j = 0; j < 4; ++j ) { -// // int aNodeID = itOnSubFace->next()->GetID(); -// // itOnMap = theNodeId2NodeIndexMap.find(aNodeID); -// // if (itOnMap != theNodeId2NodeIndexMap.end()) -// // aqt.push_back((*itOnMap).second); -// // else { -// // isOK = false; -// // theEnforcedQuadrangles.erase(elemIt); -// // break; -// // } -// // } -// // if (isOK) -// // qt.push_back(aqt); -// // } -// // } -// // -// -// // /* Write quadrilaterals number */ -// // if (qt.size()) { -// // GmfSetKwd(idx, GmfQuadrilaterals, qt.size()); -// // for (int i=0;i & theSmdsToHybridIdMap, -// const std::map & theEnforcedNodeIdToHybridIdMap, -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles) -// { -// // record structure: -// // -// // NB_ELEMS DUMMY_INT -// // Loop from 1 to NB_ELEMS -// // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT - -// TopoDS_Shape aShape; -// const SMESHDS_SubMesh* theSubMesh; -// const SMDS_MeshElement* aFace; -// const char* space = " "; -// const int dummyint = 0; -// std::map::const_iterator itOnMap; -// SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace; -// int nbNodes, aSmdsID; - -// TIDSortedElemSet::const_iterator elemIt; -// int nbEnforcedEdges = theEnforcedEdges.size(); -// int nbEnforcedTriangles = theEnforcedTriangles.size(); - -// // count triangles bound to geometry -// int nbTriangles = 0; - -// TopTools_IndexedMapOfShape facesMap, trianglesMap; -// TopExp::MapShapes( theShape, TopAbs_FACE, facesMap ); - -// int nbFaces = facesMap.Extent(); - -// for ( int i = 1; i <= nbFaces; ++i ) -// if (( theSubMesh = theMesh.GetSubMesh( facesMap(i)))) -// nbTriangles += theSubMesh->NbElements(); -// std::string tmpStr; -// (nbFaces == 0 || nbFaces == 1) ? tmpStr = " shape " : tmpStr = " shapes " ; -// std::cout << " " << nbFaces << tmpStr << "of 2D dimension"; -// int nbEnforcedElements = nbEnforcedEdges+nbEnforcedTriangles; -// if (nbEnforcedElements > 0) { -// (nbEnforcedElements == 1) ? tmpStr = "shape:" : tmpStr = "shapes:"; -// std::cout << " and" << std::endl; -// std::cout << " " << nbEnforcedElements -// << " enforced " << tmpStr << std::endl; -// } -// else -// std::cout << std::endl; -// if (nbEnforcedEdges) { -// (nbEnforcedEdges == 1) ? tmpStr = "edge" : tmpStr = "edges"; -// std::cout << " " << nbEnforcedEdges << " enforced " << tmpStr << std::endl; -// } -// if (nbEnforcedTriangles) { -// (nbEnforcedTriangles == 1) ? tmpStr = "triangle" : tmpStr = "triangles"; -// std::cout << " " << nbEnforcedTriangles << " enforced " << tmpStr << std::endl; -// } -// std::cout << std::endl; - -// // theFile << space << nbTriangles << space << dummyint << std::endl; -// std::ostringstream globalStream, localStream, aStream; - -// for ( int i = 1; i <= facesMap.Extent(); i++ ) -// { -// aShape = facesMap(i); -// theSubMesh = theMesh.GetSubMesh(aShape); -// if ( !theSubMesh ) continue; -// itOnSubMesh = theSubMesh->GetElements(); -// while ( itOnSubMesh->more() ) -// { -// aFace = itOnSubMesh->next(); -// nbNodes = aFace->NbCornerNodes(); - -// localStream << nbNodes << space; - -// itOnSubFace = aFace->nodesIterator(); -// for ( int j = 0; j < 3; ++j ) { -// // find HYBRID ID -// aSmdsID = itOnSubFace->next()->GetID(); -// itOnMap = theSmdsToHybridIdMap.find( aSmdsID ); -// // if ( itOnMap == theSmdsToHybridIdMap.end() ) { -// // cout << "not found node: " << aSmdsID << endl; -// // return false; -// // } -// ASSERT( itOnMap != theSmdsToHybridIdMap.end() ); - -// localStream << (*itOnMap).second << space ; -// } - -// // (NB_NODES + 1) times: DUMMY_INT -// for ( int j=0; j<=nbNodes; j++) -// localStream << dummyint << space ; - -// localStream << std::endl; -// } -// } - -// globalStream << localStream.str(); -// localStream.str(""); - -// // -// // FACES : END -// // - -// // // -// // // ENFORCED EDGES : BEGIN -// // // -// // -// // // Iterate over the enforced edges -// // int usedEnforcedEdges = 0; -// // bool isOK; -// // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { -// // aFace = (*elemIt); -// // isOK = true; -// // itOnSubFace = aFace->nodesIterator(); -// // aStream.str(""); -// // aStream << "2" << space ; -// // for ( int j = 0; j < 2; ++j ) { -// // aSmdsID = itOnSubFace->next()->GetID(); -// // itOnMap = theEnforcedNodeIdToHybridIdMap.find(aSmdsID); -// // if (itOnMap != theEnforcedNodeIdToHybridIdMap.end()) -// // aStream << (*itOnMap).second << space; -// // else { -// // isOK = false; -// // break; -// // } -// // } -// // if (isOK) { -// // for ( int j=0; j<=2; j++) -// // aStream << dummyint << space ; -// // // aStream << dummyint << space << dummyint; -// // localStream << aStream.str() << std::endl; -// // usedEnforcedEdges++; -// // } -// // } -// // -// // if (usedEnforcedEdges) { -// // globalStream << localStream.str(); -// // localStream.str(""); -// // } -// // -// // // -// // // ENFORCED EDGES : END -// // // -// // // -// // -// // // -// // // ENFORCED TRIANGLES : BEGIN -// // // -// // // Iterate over the enforced triangles -// // int usedEnforcedTriangles = 0; -// // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { -// // aFace = (*elemIt); -// // nbNodes = aFace->NbCornerNodes(); -// // isOK = true; -// // itOnSubFace = aFace->nodesIterator(); -// // aStream.str(""); -// // aStream << nbNodes << space ; -// // for ( int j = 0; j < 3; ++j ) { -// // aSmdsID = itOnSubFace->next()->GetID(); -// // itOnMap = theEnforcedNodeIdToHybridIdMap.find(aSmdsID); -// // if (itOnMap != theEnforcedNodeIdToHybridIdMap.end()) -// // aStream << (*itOnMap).second << space; -// // else { -// // isOK = false; -// // break; -// // } -// // } -// // if (isOK) { -// // for ( int j=0; j<=3; j++) -// // aStream << dummyint << space ; -// // localStream << aStream.str() << std::endl; -// // usedEnforcedTriangles++; -// // } -// // } -// // -// // if (usedEnforcedTriangles) { -// // globalStream << localStream.str(); -// // localStream.str(""); -// // } -// // -// // // -// // // ENFORCED TRIANGLES : END -// // // - -// theFile -// << nbTriangles/*+usedEnforcedTriangles+usedEnforcedEdges*/ -// << " 0" << std::endl -// << globalStream.str(); - -// return true; -// } - -//======================================================================= -//function : writePoints -//purpose : -//======================================================================= - -// static bool writePoints (ofstream & theFile, -// SMESH_MesherHelper& theHelper, -// std::map & theSmdsToHybridIdMap, -// std::map & theEnforcedNodeIdToHybridIdMap, -// std::map & theHybridIdToNodeMap, -// HYBRIDPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap, -// HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues & theEnforcedVertices, -// HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes, -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles) -// { -// // record structure: -// // -// // NB_NODES -// // Loop from 1 to NB_NODES -// // X Y Z DUMMY_INT - -// SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS(); -// int nbNodes = theMeshDS->NbNodes(); -// if ( nbNodes == 0 ) -// return false; - -// int nbEnforcedVertices = theEnforcedVertices.size(); -// int nbEnforcedNodes = theEnforcedNodes.size(); - -// const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh(); - -// int aHybridID = 1; -// SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator(); -// const SMDS_MeshNode* node; - -// // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by HYBRID -// // The problem is in nodes on degenerated edges, we need to skip nodes which are free -// // and replace not-free nodes on degenerated edges by the node on vertex -// TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex -// TNodeNodeMap::iterator n2nDegenIt; -// if ( theHelper.HasDegeneratedEdges() ) -// { -// std::set checkedSM; -// for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next()) -// { -// SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() ); -// if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() )) -// { -// if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) -// { -// TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value(); -// const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS); -// { -// SMDS_NodeIteratorPtr nIt = smDS->GetNodes(); -// while ( nIt->more() ) -// n2nDegen.insert( std::make_pair( nIt->next(), vNode )); -// } -// } -// } -// } -// nbNodes -= n2nDegen.size(); -// } - -// const bool isQuadMesh = -// theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) || -// theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) || -// theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC ); -// if ( isQuadMesh ) -// { -// // descrease nbNodes by nb of medium nodes -// while ( nodeIt->more() ) -// { -// node = nodeIt->next(); -// if ( !theHelper.IsDegenShape( node->getshapeId() )) -// nbNodes -= int( theHelper.IsMedium( node )); -// } -// nodeIt = theMeshDS->nodesIterator(); -// } - -// const char* space = " "; -// const int dummyint = 0; - -// std::string tmpStr; -// (nbNodes == 0 || nbNodes == 1) ? tmpStr = " node" : tmpStr = " nodes"; -// // NB_NODES -// std::cout << std::endl; -// std::cout << "The initial 2D mesh contains :" << std::endl; -// std::cout << " " << nbNodes << tmpStr << std::endl; -// if (nbEnforcedVertices > 0) { -// (nbEnforcedVertices == 1) ? tmpStr = "vertex" : tmpStr = "vertices"; -// std::cout << " " << nbEnforcedVertices << " enforced " << tmpStr << std::endl; -// } -// if (nbEnforcedNodes > 0) { -// (nbEnforcedNodes == 1) ? tmpStr = "node" : tmpStr = "nodes"; -// std::cout << " " << nbEnforcedNodes << " enforced " << tmpStr << std::endl; -// } -// std::cout << std::endl; -// std::cout << "Start writing in 'points' file ..." << std::endl; - -// theFile << nbNodes << std::endl; - -// // Loop from 1 to NB_NODES - -// while ( nodeIt->more() ) -// { -// node = nodeIt->next(); -// if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238 -// continue; -// if ( n2nDegen.count( node ) ) // Issue 0020674 -// continue; - -// theSmdsToHybridIdMap.insert( std::make_pair( node->GetID(), aHybridID )); -// theHybridIdToNodeMap.insert( std::make_pair( aHybridID, node )); -// aHybridID++; - -// // X Y Z DUMMY_INT -// theFile -// << node->X() << space -// << node->Y() << space -// << node->Z() << space -// << dummyint; - -// theFile << std::endl; - -// } - -// // Iterate over the enforced nodes -// std::map enfVertexIndexSizeMap; -// if (nbEnforcedNodes) { -// HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator nodeIt = theEnforcedNodes.begin(); -// for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) { -// double x = nodeIt->first->X(); -// double y = nodeIt->first->Y(); -// double z = nodeIt->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 ) -// continue; -// std::vector coords; -// coords.push_back(x); -// coords.push_back(y); -// coords.push_back(z); -// if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) -// continue; - -// // double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second; -// // theHybridIdToNodeMap.insert( std::make_pair( nbNodes + i, (*nodeIt) )); -// // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")"); -// // X Y Z PHY_SIZE DUMMY_INT -// theFile -// << x << space -// << y << space -// << z << space -// << -1 << space -// << dummyint << space; -// theFile << std::endl; -// theEnforcedNodeIdToHybridIdMap.insert( std::make_pair( nodeIt->first->GetID(), aHybridID )); -// enfVertexIndexSizeMap[aHybridID] = -1; -// aHybridID++; -// // else -// // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added "); -// } -// } - -// if (nbEnforcedVertices) { -// // Iterate over the enforced vertices -// HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues::const_iterator vertexIt = theEnforcedVertices.begin(); -// for( ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { -// double x = vertexIt->first[0]; -// double y = vertexIt->first[1]; -// double z = vertexIt->first[2]; -// // 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 ) -// continue; -// MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second); -// // X Y Z PHY_SIZE DUMMY_INT -// theFile -// << x << space -// << y << space -// << z << space -// << vertexIt->second << space -// << dummyint << space; -// theFile << std::endl; -// enfVertexIndexSizeMap[aHybridID] = vertexIt->second; -// aHybridID++; -// } -// } - - -// std::cout << std::endl; -// std::cout << "End writing in 'points' file." << std::endl; - -// return true; -// } - -//======================================================================= -//function : readResultFile -//purpose : readResultFile with geometry -//======================================================================= - -// static bool readResultFile(const int fileOpen, -// #ifdef WIN32 -// const char* fileName, -// #endif -// HYBRIDPlugin_HYBRID* theAlgo, -// SMESH_MesherHelper& theHelper, -// TopoDS_Shape tabShape[], -// double** tabBox, -// const int nbShape, -// std::map & theHybridIdToNodeMap, -// std::map & theNodeId2NodeIndexMap, -// bool toMeshHoles, -// int nbEnforcedVertices, -// int nbEnforcedNodes, -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles, -// bool toMakeGroupsOfDomains) -// { -// MESSAGE("HYBRIDPlugin_HYBRID::readResultFile()"); -// Kernel_Utils::Localizer loc; -// struct stat status; -// size_t length; - -// std::string tmpStr; - -// char *ptr, *mapPtr; -// char *tetraPtr; -// char *shapePtr; - -// SMESHDS_Mesh* theMeshDS = theHelper.GetMeshDS(); - -// int nbElems, nbNodes, nbInputNodes; -// int nbTriangle; -// int ID, shapeID, hybridShapeID; -// int IdShapeRef = 1; -// int compoundID = -// nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() ); - -// int *tab, *tabID, *nodeID, *nodeAssigne; -// double *coord; -// const SMDS_MeshNode **node; - -// tab = new int[3]; -// nodeID = new int[4]; -// coord = new double[3]; -// node = new const SMDS_MeshNode*[4]; - -// TopoDS_Shape aSolid; -// SMDS_MeshNode * aNewNode; -// std::map ::iterator itOnNode; -// SMDS_MeshElement* aTet; -// #ifdef _DEBUG_ -// std::set shapeIDs; -// #endif - -// // Read the file state -// fstat(fileOpen, &status); -// length = status.st_size; - -// // Mapping the result file into memory -// #ifdef WIN32 -// HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, -// NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -// HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY, -// 0, (DWORD)length, NULL); -// ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 ); -// #else -// ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0); -// #endif -// mapPtr = ptr; - -// ptr = readMapIntLine(ptr, tab); -// tetraPtr = ptr; - -// nbElems = tab[0]; -// nbNodes = tab[1]; -// nbInputNodes = tab[2]; - -// nodeAssigne = new int[ nbNodes+1 ]; - -// if (nbShape > 0) -// aSolid = tabShape[0]; - -// // Reading the nodeId -// for (int i=0; i < 4*nbElems; i++) -// strtol(ptr, &ptr, 10); - -// MESSAGE("nbInputNodes: "<computeCanceled()) -// return false; -// for (int iCoor=0; iCoor < 3; iCoor++) -// coord[ iCoor ] = strtod(ptr, &ptr); -// nodeAssigne[ iNode ] = 1; -// if ( iNode > (nbInputNodes-(nbEnforcedVertices+nbEnforcedNodes)) ) { -// // Creating SMESH nodes -// // - for enforced vertices -// // - for vertices of forced edges -// // - for hybrid nodes -// nodeAssigne[ iNode ] = 0; -// aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] ); -// theHybridIdToNodeMap.insert(theHybridIdToNodeMap.end(), std::make_pair( iNode, aNewNode )); -// } -// } - -// // Reading the number of triangles which corresponds to the number of sub-domains -// nbTriangle = strtol(ptr, &ptr, 10); - -// tabID = new int[nbTriangle]; -// for (int i=0; i < nbTriangle; i++) { -// if(theAlgo->computeCanceled()) -// return false; -// tabID[i] = 0; -// // find the solid corresponding to HYBRID sub-domain following -// // the technique proposed in HYBRID manual in chapter -// // "B.4 Subdomain (sub-region) assignment" -// int nodeId1 = strtol(ptr, &ptr, 10); -// int nodeId2 = strtol(ptr, &ptr, 10); -// int nodeId3 = strtol(ptr, &ptr, 10); -// if ( nbTriangle > 1 ) { -// const SMDS_MeshNode* n1 = theHybridIdToNodeMap[ nodeId1 ]; -// const SMDS_MeshNode* n2 = theHybridIdToNodeMap[ nodeId2 ]; -// const SMDS_MeshNode* n3 = theHybridIdToNodeMap[ nodeId3 ]; -// if (!n1 || !n2 || !n3) { -// tabID[i] = HOLE_ID; -// continue; -// } -// try { -// OCC_CATCH_SIGNALS; -// // tabID[i] = findShapeID( theHelper, n1, n2, n3, toMeshHoles ); -// tabID[i] = findShapeID( *theHelper.GetMesh(), n1, n2, n3, toMeshHoles ); -// // -- 0020330: Pb with hybrid as a submesh -// // check that found shape is to be meshed -// if ( tabID[i] > 0 ) { -// const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] ); -// bool isToBeMeshed = false; -// for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS ) -// isToBeMeshed = foundShape.IsSame( tabShape[ iS ]); -// if ( !isToBeMeshed ) -// tabID[i] = HOLE_ID; -// } -// // END -- 0020330: Pb with hybrid as a submesh -// #ifdef _DEBUG_ -// std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl; -// #endif -// } -// catch ( Standard_Failure & ex) -// { -// #ifdef _DEBUG_ -// std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl; -// #endif -// } -// catch (...) { -// #ifdef _DEBUG_ -// std::cout << i+1 << " subdomain: unknown exception caught " << std::endl; -// #endif -// } -// } -// } - -// shapePtr = ptr; - -// if ( nbTriangle <= nbShape ) // no holes -// toMeshHoles = true; // not avoid creating tetras in holes - -// // IMP 0022172: [CEA 790] create the groups corresponding to domains -// std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain( Max( nbTriangle, nbShape )); - -// // Associating the tetrahedrons to the shapes -// shapeID = compoundID; -// for (int iElem = 0; iElem < nbElems; iElem++) { -// if(theAlgo->computeCanceled()) -// return false; -// for (int iNode = 0; iNode < 4; iNode++) { -// ID = strtol(tetraPtr, &tetraPtr, 10); -// itOnNode = theHybridIdToNodeMap.find(ID); -// node[ iNode ] = itOnNode->second; -// nodeID[ iNode ] = ID; -// } -// // We always run HYBRID with "to mesh holes"==TRUE but we must not create -// // tetras within holes depending on hypo option, -// // so we first check if aTet is inside a hole and then create it -// //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] ); -// hybridShapeID = 0; // domain ID -// if ( nbTriangle > 1 ) { -// shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles -// hybridShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef; -// if ( tabID[ hybridShapeID ] == 0 ) { -// TopAbs_State state; -// aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state); -// if ( toMeshHoles || state == TopAbs_IN ) -// shapeID = theMeshDS->ShapeToIndex( aSolid ); -// tabID[ hybridShapeID ] = shapeID; -// } -// else -// shapeID = tabID[ hybridShapeID ]; -// } -// else if ( nbShape > 1 ) { -// // Case where nbTriangle == 1 while nbShape == 2 encountered -// // with compound of 2 boxes and "To mesh holes"==False, -// // so there are no subdomains specified for each tetrahedron. -// // Try to guess a solid by a node already bound to shape -// shapeID = 0; -// for ( int i=0; i<4 && shapeID==0; i++ ) { -// if ( nodeAssigne[ nodeID[i] ] == 1 && -// node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE && -// node[i]->getshapeId() > 1 ) -// { -// shapeID = node[i]->getshapeId(); -// } -// } -// if ( shapeID==0 ) { -// aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape); -// shapeID = theMeshDS->ShapeToIndex( aSolid ); -// } -// } -// // set new nodes and tetrahedron onto the shape -// for ( int i=0; i<4; i++ ) { -// if ( nodeAssigne[ nodeID[i] ] == 0 ) { -// if ( shapeID != HOLE_ID ) -// theMeshDS->SetNodeInVolume( node[i], shapeID ); -// nodeAssigne[ nodeID[i] ] = shapeID; -// } -// } -// if ( toMeshHoles || shapeID != HOLE_ID ) { -// aTet = theHelper.AddVolume( node[1], node[0], node[2], node[3], -// /*id=*/0, /*force3d=*/false); -// theMeshDS->SetMeshElementOnShape( aTet, shapeID ); -// if ( toMakeGroupsOfDomains ) -// { -// if ( int( elemsOfDomain.size() ) < hybridShapeID+1 ) -// elemsOfDomain.resize( hybridShapeID+1 ); -// elemsOfDomain[ hybridShapeID ].push_back( aTet ); -// } -// } -// #ifdef _DEBUG_ -// shapeIDs.insert( shapeID ); -// #endif -// } -// if ( toMakeGroupsOfDomains ) -// makeDomainGroups( elemsOfDomain, &theHelper ); - -// // Add enforced elements -// HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt; -// const SMDS_MeshElement* anElem; -// SMDS_ElemIteratorPtr itOnEnfElem; -// std::map::const_iterator itOnMap; -// shapeID = compoundID; -// // Enforced edges -// if (theEnforcedEdges.size()) { -// (theEnforcedEdges.size() <= 1) ? tmpStr = " enforced edge" : " enforced edges"; -// std::cout << "Add " << theEnforcedEdges.size() << tmpStr << std::endl; -// std::vector< const SMDS_MeshNode* > node( 2 ); -// // Iterate over the enforced edges -// for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { -// anElem = elemIt->first; -// bool addElem = true; -// itOnEnfElem = anElem->nodesIterator(); -// for ( int j = 0; j < 2; ++j ) { -// int aNodeID = itOnEnfElem->next()->GetID(); -// itOnMap = theNodeId2NodeIndexMap.find(aNodeID); -// if (itOnMap != theNodeId2NodeIndexMap.end()) { -// itOnNode = theHybridIdToNodeMap.find((*itOnMap).second); -// if (itOnNode != theHybridIdToNodeMap.end()) { -// node.push_back((*itOnNode).second); -// // shapeID =(*itOnNode).second->getshapeId(); -// } -// else -// addElem = false; -// } -// else -// addElem = false; -// } -// if (addElem) { -// aTet = theHelper.AddEdge( node[0], node[1], 0, false); -// theMeshDS->SetMeshElementOnShape( aTet, shapeID ); -// } -// } -// } -// // Enforced faces -// if (theEnforcedTriangles.size()) { -// (theEnforcedTriangles.size() <= 1) ? tmpStr = " enforced triangle" : " enforced triangles"; -// std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles" << std::endl; -// std::vector< const SMDS_MeshNode* > node( 3 ); -// // Iterate over the enforced triangles -// for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { -// anElem = elemIt->first; -// bool addElem = true; -// itOnEnfElem = anElem->nodesIterator(); -// for ( int j = 0; j < 3; ++j ) { -// int aNodeID = itOnEnfElem->next()->GetID(); -// itOnMap = theNodeId2NodeIndexMap.find(aNodeID); -// if (itOnMap != theNodeId2NodeIndexMap.end()) { -// itOnNode = theHybridIdToNodeMap.find((*itOnMap).second); -// if (itOnNode != theHybridIdToNodeMap.end()) { -// node.push_back((*itOnNode).second); -// // shapeID =(*itOnNode).second->getshapeId(); -// } -// else -// addElem = false; -// } -// else -// addElem = false; -// } -// if (addElem) { -// aTet = theHelper.AddFace( node[0], node[1], node[2], 0, false); -// theMeshDS->SetMeshElementOnShape( aTet, shapeID ); -// } -// } -// } - -// // Remove nodes of tetras inside holes if !toMeshHoles -// if ( !toMeshHoles ) { -// itOnNode = theHybridIdToNodeMap.find( nbInputNodes ); -// for ( ; itOnNode != theHybridIdToNodeMap.end(); ++itOnNode) { -// ID = itOnNode->first; -// if ( nodeAssigne[ ID ] == HOLE_ID ) -// theMeshDS->RemoveFreeNode( itOnNode->second, 0 ); -// } -// } - - -// if ( nbElems ) { -// (nbElems <= 1) ? tmpStr = " tetrahedra" : " tetrahedrons"; -// cout << nbElems << tmpStr << " have been associated to " << nbShape; -// (nbShape <= 1) ? tmpStr = " shape" : " shapes"; -// cout << tmpStr << endl; -// } -// #ifdef WIN32 -// UnmapViewOfFile(mapPtr); -// CloseHandle(hMapObject); -// CloseHandle(fd); -// #else -// munmap(mapPtr, length); -// #endif -// close(fileOpen); - -// delete [] tab; -// delete [] tabID; -// delete [] nodeID; -// delete [] coord; -// delete [] node; -// delete [] nodeAssigne; - -// #ifdef _DEBUG_ -// shapeIDs.erase(-1); -// if ((int) shapeIDs.size() != nbShape ) { -// (shapeIDs.size() <= 1) ? tmpStr = " solid" : " solids"; -// std::cout << "Only " << shapeIDs.size() << tmpStr << " of " << nbShape << " found" << std::endl; -// for (int i=0; iShapeToIndex( tabShape[i] ); -// if ( shapeIDs.find( shapeID ) == shapeIDs.end() ) -// std::cout << " Solid #" << shapeID << " not found" << std::endl; -// } -// } -// #endif - -// return true; -// } - - //============================================================================= /*! *Here we are going to use the HYBRID mesher with geometry @@ -2821,35 +1405,26 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // a unique working file name // to avoid access to the same files by eg different users _genericName = HYBRIDPlugin_Hypothesis::GetFileName(_hyp); - TCollection_AsciiString aGenericName((char*) _genericName.c_str() ); - TCollection_AsciiString aGenericNameRequired = aGenericName + "_required"; + std::string aGenericName = _genericName; + std::string aGenericNameRequired = aGenericName + "_required"; - TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log - TCollection_AsciiString aResultFileName; + std::string aLogFileName = aGenericName + ".log"; // log + std::string aResultFileName; - TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName, aResSolFileName; -//#ifdef _DEBUG_ + std::string aGMFFileName, aRequiredVerticesFileName, aSolFileName, aResSolFileName; aGMFFileName = aGenericName + ".mesh"; // GMF mesh file aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file aResSolFileName = aGenericName + "Vol.sol"; // GMF mesh file aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file -//#else -// aGMFFileName = aGenericName + ".meshb"; // GMF mesh file -// aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file -// aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file -// aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file -//#endif std::map aNodeId2NodeIndexMap, aSmdsToHybridIdMap, anEnforcedNodeIdToHybridIdMap; - //std::map aHybridIdToNodeMap; std::map nodeID2nodeIndexMap; std::map, std::string> enfVerticesWithGroup; HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues coordsSizeMap = HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp); HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = HYBRIDPlugin_Hypothesis::GetEnforcedNodes(_hyp); HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = HYBRIDPlugin_Hypothesis::GetEnforcedEdges(_hyp); HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(_hyp); -// TIDSortedElemSet enforcedQuadrangles = HYBRIDPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp); HYBRIDPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList enfVertices = HYBRIDPlugin_Hypothesis::GetEnforcedVertices(_hyp); @@ -2859,53 +1434,30 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt) { HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* enfVertex = (*enfVerIt); -// if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) { if (enfVertex->coords.size()) { coordsSizeMap.insert(std::make_pair(enfVertex->coords,enfVertex->size)); enfVerticesWithGroup.insert(std::make_pair(enfVertex->coords,enfVertex->groupName)); -// MESSAGE("enfVerticesWithGroup.insert(std::make_pair(("<coords[0]<<","<coords[1]<<","<coords[2]<<"),\""<groupName<<"\"))"); } else { -// if (!enfVertex->geomEntry.empty()) { TopoDS_Shape GeomShape = entryToShape(enfVertex->geomEntry); -// GeomType = GeomShape.ShapeType(); - -// if (!enfVertex->isCompound) { -// // if (GeomType == TopAbs_VERTEX) { -// coords.clear(); -// aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape)); -// coords.push_back(aPnt.X()); -// coords.push_back(aPnt.Y()); -// coords.push_back(aPnt.Z()); -// if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { -// coordsSizeMap.insert(std::make_pair(coords,enfVertex->size)); -// enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName)); -// } -// } -// -// // Group Management -// else { -// if (GeomType == TopAbs_COMPOUND){ - for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ - coords.clear(); - if (it.Value().ShapeType() == TopAbs_VERTEX){ - gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value())); - coords.push_back(aPnt.X()); - coords.push_back(aPnt.Y()); - coords.push_back(aPnt.Z()); - if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { - coordsSizeMap.insert(std::make_pair(coords,enfVertex->size)); - enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName)); -// MESSAGE("enfVerticesWithGroup.insert(std::make_pair(("<groupName<<"\"))"); - } + for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ + coords.clear(); + if (it.Value().ShapeType() == TopAbs_VERTEX){ + gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value())); + coords.push_back(aPnt.X()); + coords.push_back(aPnt.Y()); + coords.push_back(aPnt.Z()); + if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { + coordsSizeMap.insert(std::make_pair(coords,enfVertex->size)); + enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName)); } } -// } + } } } int nbEnforcedVertices = coordsSizeMap.size(); int nbEnforcedNodes = enforcedNodes.size(); - + std::string tmpStr; (nbEnforcedNodes <= 1) ? tmpStr = "node" : "nodes"; std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl; @@ -2925,9 +1477,9 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, MG_HYBRID_API mgHybrid( _computeCanceled, _progress ); Ok = writeGMFFile(&mgHybrid, - aGMFFileName.ToCString(), - aRequiredVerticesFileName.ToCString(), - aSolFileName.ToCString(), + aGMFFileName.c_str(), + aRequiredVerticesFileName.c_str(), + aSolFileName.c_str(), *proxyMesh, helper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap, aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId, @@ -2935,9 +1487,9 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, enfVerticesWithGroup, coordsSizeMap); // Write aSmdsToHybridIdMap to temp file - TCollection_AsciiString aSmdsToHybridIdMapFileName; + std::string aSmdsToHybridIdMapFileName; aSmdsToHybridIdMapFileName = aGenericName + ".ids"; // ids relation - ofstream aIdsFile ( aSmdsToHybridIdMapFileName.ToCString() , ios::out); + ofstream aIdsFile ( aSmdsToHybridIdMapFileName , ios::out); Ok = aIdsFile.rdbuf()->is_open(); if (!Ok) { INFOS( "Can't write into " << aSmdsToHybridIdMapFileName); @@ -2967,23 +1519,21 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // run hybrid mesher // ----------------- - TCollection_AsciiString cmd( (char*)HYBRIDPlugin_Hypothesis::CommandToRun( _hyp ).c_str() ); + std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh ); if ( mgHybrid.IsExecutable() ) { - cmd += TCollection_AsciiString(" --in ") + aGMFFileName; - //if ( nbEnforcedVertices + nbEnforcedNodes) - // cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired; - cmd += TCollection_AsciiString(" --out ") + aResultFileName; + cmd += " --in " + aGMFFileName; + cmd += " --out " + aResultFileName; } std::cout << std::endl; std::cout << "Hybrid execution with geometry..." << std::endl; std::cout << cmd; if ( !_logInStandardOutput ) { - mgHybrid.SetLogFile( aLogFileName.ToCString() ); + mgHybrid.SetLogFile( aLogFileName ); if ( mgHybrid.IsExecutable() ) - cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file + cmd += " 1>" + aLogFileName; // dump into file std::cout << " 1> " << aLogFileName; } std::cout << std::endl; @@ -2991,7 +1541,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, _computeCanceled = false; std::string errStr; - Ok = mgHybrid.Compute( cmd.ToCString(), errStr ); // run + Ok = mgHybrid.Compute( cmd, errStr ); // run if ( _logInStandardOutput && mgHybrid.IsLibrary() ) std::cout << std::endl << mgHybrid.GetLog() << std::endl; @@ -3004,22 +1554,21 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // Mapping the result file - HYBRIDPlugin_Hypothesis::TSetStrings groupsToRemove = HYBRIDPlugin_Hypothesis::GetGroupsToRemove(_hyp); - bool toMeshHoles = - _hyp ? _hyp->GetToMeshHoles(true) : HYBRIDPlugin_Hypothesis::DefaultMeshHoles(); - const bool toMakeGroupsOfDomains = HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp ); + HYBRIDPlugin_Hypothesis::TSetStrings groupsToRemove = HYBRIDPlugin_Hypothesis::GetGroupsToRemove(_hyp); + bool toMeshHoles = + _hyp ? _hyp->GetToMeshHoles(true) : HYBRIDPlugin_Hypothesis::DefaultMeshHoles(); + const bool toMakeGroupsOfDomains = HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp ); - helper.IsQuadraticSubMesh( theShape ); - helper.SetElementsOnShape( false ); - - Ok = readGMFFile(&mgHybrid, aResultFileName.ToCString(), - this, - &helper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap, - aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId, - groupsToRemove, toMakeGroupsOfDomains, toMeshHoles); + helper.IsQuadraticSubMesh( theShape ); + helper.SetElementsOnShape( false ); - removeEmptyGroupsOfDomains( helper.GetMesh(), !toMakeGroupsOfDomains ); + Ok = readGMFFile(&mgHybrid, aResultFileName.c_str(), + this, + &helper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap, + aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId, + groupsToRemove, toMakeGroupsOfDomains, toMeshHoles); + removeEmptyGroupsOfDomains( helper.GetMesh(), !toMakeGroupsOfDomains ); @@ -3031,15 +1580,12 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, { if ( _removeLogOnSuccess ) removeFile( aLogFileName ); - - // if ( _hyp && _hyp->GetToMakeGroupsOfDomains() ) - // error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" ); } else if ( mgHybrid.HasLog() ) { // get problem description from the log file _Ghs2smdsConvertor conv( aNodeByHybridId ); - storeErrorDescription( _logInStandardOutput ? 0 : aLogFileName.ToCString(), + storeErrorDescription( _logInStandardOutput ? 0 : aLogFileName.c_str(), mgHybrid.GetLog(), conv ); } else if ( !errStr.empty() ) @@ -3062,7 +1608,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, } if ( mgHybrid.IsExecutable() ) { - std::cout << "<" << aResultFileName.ToCString() << "> HYBRID output file "; + std::cout << "<" << aResultFileName << "> HYBRID output file "; if ( !Ok ) std::cout << "not "; std::cout << "treated !" << std::endl; @@ -3084,39 +1630,29 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, SMESH_MesherHelper* theHelper) { - MESSAGE("HYBRIDPlugin_HYBRID::Compute()"); - theHelper->IsQuadraticSubMesh( theHelper->GetSubShape() ); // a unique working file name // to avoid access to the same files by eg different users _genericName = HYBRIDPlugin_Hypothesis::GetFileName(_hyp); - TCollection_AsciiString aGenericName((char*) _genericName.c_str() ); - TCollection_AsciiString aGenericNameRequired = aGenericName + "_required"; + std::string aGenericName((char*) _genericName.c_str() ); + std::string aGenericNameRequired = aGenericName + "_required"; - TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log - TCollection_AsciiString aResultFileName; + std::string aLogFileName = aGenericName + ".log"; // log + std::string aResultFileName; bool Ok; - TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName, aResSolFileName; -//#ifdef _DEBUG_ + std::string aGMFFileName, aRequiredVerticesFileName, aSolFileName, aResSolFileName; aGMFFileName = aGenericName + ".mesh"; // GMF mesh file aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file aResSolFileName = aGenericName + "Vol.sol"; // GMF mesh file aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file -//#else -// aGMFFileName = aGenericName + ".meshb"; // GMF mesh file -// aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file -// aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file -// aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file -//#endif std::map nodeID2nodeIndexMap; std::map, std::string> enfVerticesWithGroup; HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues coordsSizeMap; TopoDS_Shape GeomShape; -// TopAbs_ShapeEnum GeomType; std::vector coords; gp_Pnt aPnt; HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* enfVertex; @@ -3127,69 +1663,31 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt) { enfVertex = (*enfVerIt); -// if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) { if (enfVertex->coords.size()) { coordsSizeMap.insert(std::make_pair(enfVertex->coords,enfVertex->size)); enfVerticesWithGroup.insert(std::make_pair(enfVertex->coords,enfVertex->groupName)); -// MESSAGE("enfVerticesWithGroup.insert(std::make_pair(("<coords[0]<<","<coords[1]<<","<coords[2]<<"),\""<groupName<<"\"))"); } else { -// if (!enfVertex->geomEntry.empty()) { GeomShape = entryToShape(enfVertex->geomEntry); -// GeomType = GeomShape.ShapeType(); - -// if (!enfVertex->isCompound) { -// // if (GeomType == TopAbs_VERTEX) { -// coords.clear(); -// aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape)); -// coords.push_back(aPnt.X()); -// coords.push_back(aPnt.Y()); -// coords.push_back(aPnt.Z()); -// if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { -// coordsSizeMap.insert(std::make_pair(coords,enfVertex->size)); -// enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName)); -// } -// } -// -// // Group Management -// else { -// if (GeomType == TopAbs_COMPOUND){ - for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ - coords.clear(); - if (it.Value().ShapeType() == TopAbs_VERTEX){ - aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value())); - coords.push_back(aPnt.X()); - coords.push_back(aPnt.Y()); - coords.push_back(aPnt.Z()); - if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { - coordsSizeMap.insert(std::make_pair(coords,enfVertex->size)); - enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName)); -// MESSAGE("enfVerticesWithGroup.insert(std::make_pair(("<groupName<<"\"))"); - } + for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ + coords.clear(); + if (it.Value().ShapeType() == TopAbs_VERTEX){ + aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value())); + coords.push_back(aPnt.X()); + coords.push_back(aPnt.Y()); + coords.push_back(aPnt.Z()); + if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { + coordsSizeMap.insert(std::make_pair(coords,enfVertex->size)); + enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName)); } } -// } + } } } -// const SMDS_MeshNode* enfNode; HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = HYBRIDPlugin_Hypothesis::GetEnforcedNodes(_hyp); -// HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin(); -// for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt) -// { -// enfNode = enfNodeIt->first; -// coords.clear(); -// coords.push_back(enfNode->X()); -// coords.push_back(enfNode->Y()); -// coords.push_back(enfNode->Z()); -// if (enfVerticesWithGro -// enfVerticesWithGroup.insert(std::make_pair(coords,enfNodeIt->second)); -// } - - HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = HYBRIDPlugin_Hypothesis::GetEnforcedEdges(_hyp); HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(_hyp); -// TIDSortedElemSet enforcedQuadrangles = HYBRIDPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp); HYBRIDPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); std::string tmpStr; @@ -3211,8 +1709,8 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, MG_HYBRID_API mgHybrid( _computeCanceled, _progress ); Ok = writeGMFFile(&mgHybrid, - aGMFFileName.ToCString(), - aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), + aGMFFileName.c_str(), + aRequiredVerticesFileName.c_str(), aSolFileName.c_str(), *proxyMesh, *theHelper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap, aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId, @@ -3223,19 +1721,17 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // run hybrid mesher // ----------------- - TCollection_AsciiString cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str(); + std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh ); if ( mgHybrid.IsExecutable() ) { - cmd += TCollection_AsciiString(" --in ") + aGMFFileName; - //if ( nbEnforcedVertices + nbEnforcedNodes) - // cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired; - cmd += TCollection_AsciiString(" --out ") + aResultFileName; + cmd += " --in " + aGMFFileName; + cmd += " --out " + aResultFileName; } if ( !_logInStandardOutput ) { - cmd += TCollection_AsciiString(" 1> " ) + aLogFileName; // dump into file - mgHybrid.SetLogFile( aLogFileName.ToCString() ); + cmd += " 1> " + aLogFileName; // dump into file + mgHybrid.SetLogFile( aLogFileName ); } std::cout << std::endl; std::cout << "Hybrid execution w/o geometry..." << std::endl; @@ -3244,7 +1740,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, _computeCanceled = false; std::string errStr; - Ok = mgHybrid.Compute( cmd.ToCString(), errStr ); // run + Ok = mgHybrid.Compute( cmd, errStr ); // run if ( _logInStandardOutput && mgHybrid.IsLibrary() ) std::cout << std::endl << mgHybrid.GetLog() << std::endl; @@ -3258,14 +1754,13 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, const bool toMakeGroupsOfDomains = HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp ); Ok = Ok && readGMFFile(&mgHybrid, - aResultFileName.ToCString(), + aResultFileName.c_str(), this, theHelper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap, aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId, groupsToRemove, toMakeGroupsOfDomains); updateMeshGroups(theHelper->GetMesh(), groupsToRemove); - //removeEmptyGroupsOfDomains( theHelper->GetMesh(), notEmptyAsWell ); removeEmptyGroupsOfDomains( theHelper->GetMesh(), !toMakeGroupsOfDomains ); if ( Ok ) { @@ -3281,21 +1776,18 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, { if ( _removeLogOnSuccess ) removeFile( aLogFileName ); - - //if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() ) - //error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." ); } else if ( mgHybrid.HasLog() ) { // get problem description from the log file _Ghs2smdsConvertor conv( aNodeByHybridId ); - storeErrorDescription( _logInStandardOutput ? 0 : aLogFileName.ToCString(), + storeErrorDescription( _logInStandardOutput ? 0 : aLogFileName.c_str(), mgHybrid.GetLog(), conv ); } else { // the log file is empty removeFile( aLogFileName ); - INFOS( "HYBRID Error, command '" << cmd.ToCString() << "' failed" ); + INFOS( "HYBRID Error, command '" << cmd << "' failed" ); error(COMPERR_ALGO_FAILED, "hybrid: command not found" ); } @@ -3315,8 +1807,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, void HYBRIDPlugin_HYBRID::CancelCompute() { _computeCanceled = true; -#ifdef WIN32 -#else +#if !defined(WIN32) && !defined(__APPLE__) std::string cmd = "ps xo pid,args | grep " + _genericName; //cmd += " | grep -e \"^ *[0-9]\\+ \\+" + HYBRIDPlugin_Hypothesis::GetExeName() + "\""; cmd += " | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1";