![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
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
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,
00057 const bool overwrite,
00058 const FileOptions& opts,
00059 const EntityHandle* output_list,
00060 const int num_sets,
00061 const std::vector< std::string >& qa_list,
00062 const Tag* tag_list = NULL,
00063 int num_tags = 0,
00064 int export_dimension = 3 );
00065
00066 protected:
00067 enum ByteOrder
00068 {
00069 STL_BIG_ENDIAN,
00070 STL_LITTLE_ENDIAN,
00071 STL_UNKNOWN_BYTE_ORDER
00072 };
00073
00074 //! Write list of triangles to an STL file.
00075 ErrorCode ascii_write_triangles( FILE* file, const char header[81], const Range& triangles, int precision );
00076 //! Write list of triangles to an STL file.
00077 ErrorCode binary_write_triangles( FILE* file, const char header[81], ByteOrder byte_order, const Range& triangles );
00078
00079 //! Given an array of vertex coordinates for a triangle,
00080 //! pass back individual point coordinates as floats and
00081 //! calculate triangle normal.
00082 ErrorCode get_triangle_data( const double vtx_coords[9], float v1[3], float v2[3], float v3[3], float n[3] );
00083
00084 ErrorCode get_triangle_data( const double vtx_coords[9], CartVect& v1, CartVect& v2, CartVect& v3, CartVect& n );
00085
00086 //! interface instance
00087 Interface* mbImpl;
00088 WriteUtilIface* mWriteIface;
00089
00090 private:
00091 //! Construct 80-byte, null-terminated description string from
00092 //! qa_list. Unused space in header will be null-char padded.
00093 ErrorCode make_header( char header[81], const std::vector< std::string >& qa_list );
00094
00095 //! Get triangles to write from input array of entity sets. If
00096 //! no sets, gets all triangles.
00097 ErrorCode get_triangles( const EntityHandle* set_array, int set_array_length, Range& triangles );
00098
00099 //! Open a file, respecting passed overwrite value and
00100 //! subclass-specified value for need_binary_io().
00101 FILE* open_file( const char* name, bool overwrite, bool binary );
00102 };
00103
00104 } // namespace moab
00105
00106 #endif