]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Unify code for 2d and 3d eps output.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 25 Jun 1999 16:58:23 +0000 (16:58 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 25 Jun 1999 16:58:23 +0000 (16:58 +0000)
git-svn-id: https://svn.dealii.org/trunk@1475 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/source/grid/grid_out.all_dimensions.cc [new file with mode: 0644]
deal.II/deal.II/source/grid/grid_out.cc

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 (file)
index 0000000..31d39e4
--- /dev/null
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+#include <basic/grid_out.h>
+
+
+template <int dim>
+void GridOut::write (const Triangulation<dim> &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";
+};
+
+
index c3ff16781f22806110e2289a47358a93be4837a8..f52c3d2e5a4c1a8d8536fd129041dd89fe96835d 100644 (file)
@@ -86,17 +86,6 @@ void GridOut::write_gnuplot (const Triangulation<dim> &tria,
 template <int dim>
 void GridOut::write_eps (const Triangulation<dim> &tria,
                         ostream                  &out) 
-{
-  Assert (false, ExcNotImplemented());
-};
-
-
-
-#if deal_II_dimension == 2
-
-template <>
-void GridOut::write_eps (const Triangulation<2> &tria,
-                        ostream                &out) 
 {
   typedef list<pair<Point<2>,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<unsigned int>( (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<dim>::active_line_iterator line   =tria.begin_active_line ();
+       Triangulation<dim>::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<dim>,
+                                          // but we want a Point<2>.
+                                          // in fact, whenever we're here,
+                                          // the vertex is a Point<dim>,
+                                          // 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<dim>::active_line_iterator line   =tria.begin_active_line ();
+       Triangulation<dim>::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<dim> 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<dim> vector1
+         = Point<dim>(0,0,1) - ((Point<dim>(0,0,1) * view_direction) * view_direction);
+       const Point<dim> 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<dim> vector2
+         = (Point<dim>(1,0,0)
+            - ((Point<dim>(1,0,0) * view_direction) * view_direction)
+            - ((Point<dim>(1,0,0) * unit_vector1)   * unit_vector1));
+       const Point<dim> 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<pair<Point<2>,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<deal_II_dimension> &, ostream &);
-//template void GridOut::write_eps (const Triangulation<deal_II_dimension> &, ostream &);
+template void GridOut::write_eps (const Triangulation<deal_II_dimension> &, ostream &);
 template void GridOut::write (const Triangulation<deal_II_dimension> &, ostream &, OutputFormat);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.