Field3D
Sparse::CheckAllEqual< Data_T > Struct Template Reference

Checks if all the values in the SparseBlock are equal. Used by SparseField::releaseBlocks(). More...

#include <SparseField.h>

Public Member Functions

bool check (const SparseBlock< Data_T > &block, Data_T &retEmptyValue, const V3i &validSize, const V3i &blockSize)
 Checks whether a given block can be released. It's safe to assume that the block is allocated if this functor is called. More...
 

Detailed Description

template<typename Data_T>
struct Sparse::CheckAllEqual< Data_T >

Checks if all the values in the SparseBlock are equal. Used by SparseField::releaseBlocks().

Definition at line 455 of file SparseField.h.

Member Function Documentation

◆ check()

template<typename Data_T >
bool Sparse::CheckAllEqual< Data_T >::check ( const SparseBlock< Data_T > &  block,
Data_T &  retEmptyValue,
const V3i validSize,
const V3i blockSize 
)
inline

Checks whether a given block can be released. It's safe to assume that the block is allocated if this functor is called.

Parameters
blockReference to the block to check
retEmptyValueIf the block is to be removed, store the "empty value" that replaces it in this variable
validSizeNumber of voxels per dim within field data window
blockSizeNumber of voxels actually allocated per dim
Returns
Whether or not the supplied block can be released.

Definition at line 465 of file SparseField.h.

References Sparse::SparseBlock< Data_T >::data.

467  {
468  // Store first value
469  Data_T first = block.data[0];
470  // Iterate over rest
471  bool match = true;
472  if (validSize == blockSize) {
473  // interior block so look at all voxels
474  for (typename std::vector<Data_T>::const_iterator i = block.data.begin();
475  i != block.data.end(); ++i) {
476  if (*i != first) {
477  match = false;
478  break;
479  }
480  }
481  } else {
482  // only look at valid voxels
483  int x=0, y=0, z=0;
484  for (typename std::vector<Data_T>::const_iterator i = block.data.begin();
485  i != block.data.end(); ++i, ++x) {
486  if (x >= blockSize.x) {
487  x = 0;
488  ++y;
489  if (y >= blockSize.y) {
490  y = 0;
491  ++z;
492  }
493  }
494  if (x >= validSize.x || y >= validSize.y || z >= validSize.z) {
495  continue;
496  }
497 
498  if (*i != first) {
499  match = false;
500  break;
501  }
502  }
503  } // end of interior block test
504 
505  if (match) {
506  retEmptyValue = first;
507  return true;
508  } else {
509  return false;
510  }
511  }

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