 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_BITMACARRAY2_H
26 #define SHKZ_BITMACARRAY2_H
97 virtual bool send_message( std::string message,
void *ptr )
override {
114 bool handled (
false);
136 if(
this != &array ) {
138 for(
int dim : DIMS2 ) (*this)[dim].copy(array[dim]);
151 for(
int dim : DIMS2 )(*this)[dim].initialize(
shape.
face(dim));
161 for(
int dim : DIMS2 ) sum += (*this)[dim].count();
170 std::array<std::vector<vec2i>,DIM2>
actives()
const {
171 std::array<std::vector<vec2i>,DIM2> result;
172 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
173 result[dim] = (*this)[dim].actives();
185 void activate(
const std::array<std::vector<vec2i>,DIM2> &active_entries,
const std::array<vec2i,DIM2> &offsets={
vec2i(),
vec2i()} ) {
186 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
187 (*this)[dim].activate(active_entries[dim],offsets[dim]);
199 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
200 (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
212 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
213 (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
221 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
222 (*this)[dim].activate_all();
234 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
235 (*this)[dim].copy_active_as(array[dim],offset);
261 for(
int dim : DIMS2 )(*this)[dim].clear();
272 return ! (*
this == v);
283 for(
int dim : DIMS2 ) {
284 if((*
this)[dim] != v[dim])
return false;
295 return dim==0 ? m_array_0 : m_array_1;
304 return dim==0 ? m_array_0 : m_array_1;
313 for(
int dim : DIMS2 ) (*this)[dim].set_thread_num(number);
325 enum { ACTIVES =
true, ALL =
false };
403 for(
int dim : DIMS2 ) {
404 (*this)[dim].parallel_op([&](
int i,
int j,
typename bitarray2::iterator& it,
int thread_index) {
405 func(dim,i,j,it,thread_index);
463 inline void const_parallel_actives( std::function<
void(
int dim,
int i,
int j,
int thread_index)> func )
const {
const_parallel_op([&](
int dim,
int i,
int j,
const typename bitarray2::const_iterator& it,
int thread_index) { func(dim,i,j,thread_index); }, ACTIVES); }
480 for(
int dim : DIMS2 ) {
482 func(dim,i,j,it,thread_index);
536 for(
int dim : DIMS2 ) {
586 for(
int dim : DIMS2 ) {
642 for(
int dim : DIMS2 ) {
692 for(
int dim : DIMS2 ) {
708 m_parallel.
for_each(DIM2,[&](
size_t dim ) {
710 func(dim,i,j,it,thread_index);
745 void erode( std::function<
bool(
int dim,
int i,
int j,
int thread_index)> func,
int count=1 ) {
747 m_parallel.
for_each(DIM2,[&](
size_t dim ) {
749 return func(dim,i,j,thread_index);
762 void erode( std::function<
bool(
int dim,
int i,
int j)> func,
int count=1 ) {
763 erode([&](
int dim,
int i,
int j,
int thread_index) {
764 return func(dim,i,j);
774 return erode([&](
int dim,
int i,
int j){
return true; },
count);
void serial_all(std::function< void(typename bitarray2::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray2.h:499
void interruptible_serial_actives(std::function< bool(typename bitarray2::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray2.h:598
void clear()
Clear out the grid.
Definition: bitmacarray2.h:260
void activate_all()
Activate all the cells.
Definition: bitmacarray2.h:220
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitarray2.h:135
std::string core_name
Core name of the module.
Definition: bitmacarray2.h:802
void interruptible_const_serial_actives(std::function< bool(int dim, int i, int j)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitmacarray2.h:674
void const_serial_actives(std::function< void(int dim, int i, int j)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: bitmacarray2.h:568
bool operator!=(const bitmacarray2 &v) const
Return if the grid is different from an input array.
Definition: bitmacarray2.h:271
std::string get_core_name() const
Get the core name of module of this grid.
Definition: bitmacarray2.h:792
void const_parallel_actives(std::function< void(int dim, int i, int j, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitmacarray2.h:463
void serial_actives(std::function< void(typename bitarray2::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray2.h:492
void dilate(int count=1)
Dilate cells.
Definition: bitmacarray2.h:734
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 set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitmacarray2.h:782
Two dimensional staggered bit grid class designed to be defined as instance member in recursive_confi...
Definition: bitmacarray2.h:37
void parallel_actives(std::function< void(typename bitarray2::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitmacarray2.h:332
shape2 shape(int dim) const
Get the shape of the staggered grid of a specified dimension.
Definition: bitmacarray2.h:251
void activate_as_bit(const bitmacarray2 &array, const std::array< vec2i, DIM2 > &offsets={vec2i(), vec2i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: bitmacarray2.h:198
void erode(std::function< bool(int i, int j, int thread_index)> func, int count=1)
Erode cells.
Definition: bitarray2.h:987
Collection of properties of this grid.
Definition: bitmacarray2.h:797
void parallel_op(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitmacarray2.h:375
bitmacarray2(recursive_configurable *parent, const shape2 &shape, std::string core_name="")
Constructor for bitmacarray2.
Definition: bitmacarray2.h:49
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: bitmacarray2.h:312
void const_serial_all(std::function< void(int dim, int i, int j, const typename bitarray2::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray2.h:576
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: bitmacarray2.h:321
void erode(std::function< bool(int dim, int i, int j, int thread_index)> func, int count=1)
Erode cells.
Definition: bitmacarray2.h:745
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
void activate(const std::array< std::vector< vec2i >, DIM2 > &active_entries, const std::array< vec2i, DIM2 > &offsets={vec2i(), vec2i()})
Activate cells at the positons of active_entries.
Definition: bitmacarray2.h:185
void serial_actives(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray2.h:519
void const_parallel_all(std::function< void(int dim, int i, int j, const typename bitarray2::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: bitmacarray2.h:443
void initialize(const shape2 &shape)
Allocate grid memory with value.
Definition: bitmacarray2.h:149
bitmacarray2(recursive_configurable *parent, std::string core_name="")
Constructor for bitmacarray2.
Definition: bitmacarray2.h:61
void parallel_op(std::function< void(typename bitarray2::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitmacarray2.h:348
size_t count() const
Function to count the number of active cells.
Definition: bitmacarray2.h:159
const bitarray2 & operator[](int dim) const
Get the read-only reference to the staggered array of a specified dimension.
Definition: bitmacarray2.h:294
void parallel_op(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it, int thread_index)> func, bool type=ALL)
Loop over cells in parallel.
Definition: bitmacarray2.h:402
void interruptible_serial_actives(std::function< bool(int dim, int i, int j, typename bitarray2::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: bitmacarray2.h:625
void erode(std::function< bool(int dim, int i, int j)> func, int count=1)
Erode cells.
Definition: bitmacarray2.h:762
void serial_all(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray2.h:526
void parallel_actives(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it, int thread_index)> func)
Loop over all the active cells in parallel.
Definition: bitmacarray2.h:386
type2 type() const
Get the type of this grid.
Definition: bitarray2.h:1128
void interruptible_const_serial_op(std::function< bool(int dim, int i, int j, const typename bitarray2::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: bitmacarray2.h:691
void const_parallel_op(std::function< void(int dim, int i, int j, const typename bitarray2::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: bitmacarray2.h:452
void const_serial_all(std::function< void(const typename bitarray2::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray2.h:548
std::array< std::vector< vec2i >, DIM2 > actives() const
Function to return the list of active cells positions.
Definition: bitmacarray2.h:170
void dilate(std::function< void(int i, int j, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: bitarray2.h:949
void copy_active_as(const bitmacarray2 &array, const vec2i &offset=vec2i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: bitmacarray2.h:233
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
bitmacarray2(const shape2 &shape, std::string core_name="")
Constructor for bitmacarray2.
Definition: bitmacarray2.h:77
void const_parallel_all(std::function< void(const typename bitarray2::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: bitmacarray2.h:415
void interruptible_serial_all(std::function< bool(typename bitarray2::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray2.h:605
void interruptible_serial_op(std::function< bool(typename bitarray2::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray2.h:614
shape2 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:257
Read-only iterator.
Definition: bitarray2.h:508
void serial_op(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray2.h:535
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: bitmacarray2.h:97
void const_parallel_actives(std::function< void(int dim, int i, int j)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: bitmacarray2.h:435
void set()
Set a value.
Definition: bitarray2.h:484
bool operator==(const bitmacarray2 &v) const
Return if the grid is same to an input array.
Definition: bitmacarray2.h:282
bitarray2::type2 type1
Type for y dimensional grid.
Definition: bitmacarray2.h:817
void interruptible_const_serial_op(std::function< bool(const typename bitarray2::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: bitmacarray2.h:663
shape2 shape
Shape of the grid.
Definition: bitmacarray2.h:807
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: bitmacarray2.h:113
bitmacarray2 & operator=(const bitmacarray2 &array)
Deep copy operation for bitmacarray2.
Definition: bitmacarray2.h:125
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 parallel_all(std::function< void(typename bitarray2::iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitmacarray2.h:339
void const_parallel_op(std::function< void(const typename bitarray2::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: bitmacarray2.h:424
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
bitmacarray2(std::string core_name="")
Constructor for bitmacarray2.
Definition: bitmacarray2.h:68
void erode(int count=1)
Erode cells.
Definition: bitmacarray2.h:773
Fixed sized vector structure.
Definition: vec.h:38
std::string get_core_name() const
Get the core name of module of this grid.
Definition: bitarray2.h:1078
bitarray2 & operator[](int dim)
Get the reference to the staggered array of a specified dimension.
Definition: bitmacarray2.h:303
void parallel_actives(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: bitmacarray2.h:359
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: bitarray2.h:1069
void interruptible_const_serial_all(std::function< bool(int dim, int i, int j, const typename bitarray2::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray2.h:682
Structure that defines shape such as width, height.
Definition: shape.h:42
void dilate(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: bitmacarray2.h:706
Message class.
Definition: messageable.h:36
void copy(const bitmacarray2 &array)
Deep copy function for bitmacarray2.
Definition: bitmacarray2.h:135
void dilate(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func, int count=1)
Dilate cells.
Definition: bitmacarray2.h:723
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
bitmacarray2(const bitmacarray2 &v)
Copy constructor for bitmacarray2.
Definition: bitmacarray2.h:84
void const_serial_op(std::function< void(const typename bitarray2::const_iterator &it)> func, bool type=ALL) const
Loop over the cells in serial order by read-only fashion.
Definition: bitmacarray2.h:557
bool operator==(const type2 &type) const
Check equality.
Definition: bitmacarray2.h:824
void interruptible_serial_op(std::function< bool(int dim, int i, int j, typename bitarray2::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray2.h:641
void parallel_all(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it, int thread_index)> func)
Loop over all the cells in parallel.
Definition: bitmacarray2.h:393
shape2 shape() const
Get the shape of the array.
Definition: bitmacarray2.h:244
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
void const_serial_op(std::function< void(int dim, int i, int j, const typename bitarray2::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: bitmacarray2.h:585
void interruptible_const_serial_all(std::function< bool(const typename bitarray2::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: bitmacarray2.h:654
type2 type() const
Get the type of this grid.
Definition: bitmacarray2.h:836
void parallel_all(std::function< void(int dim, int i, int j, typename bitarray2::iterator &it)> func)
Loop over all the cells in parallel.
Definition: bitmacarray2.h:366
void const_parallel_all(std::function< void(int dim, int i, int j, const typename bitarray2::const_iterator &it, int thread_index)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: bitmacarray2.h:470
void set_type(const type2 &type)
Set the type of this grid.
Definition: bitmacarray2.h:845
void activate_as(const Y &array, const std::array< vec2i, DIM2 > &offsets={vec2i(), vec2i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: bitmacarray2.h:211
bitarray2::type2 type0
Type for x dimensional grid.
Definition: bitmacarray2.h:812
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
void interruptible_serial_all(std::function< bool(int dim, int i, int j, typename bitarray2::iterator &it)> func)
Loop over all the cells in serial order.
Definition: bitmacarray2.h:632
void const_parallel_op(std::function< void(int dim, int i, int j, const typename bitarray2::const_iterator &it, int thread_index)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: bitmacarray2.h:479
void serial_op(std::function< void(typename bitarray2::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: bitmacarray2.h:508
Two dimensional bit grid class designed to be defined as instance member in recursive_configurable cl...
Definition: bitarray2.h:43