[vtkusers] How to get pixel color from 3D coordinates ?
corentin.desfarges
corentin.desfarges.dev at gmail.com
Wed Mar 9 06:22:21 EST 2016
Hi
I'm trying to get the color of a pixel picked from a vtkPolyData.
I tried to combine this two tutorials : PickPixel and (Point)Picking
I can get the coordinates of the picked point, but unfortunatly, I'm can't
get the vtkCell...
Here is the code I use :
std::string inputFilename = "/home/cde/data/mesh.vtk";
vtkSmartPointer<vtkGenericDataObjectReader> reader =
vtkSmartPointer<vtkGenericDataObjectReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
polydata = reader->GetPolyDataOutput();
[...]
double* pos = picker->GetPickPosition();
vtkPointData* pd = polydata->GetPointData();
if( !pd )
{
return;
}
// Use tolerance as a function of size of source data
double tol2 = polydata->GetLength();
tol2 = tol2 ? tol2*tol2 / 1000.0 : 0.001;
// Find the cell that contains pos
int subId;
double pcoords[3], weights[8];
vtkCell* cell = polydata->FindAndGetCell( pos, NULL, -1, tol2, subId,
pcoords, weights );
if( cell )
{
// Interpolate the point data
this->PointData->InterpolatePoint( pd, 0, cell->PointIds, weights );
double* tuple = this->PointData->GetScalars()->GetTuple( 0 );
double r = std::stod(vtkVariant(tuple[0]).ToString())/255;
double g = std::stod(vtkVariant(tuple[1]).ToString())/255;
double b = std::stod(vtkVariant(tuple[2]).ToString())/255;
std::cout << r*255 << " " << g*255 << " " << b*255 << std::endl;
renderer->SetBackground(r,g,b);
}
else
{
std::cout << "no cell found " << std::endl;
}
Thanks for your help,
Corentin
--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-get-pixel-color-from-3D-coordinates-tp5737117.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list