MOAB: Mesh Oriented datABase  (version 5.2.1)
ReadSTL.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 READ_STL_HPP
00017 #define READ_STL_HPP
00018 
00019 #include <stdio.h>
00020 #include "moab/Forward.hpp"
00021 #include "moab/ReaderIface.hpp"
00022 
00023 namespace moab
00024 {
00025 
00026 class ReadUtilIface;
00027 
00028 /**
00029  * \brief ASCII and Binary Stereo Lithography File readers.
00030  * \author Jason Kraftcheck
00031  *
00032  * STL files contain no connectivity infomration.  Each triangle
00033  * is specified as by three sets of single-precision coordinate
00034  * triples.  This reader does not use ANY tolerance when comparing
00035  * vertex locations to recover connectivity.  The points must be
00036  * EXACTLY equal (including the sign on zero values.)  If the file
00037  * was written by an application which represented connectivity
00038  * explicitly, there is no reason for the vertex coordinates to
00039  * be anything other than exactly equal.
00040  *
00041  * For binary STL files, the defacto standard is that they be written
00042  * with a little-endian byte order.  The reader will attempt to
00043  * determine the byte order automatically, and if it is ambiguous,
00044  * will default to little-endian.  The byte ordering may be forced by
00045  * by creating an integer tag named "__STL_BYTE_ORDER" and setting a
00046  * global/mesh value for the tag as 1 for big-endian or 0 for
00047  * little-endian.
00048  *
00049  * For binary files, this reader relies on the file size to determine
00050  * the validity of the file and may use it in guessing the byte order.
00051  * This should not be an issue, as the file size can be determined
00052  * exactly from the number of triangles for a valid file.  However, if
00053  * for some reason the file is readable even though it is invalid (e.g.
00054  * it is some hybrid file with STL data in the beginning and some app-
00055  * specific data appended to the end of the file) the check on the file
00056  * size can be disabled by giving the reader a something other than a
00057  * regular file to read from.  For example, on Unix-like systems, have
00058  * the reader read from a FIFO instead of a file:
00059  *   mkfifo /tmp/fifo.stlb
00060  *   cat my_binary_file.stlb > /tmp/fifo.stlb
00061  * and instruct the MOAB-based application to read from /tmp/fifo.stlb
00062  */
00063 class ReadSTL : public ReaderIface
00064 {
00065 
00066   public:
00067     //! factory method for STL reader
00068     static ReaderIface* factory( Interface* );
00069 
00070     //! Generic file loading code for both binary and ASCII readers.
00071     //! Calls reader-specific read_triangles function to do actual I/O.
00072     ErrorCode load_file( const char* file_name, const EntityHandle* file_set, const FileOptions& opts,
00073                          const SubsetList* subset_list = 0, const Tag* file_id_tag = 0 );
00074 
00075     ErrorCode read_tag_values( const char* file_name, const char* tag_name, const FileOptions& opts,
00076                                std::vector< int >& tag_values_out, const SubsetList* subset_list = 0 );
00077 
00078     //! Constructor
00079     ReadSTL( Interface* impl = NULL );
00080 
00081     //! Destructor
00082     virtual ~ReadSTL();
00083 
00084     // An object to hold vertex coordinates, and an operator
00085     // for storing them in a STL tree-based container.
00086     struct Point
00087     {
00088         float coords[3];
00089         bool operator<( const Point& ) const;
00090     };
00091     // Data returned by read_triangles.
00092     struct Triangle
00093     {
00094         Point points[3];
00095     };
00096 
00097     enum ByteOrder
00098     {
00099         STL_BIG_ENDIAN,
00100         STL_LITTLE_ENDIAN,
00101         STL_UNKNOWN_BYTE_ORDER
00102     };
00103 
00104   protected:
00105     // I/O specific part of reader - read ASCII file
00106     ErrorCode ascii_read_triangles( const char* file_name, std::vector< Triangle >& tris_out );
00107 
00108     // I/O specific part of reader - read binary file
00109     ErrorCode binary_read_triangles( const char* file_name, ByteOrder byte_order, std::vector< Triangle >& tris_out );
00110 
00111     ReadUtilIface* readMeshIface;
00112 
00113     //! interface instance
00114     Interface* mdbImpl;
00115 };
00116 
00117 }  // namespace moab
00118 
00119 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines