# Convert vtkPropPicker value to vtkVoxel values

**URL:** https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549
**Category:** Support
**Created:** [February 5, 2020, 11:25am UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549 "2020-02-05T11:25:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [February 5, 2020, 11:25am UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/1 "2020-02-05T11:25:27Z")

</div>

I am trying to know the _min\_voxel_ / _max\_voxel_ for **vtkImageConnectivityFilter::SetSizeRange** for bones, and I don’t know from where I taken … and I thinking (maybe is stupid) to get those values from a vtkPropPicker … it is possible ? if it is, how can do that ?

```
int nPickPosition[2];
GetInteractor()->GetEventPosition(nPickPosition);
vtkPropPicker* pPicker = vtkPropPicker::New();
pPicker->Pick(nPosition[0], nPosition[1], 0, GetRenderer());
double* dWorldPosition = pPicker->GetPickPosition();

```

so, how can I use dWorldPosition to get voxel values in order to use them into a vtkImageConnectivityFilter object ?

Thank you for your time and patience 🙂

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 5, 2020, 2:08pm UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/2 "2020-02-05T14:08:36Z")

</div>

Hi, friend,

To get values from my model (probing) I used `vtkCellPicker` in addition to `vtkPropPicker`:

```
   (...)
    // Get the cell of a 3D object under the 2D screen coordinates (ray casting).
    vtkSmartPointer<vtkCellPicker> cellPicker = vtkSmartPointer<vtkCellPicker>::New();
    cellPicker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());

    //if something was picked
    if( picker->GetActor() && cellPicker->GetCellId() != -1 ) {

        // Output the probed value at the picked location.
        vtkDataSet* dataSet = cellPicker->GetDataSet();
        vtkCellData* cellData = dataSet->GetCellData();
        vtkDataArray* dataArray = cellData->GetScalars();
        if( dataArray->GetNumberOfComponents() <= 200 ){
            double values[200]; //200 is a fairly large number of scalar fields.
            dataArray->GetTuple( cellPicker->GetCellId(), values );
            QString valuesText = "NO VALUES";
            for( int i = 0; i < dataArray->GetNumberOfComponents(); ++i )
                if( i == 0)
                    valuesText = QString::number(values[0]); 
                else
                    valuesText = valuesText + "; " + QString::number(values[i]); 
            std::cout << "Picked value(s): " << valuesText.toStdString() << std::endl;
        } else
            std::err << "Probing not possible if VTK object has more than 200 scalar fields in it." << std::endl;
    }
   (...)

```

For the complete example how I do probing can be found [here](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp).

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [February 5, 2020, 5:58pm UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/3 "2020-02-05T17:58:12Z")

</div>

Paulo, thank you for your interest. Some light coming to my mind after I read your code. Still, I have some unknowns. I have tried the following code:

```
	vtkPropPicker* pPicker = vtkPropPicker::New();
	pPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer);
	vtkCellPicker* pCellPicker = vtkCellPicker::New();
	pCellPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer);
	TRACE("==%p\t%d\n", pPicker->GetActor(), pCellPicker->GetCellId());

```

and after I made click on my 3d volume, on a tooth, I got always pPicker-\>GetActor() as NULL:

| ==0000000000000000 | 2155982 |
| --- | --- |
| ==0000000000000000 | 4525593 |
| ==0000000000000000 | 4866664 |

I don’t know why … could you tell me ?

After that code, I wrote:

```
	if (pPicker->GetActor() && -1 != pCellPicker->GetCellId())
	{
		vtkDataSet* pDataSet = pCellPicker->GetDataSet();
		vtkCellData* pCellData = pDataSet->GetCellData();
		vtkDataArray* pArrData = pCellData->GetScalars();
		if (pArrData->GetNumberOfComponents() <= 200)
		{
			double* dValue = pArrData->GetTuple(pCellPicker->GetCellId());
			for (int i = 0; i < pArrData->GetNumberOfComponents(); ++i)
			{
				TRACE(">>>%f\n", dValue[i]);
			}
		}
	}
	pCellPicker->Delete();
	pPicker->Delete();

```

of course, is never enter there …

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 5, 2020, 6:58pm UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/4 "2020-02-05T18:58:33Z")

</div>

Since your case is a volume, maybe the object you’re picking is not a subclass of `vtkActor`. If you are picking volume slices (`vtkImageSlice`), then `GetActor()` will return `nullptr` indeed.

Take a look at the [`vtkProp` family](https://vtk.org/doc/nightly/html/classvtkProp.html). Then locate the visual VTK class that you’re using to render your image there. After that, you have to call the adequate method instead of `getActor()`. Maybe `GetProp3D()` will do.

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [February 6, 2020, 9:12am UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/5 "2020-02-06T09:12:11Z")

</div>

I come back to new results, hoping to learn as much as as can 🙂

Here is my new trial code:

```
	vtkVolumePicker* pPicker = vtkVolumePicker::New();
	pPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer);
	vtkCellPicker* pCellPicker = vtkCellPicker::New();
	pCellPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer);
	TRACE("==%p\t%d\n", pPicker->GetActor(), pCellPicker->GetCellId());

==0000000000000000|5175224|
==0000000000000000|7797620|

```

but has the same result … didn’t used the right picker ? if I didn’t, what should be the right picker ?

Thank you for any response, this my main source of VTK learning (beside VTK documentation and examples) … so, don’t hesitate to write me anything of what I could learn here 🙂

Regards,  
Flaviu.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 7, 2020, 1:47pm UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/6 "2020-02-07T13:47:03Z")

</div>

Hello,

Have you tried `GetProp3D()` instead of `GetActor()`? If the visual object you’re picking is not a `vtkActor` you have to use some other `Get*()` method of `pPicker`.

cheers,

Paulo

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [February 9, 2020, 9:50am UTC](https://discourse.vtk.org/t/convert-vtkproppicker-value-to-vtkvoxel-values/2549/7 "2020-02-09T09:50:04Z")

</div>

With **vtkVolumePicker::GetProp3D** I got the pointer of the volume. Thank you !!!
