Hunting down some bugs and verfiying correct oct-tree traversal, not quite there yet but close

This commit is contained in:
MitchellHansen
2017-03-21 22:05:23 -07:00
parent 5e222a0331
commit 30959128e4
6 changed files with 102 additions and 79 deletions

View File

@@ -1,7 +1,5 @@
#include "Map.h"
void SetBit(int position, char* c) {
*c |= (uint64_t)1 << position;
}
@@ -70,33 +68,38 @@ bool IsLeaf(const uint64_t descriptor) {
Map::Map(sf::Vector3i position) {
srand(time(NULL));
load_unload(position);
for (int i = 0; i < OCT_DIM * OCT_DIM * OCT_DIM; i++) {
if (rand() % 8 > 2)
if (rand() % 2 == 1)
voxel_data[i] = 0;
else
voxel_data[i] = 1;
}
voxel_data[0 + OCT_DIM * (0 + OCT_DIM * 0)] = 1;
}
uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
uint64_t Map::generate_children(sf::Vector3i pos, int voxel_scale) {
// The 8 subvoxel coords starting from the 1th direction, the direction of the origin of the 3d grid
// XY, Z++, XY
std::vector<sf::Vector3i> v = {
sf::Vector3i(pos.x , pos.y , pos.z),
sf::Vector3i(pos.x + dim, pos.y , pos.z),
sf::Vector3i(pos.x , pos.y + dim, pos.z),
sf::Vector3i(pos.x + dim, pos.y + dim, pos.z),
sf::Vector3i(pos.x , pos.y , pos.z + dim),
sf::Vector3i(pos.x + dim, pos.y , pos.z + dim),
sf::Vector3i(pos.x , pos.y + dim, pos.z + dim),
sf::Vector3i(pos.x + dim, pos.y + dim, pos.z + dim)
sf::Vector3i(pos.x + voxel_scale, pos.y , pos.z),
sf::Vector3i(pos.x , pos.y + voxel_scale, pos.z),
sf::Vector3i(pos.x + voxel_scale, pos.y + voxel_scale, pos.z),
sf::Vector3i(pos.x , pos.y , pos.z + voxel_scale),
sf::Vector3i(pos.x + voxel_scale, pos.y , pos.z + voxel_scale),
sf::Vector3i(pos.x , pos.y + voxel_scale, pos.z + voxel_scale),
sf::Vector3i(pos.x + voxel_scale, pos.y + voxel_scale, pos.z + voxel_scale)
};
if (dim == 1) {
if (voxel_scale == 1) {
// Return the base 2x2 leaf node
uint64_t tmp = 0;
@@ -126,10 +129,11 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
for (int i = 0; i < v.size(); i++) {
// Get the child descriptor from the i'th to 8th subvoxel
child = generate_children(v.at(i), dim / 2);
child = generate_children(v.at(i), voxel_scale / 2);
PrettyPrintUINT64(child, &ss);
ss << " " << dim << " " << counter++ << std::endl;
//
PrettyPrintUINT64(child, &output_stream);
output_stream << " " << voxel_scale << " " << counter++ << std::endl;
if (IsLeaf(child)) {
if (CheckLeafSign(child))
@@ -168,8 +172,8 @@ void Map::generate_octree() {
uint64_t root_node = generate_children(sf::Vector3i(0, 0, 0), OCT_DIM/2);
uint64_t tmp = 0;
PrettyPrintUINT64(root_node, &ss);
ss << " " << OCT_DIM << " " << counter++ << std::endl;
PrettyPrintUINT64(root_node, &output_stream);
output_stream << " " << OCT_DIM << " " << counter++ << std::endl;
if (IsLeaf(root_node)) {
if (CheckLeafSign(root_node))
@@ -185,7 +189,7 @@ void Map::generate_octree() {
tmp |= a.copy_to_stack(std::vector<uint64_t>{root_node});
DumpLog(&ss, "raw_output.txt");
DumpLog(&output_stream, "raw_output.txt");
a.print_block(0);
@@ -246,7 +250,35 @@ char Map::getVoxelFromOctree(sf::Vector3i position)
return a.get_voxel(position);
}
char Map::getVoxel(sf::Vector3i pos){
bool Map::getVoxel(sf::Vector3i pos){
if (voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)]) {
return true;
} else {
return false;
}
}
void Map::test_map() {
for (int x = 0; x < OCT_DIM; x++) {
for (int y = 0; y < OCT_DIM; y++) {
for (int z = 0; z < OCT_DIM; z++) {
sf::Vector3i pos(x, y, z);
bool arr1 = getVoxel(pos);
bool arr2 = getVoxelFromOctree(pos);
if (arr1 != arr2) {
std::cout << "MISMATCH" << std::endl;
}
}
}
}
std::cout << "\nGOOD" << std::endl;
return voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)];
}

View File

@@ -93,10 +93,13 @@ int main() {
// ni.stop_listening_for_clients();
// =============================
// Map _map(sf::Vector3i(0, 0, 0));
// _map.generate_octree();
// _map.a.get_voxel(sf::Vector3i(5, 5, 0));
// return 0;
Map _map(sf::Vector3i(0, 0, 0));
_map.generate_octree();
std::cout << _map.a.get_voxel(sf::Vector3i(5, 5, 0));
std::cout << _map.getVoxel(sf::Vector3i(5, 5, 0));
_map.test_map();
std::cin.get();
return 0;
// =============================
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");

View File

@@ -11,7 +11,6 @@ Hardware_Caster::~Hardware_Caster() {
int Hardware_Caster::init() {
// Initialize opencl up to the point where we start assigning buffers
error = acquire_platform_and_device();
if(vr_assert(error, "aquire_platform_and_device"))
return error;
@@ -316,6 +315,7 @@ int Hardware_Caster::acquire_platform_and_device() {
clGetDeviceInfo(d.id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &d.comp_units, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_EXTENSIONS, 1024, &d.extensions, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_NAME, 256, &d.name, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_ENDIAN_LITTLE, sizeof(cl_bool), &d.is_little_endian, NULL);
std::cout << "Device: " << q << std::endl;
std::cout << "Device Name : " << d.name << std::endl;
@@ -335,6 +335,7 @@ int Hardware_Caster::acquire_platform_and_device() {
std::cout << "Max clock frequency : " << d.clock_frequency << std::endl;
std::cout << "Max compute units : " << d.comp_units << std::endl;
std::cout << "Is little endian : " << std::boolalpha << static_cast<bool>(d.is_little_endian) << std::endl;
std::cout << "cl_khr_gl_sharing supported: ";
if (std::string(d.extensions).find("cl_khr_gl_sharing") == std::string::npos &&