MOAB: Mesh Oriented datABase  (version 5.2.1)
WriteSTL.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain 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  */
00015 
00016 #ifndef WRITE_STL_HPP
00017 #define WRITE_STL_HPP
00018 
00019 #include "moab/CartVect.hpp"
00020 #include "moab/Forward.hpp"
00021 #include "moab/WriterIface.hpp"
00022 
00023 #include <stdio.h>
00024 
00025 namespace moab
00026 {
00027 
00028 class WriteUtilIface;
00029 
00030 /**
00031  * \brief ASCII and Binary Stereo Lithography File writers.
00032  * \author Jason Kraftcheck
00033  *
00034  * This writer will write only the MBTRI elements in the mesh.  It
00035  * will not decompose other 2-D elements into triangles, nor will
00036  * it skin the mesh or do any other high-level operation to generate
00037  * triangles from 3-D elements.
00038  *
00039  * Binary files will be written with a little-endian byte order by
00040  * default.  The byte order can be controlled with writer options.
00041  */
00042 class WriteSTL : public WriterIface
00043 {
00044 
00045   public:
00046     //! factory method forSTL writer
00047     static WriterIface* factory( Interface* );
00048 
00049     //! Constructor
00050     WriteSTL( Interface* impl );
00051 
00052     //! Destructor
00053     virtual ~WriteSTL();
00054 
00055     //! writes out a file
00056     ErrorCode write_file( const char* file_name, const bool overwrite, const FileOptions& opts,
00057                           const EntityHandle* output_list, const int num_sets,
00058                           const std::vector< std::string >& qa_list, const Tag* tag_list = NULL, int num_tags = 0,
00059                           int export_dimension = 3 );
00060 
00061   protected:
00062     enum ByteOrder
00063     {
00064         STL_BIG_ENDIAN,
00065         STL_LITTLE_ENDIAN,
00066         STL_UNKNOWN_BYTE_ORDER
00067     };
00068 
00069     //! Write list of triangles to an STL file.
00070     ErrorCode ascii_write_triangles( FILE* file, const char header[81], const Range& triangles, int precision );
00071     //! Write list of triangles to an STL file.
00072     ErrorCode binary_write_triangles( FILE* file, const char header[81], ByteOrder byte_order, const Range& triangles );
00073 
00074     //! Given an array of vertex coordinates for a triangle,
00075     //! pass back individual point coordinates as floats and
00076     //! calculate triangle normal.
00077     ErrorCode get_triangle_data( const double vtx_coords[9], float v1[3], float v2[3], float v3[3], float n[3] );
00078 
00079     ErrorCode get_triangle_data( const double vtx_coords[9], CartVect& v1, CartVect& v2, CartVect& v3, CartVect& n );
00080 
00081     //! interface instance
00082     Interface* mbImpl;
00083     WriteUtilIface* mWriteIface;
00084 
00085   private:
00086     //! Construct 80-byte, null-terminated description string from
00087     //! qa_list.  Unused space in header will be null-char padded.
00088     ErrorCode make_header( char header[81], const std::vector< std::string >& qa_list );
00089 
00090     //! Get triangles to write from input array of entity sets.  If
00091     //! no sets, gets all triangles.
00092     ErrorCode get_triangles( const EntityHandle* set_array, int set_array_length, Range& triangles );
00093 
00094     //! Open a file, respecting passed overwrite value and
00095     //! subclass-specified value for need_binary_io().
00096     FILE* open_file( const char* name, bool overwrite, bool binary );
00097 };
00098 
00099 }  // namespace moab
00100 
00101 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines