- // tabID = new int[nbShape];
- tabID = new int[nbDomains];
- tabRef = new int[nField];
- tabDummy = new bool[nField];
-
- for (int i=0; i<nbDomains; i++)
- tabID[i] = 0;
- if ( nbDomains == 1 )
- tabID[0] = theMesh->ShapeToIndex( tabShape[0] );
-
- mapField["MeshVersionFormatted"] = 0; tabRef[0] = 0; tabDummy[0] = false;
- mapField["Dimension"] = 1; tabRef[1] = 0; tabDummy[1] = false;
- mapField["Vertices"] = 2; tabRef[2] = 3; tabDummy[2] = true;
- mapField["Corners"] = 3; tabRef[3] = 1; tabDummy[3] = false;
- mapField["Edges"] = 4; tabRef[4] = 2; tabDummy[4] = true;
- mapField["Ridges"] = 5; tabRef[5] = 1; tabDummy[5] = false;
- mapField["Quadrilaterals"] = 6; tabRef[6] = 4; tabDummy[6] = true;
- mapField["Hexahedra"] = 7; tabRef[7] = 8; tabDummy[7] = true;
- mapField["End"] = 8; tabRef[8] = 0; tabDummy[0] = false;
-
- SMDS_NodeIteratorPtr itOnHexoticInputNode = theMesh->nodesIterator();
- while ( itOnHexoticInputNode->more() )
- theMesh->RemoveNode( itOnHexoticInputNode->next() );
-
- int nbVertices = getNbShape(theFile, "Vertices");
- int nbCorners = getNbShape(theFile, "Corners", countShape( theMesh, TopAbs_VERTEX ));
- int nbShapeEdge = countShape( theMesh, TopAbs_EDGE );
-
- tabCorner = new TopoDS_Shape[ nbCorners ];
- tabEdge = new TopoDS_Shape[ nbShapeEdge ];
- nodeAssigne = new int[ nbVertices + 1 ];
- HexoticNode = new SMDS_MeshNode*[ nbVertices + 1 ];
-
- getShape(theMesh, TopAbs_VERTEX, tabCorner);
- getShape(theMesh, TopAbs_EDGE, tabEdge);
-
- MESSAGE("Read " << theFile << " file");
- std::ifstream fileRes(theFile.c_str());
- ASSERT(fileRes);
-
- while ( EndOfFile == 0 ) {
- int dummy;
- fileRes >> token;
-
- if (mapField.count(token)) {
- nField = mapField[token];
- nbRef = tabRef[nField];
- hasDummy = tabDummy[nField];
- }
- else {
- nField = -1;
- nbRef = 0;
- }
-
- nbElem = 0;
- if ( nField < (mapField.size() - 1) && nField >= 0 )
- fileRes >> nbElem;
-
- switch (nField) {
- case 0: { // "MeshVersionFormatted"
- MESSAGE(token << " " << nbElem);
- break;
- }
- case 1: { // "Dimension"
- MESSAGE("Mesh dimension " << nbElem << "D");
- break;
- }
- case 2: { // "Vertices"
- MESSAGE("Read " << nbElem << " " << token);
- int aHexoticID;
- double *coord;
- SMDS_MeshNode * aHexoticNode;
-
- coord = new double[nbRef];
- for ( int iElem = 0; iElem < nbElem; iElem++ ) {
- if(theAlgo->computeCanceled())
- {
- return false;
- }
- aHexoticID = iElem + 1;
- for ( int iCoord = 0; iCoord < 3; iCoord++ )
- fileRes >> coord[ iCoord ];
- fileRes >> dummy;
- aHexoticNode = theMesh->AddNode(coord[0], coord[1], coord[2]);
- HexoticNode[ aHexoticID ] = aHexoticNode;
- nodeAssigne[ aHexoticID ] = 0;
- }
- delete [] coord;
- break;
- }
- case 3: // "Corners"
- case 4: // "Edges"
- case 5: // "Ridges"
- case 6: // "Quadrilaterals"
- case 7: { // "Hexahedra"
- MESSAGE("Read " << nbElem << " " << token);
- SMDS_MeshNode** node;
- int nodeDim, *nodeID;
- SMDS_MeshElement * aHexoticElement = 0;
-
- node = new SMDS_MeshNode*[ nbRef ];
- nodeID = new int[ nbRef ];
- for ( int iElem = 0; iElem < nbElem; iElem++ ) {
- if(theAlgo->computeCanceled())
- {
- return false;
- }
- for ( int iRef = 0; iRef < nbRef; iRef++ ) {
- fileRes >> aHexoticNodeID; // read nbRef aHexoticNodeID
- node[ iRef ] = HexoticNode[ aHexoticNodeID ];
- nodeID[ iRef ] = aHexoticNodeID;
- }
- if ( hasDummy )
- fileRes >> dummy;
- switch (nField) {
- case 3: { // "Corners"
- nodeDim = 1;
- gp_Pnt HexoticPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
- for ( int i=0; i<nbElem; i++ ) {
- aVertex = TopoDS::Vertex( tabCorner[i] );
- gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
- if ( aPnt.Distance( HexoticPnt ) < epsilon )
- break;
- }
- break;
- }
- case 4: { // "Edges"
- nodeDim = 2;
- aHexoticElement = theMesh->AddEdge( node[0], node[1] );
- int iNode = 1;
- if ( nodeAssigne[ nodeID[0] ] == 0 || nodeAssigne[ nodeID[0] ] == 2 )
- iNode = 0;
- if(retrieve_edges)
- shapeID = findEdge( node[iNode], theMesh, nbShapeEdge, tabEdge );
- else
- shapeID = 0;
- break;
- }
- case 5: { // "Ridges"
- break;
- }
- case 6: { // "Quadrilaterals"
- nodeDim = 3;
- aHexoticElement = theMesh->AddFace( node[0], node[1], node[2], node[3] );
- shapeID = dummy;
- break;
- }
- case 7: { // "Hexahedra"
- nodeDim = 4;
- if ( nbDomains > 1 ) {
- hexoticShapeID = dummy - IdShapeRef;
- if ( tabID[ hexoticShapeID ] == 0 ) {
- aShape = findShape(node, aShape, tabShape, tabBox, nbShape);
- shapeID = aShape.IsNull() ? holeID : theMesh->ShapeToIndex( aShape );
- tabID[ hexoticShapeID ] = shapeID;
- }
- else
- shapeID = tabID[ hexoticShapeID ];
- if ( iElem == (nbElem - 1) ) {
- int shapeAssociated = 0;
- for ( int i=0; i<nbDomains; i++ ) {
- if (tabID[i] > 0 )
- shapeAssociated += 1;
- }
- if ( shapeAssociated != nbShape )
- printWarning(nbShape, "domains", shapeAssociated);
- }
- }
- else {
- shapeID = tabID[0];
- }
- if ( shapeID != holeID )
- aHexoticElement = theMesh->AddVolume( node[0], node[3], node[2], node[1], node[4], node[7], node[6], node[5] );
- break;
- }
- } // switch (nField)
-
- if ( token != "Ridges" && ( shapeID > 0 || token == "Corners")) {
- for ( int i=0; i<nbRef; i++ ) {
- if ( nodeAssigne[ nodeID[i] ] == 0 ) {
- if ( token == "Corners" ) theMesh->SetNodeOnVertex( node[0], aVertex );
- else if ( token == "Edges" ) theMesh->SetNodeOnEdge( node[i], shapeID );
- else if ( token == "Quadrilaterals" ) theMesh->SetNodeOnFace( node[i], shapeID );
- else if ( token == "Hexahedra" ) theMesh->SetNodeInVolume( node[i], shapeID );
- nodeAssigne[ nodeID[i] ] = nodeDim;
- }
- }
- if ( token != "Corners" && aHexoticElement )
- theMesh->SetMeshElementOnShape( aHexoticElement, shapeID );
- }
- }
- delete [] node;
- delete [] nodeID;
- break;
- }
- case 8: { // "End"
- EndOfFile = 1;
- MESSAGE("End of " << theFile << " file");
- break;
- }
- default: {
- MESSAGE("Unknown Token: " << token);
- }
- }