Problem with vtkDataSetMapper::SetScalarModeToUseCellData()
pahsieh at usgs.gov
pahsieh at usgs.gov
Tue Mar 7 18:35:14 EST 2000
In vtk 3.1, vtkDataSetMapper doesn't seem to recognize cell data.
This is illustrated by the test program below. A structured points
data set with cell data is rendered by both vtkDataSetMapper and
by vtkPolyDataMapper (the latter via vtkGeometryFilter). The
vtkDataSetMapper appears to have lost the scalar data as the
resultant grid is white. In vtk 2.3, both pipelines lead to
identical images.
This is not a severe program because one can always work around
it by using vtkGeometryFilter and vtkPolyDataMapper.
Thanks.
Paul
//=======test program=======
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPoints.h"
#include "vtkScalars.h"
#include "vtkGeometryFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkDataSetMapper.h"
#include "vtkActor.h"
void main()
{
// Create rendering stuff
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// Create structured points data set
vtkStructuredPoints *sp = vtkStructuredPoints::New();
sp->SetDimensions(3, 3, 1);
sp->SetOrigin(0, 0, 0);
sp->SetSpacing(1, 1, 1);
// Create cell scalars
vtkScalars *scalars = vtkScalars::New();
for (int i=0; i<4; i++)
{
scalars->InsertNextScalar(i*0.33f);
}
sp->GetCellData()->SetScalars(scalars);
scalars->Delete();
// Render the data set by vtkPolyDataMapper via vtkGeometryFilter
// (works in vtk 3.1)
vtkGeometryFilter *geom = vtkGeometryFilter::New();
geom->SetInput(sp);
vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(geom->GetOutput());
mapper1->SetScalarModeToUseCellData();
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
ren->AddActor(actor1);
// Render the same data set by vtkDataSetMapper
// (doesn't work in vtk 3.1 but works in vtk 2.3)
vtkDataSetMapper *mapper2 = vtkDataSetMapper::New();
mapper2->SetInput(sp);
mapper2->SetScalarModeToUseCellData();
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
actor2->AddPosition(4, 0, 0);
ren->AddActor(actor2);
renWin->Render();
iren->Start();
ren->Delete();
renWin->Delete();
iren->Delete();
sp->Delete();
geom->Delete();
mapper1->Delete();
actor1->Delete();
mapper2->Delete();
actor2->Delete();
}
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------
More information about the vtkusers
mailing list