From ddc54e0862ce5d8e3e4ee53afc2f68becc588f78 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 20 Sep 2011 18:38:13 +0100 Subject: [PATCH 1/3] Raycast now track previous voxel, for working out which direction you came from. --- library/PolyVoxCore/include/PolyVoxCore/Raycast.h | 1 + library/PolyVoxCore/include/PolyVoxCore/Raycast.inl | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index b94cf5f8..860f4efb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h @@ -41,6 +41,7 @@ namespace PolyVox bool foundIntersection; ///If an intersection was found then this field holds the intersecting voxel, otherwise it is undefined. Vector3DInt32 intersectionVoxel; + Vector3DInt32 previousVoxel; }; /// The Raycast class can be used to find the fist filled voxel along a given path. diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl index fb0f99ef..43da1dc9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl @@ -134,6 +134,7 @@ namespace PolyVox float deltatz = 1.0f / abs(z2 - z1); m_sampVolume.setPosition(i,j,k); + m_result.previousVoxel = Vector3DInt32(i,j,k); for(;;) { @@ -143,7 +144,7 @@ namespace PolyVox m_result.intersectionVoxel = Vector3DInt32(i,j,k); return; } - + m_result.previousVoxel = Vector3DInt32(i,j,k); if(tx <= ty && tx <= tz) { if(i == iend) break; @@ -174,5 +175,6 @@ namespace PolyVox //Didn't hit anything m_result.foundIntersection = false; m_result.intersectionVoxel = Vector3DInt32(0,0,0); + m_result.previousVoxel = Vector3DInt32(0,0,0); } } \ No newline at end of file From 7bbdb1a29d37e67ddaadc9831ffcb0a19193d711 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 24 Sep 2011 11:02:01 +0100 Subject: [PATCH 2/3] Added equality/inequality tests for vector and region. --- .../PolyVoxCore/include/PolyVoxCore/Region.h | 5 +++ .../PolyVoxCore/include/PolyVoxCore/Vector.h | 2 + .../include/PolyVoxCore/Vector.inl | 12 ++++++ library/PolyVoxCore/source/Region.cpp | 22 ++++++++++ tests/CMakeLists.txt | 5 +++ tests/TestRegion.cpp | 42 +++++++++++++++++++ tests/TestRegion.h | 37 ++++++++++++++++ tests/testvector.cpp | 8 ++++ tests/testvector.h | 1 + 9 files changed, 134 insertions(+) create mode 100644 tests/TestRegion.cpp create mode 100644 tests/TestRegion.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 3668d847..5c91390c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -44,6 +44,11 @@ namespace PolyVox Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner); Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ); + ///Equality Operator. + bool operator==(const Region& rhs) const throw(); + ///Inequality Operator. + bool operator!=(const Region& rhs) const throw(); + const Vector3DInt32& getLowerCorner(void) const; const Vector3DInt32& getUpperCorner(void) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.h b/library/PolyVoxCore/include/PolyVoxCore/Vector.h index 1269fe73..cbcdb6ec 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.h @@ -81,6 +81,8 @@ namespace PolyVox Vector& operator=(const Vector& rhs) throw(); ///Equality Operator. bool operator==(const Vector& rhs) const throw(); + ///Inequality Operator. + bool operator!=(const Vector& rhs) const throw(); ///Comparison Operator. bool operator<(const Vector& rhs) const throw(); ///Addition and Assignment Operator. diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index bd9dd88e..b6d92c15 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -150,6 +150,18 @@ namespace PolyVox return equal; } + /** + Checks whether two Vectors are not equal. + \param rhs The Vector to compare to. + \return true if the Vectors do not match. + \see operator== + */ + template + inline bool Vector::operator!=(const Vector &rhs) const throw() + { + return !(*this == rhs); //Just call equality operator and invert the result. + } + /** Checks whether this vector is less than the parameter. The metric is meaningless but it allows Vectors to me used as key in sdt::map, etc. diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index fcb4f6fd..436265b0 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -60,6 +60,28 @@ namespace PolyVox assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ()); } + /** + Checks whether two Regions are equal. + \param rhs The Region to compare to. + \return true if the Regions match. + \see operator!= + */ + bool Region::operator==(const Region& rhs) const throw() + { + return ((m_v3dLowerCorner == rhs.m_v3dLowerCorner) && (m_v3dUpperCorner == rhs.m_v3dUpperCorner)); + } + + /** + Checks whether two Regions are not equal. + \param rhs The Region to compare to. + \return true if the Regions do not match. + \see operator== + */ + bool Region::operator!=(const Region& rhs) const throw() + { + return !(*this == rhs); + } + const Vector3DInt32& Region::getLowerCorner(void) const { return m_v3dLowerCorner; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 299ed23c..db002c91 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,10 +59,15 @@ ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize) CREATE_TEST(testmaterial.h testmaterial.cpp testmaterial) ADD_TEST(MaterialTestCompile ${LATEST_TEST} testCompile) +# Region tests +CREATE_TEST(TestRegion.h TestRegion.cpp TestRegion) +ADD_TEST(RegionEqualityTest ${LATEST_TEST} testEquality) + #Vector tests CREATE_TEST(testvector.h testvector.cpp testvector) ADD_TEST(VectorLengthTest ${LATEST_TEST} testLength) ADD_TEST(VectorDotProductTest ${LATEST_TEST} testDotProduct) +ADD_TEST(VectorEqualityTest ${LATEST_TEST} testEquality) # Volume subclass tests CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass) diff --git a/tests/TestRegion.cpp b/tests/TestRegion.cpp new file mode 100644 index 00000000..a0f74913 --- /dev/null +++ b/tests/TestRegion.cpp @@ -0,0 +1,42 @@ +/******************************************************************************* +Copyright (c) 2010 Matt 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. +*******************************************************************************/ + +#include "TestRegion.h" + +#include "PolyVoxCore/Region.h" + +#include + +using namespace PolyVox; + +void TestRegion::testEquality() +{ + Region reg1(1,2,3,4,5,6); + Region reg2(0,0,0,10,20,30); + Region reg3(Vector3DInt32(1,2,3), Vector3DInt32(4,5,6)); + + QCOMPARE(reg1 != reg2, true); + QCOMPARE(reg1 == reg3, true); +} + +QTEST_MAIN(TestRegion) diff --git a/tests/TestRegion.h b/tests/TestRegion.h new file mode 100644 index 00000000..be3c29de --- /dev/null +++ b/tests/TestRegion.h @@ -0,0 +1,37 @@ +/******************************************************************************* +Copyright (c) 2010 Matt 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_TestRegion_H__ +#define __PolyVox_TestRegion_H__ + +#include + +class TestRegion: public QObject +{ + Q_OBJECT + + private slots: + void testEquality(); +}; + +#endif diff --git a/tests/testvector.cpp b/tests/testvector.cpp index 4f75bff6..0239bd0f 100644 --- a/tests/testvector.cpp +++ b/tests/testvector.cpp @@ -43,4 +43,12 @@ void TestVector::testDotProduct() QCOMPARE(vecxy.dot(vecz), int8_t(0)); //QCOMPARE is very strict on the types matching } +void TestVector::testEquality() +{ + Vector3DInt8 vecxy(3, 4, 0); + Vector3DInt8 vecz(0, 0, 1); + + QCOMPARE(vecxy != vecz, true); +} + QTEST_MAIN(TestVector) diff --git a/tests/testvector.h b/tests/testvector.h index f9aa2746..baad1e3d 100644 --- a/tests/testvector.h +++ b/tests/testvector.h @@ -33,6 +33,7 @@ class TestVector: public QObject private slots: void testLength(); void testDotProduct(); + void testEquality(); }; #endif From 6a267b5b8d1f585187a54fe7996c93cb51007466 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 25 Sep 2011 12:52:00 +0100 Subject: [PATCH 3/3] Fixed some compile warnings (thanks to Gnurfos). --- library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index 24b8178d..c206c850 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -27,8 +27,8 @@ namespace PolyVox SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result) :m_volData(volData) ,m_sampVolume(volData) - ,m_regSizeInVoxels(region) ,m_meshCurrent(result) + ,m_regSizeInVoxels(region) { //m_regSizeInVoxels.cropTo(m_volData->getEnclosingRegion()); m_regSizeInCells = m_regSizeInVoxels; @@ -524,7 +524,6 @@ namespace PolyVox //Current position const uint32_t uXRegSpace = m_sampVolume.getPosX() - m_regSizeInVoxels.getLowerCorner().getX(); const uint32_t uYRegSpace = m_sampVolume.getPosY() - m_regSizeInVoxels.getLowerCorner().getY(); - const uint32_t uZRegSpace = m_sampVolume.getPosZ() - m_regSizeInVoxels.getLowerCorner().getZ(); //Determine the index into the edge table which tells us which vertices are inside of the surface uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace]; @@ -618,4 +617,4 @@ namespace PolyVox }//For each cell } } -} \ No newline at end of file +}