Flow123d  last_with_con_2.0.0-4-g42e6930
output_vtk.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file output_vtk.h
15  * @brief Header: The functions for VTK outputs.
16  */
17 
18 #ifndef OUTPUT_VTK_HH_
19 #define OUTPUT_VTK_HH_
20 
22 
23 #include "output_data_base.hh"
24 #include "output_time.hh"
25 
26 #include <ostream>
27 
28 using namespace std;
29 
30 /**
31  * \brief This class is used for output data to VTK file format
32  */
33 class OutputVTK : public OutputTime {
34 
35 public:
37 
38 
39  /**
40  * \brief The constructor of this class. The head of file is written, when
41  * constructor is called
42  */
43  OutputVTK();
44 
45  /**
46  * \brief The destructor of this class. It writes tail of the file too.
47  */
48  ~OutputVTK();
49 
50  /**
51  * \brief The definition of input record for vtk file format
52  */
53  static const Input::Type::Record & get_input_type();
54 
55  /**
56  * \brief The definition of input record for selection of variant of file format
57  */
58  static const Input::Type::Selection & get_input_type_variant();
59 
60  /**
61  * \brief The definition of input record for selection of compression type
62  */
63  static const Input::Type::Selection & get_input_type_compression();
64 
65  /**
66  * \brief This function write data to VTK (.pvd) file format
67  * for curent time
68  */
69  int write_data(void);
70 
71  /**
72  * \brief This function writes header of VTK (.pvd) file format
73  */
74  int write_head(void);
75 
76  /**
77  * \brief This function writes tail of VTK (.pvd) file format
78  */
79  int write_tail(void);
80 
81 protected:
82 
83  /**
84  * \brief The declaration enumeration used for variant of file VTK format
85  */
86  typedef enum Variant {
87  VARIANT_ASCII = 1,
88  VARIANT_BINARY = 2
89  } Variant;
90 
91  /**
92  * \brief The declaration of enumeration used for type of compression
93  * used in file format
94  */
95  typedef enum Compression {
96  COMPRESSION_NONE = 1,
97  COMPRESSION_GZIP = 2
98  } Compression;
99 
100  // VTK Element types
101  typedef enum {
102  VTK_VERTEX = 1,
103  VTK_POLY_VERTEX = 2,
104  VTK_LINE = 3,
105  VTK_POLY_LINE = 4,
106  VTK_TRIANGLE = 5,
107  VTK_TRIANGLE_STRIP = 6,
108  VTK_POLYGON = 7,
109  VTK_PIXEL = 8,
110  VTK_QUAD = 9,
111  VTK_TETRA = 10,
112  VTK_VOXEL = 11,
113  VTK_HEXAHEDRON = 12,
114  VTK_WEDGE = 13,
115  VTK_PYRAMID = 14,
116  VTK_QUADRIC_EDGE = 21,
117  VTK_QUADRIC_TRIANGLE = 22,
118  VTK_QUADRIC_QUAD = 23,
119  VTK_QUADRIC_TETRA = 24,
120  VTK_QUADRIC_HEXAHEDRON = 25
121  } VTKElemType;
122 
123  // VTK Element size (number of nodes)
124  typedef enum {
125  VTK_LINE_SIZE = 2,
126  VTK_TRIANGLE_SIZE = 3,
127  VTK_TETRA_SIZE = 4
128  } VTKElemSize;
129 
130  typedef enum { VTK_INT8, VTK_UINT8, VTK_INT16, VTK_UINT16, VTK_INT32, VTK_UINT32,
131  VTK_FLOAT32, VTK_FLOAT64
132  } VTKValueType;
133 
134  static const std::string vtk_value_type_map(VTKValueType t) {
135  static const std::vector<std::string> types = {
136  "Int8", "UInt8", "Int16", "UInt16", "Int32", "UInt32",
137  "Float32","Float64"};
138  return types[t];
139  };
140 
141  /// Registrar of class to factory
142  static const int registrar;
143 
144  /**
145  * \brief Write header of VTK file (.vtu)
146  */
147  void write_vtk_vtu_head(void);
148 
149  /**
150  * \brief Fills the given vector with VTK element types indicators.
151  */
152  void fill_element_types_vector(std::vector<unsigned int> &data);
153 
154  /**
155  * Write registered data to output stream using ascii format
156  */
157  void write_vtk_data_ascii(OutputDataFieldVec &output_data_map);
158 
159  /**
160  * Write registered data to output stream using ascii format
161  */
162  void write_vtk_data_ascii(OutputDataPtr output_data, VTKValueType type);
163 
164  /**
165  * \brief Write names of data sets in @p output_data vector that have value type equal to @p type.
166  * Output is done into stream @p file.
167  */
168  void write_vtk_data_names(ofstream &file,
169  OutputDataFieldVec &output_data_map);
170 
171  /**
172  * \brief Write data on nodes to the VTK file (.vtu)
173  */
174  void write_vtk_node_data(void);
175 
176  /**
177  * \brief Write data on elements to the VTK file (.vtu)
178  */
179  void write_vtk_element_data(void);
180 
181  /**
182  * \brief Write tail of VTK file (.vtu)
183  */
184  void write_vtk_vtu_tail(void);
185 
186  /**
187  * \brief This function write all scalar and vector data on nodes and elements
188  * to the VTK file (.vtu)
189  */
190  void write_vtk_vtu(void);
191 
192  /**
193  * Set appropriate file path substrings.
194  * Make subdirectory for VTU time frames.
195  */
196  void make_subdirectory();
197 
198 
199  /**
200  * Data output stream (could be same as base_file)
201  */
202  ofstream _data_file;
203 
204  /**
205  * Path to time frame VTU data subdirectory
206  */
207  string subdir_name_;
208 
210 
212 };
213 
214 #endif /* OUTPUT_VTK_HH_ */
string subdir_name_
Definition: output_vtk.hh:207
static const int registrar
Registrar of class to factory.
Definition: output_vtk.hh:139
string main_output_basename_
Definition: output_vtk.hh:209
string main_output_dir_
Definition: output_vtk.hh:211
OutputTime FactoryBaseType
Definition: output_vtk.hh:36
ofstream _data_file
Definition: output_vtk.hh:202
This class is used for output data to VTK file format.
Definition: output_vtk.hh:33
static const std::string vtk_value_type_map(VTKValueType t)
Definition: output_vtk.hh:134
The class for outputting data during time.
Definition: output_time.hh:48
Variant
The declaration enumeration used for variant of file VTK format.
Definition: output_vtk.hh:86
std::shared_ptr< OutputDataBase > OutputDataPtr
Definition: output_time.hh:191
Record type proxy class.
Definition: type_record.hh:171
Compression
The declaration of enumeration used for type of compression used in file format.
Definition: output_vtk.hh:95
Template for classes storing finite set of named values.