BasicVoxelFileReader.h 4.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//======================================================================================================================
//
//  This file is part of waLBerla. waLBerla is free software: you can 
//  redistribute it and/or modify it under the terms of the GNU General Public
//  License as published by the Free Software Foundation, either version 3 of 
//  the License, or (at your option) any later version.
//  
//  waLBerla is distributed in the hope that it will be useful, but WITHOUT 
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//  for more details.
//  
//  You should have received a copy of the GNU General Public License along
//  with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file BasicVoxelFileReader.h
//! \ingroup geometry
//! \author Christian Godenschwager <christian.godenschwager@fau.de>
//! \brief Declares class StructuredGeometryFileBasicReader that provides a low-level reader for waLBerla geometry files.
//!
21
//! This reader has no dependencies towards waLBerla or even boost so it can be used by external
22
23
24
25
26
27
//! software to read or write geometry files.
//
//======================================================================================================================

#pragma once

28
#include <cstddef>
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <fstream>
#include <string>
#include <vector>


namespace walberla {
namespace geometry {

struct CellAABB;

/*******************************************************************************************************************//**
 *
 * \brief Provides a low level reader for waLBerla geometry files.
 *
 * \tparam T The underlying datatype that is stored in binary form in the geometry file
 *
 * \ingroup geometry
 *
 **********************************************************************************************************************/
template<typename T>
class BasicVoxelFileReader
{
public:
   BasicVoxelFileReader();
   BasicVoxelFileReader( const std::string & _filename);
54
55
   BasicVoxelFileReader( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, T value = T() );
   BasicVoxelFileReader( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, const T * values );
56
57
58
   ~BasicVoxelFileReader();

   void open  ( const std::string & _filename );
59
60
   void create( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, T value = T() );
   void create( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, const T * values );
61
62
63
64
   void close ();

   bool isOpen() const;
   const std::string & filename() const;
65
   std::size_t numCells() const;
66

67
68
69
   std::size_t xSize() const;
   std::size_t ySize() const;
   std::size_t zSize() const;
70
71
72
73
74
75
76
77
78
79
80

   void read ( const CellAABB & cellAABB,       std::vector<T> & data ) const;
   void write( const CellAABB & cellAABB, const std::vector<T> & data );

private:
   mutable std::fstream filestream_; ///< fstream object managing the opened file

   std::string filename_; ///< Filename of the geometry file currently opened.

   std::streampos dataBegin_; ///< Position in the stream where to raw data starts

81
82
83
   std::size_t xSize_; ///< Extend of the currently open geometry file in x direction
   std::size_t ySize_; ///< Extend of the currently open geometry file in y direction
   std::size_t zSize_; ///< Extend of the currently open geometry file in z direction
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

}; // class StructuredGeometryFileBasicReader


/*******************************************************************************************************************//**
 *
 * \brief Helper class to provide a cell based axis-aligned bounding box
 *
 * The AABB includes the cells with their x coordinate lying in [xBegin, xEnd], their y coordinate
 * lying in [yBegin, yEnd] and their z coordinate lying in [zBegin, zEnd].
 *
 * \ingroup geometry
 *
 **********************************************************************************************************************/
struct CellAABB
{
   inline CellAABB();
101
102
   inline CellAABB(std::size_t _xBegin, std::size_t _yBegin, std::size_t _zBegin,
                   std::size_t _xEnd,   std::size_t _yEnd,   std::size_t _zEnd);
103

104
105
106
107
   inline std::size_t numCells() const;
   inline std::size_t xSize() const;
   inline std::size_t ySize() const;
   inline std::size_t zSize() const;
108

109
110
111
   std::size_t xBegin; ///< The minimal x coordinate of all cells included in the AABB.
   std::size_t yBegin; ///< The minimal y coordinate of all cells included in the AABB.
   std::size_t zBegin; ///< The minimal z coordinate of all cells included in the AABB.
112

113
114
115
   std::size_t xEnd; ///< The maximal x coordinate of all cells included in the AABB.
   std::size_t yEnd; ///< The maximal y coordinate of all cells included in the AABB.
   std::size_t zEnd; ///< The maximal z coordinate of all cells included in the AABB.
116
117
118
119
120
121
122
123

}; // class CellAABB

} // namespace geometry
} // namespace walberla

#include "BasicVoxelFileReader.impl.h"