Loading...
Searching...
No Matches
DGF.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25// ========================================================================== //
26// DGF IO FUNCTIONS //
27// //
28// I/O functions for .dgf file formats //
29// ========================================================================== //
30// INTFO //
31// ========================================================================== //
32// Author : Alessandro Alaia //
33// Version : v3.0 //
34// //
35// All rights reserved. //
36// ========================================================================== //
37# ifndef __BITPIT_DGF_HPP__
38# define __BITPIT_DGF_HPP__
39
40// ========================================================================== //
41// INCLUDES //
42// ========================================================================== //
43
44// Standard Template Library
45# include <vector>
46# include <string>
47# include <fstream>
48# include <sstream>
49# include <cstdarg>
50# include <iostream>
51
52// Classes
53// none
54
55// bitpit
56# include "bitpit_common.hpp"
57# include "Operators.hpp"
58
59namespace bitpit{
60
61// ========================================================================== //
62// DATA STRUCTURES AND CLASSES //
63// ========================================================================== //
69struct DGFData {
70 int nV;
71 int nS;
72 std::vector<int> nV_data;
73 std::vector<std::string> sV_data;
74 std::vector<int> nS_data;
75 std::vector<std::string> sS_data;
76};
77
78class DGFObj {
79
80 // Members ============================================================== //
81
82 // Public members ------------------------------------------------------- //
83 public:
84 std::string dgf_name;
85 unsigned int err;
88 // Private members ------------------------------------------------------ //
89 private:
90 std::ifstream ifile_handle;
91 std::ofstream ofile_handle;
92 std::vector<std::vector<int> > dgf_error;
94 // Constructor ========================================================== //
95 public:
96 DGFObj( // Standard constructor for DGF object
97 void // (input) none
98 );
99 DGFObj( // Custom constructor #1 for DGF object
100 const std::string & // (input) dgf file name
101 );
102
103 // Destructor =========================================================== //
104 public:
105 // none
106
107 // Methods ============================================================== //
108
109 // Public methods ------------------------------------------------------- //
110 public:
111 void open( // Open input/output stream to dgf file
112 const std::string & // (input) stream mode
113 );
114 void close( // Close input/output stream to dgf file
115 const std::string &a = "inout" // (input) stream mode
116 );
117 void clear( // Reser members to default value
118 void // (input) none
119 );
120 void display( // Display dgf info
121 std::ostream & // (input) output stream
122 );
123 void scan( // Scan dgf file for infos
124 void // (input) none
125 );
126 void check( // Check data structure in .dgf file
127 void // (input) none
128 );
129 void load( // Load mesh data from .dgf file
130 int &, // (input/output) number of mesh vertices
131 int &, // (input/output) number of mesh facets
132 std::vector<std::vector<double> > &, // (input/output) vertex coordinate list
133 std::vector<std::vector<int> > & // (input/output) simplex-vertex connectivity
134 );
135 void load( // Load mesh data from .dgf file
136 int &, // (input/output) number of mesh vertices
137 int &, // (input/output) number of mesh facets
138 std::vector<std::array<double,3> > &, // (input/output) vertex coordinate list
139 std::vector<std::vector<int> > & // (input/output) simplex-vertex connectivity
140 );
141 void load( // Load mesh data from .dgf file
142 int &, // (input/output) number of mesh vertices
143 int &, // (input/output) number of mesh facets
144 std::vector<std::array<double,3> > &, // (input/output) vertex coordinate list
145 std::vector<std::vector<int> > &, // (input/output) simplex-vertex connectivity
146 std::vector<int> &, // (input/output) pid list
147 const std::string &pidName = "PID" // name of simplexdata to be used as PID
148 );
149 void save( // Save mesh data into a .dgf file
150 int &, // (input) number of mesh vertices
151 int &, // (input) number of mesh facets
152 std::vector<std::vector<double> > &, // (input) vertex coordinate list
153 std::vector<std::vector<int> > & // (input) simplex-vertex connectivity
154 );
155 void save( // Save mesh data into a .dgf file
156 int &, // (input) number of mesh vertices
157 int &, // (input) number of mesh facets
158 std::vector<std::array<double,3> > &, // (input) vertex coordinate list
159 std::vector<std::vector<int> > & // (input) simplex-vertex connectivity
160 );
161
162 template< typename T, typename ... T2 >
163 void loadVData( // Load vertex data sets from dgf file
164 const std::string &data_name, // (input) dataset name
165 int &n, // (input/output) number of data in the dataset
166 std::vector< T > &data, // (input/output) loaded dataset
167 T2 &... others // (input/optional) others datasets to be loaded
168 );
169 template< typename T, typename ... T2 >
170 void loadSData( // Load simplex data sets from dgf file
171 const std::string &data_name, // (input) dataset name
172 int &n, // (input/output) number of data in the dataset
173 std::vector< T > &data, // (input/output) loaded dataset
174 T2 &... others // (input/optional) others datasets to be loaded
175 );
176 template < typename T, typename ... T2 >
177 void appendVData( // Append vertex data set to dgf file
178 const std::string &data_name, // (input) dataset name
179 int &n, // (input) number of data in the dataset
180 std::vector< T > &data, // (input) dataset to be exported
181 T2 &... others // (input/optional) others datasets to be exported
182 );
183 template < typename T, typename ... T2 >
184 void appendSData( // Append simplex data set to dgf file
185 const std::string &data_name, // (input) dataset name
186 int &n, // (input) number of data in the dataset
187 std::vector< T > &data, // (input) dataset to be exported
188 T2 &... others // (input/optional) others datasets to be exported
189 );
190
191 // Private methods ------------------------------------------------------ //
192 private:
193 void loadVData( // Dummy function for recursive variadic-template "load_vdata"
194 void // (input) none
195 );
196 void loadSData( // Dummy function for recursive variadic-template "load_sdata"
197 void // (input) none
198 );
199 void appendVData( // Dummy function for recursive variadic template "append_vdata"
200 void // (input) none
201 );
202 void appendSData( // Dummy function for recursive variadic template "append_sdata"
203 void // (input) none
204 );
205
206};
207
212namespace dgf{
213
214// Scanning routines -------------------------------------------------------- //
215unsigned int scanData( // Scan DGF data and returns info
216 std::ifstream &, // (input) input stream to dgf file
217 int & // (input/output) number of data in the dataset
218);
219unsigned int scan( // Scan DGF file and returns infos
220 std::ifstream &, // (input) input stream to dgf file
221 int &, // (input/output) number of mesh vertices
222 int &, // (input/output) number of simplicies
223 std::vector<std::string> &, // (input/output) names of vertex datasets
224 std::vector<std::string> &, // (input/output) names of simplex datasets
225 std::vector<int> &, // (input/output) number of data in each vertex dataset
226 std::vector<int> & // (input/outptu) number of data in each simplex dataset
227);
228
229// Check routines ----------------------------------------------------------- //
230unsigned int checkData( // Check DGF data structure
231 std::ifstream &, // (input) input stream to dgf file
232 int & // (input/output) error code
233);
234unsigned int check( // Check DGF
235 std::ifstream &, // (input) input stream to dgf file
236 std::vector<std::vector<int> > & // (input/output) error code for each dataset
237);
238
239// Input routines ----------------------------------------------------------- //
240template< typename T >
241unsigned int readData( // Read DGF data
242 std::ifstream &file_handle, // (input) input stream to dgf file
243 int &N, // (input/output) number of data loaded
244 std::vector< T > &Data // (input/output) loaded data
245);
246unsigned int readMesh( // Read mesh data from file.
247 std::ifstream &, // (input) input stream to dgf file
248 int &, // (input/output) number of mesh vertices
249 int &, // (input/output) number of simplicies
250 std::vector<std::vector<double> > &, // (input/output) vertex coordinate list
251 std::vector<std::vector<int> > & // (input/output) simplex-vertex connectivity
252);
253unsigned int readMesh( // Read mesh data from file.
254 std::ifstream &, // (input) input stream to dgf file
255 int &, // (input/output) number of mesh vertices
256 int &, // (input/output) number of simplicies
257 std::vector<std::array<double,3> > &, // (input/output) vertex coordinate list
258 std::vector<std::vector<int> > & // (input/output) simplex-vertex connectivity
259);
260template <typename T>
261unsigned int readVertexData( // Load dgf vertex data
262 std::ifstream &file_handle, // (input) input stream to dgf file
263 int &n, // (input/output) number of loaded data
264 std::vector< T > &data, // (input/output) loaded data
265 const std::string &data_name = "" // (input/optional) dataset name
266);
267template< typename T >
268unsigned int readSimplexData( // Load dgf simplex data
269 std::ifstream &file_handle, // (input) input stream to dgf file
270 int &n, // (input/output) number of loaded data
271 std::vector< T > &data, // (input/output) loaded data
272 const std::string &data_name = "" // (input/optional) dataset name
273);
274
275// Output routines ---------------------------------------------------------- //
276template < typename T >
277unsigned int writeData( // Export data set to dgf file
278 std::ofstream &, // (input) output stream to dgf file
279 int &, // (input) number of data in the dataset
280 std::vector< T > & // (input) dataset to be exported
281);
282unsigned int writeMesh( // Export mesh data into dgf file
283 std::ofstream &, // (input) output stream to dgf file
284 int &, // (input) number of vertices
285 int &, // (input) number of simplicies
286 std::vector<std::vector<double> > &, // (input) vertex coordinate list
287 std::vector<std::vector<int> > & // (input) simplex-vertex connectivity
288);
289unsigned int writeMesh( // Export mesh data into dgf file
290 std::ofstream &, // (input) output stream to dgf file
291 int &, // (input) number of vertices
292 int &, // (input) number of simplicies
293 std::vector<std::array<double,3> > &, // (input) vertex coordinate list
294 std::vector<std::vector<int> > & // (input) simplex-vertex connectivity
295);
296
297template < typename T >
298unsigned int writeVertexData( // Export vertex data to dgf file
299 std::ofstream &file_handle, // (input) output stream to dgf file
300 int &N, // (input) number of data in the dataset
301 std::vector< T > &Data, // (input) vertex data set
302 const std::string &Data_name = "" // (input/optional) data set name
303);
304template < typename T >
305unsigned int writeSimplexData( // Export simplex data to dgf file
306 std::ofstream &file_handle, // (input) output stream to dgf file
307 int &N, // (input) number of data in the dataset
308 std::vector< T > &Data, // (input) simplex data set
309 const std::string &Data_name = "" // (input/optional) data set name
310);
311
312}
313
314// ========================================================================== //
315// TEMPLATES //
316// ========================================================================== //
317# include "DGF.tpp"
318}
319
320
321# endif
Interface to DGF I/O function.
Definition DGF.hpp:78
unsigned int err
Definition DGF.hpp:85
void clear(void)
Definition DGF.cpp:263
void close(const std::string &a="inout")
Definition DGF.cpp:214
DGFObj(void)
Definition DGF.cpp:70
void save(int &, int &, std::vector< std::vector< double > > &, std::vector< std::vector< int > > &)
Definition DGF.cpp:676
void open(const std::string &)
Definition DGF.cpp:151
void check(void)
Definition DGF.cpp:463
void display(std::ostream &)
Definition DGF.cpp:304
void scan(void)
Definition DGF.cpp:421
void load(int &, int &, std::vector< std::vector< double > > &, std::vector< std::vector< int > > &)
Definition DGF.cpp:516
DGFData data
Definition DGF.hpp:86
std::string dgf_name
Definition DGF.hpp:84
unsigned int scan(std::ifstream &, int &, int &, std::vector< std::string > &, std::vector< std::string > &, std::vector< int > &, std::vector< int > &)
Definition DGF.cpp:972
unsigned int writeMesh(std::ofstream &, int &, int &, std::vector< std::vector< double > > &, std::vector< std::vector< int > > &)
Definition DGF.cpp:1439
unsigned int check(std::ifstream &, std::vector< std::vector< int > > &)
Definition DGF.cpp:1169
unsigned int checkData(std::ifstream &, int &)
Definition DGF.cpp:1090
unsigned int readMesh(std::ifstream &, int &, int &, std::vector< std::vector< double > > &, std::vector< std::vector< int > > &)
Definition DGF.cpp:1270
unsigned int scanData(std::ifstream &, int &)
Definition DGF.cpp:893
Definition DGF.tpp:233
structure holding meta-information
Definition DGF.hpp:69
std::vector< std::string > sS_data
Definition DGF.hpp:75
std::vector< std::string > sV_data
Definition DGF.hpp:73
std::vector< int > nV_data
Definition DGF.hpp:72
std::vector< int > nS_data
Definition DGF.hpp:74
--- layout: doxygen_footer ---