[vtkusers] color mapping on isosurface

Tracy flypureau at hotmail.com
Tue Nov 9 02:32:43 EST 2004


Hi, everyone,

I try to use colour mapping on the isosuface which is generated by vtkMarchingCubes.
The scalar range is between 0 and 53. but I only can get one colour. 

The following is my code structure. Please help me to find where I am wrong.

Thanks in advance!

Tracy

*************************************************************************************************************************************************

int main(int argc, char **argv)
{
 float range[2];

// Read dataset and extract a portion of an input structured points dataset
vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();  
 reader->SetFileName(".//Data//MH_Zoning2.vtk");

vtkExtractVOI *extract = vtkExtractVOI::New();
 extract->SetInput(reader->GetOutput());
 extract->SetVOI(0, 49, 0, 24, 0, 79);      // whole dimention 50*50*80 
 extract->SetSampleRate(1, 2, 3);
 extract->Update();
 extract->GetOutput()->GetScalarRange(range);

// define lookuptable
vtkLookupTable *lut = vtkLookupTable::New();
    lut->SetHueRange (0.0,0.667);
 lut->SetNumberOfColors (256);
 lut->Build();
 for (int i=0; i<53; i++)
      lut->SetTableValue(i, (i+1)/255.0,(i+2)/255.0,(i+3)/255.0, 1.0);

// data rendering
vtkMarchingCubes *plane = vtkMarchingCubes::New();
   plane->SetInput(extract->GetOutput());
   plane->GenerateValues(54, 0,53);

vtkCleanPolyData *cleaner = vtkCleanPolyData::New();
   cleaner->SetInput(plane->GetOutput());
   
 //vtkDecimatePro *deci = vtkDecimatePro::New();
 //   deci->SetInput(contours->GetOutput());
 //   deci->SetTargetReduction(0.9);
 //   deci->PreserveTopologyOn();

vtkSmoothPolyDataFilter *smoother = vtkSmoothPolyDataFilter::New();
    smoother->SetInput (cleaner->GetOutput());
 smoother->SetNumberOfIterations(150);
    
vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
    normals->SetInput (smoother->GetOutput());
    normals->FlipNormalsOff();

vtkPolyDataMapper *contMapper = vtkPolyDataMapper::New();
   contMapper->SetInput(normals->GetOutput());
   contMapper->ScalarVisibilityOn();
   contMapper->SetScalarRange(range);
   contMapper->SetLookupTable(lut);

vtkActor *contActor = vtkActor::New();
   contActor->SetMapper(contMapper);
   contActor->GetProperty()->SetOpacity (1);

// window stuff
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer( ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow( renWin);

ren1->SetBackground( 0.5, 0, 0.5);
ren1->AddActor( contActor);

iren->Initialize();
iren->Start();

reader->Delete();
extract->Delete();
lut->Delete();
.....

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20041109/16cb528d/attachment.htm>


More information about the vtkusers mailing list