[vtkusers] How to visualize segments/surfaces selectively: vtkLookupTable with vtkContourFilter

Bill Lorensen bill.lorensen at gmail.com
Fri Feb 28 07:11:18 EST 2014


Try DiscreteMarchingCubes. It works with segmented data that has
discrete labels.


On Fri, Feb 28, 2014 at 5:32 AM, Divya Rathore <divyarathore at gmail.com> wrote:
> I have a 16bit cube data that has various segments of unique grey levels. I
> want to visualize each of these segments selectively using a slider (just
> the surface visualization is good enough) . This slider ranges from the min
> to the max of the grey levels in that cube.
>
> I expected isosurfaces to do that job well. But it seems any level of
> isovalue behaves somewhat like thresholding and essentially divides the grey
> levels in 2 parts - the ones lower than the isovalue and the ones higher
> than the isovalue. This means that all of the segments higher than the
> selected would get 'iso-surfaced' (if I may say so!) as well (as in attached
> image).
>
> How can I view just one of the segments at a time, interactively?
> Ideally in the image, I should be seeing just 1 of those structures at a
> time (it currently shows 3).
>
> here's part of the code:
>
>
> // short data
>
> vtkSmartPointer<vtkImageReader> v16 =
> vtkSmartPointer<vtkImageReader>::New();
>
> v16->SetFileName(argv[2]);
> v16->SetFileDimensionality(3);
> v16->SetDataScalarTypeToUnsignedShort();
> v16->SetDataByteOrderToLittleEndian();
> v16->SetNumberOfScalarComponents(1);
> v16->SetDataExtent(0,width-1, 0,height-1, 0,depth-1);
> v16->SetDataSpacing (1.0, 1.0, 1.0);
> v16->Update();
>
> double range[2];
> v16->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
> std::cout << "Range: " << range[0] << " , " << range[1] << std::endl;
> double midpoint = (range[1]-range[0])/2;
>
> //Now build a LUT
> vtkSmartPointer<vtkLookupTable> lookupTable =
> vtkSmartPointer<vtkLookupTable>::New();
> lookupTable->SetNumberOfTableValues(range[1]);
> lookupTable->SetTableRange(range[0], range[1]);
> // Firstly, set all transparent
> for(int i=range[0]; i<range[1]; ++i)
> {
> lookupTable->SetTableValue( i, .66, .92, .33, 0.0 ); //some shade of green
> but transparent
> }
> // Make that 1 value corresponding to slider visible
> lookupTable->SetTableValue( (int) midpoint, .66, .92, .33, 1.0 ); //same
> color as above, but visible
> lookupTable->Build();
>
> //Usual steps as in Medical3 example
> vtkSmartPointer<vtkContourFilter> Extractor =
> vtkSmartPointer<vtkContourFilter>::New();
> Extractor->SetInputConnection( v16->GetOutputPort());
> Extractor->SetNumberOfContours(1);
> // set an isovalue. in this case, the midpoint of the greyscales
> Extractor->GenerateValues(1, midpoint, midpoint);
> Extractor->Update();
>
> vtkSmartPointer<vtkPolyDataNormals> Normals =
> vtkSmartPointer<vtkPolyDataNormals>::New();
> Normals->SetInputConnection(grainExtractor->GetOutputPort());
> Normals->ReleaseDataFlagOn();
> Normals->SetFeatureAngle(60.0);
> Normals->Update();
>
> vtkSmartPointer<vtkStripper> Stripper =
> vtkSmartPointer<vtkStripper>::New();
> Stripper->SetInputConnection(grainNormals->GetOutputPort());
> Stripper->ReleaseDataFlagOn();
> Stripper->Update();
>
> // An addition to Medical 3 example: Provide LUT to Mapper
> vtkSmartPointer<vtkPolyDataMapper> Mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> Mapper->SetInputConnection(grainStripper->GetOutputPort());
> Mapper->ReleaseDataFlagOn();
> Mapper->ScalarVisibilityOn();
> Mapper->SetScalarRange(lookupTable->GetRange());
> Mapper->SetLookupTable(lookupTable);
> Mapper->Update();
>
> vtkSmartPointer<vtkActor> Actor =
> vtkSmartPointer<vtkActor>::New();
> Actor->SetMapper(grainMapper);
> Actor->GetProperty()->SetDiffuseColor(.66, .92, .33);
> Actor->GetProperty()->SetSpecular(.3);
> Actor->GetProperty()->SetSpecularPower(20);
> Actor->GetProperty()->SetOpacity(1.0);
>
>
> // Rest of the code handles a slider that tries to change the isovalue
> // But doesn't reflect the change :(
>
> What's wrong in my approach of using vtkLookupTable with vtkContourFilter?
> Is there an alternate?
>
>
> best regards,
> Divya Rathore
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list