[vtkusers] Interactivly changing isovalue using slider

Divya Rathore divyarathore at gmail.com
Wed Jan 29 12:06:35 EST 2014


Hi All,

I am trying to change the isovalue interactively in the medical2 sample. I
am trying to use the 3D Slider example (
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/Slider) to do this.

I have modified the above class vtkSliderCallback as:

class vtkSliderCallback : public vtkCommand
{
public:
static vtkSliderCallback *New()
 {
return new vtkSliderCallback;
}
 virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkSliderWidget *sliderWidget = reinterpret_cast<vtkSliderWidget*>(caller);
 int value = static_cast<int>(static_cast<vtkSliderRepresentation
*>(sliderWidget->GetRepresentation())->GetValue());
 this->contourFilter->SetValue(0, value);
this->contourFilter->Update();
this->polyDataNormals->Update();
 this->stripper->Update();
this->polyDataMapper->Update();
this->renderWindow->Render();
 }
 vtkSliderCallback():ImageActor(0)
 {
contourFilter = NULL;
polyDataNormals = NULL;
 stripper = NULL;
polyDataMapper = NULL;
 renderWindow = NULL;
}
vtkContourFilter *contourFilter;
 vtkPolyDataNormals *polyDataNormals;
vtkStripper *stripper;
vtkPolyDataMapper *polyDataMapper;
 vtkRenderWindow* renderWindow;

};


main()
{

// read data
  // 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();
  //..##

// An isosurface, or contour value of 500 is known to correspond to
// the skin of the patient. Once generated, a vtkPolyDataNormals
// filter is is used to create normals for smooth surface shading
// during rendering.  The triangle stripper is used to create triangle
// strips from the isosurface; these render much faster on may
// systems.
  vtkSmartPointer<vtkContourFilter> Extractor =
    vtkSmartPointer<vtkContourFilter>::New();
  Extractor->SetInputConnection( v16->GetOutputPort());
  Extractor->ReleaseDataFlagOn();
  Extractor->SetValue(0, 10240.0);
  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();

  vtkSmartPointer<vtkPolyDataMapper> Mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  Mapper->SetInputConnection(grainStripper->GetOutputPort());
  Mapper->ReleaseDataFlagOn();
  Mapper->ScalarVisibilityOff();

  vtkSmartPointer<vtkActor> surface =
    vtkSmartPointer<vtkActor>::New();
  surface->SetMapper(grainMapper);
  surface->GetProperty()->SetDiffuseColor(.66, .92, .33);
  surface->GetProperty()->SetSpecular(.3);
  surface->GetProperty()->SetSpecularPower(20);
  surface->GetProperty()->SetOpacity(1.0);


// set up the slider
  vtkSmartPointer<vtkSliderCallback> callbackSlider =
vtkSmartPointer<vtkSliderCallback>::New();
  callbackSlider->contourFilter = Extractor;
  callbackSlider->polyDataNormals = Normals;
  callbackSlider->stripper = Stripper;
  callbackSlider->polyDataMapper = Mapper;
  callbackSlider->renderWindow = renWin;

//..
// other aspects as covered in the above URL
//..

// Finally add observer
sliderWidgetSCP->AddObserver(vtkCommand::EndInteractionEvent,
callbackSlider);

}



As such the interactivity pipeline is in place. But the problem is that on
moving the slider the previous iso-values are not clearing and the surfaces
keep on adding up (the shown surface keeps growing, obviously it all having
the same color due to the call this->contourFilter->SetValue(0, value))

What am I missing here? I want just that iso-value to be shown that the
slider reflects.

best regards,
Divya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140129/48037214/attachment.html>


More information about the vtkusers mailing list