BasicVoxelFileReader.impl.h 26.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//======================================================================================================================
//
//  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.impl.h
//! \ingroup geometry
//! \author Christian Godenschwager <christian.godenschwager@fau.de>
//! \brief Defines class StructuredGeometryFileBasicReader that provides a low-level reader for waLBerla geometry files.
//
//======================================================================================================================

#include <cassert>
24
#include <cstddef>
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
#include <sstream>
#include <stdexcept>
#include <typeinfo>


namespace walberla {
namespace geometry {

/*******************************************************************************************************************//**
 * \brief Constructs on empty geometry file
 *
 * \post isOpen() == false
 **********************************************************************************************************************/
template<typename T>
BasicVoxelFileReader<T>::BasicVoxelFileReader() : xSize_(0), ySize_(0), zSize_(0)
{
   assert( !isOpen() );
   assert( filename_.empty() );
   assert( dataBegin_ == std::streampos() );
   assert( xSize_ == 0 );
   assert( ySize_ == 0 );
   assert( zSize_ == 0 );
}

/*******************************************************************************************************************//**
 * \brief Opens an existing geometry file.
 *
 * \param filename Name (path) of the file.
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \post isOpen() == true
 **********************************************************************************************************************/
template<typename T>
BasicVoxelFileReader<T>::BasicVoxelFileReader( const std::string & _filename)
   :  xSize_(0), ySize_(0), zSize_(0)
{
   open(_filename);

   assert( dataBegin_ != std::streampos(-1) );
   assert( dataBegin_ != std::streampos() );
   assert( isOpen() );
   assert( xSize() != 0 );
   assert( ySize() != 0 );
   assert( zSize() != 0 );
   assert( filename() == _filename );
}

/*******************************************************************************************************************//**
 * \brief Creates a new geometry file with extends xSize x ySize x zSize.
 *
 * \param filename Name (path) of the file.
 * \param xSize    Extend of the geometry file in x direction.
 * \param ySize    Extend of the geometry file in y direction.
 * \param zSize    Extend of the geometry file in z direction.
 * \param value    The value the cells are initialized with. Defaults to T().
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \post isOpen() == true
 **********************************************************************************************************************/
template<typename T>
87
BasicVoxelFileReader<T>::BasicVoxelFileReader( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, T value /*= T()*/ )
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
   : xSize_(0), ySize_(0), zSize_(0)
{
   create(_filename, _xSize, _ySize, _zSize, value);

   assert( dataBegin_ != std::streampos(-1) );
   assert( dataBegin_ != std::streampos() );
   assert( isOpen() );
   assert( xSize_ == _xSize );
   assert( ySize_ == _ySize );
   assert( zSize_ == _zSize );
   assert( filename_ == _filename );
}

/*******************************************************************************************************************//**
 * \brief Creates a new geometry file with extends xSize x ySize x zSize.
 *
 * \param filename Name (path) of the file.
 * \param xSize    Extend of the geometry file in x direction.
 * \param ySize    Extend of the geometry file in y direction.
 * \param zSize    Extend of the geometry file in z direction.
 * \param values   An array of size xSize * ySize * zSize with the values to initialize the
 * 					 geometry file with.
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \pre values != nullptr
 *
 * \post isOpen() == true
 **********************************************************************************************************************/
template<typename T>
118
BasicVoxelFileReader<T>::BasicVoxelFileReader( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, const T * values )
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
   : xSize_(0), ySize_(0), zSize_(0)
{
   assert(values != 0);

   create(_filename, _xSize, _ySize, _zSize, values);

   assert( dataBegin_ != std::streampos(-1) );
   assert( dataBegin_ != std::streampos() );
   assert( isOpen() );
   assert( xSize_ == _xSize );
   assert( ySize_ == _ySize );
   assert( zSize_ == _zSize );
   assert( filename_ == _filename );
}

/*******************************************************************************************************************//**
 * \brief Destructor that closes the file if necessary.
 **********************************************************************************************************************/
template<typename T>
BasicVoxelFileReader<T>::~BasicVoxelFileReader()
{
   //filestream_.exceptions( std::ios_base::iostate(0) );
   if(filestream_.is_open())
      filestream_.close();
}

/*******************************************************************************************************************//**
* \brief Opens an existing geometry file.
*
* 	An already opened file gets closed beforehand.
*
* \param filename Name (path) of the file.
*
* \throws std::runtime_error on I/O errors.
* \throws std::runtime_error if the loaded geometry file's format is corrupt
*
* \post isOpen() == true
 **********************************************************************************************************************/
template<typename T>
void BasicVoxelFileReader<T>::open( const std::string & _filename )
{
   if( isOpen() )
      close();

   filename_ = _filename;

   filestream_.open(_filename.c_str(),  std::fstream::in | std::fstream::out | std::fstream::binary);
   if( filestream_.fail() || filestream_.bad())
      throw std::runtime_error("Error opening file \"" + _filename + "\"!");

   std::string firstLine;
   std::getline(filestream_, firstLine);
   if( filestream_.fail() || filestream_.bad() )
      throw std::runtime_error("Error reading header from file \"" + _filename + "\"!");
   {
      std::stringstream ss(firstLine);
      ss >> xSize_;
      ss >> ySize_;
      ss >> zSize_;
   }

   dataBegin_ = filestream_.tellg();
   if( filestream_.fail() || filestream_.bad() || dataBegin_ == std::streampos(-1) )
      throw std::runtime_error("I/O Error while reading file \"" + _filename + "\"!");

   filestream_.seekg(0, std::ios::end);
   if( filestream_.fail() || filestream_.bad() )
      throw std::runtime_error("I/O Error while reading file \"" + _filename + "\"!");

   std::streampos dataEnd = filestream_.tellg();
   if( filestream_.fail() || filestream_.bad() || dataEnd == std::streampos(-1) )
      throw std::runtime_error("I/O Error while reading file \"" + _filename + "\"!");


   assert(dataBegin_ <= dataEnd);
194
   std::size_t rawDataLengthBytes = static_cast<std::size_t>( dataEnd - dataBegin_ );
195
196
197
198
199
200
201
202
   if( rawDataLengthBytes % sizeof(T) != 0 )
   {
      std::stringstream ss;
      ss << "Raw data part of file " << _filename << " has size " << rawDataLengthBytes << " bytes. Data is of Type T = "
         << typeid(T).name() << " and sizeof(T) == " << sizeof(T) << "\nError: size % sizeof(T) != 0!";
      throw std::runtime_error(ss.str());
   }
   assert(rawDataLengthBytes % sizeof(T) == 0);
203
   std::size_t rawDataLength = rawDataLengthBytes / sizeof(T);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
   if( rawDataLength != numCells() )
   {
      std::stringstream ss;
      ss << "Raw data part of file " << _filename << " has size " << rawDataLengthBytes << " bytes. Data is of Type T = "
         << typeid(T).name() << " and sizeof(T) == " << sizeof(T) << ". Error: Number of cells in data section of file = size / sizeof(T) = "
         << rawDataLength << " != Number of cells specified file header = " << numCells();
      throw std::runtime_error(ss.str());
   }

   assert(dataBegin_ != std::streampos(-1));
   assert(dataBegin_ != std::streampos());
   assert(filename_ == _filename);
   assert(xSize_ != 0);
   assert(ySize_ != 0);
   assert(zSize_ != 0);
}

/*******************************************************************************************************************//**
 * \brief Creates a new geometry file with extends xSize x ySize x zSize.
 *
 * An already opened file gets closed beforehand.
 *
 * \param filename Name (path) of the file.
 * \param xSize    Extend of the geometry file in x direction.
 * \param ySize    Extend of the geometry file in y direction.
 * \param zSize    Extend of the geometry file in z direction.
 * \param value    The value the cells are initialized with. Defaults to T().
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \post isOpen() == true
 **********************************************************************************************************************/
template<typename T>
237
void BasicVoxelFileReader<T>::create( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, T value /*= T()*/ )
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
{
   if( isOpen() )
      close();

   filename_ = _filename;

   xSize_ = _xSize;
   ySize_ = _ySize;
   zSize_ = _zSize;

   filestream_.open(_filename.c_str(), std::fstream::out | std::fstream::binary);
   if( filestream_.fail() || filestream_.bad())
      throw std::runtime_error("Error opening file \"" + _filename + "\"!");

   filestream_ << _xSize << " " << _ySize << " " << _zSize << "\n";
   if( filestream_.fail() || filestream_.bad())
      throw std::runtime_error("Error writing header to file \"" + _filename + "\"!");

   dataBegin_ = filestream_.tellp();
   if( filestream_.fail() || filestream_.bad() || dataBegin_ == std::streampos(-1) )
      throw std::runtime_error("I/O Error while writing file \"" + _filename + "\"!");

260
261
   const std::size_t maxChunkSizeBytes = 1024 * 1024; // 1 MegaByte
   const std::size_t numCellsPerChunk = maxChunkSizeBytes / sizeof(T);
262
263
264
265
266
267
   const std::streamsize bytesPerChunk = static_cast< std::streamsize >( numCellsPerChunk * sizeof(T) );

   const std::vector<T> chunkData(numCellsPerChunk, value);
   assert(!chunkData.empty());
   const char * rawData = reinterpret_cast<const char*>(&chunkData[0]);

268
   std::size_t cellsLeft = numCells();
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
   while( cellsLeft >= numCellsPerChunk )
   {
      filestream_.write(rawData, bytesPerChunk);
      if( filestream_.fail() || filestream_.bad() )
         throw std::runtime_error("I/O Error while writing file \"" + _filename + "\"!");
      cellsLeft -= numCellsPerChunk;
   }

   const std::streamsize bytesLastChunk = static_cast< std::streamsize >( cellsLeft * sizeof(T) );
   assert(bytesLastChunk < bytesPerChunk);
   filestream_.write(rawData, bytesLastChunk);
   if( filestream_.fail() || filestream_.bad() )
      throw std::runtime_error("I/O Error while writing file \"" + _filename + "\"!");

   close();
   open(_filename);

   assert(dataBegin_ != std::streampos(-1));
   assert(dataBegin_ != std::streampos());
   assert(filename_ == _filename);
   assert(xSize_ == _xSize);
   assert(ySize_ == _ySize);
   assert(zSize_ == _zSize);
}

/*******************************************************************************************************************//**
 * \brief Creates a new geometry file with extends xSize x ySize x zSize.
 *
 * An already opened file gets closed beforehand.
 *
 * \param filename Name (path) of the file.
 * \param xSize    Extend of the geometry file in x direction.
 * \param ySize    Extend of the geometry file in y direction.
 * \param zSize    Extend of the geometry file in z direction.
 * \param values   An array of size xSize * ySize * zSize with the values to initialize the
 * 					 geometry file with.
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \pre values != nullptr
 *
 * \post isOpen() == true
 **********************************************************************************************************************/
template<typename T>
313
void BasicVoxelFileReader<T>::create( const std::string & _filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, const T * values )
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
{
   if( isOpen() )
      close();

   filename_ = _filename;

   xSize_ = _xSize;
   ySize_ = _ySize;
   zSize_ = _zSize;

   filestream_.open(_filename.c_str(), std::fstream::out | std::fstream::binary);
   if( filestream_.fail() || filestream_.bad())
      throw std::runtime_error("Error opening file \"" + _filename + "\"!");

   filestream_ << _xSize << " " << _ySize << " " << _zSize << "\n";
   if( filestream_.fail() || filestream_.bad())
      throw std::runtime_error("Error writing header to file \"" + _filename + "\"!");

   dataBegin_ = filestream_.tellp();
   if( filestream_.fail() || filestream_.bad() || dataBegin_ == std::streampos(-1) )
      throw std::runtime_error("I/O Error while writing file \"" + _filename + "\"!");

   const char * rawData = reinterpret_cast<const char*>(values);
337
   std::size_t dataSizeBytes = numCells() * sizeof(T);
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
   filestream_.write(rawData, static_cast< std::streamsize >( dataSizeBytes ) );
   if( filestream_.fail() || filestream_.bad() )
      throw std::runtime_error("I/O Error while writing file \"" + _filename + "\"!");

   close();
   open(_filename);

   assert(dataBegin_ != std::streampos(-1));
   assert(dataBegin_ != std::streampos());
   assert(filename_ == _filename);
   assert(xSize_ == _xSize);
   assert(ySize_ == _ySize);
   assert(zSize_ == _zSize);
}

/*******************************************************************************************************************//**
 * \brief Closes an opened geometry file.
 *
 * If no geometry file is open, this does nothing.
 *
 * \post isOpen() == false
 **********************************************************************************************************************/
template<typename T>
void BasicVoxelFileReader<T>::close()
{
   if( isOpen() )
   {
      filestream_.close();
      dataBegin_ = std::streampos();
      filename_.clear();
368
369
370
      xSize_ = std::size_t(0);
      ySize_ = std::size_t(0);
      zSize_ = std::size_t(0);
371
372
373
374
   }

   assert(!filestream_.is_open());
   assert(dataBegin_ == std::streampos());
Sebastian Eibl's avatar
Sebastian Eibl committed
375
   assert(filename_.empty());
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
   assert(xSize_ == 0);
   assert(ySize_ == 0);
   assert(zSize_ == 0);
   assert( !isOpen() );
}

/*******************************************************************************************************************//**
 * \brief Query if a geometry file is open.
 *
 * \return true if a file is opened, false if not.
 **********************************************************************************************************************/
template<typename T>
bool BasicVoxelFileReader<T>::isOpen() const
{
   return filestream_.is_open();
}

/*******************************************************************************************************************//**
 * \brief Gets the filename of the opened geometry file.
 *
 * \pre isOpen() == true
 *
 * \return The filename of the opened geometry file.
 **********************************************************************************************************************/
template<typename T>
const std::string & BasicVoxelFileReader<T>::filename() const
{
   assert( isOpen() );
   return filename_;
}

/*******************************************************************************************************************//**
 * \brief Gets the extend of the geometry file in x direction.
 *
 * \pre isOpen() == true
 *
 * \return The extend of the geometry file in x direction.
 **********************************************************************************************************************/
template<typename T>
415
std::size_t BasicVoxelFileReader<T>::xSize() const
416
417
418
419
420
421
422
423
424
425
426
427
428
{
   assert( isOpen() );
   return xSize_;
}

/*******************************************************************************************************************//**
 * \brief Gets the extend of the geometry file in y direction.
 *
 * \pre isOpen() == true
 *
 * \return The extend of the geometry file in y direction.
 **********************************************************************************************************************/
template<typename T>
429
std::size_t BasicVoxelFileReader<T>::ySize() const
430
431
432
433
434
435
436
437
438
439
440
441
442
{
   assert( isOpen() );
   return ySize_;
}

/*******************************************************************************************************************//**
 * \brief Gets the extend of the geometry file in z direction.
 *
 * \pre isOpen() == true
 *
 * \return The extend of the geometry file in z direction.
 **********************************************************************************************************************/
template<typename T>
443
std::size_t BasicVoxelFileReader<T>::zSize() const
444
445
446
447
448
449
450
451
452
453
454
455
456
{
   assert( isOpen() );
   return zSize_;
}

/*******************************************************************************************************************//**
 * \brief Gets the number of cells of the currently loaded geometry file.
 *
 * \pre isOpen() == true
 *
 * \return xSize() * ySize() * zSize().
 **********************************************************************************************************************/
template<typename T>
457
std::size_t BasicVoxelFileReader<T>::numCells() const
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
{
   assert( isOpen() );
   return xSize() * ySize() * zSize();
}

/*******************************************************************************************************************//**
 * \brief Reads a block of data from the opened geometry file.
 *
 * \param cellAABB   The axis-aligned bounding box of the block of data to be read.
 * \param [out] data The vector the read data is stored to. The Storage order is zyx. (Meaning
 * 				      your innermost loop should iterate over x)
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \pre isOpen() == true
 * \pre cellAABB.xEnd < xSize()
 * \pre cellAABB.yEnd < ySize()
 * \pre cellAABB.zEnd < zSize()
 *
 * \post data.size() == cellAABB.numCells()
 **********************************************************************************************************************/
template<typename T>
void BasicVoxelFileReader<T>::read( const CellAABB & cellAABB, std::vector<T> & data ) const
{
   assert( isOpen() );
   assert( cellAABB.xEnd < xSize() );
   assert( cellAABB.yEnd < ySize() );
   assert( cellAABB.zEnd < zSize() );

   data.clear();
   data.resize( cellAABB.numCells() );
   assert(!data.empty());
   char * buffer = reinterpret_cast<char*>( &data[0] );

492
493
   const std::size_t zFactor = xSize() * ySize();
   const std::size_t yFactor = xSize();
494
495
   std::streamsize lineLength = static_cast< std::streamsize >( cellAABB.xSize() * sizeof(T) );

496
497
   for(std::size_t z = cellAABB.zBegin; z <= cellAABB.zEnd; ++z)
      for(std::size_t y = cellAABB.yBegin; y <= cellAABB.yEnd; ++y)
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
      {
         assert( buffer < reinterpret_cast<char*>(&data[0] + data.size()) );
         assert( buffer + lineLength - 1 < reinterpret_cast<char*>(&data[0] + data.size()) );
         std::streamoff offset = static_cast< std::streamoff >( (z * zFactor + y * yFactor + cellAABB.xBegin) * sizeof(T) );

         filestream_.seekg(dataBegin_ + offset);
         if( filestream_.fail() || filestream_.bad() )
            throw std::runtime_error("I/O Error while reading file \"" + filename() + "\"!");

         filestream_.read(buffer, lineLength);
         if( filestream_.fail() || filestream_.bad() )
            throw std::runtime_error("I/O Error while reading file \"" + filename() + "\"!");

         assert(filestream_.gcount() == lineLength);

         buffer += lineLength;
      }

   assert( buffer == reinterpret_cast<char*>(&data[0] + data.size()) );
   assert( data.size() == cellAABB.numCells() );
}

/*******************************************************************************************************************//**
 * \brief Writes a block of data to the geometry file.
 *
 * \param cellAABB The axis-aligned bounding box of the block of data to be written.
 * \param data     The vector holding the data to bw written to the geometry file. The Storage
 * 					 order is zyx. (Meaning your innermost loop should iterate over x)
 *
 * \throws std::runtime_error on I/O errors.
 *
 * \pre isOpen() == true
 * \pre cellAABB.xEnd < xSize()
 * \pre cellAABB.yEnd < ySize()
 * \pre cellAABB.zEnd < zSize()
 * \pre data.size() >= cellAABB.numCells()
 **********************************************************************************************************************/
template<typename T>
void BasicVoxelFileReader<T>::write( const CellAABB & cellAABB, const std::vector<T> & data )
{
   assert( isOpen() );
   assert( cellAABB.xEnd < xSize_ );
   assert( cellAABB.yEnd < ySize_ );
   assert( cellAABB.zEnd < zSize_ );
   assert( !data.empty() );
   assert( data.size() >= cellAABB.numCells() );

   const char * buffer = reinterpret_cast<const char*>( &data[0] );

547
548
   const std::size_t zFactor = xSize() * ySize();
   const std::size_t yFactor = xSize();
549
550
   std::streamsize lineLength = static_cast< std::streamsize >( cellAABB.xSize() * sizeof(T) );

551
552
   for(std::size_t z = cellAABB.zBegin; z <= cellAABB.zEnd; ++z)
      for(std::size_t y = cellAABB.yBegin; y <= cellAABB.yEnd; ++y)
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
      {
         assert( buffer < reinterpret_cast<const char*>(&data[0] + data.size()) );
         assert( buffer + lineLength - 1 < reinterpret_cast<const char*>(&data[0] + data.size()) );
         std::streamoff offset = static_cast< std::streamoff >( (z * zFactor + y * yFactor + cellAABB.xBegin) * sizeof(T) );

         filestream_.seekp(dataBegin_ + offset);
         if( filestream_.fail() || filestream_.bad() )
            throw std::runtime_error("I/O Error while writing file \"" + filename() + "\"!");

         filestream_.write(buffer, lineLength);
         if( filestream_.fail() || filestream_.bad() )
            throw std::runtime_error("I/O Error while writing file \"" + filename() + "\"!");

         buffer += lineLength;
      }

   assert( buffer == reinterpret_cast<const char*>(&data[0] + cellAABB.numCells()) );
}

/*******************************************************************************************************************//**
 * \brief Constructor to initialize all members to 0.
 *
 * \post #xBegin = 0.
 * \post #yBegin = 0.
 * \post #zBegin = 0.
 * \post #xEnd = 0.
 * \post #yEnd = 0.
 * \post #zEnd = 0.
 * \post xSize() = 1
 * \post ySize() = 1
 * \post zSize() = 1
 * \post numCells() = 1
 **********************************************************************************************************************/
inline CellAABB::CellAABB()
   : xBegin(0), yBegin(0), zBegin(0), xEnd(0), yEnd(0), zEnd(0)
{ }

/*******************************************************************************************************************//**
 * \brief Constructor to initialize all members.
 *
 * \pre _xBegin <= _xEnd.
 * \pre _yBegin <= _yEnd.
 * \pre _zBegin <= _zEnd.
 *
 * \post #xBegin = _xBegin.
 * \post #yBegin = _yBegin.
 * \post #zBegin = _zBegin.
 * \post #xEnd = _xEnd.
 * \post #yEnd = _yEnd.
 * \post #zEnd = _zEnd.
 *
 * \param _xBegin The minimal x coordinate of all cells included in the AABB.
 * \param _yBegin The minimal y coordinate of all cells included in the AABB.
 * \param _zBegin The minimal z coordinate of all cells included in the AABB.
 * \param _xEnd   The maximal x coordinate of all cells included in the AABB.
 * \param _yEnd   The maximal y coordinate of all cells included in the AABB.
 * \param _zEnd   The maximal z coordinate of all cells included in the AABB.
 **********************************************************************************************************************/
611
612
CellAABB::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 )
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
   : xBegin(_xBegin), yBegin(_yBegin), zBegin(_zBegin),
     xEnd(_xEnd), yEnd(_yEnd), zEnd(_zEnd)
{
   assert( xBegin <= xEnd );
   assert( yBegin <= yEnd );
   assert( zBegin <= zEnd );
}

/*******************************************************************************************************************//**
 * \brief Gets the number cells included in the AABB.
 *
 * \pre #xBegin <= #xEnd.
 * \pre #yBegin <= #yEnd.
 * \pre #zBegin <= #zEnd.
 *
 * \return xSize() * ySize() * zSize().
 **********************************************************************************************************************/
630
std::size_t CellAABB::numCells() const
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
{
   assert( xBegin <= xEnd );
   assert( yBegin <= yEnd );
   assert( zBegin <= zEnd );

   return xSize() * ySize() * zSize();
}

/*******************************************************************************************************************//**
 * \brief Gets the extent of the AABB in z direction.
 *
 * \pre #xBegin <= #xEnd.
 *
 * \return #xEnd - #xBegin + 1.
 **********************************************************************************************************************/
646
std::size_t CellAABB::xSize() const
647
648
649
650
651
652
653
654
655
656
657
658
{
   assert( xBegin <= xEnd  );
   return xEnd - xBegin + 1;
}

/*******************************************************************************************************************//**
 * \brief Gets the extent of the AABB in y direction.
 *
 * \pre #yBegin <= #yEnd.
 *
 * \return #yEnd - #yBegin + 1.
 **********************************************************************************************************************/
659
std::size_t CellAABB::ySize() const
660
661
662
663
664
665
666
667
668
669
670
671
{
   assert( yBegin <= yEnd );
   return yEnd - yBegin + 1;
}

/*******************************************************************************************************************//**
 * \brief Gets the extent of the AABB in z direction.
 *
 * \pre #zBegin <= #zEnd.
 *
 * \return #zEnd - #zBegin + 1.
 **********************************************************************************************************************/
672
std::size_t CellAABB::zSize() const
673
674
675
676
677
678
679
{
   assert( zBegin <= zEnd );
   return zEnd - zBegin + 1;
}

} // namespace geometry
} // namespace walberla