[vtkusers] Results rendering bug ?

Jacques Charreyron-F264897 Jacques.Charreyron at fr.michelin.com
Thu Jan 6 06:11:25 EST 2005


Dear vtkusers,

I have a problem rendering results on quads ( and this is true, of course, for
3D elements using quads). Let's imagine we have two quads with the following
values on nodes :


0-------------1--------------0
|             |              |
|             |              | 
|             |              |
0-------------0--------------0

We would expect symetrical color gradients. But because of triangulation we get
two different mappings.

Those two quads are transformed into triangles this way (depending only on the
shortest diagonal) :
        triangle (1) with values 0 1 0
        triangle (2) with values 0 0 1
        triangle (3) with values 0 0 1
        triangle (4) with values 0 0 0

0---------------1----------------0
|          /    |           /    |
| (1)   /  (2)  |   (3)  /  (4)  | 
|    /          |    /           |
0---------------0----------------0

We can now see the problem :
    triangle (4) will be rendered with a single color which is false according
to the finite element and true according to OpenGl triangles.

        
One suggestion would be the following : change the triangulation of quads to
make it symetrical using by creating a fake center node located at the quad
center of gravity (simple surgery in vtkQuad::Triangulate()) assigned with a
value computed using interpolation functions. This has one major drawback :
    it introduces different kind of nodes/scalars reals and fakes 


Here is a code snippet to reproduce behaviour :


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


#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>
#include <vtkLookupTable.h>
#include <vtkTexture.h>
#include <vtkStructuredPoints.h>
#include <vtkBandedPolyDataContourFilter.h>
#include <vtkGeometryFilter.h>
#include <vtkPolyDataMapper.h>

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

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

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

    points->SetPoint(4, 2,      0,      0);
    points->SetPoint(5, 2,      1,      0);



    vtkIdType pointIds[4];
    
    pointIds[0] = 0;
    pointIds[1] = 1;
    pointIds[2] = 2;
    pointIds[3] = 3;
    
    vtkIdType pointIds2[4];

    pointIds2[0] = 1;
    pointIds2[1] = 2;
    pointIds2[2] = 5;
    pointIds2[3] = 4;
    

    //--------------
    // Quad grid
    //--------------

    vtkUnstructuredGrid*    grid = vtkUnstructuredGrid::New();

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

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



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


    // 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);
    currentMapper->SetInterpolateScalarsBeforeMapping(1);

    // 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;
}


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



 

Do you think this is worth reporting it as a bug ?


Yours,


Jacques Charreyron

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


More information about the vtkusers mailing list