Raycast and ambient occlusion tests now use primitive types instead of Material/Density classes.

This commit is contained in:
unknown 2012-03-27 14:32:33 +02:00
parent 6d656ad173
commit 0e16b0d07e
3 changed files with 17 additions and 21 deletions

View File

@ -31,9 +31,11 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Region.h" #include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Raycast.h" #include "PolyVoxCore/Raycast.h"
//These two should not be here! #if defined(_MSC_VER)
#include "PolyVoxCore/Material.h" //These two should not be here!
#include "PolyVoxCore/SimpleVolume.h" #include "PolyVoxCore/Material.h"
#include "PolyVoxCore/SimpleVolume.h"
#endif
#include <algorithm> #include <algorithm>

View File

@ -24,16 +24,15 @@ freely, subject to the following restrictions:
#include "TestAmbientOcclusionGenerator.h" #include "TestAmbientOcclusionGenerator.h"
#include "PolyVoxCore/AmbientOcclusionCalculator.h" #include "PolyVoxCore/AmbientOcclusionCalculator.h"
#include "PolyVoxCore/Material.h"
#include "PolyVoxCore/SimpleVolume.h" #include "PolyVoxCore/SimpleVolume.h"
#include <QtTest> #include <QtTest>
using namespace PolyVox; using namespace PolyVox;
bool isVoxelTransparent(Material8 voxel) bool isVoxelTransparent(uint8_t voxel)
{ {
return voxel.getMaterial() == 0; return voxel == 0;
} }
void TestAmbientOcclusionGenerator::testExecute() void TestAmbientOcclusionGenerator::testExecute()
@ -41,7 +40,7 @@ void TestAmbientOcclusionGenerator::testExecute()
const int32_t g_uVolumeSideLength = 64; const int32_t g_uVolumeSideLength = 64;
//Create empty volume //Create empty volume
SimpleVolume<Material8> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1))); SimpleVolume<uint8_t> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)));
//Create two solid walls at opposite sides of the volume //Create two solid walls at opposite sides of the volume
for (int32_t z = 0; z < g_uVolumeSideLength; z++) for (int32_t z = 0; z < g_uVolumeSideLength; z++)
@ -52,8 +51,7 @@ void TestAmbientOcclusionGenerator::testExecute()
{ {
for (int32_t x = 0; x < g_uVolumeSideLength; x++) for (int32_t x = 0; x < g_uVolumeSideLength; x++)
{ {
Material8 voxel(1); volData.setVoxelAt(x, y, z, 1);
volData.setVoxelAt(x, y, z, voxel);
} }
} }
} }
@ -64,7 +62,7 @@ void TestAmbientOcclusionGenerator::testExecute()
Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength)); Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength));
//Create the ambient occlusion calculator //Create the ambient occlusion calculator
AmbientOcclusionCalculator<SimpleVolume, Material8> calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent); AmbientOcclusionCalculator<SimpleVolume, uint8_t> calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent);
//Execute the calculator //Execute the calculator
calculator.execute(); calculator.execute();

View File

@ -33,9 +33,9 @@ freely, subject to the following restrictions:
using namespace PolyVox; using namespace PolyVox;
bool isPassableByRay(const SimpleVolume<Density8>::Sampler& sampler) bool isPassableByRay(const SimpleVolume<int8_t>::Sampler& sampler)
{ {
return sampler.getVoxel().getDensity() < Density8::getThreshold(); return sampler.getVoxel() <= 0;
} }
void TestRaycast::testExecute() void TestRaycast::testExecute()
@ -43,25 +43,21 @@ void TestRaycast::testExecute()
const int32_t uVolumeSideLength = 32; const int32_t uVolumeSideLength = 32;
//Create a hollow volume, with solid sides on x and y but with open ends in z. //Create a hollow volume, with solid sides on x and y but with open ends in z.
SimpleVolume<Density8> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1))); SimpleVolume<int8_t> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1)));
for (int32_t z = 0; z < uVolumeSideLength; z++) for (int32_t z = 0; z < uVolumeSideLength; z++)
{ {
for (int32_t y = 0; y < uVolumeSideLength; y++) for (int32_t y = 0; y < uVolumeSideLength; y++)
{ {
for (int32_t x = 0; x < uVolumeSideLength; x++) for (int32_t x = 0; x < uVolumeSideLength; x++)
{ {
Density8 voxelValue;
if((x == 0) || (x == uVolumeSideLength-1) || (y == 0) || (y == uVolumeSideLength-1)) if((x == 0) || (x == uVolumeSideLength-1) || (y == 0) || (y == uVolumeSideLength-1))
{ {
voxelValue.setDensity(255); volData.setVoxelAt(x, y, z, 100);
} }
else else
{ {
voxelValue.setDensity(0); volData.setVoxelAt(x, y, z, -100);
} }
volData.setVoxelAt(x, y, z, voxelValue);
} }
} }
} }
@ -72,7 +68,7 @@ void TestRaycast::testExecute()
for(int ct = 0; ct < 1000000; ct++) for(int ct = 0; ct < 1000000; ct++)
{ {
RaycastResult result; RaycastResult result;
Raycast<SimpleVolume, Density8> raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay); Raycast<SimpleVolume, int8_t> raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay);
raycast.execute(); raycast.execute();
if(result.foundIntersection) if(result.foundIntersection)
{ {