All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
nurbs_defs.h
1 #ifndef NURBS_DEFS_H_
2 #define NURBS_DEFS_H_
3 
4 #include <fmatvec/fmatvec.h>
5 #include <mbsim/mbsim_event.h>
6 #include <iostream>
7 
8 namespace fmatvec {
12  template <int N>
13  class Point : public Vector<Fixed<N>, double> {
14  public:
15  Point<N>();
16 
17  Point<N>(Vector<Fixed<N>, double> pnt);
18 
19  virtual ~Point<N>();
20 
21  protected:
22  };
23 
24  template <int N>
25  Point<N>::Point() :
26  Vector<Fixed<N>, double>() {
27 
28  }
29 
30  template <int N>
31  Point<N>::Point(Vector<Fixed<N>, double> pnt) :
32  Vector<Fixed<N>, double>(pnt) {
33  }
34 
35  template <int N>
36  Point<N>::~Point() {
37  }
38 
42  template <int N>
43  class HPoint : public Vector<Fixed<N + 1>, double> {
44  public:
45  HPoint<N>();
46 
47  HPoint<N>(Vector<Fixed<N + 1>, double> pnt);
48 
49  virtual ~HPoint<N>();
50 
51  Point<N> projectW();
52 
53  double w();
54 
55  double w() const;
56 
57  protected:
58  };
59 
60  template <int N>
62  Vector<Fixed<N + 1>, double>() {
63  }
64 
65  template <int N>
66  HPoint<N>::HPoint(Vector<Fixed<N + 1>, double> pnt) :
67  Vector<Fixed<N + 1>, double>(pnt) {
68  }
69 
70  template <int N>
71  HPoint<N>::~HPoint() {
72  }
73 
74  template <int N>
75  Point<N> HPoint<N>::projectW() {
76  Point<N> pnt;
77  for (int i = 0; i < N; i++)
78  pnt(i) = (*this)(i);
79  return pnt;
80  }
81 
82  template <int N>
83  double HPoint<N>::w() {
84  return (*this)(N);
85  }
86 
87  template <int N>
88  double HPoint<N>::w() const {
89  return (*this)(N);
90  }
91 
92  /*mathematical operations*/
93  template <int N>
94  Point<N> project(const HPoint<N> & hPnt) {
95  Point<N> pnt;
96  for (int i = 0; i < N; i++)
97  pnt(i) = hPnt(i) / hPnt.w();
98  return pnt;
99  }
100 // /*!
101 // * \brief wrapper class for nurbs surface interpolating data point
102 // */
103 
104  template <typename T>
106  public:
107  GeneralMatrix();
108  GeneralMatrix(int nrows_, int ncols_);
110  ~GeneralMatrix();
111 
112  GeneralMatrix<T>& operator=(const GeneralMatrix<T>& m);
113 
114  T& operator()(int i, int j);
115  T const& operator()(int i, int j) const;
116  int rows() const;
117  int cols() const;
118  void resize(int nrows_, int ncols_);
119  template <typename J>
120  friend std::ostream& operator<<(std::ostream &os, const GeneralMatrix<J> &A);
121  private:
122  int nrows, ncols;
123  T* data;
124  };
125 
126  template <typename T>
128  nrows(0), ncols(0), data(NULL) {
129  }
130 
131  template <typename T>
132  inline GeneralMatrix<T>::GeneralMatrix(int nrows_, int ncols_) :
133  nrows(nrows_), ncols(ncols_) {
134  if (nrows_ == 0 || ncols_ == 0)
135  throw MBSim::MBSimError("(GeneralMatrix:: The number of rows or columns of the matrix is zero!)");
136  data = new T[nrows_ * ncols_];
137  }
138  template <typename T>
139  inline GeneralMatrix<T>::GeneralMatrix(const GeneralMatrix<T>& m) :
140  nrows(m.nrows), ncols(m.ncols) {
141  data = new T[nrows * ncols];
142  std::copy(m.data, m.data + nrows * ncols, data);
143  }
144 
145  template <typename T>
146  inline GeneralMatrix<T>::~GeneralMatrix() {
147  delete[] data;
148  }
149 
150  template <typename T>
151  inline GeneralMatrix<T>& GeneralMatrix<T>::operator=(const GeneralMatrix<T>& m) {
152  nrows = m.nrows;
153  ncols = m.ncols;
154  data = m.data;
155  return *this;
156  }
157 
158  template <typename T>
159  inline T& GeneralMatrix<T>::operator()(int row, int col) {
160  if (row >= nrows || col >= ncols)
161  throw MBSim::MBSimError("(GeneralMatrix::operator(): trying to access data out of range of the GeneralMatrix!)");
162  return data[row * ncols + col];
163  }
164 
165  template <typename T>
166  inline T const& GeneralMatrix<T>::operator()(int row, int col) const {
167  if (row >= nrows || col >= ncols)
168  throw MBSim::MBSimError("(GeneralMatrix::operator(): trying to access data out of range of the GeneralMatrix!)");
169  return data[row * ncols + col];
170  }
171 
172  template <typename T>
173  inline int GeneralMatrix<T>::rows() const {
174  return nrows;
175  }
176 
177  template <typename T>
178  inline int GeneralMatrix<T>::cols() const {
179  return ncols;
180  }
181 
182  template <typename T>
183  void GeneralMatrix<T>::resize(int nrows_, int ncols_) {
184 
185  if (nrows_ <= 0 || ncols_ <= 0) {
186  throw MBSim::MBSimError("(GeneralMatrix::resize(): non-positive resize number of rows or columns!)");
187  return;
188  }
189 
190  if (nrows_ == nrows && ncols_ == ncols)
191  return;
192 
193  T* newData = new T[nrows_ * ncols_];
194 
195  delete[] data;
196  data = newData;
197  nrows = nrows_;
198  ncols = ncols_;
199  }
200 
201  template <typename T>
202  std::ostream& operator<<(std::ostream &os, const GeneralMatrix<T> &A) {
203  os << A.rows() << " x " << A.cols() << std::endl;
204  os << " = " << std::endl;
205  os << "[ ";
206  for (int i = 0; i < A.rows(); ++i) {
207  for (int j = 0; j < A.cols(); ++j) {
208  os << trans(A.data[i * A.ncols + j]);
209  }
210  if (i != A.rows() - 1)
211  os << std::endl << " ";
212  }
213  os << " ];";
214  return os;
215  }
216 
217 }
218 
219 #endif
wrapper class for nurbs type HPoint
Definition: nurbs_defs.h:43
wrapper class for nurbs type Point
Definition: nurbs_defs.h:13
RowVector< Ref, AT > trans(const Vector< Ref, AT > &x)
basic error class for mbsim
Definition: mbsim_event.h:38
wrapper class for nurbs surface interpolating data point
Definition: nurbs_defs.h:105

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML