 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_BITARRAY3_H
26 #define SHKZ_BITARRAY3_H
39 template <
class T>
class array3;
56 m_core_name(core_name), m_shape(
shape) {
89 if( m_core_name.empty()) {
90 m_core_name = shkz_default_array_core3;
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_core3);
98 m_core = array_core3::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); }
205 std::vector<vec3i> actives()
const {
206 std::vector<vec3i> result;
208 result.push_back(
vec3i(i,j,k));
221 for(
const auto &e : active_entries ) {
222 const vec3i &pi = e + offset;
223 if( !
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
239 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
253 array.const_serial_actives([&](
int i,
int j,
int k) {
255 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
271 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
296 if( ! this->
shape().out_of_bounds(pi) ) {
297 if( (*
this)(pi) && ! array(pi)) {
327 void set(
int i,
int j,
int k ) {
328 m_core->set(i,j,k,[&](
void *value_ptr,
bool &active){
339 set(pi[0],pi[1],pi[2]);
355 return (*m_core)(i,j,k,filled) !=
nullptr;
366 return (*
this)(pi[0],pi[1],pi[2]);
382 return (*
this)(i,j,k);
395 return (*
this)(pi[0],pi[1],pi[2]);
408 m_core->set(i,j,k,[&](
void *value_ptr,
bool &active){
430 return ! (*
this == array);
442 bool differnt (
false);
502 iterator(
bool &_active ) : m_active(_active) {}
519 const bool &m_active;
522 enum { ACTIVES =
true, ALL =
false };
600 if(
type == ACTIVES ) {
601 m_core->parallel_actives([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled,
int thread_n ){
603 func(i,j,k,it,thread_n);
606 m_core->parallel_all([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled,
int thread_n ){
608 func(i,j,k,it,thread_n);
684 if(
type == ACTIVES ) {
685 m_core->const_parallel_actives([&](
int i,
int j,
int k,
const void *value_ptr,
const bool &filled,
int thread_n ){
688 func(i,j,k,it,thread_n);
691 m_core->const_parallel_all([&](
int i,
int j,
int k,
const void *value_ptr,
const bool &active,
const bool &filled,
int thread_n ){
693 func(i,j,k,it,thread_n);
747 if(
type == ACTIVES ) {
748 m_core->serial_actives([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled ){
754 m_core->serial_all([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled ){
805 if(
type == ACTIVES ) {
806 m_core->const_serial_actives([&](
int i,
int j,
int k,
const void *value_ptr,
const bool &filled ){
813 m_core->const_serial_all([&](
int i,
int j,
int k,
const void *value_ptr,
const bool &active,
const bool &filled ){
870 if(
type == ACTIVES ) {
871 m_core->serial_actives([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled ){
873 return func(i,j,k,it);
876 m_core->serial_all([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled ){
878 return func(i,j,k,it);
926 if(
type == ACTIVES ) {
927 m_core->const_serial_actives([&](
int i,
int j,
int k,
const void *value_ptr,
const bool &filled ){
930 return func(i,j,k,it);
933 m_core->const_serial_all([&](
int i,
int j,
int k,
const void *value_ptr,
const bool &active,
const bool &filled ){
935 return func(i,j,k,it);
947 void dilate( std::function<
void(
int i,
int j,
int k,
iterator& it,
int thread_index )> func,
int count=1 ) {
949 m_core->dilate([&](
int i,
int j,
int k,
void *value_ptr,
bool &active,
const bool &filled,
int thread_index) {
951 func(i,j,k,it,thread_index);
985 void erode( std::function<
bool(
int i,
int j,
int k,
int thread_index)> func,
int count=1 ) {
991 bool exit_loop (
false);
992 for(
int dim : DIMS3 ) {
993 for(
int dir=-1; dir<=1; dir+=2 ) {
995 if( ! this->
shape().out_of_bounds(pi) && ! (*
this)(pi)) {
996 if( func(i,j,k,tn)) {
997 off_positions[tn].push_back(
vec3i(i,j,k));
1003 if( exit_loop )
break;
1006 for(
const auto &bucket : off_positions )
for(
const auto &pi : bucket ) {
1019 void erode( std::function<
bool(
int i,
int j,
int k)> func,
int count=1 ) {
1020 erode([&](
int i,
int j,
int k,
int thread_index) {
1031 erode([&](
int i,
int j,
int k,
int thread_index) {
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();
1145 bool m_is_initialized {
false};
1146 std::string m_core_name;
void dilate(std::function< void(int i, int j, int k, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: bitarray3.h:947
void set_off(int i, int j, int k)
Set a position on grid inactive.
Definition: bitarray3.h:407
void set_off()
Inactivate a cell.
Definition: bitarray3.h:491
unsigned w
Width of the shape.
Definition: shape.h:942
bool operator()(int i, int j, int k) const
Get if a position on grid is active.
Definition: bitarray3.h:353
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitarray3.h:529
void initialize(const shape3 &shape)
Allocate grid memory with value.
Definition: bitarray3.h:192
void erode(std::function< bool(int i, int j, int k, int thread_index)> func, int count=1)
Erode cells.
Definition: bitarray3.h:985
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
void dilate(std::function< void(int i, int j, int k, iterator &it)> func, int count=1)
Dilate cells.
Definition: bitarray3.h:963
void copy_active_as(const bitarray3 &array, const vec3i &offset=vec3i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: bitarray3.h:293
virtual bool send_message(std::string message, void *ptr=nullptr)
Send a message.
Definition: messageable.h:48
void set_off(const vec3i &pi)
Set a position on grid inactive.
Definition: bitarray3.h:418
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
Core module class for three dimensional array designed to be used in array3 class.
Definition: array_core3.h:38
void parallel_all(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitarray3.h:563
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: bitarray3.h:776
array_core3 * get_core()
Get pointer to the core module.
Definition: bitarray3.h:1096
void clear()
Clear out the grid.
Definition: bitarray3.h:312
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
void const_serial_actives(std::function< void(int i, int j, int k)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitarray3.h:787
parallel_driver & get_parallel_driver()
Get the instance of parallel_driver of this grid.
Definition: bitarray3.h:1051
void erode(int count=1)
Erode cells.
Definition: bitarray3.h:1030
Three dimensional bit grid class designed to be defined as instance member in recursive_configurable ...
Definition: bitarray3.h:43
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: bitarray3.h:618
unsigned h
Height of the shape.
Definition: shape.h:947
void parallel_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitarray3.h:545
bitarray3(recursive_configurable *parent, const shape3 &shape, std::string core_name="")
Constructor for bitarray3.
Definition: bitarray3.h:55
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: bitarray3.h:236
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: bitarray3.h:590
void set(int i, int j, int k)
Set value on grid.
Definition: bitarray3.h:327
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: bitarray3.h:470
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: bitarray3.h:655
void parallel_all(std::function< void(iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitarray3.h:536
void set(const vec3i &pi)
Set value on grid.
Definition: bitarray3.h:338
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: bitarray3.h:767
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
Writable iterator.
Definition: bitarray3.h:475
void serial_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitarray3.h:703
bool safe_get(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: bitarray3.h:380
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: bitarray3.h:804
shape3 shape() const
Get the shape of the array.
Definition: bitarray3.h:185
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: bitarray3.h:599
unsigned d
Depth of the shape.
Definition: shape.h:952
bitarray3 & operator=(const bitarray3 &array)
Deep copy operation for bitarray3.
Definition: bitarray3.h:155
bool operator!=(const bitarray3 &array) const
Return if the grid is different from an input array.
Definition: bitarray3.h:429
bool operator()(const vec3i &pi) const
Get if a position on grid is active.
Definition: bitarray3.h:365
void set()
Set a value.
Definition: bitarray3.h:484
int get_thread_num() const
Get the number of maximal threads set.
Definition: parallel_driver.h:80
bitarray3(const bitarray3 &array)
Copy constructor for bitarray3.
Definition: bitarray3.h:144
Read-only iterator.
Definition: bitarray3.h:507
virtual bool const_send_message(std::string message, void *ptr=nullptr) const
Send a message.
Definition: messageable.h:59
bool safe_get(const vec3i &pi) const
Get if a position on grid is active. pi can be safely out of the domain.
Definition: bitarray3.h:394
void interruptible_serial_op(std::function< bool(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitarray3.h:842
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
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
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: bitarray3.h:122
bitarray3(recursive_configurable *parent, std::string core_name="")
Constructor for bitarray3.
Definition: bitarray3.h:68
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: bitarray3.h:730
void set_type(const type3 &type)
Set the type of this grid.
Definition: bitarray3.h:1135
bool operator()() const
Get if a cell is active.
Definition: bitarray3.h:498
void interruptible_serial_all(std::function< bool(iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray3.h:833
type3 type() const
Get the type of this grid.
Definition: bitarray3.h:1128
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: bitarray3.h:916
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: bitarray3.h:646
void set_thread_num(int maximal_threads)
Set the number of maximal threads set.
Definition: parallel_driver.h:89
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: bitarray3.h:627
std::string core_name
Core name of the module.
Definition: bitarray3.h:1106
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitarray3.h:1069
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: bitarray3.h:683
void activate_all()
Activate all the cells.
Definition: bitarray3.h:280
void serial_op(std::function< void(iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitarray3.h:719
Collection of properties of this grid.
Definition: bitarray3.h:1101
void dilate(int count=1)
Dilate cells.
Definition: bitarray3.h:974
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: bitarray3.h:268
void activate(const std::vector< vec3i > &active_entries, const vec3i &offset=vec3i())
Activate cells at the positons of active_entries with an offset.
Definition: bitarray3.h:220
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: bitarray3.h:583
const array_core3 * get_core() const
Get pointer to the core module.
Definition: bitarray3.h:1087
void const_parallel_actives(std::function< void(int i, int j, int k)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitarray3.h:638
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
std::string get_core_name() const
Get the core name of module of this grid.
Definition: bitarray3.h:1078
const parallel_driver & get_parallel_driver() const
Get the const instance of parallel_driver of this grid.
Definition: bitarray3.h:1060
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: bitarray3.h:925
bool operator==(const type3 &type) const
Check equality.
Definition: bitarray3.h:1118
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: bitarray3.h:860
Fixed sized vector structure.
Definition: vec.h:38
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: bitarray3.h:461
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: bitarray3.h:853
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: bitarray3.h:888
bool operator()() const
Get if a cell is active.
Definition: bitarray3.h:514
bitarray3(const shape3 &shape, std::string core_name="")
Constructor for bitarray3.
Definition: bitarray3.h:84
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: bitarray3.h:252
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: bitarray3.h:795
void interruptible_serial_actives(std::function< bool(iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitarray3.h:826
void parallel_actives(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitarray3.h:556
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: bitarray3.h:869
Class that controls the settings of the program.
Definition: configuration.h:39
Message class.
Definition: messageable.h:36
void interruptible_const_serial_actives(std::function< bool(int i, int j, int k)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitarray3.h:908
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
void parallel_op(std::function< void(int i, int j, int k, iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitarray3.h:572
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitarray3.h:135
void erode(std::function< bool(int i, int j, int k)> func, int count=1)
Erode cells.
Definition: bitarray3.h:1019
void serial_all(std::function< void(iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray3.h:710
shape3 shape
Shape of the grid.
Definition: bitarray3.h:1111
bool operator==(const bitarray3 &v) const
Return if the grid is same to an input array.
Definition: bitarray3.h:440
void swap(bitarray3 &rhs)
Swap array.
Definition: bitarray3.h:1041
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: bitarray3.h:897
void serial_all(std::function< void(int i, int j, int k, iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitarray3.h:737
void const_parallel_actives(std::function< void(int i, int j, int k, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitarray3.h:666
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: bitarray3.h:674
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
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: bitarray3.h:746
size_t count() const
Function to count the number of active cells.
Definition: bitarray3.h:204
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
void copy(const bitarray3 &array)
Deep copy function for bitarray3.
Definition: bitarray3.h:167
bitarray3(std::string core_name="")
Constructor for bitarray3.
Definition: bitarray3.h:75
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42