[vtkusers] help needed setting up the colormap/lookuptable/mapper in C++
David, John
john.david at uconn.edu
Mon Aug 13 17:16:51 EDT 2007
> put the header
> #include "vtkPointData.h"
it is already in there...
Hmmm... tell you what. At the end you will find a minimal case (but with full source) to reproduce this problem.
EBo --
ps: I've appended the code instead of attaching it to the email just in case the server strips attachments by default.
===============================================
#include <cstdlib>
#include <ctime>
#include <iostream>
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataWriter.h"
#include "vtkDoubleArray.h"
using namespace std;
int
main(int argc, char** argv)
{
int i;
int num_points = 100;
double x,y,z; // data points
double rnd_min=1.0, rnd_max=-1.0; // cache the range for SetScalarRange
vtkPoints *points = vtkPoints::New();
vtkDoubleArray *scalars = vtkDoubleArray::New();
srand48((unsigned)time(NULL));
for (i=0; i<num_points; i++)
{
// the original code read in XYZ triplets, but for testing
// just randomly create XY and set the Z to be on a slanted
// plane
x = drand48();
y = drand48();
z = (x+y)/2.0;
if (z < rnd_min) rnd_min = z;
if (z > rnd_max) rnd_max = z;
points->InsertPoint(i, x, y, z);
scalars->InsertNextValue(z);
}
vtkCellArray *polys = vtkCellArray::New();
polys->InsertNextCell(points->GetNumberOfPoints());
for (i=0; i<points->GetNumberOfPoints(); i++)
{
polys->InsertCellPoint(i);
}
vtkPolyData *polyData = vtkPolyData::New();
polyData->SetPoints(points);
polyData->SetPolys(polys);
// problem line
polyData->GetPointData()->SetScalarRange( rnd_min, rnd_max );
polyData->Update();
vtkPolyDataWriter* writer1 = vtkPolyDataWriter::New();
writer1->SetInput(polyData);
writer1->SetFileName( "tst_points.vtk" );
writer1->Update();
writer1->Delete();
return 0;
}
More information about the vtkusers
mailing list