[vtk-developers] Proposed CenterOfMass function for vtkPoints

Biddiscombe, John A. biddisco at cscs.ch
Thu Apr 1 10:17:13 EDT 2010


> Also, if you wanted to optimize this method, I'd suggest using
> GetValue()/GetTupleValue() (you would have to use some sort of macro

Here's an extract from my own templated version

JB

//----------------------------------------------------------------------------
template <typename T>
void WeightedSum(T* data, double mass, double *weightedsum) {
  weightedsum[0] += data[0]*mass;
  weightedsum[1] += data[1]*mass;
  weightedsum[2] += data[2]*mass;
}
//----------------------------------------------------------------------------
void vtkCenterOfMassFilter::UpdateCenterOfMassVariables(  
  double &totalMass, double totalWeightedMass[])
{
  vtkIdType index = 0;
  for (vtkIdType id=0; id<this->NumberOfPoints; ++id)
  {
    double mass=this->MassArray->GetTuple1(id);
    if (this->dPointData) {
      WeightedSum<double>(&this->dPointData[index], mass, totalWeightedMass);
    }
    else {
      WeightedSum<float>(&this->fPointData[index], mass, totalWeightedMass);
    }
    totalMass += mass;
    index += 3;
  }
}



> -----Original Message-----
> From: vtk-developers-bounces at vtk.org [mailto:vtk-developers-bounces at vtk.org]
> On Behalf Of Berk Geveci
> Sent: 01 April 2010 15:27
> To: David Doria
> Cc: VTK Developers; Will Schroeder
> Subject: Re: [vtk-developers] Proposed CenterOfMass function for vtkPoints
> 
> Can you post your latest implementation?
> 
> Also, if you wanted to optimize this method, I'd suggest using
> GetValue()/GetTupleValue() (you would have to use some sort of macro
> and a templated function). GetPoint() ends up calling GetTuple() which
> is virtual.
> 
> -berk
> 
> On Thu, Apr 1, 2010 at 9:12 AM, David Doria <daviddoria+vtk at gmail.com>
> wrote:
> > On Thu, Apr 1, 2010 at 8:52 AM, Will Schroeder
> > <will.schroeder at kitware.com> wrote:
> >> David-
> >>
> >> The phrase center of mass is an issue for many reasons, first if the
> >> dataset has cells that are curved (higher order cells) your assumption
> >> may not hold. Second, there is no mention of mass in the dataset API
> >> and this will confuse people.
> >
> > This is a moot point because I think GetPointsCenter is more clear
> > anyway (since there is no concept of mass, like you said), but since
> > this function is in vtkPoints there is no concept of "cells" to
> > interfere with anything - it is simply the center of the points.
> >
> > Ok, so what's the process from here? Do we wait a few days for more
> > comments/suggestions?
> >
> > David
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtk-developers
> >
> >
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers




More information about the vtk-developers mailing list