1 #ifndef PROCEDURAL_VOXEL_TILE_CONTAINER_HPP
2 #define PROCEDURAL_VOXEL_TILE_CONTAINER_HPP
4 #include "blub/core/array.hpp"
5 #include "blub/core/classVersion.hpp"
6 #include "blub/core/vector.hpp"
7 #include "blub/math/axisAlignedBoxInt32.hpp"
8 #include "blub/math/vector3int.hpp"
9 #include "blub/procedural/voxel/tile/base.hpp"
10 #include "blub/serialization/access.hpp"
11 #include "blub/serialization/nameValuePair.hpp"
29 template <
class configType>
30 class container :
public base<container<configType> >
34 typedef base<container<t_config> > t_base;
37 #if defined(BOOST_NO_CXX11_CONSTEXPR)
38 static const int32 voxelLength;
39 static const int32 voxelCount;
41 static constexpr int32 voxelLength = t_config::voxelsPerTile;
42 static constexpr int32 voxelCount = voxelLength*voxelLength*voxelLength;
45 typedef vector<t_data> t_voxelArray;
68 m_changedVoxelBoundingBox.setInvalid();
94 return m_changedVoxelBoundingBox;
108 m_changedVoxelBoundingBox.extend(pos);
112 void setVoxelIfInterpolationHigher(
const vector3int32& pos,
const t_data& toSet)
116 m_changedVoxelBoundingBox.extend(pos);
120 void setVoxelIfInterpolationHigherEqualZero(
const vector3int32& pos,
const t_data& toSet)
122 if(setVoxelIfInterpolationHigherEqualZero(
calculateIndex(pos), toSet))
124 m_changedVoxelBoundingBox.extend(pos);
128 void setVoxelIfInterpolationLower(
const vector3int32& pos,
const t_data& toSet)
132 m_changedVoxelBoundingBox.extend(pos);
144 for (uint32 indVoxel = 0; indVoxel < m_voxels.size(); ++indVoxel)
146 m_voxels[indVoxel].setMax();
148 m_countVoxelInterpolationLargerZero = voxelCount;
149 m_countVoxelMinimum = 0;
150 m_countVoxelMaximum = voxelCount;
160 for (uint32 indVoxel = 0; indVoxel < m_voxels.size(); ++indVoxel)
162 m_voxels[indVoxel].setMin();
164 m_countVoxelInterpolationLargerZero = 0;
165 m_countVoxelMinimum = voxelCount;
166 m_countVoxelMaximum = 0;
187 BASSERT(index < voxelCount);
188 return m_voxels[index];
209 BASSERT(pos.x < voxelLength);
210 BASSERT(pos.y < voxelLength);
211 BASSERT(pos.z < voxelLength);
212 return (pos.x)*(voxelLength*voxelLength) + (pos.y)*(voxelLength) + (pos.z);
222 BASSERT(m_countVoxelInterpolationLargerZero >= 0);
223 BASSERT(m_countVoxelInterpolationLargerZero <= voxelCount);
224 return m_countVoxelInterpolationLargerZero;
233 BASSERT(m_countVoxelMaximum >= 0);
234 BASSERT(m_countVoxelMaximum <= voxelCount);
235 return m_countVoxelMaximum;
244 BASSERT(m_countVoxelMinimum >= 0);
245 BASSERT(m_countVoxelMinimum <= voxelCount);
246 return m_countVoxelMinimum;
256 return m_countVoxelMinimum == container::voxelCount;
266 return m_countVoxelMaximum == container::voxelCount;
275 m_countVoxelInterpolationLargerZero = other.getCountVoxelLargerZero();
276 m_countVoxelMinimum = other.getCountVoxelMinimum();
277 m_countVoxelMaximum = other.getCountVoxelMaximum();
278 m_voxels = other.getVoxelArray();
286 : m_voxels(voxelCount)
287 , m_countVoxelInterpolationLargerZero(0)
288 , m_countVoxelMinimum(voxelCount)
289 , m_countVoxelMaximum(0)
296 bool setVoxelIfInterpolationHigher(
const int32& index,
const t_data& toSet)
300 BASSERT(index < voxelCount);
302 const int8& currentInterpolation(
getVoxel(index).getInterpolation());
303 if (currentInterpolation >= toSet.getInterpolation())
311 bool setVoxelIfInterpolationHigherEqualZero(
const int32& index,
const t_data& toSet)
315 BASSERT(index < voxelCount);
317 const int8& currentInterpolation(
getVoxel(index).getInterpolation());
318 if (currentInterpolation >= 0)
326 bool setVoxelIfInterpolationLower(
const int32& index,
const t_data& toSet)
330 BASSERT(index < voxelCount);
332 const int8& currentInterpolation(
getVoxel(index).getInterpolation());
333 if (currentInterpolation <= toSet.getInterpolation())
348 bool setVoxel(
const int32& index,
const t_data& toSet)
352 BASSERT(index < voxelCount);
354 const t_data& currentVoxel(
getVoxel(index));
356 if (currentVoxel == toSet)
364 ++m_countVoxelInterpolationLargerZero;
370 --m_countVoxelInterpolationLargerZero;
375 ++m_countVoxelMinimum;
381 --m_countVoxelMinimum;
386 ++m_countVoxelMaximum;
392 --m_countVoxelMaximum;
397 m_voxels[index] = toSet;
403 BLUB_SERIALIZATION_ACCESS
405 template <
class formatType>
406 void serialize(formatType & readWrite,
const uint32& version)
408 using namespace serialization;
412 readWrite & nameValuePair::create(
"countVoxelMinimum", m_countVoxelMinimum);
413 readWrite & nameValuePair::create(
"countVoxelMaximum", m_countVoxelMaximum);
414 readWrite & nameValuePair::create(
"countVoxelLargerZero", m_countVoxelInterpolationLargerZero);
415 readWrite & nameValuePair::create(
"editing", m_editing);
416 readWrite & nameValuePair::create(
"changedVoxelBoundingBox", m_changedVoxelBoundingBox);
417 readWrite & nameValuePair::create(
"voxels", m_voxels);
421 t_voxelArray m_voxels;
423 int32 m_countVoxelInterpolationLargerZero;
424 int32 m_countVoxelMinimum;
425 int32 m_countVoxelMaximum;
433 #if defined(BOOST_NO_CXX11_CONSTEXPR)
434 template <
class voxelType>
435 const int32 container<voxelType>::voxelLength = t_config::voxelsPerTile;
436 template <
class voxelType>
437 const int32 container<voxelType>::voxelCount = voxelLength*voxelLength*voxelLength;
439 template <
class voxelType>
440 constexpr int32 container<voxelType>::voxelLength;
441 template <
class voxelType>
442 constexpr int32 container<voxelType>::voxelCount;
454 #endif // PROCEDURAL_VOXEL_TILE_CONTAINER_HPP
bool setVoxel(const int32 &index, const t_data &toSet)
setVoxel sets voxel to array and counts if voxel is maximum or minimum
Definition: container.hpp:348
const t_data & getVoxel(const int32 &index) const
getVoxel returns a copy of a local voxel.
Definition: container.hpp:184
Definition: customVertexInformation.cpp:193
const bool & getEditing() const
getEditing returns if editing is active.
Definition: container.hpp:83
const axisAlignedBoxInt32 & getEditedVoxelBoundingBox() const
getEditedVoxelBoundingBox returns an axisAlignedBox which describes the bounds of the voxel that chan...
Definition: container.hpp:92
void endEdit()
endEdit end edit
Definition: container.hpp:74
virtual ~container()
~container destructor.
Definition: container.hpp:58
const t_voxelArray & getVoxelArray(void) const
getVoxelArray returns reference voxel-array
Definition: container.hpp:194
const int32 & getCountVoxelMaximum() const
getCountVoxelMaximum returns number of voxel that are maximum.
Definition: container.hpp:231
void setFull()
setFull sets all voxel to max.
Definition: container.hpp:140
static int32 calculateIndex(const vector3int32 &pos)
calculateIndex convertes a 3d voxel-pos to a 1d array-index. 0 <= pos.xyz < voxelLength ...
Definition: container.hpp:204
The container class contains an array of voxel. The amount of voxel per tile is voxelLength^3. The class counts how many voxel are max and how many are min. if all voxel are min or max the class simple::container::base doesnt save them. Additionally it saves an axisAlignedBox which describes the bounds of the voxel that changed.
Definition: predecl.hpp:19
const int32 & getCountVoxelLargerZero() const
getCountVoxelLargerZero returns number of voxel not minimum.
Definition: container.hpp:220
Definition: sharedPointer.hpp:12
Definition: axisAlignedBoxInt32.hpp:12
static t_base::pointer create()
create creates an instance.
Definition: container.hpp:51
void setVoxel(const vector3int32 &pos, const t_data &toSet)
setVoxel sets an voxel to a local position. Extends changed axisAlignedBox-bounds and counts if voxel...
Definition: container.hpp:104
void operator=(const container &other)
operator = copy operator
Definition: container.hpp:273
void setEmpty()
setFull sets all voxel to max.
Definition: container.hpp:156
bool isMax() const
isMax checks if all values are maximum. See class description.
Definition: data.hpp:88
bool isFull() const
isFull returns true if all voxel are maximum.
Definition: container.hpp:264
container()
container constructor
Definition: container.hpp:285
bool isMin() const
isMin checks if all values are minimum. See class description.
Definition: data.hpp:97
bool isEmpty() const
isEmpty returns true if all voxel are minimum.
Definition: container.hpp:254
void startEdit()
startEdit resets the changed-voxel-bound-aab
Definition: container.hpp:65
t_data getVoxel(const vector3int32 &pos) const
getVoxel returns a copy of a local voxel.
Definition: container.hpp:174
int8 & getInterpolation()
getInterpolation returns reference to interpolation.
Definition: data.hpp:70
Definition: deadlineTimer.hpp:10
const int32 & getCountVoxelMinimum() const
getCountVoxelMinimum returns number of voxel that are minimum.
Definition: container.hpp:242
Definition: customVertexInformation.cpp:177