[vtkusers] Re: [vtk-developers] vtkLookupTable + vtkStructuredPointsWriter = bug
Mathieu Malaterre
Mathieu.Malaterre at creatis.insa-lyon.fr
Thu Nov 20 10:02:14 EST 2003
Hum,
I hope this time someone will read this -keep finger cross ;)-
So I find a different behavior when reading a vtkLookupTable whether we
are in binary or ASCII mode. This is done throught
vtkDataReader::ReadLutData, which call :
void vtkLookupTable::SetTableValue(vtkIdType indx, float rgba[4])
{
...
this->InsertTime.Modified();
this->Modified();
}
versus in binary mode:
inline unsigned char *vtkLookupTable::WritePointer(const vtkIdType id,
const int number)
{
return this->Table->WritePointer(4*id,4*number);
}
In binary mode, there is no call to 'InsertTime.Modified' thus the
pipeline is not updated. That is too say, in ASCII mode:
vtkLookupTable::Build() is being called.
----
Now for the solution, I'll suggest we add that in
vtkLookupTable::WritePointer:
+ this->InsertTime.Modified();
+ this->Modified();
But still it doesn't solve the issue of rounding in ASCII mode...
Comments/suggestions *very* welcome.
Thanks,
mathieu
Mathieu Malaterre wrote:
> Hi,
>
> I guess my mail was a bit too long. Could at least someone reports
> that he/she could reproduce the bug ? This mail was supposed to be the
> first one, before my question of design:
>
> In VTK, a polydata with an associated lookuptable can be displayed
> automatically with the good LUT. Because vtkMapper has a
> 'vtkScalarsToColors'. However for vtkImageData, there is no such things
> -well at least I couldn't find one-. An ImageData with an associated
> LookupTable is not displayed correctly until you actually use a
> vtkImageMapToColors. So my question is simply: why ?
>
> Thanks a lot for your comments.
>
> mathieu
> Ps: I also try to track down why a vtkDataSetMapper doesn't apply the
> lookup table, I end up in
> vtkScalarsToColors::MapScalars which starts:
> ConvertUnsignedCharToRGBA
> which doesn't take into account the LUT...
>
> Mathieu Malaterre wrote:
>
>> Hi all,
>>
>> In case someone already knows the answer I am posting this. Anyway
>> here is a python script(*) that reproduce the bug. The faulty line is:
>>
>> writer.SetFileTypeToBinary()
>>
>> if a vtkImageData is saved with a vtkLookupTable in binary mode
>> everything is ok, but when saved as ASCII then the LUT can't be reread
>> properly. I'll try to find a patch ASAP.
>>
>> BTW, does anyone knows why I should explicitely set the TableRange ?
>>
>> lut.SetTableRange( 0, 255)
>>
>> Thanks,
>> mathieu
>>
>> ##################################################
>> (*)
>> import vtk
>> from vtk.util.misc import vtkGetDataRoot
>> VTK_DATA_ROOT = vtkGetDataRoot()
>>
>> reader = vtk.vtkBMPReader()
>> reader.SetFileName( VTK_DATA_ROOT + '/Data/masonry.bmp' )
>> reader.Allow8BitBMPOn ()
>> reader.Update()
>>
>> #construct an image data with a lookup table
>> image = reader.GetOutput()
>> image.GetPointData().GetScalars().SetLookupTable(
>> reader.GetLookupTable() )
>>
>> writer = vtk.vtkStructuredPointsWriter()
>> writer.SetInput( image )
>> writer.SetFileName( 'demolut.vtk' )
>> #writer.SetFileTypeToBinary() #culprit !!!
>> writer.Write()
>>
>> reader2 = vtk.vtkStructuredPointsReader()
>> reader2.SetFileName( 'demolut.vtk' )
>> reader2.UpdateWholeExtent()
>>
>> lut = reader2.GetOutput().GetPointData().GetScalars().GetLookupTable()
>> lut.SetTableRange( 0, 255) #trick ??
>>
>> map2 = vtk.vtkImageMapToColors ()
>> map2.SetInput (reader2.GetOutput())
>> map2.SetLookupTable ( lut )
>> map2.SetOutputFormatToRGB()
>>
>> iren = vtk.vtkRenderWindowInteractor();
>>
>> viewer = vtk.vtkImageViewer2()
>> viewer.SetInput (map2.GetOutput())
>> viewer.SetupInteractor (iren)
>>
>> #make interface
>> iren.Initialize()
>> iren.Start()
>> ##################################################
>
>
More information about the vtkusers
mailing list