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

#include <MIPUtil.h>

Public Member Functions

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

Private Attributes

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>
struct detail::MIPSeparableThreadOp< Field_T, FilterOp_T >

Definition at line 170 of file MIPUtil.h.

Constructor & Destructor Documentation

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

Definition at line 172 of file MIPUtil.h.

177  : m_src(src),
178  m_tgt(tgt),
179  m_filterOp(filterOp),
180  m_level(level),
181  m_dim(dim),
182  m_blocks(blocks),
183  m_nextIdx(nextIdx),
184  m_mutex(mutex),
185  m_numBlocks(blocks.size())
186  {
187  // Empty
188  }
const std::vector< Box3i > & m_blocks
Definition: MIPUtil.h:282
const FilterOp_T & m_filterOp
Definition: MIPUtil.h:279
const size_t m_numBlocks
Definition: MIPUtil.h:285
boost::mutex & m_mutex
Definition: MIPUtil.h:284
const Field_T & m_src
Definition: MIPUtil.h:277

Member Function Documentation

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

Definition at line 190 of file MIPUtil.h.

References detail::ceil(), detail::checkInputEmpty(), discToCont(), and detail::floor().

191  {
192  using namespace std;
193 
194  // Defer to ComputationType to determine the processing data type
195  typedef typename Field_T::value_type Data_T;
196  typedef typename ComputationType<Data_T>::type Value_T;
197 
198  // To ensure we don't sample outside source data
199  Box3i srcDw = m_src.dataWindow();
200 
201  // Coordinate frame conversion constants
202  const float tgtToSrcMult = 2.0;
203  const float filterCoordMult = 1.0f / (tgtToSrcMult);
204 
205  // Filter info
206  const float support = m_filterOp.support();
207 
208  // Get next index to process
209  size_t idx;
210  {
211  boost::mutex::scoped_lock lock(m_mutex);
212  idx = m_nextIdx;
213  m_nextIdx++;
214  }
215  // Keep going while there is data to process
216  while (idx < m_numBlocks) {
217  // Grab the bounds
218  const Box3i box = m_blocks[idx];
219  // Early exit if input blocks are all empty
220  if (!detail::checkInputEmpty(m_src, m_tgt, box, support, m_dim)) {
221  // For each output voxel
222  for (int k = box.min.z; k <= box.max.z; ++k) {
223  for (int j = box.min.y; j <= box.max.y; ++j) {
224  for (int i = box.min.x; i <= box.max.x; ++i) {
225  Value_T accumValue = static_cast<Value_T>(0.0);
226  float accumWeight = 0.0f;
227  // Transform from current point in target frame to source frame
228  const int curTgt = V3i(i, j, k)[m_dim];
229  const float curSrc = discToCont(curTgt) * tgtToSrcMult;
230  // Find interval
231  int startSrc =
232  static_cast<int>(std::floor(curSrc - support * tgtToSrcMult));
233  int endSrc =
234  static_cast<int>(std::ceil(curSrc + support *
235  tgtToSrcMult)) - 1;
236  startSrc = std::max(startSrc, srcDw.min[m_dim]);
237  endSrc = std::min(endSrc, srcDw.max[m_dim]);
238  // Loop over source voxels
239  for (int s = startSrc; s <= endSrc; ++s) {
240  // Source index
241  const int xIdx = m_dim == 0 ? s : i;
242  const int yIdx = m_dim == 1 ? s : j;
243  const int zIdx = m_dim == 2 ? s : k;
244  // Source voxel in continuous coords
245  const float srcP = discToCont(s);
246  // Compute filter weight in source space (twice as wide)
247  const float weight = m_filterOp.eval(std::abs(srcP - curSrc) *
248  filterCoordMult);
249  // Value
250  const Value_T value = m_src.fastValue(xIdx, yIdx, zIdx);
251  // Update
252  accumWeight += weight;
253  accumValue += value * weight;
254  }
255  // Update final value
256  if (accumWeight > 0.0f &&
257  accumValue != static_cast<Value_T>(0.0)) {
258  m_tgt.fastLValue(i, j, k) = accumValue / accumWeight;
259  }
260  }
261  }
262  }
263  } // Empty input
264  // Get next index
265  {
266  boost::mutex::scoped_lock lock(m_mutex);
267  idx = m_nextIdx;
268  m_nextIdx++;
269  }
270  }
271  }
bool checkInputEmpty(const SparseField< Data_T > &src, const SparseField< Data_T > &, const Box3i &tgtBox, const float support, const size_t dim)
Definition: MIPUtil.h:119
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
const std::vector< Box3i > & m_blocks
Definition: MIPUtil.h:282
Imath::V3i V3i
Definition: SpiMathLib.h:71
const FilterOp_T & m_filterOp
Definition: MIPUtil.h:279
FIELD3D_VEC3_T< T > floor(const FIELD3D_VEC3_T< T > &v)
Floor function for Vec3.
Definition: CoordSys.h:95
const size_t m_numBlocks
Definition: MIPUtil.h:285
boost::mutex & m_mutex
Definition: MIPUtil.h:284
FIELD3D_VEC3_T< T > ceil(const FIELD3D_VEC3_T< T > &v)
Ceil function for Vec3.
Definition: CoordSys.h:105
const Field_T & m_src
Definition: MIPUtil.h:277
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel...
Definition: Field.h:1075

Member Data Documentation

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

Definition at line 277 of file MIPUtil.h.

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

Definition at line 278 of file MIPUtil.h.

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

Definition at line 279 of file MIPUtil.h.

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

Definition at line 280 of file MIPUtil.h.

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

Definition at line 281 of file MIPUtil.h.

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

Definition at line 282 of file MIPUtil.h.

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

Definition at line 283 of file MIPUtil.h.

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

Definition at line 284 of file MIPUtil.h.

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

Definition at line 285 of file MIPUtil.h.


The documentation for this struct was generated from the following file: