Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadTetGen.hpp
Go to the documentation of this file.
1 #ifndef READ_TET_GEN_HPP
2 #define READ_TET_GEN_HPP
3 
4 #include <iosfwd>
5 #include "moab/Forward.hpp"
6 #include "moab/ReaderIface.hpp"
7 #include <string>
8 
9 namespace moab
10 {
11 
12 class ReadUtilIface;
13 
14 /* TetGen mesh data is typically split into two or three files:
15  * name.node : node data
16  * name.ele : tet data
17  * name.face : tri data
18  * The reader will attempt to guess the correct file names from
19  * the single input file name unless explicit file names are
20  * specified using file options as described below.
21  *
22  * File options:
23  * NODE_FILE=filename : node file name
24  * ELE_FILE[=filename] : require tet file and optionally specify file name
25  * FACE_FILE[=filename] : reequire tri file and optionally specify file name
26  * EDGE_FILE[=filename] : reequire edge file and optionally specify file name
27  * NODE_ATTR_LIST=name[,name[,...]] : List of tag names in which to store
28  * attribute values. If the same name
29  * is repeated multiple times, multiple
30  * attribute values will be stored in the
31  * same tag as array values in the order
32  * they are read from the file. If a
33  * name is zero-length, the attribute data
34  * will be disgarded.
35  */
36 class ReadTetGen : public ReaderIface
37 {
38 
39  public:
40  static ReaderIface* factory( Interface* );
41 
42  //! load a file
43  ErrorCode load_file( const char* file_name,
44  const EntityHandle* file_set,
45  const FileOptions& opts,
46  const SubsetList* subset_list = 0,
47  const Tag* file_id_tag = 0 );
48 
49  ErrorCode read_tag_values( const char* file_name,
50  const char* tag_name,
51  const FileOptions& opts,
52  std::vector< int >& tag_values_out,
53  const SubsetList* subset_list = 0 );
54 
55  //! Constructor
56  ReadTetGen( Interface* impl = NULL );
57 
58  //! Destructor
59  virtual ~ReadTetGen();
60 
61  private:
64 
65  /**\brief Try to open one of several input files
66  *
67  *\param input_file_name The file name as passed in by the application
68  *\param input_name_base If the input file name ends with a known suffix,
69  * the portition of the input file without the suffix.
70  * Otherwise equal to input_file_name.
71  *\param input_file_suffix If the input file name ends with a known suffix,
72  * the suffix. Otherwise empty.
73  *\param file_type_suffix The suffix for the file type that is to be opened.
74  *\param file_name_option The FileOptions option name specifying the file
75  * name to open.
76  *\param opts Input options list.
77  *\param file_stream The stream to open for the file.
78  */
79  ErrorCode open_file( const std::string& input_file_name,
80  const std::string& input_name_base,
81  const std::string& input_name_suffix,
82  const char* file_type_suffix,
83  const char* file_name_option,
84  const FileOptions& opts,
85  std::ifstream& file_stream,
86  bool file_required = false );
87 
88  /**\brief Read a line from a file
89  *
90  * Read the next non-empty line. Strips comments.
91  *\param file The stream to read from
92  *\param line Output: the line read from the stream
93  *\param lineno Incremented for each real line read from the stream
94  * (including disgarded empty and comment lines.)
95  */
96  ErrorCode read_line( std::istream& file, std::string& line, int& lineno );
97 
98  /**\brief Read a line of double values from a file.
99  */
100  ErrorCode read_line( std::istream& file, double* values_out, int num_values, int& lineno );
101 
102  /**\brief Parse option string specifying mapping from
103  * attributes to tags.
104  *
105  * Given a file option string describing the mapping from tetgen
106  * attributes to MOAB tags, parse it and populate the passed vectors.
107  * \param option_str Input: The option string to parse.
108  * \param tag_list Output: A list tag handles, one for each attribute.
109  * Tag handle value will be zero if the attribute
110  * is to be interpreted as a group id.
111  * \param index_list Output: Which array index to store the attribute
112  * value at for a multi-valued tag. Zero for single-
113  * valued tags. -1 if the corresponding attribute value
114  * is to be interpreted as a group ID.
115  * \param group_designator Input: special tag name used to designate an
116  * attribute as the group (surface or volume) ID.
117  */
118  ErrorCode parse_attr_list( const std::string& option_str,
119  std::vector< Tag >& tag_list,
120  std::vector< int >& index_list,
121  const char* group_designator = 0 );
122 
123  ErrorCode read_node_file( std::istream& file,
124  const Tag* attr_tag_list,
125  const int* attr_tag_index,
126  int attr_tag_list_len,
127  std::vector< EntityHandle >& nodes );
128 
129  ErrorCode read_elem_file( EntityType type,
130  std::istream& file,
131  const std::vector< EntityHandle >& nodes,
132  Range& elems );
133 };
134 
135 } // namespace moab
136 
137 #endif // defined(READ_TET_GEN_HPP)