Hi,
In the past, I had a slow rendering problem. At the time, the problem was color management with ‘vtkColorTransferFunction’.
I solved the problem by using a ‘vtkLookupTable’ along with the ‘vtkColorTransferFunction’, example :
// I add control points to the vtkColorTransferFunction
for (const auto& pt : ctrlPts)
{
m_transferFunction->AddRGBPoint(pt[0], pt[1], pt[2], pt[3]);
}
/* I build the lut */
m_lookupTable->SetNumberOfTableValues(m_lookupTableSize); // e.g. m_lookupTableSize == 256
m_lookupTable->SetRange(minRange, maxRange); // the range of data retrieved from a vtkImageData
m_lookupTable->Build();
double rgb[3];
for (size_t i = 0; i < m_lookupTableSize; ++i)
{
m_transferFunction->GetColor(static_cast<double>(i) / m_lookupTableSize, rgb);
m_lookupTable->SetTableValue(i, rgb[0], rgb[1], rgb[2]);
// in the VTK examples, there is a memory bug, do not feed rgb a ptr to SetTableValue
}
Recently, I encountered a class named vtkDiscretizableColorTransferFunction, that is also wrapped in ParaView under the name vtkPVDiscretizableColorTransferFunction.
I thought this last is doing what I am doing in the code I posted above, but when I tested it, it was slow as hell, just like ‘vtkColorTransferFunction’.
Strangely, in Paraview (with a 256 LUT sized table for example), rendering didn’t seem slow, may be I am using it wrong. Example :
vtkNew<vtkDiscretizableColorTransferFunction> discretTF; discretTF->DiscretizeOn(); discretTF->SetNumberOfValues(256); discretTF->IndexedLookupOff(); discretTF->AddRGBPoint(0, 0.23137254902, 0.298039215686, 0.752941176471); discretTF->AddRGBPoint(0.5, 0.865, 0.865, 0.865); discretTF->AddRGBPoint(1, 0.705882352941, 0.0156862745098, 0.149019607843); discretTF->Build();
When I render a vtkImageData with the code above, it’s as slow as using vtkColorTransferFunction (not discretized I guess).
My questions are :
- If we want discretized colors (to provide the fastest rendering), what’s the best strategy ?
- Why vtkDiscretizableColorTransferFunction (or even vtkPVDiscretizableColorTransferFunction, I took the class from ParaView and it has the same slow rendering time as vtkDiscretizableColorTransferFunction) is slow ?
Thanks.