[vtkusers] Quadratic cell data bug ?
    John Platt 
    jcplatt at lineone.net
       
    Mon Feb 21 09:06:46 EST 2005
    
    
  
Hi Jacques,
 
On a very quick look, check
 
     currentMapper->SetScalarModeToUseCellData();  
Did you mean point data?
 
HTH 
John.
 
 
-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
Behalf Of jacques.charreyron
Sent: 21 February 2005 10:25
To: vtkusers at vtk.org
Subject: [vtkusers] Quadratic cell data bug ?
 
Hello,
I am trying to display values on quadratic cells. In my example I have
one quadratic quad cell 
I allocate only one tuple in my float array and put an arbitrary value :
    vtkFloatArray *pointScalars = vtkFloatArray::New();
    
    pointScalars->SetNumberOfComponents(1);
    pointScalars->SetNumberOfTuples(6);
    pointScalars->SetTuple1(0,10.0);
    grid->GetCellData()->SetScalars(pointScalars);
When running this example I get this error :
ERROR: In
G:\Sandbox\Shared\common\intel_a\Api\Vtk\R4.4\Src\Common\vtkDataSet.cxx,
line 403
vtkPolyData (0x01BADF98): Cell array  with 1 components, has only 0
tuples but there are 6 cells
When I allocate six tuples to put six value : ie one for each triangle
like this :
    vtkFloatArray *pointScalars = vtkFloatArray::New();
    
    pointScalars->SetNumberOfComponents(1);
    pointScalars->SetNumberOfTuples(6);
    pointScalars->SetTuple1(0,10.0);
    pointScalars->SetTuple1(1,10.0);
    pointScalars->SetTuple1(2,10.0);
    pointScalars->SetTuple1(3,10.0);
    pointScalars->SetTuple1(4,10.0);
    pointScalars->SetTuple1(5,10.0);
    grid->GetCellData()->SetScalars(pointScalars);
  
 I get the following error :
Warning: In
G:\Sandbox\Shared\common\intel_a\Api\Vtk\R4.4\Src\Common\vtkDataSet.cxx,
line 411
vtkUnstructuredGrid (0x01B8CB00): Cell array  with 1 components, has 6
tuples but there are only 1 cells
ERROR: In
G:\Sandbox\Shared\common\intel_a\Api\Vtk\R4.4\Src\Common\vtkDataSet.cxx,
line 403
vtkPolyData (0x01BADF98): Cell array  with 1 components, has only 0
tuples but there are 6 cells
Any idea ?
Here is a code snippet to reproduce the 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>
#include <vtkCellData.h>
int main( int argc, char *argv[] )
{
    vtkPoints *points = vtkPoints::New();
    points->SetNumberOfPoints(8);
    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,    0.5,    0,        0);
    points->SetPoint(5,    1,        0.5,    0);
    points->SetPoint(6,    0.5,    1,        0);
    points->SetPoint(7,    0,        0.5,    0);
    vtkIdType pointIds[8];
    
    pointIds[0] = 0;
    pointIds[1] = 1;
    pointIds[2] = 2;
    pointIds[3] = 3;
    pointIds[4] = 4;
    pointIds[5] = 5;
    pointIds[6] = 6;
    pointIds[7] = 7;
    //--------------
    // Quad grid
    //--------------
    vtkUnstructuredGrid*    grid = vtkUnstructuredGrid::New();
    grid->Allocate(1);
    grid->SetPoints(points);
    grid->InsertNextCell(VTK_QUADRATIC_QUAD,8,pointIds);
    // Point data (scalars)
    vtkFloatArray *pointScalars = vtkFloatArray::New();
    
    pointScalars->SetNumberOfComponents(1);
    pointScalars->SetNumberOfTuples(6);
    pointScalars->SetTuple1(0,10.0);
    grid->GetCellData()->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->ScalarVisibilityOff();
    currentMapper->SetLookupTable(lookupTable);
    currentMapper->SetInterpolateScalarsBeforeMapping(1);
    currentMapper->SetScalarModeToUseCellData();
    // 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;
}
  <http://premiummail.caramail.lycos.fr/Images/Mail/_icons/premium.gif>
300 Mo gratuits sur CaraMail : Cliquez
<http://secure.caramail.lycos.fr/services/signin/mail.jsp>  ici pour en
profiter!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050221/8d5f092f/attachment.htm>
    
    
More information about the vtkusers
mailing list