Blame view

rts/rtsPoint.h 2.16 KB
a47a23a9   dmayerich   added ENVI functions
1
2
  #ifndef RTS_rtsPoint_H

  #define RTS_rtsPoint_H

f1402849   dmayerich   renewed commit
3
4
5
6
7
8
9
10
  

  //#include "rts/vector.h"
  #include <string.h>

  

  namespace rts

  {

  

  template <class T, int N>

a47a23a9   dmayerich   added ENVI functions
11
  struct rtsPoint

f1402849   dmayerich   renewed commit
12
13
14
  {

  	T p[N];

  

a47a23a9   dmayerich   added ENVI functions
15
  	CUDA_CALLABLE rtsPoint()

f1402849   dmayerich   renewed commit
16
17
18
19
20
  	{
  

  	}

  

  	//efficiency constructor, makes construction easier for 1D-4D vectors

a47a23a9   dmayerich   added ENVI functions
21
  	CUDA_CALLABLE rtsPoint(T x, T y = (T)0.0, T z = (T)0.0, T w = (T)0.0)

f1402849   dmayerich   renewed commit
22
23
24
25
26
27
28
29
30
31
32
33
  	{

  		if(N >= 1)

  			p[0] = x;

  		if(N >= 2)

  			p[1] = y;

  		if(N >= 3)

  			p[2] = z;

  		if(N >= 4)

  			p[3] = w;

  	}
  
  	//arithmetic operators
a47a23a9   dmayerich   added ENVI functions
34
  	CUDA_CALLABLE rts::rtsPoint<T, N> operator+(rts::rtsVector<T, N> v)
f1402849   dmayerich   renewed commit
35
  	{
a47a23a9   dmayerich   added ENVI functions
36
          rts::rtsPoint<T, N> r;
f1402849   dmayerich   renewed commit
37
  
a47a23a9   dmayerich   added ENVI functions
38
          //calculate the position of the resulting rtsPoint
f1402849   dmayerich   renewed commit
39
40
41
42
43
          for(int i=0; i<N; i++)
              r.p[i] = p[i] + v.v[i];
  
          return r;
  	}
a47a23a9   dmayerich   added ENVI functions
44
  	CUDA_CALLABLE rts::rtsPoint<T, N> operator-(rts::rtsVector<T, N> v)
f1402849   dmayerich   renewed commit
45
  	{
a47a23a9   dmayerich   added ENVI functions
46
          rts::rtsPoint<T, N> r;
f1402849   dmayerich   renewed commit
47
  
a47a23a9   dmayerich   added ENVI functions
48
          //calculate the position of the resulting rtsPoint
f1402849   dmayerich   renewed commit
49
50
51
52
53
          for(int i=0; i<N; i++)
              r.p[i] = p[i] - v.v[i];
  
          return r;
  	}
a47a23a9   dmayerich   added ENVI functions
54
  	CUDA_CALLABLE rts::rtsVector<T, N> operator-(rts::rtsPoint<T, N> rhs)
f1402849   dmayerich   renewed commit
55
  	{
a47a23a9   dmayerich   added ENVI functions
56
          rts::rtsVector<T, N> r;
f1402849   dmayerich   renewed commit
57
  
a47a23a9   dmayerich   added ENVI functions
58
          //calculate the position of the resulting rtsPoint
f1402849   dmayerich   renewed commit
59
60
61
62
63
          for(int i=0; i<N; i++)
              r.v[i] = p[i] - rhs.p[i];
  
          return r;
  	}
a47a23a9   dmayerich   added ENVI functions
64
  	CUDA_CALLABLE rts::rtsPoint<T, N> operator*(T rhs)
f1402849   dmayerich   renewed commit
65
  	{
a47a23a9   dmayerich   added ENVI functions
66
          rts::rtsPoint<T, N> r;
f1402849   dmayerich   renewed commit
67
  
a47a23a9   dmayerich   added ENVI functions
68
          //calculate the position of the resulting rtsPoint
f1402849   dmayerich   renewed commit
69
70
71
72
73
74
          for(int i=0; i<N; i++)
              r.p[i] = p[i] * rhs;
  
          return r;
  	}

  

a47a23a9   dmayerich   added ENVI functions
75
  	CUDA_CALLABLE rtsPoint(const T(&data)[N])

f1402849   dmayerich   renewed commit
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
  	{

  		memcpy(p, data, sizeof(T) * N);

  	}

  

  	std::string toStr()

  	{

  		std::stringstream ss;

  

  		ss<<"(";

  		for(int i=0; i<N; i++)

  		{

  			ss<<p[i];

  			if(i != N-1)

  				ss<<", ";

  		}

  		ss<<")";

  

  		return ss.str();

  	}
  
  	//bracket operator
  	CUDA_CALLABLE T& operator[](int i)
  	{

          return p[i];
      }

  

  };
  
  }	//end namespace rts
  
  template <typename T, int N>
a47a23a9   dmayerich   added ENVI functions
107
  std::ostream& operator<<(std::ostream& os, rts::rtsPoint<T, N> p)
f1402849   dmayerich   renewed commit
108
109
110
111
112
113
114
  {
      os<<p.toStr();
      return os;
  }
  
  //arithmetic
  template <typename T, int N>
a47a23a9   dmayerich   added ENVI functions
115
  CUDA_CALLABLE rts::rtsPoint<T, N> operator*(T lhs, rts::rtsPoint<T, N> rhs)
f1402849   dmayerich   renewed commit
116
  {
a47a23a9   dmayerich   added ENVI functions
117
      rts::rtsPoint<T, N> r;
f1402849   dmayerich   renewed commit
118
119
120
121
122
123
124
  
      return rhs * lhs;
  }
  

  

  

  #endif