[vtkusers] Help on Point Coloring
Helder Carvalho
hel_carvalho at hotmail.com
Mon Sep 1 10:48:22 EDT 2003
Hi,
Could someone Please take a look a t this code and see What im dong wrong.
The objective is to paint each of the 300 points with diferent colors. The
problem is probably related with the LookUpTable but i cant figure how to
work with this things.
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkActorCollection.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPolyDataReader.h"
#include "vtkProperty.h"
#include "vtkPointData.h"
#include "vtkIntArray.h"
#include "vtkCellArray.h"
#include "vtkLookupTable.h"
void main()
{
float colors[300][3];
for(int go = 0; go<300; go++)
{
colors[go][0] = 1-(go*0.02);
colors[go][1] = go*0.02;
colors[go][2] = 0.5+go*0.01;
}
vtkPolyDataReader *inReader = vtkPolyDataReader::New();
inReader->SetFileName("In");
inReader->Update();
vtkPolyData *Poly = inReader->GetOutput();
Poly->Update();
vtkLookupTable *lut = vtkLookupTable::New();
lut->SetNumberOfColors(Poly->GetNumberOfPoints());
lut->Build();
for(int kValue=0; kValue<Poly->GetNumberOfPoints(); kValue++)
{
lut->SetTableValue(kValue,colors[kValue][0],colors[kValue][1],colors[kValue[2],1);
}
vtkCellArray *ca = vtkCellArray::New();
vtkIntArray *scalars = vtkIntArray::New();
for(kValue=0; kValue<Poly->GetNumberOfPoints(); kValue++)
{
ca->InsertNextCell(1);
ca->InsertCellPoint(kValue);
scalars->InsertNextTuple1(kValue);
}
vtkPolyData *cutPoly = vtkPolyData::New();
cutPoly->SetPoints (Poly->GetPoints());
cutPoly->SetVerts(ca);
cutPoly->GetPointData()->SetScalars(scalars);
cutPoly->Update();
vtkPolyDataMapper *inMapper = vtkPolyDataMapper::New();
inMapper->SetLookupTable(lut);
inMapper->SetInput(cutPoly);
inMapper->Update();
vtkActor *inActor = vtkActor::New();
inActor->GetProperty()->SetPointSize(5);
inActor->SetMapper(inMapper);
vtkRenderWindow *renWin = vtkRenderWindow::New();
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(inActor);
ren->SetBackground(0.3, 0.3, 0.3);
renWin->AddRenderer(ren);
renWin->SetSize(800, 800);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->Initialize();
iren->Start();
}
Regards,
Helder Carvalho
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the vtkusers
mailing list