@@ -307,30 +307,115 @@ TEST_F(TestLeafBool, testIO)
307307}
308308
309309
310- TEST_F (TestLeafBool, testTopologyCopy )
310+ TEST_F (TestLeafBool, testConstructors )
311311{
312312 using openvdb::Coord;
313313
314- // LeafNode<float, Log2Dim> having the same Log2Dim as LeafType
315- typedef LeafType::ValueConverter<float >::Type FloatLeafType;
314+ { // Test constructor which takes a value mask and buffer accepts 2 value masks
315+ LeafType a, b;
316+ a.setValueOn (1 , true );
317+ a.setValueOn (2 , false );
318+ a.setValueOn (3 , true );
319+ a.setValueOn (4 , false );
320+
321+ b.setValueOn (1 , false );
322+ b.setValueOff (2 , true );
323+ b.setValueOn (3 , false );
324+ b.setValueOn (4 , true );
325+ b.setValueOff (5 , true );
326+ b.setValueOff (6 , false );
327+ const LeafType c (Coord (12 ,4 ,25 ), /* mask=*/ a.getValueMask (), /* buff=*/ b.getValueMask ());
328+ EXPECT_EQ (c.origin (), Coord (8 ,0 ,24 ));
329+ EXPECT_EQ (c.getValueMask (), a.getValueMask ());
330+ EXPECT_EQ (c.buffer (), b.getValueMask ());
331+
332+ EXPECT_TRUE (c.isValueOn (1 ));
333+ EXPECT_TRUE (c.isValueOn (2 ));
334+ EXPECT_TRUE (c.isValueOn (3 ));
335+ EXPECT_TRUE (c.isValueOn (4 ));
336+ EXPECT_TRUE (!c.isValueOn (5 ));
337+ EXPECT_TRUE (!c.isValueOn (6 ));
338+
339+ EXPECT_EQ (c.getValue (1 ), true );
340+ EXPECT_EQ (c.getValue (2 ), false );
341+ EXPECT_EQ (c.getValue (3 ), true );
342+ EXPECT_EQ (c.getValue (4 ), true );
343+ EXPECT_EQ (c.getValue (5 ), false );
344+ EXPECT_EQ (c.getValue (6 ), false );
345+ }
346+
347+ { // Test copy constructor with new buffer values
348+ LeafType a;
349+ a.setValueOn (1 , true );
350+ a.setValueOn (2 , false );
351+ a.setValueOn (3 , true );
352+ a.setValueOn (4 , false );
353+ a.setValueOff (5 , true );
354+ a.setValueOff (6 , false );
355+
356+ const LeafType b (a, /* off=*/ true , /* on=*/ false , openvdb::TopologyCopy ());
357+ EXPECT_EQ (b.getValueMask (), a.getValueMask ());
358+ EXPECT_EQ (b.getValue (1 ), false );
359+ EXPECT_EQ (b.getValue (2 ), false );
360+ EXPECT_EQ (b.getValue (3 ), false );
361+ EXPECT_EQ (b.getValue (4 ), false );
362+ EXPECT_TRUE (b.isValueOn (1 ));
363+ EXPECT_TRUE (b.isValueOn (2 ));
364+ EXPECT_TRUE (b.isValueOn (3 ));
365+ EXPECT_TRUE (b.isValueOn (4 ));
366+ for (openvdb::Index i = 5 ; i < LeafType::SIZE; ++i) {
367+ EXPECT_EQ (b.getValue (i), true );
368+ EXPECT_TRUE (!b.isValueOn (i));
369+ }
370+ }
316371
317- FloatLeafType fleaf (Coord (10 , 20 , 30 ), /* background=*/ -1.0 );
318- std::set<Coord> coords;
319- for (openvdb::Index n = 0 ; n < fleaf.numValues (); n += 10 ) {
320- Coord xyz = fleaf.offsetToGlobalCoord (n);
321- fleaf.setValueOn (xyz, float (n));
322- coords.insert (xyz);
372+ { // Test copy constructor with background value
373+ LeafType a;
374+ a.setValueOn (1 , true );
375+ a.setValueOn (2 , false );
376+ a.setValueOn (3 , true );
377+ a.setValueOn (4 , false );
378+ a.setValueOff (5 , true );
379+ a.setValueOff (6 , false );
380+
381+ const LeafType b (a, /* background*/ true , openvdb::TopologyCopy ());
382+ EXPECT_EQ (b.getValueMask (), a.getValueMask ());
383+ EXPECT_TRUE (b.isValueOn (1 ));
384+ EXPECT_TRUE (b.isValueOn (2 ));
385+ EXPECT_TRUE (b.isValueOn (3 ));
386+ EXPECT_TRUE (b.isValueOn (4 ));
387+ // All values are background
388+ for (openvdb::Index i = 0 ; i < LeafType::SIZE; ++i) {
389+ EXPECT_EQ (b.getValue (i), true );
390+ }
323391 }
324392
325- LeafType leaf (fleaf, openvdb::TopologyCopy ());
326- EXPECT_EQ (fleaf.onVoxelCount (), leaf.onVoxelCount ());
393+ {
394+ // LeafNode<float, Log2Dim> having the same Log2Dim as LeafType
395+ typedef LeafType::ValueConverter<float >::Type FloatLeafType;
396+
397+ FloatLeafType fleaf (Coord (10 , 20 , 30 ), /* background=*/ -1.0 );
398+ std::set<Coord> coords;
399+ for (openvdb::Index n = 0 ; n < fleaf.numValues (); n += 10 ) {
400+ Coord xyz = fleaf.offsetToGlobalCoord (n);
401+ fleaf.setValueOn (xyz, float (n));
402+ coords.insert (xyz);
403+ }
404+
405+ OPENVDB_NO_DEPRECATION_WARNING_BEGIN
406+ LeafType leaf (fleaf, openvdb::TopologyCopy ());
407+ OPENVDB_NO_DEPRECATION_WARNING_END
327408
328- EXPECT_TRUE (leaf.hasSameTopology (&fleaf));
409+ EXPECT_EQ (fleaf.onVoxelCount (), leaf.onVoxelCount ());
410+ EXPECT_TRUE (leaf.hasSameTopology (&fleaf));
329411
330- for (LeafType::ValueOnIter iter = leaf.beginValueOn (); iter; ++iter) {
331- coords.erase (iter.getCoord ());
412+ for (LeafType::ValueOnIter iter = leaf.beginValueOn (); iter; ++iter) {
413+ coords.erase (iter.getCoord ());
414+ }
415+ EXPECT_TRUE (coords.empty ());
332416 }
333- EXPECT_TRUE (coords.empty ());
417+
418+
334419}
335420
336421
0 commit comments