ViSP  2.10.0
vpFeatureMomentBasic.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureMomentImpl.cpp 3317 2011-09-06 14:14:47Z fnovotny $
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  * Implementation for all supported moment features.
36  *
37  * Authors:
38  * Filip Novotny
39  *
40  *****************************************************************************/
41 
42 
43 
44 #include <visp/vpMomentObject.h>
45 #include <visp/vpFeatureMomentBasic.h>
46 #include <visp/vpFeatureMomentDatabase.h>
47 #include <vector>
48 #include <limits>
57 vpFeatureMomentBasic::vpFeatureMomentBasic(vpMomentDatabase& data_base,double A_, double B_, double C_,vpFeatureMomentDatabase* featureMoments) :
58  vpFeatureMoment(data_base,A_,B_,C_,featureMoments), order(0)
59 {
60 }
61 
67  int delta;
68  const vpMomentObject& m = moment->getObject();
69  order = m.getOrder()+1;
71  for(std::vector< vpMatrix >::iterator i=interaction_matrices.begin();i!=interaction_matrices.end();i++)
72  i->resize(1,6);
74  delta=0;
75  } else {
76  delta=1;
77  }
78 
79  int VX = 0;
80  int VY = 1;
81  int VZ = 2;
82  int WX = 3;
83  int WY = 4;
84  int WZ = 5;
85 
86  //i=0;j=0
87  interaction_matrices[0][0][VX] = -delta*A*m.get(0, 0);
88  interaction_matrices[0][0][VY] = -delta*B*m.get(0, 0);
89  interaction_matrices[0][0][VZ] = 3*delta*(A*m.get(1, 0)+B*m.get(0, 1)+C*m.get(0, 0))-delta*C*m.get(0, 0);
90 
91  interaction_matrices[0][0][WX] = 3*delta*m.get(0, 1);
92  interaction_matrices[0][0][WY] = -3*delta*m.get(1, 0);
93  interaction_matrices[0][0][WZ] = 0;
94 
95  // int i=0;
96  for(int j=1;j<(int)order-1;j++){
97  unsigned int j_ = (unsigned int) j;
98  unsigned int jm1_ = j_ - 1;
99  unsigned int jp1_ = j_ + 1;
100 
101  interaction_matrices[j_*order][0][VX] = -delta*A*m.get(0, j_);
102  interaction_matrices[j_*order][0][VY] = -j*(A*m.get(1,jm1_)+B*m.get(0,j_)+C*m.get(0,jm1_))-delta*B*m.get(0,j_);
103  interaction_matrices[j_*order][0][VZ] = (j+3*delta)*(A*m.get(1,j_)+B*m.get(0,jp1_)+C*m.get(0,j_))-delta*C*m.get(0,j_);
104 
105  interaction_matrices[j_*order][0][WX] = (j+3*delta)*m.get(0,jp1_)+j*m.get(0,jm1_);
106  interaction_matrices[j_*order][0][WY] = -(j+3*delta)*m.get(1,j_);
107  interaction_matrices[j_*order][0][WZ] = -j*m.get(1,jm1_);
108  }
109 
110  //int j=0;
111  for(int i=1;i<(int)order-1;i++){
112  unsigned int i_ = (unsigned int) i;
113  unsigned int im1_ = i_ - 1;
114  unsigned int ip1_ = i_ + 1;
115 
116  interaction_matrices[i_][0][VX] = -i*(A*m.get(i_, 0)+B*m.get(im1_, 1)+C*m.get(im1_, 0))-delta*A*m.get(i_, 0);
117  interaction_matrices[i_][0][VY] = -delta*B*m.get(i_, 0);
118  interaction_matrices[i_][0][VZ] = (i+3*delta)*(A*m.get(ip1_, 0)+B*m.get(i_, 1)+C*m.get(i_, 0))-delta*C*m.get(i_, 0);
119 
120  interaction_matrices[i_][0][WX] = (i+3*delta)*m.get(i_, 1);
121  interaction_matrices[i_][0][WY] = -(i+3*delta)*m.get(ip1_, 0)-i*m.get(im1_, 0);
122  interaction_matrices[i_][0][WZ] = i*m.get(im1_, 1);
123  }
124 
125  for(int j=1; j<(int)order-1; j++){
126  unsigned int j_ = (unsigned int) j;
127  unsigned int jm1_ = j_ - 1;
128  unsigned int jp1_ = j_ + 1;
129 
130  for(int i=1; i<(int)order-j-1; i++){
131  unsigned int i_ = (unsigned int) i;
132  unsigned int im1_ = i_ - 1;
133  unsigned int ip1_ = i_ + 1;
134 
135  interaction_matrices[j_*order+i_][0][VX] = -i*(A*m.get(i_, j_)+B*m.get(im1_, jp1_)+C*m.get(im1_,j_))-delta*A*m.get(i_, j_);
136  interaction_matrices[j_*order+i_][0][VY] = -j*(A*m.get(ip1_, jm1_)+B*m.get(i_, j_)+C*m.get(i_,jm1_))-delta*B*m.get(i_, j_);
137  interaction_matrices[j_*order+i_][0][VZ] = (i+j+3*delta)*(A*m.get(ip1_, j_)+B*m.get(i_,jp1_)+C*m.get(i_, j_))-delta*C*m.get(i_,j_);
138 
139  interaction_matrices[j_*order+i_][0][WX] = (i+j+3*delta)*m.get(i_, jp1_)+j*m.get(i_, jm1_);
140  interaction_matrices[j_*order+i_][0][WY] = -(i+j+3*delta)*m.get(ip1_, j_)-i*m.get(im1_, j_);
141  interaction_matrices[j_*order+i_][0][WZ] = i*m.get(im1_,jp1_)-j*m.get(ip1_, jm1_);
142  }
143  }
144 }
145 
152 vpMatrix vpFeatureMomentBasic::interaction (unsigned int select_one,unsigned int select_two) const {
153  if(select_one+select_two>moment->getObject().getOrder())
154  throw vpException(vpException::badValue,"The requested value has not been computed, you should specify a higher order.");
155  return interaction_matrices[select_two*order+select_one];
156 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
const vpMoment * moment
error that can be emited by ViSP classes.
Definition: vpException.h:76
Class for generic objects.
const std::vector< double > & get() const
std::vector< vpMatrix > interaction_matrices
vpMatrix interaction(unsigned int select_one, unsigned int select_two) const
This class allows to register all vpMoments so they can access each other according to their dependen...
This class defines shared system methods/attributes for 2D moment features but no functional code...
vpObjectType getType() const
vpFeatureMomentBasic(vpMomentDatabase &moments, double A, double B, double C, vpFeatureMomentDatabase *featureMoments=NULL)
const vpMomentObject & getObject() const
Definition: vpMoment.h:121
This class allows to register all feature moments (implemented in vpFeatureMoment... classes) so they can access each other according to their dependencies.
unsigned int getOrder() const