# No Pyhton wrapper for SetSnap To CellWithClosestPoint() ?

**URL:** https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714
**Category:** Support
**Created:** [February 16, 2023, 10:03pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714 "2023-02-16T22:03:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![aborsic](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@aborsic](https://discourse.vtk.org/u/aborsic)
#### Post date: [February 16, 2023, 10:03pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/1 "2023-02-16T22:03:48Z")

</div>

Hello Everyone,

I have an input dataset which is a polydata consisting only of points with associated scalars. I need to resample it at point locations with a second point-only polydata.

I would like to use the nearest neighbor interpolation, but in Python it seems that the method SetSnapToCellWithClosestPoint() is not wrapped for the classes vtkProbeFilter and vtkResampleWithDataSet.

Can anyone confirm this is true? If yes, is there a specific reason for this?

Does anyone have a suggestion for any other approach to nearest neighbor interpolation? (I need to use Python bindings)

Thanks in advance for any suggestion/comment,

Best Regards,

Andrea

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 18, 2023, 5:31am UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/3 "2023-02-18T05:31:40Z")

</div>

I checked using [PointInterpolator](https://kitware.github.io/vtk-examples/site/Python/Meshes/PointInterpolator/) adding the line

```plaintext
    resample.SnapToCellWithClosestPointOn()

```

and this works Ok. I also checked using

- `SnapToCellWithClosestPointOn()`
- `SnapToCellWithClosestPointOff()`
- `SetSnapToCellWithClosestPoint(True)`

All are wrapped OK. I used the vtk master in Linux. So wrapping seems to be Ok.

---

<div class="post-metadata">

### Author: ![aborsic](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@aborsic](https://discourse.vtk.org/u/aborsic)
#### Post date: [February 23, 2023, 9:08am UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/4 "2023-02-23T09:08:24Z")

</div>

> [@amaclean](#):
>
> `SnapToCellWithClosestPointOn()`

Hi Andrew,

Thanks for checking. If I try that, I get:

_AttributeError: ‘vtkmodules.vtkFiltersPoints.vtkPointInterpolator’ object has no attribute ‘SnapToCellWithClosestPointOn’_

dir(resample) does not show in fact the method.

I am using VTK 9.2.6 on Windows 11, with Python 3.6.8 64 bit

Cheers,

Andrea

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [February 24, 2023, 12:43am UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/5 "2023-02-24T00:43:19Z")

</div>

I don’t see that method on `vtkPointInterpolator`, but I do see it on `vtkProbeFilter` and `vtkResampleWithDataSet` (both from `vtkFiltersCore`).

---

<div class="post-metadata">

### Author: ![aborsic](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@aborsic](https://discourse.vtk.org/u/aborsic)
#### Post date: [February 24, 2023, 12:33pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/6 "2023-02-24T12:33:05Z")

</div>

Humm,

I still get the error for both filters, vtkProbeFilter and vtkResampleWithDataset. The messages look like this:

_AttributeError: ‘vtkmodules.vtkFiltersCore.vtkProbeFilter’ object has no attribute ‘SnapToCellWithClosestPointOn’_

_AttributeError: ‘vtkmodules.vtkFiltersParallelDIY2.vtkPResampleWith’ object has no attribute ‘SnapToCellWithClosestPointOn’_

One difference I notice is that your ResampleWithDataset belongs to vtkFiltersCore and mine is under vkFiltersParallelDIY2 (which I am not sure what it is), but I have instantiated the filter simply as: sf = vtk.vtkResampleWithDataSet()

Thanks for any advice,

Andrea

P.S. I have installed VTK with pip

---

<div class="post-metadata">

### Author: ![aborsic](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@aborsic](https://discourse.vtk.org/u/aborsic)
#### Post date: [February 24, 2023, 12:41pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/7 "2023-02-24T12:41:45Z")

</div>

This code snippet:

import vtk  
f = vtk.vtkProbeFilter()  
attrib\_list = dir(f)  
for attr in attrib\_list:  
print(f"Attribute: {attr}\n")

produces the output below, which does not include any method related to snapping:

Attribute: AbortExecuteOff

Attribute: AbortExecuteOn

Attribute: AddInputConnection

Attribute: AddInputData

Attribute: AddInputDataObject

Attribute: AddObserver

Attribute: BreakOnError

Attribute: CAN\_HANDLE\_PIECE\_REQUEST

Attribute: CAN\_PRODUCE\_SUB\_EXTENT

Attribute: CategoricalDataOff

Attribute: CategoricalDataOn

Attribute: ComputeToleranceOff

Attribute: ComputeToleranceOn

Attribute: ConvertTotalInputToPortConnection

Attribute: DEFAULT\_PRECISION

Attribute: DOUBLE\_PRECISION

Attribute: DebugOff

Attribute: DebugOn

Attribute: DesiredOutputPrecision

Attribute: FastDelete

Attribute: GetAbortExecute

Attribute: GetAddressAsString

Attribute: GetCategoricalData

Attribute: GetCellLocatorPrototype

Attribute: GetClassName

Attribute: GetCommand

Attribute: GetComputeTolerance

Attribute: GetDebug

Attribute: GetErrorCode

Attribute: GetExecutive

Attribute: GetFindCellStrategy

Attribute: GetGlobalWarningDisplay

Attribute: GetImageDataOutput

Attribute: GetInformation

Attribute: GetInput

Attribute: GetInputAlgorithm

Attribute: GetInputArrayInformation

Attribute: GetInputConnection

Attribute: GetInputDataObject

Attribute: GetInputExecutive

Attribute: GetInputInformation

Attribute: GetInputPortInformation

Attribute: GetIsInMemkind

Attribute: GetMTime

Attribute: GetNumberOfGenerationsFromBase

Attribute: GetNumberOfGenerationsFromBaseType

Attribute: GetNumberOfInputConnections

Attribute: GetNumberOfInputPorts

Attribute: GetNumberOfOutputPorts

Attribute: GetObjectDescription

Attribute: GetObjectName

Attribute: GetOutput

Attribute: GetOutputDataObject

Attribute: GetOutputInformation

Attribute: GetOutputPort

Attribute: GetOutputPortInformation

Attribute: GetPassCellArrays

Attribute: GetPassFieldArrays

Attribute: GetPassPointArrays

Attribute: GetPolyDataOutput

Attribute: GetProgress

Attribute: GetProgressObserver

Attribute: GetProgressScale

Attribute: GetProgressShift

Attribute: GetProgressText

Attribute: GetRectilinearGridOutput

Attribute: GetReferenceCount

Attribute: GetReleaseDataFlag

Attribute: GetSource

Attribute: GetSpatialMatch

Attribute: GetStructuredGridOutput

Attribute: GetStructuredPointsOutput

Attribute: GetTolerance

Attribute: GetTotalNumberOfInputConnections

Attribute: GetUnstructuredGridOutput

Attribute: GetUpdateExtent

Attribute: GetUpdateGhostLevel

Attribute: GetUpdateNumberOfPieces

Attribute: GetUpdatePiece

Attribute: GetUsingMemkind

Attribute: GetValidPointMaskArrayName

Attribute: GetValidPoints

Attribute: GlobalWarningDisplayOff

Attribute: GlobalWarningDisplayOn

Attribute: HasExecutive

Attribute: HasObserver

Attribute: INPUT\_ARRAYS\_TO\_PROCESS

Attribute: INPUT\_CONNECTION

Attribute: INPUT\_IS\_OPTIONAL

Attribute: INPUT\_IS\_REPEATABLE

Attribute: INPUT\_PORT

Attribute: INPUT\_REQUIRED\_DATA\_TYPE

Attribute: INPUT\_REQUIRED\_FIELDS

Attribute: InitializeObjectBase

Attribute: InvokeEvent

Attribute: IsA

Attribute: IsTypeOf

Attribute: Modified

Attribute: ModifyRequest

Attribute: NewInstance

Attribute: PassCellArraysOff

Attribute: PassCellArraysOn

Attribute: PassFieldArraysOff

Attribute: PassFieldArraysOn

Attribute: PassPointArraysOff

Attribute: PassPointArraysOn

Attribute: ProcessRequest

Attribute: PropagateUpdateExtent

Attribute: Register

Attribute: ReleaseDataFlagOff

Attribute: ReleaseDataFlagOn

Attribute: RemoveAllInputConnections

Attribute: RemoveAllInputs

Attribute: RemoveAllObservers

Attribute: RemoveInputConnection

Attribute: RemoveObserver

Attribute: RemoveObservers

Attribute: SINGLE\_PRECISION

Attribute: SafeDownCast

Attribute: SetAbortExecute

Attribute: SetCategoricalData

Attribute: SetCellLocatorPrototype

Attribute: SetComputeTolerance

Attribute: SetDebug

Attribute: SetDefaultExecutivePrototype

Attribute: SetExecutive

Attribute: SetFindCellStrategy

Attribute: SetGlobalWarningDisplay

Attribute: SetInformation

Attribute: SetInputArrayToProcess

Attribute: SetInputConnection

Attribute: SetInputData

Attribute: SetInputDataObject

Attribute: SetMemkindDirectory

Attribute: SetObjectName

Attribute: SetPassCellArrays

Attribute: SetPassFieldArrays

Attribute: SetPassPointArrays

Attribute: SetProgressObserver

Attribute: SetProgressShiftScale

Attribute: SetProgressText

Attribute: SetReferenceCount

Attribute: SetReleaseDataFlag

Attribute: SetSourceConnection

Attribute: SetSourceData

Attribute: SetSpatialMatch

Attribute: SetTolerance

Attribute: SetValidPointMaskArrayName

Attribute: SpatialMatchOff

Attribute: SpatialMatchOn

Attribute: UnRegister

Attribute: Update

Attribute: UpdateDataObject

Attribute: UpdateExtent

Attribute: UpdateExtentIsEmpty

Attribute: UpdateInformation

Attribute: UpdatePiece

Attribute: UpdateProgress

Attribute: UpdateTimeStep

Attribute: UpdateWholeExtent

Attribute: UsesGarbageCollector

Attribute: **class**

Attribute: **delattr**

Attribute: **dict**

Attribute: **dir**

Attribute: **doc**

Attribute: **eq**

Attribute: **format**

Attribute: **ge**

Attribute: **getattribute**

Attribute: **gt**

Attribute: **hash**

Attribute: **init**

Attribute: **init\_subclass**

Attribute: **le**

Attribute: **lt**

Attribute: **ne**

Attribute: **new**

Attribute: **reduce**

Attribute: **reduce\_ex**

Attribute: **repr**

Attribute: **setattr**

Attribute: **sizeof**

Attribute: **str**

Attribute: **subclasshook**

Attribute: **this**

Attribute: **vtkname**

Attribute: override

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [February 24, 2023, 1:42pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/8 "2023-02-24T13:42:58Z")

</div>

Those methods are only in the master branch, they aren’t yet in any releases.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [February 24, 2023, 3:10pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/9 "2023-02-24T15:10:13Z")

</div>

The `vtkPointInterpolator` with the `vtkVoronoiKernel` should provide the kind of nearest-neighbor interpolation that you’re looking for.

```python
kernel = vtkVoronoiKernel()

probe = vtkPointInterpolator()
probe.SetInputConnection(input_data)
probe.SetSourceData(source_data)
probe.SetLocator(point_locator_for_source_data)
probe.SetKernel(kernel)

```

---

<div class="post-metadata">

### Author: ![aborsic](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@aborsic](https://discourse.vtk.org/u/aborsic)
#### Post date: [February 24, 2023, 3:12pm UTC](https://discourse.vtk.org/t/no-pyhton-wrapper-for-setsnap-to-cellwithclosestpoint/10714/10 "2023-02-24T15:12:48Z")

</div>

David,

Thank you so much for the information.

Best Regards,

Andrea
