ViSP  2.9.0
vpMomentCommon.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMomentCommon.cpp 4574 2014-01-09 08:48:51Z 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  * Pre-filled moment database with all commonly used moments.
36  *
37  * Authors:
38  * Filip Novotny
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpMomentCommon.h>
43 #include <visp/vpMomentObject.h>
44 
54 vpMomentCommon::vpMomentCommon(double dstSurface,std::vector<double> ref,double refAlpha,double dstZ, bool flg_sxsyfromnormalized):
55  momentBasic(),
56  momentGravity(),
57  momentCentered(),
58  momentGravityNormalized(),
59  momentSurfaceNormalized(dstSurface,dstZ),
60  momentCInvariant(),
61  momentAlpha(ref,refAlpha),
62  momentArea()
63 {
64  momentCInvariant = new vpMomentCInvariant(flg_sxsyfromnormalized);
65 
66  momentBasic.linkTo(*this);
67  momentGravity.linkTo(*this);
68  momentCentered.linkTo(*this);
69  momentGravityNormalized.linkTo(*this);
70  momentSurfaceNormalized.linkTo(*this);
71  momentCInvariant->linkTo(*this);
72  momentAlpha.linkTo(*this);
73  momentArea.linkTo(*this);
74 }
75 
130  try {
132 
133  momentGravity.compute();
134  momentCentered.compute();
135  momentAlpha.compute();
136  momentCInvariant->compute();
137 
138  momentSurfaceNormalized.compute();
139  momentGravityNormalized.compute();
140  momentArea.compute();
141 
142  } catch(const char* ex){
143  std::cout << "exception:" << ex <<std::endl;
144 
145  }
146 }
147 
153  vpMomentDatabase moments;
154 
155  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
156  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
157 
158  moments.updateAll(object);
159 
160  momentGravity.compute();
161  momentCentered.compute();
162 
163  double a;
164  if (object.getType()==vpMomentObject::DISCRETE)
165  a = momentCentered.get(2,0)+momentCentered.get(0,2);
166  else
167  a = object.get(0,0);
168 
169  return a;
170 }
171 
177  vpMomentDatabase moments;
178 
179  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
180  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
181  vpMomentAlpha momentAlpha; momentAlpha.linkTo(moments);
182 
183  moments.updateAll(object);
184  momentGravity.compute();
185  momentCentered.compute();
186  momentAlpha.compute();
187 
188  return momentAlpha.get();
189 }
190 
195 std::vector<double> vpMomentCommon::getMu3(vpMomentObject& object) {
196  vpMomentDatabase moments;
197 
198  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
199  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
200 
201  moments.updateAll(object);
202 
203  momentGravity.compute();
204  momentCentered.compute();
205 
206  std::vector<double> mu(4);
207  unsigned int idx=0;
208  for (unsigned int j=0; j<4; j++) {
209  for (unsigned int i=0; i<4; i++) {
210  if (i+j==3){
211  mu[idx] = momentCentered.get(i,j);
212  idx++;
213  }
214  }
215  }
216  return mu;
217 }
218 
220  if (momentCInvariant)
221  delete momentCInvariant;
222 }
vpMomentCommon(double dstSurface, std::vector< double > ref, double refAlpha, double dstZ=1.0, bool flg_sxsyfromnormalized=false)
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:103
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