[vtkusers] Scalar color / LookupTable / Interpolation problem...

Jacques Charreyron-F264897 Jacques.Charreyron at fr.michelin.com
Thu Dec 9 08:15:50 EST 2004


Dear vtk users,

I guess i have the same problem as the one discribed in : 
http://public.kitware.com/pipermail/vtkusers/2004-April/073604.html
but for thresholding purpose.

Let's assume we have a quad in an unstructured grid with the following values at
each vertex.
We assign to the data set mapper a lut with ten colors and a color range from 0
to 1 

0.0-------------------  0.5
|                         |
|                         |
0.5 -------------------  1.0

The resulting rendering is a continuous color interpolation with millions of
colors between vertices where I would like to have a color mapping using only 10
colors. The SetInterpolationTo* method does not help.

Here is a code snippet to reproduce the behavior

//------------------------------------------------------------------------
#include <vtkActor.h>
#include <vtkCellType.h>
#include <vtkDataSetMapper.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkUnstructuredGrid.h>
#include <vtkWindowToImageFilter.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkActor2D.h>
#include <vtkLabeledDataMapper.h>
#include <vtkLookupTable.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkMath.h>
#include <vtkScalarBarWidget.h>
#include <vtkScalarBarActor.h>

int main( int argc, char *argv[] )
{

    //-------
    // Points
    //-------
    
    vtkPoints *points = vtkPoints::New();
    points->SetNumberOfPoints(4);

    points->SetPoint(0, 0,      0,      0);
    points->SetPoint(1, 1,      0,      0);
    points->SetPoint(2, 1,      1,      0);
    points->SetPoint(3, 0,      1,      0);

    vtkIdType pointIds[9];
    
    pointIds[0] = 0;
    pointIds[1] = 1;
    pointIds[2] = 2;
    pointIds[3] = 3;
    
    //--------------
    // Quad grid
    //--------------

    vtkUnstructuredGrid*    grid = vtkUnstructuredGrid::New();

    grid->Allocate(1);
    grid->SetPoints(points);

    grid->InsertNextCell(VTK_QUAD,4,pointIds);

    // Point data (scalars)
    vtkFloatArray *pointScalars = vtkFloatArray::New();
    pointScalars->SetNumberOfComponents(1);
    pointScalars->SetNumberOfTuples(4);
    
    pointScalars->SetTuple1(1,0);
    pointScalars->SetTuple1(2,0.5);
    pointScalars->SetTuple1(3,1);
    pointScalars->SetTuple1(4,0.5);
    grid->GetPointData()->SetScalars(pointScalars);
    
    // Lookup :
    vtkLookupTable *lookupTable = vtkLookupTable::New();
    lookupTable->SetNumberOfColors(10);
    lookupTable->SetTableRange(0,1);
    lookupTable->ForceBuild();  

    // Scalar bar actor
    vtkScalarBarWidget  *scalarBarWidget=vtkScalarBarWidget::New();
    vtkScalarBarActor *scalarBarActor = vtkScalarBarActor::New();
    scalarBarActor->SetLookupTable(lookupTable);
    scalarBarWidget->SetScalarBarActor(scalarBarActor);
    scalarBarActor->SetMaximumNumberOfColors(10);


    // Mapper
    vtkDataSetMapper *currentMapper=vtkDataSetMapper::New();
    currentMapper->SetInput(grid);
    currentMapper->SetLookupTable(lookupTable);

    // Actor
    vtkActor *quadActor = vtkActor::New();
    quadActor->SetMapper(currentMapper);

    //--------------
    // Visualization
    //--------------    
    // Renderer
    vtkRenderer *renderer= vtkRenderer::New();
    
    renderer->SetLightFollowCamera(true);
    renderer->SetBackground(0.6,0.7,0.9);
    renderer->AddActor(quadActor);
    renderer->AddActor(scalarBarActor);

    // RenderWindow
    vtkRenderWindow *renderWindow = vtkRenderWindow::New();
    renderWindow->AddRenderer(renderer);
    renderWindow->SetSize(300,300);

    // Interactor
    vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
    interactor->SetRenderWindow(renderWindow);

    // Interactor style
    vtkInteractorStyleTrackballCamera *interactorStyle =   
vtkInteractorStyleTrackballCamera::New();
    interactor->SetInteractorStyle(interactorStyle);

    // Event loop
    interactor->Initialize();
    interactor->Start();



    return 0;
}

//--------------------------------------------------------

Here is also a small jpeg of the result :

 

Does anyone know a workaround ?

Thanks for your help,

Jacques Charreyron

__________________________________________________________
\
 \          Jacques Charreyron
  \          Société Michelin 
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colormapping.jpg
Type: application/octet-stream
Size: 9577 bytes
Desc: colormapping.jpg
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20041209/26aaded7/attachment.obj>


More information about the vtkusers mailing list