 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_BITMACARRAY3_H
26 #define SHKZ_BITMACARRAY3_H
49 bitmacarray3 (
recursive_configurable *parent,
const shape3 &
shape, std::string core_name=
"") : m_shape(
shape), m_array_0(this,
shape.face(0),core_name), m_array_1(this,
shape.face(1),core_name), m_array_2(this,
shape.face(2),core_name) {
97 virtual bool send_message( std::string message,
void *ptr )
override {
100 if( m_array_1.
send_message(message,ptr)) handled =
true;
101 if( m_array_2.
send_message(message,ptr)) handled =
true;
115 bool handled (
false);
138 if(
this != &array ) {
140 for(
int dim : DIMS3 ) (*this)[dim].copy(array[dim]);
153 for(
int dim : DIMS3 ) (*this)[dim].initialize(
shape.
face(dim));
163 for(
int dim : DIMS3 ) sum += (*this)[dim].count();
172 std::array<std::vector<vec3i>,DIM3>
actives()
const {
173 std::array<std::vector<vec3i>,DIM3> result;
174 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
175 result[dim] = (*this)[dim].actives();
187 void activate(
const std::array<std::vector<vec3i>,DIM3> &active_entries,
const std::array<vec3i,DIM3> &offsets={
vec3i(),
vec3i(),
vec3i()} ) {
188 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
189 (*this)[dim].activate(active_entries[dim],offsets[dim]);
201 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
202 (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
214 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
215 (*this)[dim].activate_as(array[dim],offsets[dim]);
223 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
224 (*this)[dim].activate_all();
236 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
237 (*this)[dim].copy_active_as(array[dim],offset);
263 for(
int dim : DIMS3 ) (*this)[dim].clear();
274 return ! (*
this == v);
285 for(
int dim : DIMS3 ) {
286 if ((*
this)[dim] != v[dim])
return false;
297 return dim==0 ? m_array_0 : (dim == 1 ? m_array_1 : m_array_2 );
306 return dim==0 ? m_array_0 : (dim == 1 ? m_array_1 : m_array_2 );
315 for(
int dim : DIMS3 ) (*this)[dim].set_thread_num(number);
327 enum { ACTIVES =
true, ALL =
false };
405 for(
int dim : DIMS3 ) {
406 (*this)[dim].parallel_op([&](
int i,
int j,
int k,
typename bitarray3::iterator& it,
int thread_index) {
407 func(dim,i,j,k,it,thread_index);
466 const_parallel_op([&](
int dim,
int i,
int j,
int k,
const typename bitarray3::const_iterator& it,
int thread_index){ func(dim,i,j,k,thread_index); }, ACTIVES); }
483 for(
int dim : DIMS3 ) {
484 (*this)[dim].const_parallel_op([&](
int i,
int j,
int k,
const typename bitarray3::const_iterator& it,
int thread_index) {
485 func(dim,i,j,k,it,thread_index);
539 for(
int dim : DIMS3 ) {
589 for(
int dim : DIMS3 ) {
645 for(
int dim : DIMS3 ) {
695 for(
int dim : DIMS3 ) {
711 m_parallel.
for_each(DIM3,[&](
size_t dim ) {
713 func(dim,i,j,k,it,thread_index);
748 void erode( std::function<
bool(
int dim,
int i,
int j,
int k,
int thread_index)> func,
int count=1 ) {
750 m_parallel.
for_each(DIM3,[&](
size_t dim ) {
752 return func(dim,i,j,k,thread_index);
765 void erode( std::function<
bool(
int dim,
int i,
int j,
int k)> func,
int count=1 ) {
766 erode([&](
int dim,
int i,
int j,
int k,
int thread_index) {
767 return func(dim,i,j,k);
777 return erode([&](
int dim,
int i,
int j,
int k){
return true; },
count);
void parallel_actives(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it, int thread_index)> func)
Loop over all the active cells in parallel.
Definition: bitmacarray3.h:388
void clear()
Clear out the grid.
Definition: bitmacarray3.h:262
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 const_serial_all(std::function< void(const typename bitarray3::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray3.h:551
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: bitmacarray3.h:314
void const_parallel_op(std::function< void(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it, int thread_index)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: bitmacarray3.h:482
void erode(std::function< bool(int i, int j, int k, int thread_index)> func, int count=1)
Erode cells.
Definition: bitarray3.h:985
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
void const_parallel_actives(std::function< void(int dim, int i, int j, int k, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitmacarray3.h:465
size_t count() const
Function to count the number of active cells.
Definition: bitmacarray3.h:161
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: bitmacarray3.h:323
const bitarray3 & operator[](int dim) const
Get the read-only reference to the staggered array of a specified dimension.
Definition: bitmacarray3.h:296
void parallel_actives(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitmacarray3.h:361
void const_parallel_op(std::function< void(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: bitmacarray3.h:454
void interruptible_serial_op(std::function< bool(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray3.h:644
bitmacarray3(const shape3 &shape, std::string core_name="")
Constructor for bitmacarray3.
Definition: bitmacarray3.h:77
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitmacarray3.h:785
bitarray3::type3 type2
Type for z dimensional grid.
Definition: bitmacarray3.h:826
void interruptible_serial_actives(std::function< bool(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray3.h:628
bitmacarray3(const bitmacarray3 &v)
Copy constructor for bitmacarray3.
Definition: bitmacarray3.h:84
bool operator!=(const bitmacarray3 &v) const
Return if the grid is different from an input array.
Definition: bitmacarray3.h:273
Three dimensional bit grid class designed to be defined as instance member in recursive_configurable ...
Definition: bitarray3.h:43
void erode(int count=1)
Erode cells.
Definition: bitmacarray3.h:776
void serial_all(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray3.h:529
shape3 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:707
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: bitarray3.h:470
void interruptible_const_serial_all(std::function< bool(const typename bitarray3::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray3.h:657
std::string get_core_name() const
Get the core name of module of this grid.
Definition: bitmacarray3.h:796
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
Writable iterator.
Definition: bitarray3.h:475
bitmacarray3(std::string core_name="")
Constructor for bitmacarray3.
Definition: bitmacarray3.h:68
bitarray3::type3 type0
Type for x dimensional grid.
Definition: bitmacarray3.h:816
void interruptible_const_serial_op(std::function< bool(const typename bitarray3::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: bitmacarray3.h:666
void parallel_actives(std::function< void(typename bitarray3::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitmacarray3.h:334
std::array< std::vector< vec3i >, DIM3 > actives() const
Function to return the list of active cells positions.
Definition: bitmacarray3.h:172
void parallel_all(std::function< void(typename bitarray3::iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitmacarray3.h:341
void serial_actives(std::function< void(typename bitarray3::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray3.h:495
void const_parallel_all(std::function< void(const typename bitarray3::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: bitmacarray3.h:417
void parallel_op(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitmacarray3.h:377
void set()
Set a value.
Definition: bitarray3.h:484
shape3 shape(int dim) const
Get the shape of the staggered grid of a specified dimension.
Definition: bitmacarray3.h:253
Read-only iterator.
Definition: bitarray3.h:507
void dilate(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func, int count=1)
Dilate cells.
Definition: bitmacarray3.h:726
void const_parallel_all(std::function< void(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: bitmacarray3.h:445
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
void parallel_all(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it, int thread_index)> func)
Loop over all the cells in parallel.
Definition: bitmacarray3.h:395
void const_parallel_actives(std::function< void(int dim, int i, int j, int k)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitmacarray3.h:437
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: bitarray3.h:122
void interruptible_serial_all(std::function< bool(typename bitarray3::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray3.h:608
void copy_active_as(const bitmacarray3 &array, const vec3i &offset=vec3i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: bitmacarray3.h:235
void activate_as(const Y &array, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i(), vec3i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: bitmacarray3.h:213
void parallel_op(std::function< void(typename bitarray3::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitmacarray3.h:350
void activate_as_bit(const bitmacarray3 &array, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i(), vec3i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: bitmacarray3.h:200
void interruptible_const_serial_all(std::function< bool(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray3.h:685
void set_type(const type3 &type)
Set the type of this grid.
Definition: bitarray3.h:1135
bitmacarray3(recursive_configurable *parent, std::string core_name="")
Constructor for bitmacarray3.
Definition: bitmacarray3.h:61
type3 type() const
Get the type of this grid.
Definition: bitarray3.h:1128
void const_parallel_op(std::function< void(const typename bitarray3::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: bitmacarray3.h:426
bitarray3::type3 type1
Type for y dimensional grid.
Definition: bitmacarray3.h:821
void const_serial_all(std::function< void(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray3.h:579
void const_serial_actives(std::function< void(int dim, int i, int j, int k)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitmacarray3.h:571
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitmacarray3.h:114
void dilate(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: bitmacarray3.h:709
bitarray3 & operator[](int dim)
Get the reference to the staggered array of a specified dimension.
Definition: bitmacarray3.h:305
bool operator==(const type3 &type) const
Check equality.
Definition: bitmacarray3.h:833
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitarray3.h:1069
void erode(std::function< bool(int dim, int i, int j, int k)> func, int count=1)
Erode cells.
Definition: bitmacarray3.h:765
void activate_all()
Activate all the cells.
Definition: bitmacarray3.h:222
void const_serial_op(std::function< void(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: bitmacarray3.h:588
Collection of properties of this grid.
Definition: bitarray3.h:1101
void initialize(const shape3 &shape)
Allocate grid memory with value.
Definition: bitmacarray3.h:151
void interruptible_const_serial_op(std::function< bool(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: bitmacarray3.h:694
void interruptible_serial_actives(std::function< bool(typename bitarray3::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray3.h:601
void serial_all(std::function< void(typename bitarray3::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray3.h:502
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
void const_serial_op(std::function< void(const typename bitarray3::const_iterator &it)> func, bool type=ALL) const
Loop over the cells in serial order by read-only fashion.
Definition: bitmacarray3.h:560
Fixed sized vector structure.
Definition: vec.h:38
void set_type(const type3 &type)
Set the type of this grid.
Definition: bitmacarray3.h:854
type3 type() const
Get the type of this grid.
Definition: bitmacarray3.h:845
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: bitmacarray3.h:97
bool operator==(const bitmacarray3 &v) const
Return if the grid is same to an input array.
Definition: bitmacarray3.h:284
void copy(const bitmacarray3 &array)
Deep copy function for bitmacarray3.
Definition: bitmacarray3.h:137
void const_parallel_all(std::function< void(int dim, int i, int j, int k, const typename bitarray3::const_iterator &it, int thread_index)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: bitmacarray3.h:473
Message class.
Definition: messageable.h:36
void erode(std::function< bool(int dim, int i, int j, int k, int thread_index)> func, int count=1)
Erode cells.
Definition: bitmacarray3.h:748
void interruptible_const_serial_actives(std::function< bool(int dim, int i, int j, int k)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitmacarray3.h:677
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
void interruptible_serial_op(std::function< bool(typename bitarray3::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray3.h:617
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitarray3.h:135
void parallel_op(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it, int thread_index)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitmacarray3.h:404
bitmacarray3 & operator=(const bitmacarray3 &array)
Deep copy operation for bitmacarray3.
Definition: bitmacarray3.h:127
void serial_op(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray3.h:538
void dilate(int count=1)
Dilate cells.
Definition: bitmacarray3.h:737
void parallel_all(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitmacarray3.h:368
shape3 shape
Shape of the grid.
Definition: bitmacarray3.h:811
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
Three dimensional staggered bit grid class designed to be defined as instance member in recursive_con...
Definition: bitmacarray3.h:37
void activate(const std::array< std::vector< vec3i >, DIM3 > &active_entries, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i(), vec3i()})
Activate cells at the positons of active_entries.
Definition: bitmacarray3.h:187
void serial_op(std::function< void(typename bitarray3::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray3.h:511
bitmacarray3(recursive_configurable *parent, const shape3 &shape, std::string core_name="")
Constructor for bitmacarray3.
Definition: bitmacarray3.h:49
shape3 shape() const
Get the shape of the array.
Definition: bitmacarray3.h:246
void interruptible_serial_all(std::function< bool(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray3.h:635
void for_each(size_t size, std::function< void(size_t n, int thread_index)> func) const
Perform a parallel loop operation.
Definition: parallel_driver.h:141
Collection of properties of this grid.
Definition: bitmacarray3.h:801
void serial_actives(std::function< void(int dim, int i, int j, int k, typename bitarray3::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray3.h:522
std::string core_name
Core name of the module.
Definition: bitmacarray3.h:806