[vtkusers] GetColor from vtkLookupTable problem

Eric E. Monson emonson at cs.duke.edu
Fri Jul 9 11:12:03 EDT 2010


I'm glad it's working, but in your original code you had range1=[1.0,6.0] and generated three contours from that, so the middle value was 3.5

-Eric

On Jul 9, 2010, at 11:08 AM, Jothy wrote:

> Wow!
> 
> It works Eric, I thought x is the number of conotur in GetColor(x,color), but now realized it's the scalar value.
> 
> The values are 1,3,5 (by using ContourFilter->GetValue(0/1/2).
> 
> Thanks very much,
> 
> Jothy
> 
> 
> On Fri, Jul 9, 2010 at 3:58 PM, Eric E. Monson <emonson at cs.duke.edu> wrote:
> Well, you're requesting the color for a scalar value of 2.0 and your contours are at 1.0, 3.5 and 6.0 -- if you do GetColor(3.5,cc) you get back [0.0, 1.0, 0.0], which is the color of your middle contour, right?
> 
> -Eric
> 
> On Jul 9, 2010, at 10:50 AM, Jothy wrote:
> 
>> But this color which translates to (242,255,0) in another RGB format doesn't match with any of the actual contour colors.
>> 
>> See the attached pic.
>> 
>> Thanks,
>> 
>> Jothy
>> 
>> On Fri, Jul 9, 2010 at 3:44 PM, Eric E. Monson <emonson at cs.duke.edu> wrote:
>> I think I'm just adding two lines to your code and it prints 
>> 
>> [0.94509803921568625, 1.0, 0.0] color
>> 
>> import vtk
>> 
>> quadric =vtk.vtkQuadric()
>> quadric.SetCoefficients(1,2,3,0,1,0,0,0,0,0);
>> 
>> sample = vtk.vtkSampleFunction();
>> sample.SetSampleDimensions(40,40,40);
>> sample.SetImplicitFunction(quadric);
>> 
>> #Generate implicit surface
>> contour = vtk.vtkContourFilter();
>> contour.SetInput(sample.GetOutput());
>> range1=[1.0,6.0]
>> contour.GenerateValues(3,range1);
>> 
>> # The contour lines are mapped to the graphics library.
>> contMapper = vtk.vtkPolyDataMapper()
>> contMapper.SetInputConnection(contour.GetOutputPort())
>> contMapper.SetScalarRange(0,7)
>> 
>> contActor = vtk.vtkActor()
>> contActor.SetMapper(contMapper)
>> 
>> mapr=contMapper.GetLookupTable()
>> 
>> # TWO NEW LINES
>> mapr.SetRange(0,7)
>> mapr.Build()
>> 
>> cc=[0,0,0]
>> mapr.GetColor(2,cc)
>> print cc,'color'
>> 
>> # Create the renderer, render window, and interactor.
>> ren = vtk.vtkRenderer()
>> renWin = vtk.vtkRenderWindow()
>> renWin.AddRenderer(ren)
>> iren = vtk.vtkRenderWindowInteractor()
>> iren.SetRenderWindow(renWin)
>> 
>> # Set the background color to white. Associate the actors with the
>> # renderer.
>> ren.SetBackground(0,0,0)
>> ren.AddActor(contActor)
>> 
>> # Zoom in a little bit.
>> ren.ResetCamera()
>> ren.GetActiveCamera().Zoom(1)
>> 
>> # Initialize and start the event loop.
>> iren.Initialize()
>> renWin.Render()
>> iren.Start()
>> 
>> 
>> On Jul 9, 2010, at 10:40 AM, Jothy wrote:
>> 
>>> Hi Eric,
>>> 
>>> Now I get "None" color
>>> 
>>> What's wrong?
>>> 
>>> Jothy
>>> 
>>> On Fri, Jul 9, 2010 at 3:20 PM, Eric E. Monson <emonson at cs.duke.edu> wrote:
>>> Hey Jothy,
>>> 
>>> If you move your GetColor() call after the first Render(), then it will get the correct value. The problem is that at the point you're trying to grab the color from the lookup table it's not really built yet (you can try GetRange() to see that it's still (0,1) when you're calling for the color at 2, for example).
>>> 
>>> So, you can either grab the color after the Render() call, or explicitly call SetRange(0,7) and then Build() on the LUT before you try to grab the color.
>>> 
>>> -Eric
>>> 
>>> ------------------------------------------------------
>>> Eric E Monson
>>> Duke Visualization Technology Group
>>> 
>>> 
>>> On Jul 9, 2010, at 7:57 AM, Jothy wrote:
>>> 
>>>> Hi all,
>>>> 
>>>> I am trying to get the color of cntours using Mapper->GetLookupTable()->GetColor(0,color)
>>>> 
>>>> But the color doesn't exactly matches with the actual one!
>>>> 
>>>> What the problem in this code?
>>>> 
>>>> 
>>>> import vtk
>>>> 
>>>> quadric =vtk.vtkQuadric()
>>>> quadric.SetCoefficients(1,2,3,0,1,0,0,0,0,0);
>>>> 
>>>> sample = vtk.vtkSampleFunction();
>>>> sample.SetSampleDimensions(40,40,40);
>>>> sample.SetImplicitFunction(quadric);
>>>> 
>>>> #Generate implicit surface
>>>> contour = vtk.vtkContourFilter();
>>>> contour.SetInput(sample.GetOutput());
>>>> range1=[1.0,6.0]
>>>> contour.GenerateValues(3,range1);
>>>> 
>>>> 
>>>> 
>>>> # The contour lines are mapped to the graphics library.
>>>> contMapper = vtk.vtkPolyDataMapper()
>>>> contMapper.SetInputConnection(contour.GetOutputPort())
>>>> contMapper.SetScalarRange(0,7)
>>>> 
>>>> contActor = vtk.vtkActor()
>>>> contActor.SetMapper(contMapper)
>>>> 
>>>> mapr=contMapper.GetLookupTable()
>>>> cc=[0,0,0]
>>>> mapr.GetColor(2,cc)
>>>> print cc,'color'
>>>> 
>>>> 
>>>> # Create the renderer, render window, and interactor.
>>>> ren = vtk.vtkRenderer()
>>>> renWin = vtk.vtkRenderWindow()
>>>> renWin.AddRenderer(ren)
>>>> iren = vtk.vtkRenderWindowInteractor()
>>>> iren.SetRenderWindow(renWin)
>>>> 
>>>> # Set the background color to white. Associate the actors with the
>>>> # renderer.
>>>> ren.SetBackground(0,0,0)
>>>> ren.AddActor(contActor)
>>>> 
>>>> 
>>>> # Zoom in a little bit.
>>>> ren.ResetCamera()
>>>> ren.GetActiveCamera().Zoom(1)
>>>> 
>>>> # Initialize and start the event loop.
>>>> iren.Initialize()
>>>> renWin.Render()
>>>> iren.Start()
>>>> 
>>>> Thanks,
>>>> Jothy
>>>> 
>>>> 
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>> 
>>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>> 
>>>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>> 
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>> 
>>> 
>> 
>> 
>> <untitled.TIF>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100709/c3c05c48/attachment.htm>


More information about the vtkusers mailing list