Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpSubColVector.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 vpColVector.
32  *
33  * Authors:
34  * Laneurit Jean
35  *
36  *****************************************************************************/
37 
38 #include <stdlib.h>
39 
40 #include <visp3/core/vpSubColVector.h>
41 #include <visp3/core/vpException.h>
42 
45  : vpColVector(), pRowNum(0), parent(NULL)
46 {
47 }
48 
55 vpSubColVector::vpSubColVector(vpColVector &v, const unsigned int & offset, const unsigned int & nrows)
56  : vpColVector(), pRowNum(0), parent(NULL)
57 {
58  init(v, offset, nrows);
59 }
60 
68  const unsigned int & offset,
69  const unsigned int & nrows)
70 {
71  if (!v.data) {
73  "Cannot initialize a sub-column vector from an empty parent column vector")) ;
74  }
75 
76  if(offset+nrows<=v.getRows()){
77  data=v.data+offset;
78 
79  rowNum=nrows;
80  colNum = 1;
81 
82  pRowNum=v.getRows();
83  parent=&v;
84 
85  if(rowPtrs){
86  free(rowPtrs);
87  }
88 
89  rowPtrs=(double**)malloc( parent->getRows() * sizeof(double*));
90  for(unsigned int i=0;i<nrows;i++)
91  rowPtrs[i]=v.data+i+offset;
92 
93  dsize = rowNum ;
94  } else {
96  "Cannot create a sub-column vector that is not completely containt in the parrent column vector")) ;
97  }
98 }
99 
102  data=NULL ;
103 }
104 
111  if (!data) {
113  "The parent of the current sub-column vector has been destroyed")) ;
114  }
115  if(pRowNum!=parent->getRows()){
117  "The size of the parent sub-column vector has changed")) ;
118  }
119 }
120 
128 {
129  if ( rowNum != B.getRows()) {
131  "Cannot initialize (%dx1) sub-column vector from (%dx1) sub-column vector",
132  rowNum, B.getRows())) ;
133  }
134 
135  for (unsigned int i=0;i<rowNum;i++)
136  data[i] = B[i];
137  return *this;
138 }
139 
146 {
147  if ( rowNum != B.getRows()) {
149  "Cannot initialize (%dx1) sub-column vector from (%dx1) column vector",
150  rowNum, B.getRows())) ;
151  }
152 
153  for (unsigned int i=0;i<rowNum;i++)
154  data[i] = B[i];
155 
156  return *this;
157 }
158 
165 {
166  if ((B.getCols()!=1)||(rowNum != B.getRows())) {
168  "Cannot initialize (%dx1) sub-column vector from (%dx%d) matrix",
169  rowNum, B.getRows(), B.getCols())) ;
170  }
171 
172  for (unsigned int i=0;i<rowNum;i++)
173  data[i] = B[i][1];
174  return *this;
175 }
176 
182 {
183  for (unsigned int i=0;i<rowNum;i++)
184  data[i] = x;
185  return *this;
186 }
187 
192 {
193  unsigned int k = tv.getRows() ;
194  if (rowNum != k){
195  try {
196  resize(k);
197  }
198  catch(...)
199  {
200  throw ;
201  }
202  }
203 
204  memcpy(data, tv.data, rowNum*sizeof(double)) ;
205  return *this;
206 }
211 {
212  unsigned int k = rv.getRows() ;
213  if (rowNum != k){
214  try {
215  resize(k);
216  }
217  catch(...)
218  {
219  throw ;
220  }
221  }
222 
223  memcpy(data, rv.data, rowNum*sizeof(double)) ;
224  return *this;
225 }
230 {
231  unsigned int k = p.getRows() ;
232  if (rowNum != k){
233  try {
234  resize(k);
235  }
236  catch(...)
237  {
238  throw ;
239  }
240  }
241 
242  memcpy(data, p.data, rowNum*sizeof(double)) ;
243  return *this;
244 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
Implementation of a generic rotation vector.
vp_deprecated void init()
Definition: vpColVector.h:295
unsigned int pRowNum
Number of row of parent vpColvector at initialization.
error that can be emited by ViSP classes.
Definition: vpException.h:73
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
void checkParentStatus() const
virtual ~vpSubColVector()
Destructor that set the pointer to the parrent column vector to NULL.
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:74
vpColVector * parent
Parent vpColvector.
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
vpSubColVector & operator=(const vpSubColVector &B)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
vpSubColVector()
Default constructor that creates an empty vector.
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
Class that consider the case of a translation vector.
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:78
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:225