[vtkusers] coloring the cells of vtkDiskSource..

K.R.Subramanian krs at cs.uncc.edu
Fri Jul 19 00:42:39 EDT 2002


I had this piece of code working, but now it seems broken and always draws a fullywhite
disk, ignoring the lookup table. I want to be able to control the color of the cells
within a vtkDiskSource (fed
via a lookuptable).. if anyone sees anything obviously wrong, I would appreciate it.
The same code fed by a vtkStructuredPoints-->vtkGeometryFilter, does color
the cells using this lookup table..

Thanks.

    -- krs




--
K.R.Subramanian                        Phone: (704) 687-4872
Department of Computer Science         FAX:   (704) 687-4893
UNC Charlotte, CARC 311                Email: krs at cs.uncc.edu
Charlotte, NC 28223-0001               Web: http://www.cs.uncc.edu/~krs


-------------- next part --------------
#include <stdio.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkPoints.h>
#include <vtkActor.h>
#include <vtkInteractorStyleTrackball.h>
#include <vtkStructuredGridGeometryFilter.h>
#include <vtkGeometryFilter.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredPoints.h>
#include <vtkLookupTable.h>
#include <vtkPolyDataMapper.h>
#include <fstream>
#include <vtkIntArray.h>
#include <vtkFloatArray.h>
#include <vtkUnsignedCharArray.h>
#include <vtkLookupTable.h>
#include <vtkDiskSource.h>


#define CIRC_RESN 5

void Read (double*, double*, double*, double*);
main(int argc, char **argv)
{
	vtkRenderer *renderer = vtkRenderer::New();
		renderer->SetBackground(0.1,0.3,0.8);

	vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(renderer);
		renWin->SetSize(500,500);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
        iren->SetRenderWindow(renWin);

	vtkInteractorStyleTrackball *trackball = vtkInteractorStyleTrackball::New();
		trackball->SetTrackballModeToTrackball();

    iren->SetInteractorStyle (trackball);

	vtkDiskSource *ds = vtkDiskSource::New();
		ds->SetInnerRadius (0.1);
		ds->SetOuterRadius (1.);
		ds->SetRadialResolution (1);
		ds->SetCircumferentialResolution (CIRC_RESN);

	vtkFloatArray *ia = vtkFloatArray::New();
		ia->SetNumberOfTuples (CIRC_RESN);

	int j;
	for (j = 0; j < CIRC_RESN; j++)
		ia->SetValue (j, (float)j);

	ds->GetOutput()->GetCellData()->SetScalars (ia);
	ds->Update();
	cout << "Number of Cells:" << ds->GetOutput()->GetNumberOfCells() << endl;

	vtkLookupTable *lut = vtkLookupTable::New();
		lut->SetNumberOfColors (5);
		lut->SetTableRange (0., 4.);

		lut->SetTableValue (0, 1., 0., 0.);
		lut->SetTableValue (1, 0., 1., 0.);
		lut->SetTableValue (2, 0., 0., 1.);
		lut->SetTableValue (3, 1., 1., 0.);
		lut->SetTableValue (4, 1., 0., 1.);


	vtkPolyDataMapper *pm = vtkPolyDataMapper::New();
		pm->SetLookupTable (lut);
		pm->SetInput (ds->GetOutput());
		pm->SetScalarModeToUseCellData();
		pm->ScalarVisibilityOn();
		pm->SetScalarRange(lut->GetTableRange());

	vtkActor *a = vtkActor::New();
		a->SetMapper (pm);

	renderer->AddActor (a);

	renWin->Render();
	iren->Start();

	renderer->Delete();
	renWin->Delete();
	iren->Delete();
}
/////////////////////////////////////////////////////////////////////////


More information about the vtkusers mailing list