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.
 

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

722 {
723 // Store first value
724 Data_T first = block.data[0];
725 // Iterate over rest
726 bool match = true;
727 size_t len = blockSize.x * blockSize.y * blockSize.z;
728 if (validSize == blockSize) {
729 // interior block so look at all voxels
730 for (size_t i = 0; i < len; i++) {
731 if (block.data[i] != first) {
732 match = false;
733 break;
734 }
735 }
736 } else {
737 // only look at valid voxels
738 int x=0, y=0, z=0;
739 for (size_t i = 0; i < len; i++, x++) {
740 if (x >= blockSize.x) {
741 x = 0;
742 ++y;
743 if (y >= blockSize.y) {
744 y = 0;
745 ++z;
746 }
747 }
748 if (x >= validSize.x || y >= validSize.y || z >= validSize.z) {
749 continue;
750 }
751 if (block.data[i] != first) {
752 match = false;
753 break;
754 }
755 }
756 } // end of interior block test
757
758 if (match) {
759 retEmptyValue = first;
760 return true;
761 } else {
762 return false;
763 }
764 }
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.

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


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