openvdb icon indicating copy to clipboard operation
openvdb copied to clipboard

[REQUEST] Add `openvdb/GridFwd.h` (and friends?) providing forward declarations.

Open BenFrantzDale opened this issue 3 years ago • 3 comments

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.

BenFrantzDale avatar Mar 24 '22 18:03 BenFrantzDale

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:

  1. Just one big openvdbFwd.h that forward-declares everything.
  2. Enough forward-declaration so openvdb/Grid.h defines Grid but only forward-declares tree types.
  3. Several separate ones: TypesFwd.h that declares the basic types like scalars, points, and bboxes, TreeFwd.h that declares the tree types, GridFwd.h that includes TreeFwd.h, foward-declares the Grid template, and all of the common named grid types.

BenFrantzDale avatar Mar 28 '22 12:03 BenFrantzDale

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.

Idclip avatar Apr 04 '22 17:04 Idclip

Has there been any movements on this?

PS: @BenFrantzDale congrats on the issue number 🤓

diiigle avatar Jun 05 '23 07:06 diiigle