ViSP  2.8.0
vpMomentCommon.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMomentCommon.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 
53 vpMomentCommon::vpMomentCommon(double dstSurface,std::vector<double> ref,double refAlpha,double dstZ):
54  momentBasic(),
55  momentGravity(),
56  momentCentered(),
57  momentGravityNormalized(),
58  momentSurfaceNormalized(dstSurface,dstZ),
59  momentCInvariant(),
60  momentAlpha(ref,refAlpha),
61  momentArea()
62 {
63  momentBasic.linkTo(*this);
64  momentGravity.linkTo(*this);
65  momentCentered.linkTo(*this);
66  momentGravityNormalized.linkTo(*this);
67  momentSurfaceNormalized.linkTo(*this);
68  momentCInvariant.linkTo(*this);
69  momentAlpha.linkTo(*this);
70  momentArea.linkTo(*this);
71 }
72 
127  try {
129 
130  momentGravity.compute();
131  momentCentered.compute();
132  momentAlpha.compute();
133  momentCInvariant.compute();
134 
135  momentSurfaceNormalized.compute();
136  momentGravityNormalized.compute();
137  momentArea.compute();
138 
139  } catch(const char* ex){
140  std::cout << "exception:" << ex <<std::endl;
141 
142  }
143 
144 }
145 
151  vpMomentDatabase moments;
152 
153  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
154  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
155 
156  moments.updateAll(object);
157 
158  momentGravity.compute();
159  momentCentered.compute();
160 
161  double a;
162  if (object.getType()==vpMomentObject::DISCRETE)
163  a = momentCentered.get(2,0)+momentCentered.get(0,2);
164  else
165  a = object.get(0,0);
166 
167  return a;
168 
169 }
170 
176  vpMomentDatabase moments;
177 
178  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
179  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
180  vpMomentAlpha momentAlpha; momentAlpha.linkTo(moments);
181 
182  moments.updateAll(object);
183  momentGravity.compute();
184  momentCentered.compute();
185  momentAlpha.compute();
186 
187  return momentAlpha.get();
188 }
189 
194 std::vector<double> vpMomentCommon::getMu3(vpMomentObject& object){
195  vpMomentDatabase moments;
196 
197  vpMomentGravityCenter momentGravity;momentGravity.linkTo(moments);
198  vpMomentCentered momentCentered;momentCentered.linkTo(moments);
199 
200  moments.updateAll(object);
201 
202  momentGravity.compute();
203  momentCentered.compute();
204 
205  std::vector<double> mu(4);
206  unsigned int idx=0;
207  for (unsigned int i=0; i<4; i++) {
208  for (unsigned int j=0; j<4; j++) {
209  if (i+j==3){
210  mu[idx] = momentCentered.get(j,i);
211  idx++;
212  }
213  }
214  }
215  return mu;
216 }
vpMomentCommon(double dstSurface, std::vector< double > ref, double refAlpha, double dstZ=1.0)
static double getAlpha(vpMomentObject &objec)
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:104
double get(unsigned int i, unsigned int j)
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...
static double getSurface(vpMomentObject &object)
Class describing 2D gravity center moment.
void updateAll(vpMomentObject &object)