IVarha
(I Varha)
February 22, 2021, 8:29pm
1
Dear VTK community, I am trying check which points of my data located inside of the mesh. I use VTKEnclosedPoints to perform this check however it produce wrong results for my data (All points are off the dataset while visually a lot of points are inside
I attach all my points and mesh.
auto poly_data = vtkSmartPointer<vtkPolyData>::New();
poly_data->SetPoints(pts);
auto encl_points = vtkSmartPointer<vtkSelectEnclosedPoints>::New();
encl_points->SetInputData(poly_data);
encl_points->SetSurfaceData(this->mesh->getMesh());
encl_points->Update();
31.obj (16.0 KB) points.fcsv (116.0 KB)
Andrew
(Andrew Wilson)
February 22, 2021, 9:31pm
2
Can you run vtkCleanPolyData on your data before doing vtkSelectEnclosedPoints?
Andrew
(Andrew Wilson)
February 22, 2021, 9:44pm
3
Also for a regular grid its often faster to use a stencil which will scanline them into a binary mask.
// Allocate a new white image
vtkSmartPointer<vtkImageData> whiteImage = vtkSmartPointer<vtkImageData>::New();
whiteImage->SetSpacing(spacing);
whiteImage->SetExtent(extent);
whiteImage->SetOrigin(origin);
whiteImage->AllocateScalars(VTK_FLOAT, 1);
int* dim = whiteImage->GetDimensions();
std::fill_n(static_cast<float*>(whiteImage->GetScalarPointer()), dim[0] * dim[1] * dim[2], 1.0f);
vtkSmartPointer<vtkPolyDataToImageStencil> poly2Stencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
poly2Stencil->SetInputData(polyToRasterize);
poly2Stencil->SetOutputOrigin(origin);
poly2Stencil->SetOutputSpacing(spacing);
poly2Stencil->SetOutputWholeExtent(extent);
poly2Stencil->Update();
vtkSmartPointer<vtkImageStencil> imgStencil = vtkSmartPointer<vtkImageStencil>::New();
imgStencil->SetInputData(whiteImage);
imgStencil->SetStencilData(poly2Stencil->GetOutput());
imgStencil->ReverseStencilOff();
imgStencil->SetBackgroundValue(0.0);
imgStencil->Update();
1 Like
IVarha
(I Varha)
February 22, 2021, 9:51pm
4
I am totally sure that all vertices of the mesh are connected to faces because I never change faces and modifying only points.
IVarha
(I Varha)
February 22, 2021, 10:08pm
5
It seems like the problem occurs because I modify points of mesh on each iteration
for (int i = 0;i< this->points->GetNumberOfPoints();i++){
this->points->SetPoint(i,set_of_points[3*i],set_of_points[3*i +1],set_of_points[3*i +2]);
}
this->mesh->Initialize();
this->mesh->SetPoints(this->points);
this->mesh->SetPolys(this->triangles);