Esempio n. 1
0
    int ElmerReader::readNodes(node_map& nodes){
        string line;
        double coords[3]; // store node coords
        int id, buffer, tokens;
        char test;
        nodes.clear();
		
//		printf("reading nodes from \"%s\"\n",nodeFile.c_str());
        ifstream in(nodeFile.c_str());
        if(!in.is_open()) return -1;
//		printf("file opened successfully\n");
        while(in.good()){
            getline(in, line); test=0;
            // format for nodes is "node-id unused x y z"
            tokens=sscanf(line.c_str(),"%d %d %lf %lf %lf%c",
                    &id, &buffer, coords, coords+1, coords+2, &test);
            //printf("read %d tokens: %d %d %lf %lf %lf, test is %d\n",
            //        tokens, id, buffer, coords[0], coords[1], coords[2], test);
            if(tokens==5 && test==0){ //line format is correct
                nodes[id]=vector<double>(coords, coords+3);
            }
        }
        in.close();
//		printf("read %d nodes from %s\n", nodes.size(),nodeFile.c_str());
        return nodes.size();
    }
Esempio n. 2
0
	int readVCG(std::string filename, node_map& nodes, elem_map& elems){
		localReaderVCG::MyMesh mesh;
		nodes.clear(); elems.clear();
		int r = io::Importer<localReaderVCG::MyMesh>::Open(mesh,filename.c_str());

		id_map vertexId; unsigned int k=NODE_BASE_INDEX;
        for(localReaderVCG::MyMesh::VertexIterator vi=mesh.vert.begin(); vi!=mesh.vert.end(); ++vi) if(!vi->IsD()){
			nodes[k].assign(3,0.0);
			nodes[k][0]= vi->P()[0];
			nodes[k][1]= vi->P()[1];
			nodes[k][2]= vi->P()[2];
            vertexId[vi-mesh.vert.begin()]=k;
            ++k;
        }
        k=ELEM_BASE_INDEX;
        for(localReaderVCG::MyMesh::FaceIterator fi=mesh.face.begin(); fi!=mesh.face.end(); ++fi) if(!fi->IsD()){
			elems[k].assign(3,0);
			elems[k][0]=vertexId[tri::Index(mesh, fi->V(0))];
            elems[k][1]=vertexId[tri::Index(mesh, fi->V(1))];
            elems[k][2]=vertexId[tri::Index(mesh, fi->V(2))];
            ++k;
        }
		return r;
	}
Esempio n. 3
0
    int BEMReader::readModel(elem_map& elems, id_map& bodyIDs,
        elem_map& bndrys, elem_map& bndryParents, node_map& nodes,
        const ELEM_TYPE elemType,  const std::set<unsigned int> elemBodies,
        const ELEM_TYPE bndryType, const std::set<unsigned int> bndryBodies
    ){
		//if meshFile ends with ".stl", ".obj", ".ply" etc. use VCG to read raw-mesh (nodes & elems, nothing more)
		if( meshFile.find(".stl")!=meshFile.npos ||
			meshFile.find(".obj")!=meshFile.npos ||
			meshFile.find(".off")!=meshFile.npos ||
			meshFile.find(".ply")!=meshFile.npos
		){
			printf("\n%% reading raw triangle mesh from %s (requires --remesh option)\n%%\t",meshFile.c_str());
			return readVCG(meshFile,nodes,elems);
		}
		node_map nodes_in;
        //elem_map elems_in;
        int ret;
        // read elements and nodes
		ret=readElems(elems, elemType, elemBodies,ELEMENTS_FILE,&bodyIDs);
        if(ret<0) return ret;
        ret=readNodes(nodes_in);
        if(ret<0) return ret;
        // now switch to .boundary file
        string tmp=elemFile;
        elemFile=meshFile;
        elemFile.append(".boundary");
        ret=readElems(bndrys,bndryType,bndryBodies,BOUNDARY_FILE,NULL,&bndryParents,true);
        // restore state of the BEMReader object
        elemFile=tmp;
        //if(ret<0) return ret; // it's ok to not have a boundary file, if there's no pre-defined cracks

		// reading is complete, but for HyENA-BEM compatibility the nodes need to be numbered
		// in the same order as they appear in the element map.
        
		// run through the element map and decide new node numbers
		id_map fwd;// bkwd; // fwd[old_id]=new_id, bkwd[new_id]=old_id
		unsigned int new_id=NODE_BASE_INDEX;
		for(elem_map::iterator i = elems.begin(); i!=elems.end(); ++i){
			//run through all nodes of the element
			for(elem_map::mapped_type::iterator j = i->second.begin(); j!=i->second.end(); ++j){
				if(fwd.count(*j)==0){ // assing new number at first occurence of node
					fwd[*j]=new_id; //bkwd[new_id]=*j;
					new_id++;
				}
				(*j)=fwd[*j]; //update element
			}
		}
        nodes.clear();
		// copy from nodes_in to nodes while applying new numbering
		for(node_map::iterator i = nodes_in.begin(); i!= nodes_in.end(); ++i){
			nodes[fwd[i->first]] = i->second;
		}
		// apply new numbering to bndry elements
		for(elem_map::iterator i = bndrys.begin(); i!=bndrys.end(); ++i){
			for(elem_map::mapped_type::iterator j = i->second.begin(); j!=i->second.end(); ++j){
				(*j)=fwd[*j]; //update element
			}
		}

		return elems.size();
    }