COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coVector.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef COVISE_VECTOR_H
9 #define COVISE_VECTOR_H
10 
11 /**************************************************************************\
12  ** **
13  ** **
14  ** Description: Interface classes for application modules to the COVISE **
15  ** software environment **
16  ** **
17  ** **
18  ** **
19  ** **
20  ** **
21  ** (C)1997 RUS **
22  ** Computing Center University of Stuttgart **
23  ** Allmandring 30 **
24  ** 70550 Stuttgart **
25  ** Author: D. Rantzau **
26  ** Date: 15.08.97 V1.0 **
27 \**************************************************************************/
28 
29 #include <math.h>
30 #include <string.h>
31 #include <iostream>
32 #include <stdio.h>
33 #include "coExport.h"
34 
35 using std::ostream;
36 namespace covise
37 {
38 
39 class coMatrix;
40 
42 {
43 
44  friend class coMatrix;
45 
46 public:
47  int dim;
48  double vec4[4];
49  double *vec;
50 
52  {
53  dim = 3;
54  vec = vec4;
55  }
56 
58  {
59  dim = v.dim;
60  if (dim < 5)
61  vec = vec4;
62  else
63  vec = new double[dim];
64  for (int i = 0; i < dim; i++)
65  vec[i] = v[i];
66  }
67 
69  {
70  dim = v.dim;
71  if (dim < 5)
72  vec = vec4;
73  else
74  vec = new double[dim];
75  for (int i = 0; i < dim; i++)
76  vec[i] = v[i];
77  return *this;
78  }
79 
80  coVector(int d)
81  {
82  dim = d;
83  if (d < 5)
84  vec = vec4;
85  else
86  vec = new double[d];
87  }
88  coVector(int d, double *_val)
89  {
90  dim = d;
91  if (d < 5)
92  vec = vec4;
93  else
94  vec = new double[d];
95  for (int ctr = 0; ctr < d; ++d)
96  vec[ctr] = _val[ctr];
97  }
98 
100  {
101  if (dim > 4)
102  delete[] vec;
103  }
104 
105  coVector(double _val[3])
106  {
107  dim = 3;
108  vec = vec4;
109  vec[0] = _val[0];
110  vec[1] = _val[1];
111  vec[2] = _val[2];
112  }
113 
114  coVector(double a, double b, double c)
115  {
116  dim = 3;
117  vec = vec4;
118  vec[0] = a;
119  vec[1] = b;
120  vec[2] = c;
121  vec[3] = 1.;
122  }
123  coVector(double a, double b, double c, double d)
124  {
125  dim = 4;
126  vec = vec4;
127  vec[0] = a;
128  vec[1] = b;
129  vec[2] = c;
130  vec[3] = d;
131  }
132 
133  int operator==(coVector &v);
134 
135  coVector operator+(const coVector &v) const;
136 
137  coVector operator-(const coVector &v) const;
138 
139  coVector operator-() const;
140 
141  double operator*(const coVector &v) const;
142 
143  coVector operator*(const coMatrix &m) const;
144 
145  coVector operator*(double r) const;
146 
147  double &operator[](int i)
148  {
149  return vec[i];
150  }
151 
152  double operator[](int i) const
153  {
154  return vec[i];
155  }
156 
157  //
158  // vector operators:
159  //
160  double length() const;
161 
162  coVector scale(double f)
163  {
164  return *this * f;
165  }
166 
167  double dot(const coVector &v) const;
168 
169  coVector cross(const coVector &v) const;
170 
171  coVector eval(const coVector &v) const;
172 
173  coVector unitize() const;
174 
175  coVector negate() const;
176 
177  // print the vector:
178 
179  void print(FILE *f, char *n = 0);
180 
181  void get(double f[3])
182  {
183  f[0] = vec[0];
184  f[1] = vec[1];
185  f[2] = vec[2];
186  }
187 
188  void get(float f[3])
189  {
190  f[0] = (float)vec[0];
191  f[1] = (float)vec[1];
192  f[2] = (float)vec[2];
193  }
194 
195  coVector maximal(const coVector &v) const;
196 
197  double enclosedAngle(const coVector &v) const;
198 
199  bool isZero() const;
200 
201  coVector &normalize();
202 
203  friend ostream &operator<<(ostream &O, const coVector &v)
204  {
205  O << "[" << v[0] << "|" << v[1] << "|" << v[2] << "]";
206  return O;
207  }
208  /*{\Mbinopfunc writes $v$ componentwise to the output stream $O$.}*/
209 
210  //friend istream& operator>>(istream& I, coVector& v);
211  /*{\Mbinopfunc reads $v$ componentwise from the input stream $I$.}*/
212 };
213 }
214 #endif // COVISE_VECTOR_H
coVector(int d)
Definition: coVector.h:80
int dim
Definition: coVector.h:47
__host__ __device__ float2 operator*(float2 a, float2 b)
Definition: cutil_math.h:736
__host__ __device__ float2 normalize(float2 v)
Definition: cutil_math.h:1305
GLdouble n
Definition: khronos-glext.h:8447
GLboolean GLboolean GLboolean b
Definition: khronos-glext.h:6895
__host__ __device__ float2 operator+(float2 a, float2 b)
Definition: cutil_math.h:281
double * vec
Definition: coVector.h:49
coVector(double a, double b, double c)
Definition: coVector.h:114
__host__ __device__ float3 cross(float3 a, float3 b)
Definition: cutil_math.h:1421
Definition: coMatrix.h:35
coVector scale(double f)
Definition: coVector.h:162
coVector(double _val[3])
Definition: coVector.h:105
~coVector()
Definition: coVector.h:99
coVector & operator=(const coVector &v)
Definition: coVector.h:68
GLdouble GLdouble GLdouble r
Definition: khronos-glext.h:6457
const GLdouble * v
Definition: khronos-glext.h:6442
const GLubyte * c
Definition: khronos-glext.h:9864
GLboolean GLboolean GLboolean GLboolean a
Definition: khronos-glext.h:6895
Definition: coVector.h:41
INLINE bool operator==(const coObjID &a, const coObjID &b)
Definition: coObjID.h:166
coVector(int d, double *_val)
Definition: coVector.h:88
const GLfloat * m
Definition: khronos-glext.h:12117
double length(EDGE_VECTOR &vector)
Definition: CuttingSurfaceGPMUtil.h:70
__host__ __device__ float2 operator-(float2 &a)
Definition: cutil_math.h:252
friend ostream & operator<<(ostream &O, const coVector &v)
Definition: coVector.h:203
coVector(const coVector &v)
Definition: coVector.h:57
double operator[](int i) const
Definition: coVector.h:152
double & operator[](int i)
Definition: coVector.h:147
GLfloat f
Definition: khronos-glext.h:8258
coVector(double a, double b, double c, double d)
Definition: coVector.h:123
#define UTILEXPORT
Definition: coExport.h:182
coVector()
Definition: coVector.h:51
__host__ __device__ float dot(float2 a, float2 b)
Definition: cutil_math.h:1245