ViSP  2.9.0
vpSubColVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpSubColVector.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 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  : pRowNum(0), parent(NULL)
51 {
52 }
53 
60 vpSubColVector::vpSubColVector(vpColVector &v, const unsigned int & offset, const unsigned int & nrows)
61  : pRowNum(0), parent(NULL)
62 {
63  init(v,offset,nrows);
64 }
65 
73  const unsigned int & offset,
74  const unsigned int & nrows){
75 
76  if(!v.data){
77  vpERROR_TRACE("\n\t\t vpSubColvector parent vpColVector has been destroyed");
79  "\n\t\t \n\t\t vpSubColvector parent vpColVector has been destroyed")) ;
80  }
81 
82  if(offset+nrows<=v.getRows()){
83  data=v.data+offset;
84 
85  rowNum=nrows;
86  colNum = 1;
87 
88  pRowNum=v.getRows();
89  parent=&v;
90 
91  if(rowPtrs){
92  free(rowPtrs);
93  }
94 
95  rowPtrs=(double**)malloc( parent->getRows() * sizeof(double*));
96  for(unsigned int i=0;i<nrows;i++)
97  rowPtrs[i]=v.data+i+offset;
98 
99  dsize = rowNum ;
100  trsize =0 ;
101  }else{
102  vpERROR_TRACE("SubColVector cannot be contain in parent ColVector") ;
103  throw(vpMatrixException(vpMatrixException::incorrectMatrixSizeError,"SubColVector cannot be contain in parent ColVector")) ;
104  }
105 }
106 
108  data=NULL ;
109 }
110 
111 
117  if(!data){
118  vpERROR_TRACE("\n\t\t vpSubColvector parent vpColVector has been destroyed");
120  "\n\t\t \n\t\t vpSubColvector parent vpColVector has been destroyed")) ;
121  }
122  if(pRowNum!=parent->getRows()){
123  vpERROR_TRACE("\n\t\t vpSubColvector size of parent vpColVector has been changed");
124  throw(vpMatrixException(vpMatrixException::incorrectMatrixSizeError,"\n\t\t \n\t\t vpSubColvector size of parent vpColVector has been changed")) ;
125  }
126 }
127 
133 
134  if ( rowNum != B.getRows())
135  {
136  vpERROR_TRACE("\n\t\t vpSubColVector mismatch in operator vpSubColVector=vpSubColVector") ;
138  "\n\t\t \n\t\t vpSubMatrix mismatch in operator vpSubColVector=vpSubColVector")) ;
139  }
140 
141  for (unsigned int i=0;i<rowNum;i++)
142  data[i] = B[i];
143  return *this;
144 }
145 
151  if ( rowNum != B.getRows())
152  {
153  vpERROR_TRACE("\n\t\t vpSubColVector mismatch in operator vpSubColVector=vpColVector") ;
155  "\n\t\t \n\t\t vpSubColVector mismatch in operator vpSubColVector=vpColVector")) ;
156  }
157 
158  for (unsigned int i=0;i<rowNum;i++)
159  data[i] = B[i];
160 
161  return *this;
162 }
163 
169  if ((B.getCols()!=1)||(rowNum != B.getRows()))
170  {
171  vpERROR_TRACE("\n\t\t vpSubColVector mismatch in operator vpSubColVector=vpMatrix") ;
173  "\n\t\t \n\t\t vpSubColVector mismatch in operator vpSubColVector=vpMatrix")) ;
174  }
175 
176  for (unsigned int i=0;i<rowNum;i++)
177  data[i] = B[i][1];
178  return *this;
179 }
180 
186  for (unsigned int i=0;i<rowNum;i++)
187  data[i] = x;
188  return *this;
189 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
void checkParentStatus()
Check is partent vpColVector has changed since initialization.
void init()
Initialization of the object matrix.
Definition: vpMatrix.cpp:98
#define vpERROR_TRACE
Definition: vpDebug.h:395
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: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
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:112
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:163
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: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