Shiokaze Framework
A research-oriented fluid solver for computer graphics
bitarray2.h
Go to the documentation of this file.
1 /*
2 ** bitarray2.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 August 8, 2018.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_BITARRAY2_H
26 #define SHKZ_BITARRAY2_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 //
39 template <class T> class array2;
41 class bitarray2 : public recursive_configurable, public messageable {
44 public:
55  bitarray2( recursive_configurable *parent, const shape2 &shape, std::string core_name="" ) :
56  m_core_name(core_name), m_shape(shape) {
57  if( parent ) parent->add_child(this);
58  else setup_now();
59  }
68  bitarray2( recursive_configurable *parent, std::string core_name="" ) : bitarray2(parent,shape2(0,0),core_name) {}
75  bitarray2( std::string core_name="" ) : bitarray2(nullptr,shape2(0,0),core_name) {}
84  bitarray2( const shape2 &shape, std::string core_name="" ) : bitarray2(nullptr,shape,core_name) {}
85  //
86 private:
87  //
88  virtual void load( configuration &config ) override {
89  if( m_core_name.empty()) {
90  m_core_name = shkz_default_array_core2;
91  } else {
92  auto pos = m_core_name.find('*');
93  if( pos != std::string::npos ) {
94  m_core_name.erase(pos,1);
95  m_core_name.insert(pos,shkz_default_array_core2);
96  }
97  }
98  m_core = array_core2::quick_load_module(config,m_core_name);
99  }
100  //
101  virtual void configure( configuration &config ) override {
102  m_core->recursive_configure(config);
103  }
104  //
105  virtual void post_initialize() override {
106  if( shape().count() && ! m_is_initialized ) {
107  initialize(m_shape);
108  }
109  }
110  //
111 public:
122  virtual bool send_message( std::string message, void *ptr ) override {
123  return get_core()->send_message(message,ptr);
124  }
135  virtual bool const_send_message( std::string message, void *ptr ) const override {
136  return get_core()->const_send_message(message,ptr);
137  }
144  bitarray2( const bitarray2 &array ) {
145  m_core_name = array.m_core_name;
146  setup_now();
147  copy(array);
148  }
155  bitarray2& operator=(const bitarray2 &array) {
156  if( this != &array ) {
157  copy(array);
158  }
159  return *this;
160  }
167  void copy( const bitarray2 &array ) {
168  if( this != &array ) {
169  set_type(array.type());
170  assert(m_core);
171  if( array.m_core ) {
172  m_core->copy(*array.get_core(),[&](void *target, const void *src){},m_parallel);
173  }
174  }
175  }
176  virtual ~bitarray2() {
177  clear();
178  }
185  shape2 shape() const { return m_shape; }
192  void initialize( const shape2 &shape ) {
193  clear();
194  m_core->initialize(shape.w,shape.h,0);
195  m_shape = shape;
196  m_is_initialized = true;
197  }
204  size_t count () const { return m_core->count(m_parallel); }
211  std::vector<vec2i> actives() const {
212  std::vector<vec2i> result;
213  const_serial_actives([&](int i, int j) {
214  result.push_back(vec2i(i,j));
215  });
216  return result;
217  }
226  void activate( const std::vector<vec2i> &active_entries, const vec2i &offset=vec2i() ) {
227  for( const auto &e : active_entries ) {
228  const vec2i &pi = e + offset;
229  if( ! shape().out_of_bounds(pi) && ! (*this)(pi)) {
230  set(pi);
231  }
232  }
233  }
242  template <class Y> void activate_as( const array2<Y> &array, const vec2i &offset=vec2i() ) {
243  array.const_serial_actives([&](int i, int j, const auto &it) {
244  const vec2i &pi = vec2i(i,j) + offset;
245  if( ! this->shape().out_of_bounds(pi) && ! (*this)(pi)) {
246  this->set(pi);
247  }
248  });
249  }
258  template <class Y> void activate_as_bit( const Y &array, const vec2i &offset=vec2i() ) {
259  array.const_serial_actives([&](int i, int j) {
260  const vec2i &pi = vec2i(i,j) + offset;
261  if( ! this->shape().out_of_bounds(pi) && ! (*this)(pi)) {
262  this->set(pi);
263  }
264  });
265  }
274  template <class Y> void activate_inside_as( const array2<Y> &array, const vec2i &offset=vec2i() ) {
275  array.const_serial_inside([&](int i, int j, const auto &it) {
276  const vec2i &pi = vec2i(i,j) + offset;
277  if( ! this->shape().out_of_bounds(pi) && ! (*this)(pi)) {
278  this->set(pi);
279  }
280  });
281  }
286  void activate_all() {
287  parallel_all([&](auto &it) {
288  it.set();
289  });
290  }
299  void copy_active_as( const bitarray2 &array, const vec2i &offset=vec2i() ) {
300  parallel_actives([&](int i, int j, auto &it, int tn) {
301  const vec2i &pi = vec2i(i,j) + offset;
302  if( ! this->shape().out_of_bounds(pi) ) {
303  if( (*this)(pi) && ! array(pi)) {
304  it.set_off();
305  }
306  }
307  });
308  activate_as_bit(array,offset);
309  }
318  void clear() {
319  parallel_actives([&](iterator& it) {
320  it.set_off();
321  });
322  }
331  void set( int i, int j ) {
332  m_core->set(i,j,[&](void *value_ptr, bool &active){
333  active = true;
334  });
335  }
344  void set( const vec2i &pi ) {
345  set(pi[0],pi[1]);
346  }
357  bool operator()( int i, int j ) const {
358  bool filled;
359  return (*m_core)(i,j,filled) != nullptr;
360  }
369  bool operator()( const vec2i &pi ) const {
370  return (*this)(pi[0],pi[1]);
371  }
382  bool safe_get( int i, int j ) const {
383  if( ! m_shape.out_of_bounds(i,j)) {
384  return (*this)(i,j);
385  }
386  return false;
387  }
396  bool safe_get( const vec2i &pi ) const {
397  return (*this)(pi[0],pi[1]);
398  }
407  void set_off( int i, int j ) {
408  m_core->set(i,j,[&](void *value_ptr, bool &active){
409  active = false;
410  });
411  }
418  void set_off( const vec2i &pi ) {
419  set_off(pi[0],pi[1]);
420  }
429  bool operator!=( const bitarray2 &array ) const {
430  return ! (*this == array);
431  }
440  bool operator==(const bitarray2 &v) const {
441  if( v.type() == type() ) {
442  bool differnt (false);
443  interruptible_const_serial_actives([&]( int i, int j ) {
444  if( ! v(i,j)) {
445  differnt = true;
446  return true;
447  } else {
448  return false;
449  }
450  });
451  return ! differnt;
452  }
453  return false;
454  }
461  void set_thread_num( int number ) {
462  m_parallel.set_thread_num(number);
463  }
470  int get_thread_num() const {
471  return m_parallel.get_thread_num();
472  }
475  class iterator {
476  friend class bitarray2;
477  public:
484  void set() {
485  m_active = true;
486  }
491  void set_off() {
492  m_active = false;
493  }
498  bool operator()() const {
499  return m_active;
500  }
501  private:
502  //
503  iterator( bool &_active ) : m_active(_active) {}
504  bool &m_active;
505  };
509  friend class bitarray2;
510  public:
515  bool operator()() const {
516  return m_active;
517  }
518  private:
519  //
520  const_iterator( const bool &_active ) : m_active(_active) {}
521  const bool &m_active;
522  };
523  //
524  enum { ACTIVES = true, ALL = false };
531  void parallel_actives( std::function<void(iterator& it)> func ) { parallel_op(func,ACTIVES); }
538  void parallel_all( std::function<void(iterator& it)> func ) { parallel_op(func,ALL); }
547  void parallel_op( std::function<void(iterator& it)> func, bool type=ALL ) {
548  parallel_op([func](int i, int j, iterator& it, int thread_index){
549  func(it);
550  },type);
551  }
558  void parallel_actives( std::function<void(int i, int j, iterator& it)> func ) { parallel_op(func,ACTIVES); }
565  void parallel_all( std::function<void(int i, int j, iterator& it)> func ) { parallel_op(func,ALL); }
574  void parallel_op( std::function<void(int i, int j, iterator& it)> func, bool type=ALL ) {
575  parallel_op([func](int i, int j, iterator& it, int thread_index){
576  func(i,j,it);
577  },type);
578  }
585  void parallel_actives( std::function<void(int i, int j, iterator& it, int thread_index)> func ) { parallel_op(func,ACTIVES); }
592  void parallel_all( std::function<void(int i, int j, iterator& it, int thread_index)> func ) { parallel_op(func,ALL); }
601  void parallel_op( std::function<void(int i, int j, iterator& it, int thread_index)> func, bool type=ALL ) {
602  if( type == ACTIVES ) {
603  m_core->parallel_actives([&](int i, int j, void *value_ptr, bool &active, const bool &filled, int thread_n ){
604  iterator it(active);
605  func(i,j,it,thread_n);
606  },m_parallel);
607  } else {
608  m_core->parallel_all([&](int i, int j, void *value_ptr, bool &active, const bool &filled, int thread_n ){
609  iterator it(active);
610  func(i,j,it,thread_n);
611  },m_parallel);
612  }
613  }
620  void const_parallel_all( std::function<void(const const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
629  void const_parallel_op( std::function<void(const const_iterator& it)> func, bool type=ALL ) const {
630  const_parallel_op([func](int i, int j, const const_iterator& it, int thread_index){
631  func(it);
632  },type);
633  }
640  void const_parallel_actives( std::function<void(int i, int j)> func ) const { const_parallel_op([&](int i, int j, const const_iterator& it) {
641  func(i,j); },ACTIVES); }
648  void const_parallel_all( std::function<void(int i, int j, const const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
657  void const_parallel_op( std::function<void(int i, int j, const const_iterator& it)> func, bool type=ALL ) const {
658  const_parallel_op([func](int i, int j, const const_iterator& it, int thread_index){
659  func(i,j,it);
660  },type);
661  }
668  void const_parallel_actives( std::function<void(int i, int j, int thread_index)> func ) const { const_parallel_op(
669  [&](int i, int j, const const_iterator& it, int thread_index) { func(i,j,thread_index); },ACTIVES); }
676  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); }
685  void const_parallel_op( std::function<void(int i, int j, const const_iterator& it, int thread_index)> func, bool type=ALL ) const {
686  if( type == ACTIVES ) {
687  m_core->const_parallel_actives([&](int i, int j, const void *value_ptr, const bool &filled, int thread_n ){
688  bool active(true);
689  const_iterator it(active);
690  func(i,j,it,thread_n);
691  },m_parallel);
692  } else {
693  m_core->const_parallel_all([&](int i, int j, const void *value_ptr, const bool &active, const bool &filled, int thread_n ){
694  const_iterator it(active);
695  func(i,j,it,thread_n);
696  },m_parallel);
697  }
698  }
705  void serial_actives( std::function<void(iterator& it)> func ) { serial_op(func,ACTIVES); }
712  void serial_all( std::function<void(iterator& it)> func ) { serial_op(func,ALL); }
721  void serial_op( std::function<void(iterator& it)> func, bool type=ALL ) {
722  serial_op([func](int i, int j, iterator& it){
723  func(it);
724  },type);
725  }
732  void serial_actives( std::function<void(int i, int j, iterator& it)> func ) { serial_op(func,ACTIVES); }
739  void serial_all( std::function<void(int i, int j, iterator& it)> func ) { serial_op(func,ALL); }
748  void serial_op( std::function<void(int i, int j, iterator& it)> func, bool type=ALL ) {
749  if( type == ACTIVES ) {
750  m_core->serial_actives([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
751  iterator it(active);
752  func(i,j,it);
753  return false;
754  });
755  } else {
756  m_core->serial_all([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
757  iterator it(active);
758  func(i,j,it);
759  return false;
760  });
761  }
762  }
769  void const_serial_all( std::function<void(const const_iterator& it)> func ) const { const_serial_op(func,ALL); }
778  void const_serial_op( std::function<void(const const_iterator& it)> func, bool type=ALL ) const {
779  const_serial_op([func](int i, int j, const const_iterator& it){
780  func(it);
781  },type);
782  }
789  void const_serial_actives( std::function<void(int i, int j)> func ) const {
790  const_serial_op([&]( int i, int j, const const_iterator& it ) {func(i,j);},ACTIVES); }
797  void const_serial_all( std::function<void(int i, int j, const const_iterator& it)> func ) const { const_serial_op(func,ALL); }
806  void const_serial_op( std::function<void(int i, int j, const const_iterator& it)> func, bool type=ALL ) const {
807  if( type == ACTIVES ) {
808  m_core->const_serial_actives([&](int i, int j, const void *value_ptr, const bool &filled ){
809  bool active(true);
810  const_iterator it(active);
811  func(i,j,it);
812  return false;
813  });
814  } else {
815  m_core->const_serial_all([&](int i, int j, const void *value_ptr, const bool &active, const bool &filled ){
816  const_iterator it(active);
817  func(i,j,it);
818  return false;
819  });
820  }
821  }
828  void interruptible_serial_actives( std::function<bool(iterator& it)> func ) { interruptible_serial_op(func,ACTIVES); }
835  void interruptible_serial_all( std::function<bool(iterator& it)> func ) { interruptible_serial_op(func,ALL); }
844  void interruptible_serial_op( std::function<bool(iterator& it)> func, bool type=ALL ) {
845  interruptible_serial_op([func](int i, int j, iterator& it){
846  return func(it);
847  },type);
848  }
855  void interruptible_serial_actives( std::function<bool(int i, int j, iterator& it)> func ) { interruptible_serial_op(func,ACTIVES); }
862  void interruptible_serial_all( std::function<bool(int i, int j, iterator& it)> func ) { interruptible_serial_op(func,ALL); }
871  void interruptible_serial_op( std::function<bool(int i, int j, iterator& it)> func, bool type=ALL ) {
872  if( type == ACTIVES ) {
873  m_core->serial_actives([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
874  iterator it(active);
875  return func(i,j,it);
876  });
877  } else {
878  m_core->serial_all([&](int i, int j, void *value_ptr, bool &active, const bool &filled ){
879  iterator it(active);
880  return func(i,j,it);
881  });
882  }
883  }
890  void interruptible_const_serial_all( std::function<bool(const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ALL); }
899  void interruptible_const_serial_op( std::function<bool(const const_iterator& it)> func, bool type=ALL ) const {
900  interruptible_const_serial_op([func](int i, int j, const const_iterator& it){
901  return func(it);
902  },type);
903  }
910  void interruptible_const_serial_actives( std::function<bool(int i, int j)> func ) const {
911  interruptible_const_serial_op([&](int i, int j, const const_iterator& it) {return func(i,j);},ACTIVES); }
918  void interruptible_const_serial_all( std::function<bool(int i, int j, const const_iterator& it)> func ) const { interruptible_const_serial_op(func,ALL); }
927  void interruptible_const_serial_op( std::function<bool(int i, int j, const const_iterator& it)> func, bool type=ALL ) const {
928  if( type == ACTIVES ) {
929  m_core->const_serial_actives([&](int i, int j, const void *value_ptr, const bool &filled ){
930  bool active(true);
931  const_iterator it(active);
932  return func(i,j,it);
933  });
934  } else {
935  m_core->const_serial_all([&](int i, int j, const void *value_ptr, const bool &active, const bool &filled ){
936  const_iterator it(active);
937  return func(i,j,it);
938  });
939  }
940  }
949  void dilate( std::function<void(int i, int j, iterator& it, int thread_index)> func, int count=1 ) {
950  while( count -- ) {
951  m_core->dilate([&](int i, int j, void *value_ptr, bool &active, const bool &filled, int thread_index) {
952  iterator it(active);
953  func(i,j,it,thread_index);
954  },m_parallel);
955  }
956  }
965  void dilate( std::function<void(int i, int j, iterator& it)> func, int count=1 ) {
966  dilate([&](int i, int j, iterator& it, int thread_index) {
967  func(i,j,it);
968  },count);
969  }
976  void dilate( int count=1 ) {
977  dilate([&](int i, int j, iterator& it){ it.set(); },count);
978  }
987  void erode( std::function<bool(int i, int j, int thread_index)> func, int count=1 ) {
988  //
989  std::vector<std::vector<vec2i> > off_positions(get_thread_num());
990  //
991  while( count -- ) {
992  const_parallel_actives([&](int i, int j, int tn) {
993  bool exit_loop (false);
994  for( int dim : DIMS2 ) {
995  for( int dir=-1; dir<=1; dir+=2 ) {
996  const vec2i &pi = vec2i(i,j) + dir*vec2i(dim==0,dim==1);
997  if( ! this->shape().out_of_bounds(pi) && ! (*this)(pi)) {
998  if( func(i,j,tn)) {
999  off_positions[tn].push_back(vec2i(i,j));
1000  exit_loop = true;
1001  break;
1002  }
1003  }
1004  }
1005  if( exit_loop ) break;
1006  }
1007  });
1008  for( const auto &bucket : off_positions ) for( const auto &pi : bucket ) {
1009  set_off(pi);
1010  }
1011  }
1012  }
1021  void erode( std::function<bool(int i, int j)> func, int count=1 ) {
1022  erode([&](int i, int j, int thread_index) {
1023  return func(i,j);
1024  },count);
1025  }
1032  void erode( int count=1 ) {
1033  erode([&](int i, int j, int thread_index) { return true; },count);
1034  }
1041  void swap( bitarray2& rhs ) {
1042  m_core.swap(rhs.m_core);
1043  std::swap(m_shape,rhs.m_shape);
1044  }
1052  return m_parallel;
1053  }
1061  return m_parallel;
1062  }
1069  void set_core_name( std::string core_name ) {
1070  m_core_name = core_name;
1071  }
1078  std::string get_core_name() const {
1079  return m_core_name;
1080  }
1087  const array_core2 * get_core() const {
1088  return m_core.get();
1089  }
1097  return m_core.get();
1098  }
1101  struct type2 {
1106  std::string core_name;
1118  bool operator==( const type2 &type ) const {
1119  return core_name == type.core_name && shape == type.shape;
1120  }
1121  };
1128  type2 type() const { return { get_core_name(),shape() }; }
1135  void set_type( const type2 &type ) {
1136  m_core_name = type.core_name;
1137  m_shape = type.shape;
1138  }
1139  //
1140 private:
1141  //
1142  shape2 m_shape;
1143  parallel_driver m_parallel{this};
1144  bool m_is_initialized {false};
1145  array2_ptr m_core;
1146  std::string m_core_name;
1147 };
1148 //
1150 //
1151 #endif
bitarray2::bitarray2
bitarray2(recursive_configurable *parent, std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:68
shape.h
bitarray2::serial_all
void serial_all(std::function< void(int i, int j, iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray2.h:739
bitarray2::bitarray2
bitarray2(const shape2 &shape, std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:84
bitarray2::type2::shape
shape2 shape
Shape of the grid.
Definition: bitarray2.h:1111
bitarray2::clear
void clear()
Clear out the grid.
Definition: bitarray2.h:318
bitarray2::parallel_all
void parallel_all(std::function< void(int i, int j, iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitarray2.h:565
bitarray2::const_send_message
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitarray2.h:135
bitarray2::interruptible_serial_actives
void interruptible_serial_actives(std::function< bool(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitarray2.h:828
bitarray2::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: bitarray2.h:620
bitarray2::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: bitarray2.h:890
bitarray2::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: bitarray2.h:685
bitarray2::dilate
void dilate(std::function< void(int i, int j, iterator &it)> func, int count=1)
Dilate cells.
Definition: bitarray2.h:965
messageable::send_message
virtual bool send_message(std::string message, void *ptr=nullptr)
Send a message.
Definition: messageable.h:48
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
bitarray2::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: bitarray2.h:797
bitarray2::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: bitarray2.h:274
parallel_driver
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
bitarray2::get_thread_num
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: bitarray2.h:470
bitarray2::erode
void erode(std::function< bool(int i, int j, int thread_index)> func, int count=1)
Erode cells.
Definition: bitarray2.h:987
bitarray2::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: bitarray2.h:918
bitarray2::count
size_t count() const
Function to count the number of active cells.
Definition: bitarray2.h:204
bitarray2::erode
void erode(int count=1)
Erode cells.
Definition: bitarray2.h:1032
bitarray2::parallel_actives
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitarray2.h:531
bitarray2::bitarray2
bitarray2(std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:75
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
bitarray2::bitarray2
bitarray2(recursive_configurable *parent, const shape2 &shape, std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:55
bitarray2::serial_all
void serial_all(std::function< void(iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray2.h:712
bitarray2::parallel_op
void parallel_op(std::function< void(int i, int j, iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitarray2.h:574
bitarray2::set_off
void set_off(int i, int j)
Set a position on grid inactive.
Definition: bitarray2.h:407
bitarray2::iterator::operator()
bool operator()() const
Get if a cell is active.
Definition: bitarray2.h:498
array_core2.h
bitarray2::const_parallel_actives
void const_parallel_actives(std::function< void(int i, int j, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitarray2.h:668
bitarray2::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: bitarray2.h:732
bitarray2::parallel_all
void parallel_all(std::function< void(iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitarray2.h:538
bitarray2::type2::core_name
std::string core_name
Core name of the module.
Definition: bitarray2.h:1106
bitarray2::bitarray2
bitarray2(const bitarray2 &array)
Copy constructor for bitarray2.
Definition: bitarray2.h:144
bitarray2::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: bitarray2.h:585
bitarray2::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: bitarray2.h:226
bitarray2::safe_get
bool safe_get(int i, int j) const
Get if a position on grid is active. (i,j) can be safely out of the domain.
Definition: bitarray2.h:382
bitarray2::type
type2 type() const
Get the type of this grid.
Definition: bitarray2.h:1128
bitarray2::operator()
bool operator()(const vec2i &pi) const
Get if a position on grid is active.
Definition: bitarray2.h:369
bitarray2::set
void set(const vec2i &pi)
Set bit on grid.
Definition: bitarray2.h:344
bitarray2::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: bitarray2.h:629
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
bitarray2::parallel_op
void parallel_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitarray2.h:547
bitarray2::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: bitarray2.h:601
bitarray2::erode
void erode(std::function< bool(int i, int j)> func, int count=1)
Erode cells.
Definition: bitarray2.h:1021
parallel_driver::get_thread_num
int get_thread_num() const
Get the number of maximal threads set.
Definition: parallel_driver.h:80
shape2::h
unsigned h
Height of the shape.
Definition: shape.h:466
bitarray2::safe_get
bool safe_get(const vec2i &pi) const
Get if a position on grid is active. pi can be safely out of the domain.
Definition: bitarray2.h:396
bitarray2::parallel_actives
void parallel_actives(std::function< void(int i, int j, iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitarray2.h:558
bitarray2::dilate
void dilate(std::function< void(int i, int j, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: bitarray2.h:949
messageable::const_send_message
virtual bool const_send_message(std::string message, void *ptr=nullptr) const
Send a message.
Definition: messageable.h:59
bitarray2::get_core
const array_core2 * get_core() const
Get pointer to the core module.
Definition: bitarray2.h:1087
bitarray2::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: bitarray2.h:806
bitarray2::set_type
void set_type(const type2 &type)
Set the type of this grid.
Definition: bitarray2.h:1135
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
bitarray2::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: bitarray2.h:778
shape2::w
unsigned w
Width of the shape.
Definition: shape.h:461
bitarray2::const_serial_actives
void const_serial_actives(std::function< void(int i, int j)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitarray2.h:789
bitarray2::const_iterator
Read-only iterator.
Definition: bitarray2.h:508
bitarray2::operator=
bitarray2 & operator=(const bitarray2 &array)
Deep copy operation for bitarray2.
Definition: bitarray2.h:155
bitarray2::const_parallel_actives
void const_parallel_actives(std::function< void(int i, int j)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitarray2.h:640
bitarray2::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: bitarray2.h:855
bitarray2::swap
void swap(bitarray2 &rhs)
Swap array.
Definition: bitarray2.h:1041
bitarray2::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: bitarray2.h:676
bitarray2::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: bitarray2.h:592
parallel_driver::set_thread_num
void set_thread_num(int maximal_threads)
Set the number of maximal threads set.
Definition: parallel_driver.h:89
bitarray2::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: bitarray2.h:258
bitarray2::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: bitarray2.h:748
bitarray2::serial_op
void serial_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitarray2.h:721
bitarray2::iterator::set
void set()
Set a value.
Definition: bitarray2.h:484
bitarray2::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: bitarray2.h:871
array_core2
Core module class for two dimensional array designed to be used in array2 class.
Definition: array_core2.h:38
bitarray2::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: bitarray2.h:927
bitarray2::copy
void copy(const bitarray2 &array)
Deep copy function for bitarray2.
Definition: bitarray2.h:167
bitarray2::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: bitarray2.h:657
bitarray2::type2
Collection of properties of this grid.
Definition: bitarray2.h:1101
bitarray2::iterator
Writable iterator.
Definition: bitarray2.h:475
bitarray2::send_message
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: bitarray2.h:122
bitarray2::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: bitarray2.h:769
bitarray2::dilate
void dilate(int count=1)
Dilate cells.
Definition: bitarray2.h:976
bitarray2::serial_actives
void serial_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitarray2.h:705
bitarray2::set_thread_num
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: bitarray2.h:461
recursive_configurable
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
bitarray2::actives
std::vector< vec2i > actives() const
Function to return the list of active cells positions.
Definition: bitarray2.h:211
parallel_driver.h
bitarray2::const_iterator::operator()
bool operator()() const
Get if a cell is active.
Definition: bitarray2.h:515
vec
Fixed sized vector structure.
Definition: vec.h:38
bitarray2::shape
shape2 shape() const
Get the shape of the array.
Definition: bitarray2.h:185
vec.h
bitarray2::get_core_name
std::string get_core_name() const
Get the core name of module of this grid.
Definition: bitarray2.h:1078
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
bitarray2::get_parallel_driver
const parallel_driver & get_parallel_driver() const
Get the const instance of parallel_driver of this grid.
Definition: bitarray2.h:1060
bitarray2::copy_active_as
void copy_active_as(const bitarray2 &array, const vec2i &offset=vec2i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: bitarray2.h:299
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
bitarray2::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: bitarray2.h:862
bitarray2::set_core_name
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitarray2.h:1069
bitarray2::activate_all
void activate_all()
Activate all the cells.
Definition: bitarray2.h:286
configuration
Class that controls the settings of the program.
Definition: configuration.h:39
bitarray2::operator!=
bool operator!=(const bitarray2 &array) const
Return if the grid is different from an input array.
Definition: bitarray2.h:429
bitarray2::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: bitarray2.h:242
shape2
Structure that defines shape such as width, height.
Definition: shape.h:42
bitarray2::operator()
bool operator()(int i, int j) const
Get if a position on grid is active.
Definition: bitarray2.h:357
messageable
Message class.
Definition: messageable.h:36
bitarray2::interruptible_serial_op
void interruptible_serial_op(std::function< bool(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitarray2.h:844
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
bitarray2::interruptible_serial_all
void interruptible_serial_all(std::function< bool(iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray2.h:835
bitarray2::type2::operator==
bool operator==(const type2 &type) const
Check equality.
Definition: bitarray2.h:1118
bitarray2::set_off
void set_off(const vec2i &pi)
Set a position on grid inactive.
Definition: bitarray2.h:418
bitarray2::iterator::set_off
void set_off()
Inactivate a cell.
Definition: bitarray2.h:491
recursive_configurable::add_child
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
bitarray2::get_parallel_driver
parallel_driver & get_parallel_driver()
Get the instance of parallel_driver of this grid.
Definition: bitarray2.h:1051
bitarray2::operator==
bool operator==(const bitarray2 &v) const
Return if the grid is same to an input array.
Definition: bitarray2.h:440
bitarray2::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: bitarray2.h:899
bitarray2::interruptible_const_serial_actives
void interruptible_const_serial_actives(std::function< bool(int i, int j)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitarray2.h:910
bitarray2::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: bitarray2.h:648
bitarray2::set
void set(int i, int j)
Set bit on grid.
Definition: bitarray2.h:331
bitarray2::get_core
array_core2 * get_core()
Get pointer to the core module.
Definition: bitarray2.h:1096
bitarray2::initialize
void initialize(const shape2 &shape)
Allocate grid memory with value.
Definition: bitarray2.h:192
bitarray2
Two dimensional bit grid class designed to be defined as instance member in recursive_configurable cl...
Definition: bitarray2.h:43