From 396e1fea300ce21321965dfb3d95269800dd8167 Mon Sep 17 00:00:00 2001 From: p265186 Date: Thu, 12 Jan 2012 14:50:53 +0100 Subject: [PATCH] Refactoring of basic voxel types. --- library/PolyVoxCore/CMakeLists.txt | 1 + .../PolyVoxCore/include/PolyVoxCore/Density.h | 6 +- .../include/PolyVoxCore/Material.h | 6 +- .../include/PolyVoxCore/MaterialDensityPair.h | 4 +- .../PolyVoxCore/include/PolyVoxCore/Voxel.h | 57 +++++++++++++++++++ 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/Voxel.h diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 8a4574f8..0b6c3ff1 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -70,6 +70,7 @@ SET(CORE_INC_FILES include/PolyVoxCore/VertexTypes.h include/PolyVoxCore/VolumeResampler.h include/PolyVoxCore/VolumeResampler.inl + include/PolyVoxCore/Voxel.h include/PolyVoxCore/VoxelFilters.h ) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 308310bb..eefdb370 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Density_H__ #define __PolyVox_Density_H__ +#include "PolyVoxCore/Voxel.h" + #include "PolyVoxImpl/TypeDef.h" #include @@ -44,7 +46,7 @@ namespace PolyVox /// \sa Material, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// template - class Density + class Density : public Voxel { public: //We expose DensityType and MaterialType in this way so that, when code is @@ -52,7 +54,7 @@ namespace PolyVox //using code such as 'VoxelType::DensityType value = voxel.getDensity()' //or 'VoxelType::MaterialType value = voxel.getMaterial()'. typedef Type DensityType; - typedef uint8_t MaterialType; + typedef uint8_t MaterialType; //Shouldn't define this one... Density() : m_uDensity(0) {} Density(DensityType uDensity) : m_uDensity(uDensity) {} diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 390dfd71..5c331cf5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Material_H__ #define __PolyVox_Material_H__ +#include "PolyVoxCore/Voxel.h" + #include "PolyVoxImpl/TypeDef.h" #include @@ -44,14 +46,14 @@ namespace PolyVox /// \sa Density, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// template - class Material + class Material : public Voxel { public: //We expose DensityType and MaterialType in this way so that, when code is //templatised on voxel type, it can determine the underlying storage type //using code such as 'VoxelType::DensityType value = voxel.getDensity()' //or 'VoxelType::MaterialType value = voxel.getMaterial()'. - typedef uint8_t DensityType; + typedef uint8_t DensityType; //Shouldn't define this one... typedef Type MaterialType; Material() : m_uMaterial(0) {} diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 663eded5..45a3433c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_MaterialDensityPair_H__ #define __PolyVox_MaterialDensityPair_H__ +#include "PolyVoxCore/Voxel.h" + #include "PolyVoxImpl/TypeDef.h" namespace PolyVox @@ -43,7 +45,7 @@ namespace PolyVox /// \sa Density, Material //////////////////////////////////////////////////////////////////////////////// template - class MaterialDensityPair + class MaterialDensityPair : public Voxel { public: //We expose DensityType and MaterialType in this way so that, when code is diff --git a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h new file mode 100644 index 00000000..d9d70454 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h @@ -0,0 +1,57 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_Voxel_H__ +#define __PolyVox_Voxel_H__ + +#include "PolyVoxImpl/TypeDef.h" + +#include +#include + +namespace PolyVox +{ + /// This class represents a voxel + //////////////////////////////////////////////////////////////////////////////// + /// Detailed description... + //////////////////////////////////////////////////////////////////////////////// + template + class Voxel + { + public: + //We expose DensityType and MaterialType in this way so that, when code is + //templatised on voxel type, it can determine the underlying storage type + //using code such as 'VoxelType::DensityType value = voxel.getDensity()' + //or 'VoxelType::MaterialType value = voxel.getMaterial()'. + typedef DenType DensityType; + typedef MatType MaterialType; + + DensityType getDensity() const throw() { assert(false); return 0; } + MaterialType getMaterial() const throw() { assert(false); return 0; } + + void setDensity(DensityType uDensity) { assert(false); } + void setMaterial(MaterialType /*uMaterial*/) { assert(false); } + }; +} + +#endif //__PolyVox_Voxel_H__