Difference between revisions of "VTK/Examples/Cxx/PolyData/CenterOfMass"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
 
Line 1: Line 1:
==CenterOfMass.cxx==
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CenterOfMass CenterOfMass] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
<source lang="cpp">
 
#include <vtkVersion.h>
 
#include <vtkCenterOfMass.h>
 
#include <vtkDoubleArray.h>
 
#include <vtkPoints.h>
 
#include <vtkPointData.h>
 
#include <vtkPolyData.h>
 
#include <vtkSmartPointer.h>
 
 
 
#include <limits>
 
#include <cmath>
 
 
 
int main(int, char*[])
 
{
 
  // Create a point set of a square
 
  vtkSmartPointer<vtkPoints> points =
 
    vtkSmartPointer<vtkPoints>::New();
 
  points->InsertNextPoint(0,0,0);
 
  points->InsertNextPoint(1,0,0);
 
  points->InsertNextPoint(0,1,0);
 
  points->InsertNextPoint(1,1,0);
 
 
 
  vtkSmartPointer<vtkPolyData> polydata =
 
    vtkSmartPointer<vtkPolyData>::New();
 
  polydata->SetPoints(points);
 
 
 
  // Compute the center of mass
 
  vtkSmartPointer<vtkCenterOfMass> centerOfMassFilter =
 
    vtkSmartPointer<vtkCenterOfMass>::New();
 
#if VTK_MAJOR_VERSION <= 5
 
  centerOfMassFilter->SetInput(polydata);
 
#else
 
  centerOfMassFilter->SetInputData(polydata);
 
#endif
 
  centerOfMassFilter->SetUseScalarsAsWeights(false);
 
  centerOfMassFilter->Update();
 
 
 
  double center[3];
 
  centerOfMassFilter->GetCenter(center);
 
 
 
  std::cout << "Center of mass is " << center[0] << " " << center[1] << " " << center[2] << std::endl;
 
 
 
  return EXIT_SUCCESS;
 
}
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 15:29, 9 September 2019

See CenterOfMass on the new VTKExamples website.