35#ifndef AIMS_MOMENT_MOMENT_H
36#define AIMS_MOMENT_MOMENT_H
41#include <cartodata/volume/volume.h>
42#include <aims/mesh/surface.h>
43#include <aims/bucket/bucket.h>
47template<
class T >
class Moment;
98 double cx()
const {
return _cx; }
99 double cy()
const {
return _cy; }
113 const double&
m0()
const {
return _m0; }
116 const double *
m1()
const {
return &
_m1[ 0 ]; }
118 const double *
m2()
const {
return &
_m2[ 0 ]; }
120 const double *
m3()
const {
return &
_m3[ 0 ]; }
129 virtual void update(
double,
double,
double,
int );
163template<
class T >
inline
170template<
class T >
inline
179 for ( i=0; i<3; i++ )
182 _m1[ i ] = other.
m1()[ i ];
184 for ( i=0; i<6; i++ )
_m2[ i ] = other.
m2()[ i ];
185 for ( i=0; i<9; i++ )
_m3[ i ] = other.
m3()[ i ];
189template<
class T >
inline
221#pragma GCC diagnostic push
222#pragma GCC diagnostic ignored "-Woverloaded-virtual"
223template<
class T >
inline
226 update( (
double)pt[ 0 ], (
double)pt[ 1 ], (
double)pt[ 2 ], dir );
230template<
class T >
inline
233 update( pt[ 0 ], pt[ 1 ], pt[ 2 ], dir );
237template<
class T >
inline
242#pragma GCC diagnostic pop
245template<
class T >
inline
249 carto::AllocatorContext::fast() );
264template<
class T >
inline
269 out <<
"Image geometry: (" << mom.
cx() <<
"x" << mom.
cy() <<
"x" << mom.
cz();
270 out <<
")" << std::endl <<
"Volume : " << mom.
m0() <<
"mm3" << std::endl;
271 out <<
"Number of points : " << mom.
sum() << std::endl;
272 out <<
"Volume (mm3) : " << mom.
m0() << std::endl;
273 out <<
"Order 1 moments : ";
274 for ( i=0; i<3; i++ ) out << mom.
m1()[ i ] <<
" ";
275 out << std::endl <<
"Order 2 moments : ";
276 for ( i=0; i<6; i++ ) out << mom.
m2()[ i ] <<
" ";
277 out << std::endl <<
"Order 3 moments : ";
278 for ( i=0; i<10; i++ ) out << mom.
m3()[ i ] <<
" ";
279 out << std::endl <<
"Center of Mass : (" << mom.
gravity()[ 0 ] <<
",";
280 out << mom.
gravity()[ 1 ] <<
"," << mom.
gravity()[ 2 ] <<
")" << std::endl;
281 out <<
"Orientation :" << std::endl <<
" Inerty : ";
284 out << std::endl <<
" V1 : (" << mom.
eigenVector()( 0, 0 ) <<
",";
286 out << std::endl <<
" V2 : (" << mom.
eigenVector()( 0, 1 ) <<
",";
288 out << std::endl <<
" V3 : (" << mom.
eigenVector()( 0, 2 ) <<
",";
295template<
class T >
inline
305 else if( m.
_sum == 0 )
330 double m20 = m.
_m2[0];
331 double m21 = m.
_m2[1];
332 double m22 = m.
_m2[2];
333 double m23 = m.
_m2[3];
334 double m24 = m.
_m2[4];
335 double m25 = m.
_m2[5];
337 double h0 = m.
_m1[0] / m.
_m0;
338 double h1 = m.
_m1[1] / m.
_m0;
339 double h2 = m.
_m1[2] / m.
_m0;
347 _m3[0] += m.
_m3[0] + m.
_m0*h0*h0*h0 + h0*m20*3;
348 _m3[1] += m.
_m3[1] + m.
_m0*h1*h1*h1 + h1*m21*3;
349 _m3[2] += m.
_m3[2] + m.
_m0*h2*h2*h2 + h2*m22*3;
350 _m3[3] += m.
_m3[3] + m.
_m0*h0*h0*h1 + h0*m23*2 + h1*m20;
351 _m3[4] += m.
_m3[4] + m.
_m0*h0*h0*h2 + h0*m24*2 + h2*m20;
352 _m3[5] += m.
_m3[5] + m.
_m0*h0*h1*h1 + h0*m21 + h1*m23*2;
353 _m3[6] += m.
_m3[6] + m.
_m0*h1*h1*h2 + h1*m25*2 + h2*m21;
354 _m3[7] += m.
_m3[7] + m.
_m0*h0*h2*h2 + h0*m22 + h2*m24*2;
355 _m3[8] += m.
_m3[8] + m.
_m0*h1*h2*h2 + h1*m22 + h2*m25*2;
356 _m3[9] += m.
_m3[9] + m.
_m0*h0*h1*h2 + h0*m25 + h1*m24 +h2*m23;
399template<
class T >
inline
408#pragma GCC diagnostic push
409#pragma GCC diagnostic ignored "-Woverloaded-virtual"
413 std::clog <<
"PROGRAMMING ERROR: called unimplemented base method"
414 " Moment<T>::doit( VolumeRef< T >&, T, int )"
417 throw std::logic_error(
"called unimplemented base method"
418 " Moment<T>::doit( VolumeRef< T >&, T, int )");
425 std::clog <<
"PROGRAMMING ERROR: called unimplemented base method"
426 " Moment<T>::doit( AimsSurfaceTriangle& )"
429 throw std::logic_error(
"called unimplemented base method"
430 " Moment<T>::doit( AimsSurfaceTriangle& )");
437 std::clog <<
"PROGRAMMING ERROR: called unimplemented base method"
438 " Moment<T>::doit( const aims::BucketMap<Void> & )"
441 throw std::logic_error(
"called unimplemented base method"
442 " Moment<T>::doit( const aims::BucketMap<Void> & )");
445#pragma GCC diagnostic pop
void sort(carto::VolumeRef< T > eigenvectors, carto::VolumeRef< T > eigenvalues, carto::VolumeRef< T > *wi=NULL)
Sort the eigenvectors and eigenvalues in decreasing order.
carto::VolumeRef< T > doit(carto::VolumeRef< T >, carto::VolumeRef< T > *wi=NULL)
Eigen system resolution function.
const double & sum() const
carto::VolumeRef< double > _eigenValue
virtual void update(AimsVector< double, 3 > &, int)
virtual void doit(const aims::BucketMap< Void > &)
const double * m3() const
Moment< T > & operator+=(const Moment< T > &)
const carto::VolumeRef< double > & eigenValue() const
const double * m1() const
Moment(const Moment< T > &)
const carto::VolumeRef< double > & eigenVector() const
carto::VolumeRef< double > _eigenVector
const double * gravity() const
virtual void orientation()
const double * m2() const
virtual void doit(AimsSurfaceTriangle &)
const double & m0() const
virtual void doit(carto::rc_ptr< carto::Volume< T > > &, T, int)
Moment()
doesn't necessarily clear all moments to 0. Call clear() to be sure
virtual void update(Point3df &, int)
Moment< T > operator+(const Moment< T > &)
virtual void update(double, double, double, int)
std::ostream & operator<<(std::ostream &, const Moment< T > &)
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
AimsVector< float, 3 > Point3df