Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2005 Lawrence Livermore National Laboratory. Under
5 : : the terms of Contract B545069 with the University of Wisconsin --
6 : : Madison, Lawrence Livermore National Laboratory retains certain
7 : : rights in this software.
8 : :
9 : : This library is free software; you can redistribute it and/or
10 : : modify it under the terms of the GNU Lesser General Public
11 : : License as published by the Free Software Foundation; either
12 : : version 2.1 of the License, or (at your option) any later version.
13 : :
14 : : This library is distributed in the hope that it will be useful,
15 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : Lesser General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU Lesser General Public License
20 : : (lgpl.txt) along with this library; if not, write to the Free Software
21 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 : :
23 : : [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : #ifndef MSQ_MESH_WRITER_HPP
28 : : #define MSQ_MESH_WRITER_HPP
29 : :
30 : : #include "Matrix3D.hpp"
31 : : #include "MeshInterface.hpp"
32 : :
33 : : namespace MBMesquite
34 : : {
35 : :
36 : : class PlanarDomain;
37 : : class Vector3D;
38 : : class PatchData;
39 : :
40 : : namespace MeshWriter
41 : : {
42 : :
43 : : /** \brief Enumeration of principal coordinate axes */
44 : : enum Axis
45 : : {
46 : : X = 0,
47 : : Y = 1,
48 : : Z = 2
49 : : };
50 : :
51 : : /**\brief Specify a projection to use for output
52 : : *
53 : : * This class defines a projection used to transform
54 : : * R^3 vertex positions to 2D positions to use in graphics
55 : : * file formats.
56 : : */
57 : 0 : class MESQUITE_EXPORT Projection
58 : : {
59 : : public:
60 : : /** Project into specified plane - choice of up direction is arbitrary */
61 : : Projection( PlanarDomain* domain );
62 : : /** Project into plane with specified normal - choice of up direction is arbitrary */
63 : : Projection( const Vector3D& view );
64 : : /** Project points into plane normal to #view vector. Orient
65 : : * projection such that the projection of the #up vector into
66 : : * the plane is parallel with the vertical direction in the output.
67 : : */
68 : : Projection( const Vector3D& view, const Vector3D& up );
69 : : /** Specify which principal axes should be aligned with the
70 : : * horizontal and vertical in the output
71 : : */
72 : : Projection( Axis horizontal, Axis vertical );
73 : :
74 : : /** Project a point into the plane */
75 : : void project( const Vector3D& point, float& horiz, float& vert );
76 : :
77 : : static Matrix3D rotation( const Vector3D& axis, double angle );
78 : :
79 : : private:
80 : : void init( const Vector3D& view );
81 : : void init( const Vector3D& view, const Vector3D& up );
82 : :
83 : : Matrix3D myTransform;
84 : : };
85 : :
86 : : /** \brief Write mesh as gnuplot data
87 : : *
88 : : * Write a file that can be drawn in gnuplot with the command:
89 : : * "plot 'filename' with lines"
90 : : */
91 : : MESQUITE_EXPORT
92 : : void write_gnuplot( Mesh* mesh, const char* filename, MsqError& err );
93 : : MESQUITE_EXPORT
94 : : void write_gnuplot( PatchData& pd, const char* filename, MsqError& err );
95 : : MESQUITE_EXPORT
96 : : void write_gnuplot( Mesh* mesh, std::vector< Mesh::ElementHandle >& elems, const char* filename, MsqError& err );
97 : :
98 : : /**\brief Write animator for sequence of gnuplot data files
99 : : *
100 : : * Given a set of files named foo.0.gpt, foo.1.gpt, ... foo.n.gpt,
101 : : * write a file foo.gnuplot that produces an animation of the
102 : : * data by calling write_gnuplot_animator( n, foo, err );
103 : : */
104 : : MESQUITE_EXPORT
105 : : void write_gnuplot_animator( int count, const char* basename, MsqError& err );
106 : :
107 : : /**\brief Write GNU plot commands to overlay a set of mesh timesteps in a single plot
108 : : *
109 : : * Given a set of files named foo.0.gpt, foo.1.gpt, ... foo.n.gpt,
110 : : * write a file foo.gnuplot that produces an overlay of the meshes in
111 : : * each file by calling write_gnuplot_animator( n, foo, err );
112 : : */
113 : : MESQUITE_EXPORT
114 : : void write_gnuplot_overlay( int count, const char* basename, MsqError& err );
115 : :
116 : : /** \brief Write mesh as a VTK file
117 : : *
118 : : * Write a simple VTK file for viewing. The file written by this
119 : : * function is intended for viewing. It contains only a minimal
120 : : * decription of the mesh. It does not contain other data such as
121 : : * tags/attributes. If the Mesh is a MeshImpl, use the VTK writing
122 : : * function provided in MeshImpl for a complete mesh export.
123 : : */
124 : : MESQUITE_EXPORT
125 : : void write_vtk( Mesh* mesh, const char* filename, MsqError& err );
126 : : MESQUITE_EXPORT
127 : : void write_vtk( PatchData& pd, const char* filename, MsqError& err, const Vector3D* OF_gradient = 0 );
128 : :
129 : : /** Convert inches to points */
130 : 0 : inline int in2pt( float inches )
131 : : {
132 : 0 : return (int)( inches * 72.0f );
133 : : }
134 : : /** Convert centimeters to points */
135 : : inline int cm2pt( float cm )
136 : : {
137 : : return (int)( cm * 72.0f / 2.54f );
138 : : }
139 : :
140 : : /**\brief Write an Encapsulate PostScript file.
141 : : *
142 : : * Write encapsulated postscript.
143 : : *\param proj - PostScript is a 2-D drawing format. This argument
144 : : * specifies which 2-D projection of the 3-D mesh to write.
145 : : *\param width - The width of the output image, in points.
146 : : *\param height - The height of the output image, in points.
147 : : */
148 : : MESQUITE_EXPORT
149 : : void write_eps( Mesh* mesh, const char* filename, Projection proj, MsqError& err, int width = in2pt( 6.5 ),
150 : : int height = in2pt( 9 ) );
151 : :
152 : : /**\brief Write an SVG file.
153 : : *
154 : : * Write a 2-D projection of the mesh to a Scalable Vector Graphics
155 : : * file. (W3C standard).
156 : : *\param proj - SVG is a 2-D drawing format. This argument
157 : : * specifies which 2-D projection of the 3-D mesh to write.
158 : : */
159 : : MESQUITE_EXPORT
160 : : void write_svg( Mesh* mesh, const char* filename, Projection proj, MsqError& err );
161 : :
162 : : /**\brief Write STL
163 : : *
164 : : * Write the mesh as an ASCII STL (Stereo Lithography) file.
165 : : * The STL format only supports writing triangles.
166 : : * This writer will write only the triangles contained in the
167 : : * passed mesh. Any non-triangle elements will be ignored.
168 : : */
169 : : MESQUITE_EXPORT
170 : : void write_stl( Mesh* mesh, const char* filename, MsqError& err );
171 : :
172 : : /**\brief Write EPS file containing single triangle in XY plane.
173 : : */
174 : : MESQUITE_EXPORT
175 : : void write_eps_triangle( Mesh* mesh, Mesh::ElementHandle elem, const char* filename, bool draw_iso_lines,
176 : : bool draw_nodes, MsqError& err, int width = in2pt( 6.5 ), int height = in2pt( 9 ) );
177 : : MESQUITE_EXPORT
178 : : void write_eps_triangle( const Vector3D* coords, size_t num_vtx, const char* filename, bool draw_iso_lines,
179 : : bool draw_nodes, MsqError& err, const std::vector< bool >& fixed_flags,
180 : : int width = in2pt( 6.5 ), int height = in2pt( 9 ) );
181 : :
182 : : } // namespace MeshWriter
183 : :
184 : : } // namespace MBMesquite
185 : :
186 : : #endif
|