Shiokaze Framework
A research-oriented fluid solver for computer graphics
array_extrapolator3.h
Go to the documentation of this file.
1 /*
2 ** array_extrapolator3.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 Feb 14, 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_ARRAY_EXTRAPOLATOR3_H
26 #define SHKZ_ARRAY_EXTRAPOLATOR3_H
27 //
28 #include "array3.h"
29 #include "shared_array3.h"
30 //
32 //
34 namespace array_extrapolator3 {
47  template<class T> unsigned extrapolate_if ( array3<T> &array, std::function<bool(int i, int j, int k, int thread_index )> func, int count=1 ) {
48  //
49  std::vector<unsigned> counters(array.get_thread_num());
50  const shape3 shape(array.shape());
51  //
52  array.dilate([&](int i, int j, int k, auto &it, int tn ) {
53  if( func(i,j,k,tn)) {
54  T sum (0.0);
55  int weight = 0;
56  vec3i query[] = {vec3i(i+1,j,k),vec3i(i-1,j,k),vec3i(i,j+1,k),
57  vec3i(i,j-1,k),vec3i(i,j,k-1),vec3i(i,j,k+1)};
58  for( int nq=0; nq<6; nq++ ) {
59  vec3i qi (query[nq]);
60  if( ! shape.out_of_bounds(qi) ) {
61  if( array.active(qi)) {
62  sum += array(qi);
63  weight ++;
64  }
65  }
66  }
67  if( weight ) {
68  counters[tn] ++;
69  it.set(sum / weight);
70  }
71  }
72  },count);
73  //
74  unsigned sum (0);
75  for( const auto &e : counters ) sum += e;
76  return sum;
77  }
86  template<class T> unsigned extrapolate ( array3<T> &array, int count=1 ) {
87  return extrapolate_if(array,[&](int i, int j, int k, int tn){ return true; },count);
88  }
89 };
90 //
92 //
93 #endif
94 //
shape3::out_of_bounds
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
array3::active
bool active(int i, int j, int k) const
Get if a position on grid is active.
Definition: array3.h:552
shared_array3.h
array_extrapolator3::extrapolate
unsigned extrapolate(array3< T > &array, int count=1)
Extrapolate array where it passes the test function.
Definition: array_extrapolator3.h:86
shape3
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
array3::get_thread_num
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: array3.h:954
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array3::dilate
void dilate(std::function< void(int i, int j, int k, iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: array3.h:1661
array3.h
vec
Fixed sized vector structure.
Definition: vec.h:38
array_extrapolator3
Namespace that implements array extrapolation.
Definition: array_extrapolator3.h:36
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array3::shape
shape3 shape() const
Get the shape of the array.
Definition: array3.h:218
array_extrapolator3::extrapolate_if
unsigned extrapolate_if(array3< T > &array, std::function< bool(int i, int j, int k, int thread_index)> func, int count=1)
Extrapolate array where it passes the test function.
Definition: array_extrapolator3.h:47
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42