예제 #1
0
bool TetGenInterface::readElementsFromStream(std::ifstream &ins)
{
	std::string line;
	getline (ins, line);
	size_t pos_beg (line.find_first_not_of(" "));
	size_t n_tets, n_nodes_per_tet;
	bool region_attributes;
	bool not_read_header (true);

	while (!ins.fail() && not_read_header)
	{
		line = line.substr(pos_beg);
		if (line.compare(0,1,"#") == 0)
		{
			// this line is a comment - skip
			getline (ins, line);
			pos_beg = line.find_first_not_of(" ");
		}
		else
			// read header line
			not_read_header = !parseElementsFileHeader(line,
			                                           n_tets,
			                                           n_nodes_per_tet,
			                                           region_attributes);
	}
	if (not_read_header)
		return false;
	if (!parseElements(ins, n_tets, n_nodes_per_tet, region_attributes))
		return false;

	return true;
}
예제 #2
0
파일: Gmsh2GeoIO.cpp 프로젝트: JobstM/ogs
void Gmsh2GeoIO::loadMeshAsGeometry (std::string & fname, GeoLib::GEOObjects* geo)
{
	// open file
	std::ifstream ins (fname.c_str());
	if (!ins)
	{
		std::cout << "could not open file " << fname << std::endl;
		return;
	}

	std::string line;
	// read gmsh header
	getline (ins, line); // $MeshFormat
	getline (ins, line);
	getline (ins, line); // $EndMeshFormat

	// read nodes tag
	getline (ins, line);
	// read number of nodes
	getline (ins, line);
	const size_t n_pnts (str2number<size_t>(line));
	std::vector<GeoLib::Point*>* pnts (new std::vector<GeoLib::Point*>);
	for (size_t k(0); k < n_pnts; k++)
	{
		getline (ins, line);
		// parse id
		size_t pos_beg(0);
		size_t pos_end (line.find(" "));
		// the sub string line.substr(pos_beg, pos_end-pos_beg) represents the id
		// parse x coordinate
		pos_beg = pos_end + 1;
		pos_end = line.find(" ", pos_beg);
		double x (str2number<double>(line.substr(pos_beg, pos_end - pos_beg)));
		// parse y coordinate
		pos_beg = pos_end + 1;
		pos_end = line.find(" ", pos_beg);
		double y (str2number<double>(line.substr(pos_beg, pos_end - pos_beg)));
		// parse z coordinate
		pos_beg = pos_end + 1;
		pos_end = line.find("\n", pos_beg);
		double z (str2number<double>(line.substr(pos_beg, pos_end - pos_beg)));

		pnts->push_back (new GeoLib::Point (x,y,z));
	}
	// read end nodes tag
	getline (ins, line);

	geo->addPointVec (pnts, fname);

	std::vector<size_t> const& pnt_id_map (geo->getPointVecObj(fname)->getIDMap());
	// read element tag
	getline (ins, line);
	// read number of elements
	getline (ins, line);
	const size_t n_elements (str2number<size_t>(line));
	GeoLib::Surface* sfc (new GeoLib::Surface (*pnts));
	for (size_t k(0); k < n_elements; k++)
	{
		getline (ins, line);
		// parse id
		size_t pos_beg(0);
		size_t pos_end (line.find(" "));
		// the sub string line.substr(pos_beg, pos_end-pos_beg) represents the id
		// parse element type
		pos_beg = pos_end + 1;
		pos_end = line.find(" ", pos_beg);
		size_t ele_type (str2number<size_t>(line.substr(pos_beg, pos_end - pos_beg)));
		if (ele_type == 2) // read 3 node triangle
		{ // parse number of tags
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t n_tags (str2number<size_t>(line.substr(pos_beg,
			                                                    pos_end - pos_beg)));
			// (over) read tags
			for (size_t j(0); j < n_tags; j++)
			{
				pos_beg = pos_end + 1;
				pos_end = line.find(" ", pos_beg);
			}
			// parse first id of triangle
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t id0 (str2number<size_t>(line.substr(pos_beg,
			                                                 pos_end - pos_beg)) - 1); // shift -1!
			// parse second id of triangle
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t id1 (str2number<size_t>(line.substr(pos_beg,
			                                                 pos_end - pos_beg)) - 1); // shift -1!
			// parse third id of triangle
			pos_beg = pos_end + 1;
			pos_end = line.find(" ", pos_beg);
			const size_t id2 (str2number<size_t>(line.substr(pos_beg,
			                                                 pos_end - pos_beg)) - 1); // shift -1!
			sfc->addTriangle (pnt_id_map[id0], pnt_id_map[id1], pnt_id_map[id2]);
		}
	}
	// read end element tag
	getline (ins, line);

	std::vector<GeoLib::Surface*>* sfcs (new std::vector<GeoLib::Surface*>);
	sfcs->push_back(sfc);
	geo->addSurfaceVec (sfcs, fname);
}