From: wolf Date: Fri, 25 Jun 1999 16:58:23 +0000 (+0000) Subject: Unify code for 2d and 3d eps output. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=818e66afa2d09903b48de5ebd5a2913fb9c0a947;p=dealii-svn.git Unify code for 2d and 3d eps output. git-svn-id: https://svn.dealii.org/trunk@1475 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc new file mode 100644 index 0000000000..31d39e45a1 --- /dev/null +++ b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc @@ -0,0 +1,65 @@ +/* $Id$ */ + +#include + + +template +void GridOut::write (const Triangulation &tria, + ostream &out, + OutputFormat output_format) +{ + switch (output_format) + { + case gnuplot: + write_gnuplot (tria, out); + return; + + case eps: + write_eps (tria, out); + return; + }; + + Assert (false, ExcInternalError()); +}; + + + +string GridOut::default_suffix (const OutputFormat output_format) +{ + switch (output_format) + { + case gnuplot: + return ".gnuplot"; + + case eps: + return ".eps"; + + default: + Assert (false, ExcNotImplemented()); + return ""; + }; +}; + + + + +GridOut::OutputFormat +GridOut::parse_output_format (const string &format_name) { + if (format_name == "gnuplot") + return gnuplot; + + if (format_name == "eps") + return eps; + + AssertThrow (false, ExcInvalidState ()); + // return something weird + return OutputFormat(-1); +}; + + + +string GridOut::get_output_format_names () { + return "gnuplot|eps"; +}; + + diff --git a/deal.II/deal.II/source/grid/grid_out.cc b/deal.II/deal.II/source/grid/grid_out.cc index c3ff16781f..f52c3d2e5a 100644 --- a/deal.II/deal.II/source/grid/grid_out.cc +++ b/deal.II/deal.II/source/grid/grid_out.cc @@ -86,17 +86,6 @@ void GridOut::write_gnuplot (const Triangulation &tria, template void GridOut::write_eps (const Triangulation &tria, ostream &out) -{ - Assert (false, ExcNotImplemented()); -}; - - - -#if deal_II_dimension == 2 - -template <> -void GridOut::write_eps (const Triangulation<2> &tria, - ostream &out) { typedef list,Point<2> > > LineList; @@ -105,162 +94,99 @@ void GridOut::write_eps (const Triangulation<2> &tria, // make up a list of lines by which // we will construct the triangulation + // + // this part unfortunately is a bit + // dimension dependent, so we have to + // treat every dimension different. + // however, by directly producing + // the lines to be printed, i.e. their + // 2d images, we can later do the + // actual output dimension independent + // again LineList line_list; - Triangulation<2>::active_line_iterator line =tria.begin_active_line (); - Triangulation<2>::active_line_iterator endline=tria.end_line (); - - for (; line!=endline; ++line) - line_list.push_back (make_pair(line->vertex(0), - line->vertex(1))); - - // find out minimum and maximum x and - // y coordinates to compute offsets - // and scaling factors - double x_min = tria.begin_active_line()->vertex(0)(0); - double x_max = x_min; - double y_min = tria.begin_active_line()->vertex(0)(1); - double y_max = y_min; - - for (LineList::const_iterator line=line_list.begin(); - line!=line_list.end(); ++line) - { - x_min = min (x_min, line->first(0)); - x_min = min (x_min, line->second(0)); - - x_max = max (x_max, line->first(0)); - x_max = max (x_max, line->second(0)); - - y_min = min (y_min, line->first(1)); - y_min = min (y_min, line->second(1)); - y_max = max (y_max, line->first(1)); - y_max = max (y_max, line->second(1)); - }; - - // scale in x-direction such that - // in the output 0 <= x <= 300. - // don't scale in y-direction to - // preserve the shape of the - // triangulation - const double scale = 300. / (x_max - x_min); - - - // now write preamble - if (true) + switch (dim) { - // block this to have local - // variables destroyed after - // use - time_t time1= time (0); - tm *time = localtime(&time1); - out << "%!PS-Adobe-2.0 EPSF-1.2" << endl - << "%%Title: deal.II Output" << endl - << "%%Creator: the deal.II library" << endl - << "%%Creation Date: " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << " - " - << time->tm_hour << ":" - << setw(2) << time->tm_min << ":" - << setw(2) << time->tm_sec << endl - << "%%BoundingBox: " - // lower left corner - << "0 0 " - // upper right corner - << "300 " << static_cast( (y_max-y_min) * scale ) - << endl; - - // define some abbreviations to keep - // the output small: - // m=move turtle to - // x=execute line stroke - out << "/m {moveto} bind def" << endl - << "/x {lineto stroke} bind def" << endl; - - out << "%%EndProlog" << endl - << endl; - - // set fine lines - out << "0.5 setlinewidth" << endl; + case 2: + { + Triangulation::active_line_iterator line =tria.begin_active_line (); + Triangulation::active_line_iterator endline=tria.end_line (); + + for (; line!=endline; ++line) + // one would expect + // make_pair(line->vertex(0), + // line->vertex(1)) + // here, but that is not + // dimension independent, since + // vertex(i) is Point, + // but we want a Point<2>. + // in fact, whenever we're here, + // the vertex is a Point, + // but the compiler does not + // know this. hopefully, the + // compiler will optimize away + // this little kludge + line_list.push_back (make_pair(Point<2>(line->vertex(0)(0), + line->vertex(0)(1)), + Point<2>(line->vertex(1)(0), + line->vertex(1)(1)))); + break; + }; + + case 3: + { + Triangulation::active_line_iterator line =tria.begin_active_line (); + Triangulation::active_line_iterator endline=tria.end_line (); + + // loop over all lines and compute their + // projection on the plane perpendicular + // to the direction of sight + + // direction of view equals the unit + // vector of the position of the + // spectator to the origin. + // + // we chose here the viewpoint as in + // gnuplot + const double z_angle = 60; + const double turn_angle = 30; + const double pi = 3.1415926536; + const Point view_direction(-sin(z_angle * 2.*pi / 360.) * sin(turn_angle * 2.*pi / 360.), + +sin(z_angle * 2.*pi / 360.) * cos(turn_angle * 2.*pi / 360.), + -cos(z_angle * 2.*pi / 360.)); + + // decide about the two unit vectors + // in this plane. we chose the first one + // to be the projection of the z-axis + // to this plane + const Point vector1 + = Point(0,0,1) - ((Point(0,0,1) * view_direction) * view_direction); + const Point unit_vector1 = vector1 / sqrt(vector1.square()); + + // now the third vector is fixed. we + // chose the projection of a more or + // less arbitrary vector to the plane + // perpendicular to the first one + const Point vector2 + = (Point(1,0,0) + - ((Point(1,0,0) * view_direction) * view_direction) + - ((Point(1,0,0) * unit_vector1) * unit_vector1)); + const Point unit_vector2 = vector2 / sqrt(vector2.square()); + + for (; line!=endline; ++line) + line_list.push_back (make_pair(Point<2>(line->vertex(0) * unit_vector2, + line->vertex(0) * unit_vector1), + Point<2>(line->vertex(1) * unit_vector2, + line->vertex(1) * unit_vector1))); + + break; + }; + + default: + Assert (false, ExcNotImplemented()); }; - - // now write the lines - const Point<2> offset(x_min, y_min); - - for (LineList::const_iterator line=line_list.begin(); - line!=line_list.end(); ++line) - out << (line->first - offset) * scale << " m " - << (line->second - offset) * scale << " x\n"; - - out << "showpage" << endl; - - AssertThrow (out, ExcIO()); -}; - -#endif - - - -#if deal_II_dimension == 3 - -template <> -void GridOut::write_eps (const Triangulation<3> &tria, - ostream &out) -{ - typedef list,Point<2> > > LineList; - AssertThrow (out, ExcIO()); - - // make up a list of lines by which - // we will construct the triangulation - LineList line_list; - Triangulation<3>::active_line_iterator line =tria.begin_active_line (); - Triangulation<3>::active_line_iterator endline=tria.end_line (); - - // loop over all lines and compute their - // projection on the plane perpendicular - // to the direction of sight - if (true) - { - // direction of view equals the unit - // vector of the position of the - // spectator to the origin. - // - // we chose here the viewpoint as in - // gnuplot - const double z_angle = 60; - const double turn_angle = 30; - const double pi = 3.1415926536; - const Point<3> view_direction(-sin(z_angle * 2.*pi / 360.) * sin(turn_angle * 2.*pi / 360.), - +sin(z_angle * 2.*pi / 360.) * cos(turn_angle * 2.*pi / 360.), - -cos(z_angle * 2.*pi / 360.)); - - // decide about the two unit vectors - // in this plane. we chose the first one - // to be the projection of the z-axis - // to this plane - const Point<3> vector1 - = Point<3>(0,0,1) - ((Point<3>(0,0,1) * view_direction) * view_direction); - const Point<3> unit_vector1 = vector1 / sqrt(vector1.square()); - - // now the third vector is fixed. we - // chose the projection of a more or - // less arbitrary vector to the plane - // perpendicular to the first one - const Point<3> vector2 - = (Point<3>(1,0,0) - - ((Point<3>(1,0,0) * view_direction) * view_direction) - - ((Point<3>(1,0,0) * unit_vector1) * unit_vector1)); - const Point<3> unit_vector2 = vector2 / sqrt(vector2.square()); - - for (; line!=endline; ++line) - line_list.push_back (make_pair(Point<2>(line->vertex(0) * unit_vector2, - line->vertex(0) * unit_vector1), - Point<2>(line->vertex(1) * unit_vector2, - line->vertex(1) * unit_vector1))); - }; - // find out minimum and maximum x and // y coordinates to compute offsets @@ -346,12 +272,10 @@ void GridOut::write_eps (const Triangulation<3> &tria, AssertThrow (out, ExcIO()); }; -#endif - // explicit instantiations template void GridOut::write_gnuplot (const Triangulation &, ostream &); -//template void GridOut::write_eps (const Triangulation &, ostream &); +template void GridOut::write_eps (const Triangulation &, ostream &); template void GridOut::write (const Triangulation &, ostream &, OutputFormat);