[vtkusers] vtkScalarBarActor range problem

Palmer, Mark (CMIS, Floreat Park) Mark.Palmer at CMIS.CSIRO.AU
Wed Jul 12 21:17:03 EDT 2000


I think ive been trying to resolve the same (or at least a similar)problem
for a little while. All i wanted to do was to be able to dynamicaly change
the range of a scalarBar Actor, but with no success. However, i can now do
it. The piece of tcl code at the bottom of this email demonstrates it. All
it does is use a slider to change the upper limit of a scalar bar. The
critical line, the 4th last line of code, i.e

scalarBar SetTitle "$value"

makes it happen. If this line is commented out then the upper limit remains
unchanged. So, is this a feature or a bug? can someone clarify whats going
on here?

Thanks


catch {load vtktcl}
# user interface command widget
source vtkInt.tcl
# create a rendering window and renderer
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1

vtkLookupTable lut
    lut SetTableRange 0 500
    lut SetHueRange 0.66667 0.0
    lut Build

# Create a scalar bar
vtkScalarBarActor scalarBar

    scalarBar SetLookupTable lut
    scalarBar SetTitle "Temperature"
    [scalarBar GetPositionCoordinate]
SetCoordinateSystemToNormalizedViewport
    [scalarBar GetPositionCoordinate] SetValue 0.1 0.01
    scalarBar SetOrientationToHorizontal
    scalarBar SetWidth 0.8
    scalarBar SetHeight 0.17

vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

ren1 AddActor2D scalarBar
renWin SetSize 500 500
renWin Render

# enable user interface interactor
iren SetUserMethod {wm deiconify .vtkInteract}
iren Initialize

frame .f
label .f.l -text "Change Colour LUT"
scale .f.r -from 0 -to 500 -background #f00 \
	-orient horizontal -command SetLUT
pack .f.r .f.l
pack .f

proc SetLUT {value } {
	lut SetTableRange 0 [expr $value +1]
	scalarBar SetTitle "$value"
	wm title . "$value"
	renWin Render
	}

Mark Palmer
Leeuwin Centre
Environmetrics Project
65 Brockway Rd,
CSIRO Mathematical and Information Sciences
Floreat Park
Phone:              61-8-9333-6293
Western Australia
Fax:                  61-8-9333-6713
Australia, 6014 
email                 Mark.Palmer at cmis.csiro.au
URL:                 http://www.cmis.csiro.au/envir



> -----Original Message-----
> From: Randy Heiland [mailto:heiland at ncsa.uiuc.edu]
> Sent: Thu, 13 July 2000 2:37
> To: vtkusers at public.kitware.com
> Subject: [vtkusers] vtkScalarBarActor range problem
> 
> 
> I can't figure out how to update the range (labels) on a 
> vtkScalarBarActor when
> its associated mapper changes.  I've included a test pgm.
> 
> thanks for any help,
> --Randy
> 
> //
> // Try to resolve confusion over a mapper's (scalar) range and its
> // associated LUT's (table, scalar) range
> //
> 
> #include <stdlib.h>
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkLookupTable.h"
> #include "vtkPoints.h"
> #include "vtkCellArray.h"
> #include "vtkPolyData.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkActor.h"
> #include "vtkScalarBarActor.h"
> 
> int main(int argc, char **argv)
> {
>   vtkRenderer *renderer = vtkRenderer::New();
>   vtkRenderWindow *renWin = vtkRenderWindow::New();
>     renWin->AddRenderer(renderer);
> 
>   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>     iren->SetRenderWindow(renWin);
> 
>   // ----  explicitly define one LUT
>   vtkLookupTable *lut = vtkLookupTable::New();
>   lut->Build();
> 
>   // ----- create line #1 ---------
>   vtkPoints *pts1 = vtkPoints::New();
>     pts1->InsertPoint(0, -1,0,0);
>     pts1->InsertPoint(1,  0,0,0);
>     pts1->InsertPoint(2,  1,0,0);
> 
>   vtkScalars *scalars1 = vtkScalars::New();
> //???
> //    scalars1->SetLookupTable(lut);
>     scalars1->InsertScalar(0, -1.1);
>     scalars1->InsertScalar(1,  0.2);
>     scalars1->InsertScalar(2,  2.2);
> 
>   vtkCellArray *ca1 = vtkCellArray::New();
>     ca1->InsertNextCell(3);
>     ca1->InsertCellPoint(0);
>     ca1->InsertCellPoint(1);
>     ca1->InsertCellPoint(2);
> 
>   vtkPolyData *line1 = vtkPolyData::New();
>     line1->SetPoints(pts1);
>     line1->SetLines(ca1);
>     line1->GetPointData()->SetScalars(scalars1);
> //    float *line1Range = 
> line1->GetPointData()->GetScalars()->GetRange();
> //    printf("line1Range = %f %f",line1Range[0],line1Range[1]);
> 
>   vtkPolyDataMapper *line1Map = vtkPolyDataMapper::New();
>     line1Map->SetInput(line1);
>     line1Map->ScalarVisibilityOn();
>     line1Map->SetLookupTable(lut);
>     line1Map->SetScalarRange(-1.1,2.2);
> 
>   vtkActor *line1Actor = vtkActor::New();
>     line1Actor->SetMapper(line1Map);
> 
>   // ----- Add actor ---------
>   vtkScalarBarActor *ColorBarActor = vtkScalarBarActor::New();
>   ColorBarActor->SetLookupTable(line1Map->GetLookupTable());
>   
> ColorBarActor->GetPositionCoordinate()->SetCoordinateSystemToN
> ormalizedViewport();
>   ColorBarActor->GetPositionCoordinate()->SetValue(0.1, 0.01);
>   ColorBarActor->SetOrientationToHorizontal();
>   ColorBarActor->SetWidth(0.8);
>   ColorBarActor->SetHeight(0.05);
> 
> 
>   // ----- Add actor ---------
>   renderer->AddActor(line1Actor);
>   renderer->AddActor2D(ColorBarActor);
> 
>   renderer->SetBackground(0,0,0);
>   renWin->SetSize(300,300);
> 
>   cout<<"------------ line1Map:"<<endl;
>   line1Map->PrintSelf(cout,4);
> 
>   renWin->Render();
> 
> 
> 
>   cout << "\n--- press key to change range -> 0,2:" <<endl;
>   int val;;
> //  cin >> val;
>   getchar();
> 
>   // Change the scalar range of the mapper
> //  line1Map->SetScalarRange(-1.1,2.2);
>   line1Map->SetScalarRange(0.0,2.0);
> 
>   // Change the scalar range of the LUT
>   lut->SetTableRange(0.0,2.0);
>   lut->Build();
>   line1Map->SetLookupTable(lut);
>   line1Map->Update();
> 
>   ColorBarActor->SetLookupTable(line1Map->GetLookupTable());
> 
> 
>   cout<<"------------ line1Map(2):"<<endl;
>   line1Map->PrintSelf(cout,8);
> 
>   renWin->Render();
>   iren->Start();
> }
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: 
<http://public.kitware.com/cgi-bin/vtkfaq>
vtkusers mailing list
vtkusers at public.kitware.com
http://public.kitware.com/mailman/listinfo/vtkusers




More information about the vtkusers mailing list