Files
CDAG/Research/scene/Octree/BaseTree.h

68 lines
2.6 KiB
C++

#pragma once
#include <deque>
#include <vector>
#include <string>
#include <unordered_map>
#include "../../core/Defines.h"
#include "Node.h"
class BaseTree
{
public:
BaseTree();
virtual ~BaseTree();
virtual const Node* GetNode(const unsigned32 index) const = 0;
virtual Node* GetNode(const unsigned32 index) = 0;
virtual unsigned32 GetNodeCount() const = 0;
virtual unsigned8 GetMaxLevel() const = 0;
virtual bool IsEmpty() const = 0;
virtual void Clear() = 0;
virtual Node* Create(unsigned8 level) = 0;
// Destroy the node at the given index. Note that this is not required to fix references to this node, so it is quite unsafe to call!
// This is only to save memory when, for example, moving nodes from one tree to the other
virtual void Destroy(unsigned32 index) = 0;
// Algorithms that can be done on any tree:
virtual void Shave(unsigned8 depth) = 0;
virtual std::vector<unsigned32> SortOnLevel() = 0;
// General information about the tree
virtual std::vector<size_t> GetParentCounts() const = 0;
virtual std::vector<size_t> GetNodesPerLevel() const = 0;
virtual std::vector<size_t> GetOctreeNodesPerLevel() const = 0;
virtual unsigned64 GetPointerCount() const = 0;
virtual void PrintDebugInfo() const = 0;
// Reading and writing to/from files
virtual bool ReadTree(const char* fileName) = 0;
virtual bool WriteTree(const char* fileName) = 0;
virtual bool VerifyTree(const char* fileName) = 0;
virtual bool ReadAdditionalPool(const char* fileName) = 0;
virtual bool WriteAdditionalPool(const char* fileName) = 0;
// Pool building information
virtual unsigned8 GetAdditionalTreeInfoSize() const = 0;
virtual std::vector<unsigned8> GetAdditionalTreeInfo(const std::vector<size_t>& nodePointers) const = 0;
virtual unsigned8 GetAdditionalBytesPerNode(unsigned8 level) const = 0;
virtual std::vector<unsigned8> GetAdditionalNodeBytes(const Node* node) const = 0;
virtual bool LastChildHasAdditionalBytes() const = 0;
virtual unsigned8 GetAdditionalBytesPerPointer(unsigned8 level) const = 0;
virtual std::vector<unsigned8> GetAdditionalPointerBytes(const Node* node, ChildIndex child) const = 0;
// Returns the number of bytes per pointer for each level as a vector
std::vector<unsigned8> GetAdditionalBytesPerPointer() const;
// Returns the number of bytes per node for each level as a vector.
std::vector<unsigned8> GetAdditionalBytesPerNode() const;
inline unsigned16 GetTreeIndex() const { return mTreeIndex; }
inline static BaseTree* Get(unsigned16 rootIndex) { return mTreePool[rootIndex]; }
private:
unsigned16 AssignRootIndex();
static std::vector<BaseTree*> mTreePool;
unsigned16 mTreeIndex;
};