|
| 1 | +// Copyright Contributors to the OpenVDB Project |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +#ifndef OPENVDB_ADAPTIVE_ADAPTIVE_GRID_HAS_BEEN_INCLUDED |
| 5 | +#define OPENVDB_ADAPTIVE_ADAPTIVE_GRID_HAS_BEEN_INCLUDED |
| 6 | + |
| 7 | +#include <openvdb/version.h> |
| 8 | +#include <openvdb/Grid.h> |
| 9 | +#include <openvdb/tree/Tree.h> |
| 10 | + |
| 11 | + |
| 12 | +namespace openvdb { |
| 13 | +OPENVDB_USE_VERSION_NAMESPACE |
| 14 | +namespace OPENVDB_VERSION_NAME { |
| 15 | + |
| 16 | + |
| 17 | +//////////////////////////////////////// |
| 18 | + |
| 19 | + |
| 20 | +namespace adaptive { |
| 21 | + |
| 22 | + |
| 23 | +template<typename _ValueType> |
| 24 | +class AdaptiveTree final: public TreeBase |
| 25 | +{ |
| 26 | +public: |
| 27 | + using Ptr = SharedPtr<AdaptiveTree>; |
| 28 | + using ConstPtr = SharedPtr<const AdaptiveTree>; |
| 29 | + |
| 30 | + using ValueType = _ValueType; |
| 31 | + using BuildType = _ValueType; |
| 32 | + |
| 33 | + static const Index DEPTH = 1; |
| 34 | + |
| 35 | + AdaptiveTree() = default; |
| 36 | + |
| 37 | + AdaptiveTree& operator=(const AdaptiveTree&) = delete; // disallow assignment |
| 38 | + |
| 39 | + /// Deep copy constructor |
| 40 | + AdaptiveTree(const AdaptiveTree& other): TreeBase(other), mBackground(other.mBackground) { } |
| 41 | + |
| 42 | + /// Empty tree constructor |
| 43 | + AdaptiveTree(const ValueType& background): mBackground(background) { } |
| 44 | + |
| 45 | + ~AdaptiveTree() override = default; |
| 46 | + |
| 47 | + /// Return the name of this type of tree. |
| 48 | + static const Name& treeType(); |
| 49 | + |
| 50 | + /// Return the name of this tree's type. |
| 51 | + const Name& type() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 52 | + |
| 53 | + /// Return the name of the type of a voxel's value (e.g., "float" or "vec3d"). |
| 54 | + Name valueType() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 55 | + |
| 56 | + /// Return @c true if this tree is of the same type as the template parameter. |
| 57 | + template<typename TreeType> |
| 58 | + bool isType() const { return (this->type() == TreeType::treeType()); } |
| 59 | + |
| 60 | + /// Return a pointer to a deep copy of this tree |
| 61 | + TreeBase::Ptr copy() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 62 | + |
| 63 | + /// @brief Return this tree's background value. |
| 64 | + const ValueType& background() const { return mBackground; } |
| 65 | + |
| 66 | + /// @brief Return @c true if this tree contains no nodes. |
| 67 | + bool empty() const { return true; } |
| 68 | + |
| 69 | + /// Remove all nodes. |
| 70 | + void clear() { } |
| 71 | + |
| 72 | + /// @brief Not implemented. |
| 73 | + void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) { OPENVDB_THROW(NotImplementedError, ""); } |
| 74 | + |
| 75 | + /// @brief Not implemented. |
| 76 | + void clip(const CoordBBox&) { OPENVDB_THROW(NotImplementedError, ""); } |
| 77 | + |
| 78 | + // |
| 79 | + // Tree methods |
| 80 | + // |
| 81 | + |
| 82 | + /// @brief Return in @a bbox the axis-aligned bounding box of all |
| 83 | + /// active tiles and leaf nodes with active values. |
| 84 | + /// @details This is faster than calling evalActiveVoxelBoundingBox, |
| 85 | + /// which visits the individual active voxels, and hence |
| 86 | + /// evalLeafBoundingBox produces a less tight, i.e. approximate, bbox. |
| 87 | + /// @return @c false if the bounding box is empty (in which case |
| 88 | + /// the bbox is set to its default value). |
| 89 | + bool evalLeafBoundingBox(CoordBBox& /*bbox*/) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 90 | + |
| 91 | + /// @brief Return in @a dim the dimensions of the axis-aligned bounding box |
| 92 | + /// of all leaf nodes. |
| 93 | + /// @return @c false if the bounding box is empty. |
| 94 | + bool evalLeafDim(Coord& /*dim*/) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 95 | + |
| 96 | + /// @brief Return in @a bbox the axis-aligned bounding box of all |
| 97 | + /// active voxels and tiles. |
| 98 | + /// @details This method produces a more accurate, i.e. tighter, |
| 99 | + /// bounding box than evalLeafBoundingBox which is approximate but |
| 100 | + /// faster. |
| 101 | + /// @return @c false if the bounding box is empty (in which case |
| 102 | + /// the bbox is set to its default value). |
| 103 | + bool evalActiveVoxelBoundingBox(CoordBBox& /*bbox*/) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 104 | + |
| 105 | + /// @brief Return in @a dim the dimensions of the axis-aligned bounding box of all |
| 106 | + /// active voxels. This is a tighter bounding box than the leaf node bounding box. |
| 107 | + /// @return @c false if the bounding box is empty. |
| 108 | + bool evalActiveVoxelDim(Coord& /*dim*/) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 109 | + |
| 110 | + void getIndexRange(CoordBBox& /*bbox*/) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 111 | + |
| 112 | + /// @brief Replace with background tiles any nodes whose voxel buffers |
| 113 | + /// have not yet been allocated. |
| 114 | + /// @details Typically, unallocated nodes are leaf nodes whose voxel buffers |
| 115 | + /// are not yet resident in memory because delayed loading is in effect. |
| 116 | + /// @sa readNonresidentBuffers, io::File::open |
| 117 | + void clipUnallocatedNodes() override { OPENVDB_THROW(NotImplementedError, ""); } |
| 118 | + /// Return the total number of unallocated leaf nodes residing in this tree. |
| 119 | + Index32 unallocatedLeafCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 120 | + |
| 121 | + |
| 122 | + // |
| 123 | + // Statistics |
| 124 | + // |
| 125 | + /// @brief Return the depth of this tree. |
| 126 | + /// |
| 127 | + /// A tree with only a root node and leaf nodes has depth 2, for example. |
| 128 | + Index treeDepth() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 129 | + /// Return the number of leaf nodes. |
| 130 | + Index32 leafCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 131 | + /// Return a vector with node counts. The number of nodes of type NodeType |
| 132 | + /// is given as element NodeType::LEVEL in the return vector. Thus, the size |
| 133 | + /// of this vector corresponds to the height (or depth) of this tree. |
| 134 | + std::vector<Index32> nodeCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 135 | + /// Return the number of non-leaf nodes. |
| 136 | + Index32 nonLeafCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 137 | + /// Return the number of active voxels stored in leaf nodes. |
| 138 | + Index64 activeLeafVoxelCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 139 | + /// Return the number of inactive voxels stored in leaf nodes. |
| 140 | + Index64 inactiveLeafVoxelCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 141 | + /// Return the total number of active voxels. |
| 142 | + Index64 activeVoxelCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 143 | + /// Return the number of inactive voxels within the bounding box of all active voxels. |
| 144 | + Index64 inactiveVoxelCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 145 | + /// Return the total number of active tiles. |
| 146 | + Index64 activeTileCount() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 147 | + |
| 148 | + |
| 149 | + // |
| 150 | + // I/O methods |
| 151 | + // |
| 152 | + /// Read all data buffers for this tree. |
| 153 | + void readBuffers(std::istream&, bool /*saveFloatAsHalf*/ = false) override { OPENVDB_THROW(NotImplementedError, ""); } |
| 154 | + /// Read all of this tree's data buffers that intersect the given bounding box. |
| 155 | + void readBuffers(std::istream&, const CoordBBox&, bool /*saveFloatAsHalf*/ = false) override { OPENVDB_THROW(NotImplementedError, ""); } |
| 156 | + /// @brief Read all of this tree's data buffers that are not yet resident in memory |
| 157 | + /// (because delayed loading is in effect). |
| 158 | + /// @details If this tree was read from a memory-mapped file, this operation |
| 159 | + /// disconnects the tree from the file. |
| 160 | + /// @sa clipUnallocatedNodes, io::File::open, io::MappedFile |
| 161 | + void readNonresidentBuffers() const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 162 | + /// Write out all the data buffers for this tree. |
| 163 | + void writeBuffers(std::ostream&, bool /*saveFloatAsHalf*/ = false) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 164 | + |
| 165 | + /// @brief Print statistics, memory usage and other information about this tree. |
| 166 | + /// @param os a stream to which to write textual information |
| 167 | + /// @param verboseLevel 1: print tree configuration only; |
| 168 | + /// 2: include node and voxel statistics; |
| 169 | + /// 3: include memory usage; |
| 170 | + /// 4: include minimum and maximum voxel values |
| 171 | + /// @warning @a verboseLevel 4 forces loading of any unallocated nodes. |
| 172 | + void print(std::ostream& /*os*/ = std::cout, int /*verboseLevel*/ = 1) const override { OPENVDB_THROW(NotImplementedError, ""); } |
| 173 | + |
| 174 | + /// @brief Dummy declarations to keep Grid class happy |
| 175 | + using LeafNodeType = void; |
| 176 | + using ValueAllIter = void; |
| 177 | + using ValueAllCIter = void; |
| 178 | + using ValueOnIter = void; |
| 179 | + using ValueOnCIter = void; |
| 180 | + using ValueOffIter = void; |
| 181 | + using ValueOffCIter = void; |
| 182 | + |
| 183 | +private: |
| 184 | + ValueType mBackground = zeroVal<ValueType>(); |
| 185 | +}; // class AdaptiveTree |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | +//////////////////////////////////////// |
| 190 | + |
| 191 | + |
| 192 | +template<typename ValueType> |
| 193 | +inline const Name& |
| 194 | +AdaptiveTree<ValueType>::treeType() |
| 195 | +{ |
| 196 | + static std::string sTreeTypeName = []() |
| 197 | + { |
| 198 | + std::ostringstream ostr; |
| 199 | + ostr << "Adaptive_Tree_" << typeNameAsString<BuildType>(); |
| 200 | + return ostr.str(); |
| 201 | + }(); |
| 202 | + return sTreeTypeName; |
| 203 | +} |
| 204 | + |
| 205 | + |
| 206 | +/// @brief Adaptive grid. |
| 207 | +template <typename T> |
| 208 | +using AdaptiveGrid = Grid<AdaptiveTree<T>>; |
| 209 | + |
| 210 | +using FloatAdaptiveGrid = AdaptiveGrid<float>; |
| 211 | + |
| 212 | +using AdaptiveGridTypes = TypeList<FloatAdaptiveGrid>; |
| 213 | + |
| 214 | +} // namespace adaptive |
| 215 | +} // namespace OPENVDB_VERSION_NAME |
| 216 | +} // namespace openvdb |
| 217 | + |
| 218 | +#endif // OPENVDB_ADAPTIVE_ADAPTIVE_GRID_HAS_BEEN_INCLUDED |
0 commit comments