ViSP  2.10.0
vpSubRowVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpSubRowVector.cpp 4632 2014-02-03 17:06:40Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  : pColNum(0), parent(NULL)
51 {
52 }
53 
60 vpSubRowVector::vpSubRowVector(vpRowVector &v, const unsigned int & offset,const unsigned int & ncols)
61  : pColNum(0), parent(NULL)
62 {
63  init(v, offset, ncols);
64 }
65 
72 void vpSubRowVector::init(vpRowVector &v, const unsigned int & offset,const unsigned int & ncols){
73 
74  if(!v.data){
75  vpERROR_TRACE("\n\t\t vpSubColvector parent vpRowVector has been destroyed");
77  "\n\t\t \n\t\t vpSubColvector parent vpRowVector has been destroyed")) ;
78  }
79 
80  if(offset+ncols<=v.getCols()){
81  data=v.data+offset;
82 
83  rowNum=1;
84  colNum = ncols;
85 
86  pColNum=v.getCols();
87  parent=&v;
88 
89  if(rowPtrs)
90  free(rowPtrs);
91 
92  rowPtrs=(double**) malloc(1 * sizeof(double*));
93  for(unsigned int i=0;i<1;i++)
94  rowPtrs[i]=v.data+i+offset;
95 
96  dsize = colNum ;
97  trsize =0 ;
98  }else{
99  vpERROR_TRACE("SubRowVector cannot be contain in parent RowVector") ;
100  throw(vpMatrixException(vpMatrixException::incorrectMatrixSizeError,"SubRowVector cannot be contain in parent RowVector")) ;
101  }
102 }
103 
105  data=NULL ;
106 }
107 
113  if(!data){
114  vpERROR_TRACE("\n\t\t vpSubColvector parent vpRowVector has been destroyed");
116  "\n\t\t \n\t\t vpSubColvector parent vpRowVector has been destroyed")) ;
117  }
118  if(pColNum!=parent->getCols()){
119  vpERROR_TRACE("\n\t\t vpSubColvector size of parent vpRowVector has been changed");
121  "\n\t\t \n\t\t vpSubColvector size of parent vpRowVector has been changed")) ;
122  }
123 }
124 
130 
131  if ( colNum != B.getCols())
132  {
133  vpERROR_TRACE("\n\t\t vpSubRowVector mismatch in operator vpSubRowVector=vpSubRowVector") ;
135  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubRowVector=vpSubRowVector")) ;
136  }
137 
138  for (unsigned int i=0;i<rowNum;i++)
139  data[i] = B[i];
140 
141  return *this;
142 }
143 
149  if ( colNum != B.getCols())
150  {
151  vpERROR_TRACE("\n\t\t vpSubRowVector mismatch in operator vpSubRowVector=vpRowVector") ;
153  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubRowVector=vpRowVector")) ;
154  }
155 
156  for (unsigned int i=0;i<rowNum;i++)
157  data[i] = B[i];
158 
159  return *this;
160 }
161 
167  if ((B.getRows()!=1)||(colNum != B.getCols()))
168  {
169  vpERROR_TRACE("\n\t\t vpSubRowVector mismatch in operator vpSubRowVector=vpMatrix") ;
171  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubRowVector=vpMatrix")) ;
172  }
173 
174  for (unsigned int i=0;i<rowNum;i++)
175  data[i] = B[i][1];
176  return *this;
177 }
183  for (unsigned int i=0;i<rowNum;i++)
184  data[i] = x;
185  return *this;
186 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
void init()
Initialization of the object matrix.
Definition: vpMatrix.cpp:98
#define vpERROR_TRACE
Definition: vpDebug.h:395
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:118
unsigned int trsize
Total row space.
Definition: vpMatrix.h:126
double ** rowPtrs
address of the first element of each rows
Definition: vpMatrix.h:121
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:112
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:163
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:124
unsigned int colNum
number of columns
Definition: vpMatrix.h:114
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161