Shiokaze Framework
A research-oriented fluid solver for computer graphics
array_utility3.h
Go to the documentation of this file.
1 /*
2 ** array_utility3.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on Feb 14, 2018.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #include "array3.h"
26 #include <cmath>
27 #include <cstdlib>
28 //
29 #ifndef SHKZ_ARRAY_UTILITY3_H
30 #define SHKZ_ARRAY_UTILITY3_H
31 //
33 //
35 namespace array_utility3 {
46  template <class T> bool empty( const array3<T> &array ) {
47  return array.shape().count() == 0;
48  }
57  template <class T> bool has_different_values ( const array3<T> &array ) {
58  bool result (false);
59  bool assigned (false);
60  T value;
61  array.interruptible_const_serial_actives([&](int i, int j, int k, const auto &it) {
62  if( ! assigned ) {
63  value = array(i,j,k);
64  assigned = true;
65  } else if(array(i,j,k)!=value) {
66  result = true;
67  return true;
68  }
69  return false;
70  });
71  return result;
72  }
82  template <class T> bool has_value_not( const array3<T> &array, const T &v ) {
83  bool result (false);
84  array.interruptible_const_serial_actives([&](int i, int j, int k, const auto &it) {
85  if(it() != v) {
86  result = true;
87  return true;
88  }
89  return false;
90  });
91  return result;
92  }
101  template <class T> bool value_exist( const array3<T> &array ) {
102  return has_value_not(array,array.get_background_value());
103  }
112  template <class T> bool levelset_exist( const array3<T> &levelset ) {
113  //
114  bool hasInside (false);
115  levelset.interruptible_const_serial_actives([&](int i, int j, int k, const auto &it){
116  if( it() < 0.0 ) {
117  hasInside = true;
118  }
119  return hasInside;
120  });
121  return hasInside;
122  }
123  //
124 };
125 //
127 //
128 #endif
129 //
array_utility3::has_different_values
bool has_different_values(const array3< T > &array)
Get if a grid constain different values.
Definition: array_utility3.h:57
array3::interruptible_const_serial_actives
void interruptible_const_serial_actives(std::function< bool(const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array3.h:1571
array_utility3::levelset_exist
bool levelset_exist(const array3< T > &levelset)
Get if a level set grid constain both negative and positive values.
Definition: array_utility3.h:112
array3::get_background_value
T get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: array3.h:477
shape3::count
size_t count() const
Count the number of cells of the grid of this shape.
Definition: shape.h:857
array_utility3
Namespace that provides various utility functions.
Definition: array_utility3.h:37
array_utility3::value_exist
bool value_exist(const array3< T > &array)
Get if a grid constain a value that is different from the background value.
Definition: array_utility3.h:101
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array3.h
array_utility3::has_value_not
bool has_value_not(const array3< T > &array, const T &v)
Get if a grid constain a value that is different from an input value.
Definition: array_utility3.h:82
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array_utility3::empty
bool empty(const array3< T > &array)
Get if a grid is empty.
Definition: array_utility3.h:46
array3::shape
shape3 shape() const
Get the shape of the array.
Definition: array3.h:218
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42