Field3D
MIPUtil.h File Reference

Contains MIP-related utility functions. More...

#include <vector>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include "Resample.h"
#include "SparseField.h"
#include "Types.h"
#include "ns.h"

Go to the source code of this file.

Classes

struct  detail::ComputationType< T >
 Used to delegate the choice of bit depth to process at. More...
 
struct  detail::ComputationType< Field3D::half >
 Specialization for half float. More...
 
struct  detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >
 

Namespaces

 detail
 

Functions

FIELD3D_API FieldMapping::Ptr detail::adjustedMIPFieldMapping (const FieldRes *base, const V3i &baseRes, const Box3i &extents, const size_t level)
 
template<typename Field_T >
bool detail::checkInputEmpty (const Field_T &, const Field_T &, const Box3i &, const float, const size_t)
 Fallback version always returns false. More...
 
template<typename Data_T >
bool detail::checkInputEmpty (const SparseField< Data_T > &src, const SparseField< Data_T > &, const Box3i &tgtBox, const float support, const size_t dim)
 
FIELD3D_NAMESPACE_OPEN V3i computeOffset (const FieldRes &f)
 Computes the origin/offset of a field. More...
 
template<typename MIPField_T , typename Filter_T >
MIPField_T::Ptr makeMIP (const typename MIPField_T::NestedType &base, const int minSize, const size_t numThreads)
 Constructs a MIP representation of the given field. More...
 
template<typename MIPField_T , typename Filter_T >
MIPField_T::Ptr makeMIP (const typename MIPField_T::NestedType &base, const int minSize, const V3i &offset, const size_t numThreads)
 Constructs a MIP representation of the given field, with optional offset vector. The offset vector indicates the 'true' voxel space coordinate of the (0, 0, 0) voxel, such that a consistent voxel placement can be used for the MIP levels. More...
 
template<typename Field_T , typename FilterOp_T >
void detail::mipResample (const Field_T &base, const Field_T &src, Field_T &tgt, const size_t level, const V3i &offset, const FilterOp_T &filterOp, const size_t numThreads)
 
FIELD3D_API V3i detail::mipResolution (const V3i &baseRes, const size_t level, const V3i &add)
 
template<typename Field_T , typename FilterOp_T >
void detail::mipSeparable (const Field_T &src, Field_T &tgt, const V3i &oldRes, const V3i &newRes, const size_t level, const V3i &add, const FilterOp_T &filterOp, const size_t dim, const size_t numThreads)
 Threaded implementation of separable MIP filtering. More...
 
template<typename Data_T >
size_t detail::threadingBlockSize (const DenseField< Data_T > &)
 Constant size for all dense fields. More...
 
template<typename Data_T >
size_t detail::threadingBlockSize (const SparseField< Data_T > &f)
 Use block size for sparse fields. More...
 

Variables

FIELD3D_API const std::string detail::k_mipOffsetStr = "mipoffset"
 

Detailed Description

Contains MIP-related utility functions.

Definition in file MIPUtil.h.

Function Documentation

◆ computeOffset()

FIELD3D_NAMESPACE_OPEN V3i computeOffset ( const FieldRes f)

Computes the origin/offset of a field.

Definition at line 157 of file MIPUtil.cpp.

158 {
159  V3d wsOrigin(0.0), vsOrigin;
160 
161  f.mapping()->worldToVoxel(wsOrigin, vsOrigin);
162 
163  V3i offset(-static_cast<int>(std::floor(vsOrigin.x + 0.5)),
164  -static_cast<int>(std::floor(vsOrigin.y + 0.5)),
165  -static_cast<int>(std::floor(vsOrigin.z + 0.5)));
166 
167  return offset;
168 }

References detail::floor(), and FieldRes::mapping().

◆ makeMIP() [1/2]

template<typename MIPField_T , typename Filter_T >
MIPField_T::Ptr makeMIP ( const typename MIPField_T::NestedType &  base,
const int  minSize,
const V3i offset,
const size_t  numThreads 
)

Constructs a MIP representation of the given field, with optional offset vector. The offset vector indicates the 'true' voxel space coordinate of the (0, 0, 0) voxel, such that a consistent voxel placement can be used for the MIP levels.

Definition at line 490 of file MIPUtil.h.

492 {
493  using namespace Field3D::detail;
494 
495  typedef typename MIPField_T::value_type Data_T;
496  typedef typename MIPField_T::NestedType Src_T;
497  typedef typename Src_T::Ptr SrcPtr;
498  typedef typename MIPField_T::Ptr MIPPtr;
499  typedef std::vector<typename Src_T::Ptr> SrcVec;
500 
501  if (base.extents() != base.dataWindow()) {
502  return MIPPtr();
503  }
504 
505  // Initialize output vector with base resolution
506  SrcVec result;
507  result.push_back(field_dynamic_cast<Src_T>(base.clone()));
508 
509  // Iteration variables
510  V3i res = base.extents().size() + V3i(1);
511  V3i offset = baseOffset;
512 
513  // Loop until minimum size is found
514  size_t level = 1;
515  while ((res.x > minSize || res.y > minSize || res.z > minSize) &&
516  (res.x > 2 && res.y > 2 && res.z > 2)) {
517  // Perform filtering
518  SrcPtr nextField(new Src_T);
519  mipResample(base, *result.back(), *nextField, level, offset,
520  Filter_T(), numThreads);
521  // Add to vector of filtered fields
522  result.push_back(nextField);
523  // Set up for next iteration
524  res = nextField->dataWindow().size() + V3i(1);
525  // ... offset needs to be rounded towards negative inf, not towards zero
526  for (int i = 0; i < 3; ++i) {
527  if (offset[i] < 0) {
528  offset[i] = (offset[i] - 1) / 2;
529  } else {
530  offset[i] /= 2;
531  }
532  }
533  level++;
534  }
535 
536  MIPPtr mipField(new MIPField_T);
537  mipField->name = base.name;
538  mipField->attribute = base.attribute;
539  mipField->copyMetadata(base);
540  mipField->setMIPOffset(baseOffset);
541  mipField->setup(result);
542 
543  return mipField;
544 }

References detail::mipResample().

◆ makeMIP() [2/2]

template<typename MIPField_T , typename Filter_T >
MIPField_T::Ptr makeMIP ( const typename MIPField_T::NestedType &  base,
const int  minSize,
const size_t  numThreads 
)

Constructs a MIP representation of the given field.

Definition at line 477 of file MIPUtil.h.

479 {
480  // By default, there is no offset
481  const V3i zero(0);
482  // Call out to perform actual work
483  return makeMIP<MIPField_T, Filter_T>(base, minSize, zero, numThreads);
484 }
V3i
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3d
Imath::V3d V3d
Definition: SpiMathLib.h:74
detail::floor
FIELD3D_VEC3_T< T > floor(const FIELD3D_VEC3_T< T > &v)
Floor function for Vec3.
Definition: CoordSys.h:104
FieldRes::mapping
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:263
detail::mipResample
void mipResample(const Field_T &base, const Field_T &src, Field_T &tgt, const size_t level, const V3i &offset, const FilterOp_T &filterOp, const size_t numThreads)
Definition: MIPUtil.h:421