Field3D
detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T > Struct Template Reference

#include <MIPUtil.h>

Public Types

typedef Field_T::value_type T
 

Public Member Functions

 MIPSeparableThreadOp (const Field_T &src, Field_T &tgt, const size_t level, const V3i &add, const FilterOp_T &filterOp, const size_t dim, const std::vector< Box3i > &blocks, size_t &nextIdx, boost::mutex &mutex)
 
void operator() ()
 

Private Attributes

const V3im_add
 
const std::vector< Box3i > & m_blocks
 
const size_t m_dim
 
const FilterOp_T & m_filterOp
 
const size_t m_level
 
boost::mutex & m_mutex
 
size_t & m_nextIdx
 
const size_t m_numBlocks
 
const Field_T & m_src
 
Field_T & m_tgt
 

Detailed Description

template<typename Field_T, typename FilterOp_T, bool IsAnalytic_T>
struct detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >

Definition at line 187 of file MIPUtil.h.

Member Typedef Documentation

◆ T

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
typedef Field_T::value_type detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::T

Definition at line 189 of file MIPUtil.h.

Constructor & Destructor Documentation

◆ MIPSeparableThreadOp()

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::MIPSeparableThreadOp ( const Field_T &  src,
Field_T &  tgt,
const size_t  level,
const V3i add,
const FilterOp_T &  filterOp,
const size_t  dim,
const std::vector< Box3i > &  blocks,
size_t &  nextIdx,
boost::mutex &  mutex 
)
inline

Definition at line 191 of file MIPUtil.h.

197  : m_src(src),
198  m_tgt(tgt),
199  m_filterOp(filterOp),
200  m_level(level),
201  m_add(add),
202  m_dim(dim),
203  m_blocks(blocks),
204  m_nextIdx(nextIdx),
205  m_mutex(mutex),
206  m_numBlocks(blocks.size())
207  {
208  // Empty
209  }

Member Function Documentation

◆ operator()()

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
void detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::operator() ( )
inline

Definition at line 211 of file MIPUtil.h.

212  {
213  using namespace std;
214 
215  // Defer to ComputationType to determine the processing data type
216  typedef typename Field_T::value_type Data_T;
217  typedef typename ComputationType<Data_T>::type Value_T;
218 
219  // To ensure we don't sample outside source data
220  Box3i srcDw = m_src.dataWindow();
221 
222  // Coordinate frame conversion constants
223  const float tgtToSrcMult = 2.0;
224  const float filterCoordMult = 1.0f / (tgtToSrcMult);
225 
226  // Filter info, support size in target space
227  const float support = m_filterOp.support();
228 
229  // Get next index to process
230  size_t idx;
231  {
232  boost::mutex::scoped_lock lock(m_mutex);
233  idx = m_nextIdx;
234  m_nextIdx++;
235  }
236  // Keep going while there is data to process
237  while (idx < m_numBlocks) {
238  // Grab the bounds
239  const Box3i box = m_blocks[idx];
240  // Early exit if input blocks are all empty
241  if (!detail::checkInputEmpty(m_src, m_tgt, box, support, m_dim)) {
242  // For each output voxel
243  for (int k = box.min.z; k <= box.max.z; ++k) {
244  for (int j = box.min.y; j <= box.max.y; ++j) {
245  for (int i = box.min.x; i <= box.max.x; ++i) {
246  Value_T accumValue(m_filterOp.initialValue());
247  if (IsAnalytic_T) {
248  // Transform from current point in target frame to source frame
249  const int curTgt = V3i(i, j, k)[m_dim];
250  const float curSrc = discToCont(curTgt) * tgtToSrcMult - m_add[m_dim];
251  // Find interval
252  int startSrc =
253  static_cast<int>(std::floor(curSrc - support * tgtToSrcMult));
254  int endSrc =
255  static_cast<int>(std::ceil(curSrc + support *
256  tgtToSrcMult)) - 1;
257  // Clamp coordinates
258  startSrc = std::max(startSrc, srcDw.min[m_dim]);
259  endSrc = std::min(endSrc, srcDw.max[m_dim]);
260  // Loop over source voxels
261  for (int s = startSrc; s <= endSrc; ++s) {
262  // Source index
263  const int xIdx = m_dim == 0 ? s : i;
264  const int yIdx = m_dim == 1 ? s : j;
265  const int zIdx = m_dim == 2 ? s : k;
266  // Source voxel in continuous coords
267  const float srcP = discToCont(s);
268  // Compute filter weight in source space (twice as wide)
269  const float weight = m_filterOp.eval(std::abs(srcP - curSrc) *
270  filterCoordMult);
271  // Value
272  const Value_T value = m_src.fastValue(xIdx, yIdx, zIdx);
273  // Update
274  if (weight > 0.0f) {
275  FilterOp_T::op(accumValue, value);
276  }
277  }
278  // Update final value
279  if (accumValue !=
280  static_cast<Value_T>(m_filterOp.initialValue())) {
281  m_tgt.fastLValue(i, j, k) = accumValue;
282  }
283  } else {
284  float accumWeight = 0.0f;
285  // Transform from current point in target frame to source frame
286  const int curTgt = V3i(i, j, k)[m_dim];
287  const float curSrc = discToCont(curTgt) * tgtToSrcMult - m_add[m_dim];
288  // Find interval
289  int startSrc =
290  static_cast<int>(std::floor(curSrc - support * tgtToSrcMult));
291  int endSrc =
292  static_cast<int>(std::ceil(curSrc + support *
293  tgtToSrcMult)) - 1;
294  // Clamp coordinates
295  startSrc = std::max(startSrc, srcDw.min[m_dim]);
296  endSrc = std::min(endSrc, srcDw.max[m_dim]);
297  // Loop over source voxels
298  for (int s = startSrc; s <= endSrc; ++s) {
299  // Source index
300  const int xIdx = m_dim == 0 ? s : i;
301  const int yIdx = m_dim == 1 ? s : j;
302  const int zIdx = m_dim == 2 ? s : k;
303  // Source voxel in continuous coords
304  const float srcP = discToCont(s);
305  // Compute filter weight in source space (twice as wide)
306  const float weight = m_filterOp.eval(std::abs(srcP - curSrc) *
307  filterCoordMult);
308  // Value
309  const Value_T value = m_src.fastValue(xIdx, yIdx, zIdx);
310  // Update
311  accumWeight += weight;
312  accumValue += value * weight;
313  }
314  // Update final value
315  if (accumWeight > 0.0f &&
316  accumValue != static_cast<Value_T>(0.0)) {
317  m_tgt.fastLValue(i, j, k) = accumValue / accumWeight;
318  }
319  } // if (IsAnalytic_T)
320  }
321  }
322  }
323  } // Empty input
324  // Get next index
325  {
326  boost::mutex::scoped_lock lock(m_mutex);
327  idx = m_nextIdx;
328  m_nextIdx++;
329  }
330  }
331  }

References detail::ceil(), detail::checkInputEmpty(), discToCont(), detail::floor(), detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_add, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_blocks, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_dim, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_filterOp, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_mutex, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_nextIdx, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_numBlocks, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_src, detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_tgt, detail::max(), and detail::min().

Member Data Documentation

◆ m_src

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const Field_T& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_src
private

◆ m_tgt

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
Field_T& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_tgt
private

◆ m_filterOp

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const FilterOp_T& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_filterOp
private

◆ m_level

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const size_t detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_level
private

Definition at line 340 of file MIPUtil.h.

◆ m_add

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const V3i& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_add
private

◆ m_dim

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const size_t detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_dim
private

◆ m_blocks

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const std::vector<Box3i>& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_blocks
private

◆ m_nextIdx

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
size_t& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_nextIdx
private

◆ m_mutex

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
boost::mutex& detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_mutex
private

◆ m_numBlocks

template<typename Field_T , typename FilterOp_T , bool IsAnalytic_T>
const size_t detail::MIPSeparableThreadOp< Field_T, FilterOp_T, IsAnalytic_T >::m_numBlocks
private

The documentation for this struct was generated from the following file:
detail::MIPSeparableThreadOp::m_numBlocks
const size_t m_numBlocks
Definition: MIPUtil.h:346
V3i
Imath::V3i V3i
Definition: SpiMathLib.h:71
detail::MIPSeparableThreadOp::m_tgt
Field_T & m_tgt
Definition: MIPUtil.h:338
discToCont
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel.
Definition: Field.h:1070
detail::MIPSeparableThreadOp::m_filterOp
const FilterOp_T & m_filterOp
Definition: MIPUtil.h:339
detail::checkInputEmpty
bool checkInputEmpty(const SparseField< Data_T > &src, const SparseField< Data_T > &, const Box3i &tgtBox, const float support, const size_t dim)
Definition: MIPUtil.h:136
detail::floor
FIELD3D_VEC3_T< T > floor(const FIELD3D_VEC3_T< T > &v)
Floor function for Vec3.
Definition: CoordSys.h:104
detail::MIPSeparableThreadOp::m_add
const V3i & m_add
Definition: MIPUtil.h:341
detail::max
T max(const T a, const T2 b)
Max operation on mixed types.
Definition: FieldSampler.h:32
detail::MIPSeparableThreadOp::m_blocks
const std::vector< Box3i > & m_blocks
Definition: MIPUtil.h:343
detail::MIPSeparableThreadOp::m_mutex
boost::mutex & m_mutex
Definition: MIPUtil.h:345
detail::MIPSeparableThreadOp::m_dim
const size_t m_dim
Definition: MIPUtil.h:342
detail::ceil
FIELD3D_VEC3_T< T > ceil(const FIELD3D_VEC3_T< T > &v)
Ceil function for Vec3.
Definition: CoordSys.h:114
detail::MIPSeparableThreadOp::m_nextIdx
size_t & m_nextIdx
Definition: MIPUtil.h:344
detail::MIPSeparableThreadOp::m_src
const Field_T & m_src
Definition: MIPUtil.h:337
detail::MIPSeparableThreadOp::m_level
const size_t m_level
Definition: MIPUtil.h:340
Box3i
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
detail::min
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
detail::ComputationType::type
T type
Definition: MIPUtil.h:102