00001 /* 00002 * lib-gmapkernel : Un noyau de 3-G-cartes et des opérations. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-gmapkernel 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 //****************************************************************************** 00025 #include "transformation-matrix.hh" 00026 00027 #include <cassert> 00028 //****************************************************************************** 00029 INLINE 00030 CVector::CVector(TVectorType AType) 00031 { 00032 FElements = new TCoordinate[4]; 00033 00034 if (AType==NullVector) 00035 setToNull(); 00036 } 00037 //****************************************************************************** 00038 INLINE 00039 CVector::CVector(const CVector& AVector) 00040 { 00041 FElements = new TCoordinate[4]; 00042 00043 for (int i=0; i<4; ++i) 00044 (*this)[i] = AVector[i]; 00045 } 00046 //****************************************************************************** 00047 INLINE 00048 CVector::CVector(TCoordinate A0, TCoordinate A1, TCoordinate A2, TCoordinate A3) 00049 { 00050 FElements = new TCoordinate[4]; 00051 00052 FElements[0] = A0; 00053 FElements[1] = A1; 00054 FElements[2] = A2; 00055 FElements[3] = A3; 00056 } 00057 //****************************************************************************** 00058 INLINE 00059 CVector::~CVector() 00060 { 00061 delete [] FElements; 00062 } 00063 //****************************************************************************** 00064 INLINE 00065 void CVector::setToNull() 00066 { 00067 for (int i=0; i<4; ++i) 00068 FElements[i] = 0; 00069 } 00070 //****************************************************************************** 00071 INLINE 00072 CVector& CVector::operator=(const CVector& AVector) 00073 { 00074 if (&AVector != this) 00075 for (int i=0; i<4; ++i) 00076 FElements[i] = AVector.FElements[i]; 00077 00078 return *this; 00079 } 00080 //****************************************************************************** 00081 INLINE 00082 TCoordinate& CVector::operator[](int AIndex) const 00083 { 00084 assert(0 <= AIndex && AIndex <= 3); 00085 00086 return FElements[AIndex]; 00087 } 00088 //****************************************************************************** 00089 INLINE 00090 CVector CVector::operator*(const CTransformationMatrix& AMatrix) const 00091 { 00092 CVector temp(NullVector); 00093 00094 for (int row=0; row<4; ++row) 00095 for (int col=0; col<4; ++col) 00096 temp[col] += 00097 (*this)[row] * AMatrix[row][col]; 00098 00099 return temp; 00100 } 00101 //****************************************************************************** 00102 INLINE 00103 TCoordinate CVector::operator*(const CVector& AVector) const 00104 { 00105 TCoordinate temp = 0; 00106 00107 for (int k=0; k<4; ++k) 00108 temp += 00109 (*this)[k] * AVector[k]; 00110 00111 return temp; 00112 } 00113 //****************************************************************************** 00114 INLINE 00115 std::ostream& operator<<(std::ostream& AStream, const CVector& AVector) 00116 { 00117 AStream << std::endl; 00118 00119 AStream << "["; 00120 00121 for (int i=0; i<4; ++i) 00122 AStream << AVector[i] << "\t"; 00123 // AStream.form("% .3f ", AVector[i]); 00124 00125 AStream << "]" << std::endl; 00126 00127 return AStream; 00128 } 00129 //******************************************************************************