Added some debug functions

master
MitchellHansen 8 years ago
parent 97545e6cec
commit 8a9237ce50

@ -58,6 +58,11 @@ public:
// if not, allocate a new block and paste them at the bottom // if not, allocate a new block and paste them at the bottom
// Make sure to reset the position // Make sure to reset the position
for (int i = 0; i < children.size(); i++) {
if (children.at(i) == 0)
abort();
}
// Copy the children on the stack, bottom up, first node to last // Copy the children on the stack, bottom up, first node to last
memcpy(&dat[stack_pos], children.data(), children.size() * sizeof(int64_t)); memcpy(&dat[stack_pos], children.data(), children.size() * sizeof(int64_t));
stack_pos -= children.size(); stack_pos -= children.size();
@ -100,7 +105,12 @@ protected:
private: private:
// DEBUG
int counter = 0; int counter = 0;
std::stringstream ss;
// !DEBUG
uint64_t generate_children(sf::Vector3i pos, int dim); uint64_t generate_children(sf::Vector3i pos, int dim);
int cycle_counter = 0; int cycle_counter = 0;

@ -6,6 +6,7 @@
#include <sstream> #include <sstream>
#include "Vector4.hpp" #include "Vector4.hpp"
#include <bitset> #include <bitset>
#include <string>
const double PI = 3.141592653589793238463; const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f; const float PI_F = 3.14159265358979f;
@ -172,6 +173,16 @@ inline std::string read_file(std::string file_name){
return buf.str(); return buf.str();
} }
inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) {
*ss << "[" << std::bitset<15>(i) << "]";
*ss << "[" << std::bitset<1>(i >> 15) << "]";
*ss << "[" << std::bitset<8>(i >> 16) << "]";
*ss << "[" << std::bitset<8>(i >> 24) << "]";
*ss << "[" << std::bitset<32>(i >> 32) << "]";
}
inline void PrettyPrintUINT64(uint64_t i) { inline void PrettyPrintUINT64(uint64_t i) {
std::cout << "[" << std::bitset<15>(i) << "]"; std::cout << "[" << std::bitset<15>(i) << "]";
@ -181,3 +192,14 @@ inline void PrettyPrintUINT64(uint64_t i) {
std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl;
} }
inline void DumpLog(std::stringstream* ss, std::string file_name) {
std::ofstream log_file;
log_file.open(file_name);
log_file << ss->str();
log_file.close();
}

@ -137,7 +137,8 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
// Get the child descriptor from the i'th to 8th subvoxel // 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), dim / 2);
PrettyPrintUINT64(child); PrettyPrintUINT64(child, &ss);
ss << " " << dim << " " << counter++ << std::endl;
if (IsLeaf(child)) { if (IsLeaf(child)) {
if (CheckLeafSign(child)) if (CheckLeafSign(child))
@ -150,20 +151,13 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
SetBit(i + 16, &tmp); SetBit(i + 16, &tmp);
children.push_back(child); children.push_back(child);
} }
PrettyPrintUINT64(tmp);
} }
// Now put those values onto the block stack, it returns the // Now put those values onto the block stack, it returns the
// 16 bit topmost pointer to the block. The 16th bit being // 16 bit topmost pointer to the block. The 16th bit being
// a switch to jump to a far pointer. // a switch to jump to a far pointer.
PrettyPrintUINT64(tmp);
tmp |= a.copy_to_stack(children); tmp |= a.copy_to_stack(children);
std::cout << counter++ << std::endl;
if ((tmp & 0xFFFFFFFF00000000) != 0) { if ((tmp & 0xFFFFFFFF00000000) != 0) {
PrettyPrintUINT64(tmp & 0xFFFFFFFF00000000);
PrettyPrintUINT64(tmp);
abort(); abort();
} }
@ -179,6 +173,14 @@ void Map::generate_octree() {
generate_children(sf::Vector3i(0, 0, 0), OCT_DIM); generate_children(sf::Vector3i(0, 0, 0), OCT_DIM);
DumpLog(&ss, "raw_output.txt");
std::stringstream sss;
for (int i = 0; i < (int)pow(2, 15); i++) {
PrettyPrintUINT64(a.dat[i], &sss);
sss << "\n";
}
DumpLog(&sss, "raw_data.txt");
/*for (int i = 32767; i >= 31767; i--) { /*for (int i = 32767; i >= 31767; i--) {
std::cout << i; PrettyPrintUINT64(a.dat[i]); std::cout << i; PrettyPrintUINT64(a.dat[i]);
}*/ }*/

Loading…
Cancel
Save