Commit 4defcfe5 authored by Samuel Bastos de Souza Junior's avatar Samuel Bastos de Souza Junior
Browse files

commit do dia kk

parent b2c0d894
...@@ -183,8 +183,24 @@ void Octree::checkVolume(std::vector<std::vector<uint32_t>>& volume) ...@@ -183,8 +183,24 @@ void Octree::checkVolume(std::vector<std::vector<uint32_t>>& volume)
} }
void Octree::generateTree() void Octree::generateTree(IO::Volume data)
{ {
_data = data;
_dataP = std::vector<unsigned int>(_data.data.size());
for (unsigned int i = 0; i < 33; i++) {
for (unsigned int j = 0; j < 33; j++) {
for (unsigned int k = 0; k < 33; k++) {
unsigned int index = lin(i, j, k);
unsigned int value = 0;
if (_data.data[index] < 0.5)
value = 0;
else
value = 1;
_dataP[index] = value;
}
}
}
createNode(1, 0); createNode(1, 0);
std::cout << _table.size(); std::cout << _table.size();
return; return;
...@@ -213,28 +229,34 @@ void Octree::createNode(uint32_t key, int level) ...@@ -213,28 +229,34 @@ void Octree::createNode(uint32_t key, int level)
bool Octree::divideNode(uint32_t key, int level) bool Octree::divideNode(uint32_t key, int level)
{ {
// if(level >= 3) if(key == 1)
// return false; return true;
//
// return true;
for(unsigned int i = level; i >= 0; i--) if(level >= 3)
{ return false;
unsigned int aux = key >> (3*level);
unsigned int octant = aux & 7;
unsigned int x, y, z; unsigned int ci = 0, cj = 0, ck = 0;
unsigned int dem = pow2(i); findCoord(key, level, ci, cj, ck);
if(hasComplexEdge(ci, cj, ck, level))
return true;
else
std::cout << "oi";
x = (octant & 1) * 32/dem; return false;
y = ((octant & 2) >> 1) * 32/dem;
z = ((octant & 4) >> 2) * 32/dem;
}
} }
void Octree::translate(unsigned int octant, int level, int& x, int& y, int& z) void Octree::findCoord(uint32_t key, int level, unsigned int& ci, unsigned int& cj, unsigned int& ck)
{ {
for(unsigned int i = 1; i <= level; i++)
{
unsigned int aux = key >> (3*(i-1));
unsigned int octant = aux & 7;
unsigned int dem = 32/(pow2(i));
ci += (octant & 1) * dem;
cj += ((octant & 2) >> 1) * dem;
ck += ((octant & 4) >> 2) * dem;
}
} }
unsigned int Octree::pow2(unsigned int pot) unsigned int Octree::pow2(unsigned int pot)
...@@ -243,4 +265,229 @@ unsigned int Octree::pow2(unsigned int pot) ...@@ -243,4 +265,229 @@ unsigned int Octree::pow2(unsigned int pot)
for(unsigned int i = 0; i < pot; i++) for(unsigned int i = 0; i < pot; i++)
n *= 2; n *= 2;
return n; return n;
}
// USA MESMA CONVENÇAO DE ARESTAS DO DMC
bool Octree::hasComplexEdge(unsigned int ci, unsigned int cj, unsigned int ck, int level)
{
int change = 0;
unsigned int limit = 32/(pow2(level));
unsigned int aux = _dataP[lin(ci, cj, ck)];
// EDGE 0
for(unsigned int i = ci + 1; i < ci + limit; i++)
{
unsigned int current = _dataP[lin(i, cj, ck)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 2
change = 0;
aux = _dataP[lin(ci, cj + limit, ck)];
for(unsigned int i = ci + 1; i < ci + limit; i++)
{
unsigned int current = _dataP[lin(i, cj + limit, ck)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 8
change = 0;
aux = _dataP[lin(ci, cj, ck + limit)];
for(unsigned int i = ci + 1; i < ci + limit; i++)
{
unsigned int current = _dataP[lin(i, cj, ck + limit)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 10
change = 0;
aux = _dataP[lin(ci, cj + limit, ck + limit)];
for(unsigned int i = ci + 1; i < ci + limit; i++)
{
unsigned int current = _dataP[lin(i, cj + limit, ck + limit)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 3
change = 0;
aux = _dataP[lin(ci, cj, ck)];
for(unsigned int j = cj + 1; j < cj + limit; j++)
{
unsigned int current = _dataP[lin(ci, j, ck)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 3
change = 0;
aux = _dataP[lin(ci + limit, cj, ck)];
for(unsigned int j = cj + 1; j < cj + limit; j++)
{
unsigned int current = _dataP[lin(ci + limit, j, ck)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 11
change = 0;
aux = _dataP[lin(ci, cj, ck + limit)];
for(unsigned int j = cj + 1; j < cj + limit; j++)
{
unsigned int current = _dataP[lin(ci, j, ck + limit)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 9
change = 0;
aux = _dataP[lin(ci + limit, cj, ck + limit)];
for(unsigned int j = cj + 1; j < cj + limit; j++)
{
unsigned int current = _dataP[lin(ci + limit, j, ck + limit)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 4
change = 0;
aux = _dataP[lin(ci, cj, ck)];
for(unsigned int k = ck + 1; k < ck + limit; k++)
{
unsigned int current = _dataP[lin(ci, cj, k)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 5
change = 0;
aux = _dataP[lin(ci + limit, cj, ck)];
for(unsigned int k = ck + 1; k < ck + limit; k++)
{
unsigned int current = _dataP[lin(ci + limit, cj, k)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 6
change = 0;
aux = _dataP[lin(ci + limit, cj + limit, ck)];
for(unsigned int k = ck + 1; k < ck + limit; k++)
{
unsigned int current = _dataP[lin(ci + limit, cj + limit, k)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
// EDGE 7
change = 0;
aux = _dataP[lin(ci, cj + limit, ck)];
for(unsigned int k = ck + 1; k < ck + limit; k++)
{
unsigned int current = _dataP[lin(ci, cj + limit, k)];
if(current != aux)
if(change == 1)
return true;
else
change++;
aux = current;
}
return false;
}
unsigned int Octree::lin(unsigned int const x,
unsigned int const y,
unsigned int const z)
{
if(x < 0 || y < 0 || z < 0)
return -1;
if(x >= 33 || y >= 33 || z >= 33)
return -1;
return x + 33 * (y + 33 * z);
}
void Octree::printData()
{
for(unsigned int k = 0; k < 33; k++)
{
for (unsigned int j = 0; j < 33; j++)
{
for (unsigned int i = 0; i < 33; i++)
{
unsigned int index = lin(i,j,k);
std::cout << _dataP[index];
}
std::cout << std::endl;
}
std::cout << std::endl;
}
} }
\ No newline at end of file
#pragma once #pragma once
#include <map> #include <map>
#include <vector> #include <vector>
#include "IO.h"
class Octree { class Octree {
public: public:
...@@ -16,14 +18,22 @@ public: ...@@ -16,14 +18,22 @@ public:
bool nodeExists(uint32_t key); bool nodeExists(uint32_t key);
void checkVolume(std::vector<std::vector<uint32_t>>& volume); void checkVolume(std::vector<std::vector<uint32_t>>& volume);
void getCenter(uint32_t key, float x, float y); void getCenter(uint32_t key, float x, float y);
void generateTree(); void generateTree(IO::Volume data);
void createNode(uint32_t key, int level); void createNode(uint32_t key, int level);
bool divideNode(uint32_t key, int level); bool divideNode(uint32_t key, int level);
void translate(unsigned int octant, int level, int& x, int& y, int& z); void findCoord(uint32_t key, int level, unsigned int& x, unsigned int& y, unsigned int& z);
unsigned int pow2(unsigned int pot); unsigned int pow2(unsigned int pot);
bool hasComplexEdge(unsigned int ci, unsigned int cj, unsigned int ck, int level);
unsigned int lin(unsigned int const x,
unsigned int const y,
unsigned int const z);
void printData();
private: private:
int _depth; int _depth;
std::map<uint32_t, int> _table; std::map<uint32_t, int> _table;
std::map<uint32_t, int> _vtable; std::map<uint32_t, int> _vtable;
IO::Volume _data;
std::vector<unsigned int> _dataP;
}; };
\ No newline at end of file
#include <iostream> #include <iostream>
#include "Octree.h" #include "Octree.h"
#include "IO.h"
int main() int main()
{ {
IO::Volume volume; IO::Volume volume;
IO::loadRawFile(volume, "/home/samuel/CLionProjects/dual-octree-home/cube.raw", 32, 32, 32); IO::loadRawFile(volume, "/home/sambsj/CLionProjects/octree/cube.raw", 32, 32, 32);
IO::extrapolateVolume(volume); IO::extrapolateVolume(volume);
Octree octree; Octree octree;
octree.generateTree(); octree.generateTree(volume);
//octree.setParameters(2); //octree.printData();
//octree.simulateTree();
// std::vector<int8_t> vertices;
// std::vector<int> levels;
// int level;
// octree.leaf2vert(0b01000111, level, vertices, levels);
// vertices.clear();
// octree.vert2leaf(0b01001110, 2, 2, vertices);
std::vector<std::vector<uint32_t>> dualVol; std::vector<std::vector<uint32_t>> dualVol;
octree.preprocess(); octree.preprocess();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment