 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
49 shape2(
const unsigned gn[DIM2] ) :
w(gn[0]),
h(gn[1]) {}
71 return w==shape.
w &&
h==shape.
h;
80 return ! (*
this == shape);
89 if( idx == 0 )
return w;
90 else if( idx == 1 )
return h;
100 static unsigned dummy (0);
101 if( idx == 0 )
return w;
102 else if( idx == 1 )
return h;
197 void get(
unsigned &
w,
unsigned &
h )
const {
207 void get(
unsigned gn[DIM2] )
const {
238 unsigned log2h = (unsigned)log2(
h)+1;
239 return _w ^ (_h << log2h);
291 for(
unsigned dim : DIMS2 )
dx = std::min(
dx,1.0/(*
this)[dim]);
300 for(
int dim : DIMS2 ) result = std::max(result,(*
this)[dim]);
312 return clamp(pi[0],pi[1]);
326 if( i >
w-1 ) i =
w-1;
328 if( j >
h-1 ) j =
h-1;
342 return ( i < 0 || i >=
w || j < 0 || j >=
h );
366 return i==0 || j==0 || i==
w-1 || j==
h-1;
397 return w == 0 &&
h == 0;
422 return encode(pi[0],pi[1]);
433 return vec2i( value %
w, value /
w );
441 void for_each( std::function<
void(
int i,
int j)> func )
const {
442 for(
int j=0; j<
h; ++j )
for(
int i=0; i<
w; ++i ) {
453 for(
int j=0; j<
h; ++j )
for(
int i=0; i<
w; ++i ) {
454 if(func(i,j))
return;
469 static inline shape2 operator*(
double s,
const shape2 &shape) {
472 static inline shape2 operator/(
double s,
const shape2 &shape) {
485 shape3(
const unsigned gn[DIM2] ) :
w(gn[0]),
h(gn[1]),
d(gn[2]) {}
509 return w==shape.
w &&
h==shape.
h &&
d==shape.
d;
518 return ! (*
this == shape);
527 if( idx == 0 )
return w;
528 else if( idx == 1 )
return h;
529 else if( idx == 2 )
return d;
539 static unsigned dummy (0);
540 if( idx == 0 )
return w;
541 else if( idx == 1 )
return h;
542 else if( idx == 2 )
return d;
643 void get(
unsigned &
w,
unsigned &
h,
unsigned &
d )
const {
654 void get(
unsigned gn[DIM3] )
const {
687 unsigned log2h = (unsigned)log2(
h)+1;
688 unsigned log2d = (unsigned)log2(
d)+1;
689 return _w ^ (_h << log2h) ^ (_d << (log2h+log2d));
757 for(
unsigned dim : DIMS3 )
dx = std::min(
dx,1.0/(*
this)[dim]);
766 for(
int dim : DIMS3 ) result = std::max(result,(*
this)[dim]);
778 return clamp(pi[0],pi[1],pi[2]);
792 if( i >
w-1 ) i =
w-1;
794 if( j >
h-1 ) j =
h-1;
796 if( k >
d-1 ) k =
d-1;
812 return ( i < 0 || i >=
w || j < 0 || j >=
h || k < 0 || k >=
d );
838 return i==0 || j==0 || i==
w-1 || j==
h-1 || k==
d-1 || k==
d-1;
849 return on_edge(pi[0],pi[1],pi[2]);
870 return w == 0 &&
h == 0 &&
d == 0;
883 size_t encode(
int i,
int j,
int k )
const {
887 return (_w*_h)*k+_w*j+i;
898 return encode(pi[0],pi[1],pi[2]);
909 size_t plane_count =
w*
h;
910 int k = value / plane_count;
911 size_t m = value % plane_count;
922 void for_each( std::function<
void(
int i,
int j,
int k)> func )
const {
923 for(
int k=0; k<
d; ++k )
for(
int j=0; j<
h; ++j )
for(
int i=0; i<
w; ++i ) {
934 for(
int k=0; k<
d; ++k )
for(
int j=0; j<
h; ++j )
for(
int i=0; i<
w; ++i ) {
935 if(func(i,j,k))
return;
955 static inline shape3 operator*(
double s,
const shape3 &shape) {
958 static inline shape3 operator/(
double s,
const shape3 &shape) {
void get(unsigned gn[DIM2]) const
Get the dimensional numbers of this shape.
Definition: shape.h:207
bool operator<(const shape2 &rhs) const
Compare the hash from the input shape.
Definition: shape.h:228
unsigned w
Width of the shape.
Definition: shape.h:942
void interruptible_for_each(std::function< bool(int i, int j, int k)> func) const
Perform a serial loop operation.
Definition: shape.h:933
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 operator-=(const shape2 &rhs)
Shrink the shape by the input shape.
Definition: shape.h:143
size_t hash() const
Get the hash number of this shape.
Definition: shape.h:683
size_t hash() const
Get the hash number of this shape.
Definition: shape.h:235
shape3()
Constructor for shape3.
Definition: shape.h:501
vec2i find_node(const vec2< T > &p) const
Find the nearest nodal position from the input fractional position.
Definition: shape.h:273
shape3 cell() const
Get the shape for the cell-centered grid from this shape.
Definition: shape.h:695
bool operator==(const shape3 &shape) const
Get if this shape is equal to the input shape.
Definition: shape.h:508
void operator/=(double v)
Scale this shape (by division) by the input number.
Definition: shape.h:628
bool operator!=(const shape2 &shape) const
Get if this shape is different from the input shape.
Definition: shape.h:79
shape2 operator/(double s) const
Get a scaled (by division) shape by the input number.
Definition: shape.h:176
bool on_edge(const vec2i &pi) const
Get if the position lies on the edge of the index space of this shape.
Definition: shape.h:376
shape3(const unsigned gn[DIM2])
Constructor for shape3.
Definition: shape.h:485
bool operator!=(const shape3 &shape) const
Get if this shape is different from the input shape.
Definition: shape.h:517
void operator-=(const shape3 &rhs)
Shrink the shape by the input shape.
Definition: shape.h:584
bool out_of_bounds(const vec2i &pi) const
Get if the position is outside of the index space of this shape.
Definition: shape.h:352
void get(unsigned gn[DIM3]) const
Get the dimensional numbers of this shape.
Definition: shape.h:654
void operator*=(double v)
Scale this shape by the input number.
Definition: shape.h:606
unsigned h
Height of the shape.
Definition: shape.h:947
shape3 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:707
void get(unsigned &w, unsigned &h, unsigned &d) const
Get the dimensional numbers of this shape.
Definition: shape.h:643
size_t encode(int i, int j, int k) const
Encode an index position to an integer.
Definition: shape.h:883
vec2i find_face(const vec2< T > &p, unsigned dim) const
Find the nearest facial position (in the context of staggered grid) from the input fractional positio...
Definition: shape.h:282
vec3i decode(size_t value) const
Decode from an integer to an index coordinate.
Definition: shape.h:908
size_t count() const
Count the number of cells of the grid of this shape.
Definition: shape.h:857
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
double dx() const
Get the length of grid cell size.
Definition: shape.h:755
size_t encode(const vec2i &pi) const
Encode an index position to an integer.
Definition: shape.h:421
size_t count() const
Count the number of cells of the grid of this shape.
Definition: shape.h:385
unsigned d
Depth of the shape.
Definition: shape.h:952
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
size_t encode(const vec3i &pi) const
Encode an index position to an integer.
Definition: shape.h:897
vec2i find_cell(const vec2< T > &p) const
Find the nearest cell position from the input fractional position.
Definition: shape.h:264
unsigned h
Height of the shape.
Definition: shape.h:466
bool on_edge(const vec3i &pi) const
Get if the position lies on the edge of the index space of this shape.
Definition: shape.h:848
vec2i clamp(int i, int j) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:324
shape2(const unsigned gn[DIM2])
Constructor for shape2.
Definition: shape.h:49
shape3 operator/(double s) const
Get a scaled (by division) shape by the input number.
Definition: shape.h:619
shape2 cell() const
Get the shape for the cell-centered grid from this shape.
Definition: shape.h:245
vec3i find_face(const vec3< T > &p, unsigned dim) const
Find the nearest facial position (in the context of staggered grid) from the input fractional positio...
Definition: shape.h:748
vec2d box(double dx) const
Get the world coordinate size of the shape.
Definition: shape.h:219
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
vec3i find_node(const vec3< T > &p) const
Find the nearest nodal position from the input fractional position.
Definition: shape.h:730
unsigned max() const
Get the maximal number in all the dimensions.
Definition: shape.h:298
bool empty() const
Get if all the lengthes of this shape is zero.
Definition: shape.h:869
vec2i decode(size_t value) const
Decode from an integer to an index coordinate.
Definition: shape.h:432
void get(unsigned &w, unsigned &h) const
Get the dimensional numbers of this shape.
Definition: shape.h:197
unsigned w
Width of the shape.
Definition: shape.h:461
shape2 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:257
vec3i clamp(int i, int j, int k) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:790
unsigned operator[](unsigned idx) const
Get the number of a specified dimensional of this shape.
Definition: shape.h:88
void for_each(std::function< void(int i, int j, int k)> func) const
Perform a three dimensional serial loop operation.
Definition: shape.h:922
void interruptible_for_each(std::function< bool(int i, int j)> func) const
Perform a serial loop operation.
Definition: shape.h:452
shape3 operator-(const shape3 &rhs) const
Get an shrunk shape by the input shape.
Definition: shape.h:575
void operator+=(const shape3 &rhs)
Expand this shape by the input shape.
Definition: shape.h:562
shape2(unsigned w, unsigned h)
Constructor for shape2.
Definition: shape.h:58
shape3 operator+(const shape3 &rhs) const
Get an expanded shape by the input shape.
Definition: shape.h:553
unsigned & operator[](unsigned idx)
Get the writable number of a specified dimensional of this shape.
Definition: shape.h:538
vec3i find_edge(const vec3< T > &p, unsigned dim) const
Find the nearest edge position from the input fractional position.
Definition: shape.h:739
bool on_edge(int i, int j, int k) const
Get if the position lies on the edge of the index space of this shape.
Definition: shape.h:837
shape2 operator*(double s) const
Get a scaled shape by the input number.
Definition: shape.h:155
void operator+=(const shape2 &rhs)
Expand this shape by the input shape.
Definition: shape.h:122
double dx() const
Get the length of grid cell size.
Definition: shape.h:289
shape2 nodal() const
Get the shape for the nodal defined grid from this shape.
Definition: shape.h:250
shape2 operator-(const shape2 &rhs) const
Get an shrunk shape by the input shape.
Definition: shape.h:134
Fixed sized vector structure.
Definition: vec.h:38
bool empty() const
Get if all the lengthes of this shape is zero.
Definition: shape.h:396
unsigned & operator[](unsigned idx)
Get the writable number of a specified dimensional of this shape.
Definition: shape.h:99
shape2()
Constructor for shape2.
Definition: shape.h:63
void operator/=(double v)
Scale this shape (by division) by the input number.
Definition: shape.h:185
shape3 edge(int dim) const
Get the shape of edge of a specified dimension from this shape.
Definition: shape.h:714
size_t encode(int i, int j) const
Encode an index position to an integer.
Definition: shape.h:409
unsigned max() const
Get the maximal number in all the dimensions.
Definition: shape.h:764
vec3d box(double dx) const
Get the world coordinate size of the shape.
Definition: shape.h:667
vec3i find_cell(const vec3d &p) const
Find the nearest cell position from the input fractional position.
Definition: shape.h:721
vec3i clamp(const vec3i &pi) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:777
bool operator<(const shape2 &rhs) const
Compare the hash from the input shape.
Definition: shape.h:676
bool out_of_bounds(const vec3i &pi) const
Get if the position is outside of the index space of this shape.
Definition: shape.h:822
unsigned operator[](unsigned idx) const
Get the number of a specified dimensional of this shape.
Definition: shape.h:526
bool operator==(const shape2 &shape) const
Get if this shape is equal to the input shape.
Definition: shape.h:70
Structure that defines shape such as width, height.
Definition: shape.h:42
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
vec2i clamp(const vec2i &pi) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:311
bool on_edge(int i, int j) const
Get if the position lies on the edge of the index space of this shape.
Definition: shape.h:365
shape3(unsigned w, unsigned h, unsigned d)
Constructor for shape2.
Definition: shape.h:496
void operator*=(double v)
Scale this shape by the input number.
Definition: shape.h:164
shape2 operator+(const shape2 &rhs) const
Get an expanded shape by the input shape.
Definition: shape.h:113
shape3 nodal() const
Get the shape for the nodal defined grid from this shape.
Definition: shape.h:700
shape3 operator*(double s) const
Get a scaled shape by the input number.
Definition: shape.h:597
void for_each(std::function< void(int i, int j)> func) const
Perform a two dimensional serial loop operation.
Definition: shape.h:441