MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::MeshWriter Namespace Reference

Classes

class  Transform2D
 Transform from coordinates in the XY-plane to graphics coordinates. More...
class  Projection
 Specify a projection to use for output. More...

Enumerations

enum  Axis { X = 0, Y = 1, Z = 2 }
 Enumeration of principal coordinate axes. More...

Functions

void write_vtk (Mesh *mesh, const char *filename, MsqError &err)
 Write mesh as a VTK file.
void write_vtk (PatchData &pd, const char *out_filename, MsqError &err, const Vector3D *OF_gradient)
void write_gnuplot (Mesh *mesh, const char *filename, MsqError &err)
 Write mesh as gnuplot data.
void write_gnuplot (Mesh *mesh, std::vector< Mesh::ElementHandle > &elems, const char *out_filebase, MsqError &err)
void write_gnuplot (PatchData &pd, const char *out_filebase, MsqError &err)
static void find_gnuplot_agregate_range (int count, const char *basename, Vector3D &min, Vector3D &max, MsqError &err)
void write_gnuplot_animator (int count, const char *basename, MsqError &err)
 Write animator for sequence of gnuplot data files.
static unsigned red (int i, int c)
static unsigned green (int i, int c)
static unsigned blue (int i, int c)
void write_gnuplot_overlay (int count, const char *basename, MsqError &err)
 Write GNU plot commands to overlay a set of mesh timesteps in a single plot.
void write_stl (Mesh *mesh, const char *filename, MsqError &err)
 Write STL.
static void write_eps_quadratic_edge (ostream &s, Transform2D &xform, Vector3D start, Vector3D mid, Vector3D end)
void write_eps (Mesh *mesh, const char *filename, Projection proj, MsqError &err, int width=in2pt(6.5), int height=in2pt(9))
 Write an Encapsulate PostScript file.
static double tN0 (double r, double s)
static double tN1 (double r, double)
static double tN2 (double, double s)
static double tN3 (double r, double s)
static double tN4 (double r, double s)
static double tN5 (double r, double s)
static Vector3D quad_tri_pt (double r, double s, const Vector3D *coords)
void write_eps_triangle (Mesh *mesh, Mesh::ElementHandle elem, const char *filename, bool draw_iso_lines, bool draw_nodes, MsqError &err, int width=in2pt(6.5), int height=in2pt(9))
 Write EPS file containing single triangle in XY plane.
void write_eps_triangle (const Vector3D *coords, size_t num_vtx, const char *filename, bool draw_iso_lines, bool draw_nodes, MsqError &err, const std::vector< bool > &fixed, int width, int height)
void write_svg (Mesh *mesh, const char *filename, Projection proj, MsqError &err)
 Write an SVG file.
int in2pt (float inches)
int cm2pt (float cm)

Enumeration Type Documentation

Enumeration of principal coordinate axes.

Enumerator:
X 
Y 
Z 

Definition at line 44 of file MeshWriter.hpp.

    {
        X = 0,
        Y = 1,
        Z = 2
    };

Function Documentation

static unsigned MBMesquite::MeshWriter::blue ( int  i,
int  c 
) [static]

Definition at line 382 of file MeshWriter.cpp.

Referenced by update_density(), and write_gnuplot_overlay().

    {
        if( i * 4 <= c )
            return 0;
        else if( i * 4 >= 3 * c )
            return 255;
        else
            return i * 511 / c - 127;
    }
int MBMesquite::MeshWriter::cm2pt ( float  cm) [inline]

Convert centimeters to points

Definition at line 135 of file MeshWriter.hpp.

    {
        return (int)( cm * 72.0f / 2.54f );
    }
static void MBMesquite::MeshWriter::find_gnuplot_agregate_range ( int  count,
const char *  basename,
Vector3D &  min,
Vector3D &  max,
MsqError &  err 
) [static]

Helper function for write_gnuplot_animator and write_gnuplot_overlay

Read a set of input files to determine the bounding box of the combined data.

Definition at line 273 of file MeshWriter.cpp.

References MSQ_SETERR.

Referenced by write_gnuplot_animator(), and write_gnuplot_overlay().

    {
        // read all input files to determine extents
        min = Vector3D( HUGE_VAL, HUGE_VAL, HUGE_VAL );
        max = Vector3D( -HUGE_VAL, -HUGE_VAL, -HUGE_VAL );
        for( int i = 0; i <= count; ++i )
        {
            stringstream s;
            s << basename << '.' << i << ".gpt";
            ifstream infile( s.str().c_str() );
            if( !infile )
            {
                MSQ_SETERR( err )( s.str(), MsqError::FILE_ACCESS );
                return;
            }
            double c[3];
            while( infile >> c[0] >> c[1] >> c[2] )
            {
                for( int j = 0; j < 3; ++j )
                {
                    if( c[j] < min[j] ) min[j] = c[j];
                    if( c[j] > max[j] ) max[j] = c[j];
                }
            }
        }
    }
static unsigned MBMesquite::MeshWriter::green ( int  i,
int  c 
) [static]

Definition at line 372 of file MeshWriter.cpp.

Referenced by write_gnuplot_overlay().

    {
        if( i * 4 < c )
            return i * 510 / c;
        else if( i * 4 > 3 * c )
            return 1023 - i * 1023 / c;
        else
            return 255;
    }
int MBMesquite::MeshWriter::in2pt ( float  inches) [inline]

Convert inches to points

Definition at line 130 of file MeshWriter.hpp.

    {
        return (int)( inches * 72.0f );
    }
static Vector3D MBMesquite::MeshWriter::quad_tri_pt ( double  r,
double  s,
const Vector3D *  coords 
) [static]

Quadratic triangle shape function for use in write_eps_triangle

Definition at line 812 of file MeshWriter.cpp.

References tN0(), tN1(), tN2(), tN3(), tN4(), and tN5().

Referenced by write_eps_triangle().

    {
        Vector3D result = tN0( r, s ) * coords[0];
        result += tN1( r, s ) * coords[1];
        result += tN2( r, s ) * coords[2];
        result += tN3( r, s ) * coords[3];
        result += tN4( r, s ) * coords[4];
        result += tN5( r, s ) * coords[5];
        return result;
    }
static unsigned MBMesquite::MeshWriter::red ( int  i,
int  c 
) [static]

Definition at line 362 of file MeshWriter.cpp.

Referenced by write_gnuplot_overlay().

    {
        if( i * 4 <= c )
            return 255;
        else if( i * 4 >= 3 * c )
            return 0;
        else
            return 384 - i * 511 / c;
    }
static double MBMesquite::MeshWriter::tN0 ( double  r,
double  s 
) [static]

Quadratic triangle shape function for use in write_eps_triangle

Definition at line 784 of file MeshWriter.cpp.

References t.

Referenced by quad_tri_pt().

    {
        double t = 1 - r - s;
        return t * ( 2 * t - 1 );
    }
static double MBMesquite::MeshWriter::tN1 ( double  r,
double   
) [static]

Definition at line 789 of file MeshWriter.cpp.

Referenced by quad_tri_pt().

    {
        return r * ( 2 * r - 1 );
    }
static double MBMesquite::MeshWriter::tN2 ( double  ,
double  s 
) [static]

Definition at line 793 of file MeshWriter.cpp.

Referenced by quad_tri_pt().

    {
        return s * ( 2 * s - 1 );
    }
static double MBMesquite::MeshWriter::tN3 ( double  r,
double  s 
) [static]

Definition at line 797 of file MeshWriter.cpp.

References t.

Referenced by quad_tri_pt().

    {
        double t = 1 - r - s;
        return 4 * r * t;
    }
static double MBMesquite::MeshWriter::tN4 ( double  r,
double  s 
) [static]

Definition at line 802 of file MeshWriter.cpp.

Referenced by quad_tri_pt().

    {
        return 4 * r * s;
    }
static double MBMesquite::MeshWriter::tN5 ( double  r,
double  s 
) [static]

Definition at line 806 of file MeshWriter.cpp.

References t.

Referenced by quad_tri_pt().

    {
        double t = 1 - r - s;
        return 4 * s * t;
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_eps ( Mesh *  mesh,
const char *  filename,
Projection  proj,
MsqError &  err,
int  width = in2pt(6.5),
int  height = in2pt(9) 
)

Write an Encapsulate PostScript file.

Write encapsulated postscript.

Parameters:
proj- PostScript is a 2-D drawing format. This argument specifies which 2-D projection of the 3-D mesh to write.
width- The width of the output image, in points.
height- The height of the output image, in points.

Definition at line 707 of file MeshWriter.cpp.

References MBMesquite::EdgeIterator::end(), MBMesquite::MsqError::FILE_ACCESS, MBMesquite::PatchData::fill_global_patch(), MBMesquite::EdgeIterator::is_at_end(), MBMesquite::MeshWriter::Transform2D::max_horizontal(), MBMesquite::MeshWriter::Transform2D::max_vertical(), MBMesquite::EdgeIterator::mid(), MSQ_ERRRTN, MSQ_SETERR, MBMesquite::PatchData::set_mesh(), MBMesquite::EdgeIterator::start(), MBMesquite::EdgeIterator::step(), MBMesquite::MeshWriter::Transform2D::transform(), and write_eps_quadratic_edge().

Referenced by run().

    {
        // Get a global patch
        PatchData pd;
        pd.set_mesh( mesh );
        pd.fill_global_patch( err );MSQ_ERRRTN( err );

        Transform2D transf( &pd, proj, width, height, false );

        // Open the file
        ofstream s( filename );
        if( !s )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // Write header
        s << "%!PS-Adobe-2.0 EPSF-2.0" << endl;
        s << "%%Creator: Mesquite" << endl;
        s << "%%Title: Mesquite " << endl;
        s << "%%DocumentData: Clean7Bit" << endl;
        s << "%%Origin: 0 0" << endl;
        s << "%%BoundingBox: 0 0 " << transf.max_horizontal() << ' ' << transf.max_vertical() << endl;
        s << "%%Pages: 1" << endl;

        s << "%%BeginProlog" << endl;
        s << "save" << endl;
        s << "countdictstack" << endl;
        s << "mark" << endl;
        s << "newpath" << endl;
        s << "/showpage {} def" << endl;
        s << "/setpagedevice {pop} def" << endl;
        s << "%%EndProlog" << endl;

        s << "%%Page: 1 1" << endl;
        s << "1 setlinewidth" << endl;
        s << "0.0 setgray" << endl;

        // Write mesh edges
        EdgeIterator iter( &pd, err );MSQ_ERRRTN( err );
        while( !iter.is_at_end() )
        {
            int s_w, s_h, e_w, e_h;
            transf.transform( iter.start(), s_w, s_h );
            transf.transform( iter.end(), e_w, e_h );

            s << "newpath" << endl;
            s << s_w << ' ' << s_h << " moveto" << endl;

            if( !iter.mid() )
            {
                s << e_w << ' ' << e_h << " lineto" << endl;
            }
            else
            {
                write_eps_quadratic_edge( s, transf, iter.start(), *iter.mid(), iter.end() );
                // draw rings at mid-edge node location
                // transf.transform( *(iter.mid()), w1, h1 );
                // s << w1+2 << ' ' << h1 <<  " moveto"            << endl;
                // s << w1 << ' ' << h1 <<  " 2 0 360 arc"         << endl;
            }
            s << "stroke" << endl;

            iter.step( err );MSQ_ERRRTN( err );
        }

        // Write footer
        s << "%%Trailer" << endl;
        s << "cleartomark" << endl;
        s << "countdictstack" << endl;
        s << "exch sub { end } repeat" << endl;
        s << "restore" << endl;
        s << "%%EOF" << endl;
    }
static void MBMesquite::MeshWriter::write_eps_quadratic_edge ( ostream &  s,
Transform2D &  xform,
Vector3D  start,
Vector3D  mid,
Vector3D  end 
) [static]

Write quadratic edge shape in PostScript format.

Given the three points composing a quadratic mesh edge, write the cubic Bezier curve of the same shape in PostScript format. The formulas for P1 and P2 at the start of this function will result in the cubic terms of the Bezier curve dropping out, leaving the quadratic curve matching the edge shape function as described in Section 3.6 of Hughes. (If you're attempting to verify this, don't forget to adjust for the different parameter ranges: \( \xi = 2 t - 1 \)).

Definition at line 691 of file MeshWriter.cpp.

References MBMesquite::MeshWriter::Transform2D::transform().

Referenced by write_eps(), and write_eps_triangle().

    {
        Vector3D P1 = 1. / 3 * ( 4 * mid - end );
        Vector3D P2 = 1. / 3 * ( 4 * mid - start );

        int x, y;
        xform.transform( start, x, y );
        s << x << ' ' << y << " moveto" << endl;
        xform.transform( P1, x, y );
        s << x << ' ' << y << ' ';
        xform.transform( P2, x, y );
        s << x << ' ' << y << ' ';
        xform.transform( end, x, y );
        s << x << ' ' << y << " curveto" << endl;
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_eps_triangle ( Mesh *  mesh,
Mesh::ElementHandle  elem,
const char *  filename,
bool  draw_iso_lines,
bool  draw_nodes,
MsqError &  err,
int  width,
int  height 
)

Write EPS file containing single triangle in XY plane.

Definition at line 823 of file MeshWriter.cpp.

References MBMesquite::arrptr(), MBMesquite::Mesh::elements_get_attached_vertices(), MBMesquite::Mesh::elements_get_topologies(), filename, fixed, MSQ_ERRRTN, MSQ_SETERR, MBMesquite::TRIANGLE, MBMesquite::MsqError::UNSUPPORTED_ELEMENT, MBMesquite::Mesh::vertices_get_coordinates(), MBMesquite::Mesh::vertices_get_fixed_flag(), and MBMesquite::width().

    {
        // Get triangle vertices
        MsqVertex coords[6];
        EntityTopology type;
        mesh->elements_get_topologies( &elem, &type, 1, err );MSQ_ERRRTN( err );
        if( type != TRIANGLE )
        {
            MSQ_SETERR( err )( "Invalid element type", MsqError::UNSUPPORTED_ELEMENT );
            return;
        }
        std::vector< Mesh::VertexHandle > verts;
        std::vector< size_t > junk;
        mesh->elements_get_attached_vertices( &elem, 1, verts, junk, err );MSQ_ERRRTN( err );
        if( verts.size() != 3 && verts.size() != 6 )
        {
            MSQ_SETERR( err )( "Invalid element type", MsqError::UNSUPPORTED_ELEMENT );
            return;
        }
        mesh->vertices_get_coordinates( arrptr( verts ), coords, verts.size(), err );MSQ_ERRRTN( err );

        Vector3D coords2[6];
        std::copy( coords, coords + verts.size(), coords2 );

        std::vector< bool > fixed( verts.size(), false );
        if( draw_nodes )
        {
            mesh->vertices_get_fixed_flag( arrptr( verts ), fixed, verts.size(), err );MSQ_ERRRTN( err );
        }
        write_eps_triangle( coords2, verts.size(), filename, draw_iso_lines, draw_nodes, err, fixed, width, height );
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_eps_triangle ( const Vector3D *  coords,
size_t  num_vtx,
const char *  filename,
bool  draw_iso_lines,
bool  draw_nodes,
MsqError &  err,
const std::vector< bool > &  fixed,
int  width,
int  height 
)

Definition at line 862 of file MeshWriter.cpp.

References MBMesquite::MsqError::FILE_ACCESS, MBMesquite::MeshWriter::Transform2D::max_horizontal(), MBMesquite::MeshWriter::Transform2D::max_vertical(), MSQ_SETERR, quad_tri_pt(), moab::R, t, T, MBMesquite::MeshWriter::Transform2D::transform(), write_eps_quadratic_edge(), X, and Y.

    {
        const int PT_RAD        = 3;           // radius of circles for drawing nodes, in points
        const int PAD           = PT_RAD + 2;  // margin in points
        const double EDGE_GRAY  = 0.0;         // color for triangle edges, 0.0 => black
        const double ISO_GRAY   = 0.7;         // color for parameter iso-lines
        const double NODE_GRAY  = 0.0;         // color for node circle
        const double FIXED_GRAY = 1.0;         // color to fill fixed nodes with, 1.0 => white
        const double FREE_GRAY  = 0.0;         // color to fill free nodes with

        Projection proj( X, Y );
        Transform2D transf( coords, num_vtx, proj, width, height );

        // Open the file
        ofstream str( filename );
        if( !str )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // Write header
        str << "%!PS-Adobe-2.0 EPSF-2.0" << endl;
        str << "%%Creator: Mesquite" << endl;
        str << "%%Title: Mesquite " << endl;
        str << "%%DocumentData: Clean7Bit" << endl;
        str << "%%Origin: 0 0" << endl;
        str << "%%BoundingBox: " << -PAD << ' ' << -PAD << ' ' << transf.max_horizontal() + PAD << ' '
            << transf.max_vertical() + PAD << endl;
        str << "%%Pages: 1" << endl;

        str << "%%BeginProlog" << endl;
        str << "save" << endl;
        str << "countdictstack" << endl;
        str << "mark" << endl;
        str << "newpath" << endl;
        str << "/showpage {} def" << endl;
        str << "/setpagedevice {pop} def" << endl;
        str << "%%EndProlog" << endl;

        str << "%%Page: 1 1" << endl;
        str << "1 setlinewidth" << endl;
        str << EDGE_GRAY << " setgray" << endl;

        const double h = 0.5, t = 1.0 / 3.0, w = 2.0 / 3.0, s = 1. / 6, f = 5. / 6;
        const int NUM_ISO                      = 15;
        const double iso_params[NUM_ISO][2][2] = {
            { { h, 0 }, { h, h } },  // r = 1/2
            { { t, 0 }, { t, w } },  // r = 1/3
            { { w, 0 }, { w, t } },  // r = 2/3
            { { s, 0 }, { s, f } },  // r = 1/6
            { { f, 0 }, { f, s } },  // r = 5/6
            { { 0, h }, { h, h } },  // s = 1/2
            { { 0, t }, { w, t } },  // s = 1/3
            { { 0, w }, { t, w } },  // s = 2/3
            { { 0, s }, { f, s } },  // s = 1/6
            { { 0, f }, { s, f } },  // s = 5/6
            { { 0, h }, { h, 0 } },  // t = 1 - r - s = 1/2
            { { 0, w }, { w, 0 } },  // t = 1 - r - s = 1/3
            { { 0, t }, { t, 0 } },  // t = 1 - r - s = 2/3
            { { 0, f }, { f, 0 } },  // t = 1 - r - s = 1/6
            { { 0, s }, { s, 0 } }   // t = 1 - r - s = 5/6
        };

        if( num_vtx == 3 )
        {
            int x[3], y[3];
            for( size_t i = 0; i < 3; ++i )
                transf.transform( coords[i], x[i], y[i] );

            str << "newpath" << endl;
            str << x[0] << ' ' << y[0] << " moveto" << endl;
            str << x[1] << ' ' << y[1] << " lineto" << endl;
            str << x[2] << ' ' << y[2] << " lineto" << endl;
            str << x[0] << ' ' << y[0] << " lineto" << endl;
            str << "stroke" << endl;

            if( draw_iso_lines )
            {
                str << ISO_GRAY << " setgray" << endl;
                str << "newpath" << endl;
                for( int i = 0; i < NUM_ISO; ++i )
                {
                    double R[2]   = { iso_params[i][0][0], iso_params[i][1][0] };
                    double S[2]   = { iso_params[i][0][1], iso_params[i][1][1] };
                    double T[2]   = { 1 - R[0] - S[0], 1 - R[1] - S[1] };
                    Vector3D p[2] = { T[0] * coords[0] + R[0] * coords[1] + S[0] * coords[2],
                                      T[1] * coords[0] + R[1] * coords[1] + S[1] * coords[2] };
                    transf.transform( p[0], x[0], y[0] );
                    transf.transform( p[1], x[1], y[1] );
                    str << x[0] << ' ' << y[0] << " moveto" << endl;
                    str << x[1] << ' ' << y[1] << " lineto" << endl;
                }
                str << "    stroke" << endl;
            }
        }
        else if( num_vtx == 6 )
        {
            str << "newpath" << endl;
            write_eps_quadratic_edge( str, transf, coords[0], coords[3], coords[1] );
            write_eps_quadratic_edge( str, transf, coords[1], coords[4], coords[2] );
            write_eps_quadratic_edge( str, transf, coords[2], coords[5], coords[0] );
            str << "stroke" << endl;

            if( draw_iso_lines )
            {
                str << ISO_GRAY << " setgray" << endl;
                str << "newpath" << endl;
                for( int i = 0; i < NUM_ISO; ++i )
                {
                    double R[3]   = { iso_params[i][0][0], 0, iso_params[i][1][0] };
                    double S[3]   = { iso_params[i][0][1], 0, iso_params[i][1][1] };
                    R[1]          = 0.5 * ( R[0] + R[2] );
                    S[1]          = 0.5 * ( S[0] + S[2] );
                    Vector3D p[3] = { quad_tri_pt( R[0], S[0], coords ), quad_tri_pt( R[1], S[1], coords ),
                                      quad_tri_pt( R[2], S[2], coords ) };
                    write_eps_quadratic_edge( str, transf, p[0], p[1], p[2] );
                }
                str << "    stroke" << endl;
            }
        }

        if( draw_nodes )
        {
            for( size_t i = 0; i < num_vtx; ++i )
            {
                int iw, ih;
                // fill interior with either white or black depending
                // on whether or not the vertex is fixed.
                if( fixed[i] )
                    str << FIXED_GRAY << " setgray" << endl;
                else
                    str << FREE_GRAY << " setgray" << endl;
                transf.transform( coords[i], iw, ih );
                str << w + PT_RAD << ' ' << ih << " moveto" << endl;
                str << iw << ' ' << ih << ' ' << PT_RAD << " 0 360 arc" << endl;
                str << "closepath fill" << endl;
                str << NODE_GRAY << " setgray" << endl;
                str << "newpath" << endl;
                str << iw << ' ' << ih << ' ' << PT_RAD << " 0 360 arc" << endl;
                str << "stroke" << endl;
            }
        }

        // Write footer
        str << "%%Trailer" << endl;
        str << "cleartomark" << endl;
        str << "countdictstack" << endl;
        str << "exch sub { end } repeat" << endl;
        str << "restore" << endl;
        str << "%%EOF" << endl;
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_gnuplot ( Mesh *  mesh,
const char *  filename,
MsqError &  err 
)

Write mesh as gnuplot data.

Write a file that can be drawn in gnuplot with the command: "plot 'filename' with lines"

Definition at line 200 of file MeshWriter.cpp.

References MBMesquite::PatchData::fill_global_patch(), MSQ_ERRRTN, MBMesquite::PatchData::set_mesh(), and write_gnuplot().

Referenced by run().

    {
        // loads a global patch
        PatchData pd;
        pd.set_mesh( mesh );
        pd.fill_global_patch( err );MSQ_ERRRTN( err );
        write_gnuplot( pd, out_filebase, err );
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_gnuplot ( Mesh *  mesh,
std::vector< Mesh::ElementHandle > &  elems,
const char *  out_filebase,
MsqError &  err 
)

Definition at line 209 of file MeshWriter.cpp.

References MSQ_ERRRTN, MBMesquite::PatchData::set_mesh(), MBMesquite::PatchData::set_mesh_entities(), and write_gnuplot().

    {
        // loads a global patch
        PatchData pd;
        pd.set_mesh( mesh );
        std::vector< Mesh::VertexHandle > verts;
        pd.set_mesh_entities( elems, verts, err );MSQ_ERRRTN( err );
        write_gnuplot( pd, out_filebase, err );
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_gnuplot ( PatchData &  pd,
const char *  out_filebase,
MsqError &  err 
)

Definition at line 233 of file MeshWriter.cpp.

References edges, MBMesquite::EdgeIterator::end(), MBMesquite::EdgeIterator::is_at_end(), MBMesquite::EdgeIterator::mid(), MSQ_ERRRTN, MSQ_SETERR, MBMesquite::EdgeIterator::start(), and MBMesquite::EdgeIterator::step().

    {
        // Open the file
        std::string out_filename = out_filebase;
        out_filename += ".gpt";
        std::ofstream file( out_filename.c_str() );
        if( !file )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        EdgeIterator edges( &pd, err );MSQ_ERRRTN( err );

        // Write a header
        file << "\n";

        while( !edges.is_at_end() )
        {
            const Vector3D& s = edges.start();
            const Vector3D& e = edges.end();
            const Vector3D* m = edges.mid();

            file << s[0] << ' ' << s[1] << ' ' << s[2] << std::endl;
            if( m ) file << ( *m )[0] << ' ' << ( *m )[1] << ' ' << ( *m )[2] << std::endl;
            file << e[0] << ' ' << e[1] << ' ' << e[2] << std::endl;
            file << std::endl << std::endl;

            edges.step( err );MSQ_ERRRTN( err );
        }

        // Close the file
        file.close();
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_gnuplot_animator ( int  count,
const char *  basename,
MsqError &  err 
)

Write animator for sequence of gnuplot data files.

Write a GNU Plot script to produce an animation from a sequence of data files

Given a set of files named foo.0.gpt, foo.1.gpt, ... foo.n.gpt, write a file foo.gnuplot that produces an animation of the data by calling write_gnuplot_animator( n, foo, err );

Definition at line 307 of file MeshWriter.cpp.

References find_gnuplot_agregate_range(), HEIGHT, MSQ_ERRRTN, MSQ_SETERR, and WIDTH.

    {
        if( count <= 0 ) return;

        const int DELAY  = 10;
        const int WIDTH  = 640;
        const int HEIGHT = 480;

        // read all input files to determine extents
        Vector3D min, max;
        find_gnuplot_agregate_range( count, basename, min, max, err );MSQ_ERRRTN( err );

        // chose coordinate plane to plot in
        Vector3D range = max - min;
        int haxis = 0, vaxis = 1;
        if( range[0] < range[1] && range[1] < range[2] )
        {
            haxis = 1;
            vaxis = 2;
        }
        else if( range[1] < range[2] )
        {
            vaxis = 2;
        }

        // open output file
        string base( basename );
        ofstream file( ( string( basename ) + ".gnuplot" ).c_str() );
        if( !file )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // write header
        file << "#!gnuplot" << endl;
        file << "#" << endl;
        file << "# Mesquite Animation of " << basename << ".0 to " << basename << '.' << count << endl;
        file << "#" << endl;

        // write plot settings
        file << "set term gif animate transparent opt delay " << DELAY << " size " << WIDTH << "," << HEIGHT << endl;
        file << "set xrange [" << min[haxis] - 0.05 * range[haxis] << ":" << max[haxis] + 0.05 * range[haxis] << "]"
             << endl;
        file << "set yrange [" << min[vaxis] - 0.05 * range[vaxis] << ":" << max[vaxis] + 0.05 * range[vaxis] << "]"
             << endl;
        file << "set title '" << basename << "'" << endl;
        file << "set output '" << basename << ".gif'" << endl;

        // plot data
        for( int i = 0; i <= count; ++i )
            file << "plot '" << basename << '.' << i << ".gpt'"
                 << " using " << haxis + 1 << ":" << vaxis + 1 << " w l" << endl;
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_gnuplot_overlay ( int  count,
const char *  basename,
MsqError &  err 
)

Write GNU plot commands to overlay a set of mesh timesteps in a single plot.

Write a GNU Plot script to produce a single plot from a sequence of data files

Given a set of files named foo.0.gpt, foo.1.gpt, ... foo.n.gpt, write a file foo.gnuplot that produces an overlay of the meshes in each file by calling write_gnuplot_animator( n, foo, err );

Definition at line 395 of file MeshWriter.cpp.

References blue(), find_gnuplot_agregate_range(), green(), HEIGHT, MSQ_ERRRTN, MSQ_SETERR, red(), and WIDTH.

Referenced by MBMesquite::TerminationCriterion::terminate().

    {
        if( count <= 0 ) return;

        const int WIDTH  = 640;
        const int HEIGHT = 480;

        // read all input files to determine extents
        Vector3D min, max;
        find_gnuplot_agregate_range( count, basename, min, max, err );MSQ_ERRRTN( err );

        // chose coordinate plane to plot in
        Vector3D range = max - min;
        int haxis = 0, vaxis = 1;
        if( range[0] < range[1] && range[1] < range[2] )
        {
            haxis = 1;
            vaxis = 2;
        }
        else if( range[1] < range[2] )
        {
            vaxis = 2;
        }

        // open output file
        string base( basename );
        FILE* file = fopen( ( string( basename ) + ".gnuplot" ).c_str(), "w" );
        if( !file )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // write header
        fprintf( file, "#!gnuplot\n" );
        fprintf( file, "#\n" );
        fprintf( file, "# Mesquite Overlay of %s.0 to %s.%d\n", basename, basename, count );
        fprintf( file, "#\n" );

        // write plot settings
        fprintf( file, "set term gif size %d,%d\n", WIDTH, HEIGHT );
        fprintf( file, "set xrange [%f:%f]\n", min[haxis] - 0.05 * range[haxis], max[haxis] + 0.05 * range[haxis] );
        fprintf( file, "set yrange [%f:%f]\n", min[vaxis] - 0.05 * range[vaxis], max[vaxis] + 0.05 * range[vaxis] );
        fprintf( file, "set title '%s'\n", basename );
        fprintf( file, "set output '%s.gif'\n", basename );

        // plot data
        fprintf( file, "plot '%s.0.gpt' using %d:%d w l lc rgb '#%02x%02x%02x' title 't0'", basename, haxis + 1,
                 vaxis + 1, red( 0, count ), green( 0, count ), blue( 0, count ) );
        for( int i = 1; i <= count; ++i )
        {
            fprintf( file, ", \\\n     '%s.%d.gpt' using %d:%d w l lc rgb '#%02x%02x%02x' title 't%d'", basename, i,
                     haxis + 1, vaxis + 1, red( i, count ), green( i, count ), blue( i, count ), i );
        }
        fprintf( file, "\n" );

        fclose( file );
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_stl ( Mesh *  mesh,
const char *  filename,
MsqError &  err 
)

Write STL.

Write the mesh as an ASCII STL (Stereo Lithography) file. The STL format only supports writing triangles. This writer will write only the triangles contained in the passed mesh. Any non-triangle elements will be ignored.

Definition at line 454 of file MeshWriter.cpp.

References MBMesquite::arrptr(), MBMesquite::Mesh::elements_get_attached_vertices(), MBMesquite::Mesh::elements_get_topologies(), MBMesquite::Mesh::get_all_elements(), MSQ_ERRRTN, MSQ_SETERR, n, MBMesquite::Vector3D::normalize(), MBMesquite::TRIANGLE, MBMesquite::Mesh::vertices_get_coordinates(), MBMesquite::Vector3D::x(), MBMesquite::Vector3D::y(), and MBMesquite::Vector3D::z().

    {
        // Open the file
        ofstream file( filename );
        if( !file )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // Write header
        char header[70];
        sprintf( header, "Mesquite%d", rand() );
        file << "solid " << header << endl;

        MsqVertex coords[3];
        std::vector< Mesh::VertexHandle > verts( 3 );
        std::vector< size_t > offsets( 2 );

        // Iterate over all elements
        size_t count = 0;
        std::vector< Mesh::ElementHandle > elems;
        std::vector< Mesh::ElementHandle >::iterator iter;
        mesh->get_all_elements( elems, err );MSQ_ERRRTN( err );
        for( iter = elems.begin(); iter != elems.end(); ++iter )
        {
            // Skip non-triangles
            Mesh::ElementHandle elem = *iter;
            EntityTopology type;
            mesh->elements_get_topologies( &elem, &type, 1, err );MSQ_ERRRTN( err );
            if( type != TRIANGLE ) continue;
            ++count;

            // Get vertex coordinates
            mesh->elements_get_attached_vertices( &elem, 1, verts, offsets, err );MSQ_ERRRTN( err );
            mesh->vertices_get_coordinates( arrptr( verts ), coords, 3, err );MSQ_ERRRTN( err );

            // Get triagnle normal
            Vector3D n = ( coords[0] - coords[1] ) * ( coords[0] - coords[2] );
            n.normalize();

            // Write triangle
            file << "facet normal " << n.x() << " " << n.y() << " " << n.z() << endl;
            file << "outer loop" << endl;
            for( unsigned i = 0; i < 3; ++i )
                file << "vertex " << coords[i].x() << " " << coords[i].y() << " " << coords[i].z() << endl;
            file << "endloop" << endl;
            file << "endfacet" << endl;
        }

        file << "endsolid " << header << endl;

        file.close();
        if( count == 0 )
        {
            std::remove( filename );
            MSQ_SETERR( err )( "Mesh contains no triangles", MsqError::INVALID_STATE );
        }
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_svg ( Mesh *  mesh,
const char *  filename,
Projection  proj,
MsqError &  err 
)

Write an SVG file.

Write a 2-D projection of the mesh to a Scalable Vector Graphics file. (W3C standard).

Parameters:
proj- SVG is a 2-D drawing format. This argument specifies which 2-D projection of the 3-D mesh to write.

Definition at line 1023 of file MeshWriter.cpp.

References MBMesquite::EdgeIterator::end(), MBMesquite::MsqError::FILE_ACCESS, MBMesquite::PatchData::fill_global_patch(), MBMesquite::EdgeIterator::is_at_end(), MBMesquite::MeshWriter::Transform2D::max_horizontal(), MBMesquite::MeshWriter::Transform2D::max_vertical(), MSQ_ERRRTN, MSQ_SETERR, MBMesquite::PatchData::set_mesh(), MBMesquite::EdgeIterator::start(), MBMesquite::EdgeIterator::step(), and MBMesquite::MeshWriter::Transform2D::transform().

    {
        // Get a global patch
        PatchData pd;
        pd.set_mesh( mesh );
        pd.fill_global_patch( err );MSQ_ERRRTN( err );

        Transform2D transf( &pd, proj, 400, 400, true );

        // Open the file
        ofstream file( filename );
        if( !file )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // Write header
        file << "<?xml version=\"1.0\" standalone=\"no\"?>" << endl;
        file << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
             << "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << endl;
        file << endl;
        file << "<svg width=\"" << transf.max_horizontal() << "\" height=\"" << transf.max_vertical()
             << "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">" << endl;

        // Write mesh edges
        EdgeIterator iter( &pd, err );MSQ_ERRRTN( err );
        while( !iter.is_at_end() )
        {
            int s_w, s_h, e_w, e_h;
            transf.transform( iter.start(), s_w, s_h );
            transf.transform( iter.end(), e_w, e_h );

            file << "<line "
                 << "x1=\"" << s_w << "\" "
                 << "y1=\"" << s_h << "\" "
                 << "x2=\"" << e_w << "\" "
                 << "y2=\"" << e_h << "\" "
                 << " style=\"stroke:rgb(99,99,99);stroke-width:2\""
                 << "/>" << endl;

            iter.step( err );MSQ_ERRRTN( err );
        }

        // Write footer
        file << "</svg>" << endl;
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_vtk ( Mesh *  mesh,
const char *  filename,
MsqError &  err 
)

Write mesh as a VTK file.

Write a simple VTK file for viewing. The file written by this function is intended for viewing. It contains only a minimal decription of the mesh. It does not contain other data such as tags/attributes. If the Mesh is a MeshImpl, use the VTK writing function provided in MeshImpl for a complete mesh export.

Definition at line 94 of file MeshWriter.cpp.

References MBMesquite::PatchData::fill_global_patch(), MSQ_CHKERR, MSQ_ERRRTN, MBMesquite::PatchData::set_mesh(), and write_vtk.

Referenced by main(), run(), run_global_smoother(), and run_local_smoother().

    {
        if( MeshImpl* msq_mesh = dynamic_cast< MeshImpl* >( mesh ) )
        {
            msq_mesh->write_vtk( out_filename, err );MSQ_CHKERR( err );
            return;
        }

        // loads a global patch
        PatchData pd;
        pd.set_mesh( mesh );
        pd.fill_global_patch( err );MSQ_ERRRTN( err );

        // write mesh
        write_vtk( pd, out_filename, err );MSQ_CHKERR( err );
    }
MESQUITE_EXPORT void MBMesquite::MeshWriter::write_vtk ( PatchData &  pd,
const char *  out_filename,
MsqError &  err,
const Vector3D *  OF_gradient 
)

Definition at line 111 of file MeshWriter.cpp.

References MBMesquite::PatchData::element_by_index(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::MsqVertex::get_flags(), MBMesquite::MsqMeshEntity::get_node_indices(), MBMesquite::MsqVertex::is_free_vertex(), MBMesquite::VtkTypeInfo::mesquiteToVtkOrder(), MSQ_ERRRTN, MSQ_SETERR, MBMesquite::MsqMeshEntity::node_count(), MBMesquite::PatchData::num_elements(), MBMesquite::PatchData::num_free_vertices(), MBMesquite::PatchData::num_nodes(), MBMesquite::PatchData::vertex_by_index(), MBMesquite::VtkTypeInfo::vtkType, MBMesquite::Vector3D::y(), and MBMesquite::Vector3D::z().

    {
        // Open the file
        std::ofstream file( out_filename );
        if( !file )
        {
            MSQ_SETERR( err )( MsqError::FILE_ACCESS );
            return;
        }

        // Write a header
        file << "# vtk DataFile Version 2.0\n";
        file << "Mesquite Mesh " << out_filename << " .\n";
        file << "ASCII\n";
        file << "DATASET UNSTRUCTURED_GRID\n";

        // Write vertex coordinates
        file << "POINTS " << pd.num_nodes() << " float\n";
        size_t i;
        for( i = 0; i < pd.num_nodes(); i++ )
        {
            file << pd.vertex_by_index( i )[0] << ' ' << pd.vertex_by_index( i )[1] << ' ' << pd.vertex_by_index( i )[2]
                 << '\n';
        }

        // Write out the connectivity table
        size_t connectivity_size = 0;
        for( i = 0; i < pd.num_elements(); ++i )
            connectivity_size += pd.element_by_index( i ).node_count() + 1;

        file << "CELLS " << pd.num_elements() << ' ' << connectivity_size << '\n';
        for( i = 0; i < pd.num_elements(); i++ )
        {
            std::vector< size_t > vtx_indices;
            pd.element_by_index( i ).get_node_indices( vtx_indices );

            // Convert native to VTK node order, if not the same
            const VtkTypeInfo* info =
                VtkTypeInfo::find_type( pd.element_by_index( i ).get_element_type(), vtx_indices.size(), err );MSQ_ERRRTN( err );
            info->mesquiteToVtkOrder( vtx_indices );

            file << vtx_indices.size();
            for( std::size_t j = 0; j < vtx_indices.size(); ++j )
            {
                file << ' ' << vtx_indices[j];
            }
            file << '\n';
        }

        // Write out the element types
        file << "CELL_TYPES " << pd.num_elements() << '\n';
        for( i = 0; i < pd.num_elements(); i++ )
        {
            const VtkTypeInfo* info = VtkTypeInfo::find_type( pd.element_by_index( i ).get_element_type(),
                                                              pd.element_by_index( i ).node_count(), err );MSQ_ERRRTN( err );
            file << info->vtkType << '\n';
        }

        // Write out which points are fixed.
        file << "POINT_DATA " << pd.num_nodes() << "\nSCALARS fixed int\nLOOKUP_TABLE default\n";
        for( i = 0; i < pd.num_nodes(); ++i )
        {
            if( pd.vertex_by_index( i ).get_flags() & MsqVertex::MSQ_CULLED )
                file << "1\n";
            else
                file << "0\n";
        }
        file << "SCALARS culled short\nLOOKUP_TABLE default\n";
        for( i = 0; i < pd.num_nodes(); ++i )
        {
            if( pd.vertex_by_index( i ).is_free_vertex() )
                file << "0\n";
            else
                file << "1\n";
        }

        if( OF_gradient )
        {
            file << "VECTORS gradient double\n";
            for( i = 0; i < pd.num_free_vertices(); ++i )
                file << OF_gradient[i].x() << " " << OF_gradient[i].y() << " " << OF_gradient[i].z() << "\n";
            for( i = pd.num_free_vertices(); i < pd.num_nodes(); ++i )
                file << "0.0 0.0 0.0\n";
        }

        // Close the file
        file.close();
    }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines