-
- GmfCloseMesh(idx);
- if (idxRequired)
- GmfCloseMesh(idxRequired);
- if (idxSol)
- GmfCloseMesh(idxSol);
-
- return true;
-
-}
-
-// static bool writeGMFFile(const char* theMeshFileName,
-// const char* theRequiredFileName,
-// const char* theSolFileName,
-// SMESH_MesherHelper& theHelper,
-// const SMESH_ProxyMesh& theProxyMesh,
-// std::map <int,int> & theNodeId2NodeIndexMap,
-// std::map <int,int> & theSmdsToHybridIdMap,
-// std::map <int,const SMDS_MeshNode*> & 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<double> 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<int> 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( 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<std::vector<double> > VerTab;
-// std::set<std::vector<double> > VerMap;
-// VerTab.clear();
-// std::vector<double> 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<double> 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( make_pair( node->GetID(), aHybridID ));
-// theHybridIdToNodeMap.insert( 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<double> 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( make_pair( (*enfNodeIt)->GetID(), aHybridID ));
-// }
-// }
-//
-//
-// /* ENFORCED VERTICES ========================== */
-// int solSize = 0;
-// std::vector<std::vector<double> > 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<double> 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<int,int>::const_iterator itOnMap;
-// std::vector<std::vector<int> > tt, qt,et;
-// tt.clear();
-// qt.clear();
-// et.clear();
-// std::vector<int> 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<double> 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( 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<double> 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( make_pair( node->GetID(), aHybridID ));
-// aet.push_back(aHybridID);
-// }
-// if (isOK)
-// et.push_back(aet);
-// }
-// }
-//
-//
-// /* Write vertices number */
-// MESSAGE("Number of vertices: "<<aHybridID);
-// MESSAGE("Size of vector: "<<VerTab.size());
-// GmfSetKwd(idx, GmfVertices, aHybridID/*+solSize*/);
-// for (int i=0;i<aHybridID;i++)
-// GmfSetLin(idx, GmfVertices, VerTab[i][0], VerTab[i][1], VerTab[i][2], dummyint);
-// // for (int i=0;i<solSize;i++) {
-// // std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
-// // GmfSetLin(idx, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
-// // }
-//
-// if (solSize) {
-// idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
-// if (!idxRequired) {
-// GmfCloseMesh(idx);
-// return false;
-// }
-// idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
-// if (!idxSol){
-// GmfCloseMesh(idx);
-// if (idxRequired)
-// GmfCloseMesh(idxRequired);
-// return false;
-// }
-//
-// int TypTab[] = {GmfSca};
-// GmfSetKwd(idxRequired, GmfVertices, solSize);
-// GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
-//
-// for (int i=0;i<solSize;i++) {
-// double solTab[] = {enfVertexSizes.at(i)};
-// GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
-// GmfSetLin(idxSol, GmfSolAtVertices, solTab);
-// }
-// GmfCloseMesh(idxRequired);
-// GmfCloseMesh(idxSol);
-// }
-//
-// /* Write triangles number */
-// if (tt.size()) {
-// GmfSetKwd(idx, GmfTriangles, tt.size());
-// for (int i=0;i<tt.size();i++)
-// GmfSetLin(idx, GmfTriangles, tt[i][0], tt[i][1], tt[i][2], dummyint);
-// }
-//
-// /* Write edges number */
-// if (et.size()) {
-// GmfSetKwd(idx, GmfEdges, et.size());
-// for (int i=0;i<et.size();i++)
-// GmfSetLin(idx, GmfEdges, et[i][0], et[i][1], dummyint);
-// }
-//
-// /* QUADRANGLES ========================== */
-// // TODO: add pyramids ?
-// // if (nbQuadrangles) {
-// // for ( int i = 1; i <= quadranglesMap.Extent(); i++ )
-// // {
-// // aShape = quadranglesMap(i);
-// // theSubMesh = theProxyMesh.GetSubMesh(aShape);
-// // if ( !theSubMesh ) continue;
-// // itOnSubMesh = theSubMesh->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<qt.size();i++)
-// // GmfSetLin(idx, GmfQuadrilaterals, qt[i][0], qt[i][1], qt[i][2], qt[i][3], dummyint);
-// // }
-//
-// GmfCloseMesh(idx);
-// return true;
-// }
-
-
-//=======================================================================
-//function : writeFaces
-//purpose :
-//=======================================================================
-
-static bool writeFaces (ofstream & theFile,
- const SMESH_ProxyMesh& theMesh,
- const TopoDS_Shape& theShape,
- const map <int,int> & theSmdsToHybridIdMap,
- const map <int,int> & 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;
- map<int,int>::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 );