Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Vector4.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #include "Vector4.hh"
27 #include "Vector.hh"
28 
29 #include <iostream>
30 #include <fstream>
31 
32 using namespace BIAS;
33 using namespace std;
34 
35 template<class T>
37 {
38  // check if v has correct size:
39  BIASASSERT(v.size() == VECTOR4SIZE);
40  // set the 4 elements:
41  data_[0] = v[0];
42  data_[1] = v[1];
43  data_[2] = v[2];
44  data_[3] = v[3];
45 }
46 
47 
48 // jw
49 template<class T>
50 bool Vector4<T>::Load(const std::string & filename)
51 {
52  std::ifstream fs( filename.c_str() );
53  if (!fs) {
54  return false; // error, could not open file.
55  } else {
56  // read in
57  fs>>(*this);
58  fs.close();
59  };
60  return true;
61 }
62 
63 // jw
64 template<class T>
65 bool Vector4<T>::Save(const std::string & filename) const
66 {
67  std::ofstream fs( filename.c_str() );
68  if (!fs) {
69  return false; // error, could not open file.
70  } else {
71  // write out to disk
72  fs<<(*this);
73  fs.close();
74  };
75  return true;
76 }
77 
78 template <class T>
80  Matrix4x4<T> mat;
81  T rVal;
82  for (unsigned int row=0; row<this->Size(); row++) {
83  rVal = (*this)[row];
84  for (unsigned int col=0; col<v.Size(); col++)
85  mat[row][col] = rVal * v[col];
86  }
87  return mat;
88 }
89 
90 
91 #define INST(type) \
92 template class BIASMathBase_EXPORT BIAS::Vector4<type>;\
93 
94 INST(unsigned char)
95 INST(char)
96 INST(float)
97 INST(short)
98 INST(unsigned short)
99 INST(long int)
100 INST(int)
101 INST(unsigned int)
102 INST(double)
Matrix4x4< T > OuterProduct(const Vector4< T > &v) const
outer product, constructs a matrix.
Definition: Vector4.cpp:79
class for column vectors with arbitrary size
class Vector4 contains a Vector of dim.
Definition: Vector4.hh:65
const unsigned int Size() const
Definition: Vector4.hh:442
INST(unsigned char)
bool Load(const std::string &filename)
method to load directly from a given filename.
Definition: Vector4.cpp:50
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix4x4.hh:54
bool Save(const std::string &filename) const
method to save directly to a given filename.
Definition: Vector4.cpp:65
Subscript size() const
Definition: vec.h:262