Visual Servoing Platform  version 3.0.0
vpMomentCommon.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  * Pre-filled moment database with all commonly used moments.
32  *
33  * Authors:
34  * Filip Novotny
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpMomentCommon.h>
39 #include <visp3/core/vpMomentObject.h>
40 
50 vpMomentCommon::vpMomentCommon(double dstSurface,std::vector<double> ref,double refAlpha,double dstZ, bool flg_sxsyfromnormalized)
51  : vpMomentDatabase(), momentBasic(), momentGravity(), momentCentered(), momentGravityNormalized(),
52  momentSurfaceNormalized(dstSurface,dstZ), momentCInvariant(), momentAlpha(ref,refAlpha),
53  momentArea()
54 {
55  momentCInvariant = new vpMomentCInvariant(flg_sxsyfromnormalized);
56 
57  momentBasic.linkTo(*this);
58  momentGravity.linkTo(*this);
59  momentCentered.linkTo(*this);
60  momentGravityNormalized.linkTo(*this);
61  momentSurfaceNormalized.linkTo(*this);
62  momentCInvariant->linkTo(*this);
63  momentAlpha.linkTo(*this);
64  momentArea.linkTo(*this);
65 }
66 
121  try {
123 
124  momentGravity.compute();
125  momentCentered.compute();
126  momentAlpha.compute();
127  momentCInvariant->compute();
128 
129  momentSurfaceNormalized.compute();
130  momentGravityNormalized.compute();
131  momentArea.compute();
132 
133  } catch(const char* ex){
134  std::cout << "exception:" << ex <<std::endl;
135 
136  }
137 }
138 
144  vpMomentDatabase moments;
145 
146  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
147  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
148 
149  moments.updateAll(object);
150 
151  momentGravity.compute();
152  momentCentered.compute();
153 
154  double a;
155  if (object.getType()==vpMomentObject::DISCRETE)
156  a = momentCentered.get(2,0)+momentCentered.get(0,2);
157  else
158  a = object.get(0,0);
159 
160  return a;
161 }
162 
168  vpMomentDatabase moments;
169 
170  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
171  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
172  vpMomentAlpha momentAlpha; momentAlpha.linkTo(moments);
173 
174  moments.updateAll(object);
175  momentGravity.compute();
176  momentCentered.compute();
177  momentAlpha.compute();
178 
179  return momentAlpha.get();
180 }
181 
186 std::vector<double> vpMomentCommon::getMu3(vpMomentObject& object) {
187  vpMomentDatabase moments;
188 
189  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
190  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
191 
192  moments.updateAll(object);
193 
194  momentGravity.compute();
195  momentCentered.compute();
196 
197  std::vector<double> mu(4);
198  unsigned int idx=0;
199  for (unsigned int j=0; j<4; j++) {
200  for (unsigned int i=0; i<4; i++) {
201  if (i+j==3){
202  mu[idx] = momentCentered.get(i,j);
203  idx++;
204  }
205  }
206  }
207  return mu;
208 }
209 
211  if (momentCInvariant)
212  delete momentCInvariant;
213 }
vpMomentCommon(double dstSurface, std::vector< double > ref, double refAlpha, double dstZ=1.0, bool flg_sxsyfromnormalized=false)
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:99
Class for generic objects.
This class allows to register all vpMoments so they can access each other according to their dependen...
static std::vector< double > getMu3(vpMomentObject &object)
virtual void updateAll(vpMomentObject &object)
This class defines the double-indexed centered moment descriptor .
This class defines the orientation of the object inside the plane parallel to the object...
double get(unsigned int i, unsigned int j) const
static double getSurface(vpMomentObject &object)
Class describing 2D gravity center moment.
void updateAll(vpMomentObject &object)
static double getAlpha(vpMomentObject &object)
double get() const