[vtkusers] Interactivly changing isovalue using slider

Divya Rathore divyarathore at gmail.com
Mon Feb 3 06:08:42 EST 2014


Some details of the scenario I am handling..

- VTK 6.0, 64 Bit
- Visual Studio 2010

I have a 16 bit grey scale 3D data, and each grey scale (ranging from 1 to
1500) belongs to a unique segment in the 3D geometry. The slider is mapped
to this range of 1-1500.

Seems when I am choosing a particular slider position, all segments 'equal
to or greater than' chosen value are being displayed as isosurface. Hence
instead of just segment, I am seeing many of them as one big merged chunk.
My understanding was that the call:

*this->contourFilter->SetValue(**0, value); //value range = 1 to 1500*

..would set just that particular grey scale as isosurface and others would
remain invisible (and is what I need to achieve).

Correct me if I am wrong. Would be much appreciated. Code base remains same
as in previous email.

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 Thu, Jan 30, 2014 at 11:51 PM, Divya Rathore <divyarathore at gmail.com>wrote:

> 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/20140203/a924df20/attachment.html>


More information about the vtkusers mailing list