Files
CDAG/Research/core/OctreeBuilder/BaseOctreeBuilder.h

92 lines
3.6 KiB
C++

#pragma once
#ifndef GLM_FORCE_RADIANS
#define GLM_FORCE_RADIANS
#endif
#include <vector>
#include "../../inc/glm/glm.hpp"
#include "../../core/Defines.h"
struct VoxelInfo;
struct OctreeBuilderStatistics;
class BaseVoxelizer;
// BaseOctreeBuilder handles octree generation with any base voxelizer.
// Note that this class is abstract and will call several methods that any actual octree builder can implement.
class BaseOctreeBuilder
{
public:
BaseOctreeBuilder() :
mForceRebuild(false)
{}
virtual ~BaseOctreeBuilder() {}
// Given a voxelizer with a loaded scene, buil
OctreeBuilderStatistics BuildOctree(BaseVoxelizer& voxelizer, unsigned8 level, unsigned8 maxSingle);
virtual std::string GetTreeType() = 0;
void SetOutputFile(std::string outputFile) { mOutputFile = outputFile; }
std::string GetOutputFile() const { return mOutputFile; }\
void SetVerbose(bool verbose) { this->verbose = verbose; }
bool GetVerbose() const { return verbose; }
void SetForceRebuild(bool force) { mForceRebuild = force; }
bool GetForceRebuild() const { return mForceRebuild; }
protected:
virtual bool UsePreprocessing() const { return false; }
virtual bool RequiresColors() const = 0;
virtual bool RequiresNormals() const = 0;
virtual bool RequiresReflectivity() const = 0;
// Used to sort the subtrees for optimal building speed (some trees might be quicker to build in a certain order)
// Should return true if the first coord should go before the second
virtual bool SubTreeCompare(const glm::uvec3& coord1, const glm::uvec3& coord2) const;
// Functions to override for preprocessing
virtual bool CancelPreprocessing() { return false; }
virtual void InitPreprocessing() {}
virtual void InitCurPreprocessPass(glm::uvec3 coordinate) {}
virtual void PreProcessNode(const VoxelInfo& voxel) { printf("Warning: PreProcessNode() not implemented!"); }
virtual void PreProcessMissingNode(const VoxelInfo& voxel) {}
virtual void FinalizeCurPreprocessPass(glm::uvec3 coord) {}
virtual void FinalizePreprocessing() {}
// Functions to override for main tree building
virtual void InitTree() = 0;
virtual bool CancelCurPassTree(const glm::uvec3& coord) { return false; }
virtual void InitCurPassTree(glm::uvec3 coord) = 0;
virtual void AddNode(const VoxelInfo& voxel) = 0;
virtual void AddMissingNode(const VoxelInfo& voxel) = 0;
virtual void FinalizeCurPassTree(glm::uvec3 coord) = 0;
virtual void FinalizeTree() = 0;
virtual void TerminateTree() = 0;
virtual std::vector<size_t> GetOctreeNodesPerLevel() = 0;
virtual std::vector<size_t> GetNodesPerLevel() = 0;
// Some getters that are available during construction
// Returns "True" if this tree will be processed in a single pass
bool IsSinglePass() const { return maxSinglePassLayers >= maxTreeDepth; }
// Returns the depth of the main tree
unsigned8 GetTreeDepth() const { return maxTreeDepth; }
// Returns the maximum depth of a tree processing in a single pass
unsigned8 GetSinglePassTreeDepth() const { return maxTreeDepth < maxSinglePassLayers ? maxTreeDepth : maxSinglePassLayers; }
// Returns the level at which subtrees will be appended (e.g. TreeDepth - SinglePassTreeDepth)
unsigned8 GetAppendedTreeLevel() const { return IsSinglePass() ? 0 : (maxTreeDepth - maxSinglePassLayers); }
// Returns all coordinates that contain triangles in this scene.
const std::vector<glm::uvec3>& GetValidCoords() const { return mValidCoords; }
bool verbose;
private:
// Override cancelling of subtree building
bool mForceRebuild;
std::vector<glm::uvec3> mValidCoords;
std::string mOutputFile;
unsigned8 maxSinglePassLayers;
unsigned8 maxTreeDepth;
};