mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
Code cleanup
Remove warnings from multiresvolume module
This commit is contained in:
@@ -22,16 +22,10 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <float.h>
|
||||
#include <map>
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
|
||||
#include <modules/multiresvolume/rendering/localerrorhistogrammanager.h>
|
||||
#include <openspace/util/histogram.h>
|
||||
|
||||
#include <modules/multiresvolume/rendering/tsp.h>
|
||||
#include <openspace/util/progressbar.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/fmt.h>
|
||||
|
||||
@@ -43,8 +37,6 @@ namespace openspace {
|
||||
|
||||
LocalErrorHistogramManager::LocalErrorHistogramManager(TSP* tsp) : _tsp(tsp) {}
|
||||
|
||||
LocalErrorHistogramManager::~LocalErrorHistogramManager() {}
|
||||
|
||||
bool LocalErrorHistogramManager::buildHistograms(int numBins) {
|
||||
LINFO(fmt::format("Build histograms with {} bins each", numBins));
|
||||
_numBins = numBins;
|
||||
@@ -53,12 +45,14 @@ bool LocalErrorHistogramManager::buildHistograms(int numBins) {
|
||||
if (!_file->is_open()) {
|
||||
return false;
|
||||
}
|
||||
_minBin = 0.0; // Should be calculated from tsp file
|
||||
_maxBin = 1.0; // Should be calculated from tsp file as (maxValue - minValue)
|
||||
_minBin = 0.f; // Should be calculated from tsp file
|
||||
_maxBin = 1.f; // Should be calculated from tsp file as (maxValue - minValue)
|
||||
|
||||
unsigned int numOtLevels = _tsp->numOTLevels();
|
||||
unsigned int numOtLeaves = pow(8, numOtLevels - 1);
|
||||
unsigned int numBstLeaves = pow(2, _tsp->numBSTLevels() - 1);
|
||||
const unsigned int numOtLevels = _tsp->numOTLevels();
|
||||
const unsigned int numOtLeaves = static_cast<unsigned int>(pow(8, numOtLevels - 1));
|
||||
const unsigned int numBstLeaves = static_cast<unsigned int>(
|
||||
pow(2, _tsp->numBSTLevels() - 1)
|
||||
);
|
||||
|
||||
_numInnerNodes = _tsp->numTotalNodes() - numOtLeaves * numBstLeaves;
|
||||
|
||||
@@ -70,13 +64,13 @@ bool LocalErrorHistogramManager::buildHistograms(int numBins) {
|
||||
}
|
||||
|
||||
// All TSP Leaves
|
||||
int numOtNodes = _tsp->numOTNodes();
|
||||
int otOffset = (pow(8, numOtLevels - 1) - 1) / 7;
|
||||
const int numOtNodes = _tsp->numOTNodes();
|
||||
const int otOffset = static_cast<int>((pow(8, numOtLevels - 1) - 1) / 7);
|
||||
|
||||
int numBstNodes = _tsp->numBSTNodes();
|
||||
int bstOffset = numBstNodes / 2;
|
||||
const int numBstNodes = _tsp->numBSTNodes();
|
||||
const int bstOffset = numBstNodes / 2;
|
||||
|
||||
int numberOfLeaves = numOtLeaves * numBstLeaves;
|
||||
const int numberOfLeaves = numOtLeaves * numBstLeaves;
|
||||
|
||||
LINFO("Building spatial histograms");
|
||||
ProgressBar pb1(numberOfLeaves);
|
||||
@@ -86,13 +80,15 @@ bool LocalErrorHistogramManager::buildHistograms(int numBins) {
|
||||
for (int bst = bstOffset; bst < numBstNodes; bst++) {
|
||||
for (int ot = otOffset; ot < numOtNodes; ot++) {
|
||||
success &= buildFromOctreeChild(bst, ot);
|
||||
if (!success) LERROR("Failed in buildFromOctreeChild");
|
||||
if (!success) return false;
|
||||
if (!success) {
|
||||
LERROR("Failed in buildFromOctreeChild");
|
||||
}
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
pb1.print(processedLeaves++);
|
||||
}
|
||||
}
|
||||
//pb1.stop();
|
||||
|
||||
|
||||
LINFO("Building temporal histograms");
|
||||
ProgressBar pb2(numberOfLeaves);
|
||||
@@ -101,35 +97,40 @@ bool LocalErrorHistogramManager::buildHistograms(int numBins) {
|
||||
for (int ot = otOffset; ot < numOtNodes; ot++) {
|
||||
for (int bst = bstOffset; bst < numBstNodes; bst++) {
|
||||
success &= buildFromBstChild(bst, ot);
|
||||
if (!success) LERROR("Failed in buildFromBstChild");
|
||||
if (!success) return false;
|
||||
if (!success) {
|
||||
LERROR("Failed in buildFromBstChild");
|
||||
}
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
pb2.print(processedLeaves++);
|
||||
}
|
||||
}
|
||||
//pb2.stop();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool LocalErrorHistogramManager::buildFromOctreeChild(unsigned int bstOffset, unsigned int octreeOffset) {
|
||||
bool LocalErrorHistogramManager::buildFromOctreeChild(unsigned int bstOffset,
|
||||
unsigned int octreeOffset)
|
||||
{
|
||||
// Add errors to octree parent histogram
|
||||
int numOtNodes = _tsp->numOTNodes();
|
||||
unsigned int childIndex = bstOffset * numOtNodes + octreeOffset;
|
||||
bool isOctreeLeaf = _tsp->isOctreeLeaf(childIndex);
|
||||
const int numOtNodes = _tsp->numOTNodes();
|
||||
const unsigned int childIndex = bstOffset * numOtNodes + octreeOffset;
|
||||
const bool isOctreeLeaf = _tsp->isOctreeLeaf(childIndex);
|
||||
|
||||
if (octreeOffset > 0) {
|
||||
// Not octree root
|
||||
std::vector<float> childValues;
|
||||
std::vector<float> parentValues;
|
||||
|
||||
int octreeParent = parentOffset(octreeOffset, 8);
|
||||
unsigned int parentIndex = bstOffset * numOtNodes + octreeParent;
|
||||
unsigned int parentInnerNodeIndex = brickToInnerNodeIndex(parentIndex);
|
||||
const int octreeParent = parentOffset(octreeOffset, 8);
|
||||
const unsigned int parentIndex = bstOffset * numOtNodes + octreeParent;
|
||||
const unsigned int parentInnerNodeIndex = brickToInnerNodeIndex(parentIndex);
|
||||
|
||||
if (isOctreeLeaf) {
|
||||
childValues = readValues(childIndex);
|
||||
} else {
|
||||
unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex);
|
||||
const unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex);
|
||||
auto it = _voxelCache.find(childInnerNodeIndex);
|
||||
if (it != _voxelCache.end()) {
|
||||
childValues = it->second;
|
||||
@@ -144,7 +145,7 @@ bool LocalErrorHistogramManager::buildFromOctreeChild(unsigned int bstOffset, un
|
||||
}
|
||||
}
|
||||
|
||||
int octreeChildIndex = (octreeOffset - 1) % 8;
|
||||
const int octreeChildIndex = (octreeOffset - 1) % 8;
|
||||
if (octreeChildIndex == 0) {
|
||||
parentValues = readValues(parentIndex);
|
||||
_voxelCache[parentInnerNodeIndex] = parentValues;
|
||||
@@ -159,62 +160,74 @@ bool LocalErrorHistogramManager::buildFromOctreeChild(unsigned int bstOffset, un
|
||||
}
|
||||
|
||||
// Compare values and add errors to parent histogram
|
||||
unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
unsigned int brickDim = _tsp->brickDim();
|
||||
unsigned int padding = (paddedBrickDim - brickDim) / 2;
|
||||
const unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
const int brickDim = static_cast<int>(_tsp->brickDim());
|
||||
const unsigned int padding = (paddedBrickDim - brickDim) / 2;
|
||||
|
||||
glm::vec3 parentOffset = glm::vec3(octreeChildIndex % 2, (octreeChildIndex / 2) % 2, octreeChildIndex / 4) * float(brickDim) / 2.f;
|
||||
glm::vec3 parentOffset = glm::vec3(
|
||||
octreeChildIndex % 2,
|
||||
(octreeChildIndex / 2) % 2,
|
||||
octreeChildIndex / 4
|
||||
) * (brickDim / 2.f);
|
||||
|
||||
for (int z = 0; z < brickDim; z++) {
|
||||
for (int y = 0; y < brickDim; y++) {
|
||||
for (int x = 0; x < brickDim; x++) {
|
||||
glm::vec3 childSamplePoint = glm::vec3(x, y, z) + glm::vec3(padding);
|
||||
glm::vec3 parentSamplePoint = parentOffset + (glm::vec3(x, y, z) + glm::vec3(0.5)) * 0.5f;
|
||||
glm::ivec3 childSamplePoint = glm::ivec3(x, y, z) +
|
||||
glm::ivec3(padding);
|
||||
glm::vec3 parentSamplePoint = parentOffset +
|
||||
glm::vec3(x + 0.5f, y + 0.5f, z + 0.5f) * 0.5f;
|
||||
float childValue = childValues[linearCoords(childSamplePoint)];
|
||||
float parentValue = interpolate(parentSamplePoint, parentValues);
|
||||
|
||||
// Divide by number of child voxels that will be taken into account
|
||||
float rectangleHeight = std::abs(childValue - parentValue) / 8.0;
|
||||
_spatialHistograms[parentInnerNodeIndex].addRectangle(childValue, parentValue, rectangleHeight);
|
||||
float rectangleHeight = std::abs(childValue - parentValue) / 8.f;
|
||||
_spatialHistograms[parentInnerNodeIndex].addRectangle(
|
||||
childValue,
|
||||
parentValue,
|
||||
rectangleHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isLastOctreeChild = octreeOffset > 0 && octreeChildIndex == 7;
|
||||
const bool isLastOctreeChild = octreeOffset > 0 && octreeChildIndex == 7;
|
||||
if (isLastOctreeChild) {
|
||||
buildFromOctreeChild(bstOffset, octreeParent);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOctreeLeaf) {
|
||||
unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex);
|
||||
const unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex);
|
||||
_voxelCache.erase(childInnerNodeIndex);
|
||||
}
|
||||
|
||||
int bstChildIndex = bstOffset % 2;
|
||||
bool isLastBstChild = bstOffset > 0 && bstChildIndex == 0;
|
||||
const int bstChildIndex = bstOffset % 2;
|
||||
const bool isLastBstChild = bstOffset > 0 && bstChildIndex == 0;
|
||||
if (isOctreeLeaf && isLastBstChild) {
|
||||
int bstParent = parentOffset(bstOffset, 2);
|
||||
const int bstParent = parentOffset(bstOffset, 2);
|
||||
buildFromOctreeChild(bstParent, octreeOffset);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset, unsigned int octreeOffset) {
|
||||
bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset,
|
||||
unsigned int octreeOffset)
|
||||
{
|
||||
// Add errors to bst parent histogram
|
||||
int numOtNodes = _tsp->numOTNodes();
|
||||
unsigned int childIndex = bstOffset * numOtNodes + octreeOffset;
|
||||
bool isBstLeaf = _tsp->isBstLeaf(childIndex);
|
||||
const int numOtNodes = _tsp->numOTNodes();
|
||||
const unsigned int childIndex = bstOffset * numOtNodes + octreeOffset;
|
||||
const bool isBstLeaf = _tsp->isBstLeaf(childIndex);
|
||||
|
||||
if (bstOffset > 0) {
|
||||
// Not BST root
|
||||
std::vector<float> childValues;
|
||||
std::vector<float> parentValues;
|
||||
|
||||
int bstParent = parentOffset(bstOffset, 2);
|
||||
unsigned int parentIndex = bstParent * numOtNodes + octreeOffset;
|
||||
unsigned int parentInnerNodeIndex = brickToInnerNodeIndex(parentIndex);
|
||||
const int bstParent = parentOffset(bstOffset, 2);
|
||||
const unsigned int parentIndex = bstParent * numOtNodes + octreeOffset;
|
||||
const unsigned int parentInnerNodeIndex = brickToInnerNodeIndex(parentIndex);
|
||||
|
||||
if (isBstLeaf) {
|
||||
childValues = readValues(childIndex);
|
||||
@@ -229,7 +242,7 @@ bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset, unsig
|
||||
}
|
||||
}
|
||||
|
||||
int bstChildIndex = bstOffset % 2;
|
||||
const int bstChildIndex = bstOffset % 2;
|
||||
if (bstChildIndex == 1) {
|
||||
parentValues = readValues(parentIndex);
|
||||
_voxelCache[parentInnerNodeIndex] = parentValues;
|
||||
@@ -244,40 +257,44 @@ bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset, unsig
|
||||
}
|
||||
|
||||
// Compare values and add errors to parent histogram
|
||||
unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
unsigned int brickDim = _tsp->brickDim();
|
||||
unsigned int padding = (paddedBrickDim - brickDim) / 2;
|
||||
const unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
const int brickDim = static_cast<int>(_tsp->brickDim());
|
||||
const unsigned int padding = (paddedBrickDim - brickDim) / 2;
|
||||
|
||||
for (int z = 0; z < brickDim; z++) {
|
||||
for (int y = 0; y < brickDim; y++) {
|
||||
for (int x = 0; x < brickDim; x++) {
|
||||
glm::vec3 samplePoint = glm::vec3(x, y, z) + glm::vec3(padding);
|
||||
glm::ivec3 samplePoint = glm::ivec3(x, y, z) + glm::ivec3(padding);
|
||||
unsigned int linearSamplePoint = linearCoords(samplePoint);
|
||||
float childValue = childValues[linearSamplePoint];
|
||||
float parentValue = parentValues[linearSamplePoint];
|
||||
|
||||
// Divide by number of child voxels that will be taken into account
|
||||
float rectangleHeight = std::abs(childValue - parentValue) / 2.0;
|
||||
_temporalHistograms[parentInnerNodeIndex].addRectangle(childValue, parentValue, rectangleHeight);
|
||||
float rectangleHeight = std::abs(childValue - parentValue) / 2.f;
|
||||
_temporalHistograms[parentInnerNodeIndex].addRectangle(
|
||||
childValue,
|
||||
parentValue,
|
||||
rectangleHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isLastBstChild = bstOffset > 0 && bstChildIndex == 0;
|
||||
const bool isLastBstChild = bstOffset > 0 && bstChildIndex == 0;
|
||||
if (isLastBstChild) {
|
||||
buildFromBstChild(bstParent, octreeOffset);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isBstLeaf) {
|
||||
unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex);
|
||||
const unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex);
|
||||
_voxelCache.erase(childInnerNodeIndex);
|
||||
}
|
||||
|
||||
int octreeChildIndex = (octreeOffset - 1) % 8;
|
||||
bool isLastOctreeChild = octreeOffset > 0 && octreeChildIndex == 7;
|
||||
const int octreeChildIndex = (octreeOffset - 1) % 8;
|
||||
const bool isLastOctreeChild = octreeOffset > 0 && octreeChildIndex == 7;
|
||||
if (isBstLeaf && isLastOctreeChild) {
|
||||
int octreeParent = parentOffset(octreeOffset, 8);
|
||||
const int octreeParent = parentOffset(octreeOffset, 8);
|
||||
buildFromBstChild(bstOffset, octreeParent);
|
||||
}
|
||||
|
||||
@@ -295,29 +312,29 @@ bool LocalErrorHistogramManager::loadFromFile(const std::string& filename) {
|
||||
file.read(reinterpret_cast<char*>(&_minBin), sizeof(float));
|
||||
file.read(reinterpret_cast<char*>(&_maxBin), sizeof(float));
|
||||
|
||||
int nFloats = _numInnerNodes * _numBins;
|
||||
float* histogramData = new float[nFloats];
|
||||
const int nFloats = _numInnerNodes * _numBins;
|
||||
std::vector<float> histogramData(nFloats);
|
||||
|
||||
file.read(reinterpret_cast<char*>(histogramData), sizeof(float) * nFloats);
|
||||
file.read(reinterpret_cast<char*>(histogramData.data()), sizeof(float) * nFloats);
|
||||
_spatialHistograms = std::vector<Histogram>(_numInnerNodes);
|
||||
for (int i = 0; i < _numInnerNodes; ++i) {
|
||||
int offset = i*_numBins;
|
||||
for (unsigned int i = 0; i < _numInnerNodes; ++i) {
|
||||
const int offset = i * _numBins;
|
||||
// No need to deallocate histogram data, since histograms take ownership.
|
||||
float* data = new float[_numBins];
|
||||
memcpy(data, &histogramData[offset], sizeof(float) * _numBins);
|
||||
_spatialHistograms[i] = Histogram(_minBin, _maxBin, _numBins, data);
|
||||
}
|
||||
|
||||
file.read(reinterpret_cast<char*>(histogramData), sizeof(float) * nFloats);
|
||||
file.read(reinterpret_cast<char*>(histogramData.data()), sizeof(float) * nFloats);
|
||||
_temporalHistograms = std::vector<Histogram>(_numInnerNodes);
|
||||
for (int i = 0; i < _numInnerNodes; ++i) {
|
||||
int offset = i*_numBins;
|
||||
for (unsigned int i = 0; i < _numInnerNodes; ++i) {
|
||||
const int offset = i * _numBins;
|
||||
// No need to deallocate histogram data, since histograms take ownership.
|
||||
float* data = new float[_numBins];
|
||||
memcpy(data, &histogramData[offset], sizeof(float) * _numBins);
|
||||
_temporalHistograms[i] = Histogram(_minBin, _maxBin, _numBins, data);
|
||||
}
|
||||
|
||||
delete[] histogramData;
|
||||
// No need to deallocate histogram data, since histograms take ownership.
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
@@ -334,22 +351,28 @@ bool LocalErrorHistogramManager::saveToFile(const std::string& filename) {
|
||||
file.write(reinterpret_cast<char*>(&_minBin), sizeof(float));
|
||||
file.write(reinterpret_cast<char*>(&_maxBin), sizeof(float));
|
||||
|
||||
int nFloats = _numInnerNodes * _numBins;
|
||||
float* histogramData = new float[nFloats];
|
||||
const int nFloats = _numInnerNodes * _numBins;
|
||||
std::vector<float> histogramData(nFloats);
|
||||
|
||||
for (int i = 0; i < _numInnerNodes; ++i) {
|
||||
int offset = i*_numBins;
|
||||
memcpy(&histogramData[offset], _spatialHistograms[i].data(), sizeof(float) * _numBins);
|
||||
for (unsigned int i = 0; i < _numInnerNodes; ++i) {
|
||||
int offset = i * _numBins;
|
||||
memcpy(
|
||||
&histogramData[offset],
|
||||
_spatialHistograms[i].data(),
|
||||
sizeof(float) * _numBins
|
||||
);
|
||||
}
|
||||
file.write(reinterpret_cast<char*>(histogramData), sizeof(float) * nFloats);
|
||||
file.write(reinterpret_cast<char*>(histogramData.data()), sizeof(float) * nFloats);
|
||||
|
||||
for (int i = 0; i < _numInnerNodes; ++i) {
|
||||
int offset = i*_numBins;
|
||||
memcpy(&histogramData[offset], _temporalHistograms[i].data(), sizeof(float) * _numBins);
|
||||
for (unsigned int i = 0; i < _numInnerNodes; ++i) {
|
||||
int offset = i * _numBins;
|
||||
memcpy(
|
||||
&histogramData[offset],
|
||||
_temporalHistograms[i].data(),
|
||||
sizeof(float) * _numBins
|
||||
);
|
||||
}
|
||||
file.write(reinterpret_cast<char*>(histogramData), sizeof(float) * nFloats);
|
||||
|
||||
delete[] histogramData;
|
||||
file.write(reinterpret_cast<char*>(histogramData.data()), sizeof(float) * nFloats);
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
@@ -365,45 +388,49 @@ unsigned int LocalErrorHistogramManager::linearCoords(int x, int y, int z) const
|
||||
|
||||
unsigned int LocalErrorHistogramManager::linearCoords(glm::ivec3 coords) const {
|
||||
unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
return coords.z * paddedBrickDim * paddedBrickDim + coords.y * paddedBrickDim + coords.x;
|
||||
return coords.z * paddedBrickDim * paddedBrickDim + coords.y * paddedBrickDim +
|
||||
coords.x;
|
||||
}
|
||||
|
||||
float LocalErrorHistogramManager::interpolate(glm::vec3 samplePoint, const std::vector<float>& voxels) const {
|
||||
int lowX = samplePoint.x;
|
||||
int lowY = samplePoint.y;
|
||||
int lowZ = samplePoint.z;
|
||||
float LocalErrorHistogramManager::interpolate(glm::vec3 samplePoint,
|
||||
const std::vector<float>& voxels) const
|
||||
{
|
||||
const int lowX = static_cast<int>(samplePoint.x);
|
||||
const int lowY = static_cast<int>(samplePoint.y);
|
||||
const int lowZ = static_cast<int>(samplePoint.z);
|
||||
|
||||
int highX = ceil(samplePoint.x);
|
||||
int highY = ceil(samplePoint.y);
|
||||
int highZ = ceil(samplePoint.z);
|
||||
const int highX = static_cast<int>(ceil(samplePoint.x));
|
||||
const int highY = static_cast<int>(ceil(samplePoint.y));
|
||||
const int highZ = static_cast<int>(ceil(samplePoint.z));
|
||||
|
||||
float interpolatorX = 1.0 - (samplePoint.x - lowX);
|
||||
float interpolatorY = 1.0 - (samplePoint.y - lowY);
|
||||
float interpolatorZ = 1.0 - (samplePoint.z - lowZ);
|
||||
const float interpolatorX = 1.f - (samplePoint.x - lowX);
|
||||
const float interpolatorY = 1.f - (samplePoint.y - lowY);
|
||||
const float interpolatorZ = 1.f - (samplePoint.z - lowZ);
|
||||
|
||||
float v000 = voxels[linearCoords(lowX, lowY, lowZ)];
|
||||
float v001 = voxels[linearCoords(lowX, lowY, highZ)];
|
||||
float v010 = voxels[linearCoords(lowX, highY, lowZ)];
|
||||
float v011 = voxels[linearCoords(lowX, highY, highZ)];
|
||||
float v100 = voxels[linearCoords(highX, lowY, lowZ)];
|
||||
float v101 = voxels[linearCoords(highX, lowY, highZ)];
|
||||
float v110 = voxels[linearCoords(highX, highY, lowZ)];
|
||||
float v111 = voxels[linearCoords(highX, highY, highZ)];
|
||||
const float v000 = voxels[linearCoords(lowX, lowY, lowZ)];
|
||||
const float v001 = voxels[linearCoords(lowX, lowY, highZ)];
|
||||
const float v010 = voxels[linearCoords(lowX, highY, lowZ)];
|
||||
const float v011 = voxels[linearCoords(lowX, highY, highZ)];
|
||||
const float v100 = voxels[linearCoords(highX, lowY, lowZ)];
|
||||
const float v101 = voxels[linearCoords(highX, lowY, highZ)];
|
||||
const float v110 = voxels[linearCoords(highX, highY, lowZ)];
|
||||
const float v111 = voxels[linearCoords(highX, highY, highZ)];
|
||||
|
||||
float v00 = interpolatorZ * v000 + (1.0 - interpolatorZ) * v001;
|
||||
float v01 = interpolatorZ * v010 + (1.0 - interpolatorZ) * v011;
|
||||
float v10 = interpolatorZ * v100 + (1.0 - interpolatorZ) * v101;
|
||||
float v11 = interpolatorZ * v110 + (1.0 - interpolatorZ) * v111;
|
||||
const float v00 = interpolatorZ * v000 + (1.f - interpolatorZ) * v001;
|
||||
const float v01 = interpolatorZ * v010 + (1.f - interpolatorZ) * v011;
|
||||
const float v10 = interpolatorZ * v100 + (1.f - interpolatorZ) * v101;
|
||||
const float v11 = interpolatorZ * v110 + (1.f - interpolatorZ) * v111;
|
||||
|
||||
float v0 = interpolatorY * v00 + (1.0 - interpolatorY) * v01;
|
||||
float v1 = interpolatorY * v10 + (1.0 - interpolatorY) * v11;
|
||||
|
||||
return interpolatorX * v0 + (1.0 - interpolatorX) * v1;
|
||||
const float v0 = interpolatorY * v00 + (1.f - interpolatorY) * v01;
|
||||
const float v1 = interpolatorY * v10 + (1.f - interpolatorY) * v11;
|
||||
|
||||
return interpolatorX * v0 + (1.f - interpolatorX) * v1;
|
||||
}
|
||||
|
||||
const Histogram* LocalErrorHistogramManager::getSpatialHistogram(unsigned int brickIndex) const {
|
||||
unsigned int innerNodeIndex = brickToInnerNodeIndex(brickIndex);
|
||||
const Histogram* LocalErrorHistogramManager::spatialHistogram(
|
||||
unsigned int brickIndex) const
|
||||
{
|
||||
const unsigned int innerNodeIndex = brickToInnerNodeIndex(brickIndex);
|
||||
if (innerNodeIndex < _numInnerNodes) {
|
||||
return &(_spatialHistograms[innerNodeIndex]);
|
||||
} else {
|
||||
@@ -411,8 +438,10 @@ const Histogram* LocalErrorHistogramManager::getSpatialHistogram(unsigned int br
|
||||
}
|
||||
}
|
||||
|
||||
const Histogram* LocalErrorHistogramManager::getTemporalHistogram(unsigned int brickIndex) const {
|
||||
unsigned int innerNodeIndex = brickToInnerNodeIndex(brickIndex);
|
||||
const Histogram* LocalErrorHistogramManager::temporalHistogram(
|
||||
unsigned int brickIndex) const
|
||||
{
|
||||
const unsigned int innerNodeIndex = brickToInnerNodeIndex(brickIndex);
|
||||
if (innerNodeIndex < _numInnerNodes) {
|
||||
return &(_temporalHistograms[innerNodeIndex]);
|
||||
} else {
|
||||
@@ -424,70 +453,93 @@ int LocalErrorHistogramManager::parentOffset(int offset, int base) const {
|
||||
if (offset == 0) {
|
||||
return -1;
|
||||
}
|
||||
int depth = floor(log(((base - 1) * offset + 1.0)) / log(base));
|
||||
int firstInLevel = (pow(base, depth) - 1) / (base - 1);
|
||||
int inLevelOffset = offset - firstInLevel;
|
||||
const int depth = static_cast<int>(
|
||||
floor(log(((base - 1) * offset + 1.0)) / log(base))
|
||||
);
|
||||
const int firstInLevel = static_cast<int>((pow(base, depth) - 1) / (base - 1));
|
||||
const int inLevelOffset = offset - firstInLevel;
|
||||
|
||||
int parentDepth = depth - 1;
|
||||
int firstInParentLevel = (pow(base, parentDepth) - 1) / (base - 1);
|
||||
int parentInLevelOffset = inLevelOffset / base;
|
||||
const int parentDepth = depth - 1;
|
||||
const int firstInParentLevel = static_cast<int>(
|
||||
(pow(base, parentDepth) - 1) / (base - 1)
|
||||
);
|
||||
const int parentInLevelOffset = inLevelOffset / base;
|
||||
|
||||
int parentOffset = firstInParentLevel + parentInLevelOffset;
|
||||
const int parentOffset = firstInParentLevel + parentInLevelOffset;
|
||||
return parentOffset;
|
||||
}
|
||||
|
||||
std::vector<float> LocalErrorHistogramManager::readValues(unsigned int brickIndex) const {
|
||||
unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
unsigned int numBrickVals = paddedBrickDim * paddedBrickDim * paddedBrickDim;
|
||||
const unsigned int paddedBrickDim = _tsp->paddedBrickDim();
|
||||
const unsigned int numBrickVals = paddedBrickDim * paddedBrickDim * paddedBrickDim;
|
||||
std::vector<float> voxelValues(numBrickVals);
|
||||
|
||||
std::streampos offset = _tsp->dataPosition() + static_cast<long long>(brickIndex*numBrickVals*sizeof(float));
|
||||
std::streampos offset = _tsp->dataPosition() +
|
||||
static_cast<long long>(brickIndex*numBrickVals*sizeof(float));
|
||||
_file->seekg(offset);
|
||||
|
||||
_file->read(reinterpret_cast<char*>(&voxelValues[0]),
|
||||
static_cast<size_t>(numBrickVals)*sizeof(float));
|
||||
_file->read(
|
||||
reinterpret_cast<char*>(voxelValues.data()),
|
||||
static_cast<size_t>(numBrickVals)*sizeof(float)
|
||||
);
|
||||
|
||||
return voxelValues;
|
||||
}
|
||||
|
||||
unsigned int LocalErrorHistogramManager::brickToInnerNodeIndex(unsigned int brickIndex) const {
|
||||
unsigned int numOtNodes = _tsp->numOTNodes();
|
||||
unsigned int numBstLevels = _tsp->numBSTLevels();
|
||||
unsigned int LocalErrorHistogramManager::brickToInnerNodeIndex(
|
||||
unsigned int brickIndex) const
|
||||
{
|
||||
const unsigned int numOtNodes = _tsp->numOTNodes();
|
||||
const unsigned int numBstLevels = _tsp->numBSTLevels();
|
||||
const unsigned int numInnerBstNodes = static_cast<unsigned int>(
|
||||
(pow(2, numBstLevels - 1) - 1) * numOtNodes
|
||||
);
|
||||
if (brickIndex < numInnerBstNodes) {
|
||||
return brickIndex;
|
||||
}
|
||||
|
||||
unsigned int numInnerBstNodes = (pow(2, numBstLevels - 1) - 1) * numOtNodes;
|
||||
if (brickIndex < numInnerBstNodes) return brickIndex;
|
||||
const unsigned int numOtLeaves = static_cast<unsigned int>(
|
||||
pow(8, _tsp->numOTLevels() - 1)
|
||||
);
|
||||
const unsigned int numOtInnerNodes = (numOtNodes - numOtLeaves);
|
||||
|
||||
unsigned int numOtLeaves = pow(8, _tsp->numOTLevels() - 1);
|
||||
unsigned int numOtInnerNodes = (numOtNodes - numOtLeaves);
|
||||
const unsigned int innerBstOffset = brickIndex - numInnerBstNodes;
|
||||
const unsigned int rowIndex = innerBstOffset / numOtNodes;
|
||||
const unsigned int indexInRow = innerBstOffset % numOtNodes;
|
||||
|
||||
unsigned int innerBstOffset = brickIndex - numInnerBstNodes;
|
||||
unsigned int rowIndex = innerBstOffset / numOtNodes;
|
||||
unsigned int indexInRow = innerBstOffset % numOtNodes;
|
||||
if (indexInRow >= numOtInnerNodes) {
|
||||
return _numInnerNodes;
|
||||
}
|
||||
|
||||
if (indexInRow >= numOtInnerNodes) return _numInnerNodes;
|
||||
|
||||
unsigned int offset = rowIndex * numOtInnerNodes;
|
||||
unsigned int leavesOffset = offset + indexInRow;
|
||||
const unsigned int offset = rowIndex * numOtInnerNodes;
|
||||
const unsigned int leavesOffset = offset + indexInRow;
|
||||
|
||||
return numInnerBstNodes + leavesOffset;
|
||||
}
|
||||
|
||||
unsigned int LocalErrorHistogramManager::innerNodeToBrickIndex(unsigned int innerNodeIndex) const {
|
||||
unsigned int numOtNodes = _tsp->numOTNodes();
|
||||
unsigned int numBstLevels = _tsp->numBSTLevels();
|
||||
unsigned int LocalErrorHistogramManager::innerNodeToBrickIndex(
|
||||
unsigned int innerNodeIndex) const
|
||||
{
|
||||
const unsigned int numOtNodes = _tsp->numOTNodes();
|
||||
const unsigned int numBstLevels = _tsp->numBSTLevels();
|
||||
const unsigned int numInnerBstNodes = static_cast<unsigned int>(
|
||||
(pow(2, numBstLevels - 1) - 1) * numOtNodes
|
||||
);
|
||||
if (innerNodeIndex < numInnerBstNodes) {
|
||||
return innerNodeIndex;
|
||||
}
|
||||
|
||||
unsigned int numInnerBstNodes = (pow(2, numBstLevels - 1) - 1) * numOtNodes;
|
||||
if (innerNodeIndex < numInnerBstNodes) return innerNodeIndex;
|
||||
const unsigned int numOtLeaves = static_cast<unsigned int>(
|
||||
pow(8, _tsp->numOTLevels() - 1)
|
||||
);
|
||||
const unsigned int numOtInnerNodes = (numOtNodes - numOtLeaves);
|
||||
|
||||
unsigned int numOtLeaves = pow(8, _tsp->numOTLevels() - 1);
|
||||
unsigned int numOtInnerNodes = (numOtNodes - numOtLeaves);
|
||||
const unsigned int innerBstOffset = innerNodeIndex - numInnerBstNodes;
|
||||
const unsigned int rowIndex = innerBstOffset / numOtInnerNodes;
|
||||
const unsigned int indexInRow = innerBstOffset % numOtInnerNodes;
|
||||
|
||||
unsigned int innerBstOffset = innerNodeIndex - numInnerBstNodes;
|
||||
unsigned int rowIndex = innerBstOffset / numOtInnerNodes;
|
||||
unsigned int indexInRow = innerBstOffset % numOtInnerNodes;
|
||||
|
||||
unsigned int offset = rowIndex * numOtNodes;
|
||||
unsigned int leavesOffset = offset + indexInRow;
|
||||
const unsigned int offset = rowIndex * numOtNodes;
|
||||
const unsigned int leavesOffset = offset + indexInRow;
|
||||
|
||||
return numInnerBstNodes + leavesOffset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user