 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_BITARRAY2_H
26 #define SHKZ_BITARRAY2_H
39 template <
class T>
class array2;
56 m_core_name(core_name), m_shape(
shape) {
89 if( m_core_name.empty()) {
90 m_core_name = shkz_default_array_core2;
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);
98 m_core = array_core2::quick_load_module(config,m_core_name);
102 m_core->recursive_configure(config);
105 virtual void post_initialize()
override {
145 m_core_name = array.m_core_name;
156 if(
this != &array ) {
168 if(
this != &array ) {
172 m_core->copy(*array.
get_core(),[&](
void *target,
const void *src){},m_parallel);
196 m_is_initialized =
true;
204 size_t count ()
const {
return m_core->count(m_parallel); }
212 std::vector<vec2i> result;
214 result.push_back(
vec2i(i,j));
227 for(
const auto &e : active_entries ) {
228 const vec2i &pi = e + offset;
229 if( !
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
245 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
259 array.const_serial_actives([&](
int i,
int j) {
261 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
277 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
302 if( ! this->
shape().out_of_bounds(pi) ) {
303 if( (*
this)(pi) && ! array(pi)) {
331 void set(
int i,
int j ) {
332 m_core->set(i,j,[&](
void *value_ptr,
bool &active){
359 return (*m_core)(i,j,filled) !=
nullptr;
370 return (*
this)(pi[0],pi[1]);
397 return (*
this)(pi[0],pi[1]);
408 m_core->set(i,j,[&](
void *value_ptr,
bool &active){
430 return ! (*
this == array);
442 bool differnt (
false);
503 iterator(
bool &_active ) : m_active(_active) {}
521 const bool &m_active;
524 enum { ACTIVES =
true, ALL =
false };
602 if(
type == ACTIVES ) {
603 m_core->parallel_actives([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled,
int thread_n ){
605 func(i,j,it,thread_n);
608 m_core->parallel_all([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled,
int thread_n ){
610 func(i,j,it,thread_n);
641 func(i,j); },ACTIVES); }
669 [&](
int i,
int j,
const const_iterator& it,
int thread_index) { func(i,j,thread_index); },ACTIVES); }
686 if(
type == ACTIVES ) {
687 m_core->const_parallel_actives([&](
int i,
int j,
const void *value_ptr,
const bool &filled,
int thread_n ){
690 func(i,j,it,thread_n);
693 m_core->const_parallel_all([&](
int i,
int j,
const void *value_ptr,
const bool &active,
const bool &filled,
int thread_n ){
695 func(i,j,it,thread_n);
749 if(
type == ACTIVES ) {
750 m_core->serial_actives([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled ){
756 m_core->serial_all([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled ){
807 if(
type == ACTIVES ) {
808 m_core->const_serial_actives([&](
int i,
int j,
const void *value_ptr,
const bool &filled ){
815 m_core->const_serial_all([&](
int i,
int j,
const void *value_ptr,
const bool &active,
const bool &filled ){
872 if(
type == ACTIVES ) {
873 m_core->serial_actives([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled ){
878 m_core->serial_all([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled ){
928 if(
type == ACTIVES ) {
929 m_core->const_serial_actives([&](
int i,
int j,
const void *value_ptr,
const bool &filled ){
935 m_core->const_serial_all([&](
int i,
int j,
const void *value_ptr,
const bool &active,
const bool &filled ){
951 m_core->dilate([&](
int i,
int j,
void *value_ptr,
bool &active,
const bool &filled,
int thread_index) {
953 func(i,j,it,thread_index);
987 void erode( std::function<
bool(
int i,
int j,
int thread_index)> func,
int count=1 ) {
993 bool exit_loop (
false);
994 for(
int dim : DIMS2 ) {
995 for(
int dir=-1; dir<=1; dir+=2 ) {
997 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
999 off_positions[tn].push_back(
vec2i(i,j));
1005 if( exit_loop )
break;
1008 for(
const auto &bucket : off_positions )
for(
const auto &pi : bucket ) {
1021 void erode( std::function<
bool(
int i,
int j)> func,
int count=1 ) {
1022 erode([&](
int i,
int j,
int thread_index) {
1033 erode([&](
int i,
int j,
int thread_index) {
return true; },
count);
1042 m_core.swap(rhs.m_core);
1043 std::swap(m_shape,rhs.m_shape);
1070 m_core_name = core_name;
1088 return m_core.get();
1097 return m_core.get();
1144 bool m_is_initialized {
false};
1146 std::string m_core_name;
bitarray2(recursive_configurable *parent, std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:68
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(const shape2 &shape, std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:84
shape2 shape
Shape of the grid.
Definition: bitarray2.h:1111
void clear()
Clear out the grid.
Definition: bitarray2.h:318
void parallel_all(std::function< void(int i, int j, iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitarray2.h:565
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitarray2.h:135
void interruptible_serial_actives(std::function< bool(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitarray2.h:828
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
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
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
void dilate(std::function< void(int i, int j, iterator &it)> func, int count=1)
Dilate cells.
Definition: bitarray2.h:965
virtual bool send_message(std::string message, void *ptr=nullptr)
Send a message.
Definition: messageable.h:48
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
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
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
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: bitarray2.h:470
void erode(std::function< bool(int i, int j, int thread_index)> func, int count=1)
Erode cells.
Definition: bitarray2.h:987
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
size_t count() const
Function to count the number of active cells.
Definition: bitarray2.h:204
void erode(int count=1)
Erode cells.
Definition: bitarray2.h:1032
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitarray2.h:531
bitarray2(std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:75
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
bitarray2(recursive_configurable *parent, const shape2 &shape, std::string core_name="")
Constructor for bitarray2.
Definition: bitarray2.h:55
void serial_all(std::function< void(iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray2.h:712
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
void set_off(int i, int j)
Set a position on grid inactive.
Definition: bitarray2.h:407
bool operator()() const
Get if a cell is active.
Definition: bitarray2.h:498
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
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
void parallel_all(std::function< void(iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitarray2.h:538
std::string core_name
Core name of the module.
Definition: bitarray2.h:1106
bitarray2(const bitarray2 &array)
Copy constructor for bitarray2.
Definition: bitarray2.h:144
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
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
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
type2 type() const
Get the type of this grid.
Definition: bitarray2.h:1128
bool operator()(const vec2i &pi) const
Get if a position on grid is active.
Definition: bitarray2.h:369
void set(const vec2i &pi)
Set bit on grid.
Definition: bitarray2.h:344
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
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
void parallel_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitarray2.h:547
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
void erode(std::function< bool(int i, int j)> func, int count=1)
Erode cells.
Definition: bitarray2.h:1021
int get_thread_num() const
Get the number of maximal threads set.
Definition: parallel_driver.h:80
unsigned h
Height of the shape.
Definition: shape.h:466
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
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
void dilate(std::function< void(int i, int j, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: bitarray2.h:949
virtual bool const_send_message(std::string message, void *ptr=nullptr) const
Send a message.
Definition: messageable.h:59
const array_core2 * get_core() const
Get pointer to the core module.
Definition: bitarray2.h:1087
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
void set_type(const type2 &type)
Set the type of this grid.
Definition: bitarray2.h:1135
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
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
unsigned w
Width of the shape.
Definition: shape.h:461
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
Read-only iterator.
Definition: bitarray2.h:508
bitarray2 & operator=(const bitarray2 &array)
Deep copy operation for bitarray2.
Definition: bitarray2.h:155
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
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
void swap(bitarray2 &rhs)
Swap array.
Definition: bitarray2.h:1041
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
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
void set_thread_num(int maximal_threads)
Set the number of maximal threads set.
Definition: parallel_driver.h:89
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
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
void serial_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitarray2.h:721
void set()
Set a value.
Definition: bitarray2.h:484
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
Core module class for two dimensional array designed to be used in array2 class.
Definition: array_core2.h:38
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
void copy(const bitarray2 &array)
Deep copy function for bitarray2.
Definition: bitarray2.h:167
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
Collection of properties of this grid.
Definition: bitarray2.h:1101
Writable iterator.
Definition: bitarray2.h:475
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: bitarray2.h:122
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
void dilate(int count=1)
Dilate cells.
Definition: bitarray2.h:976
void serial_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitarray2.h:705
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: bitarray2.h:461
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
std::vector< vec2i > actives() const
Function to return the list of active cells positions.
Definition: bitarray2.h:211
bool operator()() const
Get if a cell is active.
Definition: bitarray2.h:515
Fixed sized vector structure.
Definition: vec.h:38
shape2 shape() const
Get the shape of the array.
Definition: bitarray2.h:185
std::string get_core_name() const
Get the core name of module of this grid.
Definition: bitarray2.h:1078
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
const parallel_driver & get_parallel_driver() const
Get the const instance of parallel_driver of this grid.
Definition: bitarray2.h:1060
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
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
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
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitarray2.h:1069
void activate_all()
Activate all the cells.
Definition: bitarray2.h:286
Class that controls the settings of the program.
Definition: configuration.h:39
bool operator!=(const bitarray2 &array) const
Return if the grid is different from an input array.
Definition: bitarray2.h:429
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
Structure that defines shape such as width, height.
Definition: shape.h:42
bool operator()(int i, int j) const
Get if a position on grid is active.
Definition: bitarray2.h:357
Message class.
Definition: messageable.h:36
void interruptible_serial_op(std::function< bool(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitarray2.h:844
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
void interruptible_serial_all(std::function< bool(iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray2.h:835
bool operator==(const type2 &type) const
Check equality.
Definition: bitarray2.h:1118
void set_off(const vec2i &pi)
Set a position on grid inactive.
Definition: bitarray2.h:418
void set_off()
Inactivate a cell.
Definition: bitarray2.h:491
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
parallel_driver & get_parallel_driver()
Get the instance of parallel_driver of this grid.
Definition: bitarray2.h:1051
bool operator==(const bitarray2 &v) const
Return if the grid is same to an input array.
Definition: bitarray2.h:440
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
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
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
void set(int i, int j)
Set bit on grid.
Definition: bitarray2.h:331
array_core2 * get_core()
Get pointer to the core module.
Definition: bitarray2.h:1096
void initialize(const shape2 &shape)
Allocate grid memory with value.
Definition: bitarray2.h:192
Two dimensional bit grid class designed to be defined as instance member in recursive_configurable cl...
Definition: bitarray2.h:43