<div dir="ltr">Hi All,
<div><br></div><div>I am trying to change the isovalue interactively in the medical2 sample. I am trying to use the 3D Slider example (<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/Slider">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/Slider</a>) to do this.</div>
<div><br></div><div>I have modified the above class vtkSliderCallback as:</div><div><br></div><div><div>class vtkSliderCallback : public vtkCommand</div><div>{</div><div>public:</div><div><span class="" style="white-space:pre"> </span>static vtkSliderCallback *New()</div>
<div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre"> </span>return new vtkSliderCallback;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span>virtual void Execute(vtkObject *caller, unsigned long, void*)</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre"> </span>vtkSliderWidget *sliderWidget = reinterpret_cast<vtkSliderWidget*>(caller);</div>
<div><span class="" style="white-space:pre"> </span>int value = static_cast<int>(static_cast<vtkSliderRepresentation *>(sliderWidget->GetRepresentation())->GetValue());</div><div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span>this->contourFilter->SetValue(0, value);</div><div><span class="" style="white-space:pre"> </span>this->contourFilter->Update();</div><div><span class="" style="white-space:pre"> </span>this->polyDataNormals->Update();</div>
<div><span class="" style="white-space:pre"> </span>this->stripper->Update();</div><div><span class="" style="white-space:pre"> </span>this->polyDataMapper->Update();</div><div><span class="" style="white-space:pre"> </span>this->renderWindow->Render();</div>
<div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span>vtkSliderCallback():ImageActor(0) </div>
<div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre"> </span>contourFilter<span class="" style="white-space:pre"> </span>= NULL;</div><div><span class="" style="white-space:pre"> </span>polyDataNormals<span class="" style="white-space:pre"> </span>= NULL;</div>
<div><span class="" style="white-space:pre"> </span>stripper<span class="" style="white-space:pre"> </span>= NULL;</div><div><span class="" style="white-space:pre"> </span>polyDataMapper<span class="" style="white-space:pre"> </span>= NULL;</div>
<div><span class="" style="white-space:pre"> </span>renderWindow<span class="" style="white-space:pre"> </span>= NULL;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>vtkContourFilter *contourFilter;</div>
<div><span class="" style="white-space:pre"> </span>vtkPolyDataNormals *polyDataNormals;</div><div><span class="" style="white-space:pre"> </span>vtkStripper *stripper;</div><div><span class="" style="white-space:pre"> </span>vtkPolyDataMapper *polyDataMapper;</div>
<div><span class="" style="white-space:pre"> </span>vtkRenderWindow* renderWindow;</div><div><br></div><div>};<br></div></div><div><br></div><div><br></div><div>main()</div><div>{</div><div><br></div><div>// read data</div>
<div><div> // short data</div><div> vtkSmartPointer<vtkImageReader> v16 = vtkSmartPointer<vtkImageReader>::New();</div><div> v16->SetFileName(argv[2]);</div><div> v16->SetFileDimensionality(3);</div>
<div> v16->SetDataScalarTypeToUnsignedShort();</div><div> v16->SetDataByteOrderToLittleEndian();</div><div> v16->SetNumberOfScalarComponents(1);</div><div> v16->SetDataExtent(0,width-1, 0,height-1, 0,depth-1);</div>
<div> v16->SetDataSpacing (1.0, 1.0, 1.0);</div><div> v16->Update();</div><div> //..##</div></div><div><br></div><div><div><div>// An isosurface, or contour value of 500 is known to correspond to</div><div>// the skin of the patient. Once generated, a vtkPolyDataNormals</div>
<div>// filter is is used to create normals for smooth surface shading</div><div>// during rendering. The triangle stripper is used to create triangle</div><div>// strips from the isosurface; these render much faster on may</div>
<div>// systems.</div></div><div> vtkSmartPointer<vtkContourFilter> Extractor =</div><div> vtkSmartPointer<vtkContourFilter>::New();</div><div> Extractor->SetInputConnection( v16->GetOutputPort());</div>
<div> Extractor->ReleaseDataFlagOn();</div><div> Extractor->SetValue(0, 10240.0);</div><div> Extractor->Update();</div><div><br></div><div> vtkSmartPointer<vtkPolyDataNormals> Normals =</div><div> vtkSmartPointer<vtkPolyDataNormals>::New();</div>
<div> Normals->SetInputConnection(grainExtractor->GetOutputPort());</div><div> Normals->ReleaseDataFlagOn();</div><div> Normals->SetFeatureAngle(60.0);</div><div> Normals->Update();</div><div><br></div>
<div> vtkSmartPointer<vtkStripper> Stripper =</div><div> vtkSmartPointer<vtkStripper>::New();</div><div> Stripper->SetInputConnection(grainNormals->GetOutputPort());</div><div> Stripper->ReleaseDataFlagOn();</div>
<div> Stripper->Update();</div><div><br></div><div> vtkSmartPointer<vtkPolyDataMapper> Mapper =</div><div> vtkSmartPointer<vtkPolyDataMapper>::New();</div><div> Mapper->SetInputConnection(grainStripper->GetOutputPort());</div>
<div> Mapper->ReleaseDataFlagOn();</div><div> Mapper->ScalarVisibilityOff();</div><div><br></div><div> vtkSmartPointer<vtkActor> surface =</div><div> vtkSmartPointer<vtkActor>::New();</div><div> surface->SetMapper(grainMapper);</div>
<div> surface->GetProperty()->SetDiffuseColor(.66, .92, .33);</div><div> surface->GetProperty()->SetSpecular(.3);</div><div> surface->GetProperty()->SetSpecularPower(20);</div><div> surface->GetProperty()->SetOpacity(1.0);</div>
</div><div><br></div><div><br></div><div>// set up the slider</div><div><div> vtkSmartPointer<vtkSliderCallback> callbackSlider = vtkSmartPointer<vtkSliderCallback>::New();</div><div> callbackSlider->contourFilter<span class="" style="white-space:pre"> </span>= Extractor;</div>
<div> callbackSlider->polyDataNormals<span class="" style="white-space:pre"> </span>= Normals;</div><div> callbackSlider->stripper<span class="" style="white-space:pre"> </span>= Stripper;</div><div> callbackSlider->polyDataMapper<span class="" style="white-space:pre"> </span>= Mapper;</div>
<div> callbackSlider->renderWindow<span class="" style="white-space:pre"> </span>= renWin;</div></div><div><br></div><div>//..</div><div>// other aspects as covered in the above URL</div><div>//..</div><div><br></div>
<div>// Finally add observer</div><div>sliderWidgetSCP->AddObserver(vtkCommand::EndInteractionEvent, callbackSlider);<br></div><div><br></div><div>}</div><div><br></div><div><br></div><div><br></div><div>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))</div>
<div><br></div><div>What am I missing here? I want just that iso-value to be shown that the slider reflects.</div><div><br></div><div>best regards,</div><div>Divya</div></div>