Shiokaze Framework
A research-oriented fluid solver for computer graphics
array_utility2.h
Go to the documentation of this file.
1 /*
2 ** array_utility2.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 "array2.h"
26 #include "macarray2.h"
27 #include <cmath>
28 #include <cstdlib>
29 //
30 #ifndef SHKZ_ARRAY_UTILITY2_H
31 #define SHKZ_ARRAY_UTILITY2_H
32 //
34 //
36 namespace array_utility2 {
47  template <class T> bool empty( const array2<T> &array ) {
48  return array.shape().count() == 0;
49  }
58  template <class T> bool has_different_values ( const array2<T> &array ) {
59  bool result (false);
60  bool assigned (false);
61  T value;
62  array.interruptible_const_serial_actives([&](int i, int j, const auto &it) {
63  if( ! assigned ) {
64  value = it();
65  assigned = true;
66  } else if(it()!=value) {
67  result = true;
68  return true;
69  }
70  return false;
71  });
72  return result;
73  }
83  template <class T> bool has_value_not( const array2<T> &array, const T &v ) {
84  bool result (false);
85  array.interruptible_const_serial_actives([&](int i, int j, const auto &it) {
86  if(it()!=v) {
87  result = true;
88  return true;
89  }
90  return false;
91  });
92  return result;
93  }
102  template <class T> bool value_exist( const array2<T> &array ) {
103  return has_value_not(array,array.get_background_value());
104  }
113  template <class T> bool levelset_exist( const array2<T> &levelset ) {
114  //
115  bool hasInside (false);
116  levelset.interruptible_const_serial_actives([&](int i, int j, const auto &it){
117  if( it() < 0.0 ) {
118  hasInside = true;
119  }
120  return hasInside;
121  });
122  return hasInside;
123  }
124  //
125 };
126 //
128 //
129 #endif
130 //
macarray2.h
array_utility2::value_exist
bool value_exist(const array2< T > &array)
Get if a grid constain a value that is different from the background value.
Definition: array_utility2.h:102
array_utility2::has_different_values
bool has_different_values(const array2< T > &array)
Get if a grid constain different values.
Definition: array_utility2.h:58
array2.h
array2::get_background_value
T get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: array2.h:475
shape2::count
size_t count() const
Count the number of cells of the grid of this shape.
Definition: shape.h:385
array_utility2::has_value_not
bool has_value_not(const array2< T > &array, const T &v)
Get if a grid constain a value that is different from an input value.
Definition: array_utility2.h:83
array2::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: array2.h:1551
array2::shape
shape2 shape() const
Get the shape of the array.
Definition: array2.h:218
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array_utility2::empty
bool empty(const array2< T > &array)
Get if a grid is empty.
Definition: array_utility2.h:47
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
array_utility2
Namespace that provides various utility functions regarding grid.
Definition: array_utility2.h:38
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array_utility2::levelset_exist
bool levelset_exist(const array2< T > &levelset)
Get if a level set grid constain both negative and positive values.
Definition: array_utility2.h:113