Shiokaze Framework
A research-oriented fluid solver for computer graphics
array2.h
Go to the documentation of this file.
1 /*
2 ** array2.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 7, 2017.
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 #ifndef SHKZ_ARRAY2_H
26 #define SHKZ_ARRAY2_H
27 //
28 #include <shiokaze/math/vec.h>
30 #include <cassert>
31 #include <cstdio>
32 #include <algorithm>
33 #include <utility>
34 #include <shiokaze/math/shape.h>
35 #include "array_core2.h"
36 //
38 //
40 template<class T> class array2 : public recursive_configurable, public messageable {
43 public:
56  array2( recursive_configurable *parent, const shape2 &shape, T value=T(), std::string core_name="" ) :
57  m_core_name(core_name), m_shape(shape), m_background_value(value) {
58  if( parent ) parent->add_child(this);
59  else setup_now();
60  }
69  array2( recursive_configurable *parent, std::string core_name="" ) : array2(parent,shape2(0,0),T(),core_name) {}
76  array2( std::string core_name="" ) : array2(nullptr,shape2(0,0),T(),core_name) {}
87  array2( const shape2 &shape, T value=T(), std::string core_name="" ) : array2(nullptr,shape,value,core_name) {}
88  //
89 private:
90  //
91  virtual void load( configuration &config ) override {
92  if( m_core_name.empty()) {
93  m_core_name = shkz_default_array_core2;
94  } else {
95  auto pos = m_core_name.find('*');
96  if( pos != std::string::npos ) {
97  m_core_name.erase(pos,1);
98  m_core_name.insert(pos,shkz_default_array_core2);
99  }
100  }
101  m_core = array_core2::quick_load_module(config,m_core_name);
102  }
103  //
104  virtual void configure( configuration &config ) override {
105  m_core->recursive_configure(config);
106  }
107  //
108  virtual void post_initialize() override {
109  if( shape().count() && ! m_is_initialized ) {
110  initialize(m_shape,m_background_value);
111  }
112  }
113  //
114 public:
125  virtual bool send_message( std::string message, void *ptr ) override {
126  return get_core()->send_message(message,ptr);
127  }
138  virtual bool const_send_message( std::string message, void *ptr ) const override {
139  return get_core()->const_send_message(message,ptr);
140  }
147  array2( const array2 &array ) {
148  m_core_name = array.m_core_name;
149  setup_now();
150  copy(array);
151  }
160  void set_touch_only_actives( bool touch_only_actives ) {
161  m_touch_only_actives = touch_only_actives;
162  }
169  array2& operator=(const array2 &array) {
170  if( this != &array ) {
171  copy(array);
172  }
173  return *this;
174  }
181  void copy( const array2 &array ) {
182  if( this != &array ) {
183  set_type(array.type());
184  assert(m_core);
185  if( array.m_core ) {
186  m_core->copy(*array.get_core(),[&](void *target, const void *src) {
187  new (target) T(*static_cast<const T *>(src));
188  },m_parallel);
189  }
190  }
191  }
198  std::vector<T> linearize() const {
199  const shape3 &s = m_shape;
200  std::vector<T> result(s.count(),m_background_value);
201  const_parallel_actives([&]( int i, int j, auto it ) {
202  result[i+j*s.w] = it();
203  });
204  const_parallel_inside([&]( int i, int j, auto it ) {
205  if( ! it.active()) result[i+j*s.w] = it();
206  });
207  return result;
208  }
209  virtual ~array2() {
210  clear();
211  }
218  shape2 shape() const { return m_shape; }
227  void initialize( const shape2 &shape, T value=T()) {
228  clear();
229  m_core->initialize(shape.w,shape.h,sizeof(T));
230  m_shape = shape;
231  m_background_value = value;
232  m_fillable = false;
233  m_levelset = false;
234  m_is_initialized = true;
235  }
242  void set_as_levelset( double bandwidth_half ) {
243  m_levelset = true;
244  m_fillable = false;
245  m_background_value = bandwidth_half;
246  m_fill_value = -bandwidth_half;
247  }
254  void set_as_fillable( const T& fill_value ) {
255  m_levelset = false;
256  m_fillable = true;
257  m_fill_value = fill_value;
258  }
265  void set_as_fillable_as( const array2 &array ) {
266  set_as_fillable(array.m_fill_value);
267  }
274  void set_as_levelset_as( const array2 &array ) {
275  set_as_levelset(array.m_background_value);
276  }
283  bool is_fillable() const {
284  return m_fillable;
285  }
292  bool is_levelset() const {
293  return m_levelset;
294  }
299  void flood_fill() {
300  if( m_fillable ) {
301  m_core->flood_fill([&](const void *value_ptr) {
302  return *static_cast<const T *>(value_ptr) == m_fill_value;
303  },m_parallel);
304  } else if( m_levelset ) {
305  m_core->flood_fill([&](const void *value_ptr) {
306  return *static_cast<const T *>(value_ptr) < 0.0;
307  },m_parallel);
308  } else {
309  printf( "Flood fill attempted without being set either levelset or fillable.\n");
310  exit(0);
311  }
312  }
319  std::vector<vec2i> fills() const {
320  std::vector<vec2i> result;
321  const_serial_inside([&](int i, int j, const auto &it) {
322  result.push_back(vec2i(i,j));
323  });
324  return result;
325  }
336  bool filled( int i, int j ) const {
337  bool filled;
338  (*m_core)(i,j,filled);
339  return filled;
340  }
349  bool filled( const vec2i &pi ) const {
350  return filled(pi[0],pi[1]);
351  }
358  size_t count () const { return m_core->count(m_parallel); }
365  std::vector<vec2i> actives() const {
366  std::vector<vec2i> result;
367  const_serial_actives([&](int i, int j, const auto &it) {
368  result.push_back(vec2i(i,j));
369  });
370  return result;
371  }
380  void activate( const std::vector<vec2i> &active_entries, const vec2i &offset=vec2i() ) {
381  for( const auto &e : active_entries ) {
382  const vec2i &pi = e + offset;
383  if( ! shape().out_of_bounds(pi) && ! active(pi)) {
384  set(pi,(*this)(pi));
385  }
386  }
387  }
396  template <class Y> void activate_as( const array2<Y> &array, const vec2i &offset=vec2i() ) {
397  array.const_serial_actives([&](int i, int j, const auto &it) {
398  const vec2i &pi = vec2i(i,j) + offset;
399  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
400  this->set(pi,(*this)(pi));
401  }
402  });
403  }
412  template <class Y> void activate_as_bit( const Y &array, const vec2i &offset=vec2i() ) {
413  array.const_serial_actives([&](int i, int j) {
414  const vec2i &pi = vec2i(i,j) + offset;
415  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
416  this->set(pi,(*this)(pi));
417  }
418  });
419  }
428  template <class Y> void activate_inside_as( const array2<Y> &array, const vec2i &offset=vec2i() ) {
429  array.const_serial_inside([&](int i, int j, const auto &it) {
430  const vec2i &pi = vec2i(i,j) + offset;
431  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
432  this->set(pi,(*this)(pi));
433  }
434  });
435  }
440  void activate_all() {
441  parallel_all([&](auto &it) {
442  it.set(it());
443  });
444  }
450  activate(fills());
451  }
460  template <class Y> void copy_active_as( const array2<Y> &array, const vec2i &offset=vec2i() ) {
461  parallel_actives([&](int i, int j, auto &it, int tn) {
462  const vec2i &pi = vec2i(i,j) + offset;
463  if( ! this->shape().out_of_bounds(pi) ) {
464  if( this->active(pi) && ! array.active(pi)) {
465  it.set_off();
466  }
467  }
468  });
469  activate_as(array,offset);
470  }
475  T get_background_value () const { return m_background_value; }
482  void set_background_value( const T& value ) { m_background_value = value; }
491  void clear() {
492  parallel_actives([&](iterator& it) {
493  it.set_off();
494  });
495  }
504  void clear(const T &v) {
505  m_background_value = v;
506  clear();
507  }
518  void set( int i, int j, const T& value ) {
519  m_core->set(i,j,[&](void *value_ptr, bool &active){
520  if( ! active ) new (value_ptr) T(value);
521  else *static_cast<T *>(value_ptr) = value;
522  active = true;
523  });
524  }
533  void set( const vec2i &pi, const T& value ) {
534  set(pi[0],pi[1],value);
535  }
546  bool active( int i, int j ) const {
547  bool filled;
548  return (*m_core)(i,j,filled) != nullptr;
549  }
558  bool active( const vec2i &pi ) const {
559  return active(pi[0],pi[1]);
560  }
571  bool safe_active( int i, int j ) const {
572  if( ! m_shape.out_of_bounds(i,j)) {
573  return active(i,j);
574  }
575  return false;
576  }
585  bool safe_active( const vec2i &pi ) const {
586  return safe_active(pi[0],pi[1]);
587  }
596  void set_off( int i, int j ) {
597  m_core->set(i,j,[&](void *value_ptr, bool &active){
598  if( active ) (static_cast<T *>(value_ptr))->~T();
599  active = false;
600  });
601  }
608  void set_off( const vec2i &pi ) {
609  set_off(pi[0],pi[1]);
610  }
621  void increment( int i, int j, const T& value ) {
622  m_core->set(i,j,[&](void *value_ptr, bool &active){
623  if( active ) *static_cast<T *>(value_ptr) += value;
624  else {
625  *static_cast<T *>(value_ptr) = m_background_value + value;
626  active = true;
627  }
628  });
629  }
638  void increment( const vec2i &pi, const T& value ) {
639  increment(pi[0],pi[1],value);
640  }
651  void subtract( int i, int j, const T& value ) {
652  m_core->set(i,j,[&](void *value_ptr, bool &active){
653  if( active ) *static_cast<T *>(value_ptr) -= value;
654  else {
655  *static_cast<T *>(value_ptr) = m_background_value - value;
656  active = true;
657  }
658  });
659  }
668  void subtract( const vec2i &pi, const T& value ) {
669  subtract(pi[0],pi[1],value);
670  }
681  void multiply( int i, int j, const T& value ) {
682  m_core->set(i,j,[&](void *value_ptr, bool &active){
683  if( active ) *static_cast<T *>(value_ptr) *= value;
684  else {
685  *static_cast<T *>(value_ptr) = m_background_value * value;
686  active = true;
687  }
688  });
689  }
698  void multiply( const vec2i &pi, const T& value ) {
699  multiply(pi[0],pi[1],value);
700  }
711  void divide( int i, int j, const T& value ) {
712  multiply(i,j,1.0/value);
713  }
722  void divide( const vec2i &pi, const T& value ) {
723  divide(pi[0],pi[1],value);
724  }
733  T* ptr(int i, int j ) {
734  bool filled (false);
735  return const_cast<T *>(static_cast<const T *>((*m_core)(i,j,filled)));
736  }
745  const T* ptr(int i, int j ) const {
746  return const_cast<array2<T> *>(this)->ptr(i,j);
747  }
754  T* ptr( const vec2i &pi ) {
755  return ptr(pi[0],pi[1]);
756  }
763  const T* ptr( const vec2i &pi ) const {
764  return const_cast<array2<T> *>(this)->ptr(pi);
765  }
774  const T& operator()(int i, int j ) const {
775  bool filled (false);
776  const T* ptr = static_cast<const T *>((*m_core)(i,j,filled));
777  if( ptr ) return *ptr;
778  else return filled ? m_fill_value : m_background_value;
779  }
786  const T& operator()(const vec2i &pi ) const {
787  return (*const_cast<array2<T> *>(this))(pi[0],pi[1]);
788  }
797  bool operator!=( const array2<T> &array ) const {
798  return ! (*this == array);
799  }
808  bool operator==(const array2<T> &v) const {
809  if( v.type() == type() ) {
810  bool differnt (false);
811  interruptible_const_serial_actives([&]( int i, int j, const const_iterator& it) {
812  if( it() != v(i,j)) {
813  differnt = true;
814  return true;
815  } else {
816  return false;
817  }
818  });
819  if( ! differnt ) {
820  interruptible_const_serial_inside([&]( int i, int j, const const_iterator& it) {
821  if( ! it.active()) {
822  if( it() != v(i,j)) {
823  differnt = true;
824  return true;
825  }
826  }
827  return false;
828  });
829  }
830  return ! differnt;
831  }
832  return false;
833  }
840  void operator=(const T &v) {
841  parallel_op([&](iterator& it) {
842  it.set(v);
843  },m_touch_only_actives);
844  }
851  void operator+=(const array2<T> &v) {
852  assert(shape()==v.shape());
853  parallel_op([&](int i, int j, iterator& it, int tn) {
854  if( ! m_touch_only_actives || v.active(i,j)) {
855  it.increment(v(i,j));
856  }
857  },m_touch_only_actives);
858  }
865  void operator-=(const array2<T> &v) {
866  assert(shape()==v.shape());
867  parallel_op([&](int i, int j, iterator& it, int tn) {
868  if( ! m_touch_only_actives || v.active(i,j)) {
869  it.subtract(v(i,j));
870  }
871  },m_touch_only_actives);
872  }
879  void operator+=(const T &v) {
880  parallel_op([&](iterator& it) {
881  it.increment(v);
882  },m_touch_only_actives);
883  }
890  void operator-=(const T &v) {
891  parallel_op([&](iterator& it) {
892  it.subtract(v);
893  },m_touch_only_actives);
894  }
901  void operator*=(const T &v) {
902  parallel_op([&](iterator& it) {
903  it.multiply(v);
904  },m_touch_only_actives);
905  }
912  void operator/=(const T &v) {
913  parallel_op([&](iterator& it) {
914  it.divide(v);
915  },m_touch_only_actives);
916  }
923  void set_thread_num( int number ) {
924  m_parallel.set_thread_num(number);
925  }
932  int get_thread_num() const {
933  return m_parallel.get_thread_num();
934  }
937  class iterator {
938  friend class array2<T>;
939  public:
946  void set( const T &value ) {
947  if( ! m_active ) allocate(value);
948  else *static_cast<T *>(m_value_ptr) = value;
949  m_active = true;
950  }
955  void set_off() {
956  if( m_active && m_value_ptr ) deallocate();
957  m_active = false;
958  }
965  void increment( const T& value ) {
966  if( m_active ) {
967  *static_cast<T *>(m_value_ptr) += value;
968  } else {
969  allocate(m_background_value + value);
970  m_active = true;
971  }
972  }
979  void subtract( const T& value ) {
980  if( m_active ) {
981  *static_cast<T *>(m_value_ptr) -= value;
982  } else {
983  allocate(m_background_value - value);
984  m_active = true;
985  }
986  }
993  void multiply( const T& value ) {
994  if( m_active ) {
995  *static_cast<T *>(m_value_ptr) *= value;
996  } else {
997  allocate(m_background_value * value);
998  m_active = true;
999  }
1000  }
1007  void divide( const T& value ) {
1008  multiply(1.0/value);
1009  }
1014  bool active() const {
1015  return m_active;
1016  }
1021  bool filled() const {
1022  return m_filled;
1023  }
1030  const T& operator()() const {
1031  if( m_active ) {
1032  return *static_cast<const T *>(m_value_ptr);
1033  } else {
1034  return m_background_value;
1035  }
1036  }
1043  T* ptr() { return m_active ? static_cast<T *>(m_value_ptr) : nullptr; }
1050  const T* ptr() const { return m_active ? static_cast<const T *>(m_value_ptr) : nullptr; }
1051  private:
1052  //
1053  iterator( void *value_ptr, bool &_active, bool _filled, const T& m_background_value )
1054  : m_value_ptr(value_ptr), m_active(_active), m_filled(_filled), m_background_value(m_background_value) {}
1055  //
1056  void allocate ( const T& value ) {
1057  new (m_value_ptr) T(value);
1058  }
1059  void deallocate() {
1060  (static_cast<T *>(m_value_ptr))->~T();
1061  }
1062  bool &m_active;
1063  bool m_filled;
1064  void *m_value_ptr;
1065  const T& m_background_value;
1066  };
1070  friend class array2<T>;
1071  public:
1076  bool active() const {
1077  return m_active;
1078  }
1083  bool filled() const {
1084  return m_filled;
1085  }
1092  const T& operator()() const {
1093  if( m_active ) {
1094  return *static_cast<const T *>(m_value_ptr);
1095  } else {
1096  return m_background_value;
1097  }
1098  }
1105  const T* ptr() const { return m_active ? static_cast<const T *>(m_value_ptr) : nullptr; }
1106  private:
1107  const_iterator( const void *value_ptr, const bool &_active, bool _filled, const T& m_background_value )
1108  : m_value_ptr(value_ptr), m_active(_active), m_filled(_filled), m_background_value(m_background_value) {}
1109  //
1110  const bool &m_active;
1111  bool m_filled;
1112  const void *m_value_ptr;
1113  const T& m_background_value;
1114  };
1115  //
1116  enum { ACTIVES = true, ALL = false };
1123  void parallel_actives( std::function<void(iterator& it)> func ) { parallel_op(func,ACTIVES); }
1130  void parallel_all( std::function<void(iterator& it)> func ) { parallel_op(func,ALL); }
1139  void parallel_op( std::function<void(iterator& it)> func, bool type=ALL ) {
1140  parallel_op([func](int i, int j, iterator& it, int thread_index){
1141  func(it);
1142  },type);
1143  }
1150  void parallel_actives( std::function<void(int i, int j, iterator& it)> func ) { parallel_op(func,ACTIVES); }
1157  void parallel_all( std::function<void(int i, int j, iterator& it)> func ) { parallel_op(func,ALL); }
1166  void parallel_op( std::function<void(int i, int j, iterator& it)> func, bool type=ALL ) {
1167  parallel_op([func](int i, int j, iterator& it, int thread_index){
1168  func(i,j,it);
1169  },type);
1170  }
1177  void parallel_actives( std::function<void(int i, int j, iterator& it, int thread_index)> func ) { parallel_op(func,ACTIVES); }
1184  void parallel_all( std::function<void(int i, int j, iterator& it, int thread_index)> func ) { parallel_op(func,ALL); }
1193  void parallel_op( std::function<void(int i, int j, iterator& it, int thread_index)> func, bool type=ALL ) {
1194  if( type == ACTIVES ) {
1195  m_core->parallel_actives([&](int i, int j, void *value_ptr, bool &active, const bool &filled, int thread_n ){
1196  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1197  func(i,j,it,thread_n);
1198  },m_parallel);
1199  } else {
1200  m_core->parallel_all([&](int i, int j, void *value_ptr, bool &active, const bool &filled, int thread_n ){
1201  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1202  func(i,j,it,thread_n);
1203  },m_parallel);
1204  }
1205  }
1212  void const_parallel_actives( std::function<void(const const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
1219  void const_parallel_all( std::function<void(const const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
1228  void const_parallel_op( std::function<void(const const_iterator& it)> func, bool type=ALL ) const {
1229  const_parallel_op([func](int i, int j, const const_iterator& it, int thread_index){
1230  func(it);
1231  },type);
1232  }
1239  void const_parallel_inside( std::function<void(const const_iterator& it)> func ) const {
1240  const_parallel_inside([func](int i, int j, const const_iterator& it, int thread_index){
1241  func(it);
1242  });
1243  }
1250  void const_parallel_actives( std::function<void(int i, int j, const const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
1257  void const_parallel_all( std::function<void(int i, int j, const const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
1266  void const_parallel_op( std::function<void(int i, int j, const const_iterator& it)> func, bool type=ALL ) const {
1267  const_parallel_op([func](int i, int j, const const_iterator& it, int thread_index){
1268  func(i,j,it);
1269  },type);
1270  }
1277  void const_parallel_inside( std::function<void(int i, int j, const const_iterator& it)> func ) const {
1278  const_parallel_inside([func](int i, int j, const const_iterator& it, int thread_index){
1279  func(i,j,it);
1280  });
1281  }
1288  void const_parallel_actives( std::function<void(int i, int j, const const_iterator& it, int thread_index)> func ) const { const_parallel_op(func,ACTIVES); }
1295  void const_parallel_all( std::function<void(int i, int j, const const_iterator& it, int thread_index)> func ) const { const_parallel_op(func,ALL); }
1304  void const_parallel_op( std::function<void(int i, int j, const const_iterator& it, int thread_index)> func, bool type=ALL ) const {
1305  if( type == ACTIVES ) {
1306  m_core->const_parallel_actives([&](int i, int j, const void *value_ptr, const bool &filled, int thread_n ){
1307  bool active(true);
1308  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1309  func(i,j,it,thread_n);
1310  },m_parallel);
1311  } else {
1312  m_core->const_parallel_all([&](int i, int j, const void *value_ptr, const bool &active, const bool &filled, int thread_n ){
1313  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1314  func(i,j,it,thread_n);
1315  },m_parallel);
1316  }
1317  }
1324  void const_parallel_inside( std::function<void(int i, int j, const const_iterator& it, int thread_index)> func ) const {
1325  m_core->const_parallel_inside([&](int i, int j, const void *value_ptr, const bool &active, int thread_n ){
1326  const_iterator it(value_ptr,active,true,m_fill_value);
1327  func(i,j,it,thread_n);
1328  },m_parallel);
1329  }
1336  void serial_actives( std::function<void(iterator& it)> func ) { serial_op(func,ACTIVES); }
1343  void serial_all( std::function<void(iterator& it)> func ) { serial_op(func,ALL); }
1352  void serial_op( std::function<void(iterator& it)> func, bool type=ALL ) {
1353  serial_op([func](int i, int j, iterator& it){
1354  func(it);
1355  },type);
1356  }
1363  void serial_actives( std::function<void(int i, int j, iterator& it)> func ) { serial_op(func,ACTIVES); }
1370  void serial_all( std::function<void(int i, int j, iterator& it)> func ) { serial_op(func,ALL); }
1379  void serial_op( std::function<void(int i, int j, iterator& it)> func, bool type=ALL ) {
1380  if( type == ACTIVES ) {
1381  m_core->serial_actives([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
1382  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1383  func(i,j,it);
1384  return false;
1385  });
1386  } else {
1387  m_core->serial_all([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
1388  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1389  func(i,j,it);
1390  return false;
1391  });
1392  }
1393  }
1400  void const_serial_actives( std::function<void(const const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
1407  void const_serial_all( std::function<void(const const_iterator& it)> func ) const { const_serial_op(func,ALL); }
1416  void const_serial_op( std::function<void(const const_iterator& it)> func, bool type=ALL ) const {
1417  const_serial_op([func](int i, int j, const const_iterator& it){
1418  func(it);
1419  },type);
1420  }
1427  void const_serial_inside( std::function<void(const const_iterator& it)> func ) const {
1428  const_serial_inside([func](int i, int j, const const_iterator& it){
1429  func(it);
1430  });
1431  }
1438  void const_serial_actives( std::function<void(int i, int j, const const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
1445  void const_serial_all( std::function<void(int i, int j, const const_iterator& it)> func ) const { const_serial_op(func,ALL); }
1454  void const_serial_op( std::function<void(int i, int j, const const_iterator& it)> func, bool type=ALL ) const {
1455  if( type == ACTIVES ) {
1456  m_core->const_serial_actives([&](int i, int j, const void *value_ptr, const bool &filled ){
1457  bool active(true);
1458  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1459  func(i,j,it);
1460  return false;
1461  });
1462  } else {
1463  m_core->const_serial_all([&](int i, int j, const void *value_ptr, const bool &active, const bool &filled ){
1464  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1465  func(i,j,it);
1466  return false;
1467  });
1468  }
1469  }
1476  void const_serial_inside( std::function<void(int i, int j, const const_iterator& it)> func ) const {
1477  m_core->const_serial_inside([&](int i, int j, const void *value_ptr, const bool &active ){
1478  const_iterator it(value_ptr,active,true,m_fill_value);
1479  func(i,j,it);
1480  return false;
1481  });
1482  }
1489  void interruptible_serial_actives( std::function<bool(iterator& it)> func ) { interruptible_serial_op(func,ACTIVES); }
1496  void interruptible_serial_all( std::function<bool(iterator& it)> func ) { interruptible_serial_op(func,ALL); }
1505  void interruptible_serial_op( std::function<bool(iterator& it)> func, bool type=ALL ) {
1506  interruptible_serial_op([func](int i, int j, iterator& it){
1507  return func(it);
1508  },type);
1509  }
1516  void interruptible_serial_actives( std::function<bool(int i, int j, iterator& it)> func ) { interruptible_serial_op(func,ACTIVES); }
1523  void interruptible_serial_all( std::function<bool(int i, int j, iterator& it)> func ) { interruptible_serial_op(func,ALL); }
1532  void interruptible_serial_op( std::function<bool(int i, int j, iterator& it)> func, bool type=ALL ) {
1533  if( type == ACTIVES ) {
1534  m_core->serial_actives([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
1535  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1536  return func(i,j,it);
1537  });
1538  } else {
1539  m_core->serial_all([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
1540  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1541  return func(i,j,it);
1542  });
1543  }
1544  }
1551  void interruptible_const_serial_actives( std::function<bool(const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ACTIVES); }
1558  void interruptible_const_serial_all( std::function<bool(const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ALL); }
1567  void interruptible_const_serial_op( std::function<bool(const const_iterator& it)> func, bool type=ALL ) const {
1568  interruptible_const_serial_op([func](int i, int j, const const_iterator& it){
1569  return func(it);
1570  },type);
1571  }
1578  void interruptible_const_serial_inside( std::function<bool(const const_iterator& it)> func ) const {
1579  const_serial_inside([func](int i, int j, const const_iterator& it){
1580  return func(it);
1581  });
1582  }
1589  void interruptible_const_serial_actives( std::function<bool(int i, int j, const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ACTIVES); }
1596  void interruptible_const_serial_all( std::function<bool(int i, int j, const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ALL); }
1605  void interruptible_const_serial_op( std::function<bool(int i, int j, const const_iterator& it)> func, bool type=ALL ) const {
1606  if( type == ACTIVES ) {
1607  m_core->const_serial_actives([&](int i, int j, const void *value_ptr, const bool &filled ){
1608  bool active(true);
1609  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1610  return func(i,j,it);
1611  });
1612  } else {
1613  m_core->const_serial_all([&](int i, int j, const void *value_ptr, const bool &active, const bool &filled ){
1614  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1615  return func(i,j,it);
1616  });
1617  }
1618  }
1625  void interruptible_const_serial_inside( std::function<bool(int i, int j, const const_iterator& it)> func ) const {
1626  m_core->const_serial_inside([&](int i, int j, const void *value_ptr, const bool &active ){
1627  const_iterator it(value_ptr,active,true,m_fill_value);
1628  return func(i,j,it);
1629  });
1630  }
1639  void dilate( std::function<void(int i, int j, iterator& it, int thread_index)> func, int count=1 ) {
1640  while( count -- ) {
1641  m_core->dilate([&](int i, int j, void *value_ptr, bool &active, const bool &filled, int thread_index) {
1642  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1643  func(i,j,it,thread_index);
1644  },m_parallel);
1645  }
1646  }
1655  void dilate( std::function<void(int i, int j, iterator& it)> func, int count=1 ) {
1656  dilate([&](int i, int j, iterator& it, int thread_index) {
1657  func(i,j,it);
1658  },count);
1659  }
1666  void dilate( int count=1 ) {
1667  dilate([&](int i, int j, iterator& it){ it.set(it()); },count);
1668  }
1677  void erode( std::function<bool(int i, int j, const const_iterator& it, int thread_index)> func, int count=1 ) {
1678  //
1679  std::vector<std::vector<vec2i> > off_positions(get_thread_num());
1680  //
1681  while( count -- ) {
1682  const_parallel_actives([&](int i, int j, const auto &it, int tn) {
1683  bool exit_loop (false);
1684  for( int dim : DIMS2 ) {
1685  for( int dir=-1; dir<=1; dir+=2 ) {
1686  const vec2i &pi = vec2i(i,j) + dir*vec2i(dim==0,dim==1);
1687  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
1688  if( func(i,j,it,tn)) {
1689  off_positions[tn].push_back(vec2i(i,j));
1690  exit_loop = true;
1691  break;
1692  }
1693  }
1694  }
1695  if( exit_loop ) break;
1696  }
1697  });
1698  for( const auto &bucket : off_positions ) for( const auto &pi : bucket ) {
1699  set_off(pi);
1700  }
1701  }
1702  }
1711  void erode( std::function<bool(int i, int j, const const_iterator& it)> func, int count=1 ) {
1712  erode([&](int i, int j, const const_iterator& it, int thread_index) {
1713  return func(i,j,it);
1714  },count);
1715  }
1722  void erode( int count=1 ) {
1723  erode([&](int i, int j, const const_iterator& it, int thread_index) { return true; },count);
1724  }
1731  void swap( array2& rhs ) {
1732  m_core.swap(rhs.m_core);
1733  std::swap(m_shape,rhs.m_shape);
1734  std::swap(m_background_value,rhs.m_background_value);
1735  std::swap(m_core_name,rhs.m_core_name);
1736  std::swap(m_touch_only_actives,rhs.m_touch_only_actives);
1737  std::swap(m_levelset,rhs.m_levelset);
1738  std::swap(m_fillable,rhs.m_fillable);
1739  std::swap(m_fill_value,rhs.m_fill_value);
1740  }
1748  return m_parallel;
1749  }
1757  return m_parallel;
1758  }
1765  void set_core_name( std::string core_name ) {
1766  m_core_name = core_name;
1767  }
1774  std::string get_core_name() const {
1775  return m_core_name;
1776  }
1783  const array_core2 * get_core() const {
1784  return m_core.get();
1785  }
1793  return m_core.get();
1794  }
1797  struct type2 {
1802  std::string core_name;
1837  bool operator==(const type2 &rhs) const {
1838  return
1839  core_name == rhs.core_name &&
1840  shape == rhs.shape &&
1841  background_value == rhs.background_value &&
1842  fill_value == rhs.fill_value &&
1843  is_fillable == rhs.is_fillable &&
1844  is_levelset == rhs.is_levelset &&
1845  touch_only_actives == rhs.touch_only_actives;
1846  }
1847  };
1854  type2 type() const { return { get_core_name(),shape(),m_background_value,m_fill_value,m_fillable,m_levelset,m_touch_only_actives}; }
1861  void set_type( const type2 &type ) {
1862  m_core_name = type.core_name;
1863  m_shape = type.shape;
1864  m_background_value = type.background_value;
1865  m_touch_only_actives = type.touch_only_actives;
1866  m_fillable = type.is_fillable;
1867  m_fill_value = type.fill_value;
1868  m_levelset = type.is_levelset;
1869  }
1870  //
1871 private:
1872  //
1873  shape2 m_shape;
1874  parallel_driver m_parallel{this};
1875  T m_background_value {T()}, m_fill_value {T()};
1876  bool m_touch_only_actives {false}, m_fillable {false}, m_levelset {false}, m_is_initialized {false};
1877  array2_ptr m_core;
1878  std::string m_core_name;
1879 };
1880 //
1882 //
1883 #endif
array2::set
void set(const vec2i &pi, const T &value)
Set value on grid.
Definition: array2.h:533
array2::interruptible_const_serial_op
void interruptible_const_serial_op(std::function< bool(int i, int j, const const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: array2.h:1605
shape.h
array2::interruptible_const_serial_actives
void interruptible_const_serial_actives(std::function< bool(int i, int j, const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array2.h:1589
shape3::w
unsigned w
Width of the shape.
Definition: shape.h:942
array2::operator-=
void operator-=(const T &v)
Subtract all the grid values with an input value.
Definition: array2.h:890
array2::erode
void erode(std::function< bool(int i, int j, const const_iterator &it)> func, int count=1)
Erode cells.
Definition: array2.h:1711
array2::type2::fill_value
T fill_value
Fill value.
Definition: array2.h:1817
array2::parallel_actives
void parallel_actives(std::function< void(int i, int j, iterator &it)> func)
Loop over all the active cells in parallel.
Definition: array2.h:1150
array2::type2::operator==
bool operator==(const type2 &rhs) const
Comparison operator.
Definition: array2.h:1837
array2::parallel_op
void parallel_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: array2.h:1139
array2::type2::shape
shape2 shape
Shape of the grid.
Definition: array2.h:1807
array2::interruptible_const_serial_op
void interruptible_const_serial_op(std::function< bool(const const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: array2.h:1567
array2::interruptible_serial_all
void interruptible_serial_all(std::function< bool(int i, int j, iterator &it)> func)
Loop over all the cells in serial order.
Definition: array2.h:1523
array2::get_core
const array_core2 * get_core() const
Get pointer to the core module.
Definition: array2.h:1783
array2::serial_all
void serial_all(std::function< void(int i, int j, iterator &it)> func)
Loop over all the cells in serial order.
Definition: array2.h:1370
array2::activate_all
void activate_all()
Activate all the cells.
Definition: array2.h:440
array2::parallel_all
void parallel_all(std::function< void(int i, int j, iterator &it, int thread_index)> func)
Loop over all the cells in parallel.
Definition: array2.h:1184
array2::const_serial_inside
void const_serial_inside(std::function< void(int i, int j, const const_iterator &it)> func) const
Loop over filled the cells in serial order by read-only fashion.
Definition: array2.h:1476
messageable::send_message
virtual bool send_message(std::string message, void *ptr=nullptr)
Send a message.
Definition: messageable.h:48
array2::active
bool active(const vec2i &pi) const
Get if a position on grid is active.
Definition: array2.h:558
array2::operator/=
void operator/=(const T &v)
Divide all the grid values with an input value.
Definition: array2.h:912
array2::const_serial_inside
void const_serial_inside(std::function< void(const const_iterator &it)> func) const
Loop over filled the cells in serial order by read-only fashion.
Definition: array2.h:1427
array2::type2::touch_only_actives
bool touch_only_actives
Are grid operations only allowed on active cells.
Definition: array2.h:1832
array2::iterator::increment
void increment(const T &value)
Increment value.
Definition: array2.h:965
array2::flood_fill
void flood_fill()
Perform flood fill. Grid should be set either level set of fillable beforehand.
Definition: array2.h:299
array2::multiply
void multiply(const vec2i &pi, const T &value)
Multiply value on grid.
Definition: array2.h:698
array2::interruptible_serial_actives
void interruptible_serial_actives(std::function< bool(int i, int j, iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array2.h:1516
array2::set_touch_only_actives
void set_touch_only_actives(bool touch_only_actives)
Set whether to force grid manipulation only on active cells. If true, operatios such operator+=() onl...
Definition: array2.h:160
array2::type2::is_levelset
bool is_levelset
Is grid level set.
Definition: array2.h:1827
parallel_driver
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
array2::set_as_fillable_as
void set_as_fillable_as(const array2 &array)
Set the grid as fillable as same as an input array.
Definition: array2.h:265
array2::const_serial_actives
void const_serial_actives(std::function< void(int i, int j, const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array2.h:1438
array2::const_parallel_all
void const_parallel_all(std::function< void(int i, int j, const const_iterator &it, int thread_index)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: array2.h:1295
array2::set_background_value
void set_background_value(const T &value)
Set the background value (alternatively, initial value) of the grid.
Definition: array2.h:482
array2::array2
array2(recursive_configurable *parent, const shape2 &shape, T value=T(), std::string core_name="")
Constructor for array2.
Definition: array2.h:56
array2::const_serial_all
void const_serial_all(std::function< void(const const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: array2.h:1407
array2::const_parallel_inside
void const_parallel_inside(std::function< void(const const_iterator &it)> func) const
Loop over all the filled cells in parallel by read-only fashion.
Definition: array2.h:1239
array2::interruptible_serial_all
void interruptible_serial_all(std::function< bool(iterator &it)> func)
Loop over all the cells in serial order.
Definition: array2.h:1496
array2::interruptible_const_serial_all
void interruptible_const_serial_all(std::function< bool(int i, int j, const const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: array2.h:1596
array2::array2
array2(recursive_configurable *parent, std::string core_name="")
Constructor for array2.
Definition: array2.h:69
array2::iterator::set_off
void set_off()
Inactivate a cell.
Definition: array2.h:955
array2::subtract
void subtract(const vec2i &pi, const T &value)
Subtract value on grid.
Definition: array2.h:668
recursive_configurable::setup_now
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
array2::set_off
void set_off(int i, int j)
Set a position on grid inactive.
Definition: array2.h:596
array2::set
void set(int i, int j, const T &value)
Set value on grid.
Definition: array2.h:518
array2::count
size_t count() const
Function to count the number of active cells.
Definition: array2.h:358
array2::const_serial_op
void const_serial_op(std::function< void(int i, int j, const const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: array2.h:1454
array2::iterator::divide
void divide(const T &value)
Divide by value.
Definition: array2.h:1007
array2::clear
void clear()
Clear out the grid.
Definition: array2.h:491
array_core2.h
array2::const_iterator::ptr
const T * ptr() const
Get const pointer to the value.
Definition: array2.h:1105
array2::operator!=
bool operator!=(const array2< T > &array) const
Return if the grid is different from an input array.
Definition: array2.h:797
array2::dilate
void dilate(std::function< void(int i, int j, iterator &it)> func, int count=1)
Dilate cells.
Definition: array2.h:1655
array2::iterator::active
bool active() const
Get if a cell is active.
Definition: array2.h:1014
array2::get_core
array_core2 * get_core()
Get pointer to the core module.
Definition: array2.h:1792
array2::array2
array2(std::string core_name="")
Constructor for array2.
Definition: array2.h:76
array2::parallel_actives
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: array2.h:1123
array2::type2
Collection of properties of this grid.
Definition: array2.h:1797
array2::parallel_op
void parallel_op(std::function< void(int i, int j, iterator &it, int thread_index)> func, bool type=ALL)
Loop over cells in parallel.
Definition: array2.h:1193
shape3::count
size_t count() const
Count the number of cells of the grid of this shape.
Definition: shape.h:857
array2::serial_actives
void serial_actives(std::function< void(int i, int j, iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array2.h:1363
array2::is_levelset
bool is_levelset() const
Return if the grid is set level set.
Definition: array2.h:292
shape3
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
array2::iterator::set
void set(const T &value)
Set a value.
Definition: array2.h:946
array2::get_background_value
T get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: array2.h:475
array2::array2
array2(const array2 &array)
Copy constructor for array2.
Definition: array2.h:147
array2::ptr
T * ptr(const vec2i &pi)
Get the pointer to the value at a position on grid.
Definition: array2.h:754
array2::iterator::multiply
void multiply(const T &value)
Multiply value.
Definition: array2.h:993
array2::serial_op
void serial_op(std::function< void(int i, int j, iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array2.h:1379
array2::serial_all
void serial_all(std::function< void(iterator &it)> func)
Loop over all the cells in serial order.
Definition: array2.h:1343
array2::serial_op
void serial_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array2.h:1352
array2::set_as_fillable
void set_as_fillable(const T &fill_value)
Set the grid as a grid that is fillable by flood fill.
Definition: array2.h:254
array2::const_parallel_actives
void const_parallel_actives(std::function< void(int i, int j, const const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: array2.h:1250
array2::set_as_levelset
void set_as_levelset(double bandwidth_half)
Set the grid as level set.
Definition: array2.h:242
array2::set_core_name
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: array2.h:1765
array2::const_parallel_op
void const_parallel_op(std::function< void(int i, int j, const const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: array2.h:1266
array2::const_serial_all
void const_serial_all(std::function< void(int i, int j, const const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: array2.h:1445
array2::increment
void increment(int i, int j, const T &value)
Increment value on grid.
Definition: array2.h:621
array2::iterator::subtract
void subtract(const T &value)
Subtract value.
Definition: array2.h:979
array2::erode
void erode(int count=1)
Erode cells.
Definition: array2.h:1722
shape2::out_of_bounds
bool out_of_bounds(int i, int j) const
Get if the position is outside of the index space of this shape.
Definition: shape.h:341
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
array2::const_iterator::filled
bool filled() const
Get if a cell is filled.
Definition: array2.h:1083
array2::interruptible_serial_op
void interruptible_serial_op(std::function< bool(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array2.h:1505
shape2::h
unsigned h
Height of the shape.
Definition: shape.h:466
array2::multiply
void multiply(int i, int j, const T &value)
Multiply value on grid.
Definition: array2.h:681
array2::set_thread_num
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: array2.h:923
messageable::const_send_message
virtual bool const_send_message(std::string message, void *ptr=nullptr) const
Send a message.
Definition: messageable.h:59
array2::const_iterator::operator()
const T & operator()() const
Get the value.
Definition: array2.h:1092
array2::set_as_levelset_as
void set_as_levelset_as(const array2 &array)
Set the grid as level set as same as an input array.
Definition: array2.h:274
array2::type2::background_value
T background_value
Background value.
Definition: array2.h:1812
array2::get_core_name
std::string get_core_name() const
Get the core name of module of this grid.
Definition: array2.h:1774
array2::active
bool active(int i, int j) const
Get if a position on grid is active.
Definition: array2.h:546
array2::activate_as
void activate_as(const array2< Y > &array, const vec2i &offset=vec2i())
Activate cells at the same positons where an input array is active with an offset.
Definition: array2.h:396
array2::ptr
const T * ptr(int i, int j) const
Get the const pointer to the value at a position on grid.
Definition: array2.h:745
array2::get_parallel_driver
const parallel_driver & get_parallel_driver() const
Get the const instance of parallel_driver of this grid.
Definition: array2.h:1756
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array2::parallel_all
void parallel_all(std::function< void(iterator &it)> func)
Loop over all the cells in parallel.
Definition: array2.h:1130
array2::iterator::ptr
const T * ptr() const
Get const pointer to the value.
Definition: array2.h:1050
shape2::w
unsigned w
Width of the shape.
Definition: shape.h:461
array2::set_type
void set_type(const type2 &type)
Set the type of this grid.
Definition: array2.h:1861
array2::activate
void activate(const std::vector< vec2i > &active_entries, const vec2i &offset=vec2i())
Activate cells at the positons of active_entries with an offset.
Definition: array2.h:380
array2::divide
void divide(int i, int j, const T &value)
Divide by value on grid.
Definition: array2.h:711
array2::operator*=
void operator*=(const T &v)
Multiply all the grid values with an input value.
Definition: array2.h:901
array2::fills
std::vector< vec2i > fills() const
Function to return the list of filled cells.
Definition: array2.h:319
array2::initialize
void initialize(const shape2 &shape, T value=T())
Allocate grid memory with value.
Definition: array2.h:227
array2::interruptible_serial_actives
void interruptible_serial_actives(std::function< bool(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array2.h:1489
array2::copy_active_as
void copy_active_as(const array2< Y > &array, const vec2i &offset=vec2i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: array2.h:460
array_core2::get
virtual void get(unsigned &nx, unsigned &ny, unsigned &element_size) const =0
Get grid information.
array2::send_message
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: array2.h:125
array2::operator-=
void operator-=(const array2< T > &v)
Subtract all the values with the values of an input array.
Definition: array2.h:865
array_core2
Core module class for two dimensional array designed to be used in array2 class.
Definition: array_core2.h:38
array2::swap
void swap(array2 &rhs)
Swap array.
Definition: array2.h:1731
array2::operator+=
void operator+=(const array2< T > &v)
Increment all the values with the values of an input array.
Definition: array2.h:851
array2::activate_inside
void activate_inside()
Activate all the filled cells.
Definition: array2.h:449
array2::iterator::filled
bool filled() const
Get if a cell is filled.
Definition: array2.h:1021
array2::const_parallel_inside
void const_parallel_inside(std::function< void(int i, int j, const const_iterator &it, int thread_index)> func) const
Loop over all the filled cells in parallel.
Definition: array2.h:1324
array2::set_off
void set_off(const vec2i &pi)
Set a position on grid inactive.
Definition: array2.h:608
array2::get_parallel_driver
parallel_driver & get_parallel_driver()
Get the instance of parallel_driver of this grid.
Definition: array2.h:1747
array2::is_fillable
bool is_fillable() const
Return if the grid is set fillable.
Definition: array2.h:283
array2::operator()
const T & operator()(const vec2i &pi) const
Get the the value at a position on grid.
Definition: array2.h:786
array2::parallel_actives
void parallel_actives(std::function< void(int i, int j, iterator &it, int thread_index)> func)
Loop over all the active cells in parallel.
Definition: array2.h:1177
array2::linearize
std::vector< T > linearize() const
Flatten this grid to a fully linearized one dimendional array, of which can be accessed like array[i+...
Definition: array2.h:198
array2::serial_actives
void serial_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array2.h:1336
array2::interruptible_const_serial_inside
void interruptible_const_serial_inside(std::function< bool(int i, int j, const const_iterator &it)> func) const
Loop over all the filled cells in serial order by read-only fashion.
Definition: array2.h:1625
array2::activate_as_bit
void activate_as_bit(const Y &array, const vec2i &offset=vec2i())
Activate cells at the same positons where an input array is active with an offset.
Definition: array2.h:412
array2::clear
void clear(const T &v)
Clear out the grid with the new backgroud value.
Definition: array2.h:504
array2::increment
void increment(const vec2i &pi, const T &value)
Increment value on grid.
Definition: array2.h:638
array2::dilate
void dilate(std::function< void(int i, int j, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: array2.h:1639
array2::operator+=
void operator+=(const T &v)
Increment all the grid values with an input value.
Definition: array2.h:879
recursive_configurable
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
parallel_driver.h
array2::activate_inside_as
void activate_inside_as(const array2< Y > &array, const vec2i &offset=vec2i())
Activate cells at the same positons where an input array is filled with an offset.
Definition: array2.h:428
array2::type2::is_fillable
bool is_fillable
Is grid fillable.
Definition: array2.h:1822
array2::operator==
bool operator==(const array2< T > &v) const
Return if the grid is same to an input array.
Definition: array2.h:808
array2::ptr
const T * ptr(const vec2i &pi) const
Get the const pointer to the value at a position on grid.
Definition: array2.h:763
array2::interruptible_const_serial_all
void interruptible_const_serial_all(std::function< bool(const const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: array2.h:1558
vec
Fixed sized vector structure.
Definition: vec.h:38
array2::parallel_all
void parallel_all(std::function< void(int i, int j, iterator &it)> func)
Loop over all the cells in parallel.
Definition: array2.h:1157
array2::filled
bool filled(const vec2i &pi) const
Function to get if a cell is filled.
Definition: array2.h:349
vec.h
array2::safe_active
bool safe_active(const vec2i &pi) const
Get if a position on grid is active. pi can be safely out of the domain.
Definition: array2.h:585
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
array2::const_serial_actives
void const_serial_actives(std::function< void(const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array2.h:1400
array2::const_parallel_inside
void const_parallel_inside(std::function< void(int i, int j, const const_iterator &it)> func) const
Loop over all the filled cells in parallel by read-only fashion.
Definition: array2.h:1277
array2::iterator
Writable iterator.
Definition: array2.h:937
array2::const_parallel_op
void const_parallel_op(std::function< void(int i, int j, const const_iterator &it, int thread_index)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: array2.h:1304
configuration
Class that controls the settings of the program.
Definition: configuration.h:39
array2::const_serial_op
void const_serial_op(std::function< void(const const_iterator &it)> func, bool type=ALL) const
Loop over the cells in serial order by read-only fashion.
Definition: array2.h:1416
shape2
Structure that defines shape such as width, height.
Definition: shape.h:42
array2::operator()
const T & operator()(int i, int j) const
Get the the value at a position on grid.
Definition: array2.h:774
array2::erode
void erode(std::function< bool(int i, int j, const const_iterator &it, int thread_index)> func, int count=1)
Erode cells.
Definition: array2.h:1677
messageable
Message class.
Definition: messageable.h:36
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array2::const_parallel_actives
void const_parallel_actives(std::function< void(const const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: array2.h:1212
array2::get_thread_num
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: array2.h:932
array2::const_send_message
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: array2.h:138
array2::const_parallel_actives
void const_parallel_actives(std::function< void(int i, int j, const const_iterator &it, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: array2.h:1288
array2::const_parallel_op
void const_parallel_op(std::function< void(const const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: array2.h:1228
array2::type2::core_name
std::string core_name
Core name of the module.
Definition: array2.h:1802
array2::const_parallel_all
void const_parallel_all(std::function< void(const const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: array2.h:1219
array2::safe_active
bool safe_active(int i, int j) const
Get if a position on grid is active. (i,j) can be safely out of the domain.
Definition: array2.h:571
array2::actives
std::vector< vec2i > actives() const
Function to return the list of active cells positions.
Definition: array2.h:365
array2::interruptible_const_serial_inside
void interruptible_const_serial_inside(std::function< bool(const const_iterator &it)> func) const
Loop over all the filled cells in serial order by read-only fashion.
Definition: array2.h:1578
array2::const_parallel_all
void const_parallel_all(std::function< void(int i, int j, const const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: array2.h:1257
array2::operator=
array2 & operator=(const array2 &array)
Deep copy operation for array2.
Definition: array2.h:169
array2::ptr
T * ptr(int i, int j)
Get the pointer to the value at a position on grid.
Definition: array2.h:733
array2::operator=
void operator=(const T &v)
Set all the grid values with an input value.
Definition: array2.h:840
array2::interruptible_serial_op
void interruptible_serial_op(std::function< bool(int i, int j, iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array2.h:1532
array2::iterator::ptr
T * ptr()
Get pointer to the value.
Definition: array2.h:1043
recursive_configurable::add_child
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
array2::parallel_op
void parallel_op(std::function< void(int i, int j, iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: array2.h:1166
array2::filled
bool filled(int i, int j) const
Function to get if a cell is filled.
Definition: array2.h:336
array2::iterator::operator()
const T & operator()() const
Get the value.
Definition: array2.h:1030
array2::const_iterator
Read-only iterator.
Definition: array2.h:1069
array2::dilate
void dilate(int count=1)
Dilate cells.
Definition: array2.h:1666
array2::const_iterator::active
bool active() const
Get if a cell is active.
Definition: array2.h:1076
array2::copy
void copy(const array2 &array)
Deep copy function for array2.
Definition: array2.h:181
array2::array2
array2(const shape2 &shape, T value=T(), std::string core_name="")
Constructor for array2.
Definition: array2.h:87
array2::type
type2 type() const
Get the type of this grid.
Definition: array2.h:1854
array2::subtract
void subtract(int i, int j, const T &value)
Subtract value on grid.
Definition: array2.h:651
array2::divide
void divide(const vec2i &pi, const T &value)
Divide by value on grid.
Definition: array2.h:722