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

namespace | 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.
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.
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.
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.
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.
template<typename Data_T>
size_t | detail::threadingBlockSize (const DenseField< Data_T > &)
| Constant size for all dense fields.
template<typename Data_T>
size_t | detail::threadingBlockSize (const SparseField< Data_T > &f)
| Use block size for sparse fields.

## Variables

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.

{
V3d wsOrigin(0.0), vsOrigin;
f.mapping()->worldToVoxel(wsOrigin, vsOrigin);
V3i offset(-static_cast<int>(std::floor(vsOrigin.x + 0.5)),
-static_cast<int>(std::floor(vsOrigin.y + 0.5)),
-static_cast<int>(std::floor(vsOrigin.z + 0.5)));
return offset;
}
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
V3d
Imath::V3d V3d
Definition SpiMathLib.h:74
FieldRes::mapping
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition Field.h:263

References 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.

{
using namespace Field3D::detail;
typedef typename MIPField_T::value_type Data_T;
typedef typename MIPField_T::NestedType Src_T;
typedef typename Src_T::Ptr SrcPtr;
typedef typename MIPField_T::Ptr MIPPtr;
typedef std::vector<typename Src_T::Ptr> SrcVec;
if (base.extents() != base.dataWindow()) {
return MIPPtr();
}
// Initialize output vector with base resolution
SrcVec result;
result.push_back(field_dynamic_cast<Src_T>(base.clone()));
// Iteration variables
V3i res = base.extents().size() + V3i(1);
V3i offset = baseOffset;
// Loop until minimum size is found
size_t level = 1;
while ((res.x > minSize || res.y > minSize || res.z > minSize) &&
(res.x > 2 && res.y > 2 && res.z > 2)) {
// Perform filtering
SrcPtr nextField(new Src_T);
mipResample(base, *result.back(), *nextField, level, offset,
Filter_T(), numThreads);
// Add to vector of filtered fields
result.push_back(nextField);
// Set up for next iteration
res = nextField->dataWindow().size() + V3i(1);
// ... offset needs to be rounded towards negative inf, not towards zero
for (int i = 0; i < 3; ++i) {
if (offset[i] < 0) {
offset[i] = (offset[i] - 1) / 2;
} else {
offset[i] /= 2;
}
}
level++;
}
MIPPtr mipField(new MIPField_T);
mipField->name = base.name;
mipField->attribute = base.attribute;
mipField->copyMetadata(base);
mipField->setMIPOffset(baseOffset);
mipField->setup(result);
return mipField;
}
field_dynamic_cast
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition RefCount.h:256
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

References field_dynamic_cast().

Referenced by makeMinMax(), and makeMIP().

## 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.

{
// By default, there is no offset
const V3i zero(0);
// Call out to perform actual work
return makeMIP<MIPField_T, Filter_T>(base, minSize, zero, numThreads);
}
makeMIP
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 in...
Definition MIPUtil.h:490

References makeMIP().