[REQUEST] Add `openvdb/GridFwd.h` (and friends?) providing forward declarations.
Is your feature request related to a problem? Please describe.
Being nearly all headers, OpenVBD is expensive to #include. There are places I pass around OpenVDB classes where I'd like to be able to just have them forward-declared so I can name them.
Using -ftime-trace on clang, and speedscope or chrome://tracing to view, I'm seeing over a second to #include <openvdb/Grid.h>.
Describe the solution you'd like
Something like openvdb/TypesFwd.h or openvdb/GridFwd.h or openvdb/openvdbFwd.h containing forward-declarations of at least the named grid types... So to get MaskGrid
#include <cstdint>
using Index32 = std::int32_t;
using Index = Index32;
template<typename T, Index Log2Dim>
class LeafNode;
template<typename _ChildNodeType, Index Log2Dim>
class InternalNode;
template<typename ChildType>
class RootNode;
template<typename _RootNodeType>
class Tree;
class ValueMask;
namespace tree {
template<typename T, Index N1=5, Index N2=4, Index N3=3>
struct Tree4 {
using Type = Tree<RootNode<InternalNode<InternalNode<LeafNode<T, N3>, N2>, N1>>>;
};
}
using MaskTree = tree::Tree4<ValueMask, 5, 4, 3>::Type;
template<typename> class Grid;
using MaskGrid = Grid<MaskTree>;
Describe alternatives you've considered
In my own codebase I've done
// This is inherited rather than a using declaration so we can forward-declare it elsewhere.
struct VolumeGrid : openvdb::MaskGrid {
using openvdb::MaskGrid::MaskGrid;
};
instead of using VolumeGrid = openvdb::MaskGrid; to allow me to forward-declare VolumeGrid.
Additional context
Beyond this, since Grid is really a shared pointer to a tree, it may be possible to reduce what Grid.h includes (or add a GridMinimal.h) which defines Grid but doesn't include tree or much else.
LMK if this is interesting and the degree of granularity we'd want and I'll consider doing it. I can see a few different approaches:
- Just one big
openvdbFwd.hthat forward-declares everything. - Enough forward-declaration so
openvdb/Grid.hdefinesGridbut only forward-declares tree types. - Several separate ones:
TypesFwd.hthat declares the basic types like scalars, points, and bboxes,TreeFwd.hthat declares the tree types,GridFwd.hthat includesTreeFwd.h, foward-declares theGridtemplate, and all of the common named grid types.
Hey @BenFrantzDale yeah there was interest in this last TSC meeting. The scope was to:
Introduce "openvdbfwd.h" which contains forward declarations for all native openvdb Grid and Tree types. Implicitly, this will also include any forward declarations for any types necessary for these Grid/Tree types.
Once we see what that looks like and what that requires we'll have a better idea of what else needs to exists to support it.
Has there been any movements on this?
PS: @BenFrantzDale congrats on the issue number 🤓