[vtkusers] VTKCenterOfMass does not generate the correct center of VTKPolyDataConnectivityFilter output data

WANGMengjiao wangmengjiao at tsinghua.org.cn
Mon Apr 20 22:31:36 EDT 2015


Dear All
   I have encountered a weird problem using 
VTKPolyDataConnectivityFilter. I had a polydata consists of two 
seperated parts. And I use the VTKPolyDataConnectivityFilter to extract 
the largest region. The code is as following:
      // Extract the feature edges
      vtkSmartPointer<vtkFeatureEdges> boundaryEdges = 
vtkSmartPointer<vtkFeatureEdges>::New();
boundaryEdges->SetInputConnection(clipper->GetOutputPort());
      boundaryEdges->BoundaryEdgesOn();
      boundaryEdges->FeatureEdgesOff();
      boundaryEdges->NonManifoldEdgesOff();
      boundaryEdges->ManifoldEdgesOff();
      // Converted the boundaryEdges to boundaryStrips
      vtkSmartPointer<vtkStripper> boundaryStrips = 
vtkSmartPointer<vtkStripper>::New();
boundaryStrips->SetInputConnection(boundaryEdges->GetOutputPort());
      boundaryStrips->Update();
      // Extract the largest region
      vtkSmartPointer<vtkPolyDataConnectivityFilter> boundaryFilter = 
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
boundaryFilter->SetInputConnection(boundaryStrips->GetOutputPort());
      boundaryFilter->SetExtractionModeToLargestRegion();
   I used a mapper and actor to visualize the extracted largest region, 
and the result is correct. However, when I tried to compute the center 
of the extracted largest region, the computed center is the same with 
the center of unfiltered poly data (i.e. the poly data consisting of two 
seperated parts). The usage of VTKCenterOfMass is as following:
      // Compute the center of extracted largest region
      vtkSmartPointer<vtkCenterOfMass> centerOfMassFilter = 
vtkSmartPointer<vtkCenterOfMass>::New();
centerOfMassFilter->SetInputConnection(boundaryFilter->GetOutputPort());
      centerOfMassFilter->Update();
      double centerOfMass[3];
      centerOfMassFilter->GetCenter(centerOfMass);
   Does anyone can help me out? Where I did it wrong?
   Many Thanks!
   John



More information about the vtkusers mailing list