versor  3.0
C++11 library for Geometric algebra
vsr_patch.h
1 /*
2  * =====================================================================================
3  *
4  * Filename: vsr_patch.h
5  *
6  * Description: poly and vxl (from gfx)
7  *
8  * Version: 1.0
9  * Created: 04/16/2015 17:41:36
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Pablo Colapinto (), gmail->wolftype
14  * Organization: wolftype
15  *
16  * =====================================================================================
17  */
18 
19 #ifndef GFX_GRAPHICS_INCLUDED
20 #define GFX_GRAPHICS_INCLUDED
21 
22 #include <iostream>
23 #include "vsr.h"
24 
25 using std::ostream;
26 
27 namespace vsr {
28 
29 using vec4 = NEVec<4,int>;
30 
31 enum Cube{
32  LEFT = 1,
33  RIGHT = 1 << 1,
34  BOTTOM = 1 << 2,
35  TOP = 1 << 3,
36  FRONT = 1 << 4,
37  BACK = 1 << 5,
38  ALLSIDES = LEFT | RIGHT | BOTTOM | TOP | FRONT | BACK
39 };
40 
41 
42 
44 struct Patch{
45  Patch(int _a, int _b, int _c, int _d, double _rw, double _rh)
46  : a(_a), b(_b), c(_c), d(_d), rw(_rw), rh(_rh)
47  {}
48 
49  int a, b, c, d;
50  double rw, rh;
51 };
52 
54 struct VPatch{
55  VPatch(int _a, int _b, int _c, int _d, int _e, int _f, int _g, int _h, double _rw, double _rh, double _rd)
56  : a(_a), b(_b), c(_c), d(_d), e(_e), f(_f), g(_g), h(_h), rw(_rw), rh(_rh), rd(_rd)
57  {}
58  int a, b, c, d, e, f, g, h;
59  double rw, rh, rd;
60 };
61 
62 
63 
65 class Nbr {
66  public:
67  Nbr(){}
68  Nbr(int _idx, int _xl, int _xr, int _yb, int _yt, int _zf, int _zb) :
69  idx(_idx), xl(_xl), xr(_xr), yb(_yb), yt(_yt), zf(_zf), zb(_zb), type(0) {
70 
71  if (xl == -1 ) type |= LEFT;
72  if (xr == -1 ) type |= RIGHT;
73  if (yb == -1 ) type |= BOTTOM;
74  if (yt == -1 ) type |= TOP;
75  if (zf == -1 ) type |= FRONT;
76  if (zb == -1 ) type |= BACK;
77 
78  }
79 
80  Nbr(int _idx, int w, int h, int d, int type)
81  : idx(_idx),
82  xl( (type & LEFT) ? -1 : _idx - ( h ) * ( d ) ),
83  xr( (type & RIGHT) ? -1 : _idx + ( h ) * ( d ) ),
84  yb( (type & BOTTOM) ? - 1 : _idx - d ),
85  yt( (type & TOP) ? - 1 : _idx + d ),
86  zf( (type & FRONT) ? - 1 : _idx - 1 ),
87  zb( (type & BACK) ? - 1 : _idx + 1 ),
88  type(type)
89  {}
90 
91 
92  int idx, xl, xr, yb, yt, zf, zb, type;
93  int& operator[] (int i) { return (&idx)[i]; }
94  int operator[] (int i) const { return (&idx)[i]; }
95 
96  friend ostream& operator << (ostream&, const Nbr&);
97 
98 };
99 
100 inline ostream& operator << (ostream& os, const Nbr& m){
101  os << "NBR: \n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3] << " " << m[4] << " " << m[5] << " " << m[6] << "\n";
102  return os;
103 }
104 
105 
106 
107 class Vxl {
108 
109  public:
110  Vxl(){};
111  Vxl(int _a, int _b, int _c, int _d, int _e, int _f, int _g, int _h, int _typ = 0) :
112  a(_a), b(_b), c(_c), d(_d), e(_e), f(_f), g(_g), h(_h), type(_typ) {}
113  int a, b, c, d, e, f, g, h, type; // indices and type
114  int& operator[] (int i) { return (&a)[i]; }
115  int operator[] (int i) const { return (&a)[i]; }
116  vec4 fr() { return vec4(a,b,c,d); } //front cw
117  vec4 ri() { return vec4(b,f,g,c);} //right cw
118  vec4 ba() { return vec4(f,e,h,g);} //back cw
119  vec4 le() { return vec4(e,a,d,h);} //left cw
120  vec4 to() { return vec4(d,c,g,h);} //top cw
121  vec4 bo() { return vec4(e,f,b,a);} //bottom cw
122 
123  Vxl& limit() { for (int i = 0; i < 8; ++i) { if ( (*this)[i] == -1 ) (*this)[i] = 0; } return *this; }
124 
125  friend ostream& operator << (ostream&, const Vxl&);
126 
127 };
128 
129 inline ostream& operator << (ostream& os, const Vxl& m){
130  os << "VXL: \n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3] << " " << m[4] << " " << m[5] << " " << m[6] << " " << m[7] << "\n";
131  return os;
132 }
133 
134 } //vsr::
135 
136 #endif
Data Structure of Neighbors in a cartesian volume (left, right, bottom, top, front, back)
Definition: vsr_patch.h:65
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
Volume Patch Info Container for Euler integration of a 3d Field.
Definition: vsr_patch.h:54
Info Container for Euler integration of a 2d Field.
Definition: vsr_patch.h:44
the versor library namespace
Definition: vsr_algebra.h:29
Definition: vsr_patch.h:107