Visual Servoing Platform  version 3.0.0
vpSubRowVector.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Mask on a vpRowVector .
32  *
33  * Authors:
34  * Laneurit Jean
35  *
36  *****************************************************************************/
37 
38 #include <stdlib.h>
39 
40 #include <visp3/core/vpSubRowVector.h>
41 #include <visp3/core/vpException.h>
42 
45  : vpRowVector(), pColNum(0), parent(NULL)
46 {
47 }
48 
55 vpSubRowVector::vpSubRowVector(vpRowVector &v, const unsigned int & offset,const unsigned int & ncols)
56  : vpRowVector(), pColNum(0), parent(NULL)
57 {
58  init(v, offset, ncols);
59 }
60 
67 void vpSubRowVector::init(vpRowVector &v, const unsigned int & offset,const unsigned int & ncols)
68 {
69  if (!v.data) {
71  "Cannot initialize a sub-row vector from an empty parent row vector")) ;
72  }
73 
74  if(offset+ncols<=v.getCols()){
75  data=v.data+offset;
76 
77  rowNum=1;
78  colNum = ncols;
79 
80  pColNum=v.getCols();
81  parent=&v;
82 
83  if(rowPtrs)
84  free(rowPtrs);
85 
86  rowPtrs=(double**) malloc(1 * sizeof(double*));
87  for(unsigned int i=0;i<1;i++)
88  rowPtrs[i]=v.data+i+offset;
89 
90  dsize = colNum ;
91  } else {
93  "Cannot create a sub-row vector that is not completely containt in the parrent row vector")) ;
94  }
95 }
96 
99  data=NULL ;
100 }
101 
108 {
109  if(!data){
111  "The parent of the current sub-row vector has been destroyed")) ;
112  }
113  if(pColNum!=parent->getCols()){
115  "The size of the parent sub-row vector has changed")) ;
116  }
117 }
118 
126 {
127  if ( colNum != B.getCols()) {
129  "Cannot initialize (1x%d) sub-row vector from (1x%d) sub-row vector",
130  colNum, B.getCols())) ;
131  }
132 
133  for (unsigned int i=0;i<rowNum;i++)
134  data[i] = B[i];
135 
136  return *this;
137 }
138 
146 {
147  if ( colNum != B.getCols()) {
149  "Cannot initialize (1x%d) sub-row vector from (1x%d) row vector",
150  colNum, B.getCols())) ;
151  }
152 
153  for (unsigned int i=0;i<rowNum;i++)
154  data[i] = B[i];
155 
156  return *this;
157 }
158 
166 {
167  if ((B.getRows()!=1)||(colNum != B.getCols())) {
169  "Cannot initialize (1x%d) sub-column vector from (%dx%d) matrix",
170  colNum, B.getRows(), B.getCols())) ;
171  }
172 
173  for (unsigned int i=0;i<rowNum;i++)
174  data[i] = B[i][1];
175  return *this;
176 }
182 {
183  for (unsigned int i=0;i<rowNum;i++)
184  data[i] = x;
185  return *this;
186 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:70
error that can be emited by ViSP classes.
Definition: vpException.h:73
void checkParentStatus() const
vp_deprecated void init()
Definition: vpRowVector.h:246
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
vpSubRowVector & operator=(const vpSubRowVector &B)
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:74
vpRowVector * parent
Parent vpColvector.
unsigned int pColNum
Number of row of parent vpColvector at initialization.
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:76
virtual ~vpSubRowVector()
Destructor that set the pointer to the parrent row vector to NULL.
vpSubRowVector()
Default constructor that creates an empty vector.
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:78