Convert vtkPropPicker value to vtkVoxel values

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 :slight_smile:

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.

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 …

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. 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.

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

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 :slight_smile:

Regards,
Flaviu.

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

1 Like

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