Shiokaze Framework
A research-oriented fluid solver for computer graphics
array3.h
Go to the documentation of this file.
1 /*
2 ** array3.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_ARRAY3_H
26 #define SHKZ_ARRAY3_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_core3.h"
36 //
38 //
40 template<class T> class array3 : public recursive_configurable, public messageable {
43 public:
56  array3( recursive_configurable *parent, const shape3 &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  array3( recursive_configurable *parent, std::string core_name="" ) : array3(parent,shape3(0,0,0),T(),core_name) {}
76  array3( std::string core_name="" ) : array3(nullptr,shape3(0,0,0),T(),core_name) {}
87  array3( const shape3 &shape, T value=T(), std::string core_name="" ) : array3(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_core3;
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_core3);
99  }
100  }
101  m_core = array_core3::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  array3( const array3 &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  array3& operator=(const array3 &array) {
170  if( this != &array ) {
171  copy(array);
172  }
173  return *this;
174  }
181  void copy( const array3 &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, int k, auto &it ) {
202  result[i + s.w * (j + s.h * k)] = it();
203  });
204  const_parallel_inside([&]( int i, int j, int k, auto &it ) {
205  if( ! it.active()) result[i + s.w * (j + s.h * k)] = it();
206  });
207  return result;
208  }
209  virtual ~array3() {
210  clear();
211  }
218  shape3 shape() const { return m_shape; }
227  void initialize( const shape3 &shape, T value=T()) {
228  clear();
229  m_core->initialize(shape.w,shape.h,shape.d,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 array3 &array ) {
266  set_as_fillable(array.m_fill_value);
267  }
274  void set_as_levelset_as( const array3 &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<vec3i> fills() const {
320  std::vector<vec3i> result;
321  const_serial_inside([&](int i, int j, int k, const auto &it) {
322  result.push_back(vec3i(i,j,k));
323  });
324  return result;
325  }
338  bool filled( int i, int j, int k ) const {
339  bool filled;
340  (*m_core)(i,j,k,filled);
341  return filled;
342  }
351  bool filled( const vec3i &pi ) const {
352  return filled(pi[0],pi[1],pi[2]);
353  }
360  size_t count () const { return m_core->count(m_parallel); }
367  std::vector<vec3i> actives() const {
368  std::vector<vec3i> result;
369  const_serial_actives([&](int i, int j, int k, const auto &it) {
370  result.push_back(vec3i(i,j,k));
371  });
372  return result;
373  }
382  void activate( const std::vector<vec3i> &active_entries, const vec3i &offset=vec3i() ) {
383  for( const auto &e : active_entries ) {
384  const vec3i &pi = e + offset;
385  if( ! shape().out_of_bounds(pi) && ! active(pi)) {
386  set(pi,(*this)(pi));
387  }
388  }
389  }
398  template <class Y> void activate_as( const array3<Y> &array, const vec3i &offset=vec3i() ) {
399  array.const_serial_actives([&](int i, int j, int k, const auto &it) {
400  const vec3i &pi = vec3i(i,j,k) + offset;
401  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
402  this->set(pi,(*this)(pi));
403  }
404  });
405  }
414  template <class Y> void activate_as_bit( const Y &array, const vec3i &offset=vec3i() ) {
415  array.const_serial_actives([&](int i, int j, int k) {
416  const vec3i &pi = vec3i(i,j,k) + offset;
417  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
418  this->set(pi,(*this)(pi));
419  }
420  });
421  }
430  template <class Y> void activate_inside_as( const array3<Y> &array, const vec3i &offset=vec3i() ) {
431  array.const_serial_inside([&](int i, int j, int k, const auto &it) {
432  const vec3i &pi = vec3i(i,j,k) + offset;
433  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
434  this->set(pi,(*this)(pi));
435  }
436  });
437  }
442  void activate_all() {
443  parallel_all([&](auto &it) {
444  it.set(it());
445  });
446  }
452  activate(fills());
453  }
462  template <class Y> void copy_active_as( const array3<Y> &array, const vec3i &offset=vec3i() ) {
463  parallel_actives([&](int i, int j, int k, auto &it, int tn) {
464  const vec3i &pi = vec3i(i,j,k) + offset;
465  if( ! this->shape().out_of_bounds(pi) ) {
466  if( this->active(pi) && ! array.active(pi)) {
467  it.set_off();
468  }
469  }
470  });
471  activate_as(array,offset);
472  }
477  T get_background_value () const { return m_background_value; }
484  void set_background_value( const T& value ) { m_background_value = value; }
493  void clear() {
494  parallel_actives([&](iterator& it) {
495  it.set_off();
496  });
497  }
506  void clear(const T &v) {
507  m_background_value = v;
508  clear();
509  }
522  void set( int i, int j, int k, const T& value ) {
523  m_core->set(i,j,k,[&](void *value_ptr, bool &active){
524  if( ! active ) new (value_ptr) T(value);
525  else *static_cast<T *>(value_ptr) = value;
526  active = true;
527  });
528  }
537  void set( const vec3i &pi, const T& value) {
538  set(pi[0],pi[1],pi[2],value);
539  }
552  bool active( int i, int j, int k ) const {
553  bool filled (false);
554  return (*m_core)(i,j,k,filled) != nullptr;
555  }
564  bool active( const vec3i &pi ) const {
565  return active(pi[0],pi[1],pi[2]);
566  }
577  bool safe_active( int i, int j, int k ) const {
578  if( ! m_shape.out_of_bounds(i,j,k)) {
579  return active(i,j,k);
580  }
581  return false;
582  }
591  bool safe_active( const vec3i &pi ) const {
592  return safe_active(pi[0],pi[1],pi[2]);
593  }
604  void set_off( int i, int j, int k ) {
605  m_core->set(i,j,k,[&](void *value_ptr, bool &active){
606  if( active ) (static_cast<T *>(value_ptr))->~T();
607  active = false;
608  });
609  }
616  void set_off( const vec3i &pi ) {
617  set_off(pi[0],pi[1],pi[2]);
618  }
631  void increment( int i, int j, int k, const T& value) {
632  m_core->set(i,j,k,[&](void *value_ptr, bool &active){
633  if( active ) *static_cast<T *>(value_ptr) += value;
634  else {
635  *static_cast<T *>(value_ptr) = m_background_value + value;
636  active = true;
637  }
638  });
639  }
648  void increment( const vec3i &pi, const T& value ) {
649  increment(pi[0],pi[1],pi[2],value);
650  }
663  void subtract( int i, int j, int k, const T& value) {
664  m_core->set(i,j,k,[&](void *value_ptr, bool &active){
665  if( active ) *static_cast<T *>(value_ptr) -= value;
666  else {
667  *static_cast<T *>(value_ptr) = m_background_value - value;
668  active = true;
669  }
670  });
671  }
680  void subtract( const vec3i &pi, const T& value ) {
681  subtract(pi[0],pi[1],pi[2],value);
682  }
695  void multiply( int i, int j, int k, const T& value ) {
696  m_core->set(i,j,k,[&](void *value_ptr, bool &active){
697  if( active ) *static_cast<T *>(value_ptr) *= value;
698  else {
699  *static_cast<T *>(value_ptr) = m_background_value * value;
700  active = true;
701  }
702  });
703  }
712  void multiply( const vec3i &pi, const T& value ) {
713  multiply(pi[0],pi[1],pi[2],value);
714  }
727  void devide( int i, int j, int k, const T& value ) {
728  multiply(i,j,k,1.0/value);
729  }
738  void devide( const vec3i &pi, const T& value) {
739  devide(pi[0],pi[1],pi[2],value);
740  }
751  T* ptr(unsigned i, unsigned j, unsigned k ) {
752  bool filled (false);
753  return const_cast<T *>(static_cast<const T *>((*m_core)(i,j,k,filled)));
754  }
765  const T* ptr(unsigned i, unsigned j, unsigned k ) const {
766  return const_cast<array3<T> *>(this)->ptr(i,j,k);
767  }
774  T* ptr( const vec3i &pi ) {
775  return ptr(pi[0],pi[1],pi[2]);
776  }
783  const T* ptr( const vec3i &pi ) const {
784  return const_cast<array3<T> *>(this)->ptr(pi);
785  }
796  const T& operator()(int i, int j, int k ) const {
797  bool filled (false);
798  const T* ptr = static_cast<const T *>((*m_core)(i,j,k,filled));
799  if( ptr ) return *ptr;
800  else return filled ? m_fill_value : m_background_value;
801  }
808  const T& operator()(const vec3i &pi ) const {
809  return (*const_cast<array3<T> *>(this))(pi[0],pi[1],pi[2]);
810  }
819  bool operator!=( const array3<T> &array ) const {
820  return ! (*this == array);
821  }
830  bool operator==(const array3<T> &v) const {
831  if( v.type() == type() ) {
832  bool differnt (false);
833  interruptible_const_serial_actives([&]( int i, int j, int k, const const_iterator& it) {
834  if( it() != v(i,j,k)) {
835  differnt = true;
836  return true;
837  } else {
838  return false;
839  }
840  });
841  if( ! differnt ) {
842  interruptible_const_serial_inside([&]( int i, int j, int k, const const_iterator& it) {
843  if( ! it.active()) {
844  if( it() != v(i,j,k)) {
845  differnt = true;
846  return true;
847  }
848  }
849  return false;
850  });
851  }
852  return ! differnt;
853  }
854  return false;
855  }
862  void operator=(const T &v) {
863  parallel_op([&](iterator& it) {
864  it.set(v);
865  },m_touch_only_actives);
866  }
873  void operator+=(const array3<T> &v) {
874  assert(shape()==v.shape());
875  parallel_op([&](int i ,int j, int k, iterator& it, int tn) {
876  if( ! m_touch_only_actives || v.active(i,j,k)) {
877  it.increment(v(i,j,k));
878  }
879  },m_touch_only_actives);
880  }
887  void operator-=(const array3<T> &v) {
888  assert(shape()==v.shape());
889  parallel_op([&](int i, int j, int k, iterator& it, int tn) {
890  if( ! m_touch_only_actives || v.active(i,j,k)) {
891  it.subtract(v(i,j,k));
892  }
893  },m_touch_only_actives);
894  }
901  void operator+=(const T &v) {
902  parallel_op([&](iterator& it) {
903  it.increment(v);
904  },m_touch_only_actives);
905  }
912  void operator-=(const T &v) {
913  parallel_op([&](iterator& it) {
914  it.subtract(v);
915  },m_touch_only_actives);
916  }
923  void operator*=(const T &v) {
924  parallel_op([&](iterator& it) {
925  it.multiply(v);
926  },m_touch_only_actives);
927  }
934  void operator/=(const T &v) {
935  parallel_op([&](iterator& it) {
936  it.divide(v);
937  },m_touch_only_actives);
938  }
945  void set_thread_num( int number ) {
946  m_parallel.set_thread_num(number);
947  }
954  int get_thread_num() const {
955  return m_parallel.get_thread_num();
956  }
959  class iterator {
960  friend class array3<T>;
961  public:
968  void set( const T &value ) {
969  if( ! m_active ) allocate(value);
970  else *static_cast<T *>(m_value_ptr) = value;
971  m_active = true;
972  }
977  void set_off() {
978  if( m_active && m_value_ptr ) deallocate();
979  m_active = false;
980  }
987  void increment( const T& value ) {
988  if( m_active ) {
989  *static_cast<T *>(m_value_ptr) += value;
990  } else {
991  allocate(m_background_value + value);
992  m_active = true;
993  }
994  }
1001  void subtract( const T& value ) {
1002  if( m_active ) {
1003  *static_cast<T *>(m_value_ptr) -= value;
1004  } else {
1005  allocate(m_background_value - value);
1006  m_active = true;
1007  }
1008  }
1015  void multiply( const T& value ) {
1016  if( m_active ) {
1017  *static_cast<T *>(m_value_ptr) *= value;
1018  } else {
1019  allocate(m_background_value * value);
1020  m_active = true;
1021  }
1022  }
1029  void divide( const T& value ) {
1030  multiply(1.0/value);
1031  }
1036  bool active() const {
1037  return m_active;
1038  }
1043  bool filled() const {
1044  return m_filled;
1045  }
1052  const T& operator()() const {
1053  if( m_active ) {
1054  return *static_cast<const T *>(m_value_ptr);
1055  } else {
1056  return m_background_value;
1057  }
1058  }
1065  T* ptr() { return m_active ? static_cast<T *>(m_value_ptr) : nullptr; }
1072  const T* ptr() const { return m_active ? static_cast<const T *>(m_value_ptr) : nullptr; }
1073  private:
1074  iterator( void *value_ptr, bool &_active, bool _filled, const T& m_background_value )
1075  : m_value_ptr(value_ptr), m_active(_active), m_filled(_filled), m_background_value(m_background_value) {}
1076  //
1077  void allocate ( const T& value ) {
1078  new (m_value_ptr) T(value);
1079  }
1080  void deallocate() {
1081  (static_cast<T *>(m_value_ptr))->~T();
1082  }
1083  bool &m_active;
1084  bool m_filled;
1085  void *m_value_ptr;
1086  const T& m_background_value;
1087  };
1091  friend class array3<T>;
1092  public:
1097  bool active() const {
1098  return m_active;
1099  }
1104  bool filled() const {
1105  return m_filled;
1106  }
1113  const T& operator()() const {
1114  if( m_active ) {
1115  return *static_cast<const T *>(m_value_ptr);
1116  } else {
1117  return m_background_value;
1118  }
1119  }
1126  const T* ptr() const { return m_active ? static_cast<const T *>(m_value_ptr) : nullptr; }
1127  private:
1128  const_iterator( const void *value_ptr, const bool &_active, bool _filled, const T& m_background_value )
1129  : m_value_ptr(value_ptr), m_active(_active), m_filled(_filled), m_background_value(m_background_value) {}
1130  const bool &m_active;
1131  bool m_filled;
1132  const void *m_value_ptr;
1133  const T& m_background_value;
1134  };
1135  //
1136  enum { ACTIVES = true, ALL = false };
1143  void parallel_actives( std::function<void(iterator& it)> func ) { parallel_op(func,ACTIVES); }
1150  void parallel_all( std::function<void(iterator& it)> func ) { parallel_op(func,ALL); }
1159  void parallel_op( std::function<void(iterator& it)> func, bool type=ALL ) {
1160  parallel_op([func](int i, int j, int k, iterator& it, int thread_index){
1161  func(it);
1162  },type);
1163  }
1170  void parallel_actives( std::function<void(int i, int j, int k, iterator& it)> func ) { parallel_op(func,ACTIVES); }
1177  void parallel_all( std::function<void(int i, int j, int k, iterator& it)> func ) { parallel_op(func,ALL); }
1186  void parallel_op( std::function<void(int i, int j, int k, iterator& it)> func, bool type=ALL ) {
1187  parallel_op([func](int i, int j, int k, iterator& it, int thread_index){
1188  func(i,j,k,it);
1189  },type);
1190  }
1197  void parallel_actives( std::function<void(int i, int j, int k, iterator& it, int thread_index)> func ) { parallel_op(func,ACTIVES); }
1204  void parallel_all( std::function<void(int i, int j, int k, iterator& it, int thread_index)> func ) { parallel_op(func,ALL); }
1213  void parallel_op( std::function<void(int i, int j, int k, iterator& it, int thread_index)> func, bool type=ALL ) {
1214  if( type == ACTIVES ) {
1215  m_core->parallel_actives([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled, int thread_n ){
1216  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1217  func(i,j,k,it,thread_n);
1218  },m_parallel);
1219  } else {
1220  m_core->parallel_all([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled, int thread_n ){
1221  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1222  func(i,j,k,it,thread_n);
1223  },m_parallel);
1224  }
1225  }
1232  void const_parallel_actives( std::function<void(const const_iterator& it)> func) const { const_parallel_op(func,ACTIVES); }
1239  void const_parallel_all( std::function<void(const const_iterator& it)> func) const { const_parallel_op(func,ALL); }
1248  void const_parallel_op( std::function<void(const const_iterator& it)> func, bool type=ALL ) const {
1249  const_parallel_op([func](int i, int j, int k, const const_iterator& it, int thread_index){
1250  func(it);
1251  },type);
1252  }
1259  void const_parallel_inside( std::function<void(const const_iterator& it)> func) const {
1260  const_parallel_inside([func](int i, int j, int k, const const_iterator& it, int thread_index){
1261  func(it);
1262  });
1263  }
1270  void const_parallel_actives( std::function<void(int i, int j, int k, const const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
1277  void const_parallel_all( std::function<void(int i, int j, int k, const const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
1286  void const_parallel_op( std::function<void(int i, int j, int k, const const_iterator& it)> func, bool type=ALL ) const {
1287  const_parallel_op([func](int i, int j, int k, const const_iterator& it, int thread_index){
1288  func(i,j,k,it);
1289  },type);
1290  }
1297  void const_parallel_inside( std::function<void(int i, int j, int k, const const_iterator& it)> func) const {
1298  const_parallel_inside([func](int i, int j, int k, const const_iterator& it, int thread_index){
1299  func(i,j,k,it);
1300  });
1301  }
1308  void const_parallel_actives( std::function<void(int i, int j, int k, const const_iterator& it, int thread_index)> func ) const { const_parallel_op(func,ACTIVES); }
1315  void const_parallel_all( std::function<void(int i, int j, int k, const const_iterator& it, int thread_index)> func ) const { const_parallel_op(func,ALL); }
1324  void const_parallel_op( std::function<void(int i, int j, int k, const const_iterator& it, int thread_index)> func, bool type=ALL ) const {
1325  if( type == ACTIVES ) {
1326  m_core->const_parallel_actives([&](int i, int j, int k, const void *value_ptr, const bool &filled, int thread_n ){
1327  bool active(true);
1328  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1329  func(i,j,k,it,thread_n);
1330  },m_parallel);
1331  } else {
1332  m_core->const_parallel_all([&](int i, int j, int k, const void *value_ptr, const bool &active, const bool &filled, int thread_n ){
1333  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1334  func(i,j,k,it,thread_n);
1335  },m_parallel);
1336  }
1337  }
1344  void const_parallel_inside( std::function<void(int i, int j, int k, const const_iterator& it, int thread_index)> func ) const {
1345  m_core->const_parallel_inside([&](int i, int j, int k, const void *value_ptr, const bool &active, int thread_n ){
1346  const_iterator it(value_ptr,active,true,m_fill_value);
1347  func(i,j,k,it,thread_n);
1348  },m_parallel);
1349  }
1356  void serial_actives( std::function<void(iterator& it)> func) { serial_op(func,ACTIVES); }
1363  void serial_all( std::function<void(iterator& it)> func) { serial_op(func,ALL); }
1372  void serial_op( std::function<void(iterator& it)> func, bool type=ALL ) {
1373  serial_op([func](int i, int j, int k, iterator& it){
1374  func(it);
1375  },type);
1376  }
1383  void serial_actives( std::function<void(int i, int j, int k, iterator& it)> func ) { serial_op(func,ACTIVES); }
1390  void serial_all( std::function<void(int i, int j, int k, iterator& it)> func ) { serial_op(func,ALL); }
1399  void serial_op( std::function<void(int i, int j, int k, iterator& it)> func, bool type=ALL ) {
1400  if( type == ACTIVES ) {
1401  m_core->serial_actives([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled ){
1402  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1403  func(i,j,k,it);
1404  return false;
1405  });
1406  } else {
1407  m_core->serial_all([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled ){
1408  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1409  func(i,j,k,it);
1410  return false;
1411  });
1412  }
1413  }
1420  void const_serial_actives( std::function<void(const const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
1427  void const_serial_all( std::function<void(const const_iterator& it)> func ) const { const_serial_op(func,ALL); }
1436  void const_serial_op( std::function<void(const const_iterator& it)> func, bool type=ALL ) const {
1437  const_serial_op([func](int i, int j, int k, const const_iterator& it){
1438  func(it);
1439  },type);
1440  }
1447  void const_serial_inside( std::function<void(const const_iterator& it)> func ) const {
1448  const_serial_inside([func](int i, int j, int k, const const_iterator& it){
1449  func(it);
1450  });
1451  }
1458  void const_serial_actives( std::function<void(int i, int j, int k, const const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
1465  void const_serial_all( std::function<void(int i, int j, int k, const const_iterator& it)> func ) const { const_serial_op(func,ALL); }
1474  void const_serial_op( std::function<void(int i, int j, int k, const const_iterator& it)> func, bool type=ALL ) const {
1475  if( type == ACTIVES ) {
1476  m_core->const_serial_actives([&](int i, int j, int k, const void *value_ptr, const bool &filled ){
1477  bool active(true);
1478  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1479  func(i,j,k,it);
1480  return false;
1481  });
1482  } else {
1483  m_core->const_serial_all([&](int i, int j, int k, const void *value_ptr, const bool &active, const bool &filled ){
1484  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1485  func(i,j,k,it);
1486  return false;
1487  });
1488  }
1489  }
1496  void const_serial_inside( std::function<void(int i, int j, int k, const const_iterator& it)> func ) const {
1497  m_core->const_serial_inside([&](int i, int j, int k, const void *value_ptr, const bool &active ){
1498  const_iterator it(value_ptr,active,true,m_fill_value);
1499  func(i,j,k,it);
1500  return false;
1501  });
1502  }
1509  void interruptible_serial_actives( std::function<bool(iterator& it)> func ) { interruptible_serial_op(func,ACTIVES); }
1516  void interruptible_serial_all( std::function<bool(iterator& it)> func ) { interruptible_serial_op(func,ALL); }
1525  void interruptible_serial_op( std::function<bool(iterator& it)> func, bool type=ALL ) {
1526  interruptible_serial_op([func](int i, int j, int k, iterator& it){
1527  return func(it);
1528  },type);
1529  }
1536  void interruptible_serial_actives( std::function<bool(int i, int j, int k, iterator& it)> func ) { interruptible_serial_op(func,ACTIVES); }
1543  void interruptible_serial_all( std::function<bool(int i, int j, int k, iterator& it)> func ) { interruptible_serial_op(func,ALL); }
1552  void interruptible_serial_op( std::function<bool(int i, int j, int k, iterator& it)> func, bool type=ALL ) {
1553  if( type == ACTIVES ) {
1554  m_core->serial_actives([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled ){
1555  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1556  return func(i,j,k,it);
1557  });
1558  } else {
1559  m_core->serial_all([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled ){
1560  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1561  return func(i,j,k,it);
1562  });
1563  }
1564  }
1571  void interruptible_const_serial_actives( std::function<bool(const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ACTIVES); }
1578  void interruptible_const_serial_all( std::function<bool(const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ALL); }
1587  void interruptible_const_serial_op( std::function<bool(const const_iterator& it)> func, bool type=ALL ) const {
1588  const_serial_op([func](int i, int j, int k, const const_iterator& it){
1589  return func(it);
1590  },type);
1591  }
1600  void interruptible_const_serial_inside( std::function<bool(const const_iterator& it)> func, bool type=ALL ) const {
1601  interruptible_const_serial_inside([func](int i, int j, int k, const const_iterator& it){
1602  return func(it);
1603  },type);
1604  }
1611  void interruptible_const_serial_actives( std::function<bool(int i, int j, int k, const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ACTIVES); }
1618  void interruptible_const_serial_all( std::function<bool(int i, int j, int k, const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ALL); }
1627  void interruptible_const_serial_op( std::function<bool(int i, int j, int k, const const_iterator& it)> func, bool type=ALL ) const {
1628  if( type == ACTIVES ) {
1629  m_core->const_serial_actives([&](int i, int j, int k, const void *value_ptr, const bool &filled ){
1630  bool active(true);
1631  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1632  return func(i,j,k,it);
1633  });
1634  } else {
1635  m_core->const_serial_all([&](int i, int j, int k, const void *value_ptr, const bool &active, const bool &filled ){
1636  const_iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1637  return func(i,j,k,it);
1638  });
1639  }
1640  }
1647  void interruptible_const_serial_inside( std::function<bool(int i, int j, int k, const const_iterator& it)> func ) const {
1648  m_core->const_serial_inside([&](int i, int j, int k, const void *value_ptr, const bool &active ){
1649  const_iterator it(value_ptr,active,true,m_fill_value);
1650  return func(i,j,k,it);
1651  });
1652  }
1661  void dilate( std::function<void(int i, int j, int k, iterator& it, int thread_index )> func, int count=1 ) {
1662  while( count -- ) {
1663  m_core->dilate([&](int i, int j, int k, void *value_ptr, bool &active, const bool &filled, int thread_index) {
1664  iterator it(value_ptr,active,filled,filled ? m_fill_value : m_background_value);
1665  func(i,j,k,it,thread_index);
1666  },m_parallel);
1667  }
1668  }
1677  void dilate( std::function<void(int i, int j, int k, iterator& it)> func, int count=1 ) {
1678  dilate([&](int i, int j, int k, iterator& it, int thread_index) {
1679  func(i,j,k,it);
1680  },count);
1681  }
1688  void dilate( int count=1 ) {
1689  dilate([&](int i, int j, int k, iterator& it){ it.set(it()); },count);
1690  }
1699  void erode( std::function<bool(int i, int j, int k, const const_iterator& it, int thread_index)> func, int count=1 ) {
1700  //
1701  std::vector<std::vector<vec3i> > off_positions(get_thread_num());
1702  //
1703  while( count -- ) {
1704  const_parallel_actives([&](int i, int j, int k, const auto &it, int tn) {
1705  bool exit_loop (false);
1706  for( int dim : DIMS3 ) {
1707  for( int dir=-1; dir<=1; dir+=2 ) {
1708  const vec3i &pi = vec3i(i,j,k) + dir*vec3i(dim==0,dim==1,dim==2);
1709  if( ! this->shape().out_of_bounds(pi) && ! this->active(pi)) {
1710  if( func(i,j,k,it,tn)) {
1711  off_positions[tn].push_back(vec3i(i,j,k));
1712  exit_loop = true;
1713  break;
1714  }
1715  }
1716  }
1717  if( exit_loop ) break;
1718  }
1719  });
1720  for( const auto &bucket : off_positions ) for( const auto &pi : bucket ) {
1721  set_off(pi);
1722  }
1723  }
1724  }
1733  void erode( std::function<bool(int i, int j, int k, const const_iterator& it)> func, int count=1 ) {
1734  erode([&](int i, int j, int k, const const_iterator& it, int thread_index) {
1735  return func(i,j,it);
1736  },count);
1737  }
1744  void erode( int count=1 ) {
1745  erode([&](int i, int j, int k, const const_iterator& it, int thread_index) {
1746  return true;
1747  },count);
1748  }
1755  void swap( array3& rhs ) {
1756  m_core.swap(rhs.m_core);
1757  std::swap(m_shape,rhs.m_shape);
1758  std::swap(m_background_value,rhs.m_background_value);
1759  std::swap(m_core_name,rhs.m_core_name);
1760  std::swap(m_touch_only_actives,rhs.m_touch_only_actives);
1761  std::swap(m_levelset,rhs.m_levelset);
1762  std::swap(m_fillable,rhs.m_fillable);
1763  std::swap(m_fill_value,rhs.m_fill_value);
1764  }
1772  return m_parallel;
1773  }
1781  return m_parallel;
1782  }
1789  void set_core_name( std::string core_name ) {
1790  m_core_name = core_name;
1791  }
1798  std::string get_core_name() const {
1799  return m_core_name;
1800  }
1807  const array_core3 * get_core() const {
1808  return m_core.get();
1809  }
1817  return m_core.get();
1818  }
1821  struct type3 {
1826  std::string core_name;
1861  bool operator==(const type3 &rhs) const {
1862  return
1863  core_name == rhs.core_name &&
1864  shape == rhs.shape &&
1865  background_value == rhs.background_value &&
1866  fill_value == rhs.fill_value &&
1867  is_fillable == rhs.is_fillable &&
1868  is_levelset == rhs.is_levelset &&
1869  touch_only_actives == rhs.touch_only_actives;
1870  }
1871  };
1878  type3 type() const { return { get_core_name(),shape(),m_background_value,m_fill_value,m_fillable,m_levelset,m_touch_only_actives}; }
1885  void set_type( const type3 &type ) {
1886  m_core_name = type.core_name;
1887  m_shape = type.shape;
1888  m_background_value = type.background_value;
1889  m_touch_only_actives = type.touch_only_actives;
1890  m_fillable = type.is_fillable;
1891  m_fill_value = type.fill_value;
1892  m_levelset = type.is_levelset;
1893  }
1894  //
1895 private:
1896  //
1897  shape3 m_shape;
1898  parallel_driver m_parallel{this};
1899  T m_background_value {T()}, m_fill_value {T()};
1900  bool m_touch_only_actives {false}, m_fillable {false}, m_levelset {false}, m_is_initialized {false};
1901  char m_levelset_halfwidth {0};
1902  array3_ptr m_core;
1903  std::string m_core_name;
1904 };
1905 //
1907 //
1908 #endif
array3::array3
array3(recursive_configurable *parent, const shape3 &shape, T value=T(), std::string core_name="")
Constructor for array3.
Definition: array3.h:56
array3::devide
void devide(int i, int j, int k, const T &value)
Divide by value on grid.
Definition: array3.h:727
array3::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: array3.h:160
array3::flood_fill
void flood_fill()
Perform flood fill. Grid should be set either level set of fillable beforehand.
Definition: array3.h:299
shape.h
array3::operator=
void operator=(const T &v)
Set all the grid values with an input value.
Definition: array3.h:862
shape3::w
unsigned w
Width of the shape.
Definition: shape.h:942
array3::iterator::increment
void increment(const T &value)
Increment value.
Definition: array3.h:987
array3::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: array3.h:1436
array3::parallel_actives
void parallel_actives(std::function< void(int i, int j, int k, iterator &it, int thread_index)> func)
Loop over all the active cells in parallel.
Definition: array3.h:1197
array3::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: array3.h:1232
array3::dilate
void dilate(int count=1)
Dilate cells.
Definition: array3.h:1688
array3::const_iterator::filled
bool filled() const
Get if a cell is filled.
Definition: array3.h:1104
array3::get_core_name
std::string get_core_name() const
Get the core name of module of this grid.
Definition: array3.h:1798
array3::interruptible_serial_op
void interruptible_serial_op(std::function< bool(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array3.h:1525
array_core3.h
array3::copy_active_as
void copy_active_as(const array3< Y > &array, const vec3i &offset=vec3i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: array3.h:462
array3::type3::shape
shape3 shape
Shape of the grid.
Definition: array3.h:1831
shape3::out_of_bounds
bool out_of_bounds(int i, int j, int k) const
Get if the position is outside of the index space of this shape.
Definition: shape.h:811
array3::interruptible_const_serial_actives
void interruptible_const_serial_actives(std::function< bool(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array3.h:1611
messageable::send_message
virtual bool send_message(std::string message, void *ptr=nullptr)
Send a message.
Definition: messageable.h:48
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
array3::clear
void clear(const T &v)
Clear out the grid with the new backgroud value.
Definition: array3.h:506
array3::parallel_actives
void parallel_actives(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the active cells in parallel.
Definition: array3.h:1170
array3::is_levelset
bool is_levelset() const
Return if the grid is set level set.
Definition: array3.h:292
parallel_driver
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
array_core3
Core module class for three dimensional array designed to be used in array3 class.
Definition: array_core3.h:38
array3::set
void set(int i, int j, int k, const T &value)
Set value on grid.
Definition: array3.h:522
array3::active
bool active(int i, int j, int k) const
Get if a position on grid is active.
Definition: array3.h:552
array_core3::get
virtual void get(unsigned &nx, unsigned &ny, unsigned &nz, unsigned &element_size) const =0
Get grid information.
array3::activate_as_bit
void activate_as_bit(const Y &array, const vec3i &offset=vec3i())
Activate cells at the same positons where an input array is active with an offset.
Definition: array3.h:414
array3::copy
void copy(const array3 &array)
Deep copy function for array3.
Definition: array3.h:181
array3::operator+=
void operator+=(const array3< T > &v)
Increment all the values with the values of an input array.
Definition: array3.h:873
array3::safe_active
bool safe_active(const vec3i &pi) const
Get if a position on grid is active. pi can be safely out of the domain.
Definition: array3.h:591
array3::set_background_value
void set_background_value(const T &value)
Set the background value (alternatively, initial value) of the grid.
Definition: array3.h:484
array3::multiply
void multiply(int i, int j, int k, const T &value)
Multiply value on grid.
Definition: array3.h:695
array3::iterator::ptr
const T * ptr() const
Get const pointer to the value.
Definition: array3.h:1072
array3::get_background_value
T get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: array3.h:477
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
array3::ptr
const T * ptr(const vec3i &pi) const
Get the const pointer to the value at a position on grid.
Definition: array3.h:783
array3::type3::background_value
T background_value
Background value.
Definition: array3.h:1836
array3::const_iterator::operator()
const T & operator()() const
Get the value.
Definition: array3.h:1113
array3::parallel_op
void parallel_op(std::function< void(int i, int j, int k, iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: array3.h:1186
array3::ptr
T * ptr(const vec3i &pi)
Get the pointer to the value at a position on grid.
Definition: array3.h:774
array3::serial_all
void serial_all(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the cells in serial order.
Definition: array3.h:1390
array3::const_iterator::active
bool active() const
Get if a cell is active.
Definition: array3.h:1097
array3::subtract
void subtract(const vec3i &pi, const T &value)
Subtract value on grid.
Definition: array3.h:680
array3::const_parallel_all
void const_parallel_all(std::function< void(int i, int j, int k, const const_iterator &it, int thread_index)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: array3.h:1315
array3::iterator::operator()
const T & operator()() const
Get the value.
Definition: array3.h:1052
shape3::h
unsigned h
Height of the shape.
Definition: shape.h:947
array3::operator()
const T & operator()(const vec3i &pi) const
Get the the value at a position on grid.
Definition: array3.h:808
array3::dilate
void dilate(std::function< void(int i, int j, int k, iterator &it)> func, int count=1)
Dilate cells.
Definition: array3.h:1677
array3::operator!=
bool operator!=(const array3< T > &array) const
Return if the grid is different from an input array.
Definition: array3.h:819
array3::activate_as
void activate_as(const array3< Y > &array, const vec3i &offset=vec3i())
Activate cells at the same positons where an input array is active with an offset.
Definition: array3.h:398
array3::erode
void erode(std::function< bool(int i, int j, int k, const const_iterator &it, int thread_index)> func, int count=1)
Erode cells.
Definition: array3.h:1699
array3::active
bool active(const vec3i &pi) const
Get if a position on grid is active.
Definition: array3.h:564
array3::set_as_fillable
void set_as_fillable(const T &fill_value)
Set the grid as a grid that is fillable by flood fill.
Definition: array3.h:254
array3::clear
void clear()
Clear out the grid.
Definition: array3.h:493
array3::set_core_name
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: array3.h:1789
shape3::count
size_t count() const
Count the number of cells of the grid of this shape.
Definition: shape.h:857
array3::set_off
void set_off(int i, int j, int k)
Set a position on grid inactive.
Definition: array3.h:604
array3::const_iterator
Read-only iterator.
Definition: array3.h:1090
array3::increment
void increment(const vec3i &pi, const T &value)
Increment value on grid.
Definition: array3.h:648
array3::operator*=
void operator*=(const T &v)
Multiply all the grid values with an input value.
Definition: array3.h:923
shape3
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
array3::const_serial_actives
void const_serial_actives(std::function< void(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array3.h:1458
array3::const_serial_all
void const_serial_all(std::function< void(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: array3.h:1465
array3::serial_op
void serial_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array3.h:1372
array3::devide
void devide(const vec3i &pi, const T &value)
Divide by value on grid.
Definition: array3.h:738
array3::get_thread_num
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: array3.h:954
array3::is_fillable
bool is_fillable() const
Return if the grid is set fillable.
Definition: array3.h:283
array3::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: array3.h:1578
array3::serial_actives
void serial_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array3.h:1356
shape3::d
unsigned d
Depth of the shape.
Definition: shape.h:952
array3::activate_inside_as
void activate_inside_as(const array3< Y > &array, const vec3i &offset=vec3i())
Activate cells at the same positons where an input array is filled with an offset.
Definition: array3.h:430
array3::interruptible_serial_actives
void interruptible_serial_actives(std::function< bool(int i, int j, int k, iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array3.h:1536
array3::parallel_all
void parallel_all(std::function< void(int i, int j, int k, iterator &it, int thread_index)> func)
Loop over all the cells in parallel.
Definition: array3.h:1204
array3::array3
array3(const shape3 &shape, T value=T(), std::string core_name="")
Constructor for array3.
Definition: array3.h:87
array3::operator()
const T & operator()(int i, int j, int k) const
Get the the value at a position on grid.
Definition: array3.h:796
array3::set_thread_num
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: array3.h:945
array3::type3::is_levelset
bool is_levelset
Is grid level set.
Definition: array3.h:1851
array3::interruptible_const_serial_op
void interruptible_const_serial_op(std::function< bool(int i, int j, int k, const const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: array3.h:1627
array3::operator/=
void operator/=(const T &v)
Divide all the grid values with an input value.
Definition: array3.h:934
array3::operator-=
void operator-=(const T &v)
Subtract all the grid values with an input value.
Definition: array3.h:912
array3::operator==
bool operator==(const array3< T > &v) const
Return if the grid is same to an input array.
Definition: array3.h:830
messageable::const_send_message
virtual bool const_send_message(std::string message, void *ptr=nullptr) const
Send a message.
Definition: messageable.h:59
array3::const_parallel_actives
void const_parallel_actives(std::function< void(int i, int j, int k, const const_iterator &it, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: array3.h:1308
array3::swap
void swap(array3 &rhs)
Swap array.
Definition: array3.h:1755
array3::get_core
const array_core3 * get_core() const
Get pointer to the core module.
Definition: array3.h:1807
array3::set_as_levelset_as
void set_as_levelset_as(const array3 &array)
Set the grid as level set as same as an input array.
Definition: array3.h:274
array3::send_message
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: array3.h:125
array3::iterator::active
bool active() const
Get if a cell is active.
Definition: array3.h:1036
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array3::iterator::set_off
void set_off()
Inactivate a cell.
Definition: array3.h:977
array3::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: array3.h:1420
array3::serial_actives
void serial_actives(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array3.h:1383
array3::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: array3.h:1248
array3::set_type
void set_type(const type3 &type)
Set the type of this grid.
Definition: array3.h:1885
array3::type3::touch_only_actives
bool touch_only_actives
Are grid operations only allowed on active cells.
Definition: array3.h:1856
array3::type3
Collection of properties of this grid.
Definition: array3.h:1821
array3::iterator::ptr
T * ptr()
Get pointer to the value.
Definition: array3.h:1065
array3::set_as_levelset
void set_as_levelset(double bandwidth_half)
Set the grid as level set.
Definition: array3.h:242
array3::array3
array3(const array3 &array)
Copy constructor for array3.
Definition: array3.h:147
array3::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: array3.h:1239
array3::operator+=
void operator+=(const T &v)
Increment all the grid values with an input value.
Definition: array3.h:901
array3::parallel_all
void parallel_all(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the cells in parallel.
Definition: array3.h:1177
array3::type3::is_fillable
bool is_fillable
Is grid fillable.
Definition: array3.h:1846
array3::const_parallel_all
void const_parallel_all(std::function< void(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: array3.h:1277
array3::ptr
const T * ptr(unsigned i, unsigned j, unsigned k) const
Get the const pointer to the value at a position on grid.
Definition: array3.h:765
array3::dilate
void dilate(std::function< void(int i, int j, int k, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: array3.h:1661
array3::const_parallel_actives
void const_parallel_actives(std::function< void(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: array3.h:1270
array3::interruptible_serial_all
void interruptible_serial_all(std::function< bool(iterator &it)> func)
Loop over all the cells in serial order.
Definition: array3.h:1516
array3::iterator::multiply
void multiply(const T &value)
Multiply value.
Definition: array3.h:1015
array3::const_iterator::ptr
const T * ptr() const
Get const pointer to the value.
Definition: array3.h:1126
array3::const_serial_op
void const_serial_op(std::function< void(int i, int j, int k, const const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: array3.h:1474
array3::iterator
Writable iterator.
Definition: array3.h:959
array3::type3::fill_value
T fill_value
Fill value.
Definition: array3.h:1841
array3::type3::operator==
bool operator==(const type3 &rhs) const
Comparison operator.
Definition: array3.h:1861
array3::interruptible_const_serial_all
void interruptible_const_serial_all(std::function< bool(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: array3.h:1618
array3::get_parallel_driver
const parallel_driver & get_parallel_driver() const
Get the const instance of parallel_driver of this grid.
Definition: array3.h:1780
array3::parallel_actives
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: array3.h:1143
array3::const_send_message
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: array3.h:138
array3::const_parallel_inside
void const_parallel_inside(std::function< void(int i, int j, int k, const const_iterator &it, int thread_index)> func) const
Loop over all the filled cells in parallel.
Definition: array3.h:1344
array3::parallel_all
void parallel_all(std::function< void(iterator &it)> func)
Loop over all the cells in parallel.
Definition: array3.h:1150
array3::operator=
array3 & operator=(const array3 &array)
Deep copy operation for array3.
Definition: array3.h:169
array3::serial_all
void serial_all(std::function< void(iterator &it)> func)
Loop over all the cells in serial order.
Definition: array3.h:1363
array3::safe_active
bool safe_active(int i, int j, int k) const
Get if a position on grid is active. (i,j,k) can be safely out of the domain.
Definition: array3.h:577
array3::const_parallel_op
void const_parallel_op(std::function< void(int i, int j, int k, const const_iterator &it, int thread_index)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: array3.h:1324
array3::const_parallel_inside
void const_parallel_inside(std::function< void(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the filled cells in parallel by read-only fashion.
Definition: array3.h:1297
array3::count
size_t count() const
Function to count the number of active cells.
Definition: array3.h:360
array3::const_serial_inside
void const_serial_inside(std::function< void(int i, int j, int k, const const_iterator &it)> func) const
Loop over filled the cells in serial order by read-only fashion.
Definition: array3.h:1496
array3::interruptible_serial_all
void interruptible_serial_all(std::function< bool(int i, int j, int k, iterator &it)> func)
Loop over all the cells in serial order.
Definition: array3.h:1543
array3::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: array3.h:1259
array3::parallel_op
void parallel_op(std::function< void(int i, int j, int k, iterator &it, int thread_index)> func, bool type=ALL)
Loop over cells in parallel.
Definition: array3.h:1213
array3::increment
void increment(int i, int j, int k, const T &value)
Increment value on grid.
Definition: array3.h:631
array3::iterator::filled
bool filled() const
Get if a cell is filled.
Definition: array3.h:1043
recursive_configurable
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
array3::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: array3.h:198
parallel_driver.h
array3::filled
bool filled(int i, int j, int k) const
Function to get if a cell is filled.
Definition: array3.h:338
array3::interruptible_serial_actives
void interruptible_serial_actives(std::function< bool(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: array3.h:1509
array3::filled
bool filled(const vec3i &pi) const
Function to get if a cell is filled.
Definition: array3.h:351
array3::activate
void activate(const std::vector< vec3i > &active_entries, const vec3i &offset=vec3i())
Activate cells at the positons of active_entries with an offset.
Definition: array3.h:382
array3::array3
array3(recursive_configurable *parent, std::string core_name="")
Constructor for array3.
Definition: array3.h:69
vec
Fixed sized vector structure.
Definition: vec.h:38
array3::initialize
void initialize(const shape3 &shape, T value=T())
Allocate grid memory with value.
Definition: array3.h:227
array3::iterator::divide
void divide(const T &value)
Divide by value.
Definition: array3.h:1029
array3::iterator::set
void set(const T &value)
Set a value.
Definition: array3.h:968
array3::parallel_op
void parallel_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: array3.h:1159
vec.h
array3::const_parallel_op
void const_parallel_op(std::function< void(int i, int j, int k, const const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: array3.h:1286
array3::set_off
void set_off(const vec3i &pi)
Set a position on grid inactive.
Definition: array3.h:616
array3::erode
void erode(std::function< bool(int i, int j, int k, const const_iterator &it)> func, int count=1)
Erode cells.
Definition: array3.h:1733
configuration
Class that controls the settings of the program.
Definition: configuration.h:39
array3::set
void set(const vec3i &pi, const T &value)
Set value on grid.
Definition: array3.h:537
messageable
Message class.
Definition: messageable.h:36
array3::interruptible_const_serial_inside
void interruptible_const_serial_inside(std::function< bool(const const_iterator &it)> func, bool type=ALL) const
Loop over all the filled cells in serial order by read-only fashion.
Definition: array3.h:1600
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array3::type
type3 type() const
Get the type of this grid.
Definition: array3.h:1878
array3::actives
std::vector< vec3i > actives() const
Function to return the list of active cells positions.
Definition: array3.h:367
array3::interruptible_serial_op
void interruptible_serial_op(std::function< bool(int i, int j, int k, iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array3.h:1552
array3::subtract
void subtract(int i, int j, int k, const T &value)
Subtract value on grid.
Definition: array3.h:663
array3::array3
array3(std::string core_name="")
Constructor for array3.
Definition: array3.h:76
array3::fills
std::vector< vec3i > fills() const
Function to return the list of filled cells.
Definition: array3.h:319
array3::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: array3.h:1427
array3::serial_op
void serial_op(std::function< void(int i, int j, int k, iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: array3.h:1399
array3::get_parallel_driver
parallel_driver & get_parallel_driver()
Get the instance of parallel_driver of this grid.
Definition: array3.h:1771
array3::interruptible_const_serial_inside
void interruptible_const_serial_inside(std::function< bool(int i, int j, int k, const const_iterator &it)> func) const
Loop over all the filled cells in serial order by read-only fashion.
Definition: array3.h:1647
recursive_configurable::add_child
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
array3::get_core
array_core3 * get_core()
Get pointer to the core module.
Definition: array3.h:1816
array3::multiply
void multiply(const vec3i &pi, const T &value)
Multiply value on grid.
Definition: array3.h:712
array3::activate_inside
void activate_inside()
Activate all the filled cells.
Definition: array3.h:451
array3::shape
shape3 shape() const
Get the shape of the array.
Definition: array3.h:218
array3::iterator::subtract
void subtract(const T &value)
Subtract value.
Definition: array3.h:1001
array3::type3::core_name
std::string core_name
Core name of the module.
Definition: array3.h:1826
array3::ptr
T * ptr(unsigned i, unsigned j, unsigned k)
Get the pointer to the value at a position on grid.
Definition: array3.h:751
array3::operator-=
void operator-=(const array3< T > &v)
Subtract all the values with the values of an input array.
Definition: array3.h:887
array3::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: array3.h:1447
array3::erode
void erode(int count=1)
Erode cells.
Definition: array3.h:1744
array3::set_as_fillable_as
void set_as_fillable_as(const array3 &array)
Set the grid as fillable as same as an input array.
Definition: array3.h:265
array3::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: array3.h:1587
array3::activate_all
void activate_all()
Activate all the cells.
Definition: array3.h:442
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42