BasicVoxelFileReader.h 4.8 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
28
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! software to read or write geometry files.
//
//======================================================================================================================

#pragma once

#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);
   BasicVoxelFileReader( const std::string & _filename, size_t _xSize, size_t _ySize, size_t _zSize, T value = T() );
   BasicVoxelFileReader( const std::string & _filename, size_t _xSize, size_t _ySize, size_t _zSize, const T * values );
   ~BasicVoxelFileReader();

   void open  ( const std::string & _filename );
   void create( const std::string & _filename, size_t _xSize, size_t _ySize, size_t _zSize, T value = T() );
   void create( const std::string & _filename, size_t _xSize, size_t _ySize, size_t _zSize, const T * values );
   void close ();

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

   size_t xSize() const;
   size_t ySize() const;
   size_t zSize() const;

   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

   size_t xSize_; ///< Extend of the currently open geometry file in x direction
   size_t ySize_; ///< Extend of the currently open geometry file in y direction
   size_t zSize_; ///< Extend of the currently open geometry file in z direction

}; // 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();
   inline CellAABB(size_t _xBegin, size_t _yBegin, size_t _zBegin,
                   size_t _xEnd,   size_t _yEnd,   size_t _zEnd);

   inline size_t numCells() const;
   inline size_t xSize() const;
   inline size_t ySize() const;
   inline size_t zSize() const;

   size_t xBegin; ///< The minimal x coordinate of all cells included in the AABB.
   size_t yBegin; ///< The minimal y coordinate of all cells included in the AABB.
   size_t zBegin; ///< The minimal z coordinate of all cells included in the AABB.

   size_t xEnd; ///< The maximal x coordinate of all cells included in the AABB.
   size_t yEnd; ///< The maximal y coordinate of all cells included in the AABB.
   size_t zEnd; ///< The maximal z coordinate of all cells included in the AABB.

}; // class CellAABB

} // namespace geometry
} // namespace walberla

#include "BasicVoxelFileReader.impl.h"