Skip to content

Commit 63395e2

Browse files
committed
Add OPENVDB_ENABLE_TREE_IO
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent 031489e commit 63395e2

24 files changed

Lines changed: 140 additions & 15 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ option(OPENVDB_BUILD_NANOVDB "Build the NanoVDB library. Turns ON if USE_NANOVDB
8080
# Global options
8181
option(OPENVDB_ENABLE_RPATH "Build with RPATH information" ON)
8282
option(OPENVDB_ENABLE_ASSERTS "Build with asserts in OpenVDB code enabled" OFF)
83+
option(OPENVDB_ENABLE_TREE_IO "Build with Tree I/O functionality enabled" ON)
8384
option(OPENVDB_CXX_STRICT "Enable or disable pre-defined compiler warnings" OFF)
8485
cmake_dependent_option(OPENVDB_INSTALL_CMAKE_MODULES
8586
"Install the provided OpenVDB CMake modules when building the core library"

openvdb/openvdb/Grid.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,23 +448,23 @@ class OPENVDB_API GridBase: public MetaMap
448448

449449
/// @brief Read the grid topology from a stream.
450450
/// This will read only the grid structure, not the actual data buffers.
451-
virtual void readTopology(std::istream&) = 0;
451+
virtual void readTopology(std::istream&) = OPENVDB_TREE_IO_VIRTUAL;
452452
/// @brief Write the grid topology to a stream.
453453
/// This will write only the grid structure, not the actual data buffers.
454-
virtual void writeTopology(std::ostream&) const = 0;
454+
virtual void writeTopology(std::ostream&) const = OPENVDB_TREE_IO_VIRTUAL;
455455

456456
/// Read all data buffers for this grid.
457-
virtual void readBuffers(std::istream&) = 0;
457+
virtual void readBuffers(std::istream&) = OPENVDB_TREE_IO_VIRTUAL;
458458
/// Read all of this grid's data buffers that intersect the given index-space bounding box.
459-
virtual void readBuffers(std::istream&, const CoordBBox&) = 0;
459+
virtual void readBuffers(std::istream&, const CoordBBox&) = OPENVDB_TREE_IO_VIRTUAL;
460460

461461
#if OPENVDB_ABI_VERSION_NUMBER < 14
462462
OPENVDB_DEPRECATED_MESSAGE("This method is deprecated and will be removed. Delayed loading is no longer supported.")
463463
virtual void readNonresidentBuffers() const = 0;
464464
#endif
465465

466466
/// Write out all data buffers for this grid.
467-
virtual void writeBuffers(std::ostream&) const = 0;
467+
virtual void writeBuffers(std::ostream&) const = OPENVDB_TREE_IO_VIRTUAL;
468468

469469
/// Read in the transform for this grid.
470470
void readTransform(std::istream& is) { transform().read(is); }
@@ -928,6 +928,7 @@ class Grid: public GridBase
928928
/// @name I/O
929929
/// @{
930930

931+
#ifdef OPENVDB_ENABLE_TREE_IO
931932
/// @brief Read the grid topology from a stream.
932933
/// This will read only the grid structure, not the actual data buffers.
933934
void readTopology(std::istream&) override;
@@ -939,14 +940,17 @@ class Grid: public GridBase
939940
void readBuffers(std::istream&) override;
940941
/// Read all of this grid's data buffers that intersect the given index-space bounding box.
941942
void readBuffers(std::istream&, const CoordBBox&) override;
943+
#endif // OPENVDB_ENABLE_TREE_IO
942944

943945
#if OPENVDB_ABI_VERSION_NUMBER < 14
944946
OPENVDB_DEPRECATED_MESSAGE("This method is deprecated and will be removed. Delayed loading is no longer supported.")
945947
void readNonresidentBuffers() const override { }
946948
#endif
947949

950+
#ifdef OPENVDB_ENABLE_TREE_IO
948951
/// Write out all data buffers for this grid.
949952
void writeBuffers(std::ostream&) const override;
953+
#endif // OPENVDB_ENABLE_TREE_IO
950954

951955
/// Output a human-readable description of this grid.
952956
void print(std::ostream& = std::cout, int verboseLevel = 1) const override;
@@ -1625,6 +1629,8 @@ Grid<TreeT>::evalActiveVoxelDim() const
16251629
/// @internal Consider using the stream tagging mechanism (see io::Archive)
16261630
/// to specify the float precision, but note that the setting is per-grid.
16271631

1632+
#ifdef OPENVDB_ENABLE_TREE_IO
1633+
16281634
template<typename TreeT>
16291635
inline void
16301636
Grid<TreeT>::readTopology(std::istream& is)
@@ -1717,6 +1723,8 @@ Grid<TreeT>::writeBuffers(std::ostream& os) const
17171723
}
17181724
}
17191725

1726+
#endif // OPENVDB_ENABLE_TREE_IO
1727+
17201728

17211729
//static
17221730
template<typename TreeT>

openvdb/openvdb/io/Archive.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,12 +1005,17 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
10051005
if (codec) {
10061006
codec->readTopology(is, *codecData, readOptions, diagnostics);
10071007
} else {
1008+
#ifdef OPENVDB_ENABLE_TREE_IO
10081009
grid->readTopology(is);
1010+
#else
1011+
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
1012+
#endif
10091013
}
10101014
// read buffers
10111015
if (codec) {
10121016
codec->readBuffers(is, *codecData, readOptions, diagnostics);
10131017
} else {
1018+
#ifdef OPENVDB_ENABLE_TREE_IO
10141019
const auto& worldBBox = readOptions.clipBBox;
10151020
const bool clip = worldBBox.isSorted();
10161021
if (clip) {
@@ -1019,6 +1024,9 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
10191024
} else {
10201025
grid->readBuffers(is);
10211026
}
1027+
#else
1028+
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
1029+
#endif
10221030
}
10231031
}
10241032

@@ -1204,7 +1212,11 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
12041212
if (codec) {
12051213
codec->writeTopology(os, *grid, writeOptions);
12061214
} else {
1215+
#ifdef OPENVDB_ENABLE_TREE_IO
12071216
grid->writeTopology(os);
1217+
#else
1218+
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
1219+
#endif
12081220
}
12091221

12101222
// Now we know the grid block storage position.
@@ -1214,7 +1226,11 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
12141226
if (codec) {
12151227
codec->writeBuffers(os, *grid, writeOptions);
12161228
} else {
1229+
#ifdef OPENVDB_ENABLE_TREE_IO
12171230
grid->writeBuffers(os);
1231+
#else
1232+
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
1233+
#endif
12181234
}
12191235

12201236
// Now we know the end position of this grid.

openvdb/openvdb/points/PointDataGrid.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,18 @@ class PointDataLeafNode : public tree::LeafNode<T, Log2Dim>, io::PointDataGridMu
362362
//@}
363363

364364
// I/O methods
365-
365+
#ifdef OPENVDB_ENABLE_TREE_IO
366366
void readTopology(std::istream& is, bool fromHalf = false);
367367
void writeTopology(std::ostream& os, bool toHalf = false) const;
368+
#endif // OPENVDB_ENABLE_TREE_IO
368369

369370
Index buffers() const;
370371

372+
#ifdef OPENVDB_ENABLE_TREE_IO
371373
void readBuffers(std::istream& is, bool fromHalf = false);
372374
void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
373375
void writeBuffers(std::ostream& os, bool toHalf = false) const;
374-
376+
#endif // OPENVDB_ENABLE_TREE_IO
375377

376378
Index64 memUsage() const;
377379
OPENVDB_DEPRECATED_MESSAGE("Use memUsage() instead. This method is deprecated and will be removed. Delayed loading is no longer supported.")
@@ -987,6 +989,7 @@ PointDataLeafNode<T, Log2Dim>::setOffsetOnly(Index offset, const ValueType& val)
987989
this->buffer().setValue(offset, val);
988990
}
989991

992+
#ifdef OPENVDB_ENABLE_TREE_IO
990993
template<typename T, Index Log2Dim>
991994
inline void
992995
PointDataLeafNode<T, Log2Dim>::readTopology(std::istream& is, bool fromHalf)
@@ -1000,6 +1003,7 @@ PointDataLeafNode<T, Log2Dim>::writeTopology(std::ostream& os, bool toHalf) cons
10001003
{
10011004
BaseLeaf::writeTopology(os, toHalf);
10021005
}
1006+
#endif // OPENVDB_ENABLE_TREE_IO
10031007

10041008
template<typename T, Index Log2Dim>
10051009
inline Index
@@ -1013,6 +1017,7 @@ PointDataLeafNode<T, Log2Dim>::buffers() const
10131017
/*cleanup*/ 1);
10141018
}
10151019

1020+
#ifdef OPENVDB_ENABLE_TREE_IO
10161021
template<typename T, Index Log2Dim>
10171022
inline void
10181023
PointDataLeafNode<T, Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
@@ -1385,6 +1390,7 @@ PointDataLeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
13851390
Local::destroyPagedStream(meta->auxData(), attributeIndex);
13861391
}
13871392
}
1393+
#endif // OPENVDB_ENABLE_TREE_IO
13881394

13891395
template<typename T, Index Log2Dim>
13901396
inline Index64

openvdb/openvdb/tools/PointIndexGrid.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,11 @@ struct PointIndexLeafNode : public tree::LeafNode<T, Log2Dim>
14851485

14861486
// I/O methods
14871487

1488+
#ifdef OPENVDB_ENABLE_TREE_IO
14881489
void readBuffers(std::istream& is, bool fromHalf = false);
14891490
void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
14901491
void writeBuffers(std::ostream& os, bool toHalf = false) const;
1492+
#endif // OPENVDB_ENABLE_TREE_IO
14911493

14921494

14931495
Index64 memUsage() const;
@@ -1718,6 +1720,8 @@ PointIndexLeafNode<T, Log2Dim>::isEmpty(const CoordBBox& bbox) const
17181720
}
17191721

17201722

1723+
#ifdef OPENVDB_ENABLE_TREE_IO
1724+
17211725
template<typename T, Index Log2Dim>
17221726
inline void
17231727
PointIndexLeafNode<T, Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
@@ -1791,6 +1795,8 @@ PointIndexLeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) cons
17911795
os.write(reinterpret_cast<const char*>(&auxDataBytes), sizeof(Index64));
17921796
}
17931797

1798+
#endif // OPENVDB_ENABLE_TREE_IO
1799+
17941800

17951801
template<typename T, Index Log2Dim>
17961802
inline Index64

openvdb/openvdb/tree/InternalNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ class InternalNode
454454
/// Mark all values (both tiles and voxels) as active.
455455
void setValuesOn();
456456

457+
#ifdef OPENVDB_ENABLE_TREE_IO
457458
//
458459
// I/O
459460
//
@@ -463,6 +464,7 @@ class InternalNode
463464
void readBuffers(std::istream&, bool fromHalf = false);
464465
void readBuffers(std::istream&, const CoordBBox&, bool fromHalf = false);
465466

467+
#endif // OPENVDB_ENABLE_TREE_IO
466468

467469
//
468470
// Unsafe methods
@@ -2388,6 +2390,7 @@ InternalNode<ChildT, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense)
23882390

23892391
////////////////////////////////////////
23902392

2393+
#ifdef OPENVDB_ENABLE_TREE_IO
23912394

23922395
template<typename ChildT, Index Log2Dim>
23932396
inline void
@@ -2458,6 +2461,7 @@ InternalNode<ChildT, Log2Dim>::readTopology(std::istream& is, bool fromHalf)
24582461
}
24592462
}
24602463

2464+
#endif // OPENVDB_ENABLE_TREE_IO
24612465

24622466
////////////////////////////////////////
24632467

@@ -3213,6 +3217,8 @@ InternalNode<ChildT, Log2Dim>::combine2(const InternalNode& other, const OtherVa
32133217
////////////////////////////////////////
32143218

32153219

3220+
#ifdef OPENVDB_ENABLE_TREE_IO
3221+
32163222
template<typename ChildT, Index Log2Dim>
32173223
inline void
32183224
InternalNode<ChildT, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
@@ -3254,6 +3260,8 @@ InternalNode<ChildT, Log2Dim>::readBuffers(std::istream& is,
32543260
this->clip(clipBBox, background);
32553261
}
32563262

3263+
#endif // OPENVDB_ENABLE_TREE_IO
3264+
32573265

32583266
////////////////////////////////////////
32593267

openvdb/openvdb/tree/LeafNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ class LeafNode
378378
const Buffer& buffer() const { return mBuffer; }
379379
Buffer& buffer() { return mBuffer; }
380380

381+
#ifdef OPENVDB_ENABLE_TREE_IO
381382
//
382383
// I/O methods
383384
//
@@ -403,6 +404,7 @@ class LeafNode
403404
/// @param os the stream to which to write
404405
/// @param toHalf if true, output floating-point values as 16-bit half floats
405406
void writeBuffers(std::ostream& os, bool toHalf = false) const;
407+
#endif // OPENVDB_ENABLE_TREE_IO
406408

407409
size_t streamingSize(bool toHalf = false) const;
408410

@@ -921,7 +923,9 @@ class LeafNode
921923
void setValueMaskOn(Index n) { mValueMask.setOn(n); }
922924
void setValueMaskOff(Index n) { mValueMask.setOff(n); }
923925

926+
#ifdef OPENVDB_ENABLE_TREE_IO
924927
inline void skipCompressedValues(bool seekable, std::istream&, bool fromHalf);
928+
#endif // OPENVDB_ENABLE_TREE_IO
925929

926930
/// Compute the origin of the leaf node that contains the voxel with the given coordinates.
927931
static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
@@ -1319,6 +1323,8 @@ LeafNode<T, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
13191323
////////////////////////////////////////
13201324

13211325

1326+
#ifdef OPENVDB_ENABLE_TREE_IO
1327+
13221328
template<typename T, Index Log2Dim>
13231329
inline void
13241330
LeafNode<T, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
@@ -1433,6 +1439,8 @@ LeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
14331439
mValueMask, /*childMask=*/NodeMaskType(), toHalf);
14341440
}
14351441

1442+
#endif // OPENVDB_ENABLE_TREE_IO
1443+
14361444

14371445
////////////////////////////////////////
14381446

openvdb/openvdb/tree/LeafNodeBool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class LeafNode<bool, Log2Dim>
200200
const Buffer& buffer() const { return mBuffer; }
201201
Buffer& buffer() { return mBuffer; }
202202

203+
#ifdef OPENVDB_ENABLE_TREE_IO
203204
//
204205
// I/O methods
205206
//
@@ -213,6 +214,7 @@ class LeafNode<bool, Log2Dim>
213214
void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
214215
/// Write out the topology and the origin.
215216
void writeBuffers(std::ostream&, bool toHalf = false) const;
217+
#endif // OPENVDB_ENABLE_TREE_IO
216218

217219
//
218220
// Accessor methods
@@ -976,6 +978,8 @@ LeafNode<bool, Log2Dim>::offsetToGlobalCoord(Index n) const
976978
////////////////////////////////////////
977979

978980

981+
#ifdef OPENVDB_ENABLE_TREE_IO
982+
979983
template<Index Log2Dim>
980984
inline void
981985
LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
@@ -1038,6 +1042,7 @@ LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
10381042
mBuffer.mData.save(os);
10391043
}
10401044

1045+
#endif // OPENVDB_ENABLE_TREE_IO
10411046

10421047
////////////////////////////////////////
10431048

openvdb/openvdb/tree/LeafNodeMask.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class LeafNode<ValueMask, Log2Dim>
199199
const Buffer& buffer() const { return mBuffer; }
200200
Buffer& buffer() { return mBuffer; }
201201

202+
#ifdef OPENVDB_ENABLE_TREE_IO
202203
//
203204
// I/O methods
204205
//
@@ -212,6 +213,7 @@ class LeafNode<ValueMask, Log2Dim>
212213
void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
213214
/// Write out the topology and the origin.
214215
void writeBuffers(std::ostream&, bool toHalf = false) const;
216+
#endif // OPENVDB_ENABLE_TREE_IO
215217

216218
//
217219
// Accessor methods
@@ -962,6 +964,8 @@ LeafNode<ValueMask, Log2Dim>::offsetToGlobalCoord(Index n) const
962964
////////////////////////////////////////
963965

964966

967+
#ifdef OPENVDB_ENABLE_TREE_IO
968+
965969
template<Index Log2Dim>
966970
inline void
967971
LeafNode<ValueMask, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
@@ -1017,6 +1021,8 @@ LeafNode<ValueMask, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) co
10171021
os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
10181022
}
10191023

1024+
#endif // OPENVDB_ENABLE_TREE_IO
1025+
10201026

10211027
////////////////////////////////////////
10221028

0 commit comments

Comments
 (0)