# vtkHardwarePicker and vtkImageData

**URL:** <https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277>\
**Category:** Support\
**Created:** [September 13, 2023, 1:41pm UTC](https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277 "2023-09-13T13:41:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Jackson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael_jackson/32/61_2.png) [@Michael\_Jackson](https://discourse.vtk.org/u/Michael_Jackson)\
**Post date:** [September 13, 2023, 1:41pm UTC](https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277/1 "2023-09-13T13:41:13Z")

</div>

we are trying to use the vtkHardwarePicker to give information about a user hovered location in a data set. With unstructured grids this seems to be working correctly. However with vtkImageData when the user hovers over a cell (cell centered data) I get information from the extracted surface instead of the cell centered data. I am wondering if we are just using this incorrectly or if there are special hoops I need to jump through when using a vtkImageData?

We use a `vtkImageToStructuredGrid` and `vtkDataSetMapper` to show the data on screen. Then here is our function to attempt to get information from the vtkHardwarePicker:

```auto
std::string GenerateHoverString()
  {
    int* clickPos = m_VisualizationWidget->renderWindow()->GetInteractor()->GetEventPosition();
    vtkNew<vtkHardwarePicker> picker;
    // pick a dataset
    picker->SetSnapToMeshPoint(m_PointPickerOn);
    int const pickResult = picker->Pick(clickPos[0], clickPos[1], 0, m_Renderer);
    if(pickResult == 1)
    {
      vtkDataSet* pickedDataSet = picker->GetDataSet();
      if(pickedDataSet != nullptr)
      {
        vtkIdType cellId = picker->GetCellId();
        vtkIdType pointId = picker->GetPointId();
        if(m_PointPickerOn)
        {
          return printDataValues(pickedDataSet->GetPointData(), pointId, "Point");
        }
        if(m_CellPickerOn)
        {
          return printDataValues(pickedDataSet->GetCellData(), cellId, "Cell");
        }
      }
    }
    return {""};
  }

```

I am hoping this is just a simple misunderstanding on my part on how to use the vtkHardwarePicker. Maybe I need to work my way back up through the vtk pipeline to find the original source instead of what comes out of the `vtkImageToStructuredGrid` filter?

---

<div class="post-metadata">

**Author:** ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)\
**Post date:** [September 14, 2023, 3:08am UTC](https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277/2 "2023-09-14T03:08:40Z")

</div>

> [@Michael\_Jackson](#):
>
> `vtkImageToStructuredGrid`

Why do you use `vtkImageToStructuredGrid` and not `vtkDataSetMapper` only?

---

<div class="post-metadata">

**Author:** ![Michael\_Jackson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael_jackson/32/61_2.png) [@Michael\_Jackson](https://discourse.vtk.org/u/Michael_Jackson)\
**Post date:** [September 15, 2023, 3:28pm UTC](https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277/3 "2023-09-15T15:28:14Z")

</div>

Honestly, not really sure why. It seemed to work for what we needed so we stuck with it. I am not sure of the actual difference. I’m willing to try what ever though.

---

<div class="post-metadata">

**Author:** ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)\
**Post date:** [September 15, 2023, 4:12pm UTC](https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277/4 "2023-09-15T16:12:01Z")

</div>

Remove it and see what happens.

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [September 20, 2023, 3:21pm UTC](https://discourse.vtk.org/t/vtkhardwarepicker-and-vtkimagedata/12277/5 "2023-09-20T15:21:45Z")

</div>

@Michael_Jackson How are you rendering the image data? Which mapper do you use? If you’re rendering it using the dataset mapper, that just extracts the outer geometry to render - which is why the picker just picks surface cells.
