@@ -629,29 +629,35 @@ template<class ValueT, class TreeT, size_t N>
629
629
inline void
630
630
BoxSampler::getValues (ValueT (&data)[N][N][N], const TreeT& inTree, Coord ijk)
631
631
{
632
- data[ 0 ][ 0 ][ 0 ] = inTree. getValue (ijk); // i, j, k
632
+ // This algorithm is only defined for sparse grids
633
633
634
- ijk[ 2 ] += 1 ;
635
- data[0 ][0 ][1 ] = inTree.getValue (ijk); // i, j, k + 1
634
+ if constexpr (TreeTraits<TreeT>::IsSparse) {
635
+ data[0 ][0 ][0 ] = inTree.getValue (ijk); // i, j, k
636
636
637
- ijk[1 ] += 1 ;
638
- data[0 ][1 ][1 ] = inTree.getValue (ijk); // i, j+1 , k + 1
637
+ ijk[2 ] += 1 ;
638
+ data[0 ][0 ][1 ] = inTree.getValue (ijk); // i, j, k + 1
639
639
640
- ijk[2 ] - = 1 ;
641
- data[0 ][1 ][0 ] = inTree.getValue (ijk); // i, j+1, k
640
+ ijk[1 ] + = 1 ;
641
+ data[0 ][1 ][1 ] = inTree.getValue (ijk); // i, j+1, k + 1
642
642
643
- ijk[0 ] += 1 ;
644
- ijk[1 ] -= 1 ;
645
- data[1 ][0 ][0 ] = inTree.getValue (ijk); // i+1, j, k
643
+ ijk[2 ] -= 1 ;
644
+ data[0 ][1 ][0 ] = inTree.getValue (ijk); // i, j+1, k
646
645
647
- ijk[2 ] += 1 ;
648
- data[1 ][0 ][1 ] = inTree.getValue (ijk); // i+1, j, k + 1
646
+ ijk[0 ] += 1 ;
647
+ ijk[1 ] -= 1 ;
648
+ data[1 ][0 ][0 ] = inTree.getValue (ijk); // i+1, j, k
649
649
650
- ijk[1 ] += 1 ;
651
- data[1 ][1 ][1 ] = inTree.getValue (ijk); // i+1, j+1 , k + 1
650
+ ijk[2 ] += 1 ;
651
+ data[1 ][0 ][1 ] = inTree.getValue (ijk); // i+1, j, k + 1
652
652
653
- ijk[2 ] -= 1 ;
654
- data[1 ][1 ][0 ] = inTree.getValue (ijk); // i+1, j+1, k
653
+ ijk[1 ] += 1 ;
654
+ data[1 ][1 ][1 ] = inTree.getValue (ijk); // i+1, j+1, k + 1
655
+
656
+ ijk[2 ] -= 1 ;
657
+ data[1 ][1 ][0 ] = inTree.getValue (ijk); // i+1, j+1, k
658
+ } else {
659
+ static_assert (AlwaysFalseValue<TreeT>, " Not Implemented" );
660
+ }
655
661
}
656
662
657
663
template <class ValueT , class TreeT , size_t N>
@@ -744,39 +750,63 @@ inline bool
744
750
BoxSampler::sample (const TreeT& inTree, const Vec3R& inCoord,
745
751
typename TreeT::ValueType& result)
746
752
{
747
- using ValueT = typename TreeT::ValueType;
748
-
749
- const Vec3i inIdx = local_util::floorVec3 (inCoord);
750
- const Vec3R uvw = inCoord - inIdx;
751
-
752
- // Retrieve the values of the eight voxels surrounding the
753
- // fractional source coordinates.
754
- ValueT data[2 ][2 ][2 ];
755
-
756
- const bool hasActiveValues = BoxSampler::probeValues (data, inTree, Coord (inIdx));
757
-
758
- result = BoxSampler::trilinearInterpolation (data, uvw);
759
-
760
- return hasActiveValues;
753
+ if constexpr (TreeTraits<TreeT>::IsSparse) {
754
+ using ValueT = typename TreeT::ValueType;
755
+
756
+ const Vec3i inIdx = local_util::floorVec3 (inCoord);
757
+ const Vec3R uvw = inCoord - inIdx;
758
+
759
+ // Retrieve the values of the eight voxels surrounding the
760
+ // fractional source coordinates.
761
+ ValueT data[2 ][2 ][2 ];
762
+
763
+ const bool hasActiveValues = BoxSampler::probeValues (data, inTree, Coord (inIdx));
764
+
765
+ result = BoxSampler::trilinearInterpolation (data, uvw);
766
+
767
+ return hasActiveValues;
768
+ } else if constexpr (TreeTraits<TreeT>::IsAdaptive) {
769
+ // As an example, return the background value.
770
+ // This is where the logic that could sample against an adaptive tree would live.
771
+ // Extract the tree from the Tree or ValueAccessor
772
+ auto & tree = TreeAdapter<TreeT>::tree (inTree);
773
+ result = tree.background ();
774
+ return true ;
775
+ } else {
776
+ static_assert (AlwaysFalseValue<TreeT>, " Not Implemented" );
777
+ }
778
+ std::abort (); // unreachable
761
779
}
762
780
763
781
764
782
template <class TreeT >
765
783
inline typename TreeT::ValueType
766
784
BoxSampler::sample (const TreeT& inTree, const Vec3R& inCoord)
767
785
{
768
- using ValueT = typename TreeT::ValueType;
786
+ if constexpr (TreeTraits< TreeT>::IsSparse) {
769
787
770
- const Vec3i inIdx = local_util::floorVec3 (inCoord);
771
- const Vec3R uvw = inCoord - inIdx;
788
+ using ValueT = typename TreeT::ValueType;
772
789
773
- // Retrieve the values of the eight voxels surrounding the
774
- // fractional source coordinates.
775
- ValueT data[2 ][2 ][2 ];
790
+ const Vec3i inIdx = local_util::floorVec3 (inCoord);
791
+ const Vec3R uvw = inCoord - inIdx;
792
+
793
+ // Retrieve the values of the eight voxels surrounding the
794
+ // fractional source coordinates.
795
+ ValueT data[2 ][2 ][2 ];
776
796
777
- BoxSampler::getValues (data, inTree, Coord (inIdx));
797
+ BoxSampler::getValues (data, inTree, Coord (inIdx));
778
798
779
- return BoxSampler::trilinearInterpolation (data, uvw);
799
+ return BoxSampler::trilinearInterpolation (data, uvw);
800
+ } else if constexpr (TreeTraits<TreeT>::IsAdaptive) {
801
+ // As an example, return the background value.
802
+ // This is where the logic that could sample against an adaptive tree would live.
803
+ // Extract the tree from the Tree or ValueAccessor
804
+ auto & tree = TreeAdapter<TreeT>::tree (inTree);
805
+ return tree.background ();
806
+ } else {
807
+ static_assert (AlwaysFalseValue<TreeT>, " Not Implemented" );
808
+ }
809
+ std::abort (); // unreachable
780
810
}
781
811
782
812
0 commit comments