versor  3.0
C++11 library for Geometric algebra
vsr_cga2D_draw.h
1 #ifndef VSR_CGA2D_DRAW_H_INCLUDED
2 #define VSR_CGA2D_DRAW_H_INCLUDED
3 
4 #include "gfx/gfx_glyphs.h"
5 #include "gfx/gfx_render.h"
6 
7 
8 #include "draw/vsr_draw.h"
9 #include "space/vsr_cga2D_types.h"
10 #include "form/vsr_field.h"
11 
12 
13 namespace gfx{
14 
15  // namespace cga2D{
16 
17  // using namespace cga2D;//::types;
18  // using namespace gfx;
19 
20 // template<class A>
21 // void Draw( const A& s, float r = 1, float g = 1, float b = 1, float a = 1){
22 // glPushMatrix();
23 // glNormal3f(0,0,1);
24 // glColor4f(r,g,b,a);
25 // Immediate(s);
26 // glPopMatrix();
27 // }
28 //
29 // /*! Draw Some Type A at 2D Position B */
30 // typedef void (*GFunc)();
31 // template<class B>
32 // void DrawAt( GFunc glyph, const B& p, float r = 1, float g = 1, float b = 1, float a = 1){
33 // glPushMatrix();
34 // glTranslatef( p[0], p[1], 0 );
35 // glNormal3f(0,0,1);
36 // glColor4f(r,g,b,a);
37 // glyph();//Immediate(s);
38 // glPopMatrix();
39 // }
40  // FEATURE ExTRAcTION (ROTATION AND POSITION)
41 
42  using namespace vsr;
43 
44 
45  cga2D::Rot AA( const cga2D::Vec& s){
46  cga2D::Rot r = nga::Gen::ratio(cga2D::Vec::y, s.unit() );
47  //Vec v = Op::dle( Gen::pl( r ) ) ;
48  VSR_PRECISION deg = nga::Gen::iphi(r) * ( -180 / PI );
49  return cga2D::Rot(deg, nga::Gen::pl( r )[0]);
50 
51  }
52 
53 
54  template<> void Renderable<cga2D::Vec>::DrawImmediate(const cga2D::Vec& s){
55  cga2D::Rot t = AA(s);
56 
57  gfx::Glyph::Line2D(s);
58  glPushMatrix();
59  gfx::GL::translate( s[0], s[1], 0 );
60  gfx::GL::rotate(t[0], 0, 0, t[1] );
61  Glyph::Tri();
62  glPopMatrix();
63  }
64 
65  template<> void Renderable<cga2D::Drv>::DrawImmediate (const cga2D::Drv& d){
66  Renderable<cga2D::Vec>::DrawImmediate( d.copy<cga2D::Vec>() );
67  }
68 
69 
70  template<> void Renderable<cga2D::Point>::DrawImmediate(const cga2D::Point& s){
71 
72  VSR_PRECISION ta = nga::Round::size( s, true );
73 
74  //treat as dual circle (if |radius^2| > 0.000001);
75  if ( fabs(ta) > FPERROR ) {
76 
77  bool real = ta > 0 ? 1 : 0;
78 
79  cga2D::Pnt p = nga::Round::cen( s );
80  VSR_PRECISION t = sqrt ( fabs ( ta ) );
81 
82  gfx::GL::translate ( p[0], p[1], 0 );
83  (real) ? gfx::Glyph::Circle( t ) : gfx::Glyph::DashedCircle( t );
84  } else {
85 
86  gfx::Glyph::Point2D(s);
87  }
88  }
89 
90  template<> void Renderable<cga2D::Flp>::DrawImmediate(const cga2D::Flp& s){
91  Renderable<cga2D::Point>::DrawImmediate( (s / s[2]).null() );
92  }
93 
94  template<> void Renderable<cga2D::Dfp>::DrawImmediate(const cga2D::Dfp& s){
95  Renderable<cga2D::Flp>::DrawImmediate( s.dual() );
96  }
97 
98 
99  template<> void Renderable<cga2D::Circle>::DrawImmediate(const cga2D::Circle& s){
100  Renderable<cga2D::Point>::DrawImmediate( s.dual() );
101  }
102 
103  template<> void Renderable<cga2D::Pair>::DrawImmediate(const cga2D::Pair& s){
104  //Is Imaginary?
105  VSR_PRECISION size = nga::Round::size( s, false );
106  std::vector<cga2D::Pnt> pp = nga::Round::split( s );
107 
108  VSR_PRECISION ta = nga::Round::size( pp[0], true );
109 
110  if ( fabs(ta) > FPERROR ) {
111  cga2D::Pnt p1 = nga::Round::cen( pp[0] );
112  cga2D::Pnt p2 = nga::Round::cen( pp[1] );
113  double t = sqrt ( fabs ( ta ) );
114  bool real = size > 0 ? 1 : 0;
115 
116  glPushMatrix();
117  gfx::GL::translate ( p1[0], p1[1], 0 );//(p1[0], p1[1], p1[2]);
118  (real) ? gfx::Glyph::Circle( t ) : gfx::Glyph::DashedCircle( t );
119  glPopMatrix();
120 
121  gfx::GL::translate ( p2[0], p2[1], 0 );
122  (real) ? gfx::Glyph::Circle( t ) : gfx::Glyph::DashedCircle( t );
123 
124  } else {
125  gfx::Glyph::Point2D(pp[0]);
126  gfx::Glyph::Point2D(pp[1]);
127  }
128  }
129 
130 
131  template<> void Renderable<cga2D::Line>::DrawImmediate(const cga2D::Line& s){
132  cga2D::Drv d = nga::Flat::dir( s );
133  cga2D::Dls v = nga::Flat::loc( s , nga::Round::point(0,0), false);
134  gfx::GL::translate (v[0], v[1],0);
135  gfx::Glyph::Line2D(d * 10, d * -10);
136  }
137 
138 
139  template<> void Renderable<cga2D::DualLine>::DrawImmediate(const cga2D::DualLine& s){
140  Renderable<cga2D::Line>::DrawImmediate(s.dual() );
141  }
142 
143 
144  /*-----------------------------------------------------------------------------
145  * FIELDS
146  *-----------------------------------------------------------------------------*/
147 
148  template<> void Renderable<Field<cga2D::Vec>>::DrawImmediate( const Field<cga2D::Vec>& f){
149  for (int i = 0; i < f.num(); ++i){
150  glPushMatrix();
151  glTranslatef( f.grid(i)[0], f.grid(i)[1],f.grid(i)[2]);
152 
153  Renderable<cga2D::Vec>::DrawImmediate(f[i]);
154 
155  glPopMatrix();
156  }
157  }
158 } //vsr::
159 
160 #endif
static auto ratio(const GAVec< A > &a, const GAVec< A > &b) -> decltype((a *b))
Generate general rotation as exponential of anonymous Implemented from "Square Root and Logarithm of ...
Definition: vsr_generic_op.h:504
Definition: vsr_cga2D_draw.h:13
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
A Basic 3D Field (slowly porting this over from the now defunct vsr_lattice class) Use to Evaluate Ne...
Definition: vsr_field.h:67
static constexpr auto dir(const Multivector< A, B > &f) -> auto
Direction of Direct Flat.
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
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 std::vector< GAPnt< A > > split(const GAPar< A > &pp)
Split Points from Point Pair.
Definition: vsr_generic_op.h:743
static auto pl(const GARot< A > &r) -> GABiv< A >
Normalized plane of rotation from Rotor.
Definition: vsr_generic_op.h:321
static VSR_PRECISION iphi(const GARot< A > &r)
Angle of Rotation from Rotor.
Definition: vsr_generic_op.h:339
the versor library namespace
Definition: vsr_algebra.h:29
B copy() const
Copying to type B.
T::space::point & grid(int i)
Set Grid (position) Data.
Definition: vsr_cubicLattice.h:464
NTri< 5 > Tri
Trivector
Definition: vsr_cga3D_types.h:65
static constexpr NPnt< sizeof...(T)+2 > point(T...v)
Null Point from Coordinates.
Definition: vsr_generic_op.h:571
NRot< 5 > Rot
Rotor
Definition: vsr_cga3D_types.h:64
static constexpr GAPnt< A > cen(const Multivector< A, B > &s)
Simple Center of A Round Element (shorthand)
Definition: vsr_generic_op.h:653