ViSP  2.8.0
vpSubColVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpSubColVector.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Mask on a vpColVector .
36  *
37  * Authors:
38  * Laneurit Jean
39  *
40  *****************************************************************************/
41 
42 
43 #include <visp/vpSubColVector.h>
44 #include <visp/vpException.h>
45 #include <visp/vpMatrixException.h>
46 #include <visp/vpDebug.h>
47 #include <stdlib.h>
48 
50  data=NULL;
51  parent=NULL;
52  rowPtrs=NULL;
53  rowNum=0;
54  colNum=0;
55  pRowNum=0;
56  dsize=0;
57  trsize=0;
58 }
59 
66 vpSubColVector::vpSubColVector(vpColVector &v, const unsigned int & offset,const unsigned int & nrows){
67  init(v,offset,nrows);
68 }
69 
77  const unsigned int & offset,
78  const unsigned int & nrows){
79 
80  if(!v.data){
81  vpERROR_TRACE("\n\t\t vpSubColvector parent vpColVector has been destroyed");
83  "\n\t\t \n\t\t vpSubColvector parent vpColVector has been destroyed")) ;
84  }
85 
86  if(offset+nrows<=v.getRows()){
87  data=v.data+offset;
88 
89  rowNum=nrows;
90  colNum = 1;
91 
92  pRowNum=v.getRows();
93  parent=&v;
94 
95  if(rowPtrs){
96  free(rowPtrs);
97  }
98 
99  rowPtrs=(double**)malloc( parent->getRows() * sizeof(double*));
100  for(unsigned int i=0;i<nrows;i++)
101  rowPtrs[i]=v.data+i+offset;
102 
103  dsize = rowNum ;
104  trsize =0 ;
105  }else{
106  vpERROR_TRACE("SubColVector cannot be contain in parent ColVector") ;
107  throw(vpMatrixException(vpMatrixException::incorrectMatrixSizeError,"SubColVector cannot be contain in parent ColVector")) ;
108  }
109 }
110 
112  data=NULL ;
113 }
114 
115 
121  if(!data){
122  vpERROR_TRACE("\n\t\t vpSubColvector parent vpColVector has been destroyed");
124  "\n\t\t \n\t\t vpSubColvector parent vpColVector has been destroyed")) ;
125  }
126  if(pRowNum!=parent->getRows()){
127  vpERROR_TRACE("\n\t\t vpSubColvector size of parent vpColVector has been changed");
128  throw(vpMatrixException(vpMatrixException::incorrectMatrixSizeError,"\n\t\t \n\t\t vpSubColvector size of parent vpColVector has been changed")) ;
129  }
130 }
131 
137 
138  if ( rowNum != B.getRows())
139  {
140  vpERROR_TRACE("\n\t\t vpSubColVector mismatch in operator vpSubColVector=vpSubColVector") ;
142  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubColVector=vpSubColVector")) ;
143  }
144 
145  for (unsigned int i=0;i<rowNum;i++)
146  data[i] = B[i];
147  return *this;
148 }
149 
155  if ( rowNum != B.getRows())
156  {
157  vpERROR_TRACE("\n\t\t vpSubColVector mismatch in operator vpSubColVector=vpColVector") ;
159  "\n\t\t \n\t\t vpSubColVector mismatch in operator vpSubColVector=vpColVector")) ;
160  }
161 
162  for (unsigned int i=0;i<rowNum;i++)
163  data[i] = B[i];
164 
165  return *this;
166 }
167 
173  if ((B.getCols()!=1)||(rowNum != B.getRows()))
174  {
175  vpERROR_TRACE("\n\t\t vpSubColVector mismatch in operator vpSubColVector=vpMatrix") ;
177  "\n\t\t \n\t\t vpSubColVector mismatch in operator vpSubColVector=vpMatrix")) ;
178  }
179 
180  for (unsigned int i=0;i<rowNum;i++)
181  data[i] = B[i][1];
182  return *this;
183 }
184 
190  for (unsigned int i=0;i<rowNum;i++)
191  data[i] = x;
192  return *this;
193 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
void checkParentStatus()
Check is partent vpColVector has changed since initialization.
void init()
Initialization of the object matrix.
Definition: vpMatrix.cpp:93
#define vpERROR_TRACE
Definition: vpDebug.h:379
unsigned int pRowNum
Number of row of parent vpColvector at initialization.
~vpSubColVector()
Destructor.
double * data
address of the first element of the data array
Definition: vpMatrix.h:116
unsigned int trsize
Total row space.
Definition: vpMatrix.h:124
double ** rowPtrs
address of the first element of each rows
Definition: vpMatrix.h:119
vpColVector * parent
Parent vpColvector.
Definition of the vpSubColVector vpSubColVector class provides a mask on a vpColVector all properties...
unsigned int rowNum
number of rows
Definition: vpMatrix.h:110
vpSubColVector & operator=(const vpSubColVector &B)
Operation such as subA = subB.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
unsigned int getCols() const
Return the number of columns of the matrix.
Definition: vpMatrix.h:159
vpSubColVector()
Default constructor.
error that can be emited by the vpMatrix class and its derivates
unsigned int dsize
Current size (rowNum * colNum)
Definition: vpMatrix.h:122
unsigned int colNum
number of columns
Definition: vpMatrix.h:112
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:157