///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// fig2poly: Converts xfig drawings into input files for Jonathan Shewczuk's triangle code.
96 cout <<
"Wrong number of command line arguments. " << std::endl;
97 cout <<
"Must specify the single file name that " << std::endl;
98 cout <<
"specifies the xfig file" << std::endl;
103 ifstream xfig_file(argv[1]);
107 vector<vector<vector<double> > > boundary_point_coords;
111 vector<vector<double> > hole_coords;
128 getline(xfig_file,input_string,
'\n');
129 std::string version_string=input_string.substr(0,8);
130 if (version_string!=
"#FIG 3.2")
132 std::cout <<
"*.fig file is in the wrong format!\n"
133 <<
"It must conform to Fig Format 3.2\n"
134 <<
"but the version string is: " << version_string
141 for (
unsigned i=0;
i<7;
i++)
144 getline(xfig_file,input_string,
'\n');
149 int scaling_factor,dummy;
150 xfig_file >> scaling_factor;
157 std::ostringstream buffer;
158 while (!xfig_file.eof())
161 getline(xfig_file,input_string,
'\n');
165 buffer <<
" " << input_string;
169 std::string aux_string(buffer.str(),0,buffer.str().length()-1);
172 std::istringstream buffer2(aux_string);
176 while (!buffer2.eof())
181 buffer2 >> object_id;
189 <<
"I've read a circle -- it will be used as a hole identifier."
200 vector<double> new_hole(2);
212 hole_coords.push_back(new_hole);
220 else if (object_id==2)
222 cout <<
"I've read a polyline -- it defines a boundary."
242 vector<vector<double> > new_boundary(npoints);
250 new_boundary[
i].resize(2);
256 boundary_point_coords.push_back(new_boundary);
261 <<
"Can't handle this sub-type of polygon: " << sub_type << std::endl
262 <<
"Can only do open polylines -- no closed boxes, etc. " << std::endl;
272 <<
"Can't handle this object id: " << object_id
273 <<
"\nMake sure your figure only contains: \n"
274 <<
"- polylines (which define boundaries) \n"
275 <<
"- circles/ellipses (which define hole points) \n"
276 <<
"Also make sure that you've broken up any\n"
277 <<
"compound objects. " << std::endl;
289 unsigned total_npoints=0;
290 unsigned nbound=boundary_point_coords.size();
291 for (
unsigned b=0;
b<nbound;
b++)
293 unsigned npoints=boundary_point_coords[
b].size();
294 total_npoints+=npoints;
300 sprintf(
filename,
"%s.poly",argv[1]);
305 <<
" 2 0 0 # of pts, 2D, no attributes or boundary markers for points"
311 for (
unsigned b=0;
b<nbound;
b++)
313 unsigned npoints=boundary_point_coords[
b].size();
314 for (
unsigned i=0;
i<npoints;
i++)
319 poly_file << count <<
" " << boundary_point_coords[
b][
i][0]
320 <<
" " << boundary_point_coords[
b][
i][1]
321 <<
" # [located on boundary " <<
b <<
"]" << std::endl;
329 poly_file <<
"# END_OF_NODE_BLOCK" << std::endl;
336 poly_file << total_npoints <<
" 1 "
337 <<
" # [number of segments (i.e. boundary edges),"
338 <<
" flag for using boundary markers here]"
345 unsigned edge_count=1;
346 unsigned npoints_in_all_previous_boundaries=0;
349 for (
unsigned b=0;
b<nbound;
b++)
351 unsigned npoints=boundary_point_coords[
b].size();
354 for (
unsigned i=0;
i<npoints-1;
i++)
358 poly_file << edge_count <<
" "
359 << npoints_in_all_previous_boundaries+
i+1 <<
" "
360 << npoints_in_all_previous_boundaries+
i+2 <<
" "
361 <<
" " <<
b+1 << std::endl;
370 poly_file << edge_count <<
" "
371 << npoints_in_all_previous_boundaries+npoints <<
" "
372 << npoints_in_all_previous_boundaries+1 <<
" "
373 <<
" " <<
b+1 << std::endl;
379 npoints_in_all_previous_boundaries+=npoints;
383 poly_file <<
"# END_OF_SEGMENT_BLOCK" << std::endl;
392 vector<vector<double> > Point_in_hole;
395 unsigned nhole=hole_coords.size();
396 Point_in_hole.resize(nhole);
397 unsigned hole_count=1;
398 poly_file << nhole <<
" # [number of holes] " << std::endl;
399 for (
unsigned i=0;
i<nhole;
i++)
401 poly_file << hole_count <<
" "
402 << hole_coords[
i][0] <<
" "
403 << hole_coords[
i][1] << std::endl;
406 Point_in_hole[
i].resize(2);
407 Point_in_hole[
i][0]= hole_coords[
i][0];
408 Point_in_hole[
i][1]= hole_coords[
i][1];
416 poly_file <<
"# END_OF_HOLE_BLOCK" << std::endl;
Scalar * b
Definition: benchVecAdd.cpp:17
void ignore_ints(std::ifstream &fig_file, const unsigned &nints=1)
Helper function – ignores specified number of ints from input stream.
Definition: fig2poly.cc:39
void ignore_floats(std::ifstream &fig_file, const unsigned &nfloats=1)
Helper function – ignores specified number of floats from input stream.
Definition: fig2poly.cc:49
string filename
Definition: MergeRestartFiles.py:39
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286