MOAB: Mesh Oriented datABase  (version 5.4.1)
MeshWriter.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2005 Lawrence Livermore National Laboratory.  Under
00005     the terms of Contract B545069 with the University of Wisconsin --
00006     Madison, Lawrence Livermore National Laboratory retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 #ifndef MSQ_MESH_WRITER_HPP
00028 #define MSQ_MESH_WRITER_HPP
00029 
00030 #include "Matrix3D.hpp"
00031 #include "MeshInterface.hpp"
00032 
00033 namespace MBMesquite
00034 {
00035 
00036 class PlanarDomain;
00037 class Vector3D;
00038 class PatchData;
00039 
00040 namespace MeshWriter
00041 {
00042 
00043     /** \brief Enumeration of principal coordinate axes */
00044     enum Axis
00045     {
00046         X = 0,
00047         Y = 1,
00048         Z = 2
00049     };
00050 
00051     /**\brief Specify a projection to use for output
00052      *
00053      * This class defines a projection used to transform
00054      * R^3 vertex positions to 2D positions to use in graphics
00055      * file formats.
00056      */
00057     class MESQUITE_EXPORT Projection
00058     {
00059       public:
00060         /** Project into specified plane - choice of up direction is arbitrary */
00061         Projection( PlanarDomain* domain );
00062         /** Project into plane with specified normal - choice of up direction is arbitrary */
00063         Projection( const Vector3D& view );
00064         /** Project points into plane normal to #view vector.  Orient
00065          *  projection such that the projection of the #up vector into
00066          *  the plane is parallel with the vertical direction in the output.
00067          */
00068         Projection( const Vector3D& view, const Vector3D& up );
00069         /** Specify which principal axes should be aligned with the
00070          *  horizontal and vertical in the output
00071          */
00072         Projection( Axis horizontal, Axis vertical );
00073 
00074         /** Project a point into the plane */
00075         void project( const Vector3D& point, float& horiz, float& vert );
00076 
00077         static Matrix3D rotation( const Vector3D& axis, double angle );
00078 
00079       private:
00080         void init( const Vector3D& view );
00081         void init( const Vector3D& view, const Vector3D& up );
00082 
00083         Matrix3D myTransform;
00084     };
00085 
00086     /** \brief Write mesh as gnuplot data
00087      *
00088      * Write a file that can be drawn in gnuplot with the command:
00089      * "plot 'filename' with lines"
00090      */
00091     MESQUITE_EXPORT
00092     void write_gnuplot( Mesh* mesh, const char* filename, MsqError& err );
00093     MESQUITE_EXPORT
00094     void write_gnuplot( PatchData& pd, const char* filename, MsqError& err );
00095     MESQUITE_EXPORT
00096     void write_gnuplot( Mesh* mesh, std::vector< Mesh::ElementHandle >& elems, const char* filename, MsqError& err );
00097 
00098     /**\brief Write animator for sequence of gnuplot data files
00099      *
00100      * Given a set of files named foo.0.gpt, foo.1.gpt, ... foo.n.gpt,
00101      * write a file foo.gnuplot that produces an animation of the
00102      * data by calling write_gnuplot_animator( n, foo, err );
00103      */
00104     MESQUITE_EXPORT
00105     void write_gnuplot_animator( int count, const char* basename, MsqError& err );
00106 
00107     /**\brief Write GNU plot commands to overlay a set of mesh timesteps in a single plot
00108      *
00109      * Given a set of files named foo.0.gpt, foo.1.gpt, ... foo.n.gpt,
00110      * write a file foo.gnuplot that produces an overlay of the meshes in
00111      * each file by calling write_gnuplot_animator( n, foo, err );
00112      */
00113     MESQUITE_EXPORT
00114     void write_gnuplot_overlay( int count, const char* basename, MsqError& err );
00115 
00116     /** \brief Write mesh as a VTK file
00117      *
00118      * Write a simple VTK file for viewing.  The file written by this
00119      * function is intended for viewing.  It contains only a minimal
00120      * decription of the mesh.  It does not contain other data such as
00121      * tags/attributes.  If the Mesh is a MeshImpl, use the VTK writing
00122      * function provided in MeshImpl for a complete mesh export.
00123      */
00124     MESQUITE_EXPORT
00125     void write_vtk( Mesh* mesh, const char* filename, MsqError& err );
00126     MESQUITE_EXPORT
00127     void write_vtk( PatchData& pd, const char* filename, MsqError& err, const Vector3D* OF_gradient = 0 );
00128 
00129     /** Convert inches to points */
00130     inline int in2pt( float inches )
00131     {
00132         return (int)( inches * 72.0f );
00133     }
00134     /** Convert centimeters to points */
00135     inline int cm2pt( float cm )
00136     {
00137         return (int)( cm * 72.0f / 2.54f );
00138     }
00139 
00140     /**\brief Write an Encapsulate PostScript file.
00141      *
00142      * Write encapsulated postscript.
00143      *\param proj - PostScript is a 2-D drawing format.  This argument
00144      *              specifies which 2-D projection of the 3-D mesh to write.
00145      *\param width - The width of the output image, in points.
00146      *\param height - The height of the output image, in points.
00147      */
00148     MESQUITE_EXPORT
00149     void write_eps( Mesh* mesh,
00150                     const char* filename,
00151                     Projection proj,
00152                     MsqError& err,
00153                     int width  = in2pt( 6.5 ),
00154                     int height = in2pt( 9 ) );
00155 
00156     /**\brief Write an SVG file.
00157      *
00158      * Write a 2-D projection of the mesh to a Scalable Vector Graphics
00159      * file. (W3C standard).
00160      *\param proj - SVG is a 2-D drawing format.  This argument
00161      *              specifies which 2-D projection of the 3-D mesh to write.
00162      */
00163     MESQUITE_EXPORT
00164     void write_svg( Mesh* mesh, const char* filename, Projection proj, MsqError& err );
00165 
00166     /**\brief Write STL
00167      *
00168      * Write the mesh as an ASCII STL (Stereo Lithography) file.
00169      * The STL format only supports writing triangles.
00170      * This writer will write only the triangles contained in the
00171      * passed mesh.  Any non-triangle elements will be ignored.
00172      */
00173     MESQUITE_EXPORT
00174     void write_stl( Mesh* mesh, const char* filename, MsqError& err );
00175 
00176     /**\brief Write EPS file containing single triangle in XY plane.
00177      */
00178     MESQUITE_EXPORT
00179     void write_eps_triangle( Mesh* mesh,
00180                              Mesh::ElementHandle elem,
00181                              const char* filename,
00182                              bool draw_iso_lines,
00183                              bool draw_nodes,
00184                              MsqError& err,
00185                              int width  = in2pt( 6.5 ),
00186                              int height = in2pt( 9 ) );
00187     MESQUITE_EXPORT
00188     void write_eps_triangle( const Vector3D* coords,
00189                              size_t num_vtx,
00190                              const char* filename,
00191                              bool draw_iso_lines,
00192                              bool draw_nodes,
00193                              MsqError& err,
00194                              const std::vector< bool >& fixed_flags,
00195                              int width  = in2pt( 6.5 ),
00196                              int height = in2pt( 9 ) );
00197 
00198 }  // namespace MeshWriter
00199 
00200 }  // namespace MBMesquite
00201 
00202 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines