OpenVDB  3.0.0
Interpolation.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 //
66 
67 #ifndef OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED
68 #define OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED
69 
70 #include <cmath>
71 #include <boost/shared_ptr.hpp>
72 #include <openvdb/version.h> // for OPENVDB_VERSION_NAME
73 #include <openvdb/Platform.h> // for round()
74 #include <openvdb/math/Math.h>// for SmoothUnitStep
75 #include <openvdb/math/Transform.h> // for Transform
76 #include <openvdb/Grid.h>
77 #include <openvdb/tree/ValueAccessor.h>
78 
79 namespace openvdb {
81 namespace OPENVDB_VERSION_NAME {
82 namespace tools {
83 
84 // The following samplers operate in voxel space.
85 // When the samplers are applied to grids holding vector or other non-scalar data,
86 // the data is assumed to be collocated. For example, using the BoxSampler on a grid
87 // with ValueType Vec3f assumes that all three elements in a vector can be assigned
88 // the same physical location. Consider using the GridSampler below instead.
89 
91 {
92  static const char* name() { return "point"; }
93  static int radius() { return 0; }
94  static bool mipmap() { return false; }
95  static bool consistent() { return true; }
96 
100  template<class TreeT>
101  static bool sample(const TreeT& inTree, const Vec3R& inCoord,
102  typename TreeT::ValueType& result);
103 };
104 
105 
107 {
108  static const char* name() { return "box"; }
109  static int radius() { return 1; }
110  static bool mipmap() { return true; }
111  static bool consistent() { return true; }
112 
116  template<class TreeT>
117  static bool sample(const TreeT& inTree, const Vec3R& inCoord,
118  typename TreeT::ValueType& result);
119 
122  template<class TreeT>
123  static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
124 
125 private:
126  template<class ValueT, size_t N>
127  static inline ValueT trilinearInterpolation(ValueT (& data)[N][N][N], const Vec3R& uvw);
128 };
129 
130 
132 {
133  static const char* name() { return "quadratic"; }
134  static int radius() { return 1; }
135  static bool mipmap() { return true; }
136  static bool consistent() { return false; }
137 
141  template<class TreeT>
142  static bool sample(const TreeT& inTree, const Vec3R& inCoord,
143  typename TreeT::ValueType& result);
144 };
145 
146 
148 
149 
150 // The following samplers operate in voxel space and are designed for Vec3
151 // staggered grid data (e.g., fluid simulations using the Marker-and-Cell approach
152 // associate elements of the velocity vector with different physical locations:
153 // the faces of a cube).
154 
156 {
157  static const char* name() { return "point"; }
158  static int radius() { return 0; }
159  static bool mipmap() { return false; }
160  static bool consistent() { return false; }
161 
165  template<class TreeT>
166  static bool sample(const TreeT& inTree, const Vec3R& inCoord,
167  typename TreeT::ValueType& result);
168 };
169 
170 
172 {
173  static const char* name() { return "box"; }
174  static int radius() { return 1; }
175  static bool mipmap() { return true; }
176  static bool consistent() { return false; }
177 
181  template<class TreeT>
182  static bool sample(const TreeT& inTree, const Vec3R& inCoord,
183  typename TreeT::ValueType& result);
184 };
185 
186 
188 {
189  static const char* name() { return "quadratic"; }
190  static int radius() { return 1; }
191  static bool mipmap() { return true; }
192  static bool consistent() { return false; }
193 
197  template<class TreeT>
198  static bool sample(const TreeT& inTree, const Vec3R& inCoord,
199  typename TreeT::ValueType& result);
200 };
201 
202 
204 
205 
220 template<typename GridOrTreeType, typename SamplerType>
222 {
223 public:
224  typedef boost::shared_ptr<GridSampler> Ptr;
225  typedef typename GridOrTreeType::ValueType ValueType;
229 
231  explicit GridSampler(const GridType& grid)
232  : mTree(&(grid.tree())), mTransform(&(grid.transform())) {}
233 
236  GridSampler(const TreeType& tree, const math::Transform& transform)
237  : mTree(&tree), mTransform(&transform) {}
238 
239  const math::Transform& transform() const { return *mTransform; }
240 
245  template<typename RealType>
246  ValueType sampleVoxel(const RealType& x, const RealType& y, const RealType& z) const
247  {
248  return this->isSample(Vec3d(x,y,z));
249  }
250 
255  ValueType sampleVoxel(typename Coord::ValueType i,
256  typename Coord::ValueType j,
257  typename Coord::ValueType k) const
258  {
259  return this->isSample(Coord(i,j,k));
260  }
261 
264  ValueType isSample(const Coord& ijk) const { return mTree->getValue(ijk); }
265 
268  ValueType isSample(const Vec3d& ispoint) const
269  {
270  ValueType result = zeroVal<ValueType>();
271  SamplerType::sample(*mTree, ispoint, result);
272  return result;
273  }
274 
277  ValueType wsSample(const Vec3d& wspoint) const
278  {
279  ValueType result = zeroVal<ValueType>();
280  SamplerType::sample(*mTree, mTransform->worldToIndex(wspoint), result);
281  return result;
282  }
283 
284 private:
285  const TreeType* mTree;
286  const math::Transform* mTransform;
287 }; // class GridSampler
288 
289 
302 template<typename TreeT, typename SamplerType>
303 class GridSampler<tree::ValueAccessor<TreeT>, SamplerType>
304 {
305 public:
306  typedef boost::shared_ptr<GridSampler> Ptr;
307  typedef typename TreeT::ValueType ValueType;
308  typedef TreeT TreeType;
311 
314  GridSampler(const AccessorType& acc,
315  const math::Transform& transform)
316  : mAccessor(&acc), mTransform(&transform) {}
317 
318  const math::Transform& transform() const { return *mTransform; }
319 
324  template<typename RealType>
325  ValueType sampleVoxel(const RealType& x, const RealType& y, const RealType& z) const
326  {
327  return this->isSample(Vec3d(x,y,z));
328  }
329 
334  ValueType sampleVoxel(typename Coord::ValueType i,
335  typename Coord::ValueType j,
336  typename Coord::ValueType k) const
337  {
338  return this->isSample(Coord(i,j,k));
339  }
340 
343  ValueType isSample(const Coord& ijk) const { return mAccessor->getValue(ijk); }
344 
347  ValueType isSample(const Vec3d& ispoint) const
348  {
349  ValueType result = zeroVal<ValueType>();
350  SamplerType::sample(*mAccessor, ispoint, result);
351  return result;
352  }
353 
356  ValueType wsSample(const Vec3d& wspoint) const
357  {
358  ValueType result = zeroVal<ValueType>();
359  SamplerType::sample(*mAccessor, mTransform->worldToIndex(wspoint), result);
360  return result;
361  }
362 
363 private:
364  const AccessorType* mAccessor;//not thread-safe!
365  const math::Transform* mTransform;
366 };//Specialization of GridSampler
367 
368 
370 
371 
381 template<typename GridOrTreeT,
382  typename SamplerT>
384 {
385 public:
386  typedef typename GridOrTreeT::ValueType ValueType;
390 
394  DualGridSampler(const GridType& sourceGrid,
395  const math::Transform& targetXform)
396  : mSourceTree(&(sourceGrid.tree()))
397  , mSourceXform(&(sourceGrid.transform()))
398  , mTargetXform(&targetXform)
399  , mAligned(targetXform == *mSourceXform)
400  {
401  }
406  DualGridSampler(const TreeType& sourceTree,
407  const math::Transform& sourceXform,
408  const math::Transform& targetXform)
409  : mSourceTree(&sourceTree)
410  , mSourceXform(&sourceXform)
411  , mTargetXform(&targetXform)
412  , mAligned(targetXform == sourceXform)
413  {
414  }
417  inline ValueType operator()(const Coord& ijk) const
418  {
419  if (mAligned) return mSourceTree->getValue(ijk);
420  const Vec3R world = mTargetXform->indexToWorld(ijk);
421  return SamplerT::sample(*mSourceTree, mSourceXform->worldToIndex(world));
422  }
424  inline bool isAligned() const { return mAligned; }
425 private:
426  const TreeType* mSourceTree;
427  const math::Transform* mSourceXform;
428  const math::Transform* mTargetXform;
429  const bool mAligned;
430 };// DualGridSampler
431 
433 template<typename TreeT,
434  typename SamplerT>
435 class DualGridSampler<tree::ValueAccessor<TreeT>, SamplerT>
436 {
437  public:
438  typedef typename TreeT::ValueType ValueType;
439  typedef TreeT TreeType;
442 
447  DualGridSampler(const AccessorType& sourceAccessor,
448  const math::Transform& sourceXform,
449  const math::Transform& targetXform)
450  : mSourceAcc(&sourceAccessor)
451  , mSourceXform(&sourceXform)
452  , mTargetXform(&targetXform)
453  , mAligned(targetXform == sourceXform)
454  {
455  }
458  inline ValueType operator()(const Coord& ijk) const
459  {
460  if (mAligned) return mSourceAcc->getValue(ijk);
461  const Vec3R world = mTargetXform->indexToWorld(ijk);
462  return SamplerT::sample(*mSourceAcc, mSourceXform->worldToIndex(world));
463  }
465  inline bool isAligned() const { return mAligned; }
466 private:
467  const AccessorType* mSourceAcc;
468  const math::Transform* mSourceXform;
469  const math::Transform* mTargetXform;
470  const bool mAligned;
471 };//Specialization of DualGridSampler
472 
474 
475 
476 // Class to derive the normalized alpha mask
477 template <typename GridT,
478  typename MaskT,
479  typename SamplerT = tools::BoxSampler,
480  typename FloatT = float>
482 {
483 public:
484  BOOST_STATIC_ASSERT(boost::is_floating_point<FloatT>::value);
485  typedef GridT GridType;
486  typedef MaskT MaskType;
487  typedef SamplerT SamlerType;
488  typedef FloatT FloatType;
489 
490  AlphaMask(const GridT& grid, const MaskT& mask, FloatT min, FloatT max, bool invert)
491  : mAcc(mask.tree())
492  , mSampler(mAcc, mask.transform() , grid.transform())
493  , mMin(min)
494  , mInvNorm(1/(max-min))
495  , mInvert(invert)
496  {
497  assert(min < max);
498  }
499 
500  inline bool operator()(const Coord& xyz, FloatT& a, FloatT& b) const
501  {
502  a = math::SmoothUnitStep( (mSampler(xyz) - mMin) * mInvNorm );//smooth mapping to 0->1
503  b = 1 - a;
504  if (mInvert) std::swap(a,b);
505  return a>0;
506  }
507 
508 protected:
509  typedef typename MaskType::ConstAccessor AccT;
510  AccT mAcc;
512  const FloatT mMin, mInvNorm;
513  const bool mInvert;
514 };// AlphaMask
515 
517 
518 namespace local_util {
519 
520 inline Vec3i
521 floorVec3(const Vec3R& v)
522 {
523  return Vec3i(int(std::floor(v(0))), int(std::floor(v(1))), int(std::floor(v(2))));
524 }
525 
526 
527 inline Vec3i
528 ceilVec3(const Vec3R& v)
529 {
530  return Vec3i(int(std::ceil(v(0))), int(std::ceil(v(1))), int(std::ceil(v(2))));
531 }
532 
533 
534 inline Vec3i
535 roundVec3(const Vec3R& v)
536 {
537  return Vec3i(int(::round(v(0))), int(::round(v(1))), int(::round(v(2))));
538 }
539 
540 } // namespace local_util
541 
542 
544 
545 
546 template<class TreeT>
547 inline bool
548 PointSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
549  typename TreeT::ValueType& result)
550 {
551  Vec3i inIdx = local_util::roundVec3(inCoord);
552  return inTree.probeValue(Coord(inIdx), result);
553 }
554 
555 
557 
558 
559 template<class ValueT, size_t N>
560 inline ValueT
561 BoxSampler::trilinearInterpolation(ValueT (& data)[N][N][N], const Vec3R& uvw)
562 {
563  // Trilinear interpolation:
564  // The eight surrounding latice values are used to construct the result. \n
565  // result(x,y,z) =
566  // v000 (1-x)(1-y)(1-z) + v001 (1-x)(1-y)z + v010 (1-x)y(1-z) + v011 (1-x)yz
567  // + v100 x(1-y)(1-z) + v101 x(1-y)z + v110 xy(1-z) + v111 xyz
568 
569  ValueT resultA, resultB;
570 
571  resultA = data[0][0][0] + ValueT((data[0][0][1] - data[0][0][0]) * uvw[2]);
572  resultB = data[0][1][0] + ValueT((data[0][1][1] - data[0][1][0]) * uvw[2]);
573  ValueT result1 = resultA + ValueT((resultB-resultA) * uvw[1]);
574 
575  resultA = data[1][0][0] + ValueT((data[1][0][1] - data[1][0][0]) * uvw[2]);
576  resultB = data[1][1][0] + ValueT((data[1][1][1] - data[1][1][0]) * uvw[2]);
577  ValueT result2 = resultA + ValueT((resultB - resultA) * uvw[1]);
578 
579  return result1 + ValueT(uvw[0] * (result2 - result1));
580 }
581 
582 
583 template<class TreeT>
584 inline bool
585 BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
586  typename TreeT::ValueType& result)
587 {
588  typedef typename TreeT::ValueType ValueT;
589 
590  Vec3i inIdx = local_util::floorVec3(inCoord);
591  Vec3R uvw = inCoord - inIdx;
592 
593  // Retrieve the values of the eight voxels surrounding the
594  // fractional source coordinates.
595  ValueT data[2][2][2];
596 
597  bool hasActiveValues = false;
598  Coord ijk(inIdx);
599  hasActiveValues |= inTree.probeValue(ijk, data[0][0][0]); // i, j, k
600  ijk[2] += 1;
601  hasActiveValues |= inTree.probeValue(ijk, data[0][0][1]); // i, j, k + 1
602  ijk[1] += 1;
603  hasActiveValues |= inTree.probeValue(ijk, data[0][1][1]); // i, j+1, k + 1
604  ijk[2] = inIdx[2];
605  hasActiveValues |= inTree.probeValue(ijk, data[0][1][0]); // i, j+1, k
606  ijk[0] += 1;
607  ijk[1] = inIdx[1];
608  hasActiveValues |= inTree.probeValue(ijk, data[1][0][0]); // i+1, j, k
609  ijk[2] += 1;
610  hasActiveValues |= inTree.probeValue(ijk, data[1][0][1]); // i+1, j, k + 1
611  ijk[1] += 1;
612  hasActiveValues |= inTree.probeValue(ijk, data[1][1][1]); // i+1, j+1, k + 1
613  ijk[2] = inIdx[2];
614  hasActiveValues |= inTree.probeValue(ijk, data[1][1][0]); // i+1, j+1, k
615 
616  result = trilinearInterpolation(data, uvw);
617  return hasActiveValues;
618 }
619 
620 
621 template<class TreeT>
622 inline typename TreeT::ValueType
623 BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
624 {
625  typedef typename TreeT::ValueType ValueT;
626 
627  Vec3i inIdx = local_util::floorVec3(inCoord);
628  Vec3R uvw = inCoord - inIdx;
629 
630  // Retrieve the values of the eight voxels surrounding the
631  // fractional source coordinates.
632  ValueT data[2][2][2];
633 
634  Coord ijk(inIdx);
635  data[0][0][0] = inTree.getValue(ijk); // i, j, k
636  ijk[2] += 1;
637  data[0][0][1] = inTree.getValue(ijk); // i, j, k + 1
638  ijk[1] += 1;
639  data[0][1][1] = inTree.getValue(ijk); // i, j+1, k + 1
640  ijk[2] = inIdx[2];
641  data[0][1][0] = inTree.getValue(ijk); // i, j+1, k
642  ijk[0] += 1;
643  ijk[1] = inIdx[1];
644  data[1][0][0] = inTree.getValue(ijk); // i+1, j, k
645  ijk[2] += 1;
646  data[1][0][1] = inTree.getValue(ijk); // i+1, j, k + 1
647  ijk[1] += 1;
648  data[1][1][1] = inTree.getValue(ijk); // i+1, j+1, k + 1
649  ijk[2] = inIdx[2];
650  data[1][1][0] = inTree.getValue(ijk); // i+1, j+1, k
651 
652  return trilinearInterpolation(data, uvw);
653 }
654 
655 
657 
658 
659 template<class TreeT>
660 inline bool
661 QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
662  typename TreeT::ValueType& result)
663 {
664  typedef typename TreeT::ValueType ValueT;
665 
666  Vec3i
667  inIdx = local_util::floorVec3(inCoord),
668  inLoIdx = inIdx - Vec3i(1, 1, 1);
669  Vec3R frac = inCoord - inIdx;
670 
671  // Retrieve the values of the 27 voxels surrounding the
672  // fractional source coordinates.
673  bool active = false;
674  ValueT v[3][3][3];
675  for (int dx = 0, ix = inLoIdx.x(); dx < 3; ++dx, ++ix) {
676  for (int dy = 0, iy = inLoIdx.y(); dy < 3; ++dy, ++iy) {
677  for (int dz = 0, iz = inLoIdx.z(); dz < 3; ++dz, ++iz) {
678  if (inTree.probeValue(Coord(ix, iy, iz), v[dx][dy][dz])) {
679  active = true;
680  }
681  }
682  }
683  }
684 
686  ValueT vx[3];
687  for (int dx = 0; dx < 3; ++dx) {
688  ValueT vy[3];
689  for (int dy = 0; dy < 3; ++dy) {
690  // Fit a parabola to three contiguous samples in z
691  // (at z=-1, z=0 and z=1), then evaluate the parabola at z',
692  // where z' is the fractional part of inCoord.z, i.e.,
693  // inCoord.z - inIdx.z. The coefficients come from solving
694  //
695  // | (-1)^2 -1 1 || a | | v0 |
696  // | 0 0 1 || b | = | v1 |
697  // | 1^2 1 1 || c | | v2 |
698  //
699  // for a, b and c.
700  const ValueT* vz = &v[dx][dy][0];
701  const ValueT
702  az = static_cast<ValueT>(0.5 * (vz[0] + vz[2]) - vz[1]),
703  bz = static_cast<ValueT>(0.5 * (vz[2] - vz[0])),
704  cz = static_cast<ValueT>(vz[1]);
705  vy[dy] = static_cast<ValueT>(frac.z() * (frac.z() * az + bz) + cz);
706  }
707  // Fit a parabola to three interpolated samples in y, then
708  // evaluate the parabola at y', where y' is the fractional
709  // part of inCoord.y.
710  const ValueT
711  ay = static_cast<ValueT>(0.5 * (vy[0] + vy[2]) - vy[1]),
712  by = static_cast<ValueT>(0.5 * (vy[2] - vy[0])),
713  cy = static_cast<ValueT>(vy[1]);
714  vx[dx] = static_cast<ValueT>(frac.y() * (frac.y() * ay + by) + cy);
715  }
716  // Fit a parabola to three interpolated samples in x, then
717  // evaluate the parabola at the fractional part of inCoord.x.
718  const ValueT
719  ax = static_cast<ValueT>(0.5 * (vx[0] + vx[2]) - vx[1]),
720  bx = static_cast<ValueT>(0.5 * (vx[2] - vx[0])),
721  cx = static_cast<ValueT>(vx[1]);
722  result = static_cast<ValueT>(frac.x() * (frac.x() * ax + bx) + cx);
723 
724  return active;
725 }
726 
727 
729 
730 
731 template<class TreeT>
732 inline bool
733 StaggeredPointSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
734  typename TreeT::ValueType& result)
735 {
736  typedef typename TreeT::ValueType ValueType;
737 
738  ValueType tempX, tempY, tempZ;
739  bool active = false;
740 
741  active = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0, 0), tempX) || active;
742  active = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0.5, 0), tempY) || active;
743  active = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0, 0.5), tempZ) || active;
744 
745  result.x() = tempX.x();
746  result.y() = tempY.y();
747  result.z() = tempZ.z();
748 
749  return active;
750 }
751 
752 
754 
755 
756 template<class TreeT>
757 inline bool
758 StaggeredBoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
759  typename TreeT::ValueType& result)
760 {
761  typedef typename TreeT::ValueType ValueType;
762 
763  ValueType tempX, tempY, tempZ;
764  tempX = tempY = tempZ = zeroVal<ValueType>();
765  bool active = false;
766 
767  active = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0, 0), tempX) || active;
768  active = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0.5, 0), tempY) || active;
769  active = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0, 0.5), tempZ) || active;
770 
771  result.x() = tempX.x();
772  result.y() = tempY.y();
773  result.z() = tempZ.z();
774 
775  return active;
776 }
777 
778 
780 
781 
782 template<class TreeT>
783 inline bool
784 StaggeredQuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
785  typename TreeT::ValueType& result)
786 {
787  typedef typename TreeT::ValueType ValueType;
788 
789  ValueType tempX, tempY, tempZ;
790  bool active = false;
791 
792  active = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0, 0), tempX) || active;
793  active = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0.5, 0), tempY) || active;
794  active = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0, 0.5), tempZ) || active;
795 
796  result.x() = tempX.x();
797  result.y() = tempY.y();
798  result.z() = tempZ.z();
799 
800  return active;
801 }
802 
803 } // namespace tools
804 } // namespace OPENVDB_VERSION_NAME
805 } // namespace openvdb
806 
807 #endif // OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED
808 
809 // Copyright (c) 2012-2014 DreamWorks Animation LLC
810 // All rights reserved. This software is distributed under the
811 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
boost::shared_ptr< GridSampler > Ptr
Definition: Interpolation.h:306
AccT mAcc
Definition: Interpolation.h:510
Vec3i ceilVec3(const Vec3R &v)
Definition: Interpolation.h:528
Vec3i roundVec3(const Vec3R &v)
Definition: Interpolation.h:535
static bool mipmap()
Definition: Interpolation.h:94
ValueType sampleVoxel(typename Coord::ValueType i, typename Coord::ValueType j, typename Coord::ValueType k) const
Sample value in integer index space.
Definition: Interpolation.h:334
const math::Transform & transform() const
Definition: Interpolation.h:239
TreeAdapter< GridType >::AccessorType AccessorType
Definition: Interpolation.h:389
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
Class that provides the interface for continuous sampling of values in a tree.
Definition: Interpolation.h:221
const math::Transform & transform() const
Definition: Interpolation.h:318
bool isAligned() const
Return true if the two grids are aligned.
Definition: Interpolation.h:424
static const char * name()
Definition: Interpolation.h:173
const bool mInvert
Definition: Interpolation.h:513
static bool mipmap()
Definition: Interpolation.h:191
static const char * name()
Definition: Interpolation.h:108
static int radius()
Definition: Interpolation.h:190
T & z()
Definition: Vec3.h:99
static const char * name()
Definition: Interpolation.h:92
AlphaMask(const GridT &grid, const MaskT &mask, FloatT min, FloatT max, bool invert)
Definition: Interpolation.h:490
TreeAdapter< GridOrTreeT >::GridType GridType
Definition: Interpolation.h:387
_TreeType TreeType
Definition: Grid.h:860
Definition: Interpolation.h:481
ValueType sampleVoxel(const RealType &x, const RealType &y, const RealType &z) const
Sample a point in index space in the grid.
Definition: Interpolation.h:325
static bool consistent()
Definition: Interpolation.h:95
TreeAdapter< GridOrTreeType >::GridType GridType
Definition: Interpolation.h:226
static bool consistent()
Definition: Interpolation.h:192
tree::ValueAccessor< TreeT > AccessorType
Definition: Interpolation.h:310
Vec3< int32_t > Vec3i
Definition: Vec3.h:626
static int radius()
Definition: Interpolation.h:158
static const char * name()
Definition: Interpolation.h:157
DualGridSampler(const GridType &sourceGrid, const math::Transform &targetXform)
Grid and transform constructor.
Definition: Interpolation.h:394
static bool consistent()
Definition: Interpolation.h:136
Definition: Interpolation.h:90
Vec3i floorVec3(const Vec3R &v)
Definition: Interpolation.h:521
ValueType operator()(const Coord &ijk) const
Return the value of the source grid at the index coordinates, ijk, relative to the target grid (or it...
Definition: Interpolation.h:417
GridOrTreeType::ValueType ValueType
Definition: Interpolation.h:225
ValueType wsSample(const Vec3d &wspoint) const
Sample in world space.
Definition: Interpolation.h:277
Definition: Interpolation.h:106
#define OPENVDB_VERSION_NAME
Definition: version.h:43
GridSampler(const GridType &grid)
Definition: Interpolation.h:231
ValueType isSample(const Coord &ijk) const
Sample value in integer index space.
Definition: Interpolation.h:343
ValueType isSample(const Vec3d &ispoint) const
Sample in fractional index space.
Definition: Interpolation.h:347
math::Vec3< Real > Vec3R
Definition: Types.h:77
Type SmoothUnitStep(Type x)
Return 0 if x < 0, 1 if x > 1 or else .
Definition: Math.h:263
This is a simple convenience class that allows for sampling from a source grid into the index space o...
Definition: Interpolation.h:383
Definition: Interpolation.h:155
Definition: Exceptions.h:39
static int radius()
Definition: Interpolation.h:93
tools::DualGridSampler< AccT, SamplerT > mSampler
Definition: Interpolation.h:511
static const char * name()
Definition: Interpolation.h:189
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
tree::ValueAccessor< TreeT > AccessorType
Definition: Interpolation.h:441
DualGridSampler(const TreeType &sourceTree, const math::Transform &sourceXform, const math::Transform &targetXform)
Tree and transform constructor.
Definition: Interpolation.h:406
TreeAdapter< GridOrTreeType >::AccessorType AccessorType
Definition: Interpolation.h:228
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:97
Vec3< double > Vec3d
Definition: Vec3.h:629
static bool consistent()
Definition: Interpolation.h:176
GridSampler(const TreeType &tree, const math::Transform &transform)
Definition: Interpolation.h:236
T & y()
Definition: Vec3.h:98
Definition: Interpolation.h:171
bool operator()(const Coord &xyz, FloatT &a, FloatT &b) const
Definition: Interpolation.h:500
ValueType sampleVoxel(const RealType &x, const RealType &y, const RealType &z) const
Sample a point in index space in the grid.
Definition: Interpolation.h:246
MaskType::ConstAccessor AccT
Definition: Interpolation.h:509
bool isAligned() const
Return true if the two grids are aligned.
Definition: Interpolation.h:465
static int radius()
Definition: Interpolation.h:174
ValueType wsSample(const Vec3d &wspoint) const
Sample in world space.
Definition: Interpolation.h:356
static int radius()
Definition: Interpolation.h:134
ValueType isSample(const Vec3d &ispoint) const
Sample in fractional index space.
Definition: Interpolation.h:268
SamplerT SamlerType
Definition: Interpolation.h:487
Definition: Interpolation.h:131
TreeAdapter< GridOrTreeType >::TreeType TreeType
Definition: Interpolation.h:227
MaskT MaskType
Definition: Interpolation.h:486
static const char * name()
Definition: Interpolation.h:133
static bool mipmap()
Definition: Interpolation.h:110
GridT GridType
Definition: Interpolation.h:485
GridOrTreeT::ValueType ValueType
Definition: Interpolation.h:386
static bool mipmap()
Definition: Interpolation.h:159
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
static bool mipmap()
Definition: Interpolation.h:175
DualGridSampler(const AccessorType &sourceAccessor, const math::Transform &sourceXform, const math::Transform &targetXform)
ValueAccessor and transform constructor.
Definition: Interpolation.h:447
static bool consistent()
Definition: Interpolation.h:160
TreeAdapter< GridOrTreeT >::TreeType TreeType
Definition: Interpolation.h:388
static bool consistent()
Definition: Interpolation.h:111
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
const FloatT mMin
Definition: Interpolation.h:512
FloatT FloatType
Definition: Interpolation.h:488
ValueType isSample(const Coord &ijk) const
Sample value in integer index space.
Definition: Interpolation.h:264
static bool mipmap()
Definition: Interpolation.h:135
ValueType operator()(const Coord &ijk) const
Return the value of the source grid at the index coordinates, ijk, relative to the target grid...
Definition: Interpolation.h:458
static int radius()
Definition: Interpolation.h:109
boost::shared_ptr< GridSampler > Ptr
Definition: Interpolation.h:224
ValueType sampleVoxel(typename Coord::ValueType i, typename Coord::ValueType j, typename Coord::ValueType k) const
Sample value in integer index space.
Definition: Interpolation.h:255
GridSampler(const AccessorType &acc, const math::Transform &transform)
Definition: Interpolation.h:314