versor  3.0
C++11 library for Geometric algebra
vsr_generic_draw.h
1 /*
2 
3  Pablo Colapinto
4  VSR2.0
5 
6  NO METRIC ASSUMED . . .
7 */
8 
9 #ifndef VSR_GENERIC_DRAW_H_INCLUDED
10 #define VSR_GENERIC_DRAW_H_INCLUDED
11 
12 #include "gfx/gfx_glyphs.h"
13 #include "detail/vsr_generic_op.h"
14 #include "form/vsr_field.h"
15 
16 namespace vsr{
17 
18  namespace generic{
19 
20  template<class A>
21  GARot<A> AA( const GAVec<A>& s){
22  GARot<A> r = Gen::ratio( GAVec<A>::z, s.unit() );
23  return nga::Gen::aa(r);
24  }
25 
26 // template<bits::type DIM>
27 // NERot<DIM> AA( const NEBiv<DIM>& s){
28 // return nga::Gen::aa( Gen::ratio( NEVec<DIM>::z, s.dual().unit() ) );
29 // }
30 
31  template<class T>
32  void Immediate(const T& t){
33  printf("no generic draw function\n");
34  }
35  template<class T>
36  void ImmediateB(const T& t){
37  printf("no generic draw function\n");
38  }
39 
40  //GENERIC EUCLIDEAN ORTHOGONAL PROJECTION
41  template<class A>
42  void Immediate (const GAVec<A>& ts){
43  NEVec<3> s = ts;
45  glPushMatrix();
46  gfx::GL::translate( s.begin() );
47  gfx::GL::rotate( AA(s).begin() );
48  gfx::Glyph::Cone();
49  glPopMatrix();
50  }
51 
52  template<class A>
53  void ImmediateB (const GAVec<A>& ts){
54  NEVec<3> s = ts;
56  glPushMatrix();
57  gfx::GL::translate( s.begin() );
58  gfx::Glyph::SolidSphere(.05);
59  glPopMatrix();
60  }
61 
62  template<class A>
63  void Immediate (const GABiv<A>& s){
64  double ta = s.norm();
65  bool sn = nga::Op::sn( s , GABiv<A>::xy * (-1));
66 
67  glPushMatrix();
68  gfx::GL::rotate( AA(s).begin() );
69  gfx::Glyph::DirCircle( ta, sn );
70  glPopMatrix();
71  }
72 
73  template<class A>
74  GARot<A> AA( const GACir<A>& s){
75  GABiv<A> b = nga::Round::dir( s ).template copy< GABiv<A> >();
76  GARot<A> r = Gen::ratio(GAVec<A>::z, nga::Op::dle( b ).unit() );
77  return nga::Gen::aa(r);
78  }
79 
80  template<class A>
81  void Immediate( const GACir<A>& s ) {
82  VSR_PRECISION rad = nga::Round::rad( s );
83  bool im = nga::Round::size(s, false) > 0 ? 1 : 0;
84 
85  //AA(s).vprint();
86  gfx::GL::translate( nga::Round::loc(s).begin() );
87  gfx::GL::rotate( AA(s).begin() );
88 
89  im ? gfx::Glyph::Circle( rad ) : gfx::Glyph::DashedCircle( rad );
90  }
91 
92  template<class A>
93  void Immediate (const GALin<A>& s){
94  GADrv<A> d = nga::Flat::dir( s );
95  GADls<A> v = nga::Flat::loc( s , nga::Round::null( GAVec<A>() ), false);
96  gfx::GL::translate (v.begin());
97  gfx::Glyph::Line(d * 10, d * -10);
98  }
99 
100  template<class A>
101  void Immediate (const GAPnt<A>& s){
102 
103  VSR_PRECISION ta = nga::Round::size( s, true );
104 
105  //Draw as dual Sphere (if |radius^2| > 0.000001);
106  if ( fabs(ta) > FPERROR ) {
107  // printf("spehere!!!!!!!!!!!!!!!!!!!!\n");
108  bool real = ta > 0 ? 1 : 0;
109 
110  GAPnt<A> p = nga::Round::cen( s );
111  VSR_PRECISION t = sqrt ( fabs ( ta ) );
112 
113  gfx::GL::translate ( p.begin() );
114  (real) ? gfx::Glyph::SolidSphere(t, 5+ floor(t*30), 5+floor(t*30)) : gfx::Glyph::Sphere(t);
115  } else {
116  // printf("NOOOOOO\n");
118  }
119  }
120 
121  template<class A>
122  void Immediate (const GAPar<A>& s){
123  //Is Imaginary?
124  VSR_PRECISION size = nga::Round::size( s, false );
125  // printf("size: %fn", size);
126  std::vector< GAPnt<A> > pp = nga::Round::split( s );
127 
128  VSR_PRECISION ta = nga::Round::size( pp[0], true );
129 
130  if ( fabs(ta) > FPERROR ) {
131  GAPnt<A> p1 = nga::Round::cen( pp[0] );
132  GAPnt<A> p2 = nga::Round::cen( pp[1] );
133  double t = sqrt ( fabs ( ta ) );
134  bool real = size > 0 ? 1 : 0;
135 
136  glPushMatrix();
137  gfx::GL::translate ( p1.begin() );//(p1[0], p1[1], p1[2]);
138  (real) ? gfx::Glyph::SolidSphere(t, 5+ floor(t*30), 5+floor(t*30)) : gfx::Glyph::Sphere(t);
139  glPopMatrix();
140 
141  gfx::GL::translate ( p2.begin() );
142  (real) ? gfx::Glyph::SolidSphere(t, 5+ floor(t*30), 5+floor(t*30)) : gfx::Glyph::Sphere(t);
143 
144  } else {
145  // pp[0].vprint(); pp[1].vprint();
146  gfx::Glyph::Point(pp[0]);
147  gfx::Glyph::Point(pp[1]);
148  }
149  }
150 
151  template<class T>
152  void Immediate( const Field<T>& f){
153  for (int i = 0; i < f.num(); ++i){
154  Draw(f[i]);
155  }
156  }
157 
158 
159 
160  //ColorTriangle
161  template<typename T>
162  void ColorTriangles( const T& a, const T& b, const T& c){
163 
164  auto normal = -NEVec<3>( ( nga::euc::hom(a) ^ nga::euc::hom(b) ^ nga::euc::hom(c) ).dual() ).unit();
165 
166  GL::normal( normal.begin() );
167  glBegin(GL_TRIANGLES);
168  glColor3f(1,0,0);
169  GL::vertex( a.begin() );
170  glColor3f(0,1,0);
171  GL::vertex( b.begin() );
172  glColor3f(0,0,1);
173  GL::vertex( c.begin() );
174  glEnd();
175  }
176 
177 
178  template<class A>
179  void Draw( const A& s, float r = 1, float g = 1, float b = 1, float a = 1){
180  glPushMatrix();
181  glNormal3f(0,0,1);
182  glColor4f(r,g,b,a);
183  generic::Immediate(s);
184  glPopMatrix();
185  }
186 
187  template<class A>
188  void DrawB( const A& s, float r = 1, float g = 1, float b = 1, float a = 1){
189  glPushMatrix();
190  glNormal3f(0,0,1);
191  glColor4f(r,g,b,a);
192  generic::ImmediateB(s);
193  glPopMatrix();
194  }
195 
197  template<class A, class B>
198  void DrawAt( const A& s, const B& p, float r = 1, float g = 1, float b = 1, float a = 1){
199  glPushMatrix();
200  glTranslatef( p[0], p[1], p[2] );
201  glNormal3f(0,0,1);
202  glColor4f(r,g,b,a);
203  generic::Immediate(s);
204  glPopMatrix();
205  }
206 
207  //Alt
208  template<class A, class B>
209  void DrawAtB( const A& s, const B& p, float r = 1, float g = 1, float b = 1, float a = 1){
210  glPushMatrix();
211  glTranslatef( p[0], p[1], p[2] );
212  glNormal3f(0,0,1);
213  glColor4f(r,g,b,a);
214  generic::ImmediateB(s);
215  glPopMatrix();
216  }
217 
218 
219  }//generic
220 
221 } //vsr::
222 
223 #endif
static constexpr GAPnt< A > null(const Multivector< A, B > &v)
Null Point from Arbitrary Multivector.
Definition: vsr_generic_op.h:548
Definition: vsr_cga2D_draw.h:13
static constexpr auto dir(const Multivector< A, B > &f) -> auto
Direction of Direct Flat.
static constexpr auto dir(const A &s) -> auto
Direction of Round Element (shorthand)
static VSR_PRECISION size(const A &r, bool dual)
Squared Size of a General Round Element (could be negative)
Definition: vsr_generic_op.h:678
core namespaced operations that are metric-agnostic
Cir Circle
Direct Circle 3-blade \(\kappa=p_a \wedge p_b \wedge p_c\)
Definition: vsr_cga3D_types.h:130
static constexpr P loc(const A &f, const P &p, bool dual)
Location of Flat A closest to Point p (shorthand)
Definition: vsr_generic_op.h:1025
static auto aa(const GARot< A > &r) -> GARot< A >
Axis Angle from Rotor (WARNING NOT GENERIC)
Definition: vsr_generic_op.h:348
static std::vector< GAPnt< A > > split(const GAPar< A > &pp)
Split Points from Point Pair.
Definition: vsr_generic_op.h:743
Pnt Point
Null Vector \(p=\{e_1,e_2,e_3,n_o,n_\infty\}\)
Definition: vsr_cga3D_types.h:128
static Rot ratio(const Vec &v, const Vec &v2)
vsr::cga::Rotor that takes one vec to another
the versor library namespace
Definition: vsr_algebra.h:29
Lin Line
Direct Line Trivector \(p_a \wedge p_b \wedge n_\infty\)
Definition: vsr_cga3D_types.h:140
static constexpr bool sn(const A &a, const A &b)
Sign of A with Respect to B (short hand)
Definition: vsr_generic_op.h:159
Sph Sphere
Direct Sphere 4-blade \(\Sigma=p_a \wedge p_b \wedge p_c \wedge p_d\)
Definition: vsr_cga3D_types.h:131
static constexpr GAPnt< A > cen(const Multivector< A, B > &s)
Simple Center of A Round Element (shorthand)
Definition: vsr_generic_op.h:653