Commit 3f15dade7fe0f135e31c41974d80a3e317a91b90

Authored by Pavel Govyadinov
1 parent 035d798f

changed the plane and rect classes

Showing 3 changed files with 108 additions and 213 deletions   Show diff stats
stim/gl/gl_spider.h
... ... @@ -140,11 +140,12 @@ class gl_spider : public virtual gl_texture<T>
140 140 setMatrix(); //create the transformation matrix.
141 141 glCallList(dList+1); //move the templates to p, d, m.
142 142 int best = getCost(ptexbufferID, numSamplesPos); //find min cost.
  143 + std::cerr << best << std::endl;
143 144 stim::vec<float> next( //find next position.
144   - pV[best][0],
145   - pV[best][1],
146   - pV[best][2],
147   - 1);
  145 + pV[best][0],
  146 + pV[best][1],
  147 + pV[best][2],
  148 + 1);
148 149 next = cT*next; //find next position.
149 150 setPosition(
150 151 next[0]*S[0]*R[0],
... ... @@ -727,7 +728,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
727 728 ///Best results if samples is can create a perfect root.
728 729 ///Default Constructor
729 730 gl_spider
730   - (int samples = 1089, int samplespos = 400,int samplesmag = 144)
  731 + (int samples = 1089, int samplespos = 441,int samplesmag = 144)
731 732 {
732 733 p = vec<float>(0.0, 0.0, 0.0);
733 734 d = vec<float>(0.0, 0.0, 1.0);
... ... @@ -750,7 +751,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
750 751 ///@param int samples, number of templates this spider is going to use.
751 752 gl_spider
752 753 (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z,
753   - float mag_x, int numsamples = 1089, int numsamplespos = 400, int numsamplesmag =144)
  754 + float mag_x, int numsamples = 1089, int numsamplespos = 441, int numsamplesmag =144)
754 755 {
755 756 p = vec<float>(pos_x, pos_y, pos_z);
756 757 d = vec<float>(dir_x, dir_y, dir_z);
... ... @@ -768,7 +769,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
768 769 ///@param float mag, size of the vector.
769 770 ///@param int samples, number of templates this spider is going to use.
770 771 gl_spider
771   - (stim::vec<float> pos, stim::vec<float> dir, float mag, int samples = 1089, int samplesPos = 400, int samplesMag = 144)
  772 + (stim::vec<float> pos, stim::vec<float> dir, float mag, int samples = 1089, int samplesPos = 441, int samplesMag = 144)
772 773 {
773 774 p = pos;
774 775 d = dir;
... ... @@ -815,13 +816,13 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
815 816 glListBase(dList);
816 817 Bind(texbufferID, fboID, numSamples);
817 818 genDirectionVectors(5*M_PI/4);
818   -// Unbind();
819   - Bind(ptexbufferID, bfboID, numSamplesPos);
  819 + Unbind();
  820 + Bind(ptexbufferID, pfboID, numSamplesPos);
820 821 genPositionVectors();
821   -// Unbind();
  822 + Unbind();
822 823 Bind(mtexbufferID, mfboID, numSamplesMag);
823 824 genMagnitudeVectors();
824   -// Unbind();
  825 + Unbind();
825 826 Bind(btexbufferID, bfboID, 27);
826 827 DrawCylinder();
827 828 Unbind();
... ... @@ -1150,13 +1151,13 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1150 1151 start = std::clock();
1151 1152 #endif
1152 1153 findOptimalDirection();
1153   - //Unbind();
  1154 + Unbind();
1154 1155 Bind(ptexbufferID, pfboID, numSamplesPos);
1155 1156 findOptimalPosition();
1156   - //Unbind();
  1157 + Unbind();
1157 1158 Bind(mtexbufferID, mfboID, numSamplesMag);
1158 1159 findOptimalScale();
1159   - //Unbind();
  1160 + Unbind();
1160 1161 CHECK_OPENGL_ERROR
1161 1162  
1162 1163 #ifdef TESTING
... ... @@ -1566,7 +1567,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1566 1567 }
1567 1568 else {
1568 1569 cL.push_back(stim::vec<float>(p[0], p[1],p[2]));
1569   - cM.push_back(m[0]);
  1570 + cM.push_back(stim::vec<float>(m[0], m[0]));
  1571 +// cM.push_back(m[0]);
  1572 +
1570 1573 sk.TexCoord(m[0]);
1571 1574 sk.Vertex(p[0], p[1], p[2]);
1572 1575 Bind(btexbufferID, bfboID, 27);
... ...
stim/math/plane.h
1   -#ifndef RTS_PLANE_H
2   -#define RTS_PLANE_H
3   -
4   -#include <iostream>
5   -#include <stim/math/vector.h>
6   -#include "rts/cuda/callable.h"
7   -
8   -
9   -namespace stim{
10   -template <typename T, int D> class plane;
11   -}
12   -
13   -template <typename T, int D>
14   -CUDA_CALLABLE stim::plane<T, D> operator-(stim::plane<T, D> v);
15   -
16   -namespace stim{
17   -
18   -template <class T, int D = 3>
19   -class plane{
20   -
21   - //a plane is defined by a point and a normal
22   -
23   -private:
24   -
25   - vec<T, D> P; //point on the plane
26   - vec<T, D> N; //plane normal
27   -
28   - CUDA_CALLABLE void init(){
29   - P = vec<T, D>(0, 0, 0);
30   - N = vec<T, D>(0, 0, 1);
31   - }
32   -
33   -
34   -public:
35   -
36   - //default constructor
37   - CUDA_CALLABLE plane(){
38   - init();
39   - }
  1 +#ifndef STIM_PLANE_H
  2 +#define STIM_PLANE_H
  3 +
  4 +namespace stim
  5 +{
  6 +template <typename T> class plane
  7 +{
  8 + private:
  9 + stim::vec<T> P;
  10 + stim::vec<T> N;
  11 +
  12 + CUDA_CALLABLE void init()
  13 + {
  14 + P = stim::vec<T>(0, 0, 0);
  15 + N = stim::vec<T>(0, 0, 1);
  16 + }
  17 +
  18 + public:
40 19  
41   - CUDA_CALLABLE plane(vec<T, D> n, vec<T, D> p = vec<T, D>(0, 0, 0)){
42   - P = p;
43   - N = n.norm();
44   - }
45   -
46   - CUDA_CALLABLE plane(T z_pos){
47   - init();
48   - P[2] = z_pos;
49   - }
50   -
51   - //create a plane from three points (a triangle)
52   - CUDA_CALLABLE plane(vec<T, D> a, vec<T, D> b, vec<T, D> c){
53   - P = c;
54   - N = (c - a).cross(b - a);
55   - if(N.len() == 0) //handle the degenerate case when two vectors are the same, N = 0
56   - N = 0;
57   - else
58   - N = N.norm();
59   - }
60   -
61   - template< typename U >
62   - CUDA_CALLABLE operator plane<U, D>(){
63   -
64   - plane<U, D> result(N, P);
65   - return result;
66   - }
67   -
68   - CUDA_CALLABLE vec<T, D> norm(){
69   - return N;
70   - }
71   -
72   - CUDA_CALLABLE vec<T, D> p(){
73   - return P;
74   - }
75   -
76   - //flip the plane front-to-back
77   - CUDA_CALLABLE plane<T, D> flip(){
78   - plane<T, D> result = *this;
79   - result.N = -result.N;
80   - return result;
81   - }
82   -
83   - //determines how a vector v intersects the plane (1 = intersects front, 0 = within plane, -1 = intersects back)
84   - CUDA_CALLABLE int face(vec<T, D> v){
  20 + CUDA_CALLABLE plane()
  21 + {
  22 + init();
  23 + }
85 24  
86   - T dprod = v.dot(N); //get the dot product between v and N
87   -
88   - //conditional returns the appropriate value
89   - if(dprod < 0)
90   - return 1;
91   - else if(dprod > 0)
92   - return -1;
93   - else
94   - return 0;
95   - }
96   -
97   - //determine on which side of the plane a point lies (1 = front, 0 = on the plane, -1 = back)
98   - CUDA_CALLABLE int side(vec<T, D> p){
99   -
100   - vec<T, D> v = p - P; //get the vector from P to the query point p
101   -
102   - return face(v);
103   - }
104   -
105   - //compute the component of v that is perpendicular to the plane
106   - CUDA_CALLABLE vec<T, D> perpendicular(vec<T, D> v){
107   - return N * v.dot(N);
108   - }
109   -
110   - //compute the projection of v in the plane
111   - CUDA_CALLABLE vec<T, D> parallel(vec<T, D> v){
112   - return v - perpendicular(v);
113   - }
114   -
115   - CUDA_CALLABLE void decompose(vec<T, D> v, vec<T, D>& para, vec<T, D>& perp){
116   - perp = N * v.dot(N);
117   - para = v - perp;
118   - }
119   -
120   - //get both the parallel and perpendicular components of a vector v w.r.t. the plane
121   - CUDA_CALLABLE void project(vec<T, D> v, vec<T, D> &v_par, vec<T, D> &v_perp){
122   -
123   - v_perp = v.dot(N);
124   - v_par = v - v_perp;
125   - }
126   -
127   - //compute the reflection of v off of the plane
128   - CUDA_CALLABLE vec<T, D> reflect(vec<T, D> v){
129   -
130   - //compute the reflection using N_prime as the plane normal
131   - vec<T, D> par = parallel(v);
132   - vec<T, D> r = (-v) + par * 2;
133   -
134   - /*std::cout<<"----------------REFLECT-----------------------------"<<std::endl;
135   - std::cout<<str()<<std::endl;
136   - std::cout<<"v: "<<v<<std::endl;
137   - std::cout<<"r: "<<r<<std::endl;
138   - std::cout<<"Perpendicular: "<<perpendicular(v)<<std::endl;
139   - std::cout<<"Parallel: "<<par<<std::endl;*/
140   - return r;
141   -
142   - }
143   -
144   - CUDA_CALLABLE rts::plane<T, D> operator-()
145   - {
146   - rts::plane<T, D> p = *this;
147   -
148   - //negate the normal vector
149   - p.N = -p.N;
150   -
151   - return p;
152   - }
153   -
154   - //output a string
155   - std::string str(){
156   - std::stringstream ss;
157   - ss<<"P: "<<P<<std::endl;
158   - ss<<"N: "<<N;
159   - return ss.str();
160   - }
161   -
162   - ///////Friendship
163   - //friend CUDA_CALLABLE rts::plane<T, D> operator- <> (rts::plane<T, D> v);
164   -
165   -
166   -
167   -};
168   -
169 25 }
170   -
171   -//arithmetic operators
172   -
173   -//negative operator flips the plane (front to back)
174   -//template <typename T, int D>
175   -
176   -
177   -
178   -
179 26 #endif
... ...
stim/math/rect.h
... ... @@ -38,31 +38,17 @@ private:
38 38 }
39 39  
40 40  
41   - CUDA_CALLABLE void normal(vec<T> n){ //orient the rectangle along the specified normal
42   -
43   - n = n.norm(); //normalize, just in case
44   - vec<T> n_current = X.cross(Y).norm(); //compute the current normal
45   - quaternion<T> q; //create a quaternion
46   - q.CreateRotation(n_current, n); //initialize a rotation from n_current to n
47   -
48   - //apply the quaternion to the vectors and position
49   - X = q.toMatrix3() * X;
50   - Y = q.toMatrix3() * Y;
51   - }
52   -
53   - CUDA_CALLABLE void init(){
54   - C = vec<T>(0, 0, 0);
55   - X = vec<T>(1, 0, 0);
56   - Y = vec<T>(0, 1, 0);
57   - }
58 41  
59 42 public:
60 43  
  44 + ///base constructor.
61 45 CUDA_CALLABLE rect(){
62 46 init();
63 47 }
64 48  
65   - //create a rectangle given a size and position
  49 + ///create a rectangle given a size and position in Z space.
  50 + ///@param size: size of the rectangle in ND space.
  51 + ///@param z_pos z coordinate of the rectangle.
66 52 CUDA_CALLABLE rect(T size, T z_pos = (T)0){
67 53 init(); //use the default setup
68 54 scale(size); //scale the rectangle
... ... @@ -70,13 +56,30 @@ public:
70 56 }
71 57  
72 58  
73   - //create a rectangle from a center point, normal, and size
  59 + ///create a rectangle from a center point, normal
  60 + ///@param c: x,y,z location of the center.
  61 + ///@param n: x,y,z direction of the normal.
74 62 CUDA_CALLABLE rect(vec<T> c, vec<T> n = vec<T>(0, 0, 1)){
75 63 init(); //start with the default setting
76 64 C = c;
77 65 normal(n); //orient
78 66 }
79 67  
  68 + ///create a rectangle from a center point, normal, and size
  69 + ///@param c: x,y,z location of the center.
  70 + ///@param s: size of the rectangle.
  71 + ///@param n: x,y,z direction of the normal.
  72 + CUDA_CALLABLE rect(vec<T> c, T s, vec<T> n = vec<T>(0, 0, 1)){
  73 + init(); //start with the default setting
  74 + C = c;
  75 + scale(s);
  76 + normal(n); //orient
  77 + }
  78 +
  79 + ///creates a rectangle from a centerpoint and an X and Y direction vectors.
  80 + ///@param center: x,y,z location of the center.
  81 + ///@param directionX: u,v,w direction of the X vector.
  82 + ///@param directionY: u,v,w direction of the Y vector.
80 83 CUDA_CALLABLE rect(vec<T> center, vec<T> directionX, vec<T> directionY )
81 84 {
82 85 C = center;
... ... @@ -84,6 +87,11 @@ public:
84 87 Y = directionY;
85 88 }
86 89  
  90 + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
  91 + ///@param size of the rectangle in ND space.
  92 + ///@param center: x,y,z location of the center.
  93 + ///@param directionX: u,v,w direction of the X vector.
  94 + ///@param directionY: u,v,w direction of the Y vector.
87 95 CUDA_CALLABLE rect(T size, vec<T> center, vec<T> directionX, vec<T> directionY )
88 96 {
89 97 C = center;
... ... @@ -91,7 +99,12 @@ public:
91 99 Y = directionY;
92 100 scale(size);
93 101 }
94   -
  102 +
  103 + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
  104 + ///@param size of the rectangle in ND space, size[0] = size in X, size[1] = size in Y.
  105 + ///@param center: x,y,z location of the center.
  106 + ///@param directionX: u,v,w direction of the X vector.
  107 + ///@param directionY: u,v,w direction of the Y vector.
95 108 CUDA_CALLABLE rect(vec<T> size, vec<T> center, vec<T> directionX, vec<T> directionY )
96 109 {
97 110 C = center;
... ... @@ -99,12 +112,36 @@ public:
99 112 Y = directionY;
100 113 scale(size[0], size[1]);
101 114 }
102   -
  115 +
  116 + ///scales a rectangle in ND space.
  117 + ///@param factor1: size of the scale in the X-direction.
  118 + ///@param factor2: size of the scale in the Y-direction.
103 119 CUDA_CALLABLE void scale(T factor1, T factor2){
104 120 X *= factor1;
105 121 Y *= factor2;
106 122 }
107 123  
  124 + ///@param n; vector with the normal.
  125 + ///Orients the rectangle along the normal n.
  126 + CUDA_CALLABLE void normal(vec<T> n){ //orient the rectangle along the specified normal
  127 +
  128 + n = n.norm(); //normalize, just in case
  129 + vec<T> n_current = X.cross(Y).norm(); //compute the current normal
  130 + quaternion<T> q; //create a quaternion
  131 + q.CreateRotation(n_current, n); //initialize a rotation from n_current to n
  132 +
  133 + //apply the quaternion to the vectors and position
  134 + X = q.toMatrix3() * X;
  135 + Y = q.toMatrix3() * Y;
  136 + }
  137 +
  138 + ///general init method that sets a general rectangle.
  139 + CUDA_CALLABLE void init(){
  140 + C = vec<T>(0, 0, 0);
  141 + X = vec<T>(1, 0, 0);
  142 + Y = vec<T>(0, 1, 0);
  143 + }
  144 +
108 145 //boolean comparison
109 146 bool operator==(const rect<T> & rhs)
110 147 {
... ... @@ -151,7 +188,7 @@ public:
151 188  
152 189 }
153 190  
154   - //scales the rectangle by a value rhs
  191 + ///multiplication operator scales the rectangle by a value rhs.
155 192 CUDA_CALLABLE rect<T> operator*(T rhs)
156 193 {
157 194 //scales the plane by a scalar value
... ... @@ -164,7 +201,8 @@ public:
164 201  
165 202 }
166 203  
167   - //computes the distance between the specified point and this rectangle
  204 + ///computes the distance between the specified point and this rectangle.
  205 + ///@param p: x, y, z coordinates of the point to calculate distance to.
168 206 CUDA_CALLABLE T dist(vec<T> p)
169 207 {
170 208 //compute the distance between a point and this rect
... ... @@ -185,6 +223,13 @@ public:
185 223 return d1;
186 224 }
187 225  
  226 + CUDA_CALLABLE T center(vec<T> p)
  227 + {
  228 + C = p;
  229 + }
  230 +
  231 + ///Returns the maximum distance of the rectangle from a point p to the sides of the rectangle.
  232 + ///@param p: x, y, z point.
188 233 CUDA_CALLABLE T dist_max(vec<T> p)
189 234 {
190 235 vec<T> A = C - X * (T)0.5 - Y * (T)0.5;
... ...