ViSP  2.8.0
vpSubRowVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpSubRowVector.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 vpRowVector .
36  *
37  * Authors:
38  * Laneurit Jean
39  *
40  *****************************************************************************/
41 
42 
43 #include <visp/vpSubRowVector.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  pColNum=0;
56  dsize=0;
57  trsize=0;
58  }
59 
66 vpSubRowVector::vpSubRowVector(vpRowVector &v, const unsigned int & offset,const unsigned int & ncols){
67  init(v,offset,ncols);
68 }
69 
76 void vpSubRowVector::init(vpRowVector &v, const unsigned int & offset,const unsigned int & ncols){
77 
78  if(!v.data){
79  vpERROR_TRACE("\n\t\t vpSubColvector parent vpRowVector has been destroyed");
81  "\n\t\t \n\t\t vpSubColvector parent vpRowVector has been destroyed")) ;
82  }
83 
84  if(offset+ncols<=v.getCols()){
85  data=v.data+offset;
86 
87  rowNum=1;
88  colNum = ncols;
89 
90  pColNum=v.getCols();
91  parent=&v;
92 
93  if(rowPtrs)
94  free(rowPtrs);
95 
96  rowPtrs=(double**) malloc(1 * sizeof(double*));
97  for(unsigned int i=0;i<1;i++)
98  rowPtrs[i]=v.data+i+offset;
99 
100  dsize = colNum ;
101  trsize =0 ;
102  }else{
103  vpERROR_TRACE("SubRowVector cannot be contain in parent RowVector") ;
104  throw(vpMatrixException(vpMatrixException::incorrectMatrixSizeError,"SubRowVector cannot be contain in parent RowVector")) ;
105  }
106 }
107 
109  data=NULL ;
110 }
111 
117  if(!data){
118  vpERROR_TRACE("\n\t\t vpSubColvector parent vpRowVector has been destroyed");
120  "\n\t\t \n\t\t vpSubColvector parent vpRowVector has been destroyed")) ;
121  }
122  if(pColNum!=parent->getCols()){
123  vpERROR_TRACE("\n\t\t vpSubColvector size of parent vpRowVector has been changed");
125  "\n\t\t \n\t\t vpSubColvector size of parent vpRowVector has been changed")) ;
126  }
127 }
128 
134 
135  if ( colNum != B.getCols())
136  {
137  vpERROR_TRACE("\n\t\t vpSubRowVector mismatch in operator vpSubRowVector=vpSubRowVector") ;
139  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubRowVector=vpSubRowVector")) ;
140  }
141 
142  for (unsigned int i=0;i<rowNum;i++)
143  data[i] = B[i];
144 
145  return *this;
146 }
147 
153  if ( colNum != B.getCols())
154  {
155  vpERROR_TRACE("\n\t\t vpSubRowVector mismatch in operator vpSubRowVector=vpRowVector") ;
157  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubRowVector=vpRowVector")) ;
158  }
159 
160  for (unsigned int i=0;i<rowNum;i++)
161  data[i] = B[i];
162 
163  return *this;
164 }
165 
171  if ((B.getRows()!=1)||(colNum != B.getCols()))
172  {
173  vpERROR_TRACE("\n\t\t vpSubRowVector mismatch in operator vpSubRowVector=vpMatrix") ;
175  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubRowVector=vpMatrix")) ;
176  }
177 
178  for (unsigned int i=0;i<rowNum;i++)
179  data[i] = B[i][1];
180  return *this;
181 }
187  for (unsigned int i=0;i<rowNum;i++)
188  data[i] = x;
189  return *this;
190 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
void init()
Initialization of the object matrix.
Definition: vpMatrix.cpp:93
#define vpERROR_TRACE
Definition: vpDebug.h:379
Definition of the row vector class.
Definition: vpRowVector.h:73
vpSubRowVector & operator=(const vpSubRowVector &B)
Operation such as subA = subB.
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
vpRowVector * parent
Parent vpColvector.
unsigned int pColNum
Number of row of parent vpColvector at initialization.
void checkParentStatus()
Check is parent vpRowVector has changed since initialization.
~vpSubRowVector()
Destructor.
unsigned int rowNum
number of rows
Definition: vpMatrix.h:110
Definition of the vpSubRowVector vpSubRowVector class provides a mask on a vpRowVector all properties...
unsigned int getCols() const
Return the number of columns of the matrix.
Definition: vpMatrix.h:159
error that can be emited by the vpMatrix class and its derivates
vpSubRowVector()
Default constructor.
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