@@ -249,60 +249,37 @@ namespace nanovdb {
249249// --------------------------> Build types <------------------------------------
250250
251251// / @brief Dummy type for a voxel whose value equals an offset into an external value array
252- class ValueIndex
253- {
254- };
252+ class ValueIndex {};
255253
256254// / @brief Dummy type for a voxel whose value equals an offset into an external value array of active values
257- class ValueOnIndex
258- {
259- };
255+ class ValueOnIndex {};
260256
261257// / @brief Like @c ValueIndex but with a mutable mask
262- class ValueIndexMask
263- {
264- };
258+ class ValueIndexMask {};
265259
266260// / @brief Like @c ValueOnIndex but with a mutable mask
267- class ValueOnIndexMask
268- {
269- };
261+ class ValueOnIndexMask {};
270262
271263// / @brief Dummy type for a voxel whose value equals its binary active state
272- class ValueMask
273- {
274- };
264+ class ValueMask {};
275265
276- // / @brief Dummy type for a 16 bit floating point values
277- class Half
278- {
279- };
266+ // / @brief Dummy type for a 16 bit floating point values (placeholder for IEEE 754 Half)
267+ class Half {};
280268
281269// / @brief Dummy type for a 4bit quantization of float point values
282- class Fp4
283- {
284- };
270+ class Fp4 {};
285271
286272// / @brief Dummy type for a 8bit quantization of float point values
287- class Fp8
288- {
289- };
273+ class Fp8 {};
290274
291275// / @brief Dummy type for a 16bit quantization of float point values
292- class Fp16
293- {
294- };
276+ class Fp16 {};
295277
296278// / @brief Dummy type for a variable bit quantization of floating point values
297- class FpN
298- {
299- };
279+ class FpN {};
300280
301- // / @dummy type for indexing points into voxels
302- class Point
303- {
304- };
305- // using Points = Point;// for backwards compatibility
281+ // / @brief Dummy type for indexing points into voxels
282+ class Point {};
306283
307284// --------------------------> GridType <------------------------------------
308285
@@ -760,7 +737,7 @@ __hostdev__ inline static T* alignPtr(T* p)
760737 return reinterpret_cast <T*>( (uint8_t *)p + alignmentPadding (p) );
761738}
762739
763- // / @brief offset the specified pointer so it is aligned.
740+ // / @brief offset the specified const pointer so it is aligned.
764741template <typename T>
765742__hostdev__ inline static const T* alignPtr (const T* p)
766743{
@@ -863,10 +840,10 @@ __hostdev__ inline bool isIndex(GridType gridType)
863840// --------------------------> memcpy64 <------------------------------------
864841
865842// / @brief copy 64 bit words from @c src to @c dst
866- // / @param dst pointer to destination
867- // / @param src pointer to source
843+ // / @param dst 64 bit aligned pointer to destination
844+ // / @param src 64 bit aligned pointer to source
868845// / @param word_count number of 64 bit words to be copied
869- // / @return destination pointer
846+ // / @return destination pointer @c dst
870847// / @warning @c src and @c dst cannot overlap and should both be 64 bit aligned
871848__hostdev__ inline static void * memcpy64 (void *dst, const void *src, size_t word_count)
872849{
@@ -948,13 +925,16 @@ class Version
948925{
949926 uint32_t mData ; // 11 + 11 + 10 bit packing of major + minor + patch
950927public:
928+ // / @brief Default constructor
951929 __hostdev__ Version ()
952930 : mData(uint32_t (NANOVDB_MAJOR_VERSION_NUMBER) << 21 |
953931 uint32_t(NANOVDB_MINOR_VERSION_NUMBER) << 10 |
954932 uint32_t(NANOVDB_PATCH_VERSION_NUMBER))
955933 {
956934 }
935+ // / @brief Constructor from a raw uint32_t data representation
957936 __hostdev__ Version (uint32_t data) : mData(data) {}
937+ // / @brief Constructor from major.minor.patch version numbers
958938 __hostdev__ Version (uint32_t major, uint32_t minor, uint32_t patch)
959939 : mData(major << 21 | minor << 10 | patch)
960940 {
@@ -970,14 +950,15 @@ class Version
970950 __hostdev__ uint32_t id () const { return mData ; }
971951 __hostdev__ uint32_t getMajor () const { return (mData >> 21 ) & ((1u << 11 ) - 1 ); }
972952 __hostdev__ uint32_t getMinor () const { return (mData >> 10 ) & ((1u << 11 ) - 1 ); }
973- __hostdev__ uint32_t getPatch () const { return mData & ((1u << 10 ) - 1 ); }
974- __hostdev__ bool isCompatible () const { return this ->getMajor () == uint32_t (NANOVDB_MAJOR_VERSION_NUMBER);}
975- // / @brief Check the major version of this instance relative to NANOVDB_MAJOR_VERSION_NUMBER
976- // / @return return 0 if the major version equals NANOVDB_MAJOR_VERSION_NUMBER, else a negative age if it is
977- // / older, i.e. smaller, and a positive age if it's newer, i.e.e larger.
953+ __hostdev__ uint32_t getPatch () const { return mData & ((1u << 10 ) - 1 ); }
954+ __hostdev__ bool isCompatible () const { return this ->getMajor () == uint32_t (NANOVDB_MAJOR_VERSION_NUMBER); }
955+ // / @brief Returns the difference between major version of this instance and NANOVDB_MAJOR_VERSION_NUMBER
956+ // / @return return 0 if the major version equals NANOVDB_MAJOR_VERSION_NUMBER, else a negative age if this
957+ // / instance has a smaller major verion (is older) , and a positive age if it is newer, i.e. larger.
978958 __hostdev__ int age () const {return int (this ->getMajor ()) - int (NANOVDB_MAJOR_VERSION_NUMBER);}
979959
980960#ifndef __CUDACC_RTC__
961+ // / @brief returns a c-string of the semantic version, i.e. major.minor.patch
981962 const char * c_str () const
982963 {
983964 char * buffer = (char *)malloc (4 + 1 + 4 + 1 + 4 + 1 ); // xxxx.xxxx.xxxx\0
@@ -990,7 +971,7 @@ class Version
990971// ----------------------------> Various math functions <-------------------------------------
991972
992973// @{
993- // / @brief Pi constant taken from Boost to match old behaviour
974+ // / @brief Pi constant taken from Boost to match old behaviour
994975template <typename T>
995976inline __hostdev__ constexpr T pi ()
996977{
@@ -3560,13 +3541,18 @@ struct NANOVDB_ALIGN(NANOVDB_DATA_ALIGNMENT) GridData
35603541 mGridType = gridType;
35613542 mBlindMetadataOffset = mGridSize ; // i.e. no blind data
35623543 mBlindMetadataCount = 0u ; // i.e. no blind data
3563- mData0 = 0u ;
3544+ mData0 = 0u ; // zero padding
35643545 mData1 = 0u ; // only used for index and point grids
3565- mData2 = 0u ;
3546+ mData2 = NANOVDB_MAGIC_GRID; // since version 32.6.0 (might be removed in the future)
35663547 }
35673548 // / @brief return true if the magic number and the version are both valid
35683549 __hostdev__ bool isValid () const {
3569- return mMagic == NANOVDB_MAGIC_GRID || (mMagic == NANOVDB_MAGIC_NUMBER && mVersion .isCompatible ());
3550+ if (mMagic == NANOVDB_MAGIC_GRID || mData2 == NANOVDB_MAGIC_GRID) return true ;
3551+ bool test = mMagic == NANOVDB_MAGIC_NUMBER;// could be GridData or io::FileHeader
3552+ if (test) test = mVersion .isCompatible ();
3553+ if (test) test = mGridCount > 0u && mGridIndex < mGridCount ;
3554+ if (test) test = mGridClass < GridClass::End && mGridType < GridType::End;
3555+ return test;
35703556 }
35713557 // Set and unset various bit flags
35723558 __hostdev__ void setMinMaxOn (bool on = true ) { mFlags .setMask (GridFlags::HasMinMax, on); }
@@ -7980,20 +7966,20 @@ VecT<GridHandleT> readUncompressedGrids(StreamT& is, const typename GridHandleT:
79807966{
79817967 VecT<GridHandleT> handles;
79827968 GridData data;
7983- is.read ((char *)&data, 40 ); // we only need to load the first 40 bytes
7984- if (data.mMagic == NANOVDB_MAGIC_GRID || data. isValid ()) {// stream contains a raw grid buffer
7969+ is.read ((char *)&data, sizeof (GridData));
7970+ if (data.isValid ()) {// stream contains a raw grid buffer
79857971 uint64_t size = data.mGridSize , sum = 0u ;
79867972 while (data.mGridIndex + 1u < data.mGridCount ) {
7987- is.skip (data.mGridSize - 40 );// skip grid
7988- is.read ((char *)&data, 40 ) ;// read 40 bytes
7973+ is.skip (data.mGridSize - sizeof (GridData) );// skip grid
7974+ is.read ((char *)&data, sizeof (GridData)) ;// read sizeof(GridData) bytes
79897975 sum += data.mGridSize ;
79907976 }
7991- is.skip (-int64_t (sum + 40 ));// rewind to start
7977+ is.skip (-int64_t (sum + sizeof (GridData) ));// rewind to start
79927978 auto buffer = GridHandleT::BufferType::create (size + sum, &pool);
79937979 is.read ((char *)(buffer.data ()), buffer.size ());
79947980 handles.emplace_back (std::move (buffer));
79957981 } else {// Header0, MetaData0, gridName0, Grid0...HeaderN, MetaDataN, gridNameN, GridN
7996- is.skip (-40 );// rewind
7982+ is.skip (-sizeof (GridData) );// rewind
79977983 FileHeader head;
79987984 while (is.read ((char *)&head, sizeof (FileHeader))) {
79997985 if (!head.isValid ()) {
0 commit comments