Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vector.h
1 
2 /***************************************************************************
3  * vector.h - Column Vector
4  *
5  * Created: Wed April 02 14:03:32 2008
6  * Copyright 2008 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __GEOMETRY_VECTOR_H_
25 #define __GEOMETRY_VECTOR_H_
26 
27 #include <ostream>
28 
29 namespace fawkes {
30 
31 class Vector
32 {
33  public:
34  Vector(unsigned int size = 3, float* elems = 0, bool manage_memory = true);
35  Vector(const Vector& v);
36  virtual ~Vector();
37 
38  unsigned int size() const;
39  void set_size(unsigned int size);
40 
41  float* data_ptr() { return m_data; }
42  const float* data_ptr() const { return m_data; }
43 
44  float get(unsigned int d) const;
45  float& get(unsigned int d);
46  void set(unsigned int d, float v);
47 
48  float x() const;
49  float& x();
50  void x(float x);
51 
52  float y() const;
53  float& y();
54  void y(float y);
55 
56  float z() const;
57  float& z();
58  void z(float z);
59 
60  float operator[](unsigned int d) const;
61  float& operator[](unsigned int d);
62 
63  Vector operator*(const float& f) const;
64  Vector& operator*=(const float& f);
65  Vector operator/(const float& f) const;
66  Vector& operator/=(const float& f);
67 
68  float operator*(const Vector& v) const;
69 
70  Vector operator+(const Vector& v) const;
71  Vector& operator+=(const Vector& v);
72  Vector operator-(const Vector& v) const;
73  Vector& operator-=(const Vector& v);
74  Vector& operator=(const Vector& v);
75 
76  bool operator==(const Vector& v);
77 
78  void print_info(const char* name = 0) const;
79 
80  friend std::ostream& operator<<(std::ostream& stream, const Vector &v);
81 
82  private:
83  unsigned int m_size;
84  float* m_data;
85  bool m_manage_memory;
86 };
87 
88 } // end namespace fawkes
89 
90 #endif /* __GEOMETRY_VECTOR_H_ */
float * data_ptr()
Get pointer to the internal data container.
Definition: vector.h:41
const float * data_ptr() const
Get pointer to the internal data container.
Definition: vector.h:42
float z() const
Convenience getter to obtain the third element.
Definition: vector.cpp:248
Vector operator+(const Vector &v) const
Adds two vectors.
Definition: vector.cpp:363
Vector operator*(const float &f) const
Multiply the vector with a scalar.
Definition: vector.cpp:307
Vector(unsigned int size=3, float *elems=0, bool manage_memory=true)
Constructor.
Definition: vector.cpp:60
A simple column vector.
Definition: vector.h:31
friend std::ostream & operator<<(std::ostream &stream, const Vector &v)
Appends the components of the Vector to the ostream.
Definition: vector.cpp:513
void set_size(unsigned int size)
Set a new size.
Definition: vector.cpp:120
float x() const
Convenience getter to obtain the first element.
Definition: vector.cpp:192
Vector & operator/=(const float &f)
In-place scalar division.
Definition: vector.cpp:350
Vector operator-(const Vector &v) const
Substract two vectors.
Definition: vector.cpp:399
unsigned int size() const
Get the number of elements.
Definition: vector.cpp:111
void print_info(const char *name=0) const
Prints the vector data to standard out.
Definition: vector.cpp:478
Vector & operator*=(const float &f)
In-place scalar multiplication.
Definition: vector.cpp:322
float operator[](unsigned int d) const
Access operator.
Definition: vector.cpp:277
bool operator==(const Vector &v)
Comparison operator.
Definition: vector.cpp:459
virtual ~Vector()
Destructor.
Definition: vector.cpp:99
Vector & operator+=(const Vector &v)
In-place vector addition.
Definition: vector.cpp:382
Vector & operator-=(const Vector &v)
In-place vector substraction.
Definition: vector.cpp:418
Vector & operator=(const Vector &v)
Assignment operator.
Definition: vector.cpp:435
void set(unsigned int d, float v)
Set a certain element.
Definition: vector.cpp:176
float y() const
Convenience getter to obtain the second element.
Definition: vector.cpp:220
Vector operator/(const float &f) const
Divide every element of the vector by a scalar.
Definition: vector.cpp:335