Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VTK check polydata point objects for intersection

Tags:

python

vtk

I have two VTK polydata objects with point data that I want to check for an intersection. Essentially, I want to make the points into a polygonal shape and then use that.

I've been told that the way to do this is to convert the point data into a triangular mesh and then use a vtkIntersectionPolyDataFilter to check. This is what I have currently:

def convert_pts_to_mesh(polydata):
    aCellArray = vtk.vtkCellArray()

    boundary = vtk.vtkPolyData()
    boundary.SetPoints(polydata.GetPoints())
    boundary.SetPolys(aCellArray)
    delaunay = vtk.vtkDelaunay2D()
    delaunay.SetInputData(polydata)
    delaunay.SetSourceData(boundary)
    delaunay.Update()

    result_polydata = delaunay.GetOutput()

    # print("result_polydata:")
    # print(result_polydata)
    return result_polydata

...

contour1 = ... # Source of polydata point object
contour2 = ... # Source of polydata point object

# Convert them to triangle meshes.
result_polydata1 = convert_pts_to_mesh(contour1)
result_polydata2 = convert_pts_to_mesh(contour2)

intersection_operation = vtk.vtkIntersectionPolyDataFilter()
intersection_operation.SetInputData(0, result_polydata1)
intersection_operation.SetInputData(1, result_polydata2)
intersection_operation.Update()

print("# of crosses: " + str(intersection_operation.GetNumberOfIntersectionPoints()))

However, this spits out errors which I believe are related to a failure within the intersection_operation.Update() call.

#121.040# [VtkError] ERROR: ERROR: In /usr/local/sv/ext/2019.02/release/gl2/src/vtk-8.1.1/Common/DataModel/vtkPointLocator.cxx, line 867
vtkPointLocator (0x555d26925800): No points to subdivide
!121.041! [VtkGenericWarning] WARNING: Generic Warning: In /usr/local/sv/ext/2019.02/release/gl2/src/vtk-8.1.1/Filters/General/vtkIntersectionPolyDataFilter.cxx, line 2518
No Intersection between objects
# of crosses: 0

The fact that the error mentions points for subdivision, I tried to feed in the contour1 and contour2 objects, but it then errors out on the SetInputData line:

!126.179! [VtkGenericWarning] WARNING: Generic Warning: In /usr/local/sv/ext/2019.02/release/gl2/src/vtk-8.1.1/Common/Core/vtkMath.cxx, line 779
vtkMath::Jacobi: Error extracting eigenfunctions

I'm not sure where to go from here, the VTK documentation on both the Delaunay and the IntersectonPolyDataFilter aren't the most useful to me here.

like image 634
ifconfig Avatar asked Sep 22 '26 20:09

ifconfig


1 Answers

If by intersection you mean overlap of point clouds you can try out:

import numpy as np
from vedo import Points, ConvexHull, show

pts = np.random.rand(1000, 3)

# Points() creates a vtkActor (with extended functionalities) from
# the original cloud of points pts:
pts1 = Points(pts, r=5).c('red') # r=radius of points

# create a second cloud displaced by a constant
pts2 = Points(pts+[0.6,0.8,0], r=2).c('green')

# create the convex hull which wraps the pts2 cloud.
# ch2 is also a vtkActor. Note that you can concatenate commands
# like .alpha() and .c() to change transparency and color..
ch2 = ConvexHull(pts2).alpha(0.2).c('green')

# extract the points of the original cloud (pts) which are inside
# the convex hull of the second (ch2) as a list of points:
print("# of crosses:", len(ch2.insidePoints(pts).points()))

# show() will render all the indicated objects:
show(pts1, pts2, ch2, axes=1)
like image 84
mmusy Avatar answered Sep 24 '26 08:09

mmusy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!