Blame view

rts/rtsQuad.h 2.92 KB
a47a23a9   dmayerich   added ENVI functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  #ifndef RTS_RECT_H
  #define RTS_RECT_H
  
  //enable CUDA_CALLABLE macro
  #include "rts/cuda_callable.h"
  #include "rts/rtsVector.h"
  #include "rts/rtsPoint.h"
  #include <iostream>
  
  namespace rts{
  
  //template for a rtsQuadangle class in ND space
  template <class T, int N>
  struct rtsQuad
  {
  	/*
  		C------------------>O
  		^                   ^
  		|                   |
  		Y                   |
  		|                   |
  		|                   |
  		A---------X-------->B
  	*/
  
  	/*T A[N];
  	T B[N];
  	T C[N];*/
  
  	rts::rtsPoint<T, N> A;
  	rts::rtsVector<T, N> X;
  	rts::rtsVector<T, N> Y;
  
  
  	CUDA_CALLABLE rtsQuad()
  	{
  
  	}
  
  	CUDA_CALLABLE rtsQuad(rtsPoint<T, N> a, rtsPoint<T, N> b, rtsPoint<T, N> c)
  	{
  
  		A = a;
  		X = b - a;
  		Y = c - a;
  
  	}
  
  	CUDA_CALLABLE rtsQuad(rts::rtsPoint<T, N> pMin, rts::rtsPoint<T, N> pMax, rts::rtsVector<T, N> normal)
  	{
  
          //assign the corner rtsPoint
          A = pMin;
  
          //compute the vector from pMin to pMax

          rts::rtsVector<T, 3> v0;
          v0 = pMax - pMin;
  
          //compute the cross product of A and the plane normal
          rts::rtsVector<T, 3> v1;
          v1 = v0.cross(normal);
  
  
          //calculate rtsPoint B
          rts::rtsPoint<T, 3> B;
          B = A + v0 * 0.5 + v1 * 0.5;
  
          //calculate rtsPoint C
          rts::rtsPoint<T, 3> C;
          C = A  + v0 * 0.5 - v1 * 0.5;
  
          //calculate X and Y
          X = B - A;
          Y = C - A;
  
  
  
  
  	}
  
  	/*CUDA_CALLABLE rtsQuad(rts::rtsPoint<T, N> p, rts::vector<T, N> x, rts::vector<T, N> y, T sx, T sy)
  	{
  		//This constructor creates a rtsQuad given a position, orientation, and size
  		//	p	= center position of the rtsQuad
  		//	x	= x-axis for the rtsQuadangle
  		//	y	= y-axis for the rtsQuadangle
  		//	sx	= size of the rtsQuad along the A-B axis
  		//	sy	= size of the rtsQuad along the A-C axis
  
  		//normalize x and y
  		rts::vector<T, N> nx = x.norm();
  		rts::vector<T, N> ny = y.norm();
  
  		//compute X and Y
  		X = sx * x;
  		Y = sy * y;
  
  		//compute A
  		A = p - 0.5 * X - 0.5 * Y;
  
  	}*/
  
  	CUDA_CALLABLE rts::rtsPoint<T, N> p(T a, T b)
  	{
  		rts::rtsPoint<T, N> result;
  		//given the two parameters a, b = [0 1], returns the position in world space
  		result = A + X * a + Y * b;
  		
  		return result;
  	}
  
  	CUDA_CALLABLE rts::rtsPoint<T, N> operator()(T a, T b)
  	{
  		return p(a, b);
  	}
  
  	std::string toStr()
  	{
  		std::stringstream ss;
  
  		ss<<"A = "<<A<<std::endl;
  		ss<<"B = "<<A + X<<std::endl;
  		ss<<"C = "<<A + X + Y<<std::endl;
  		ss<<"D = "<<A + Y<<std::endl;
  
          return ss.str();
  
  	}
  
  	CUDA_CALLABLE rtsQuad<T, N> operator*(T rhs)
  	{
  		//scales the plane by a scalar value
  
  		//compute the center rtsPoint
  		rts::rtsPoint<T, N> c = A + X*0.5 + Y*0.5;
  
  		//create the new rtsQuadangle
  		rtsQuad<T, N> result;
  		result.X = X * rhs;
  		result.Y = Y * rhs;
  		result.A = c - result.X*0.5 - result.Y*0.5;
  
  		return result;
  
  	}
  };
  
  }	//end namespace rts
  
  template <typename T, int N>
  std::ostream& operator<<(std::ostream& os, rts::rtsQuad<T, N> R)
  {
      os<<R.toStr();
      return os;
  }
  
  
  #endif