[vtkusers] Interactivly changing isovalue using slider

Divya Rathore divyarathore at gmail.com
Thu Jan 30 13:21:09 EST 2014


No luck. Still doesn't work and the iso-surfaces seem to be accumulating.
Probably I need to completely update the actor. How can I do that?

In addition to the suggested function, I modified the callback as follows
(and I still see GetNumberOfContours returning 1):


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);
cout << "# of contours, Now = " <<
this->contourFilter->GetNumberOfContours();
 this->contourFilter->SetValue(0, value);
cout << " and now = " << this->contourFilter->GetNumberOfContours() << endl;
 this->contourFilter->Modified();
this->contourFilter->Update();
 this->polyDataNormals->Modified();
this->polyDataNormals->Update();
 this->stripper->Modified();
this->stripper->Update();
 this->polyDataMapper->Modified();
this->polyDataMapper->Update();

this->renderWindow->Modified();
 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;

};


regards,
Divya

"The difference between school and life? In school, you're taught a lesson
and then given a test. In life, you're given a test that teaches you a
lesson."


On Wed, Jan 29, 2014 at 11:16 PM, Divya Rathore <divyarathore at gmail.com>wrote:

> Thanks for the Gerrick!
> Will check it out at the first chance (couple of hours from now).
>
> Is this to be set just once initially or with each slider move?
>
>
> best regards,
> Divya
>
>
>
> "The difference between school and life? In school, you're taught a lesson
> and then given a test. In life, you're given a test that teaches you a
> lesson."
>
>
> On Wed, Jan 29, 2014 at 11:06 PM, Gerrick Bivins <
> Gerrick.Bivins at halliburton.com> wrote:
>
>> Hi Divya,
>>
>> I also found this a little "unintuitive". Even though you specify the
>> same "contour index" in SetValue,
>>
>> you also need to make sure you set  the number of contours to 1.
>> Otherwise, the filter just continues to add them:
>>
>>
>> http://www.vtk.org/doc/nightly/html/classvtkContourFilter.html#a5485ad7720282f2001fa6443c303003a
>>
>>
>>
>> Hopefully that helps.
>>
>> Gerrick
>>
>> ________________________________
>> From: vtkusers [vtkusers-bounces at vtk.org] on behalf of Divya Rathore [
>> divyarathore at gmail.com]
>> Sent: Wednesday, January 29, 2014 11:06 AM
>> To: vtkusers at vtk.org
>> Subject: [vtkusers] Interactivly changing isovalue using slider
>>
>> 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
>>
>> ----------------------------------------------------------------------
>> This e-mail, including any attached files, may contain confidential and
>> privileged information for the sole use of the intended recipient.  Any
>> review, use, distribution, or disclosure by others is strictly prohibited.
>>  If you are not the intended recipient (or authorized to receive
>> information for the intended recipient), please contact the sender by reply
>> e-mail and delete all copies of this message.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140130/0324bfd7/attachment.html>


More information about the vtkusers mailing list