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 697 of file SparseField.h.

Member Function Documentation

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 707 of file SparseField.h.

References Sparse::SparseBlock< Data_T >::data, and match().

709  {
710  // Store first value
711  Data_T first = block.data[0];
712  // Iterate over rest
713  bool match = true;
714  size_t len = blockSize.x * blockSize.y * blockSize.z;
715  if (validSize == blockSize) {
716  // interior block so look at all voxels
717  for (size_t i = 0; i < len; i++) {
718  if (block.data[i] != first) {
719  match = false;
720  break;
721  }
722  }
723  } else {
724  // only look at valid voxels
725  int x=0, y=0, z=0;
726  for (size_t i = 0; i < len; i++, x++) {
727  if (x >= blockSize.x) {
728  x = 0;
729  ++y;
730  if (y >= blockSize.y) {
731  y = 0;
732  ++z;
733  }
734  }
735  if (x >= validSize.x || y >= validSize.y || z >= validSize.z) {
736  continue;
737  }
738  if (block.data[i] != first) {
739  match = false;
740  break;
741  }
742  }
743  } // end of interior block test
744 
745  if (match) {
746  retEmptyValue = first;
747  return true;
748  } else {
749  return false;
750  }
751  }
bool match(const std::string &name, const std::string &attribute, const std::vector< std::string > &patterns, const MatchFlags flags=MatchEmptyPattern)
Matches a <name>:<attribute> string against a set of patterns.

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