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>

List of all members.

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.

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

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.

  {
    // Store first value
    Data_T first = block.data[0];
    // Iterate over rest
    bool match = true;
    if (validSize == blockSize) {
      // interior block so look at all voxels
      for (typename std::vector<Data_T>::const_iterator i = block.data.begin();
           i != block.data.end(); ++i) {
        if (*i != first) {
          match = false;
          break;
        }
      }
    } else {
      // only look at valid voxels
      int x=0, y=0, z=0;
      for (typename std::vector<Data_T>::const_iterator i = block.data.begin();
           i != block.data.end(); ++i, ++x) {
        if (x >= blockSize.x) {
          x = 0;
          ++y;
          if (y >= blockSize.y) {
            y = 0;
            ++z;
          }
        }
        if (x >= validSize.x || y >= validSize.y || z >= validSize.z) {
          continue;
        }

        if (*i != first) {
          match = false;
          break;
        }
      }
    } // end of interior block test

    if (match) {
      retEmptyValue = first;
      return true;
    } else {
      return false;
    }
  }

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