[vtkusers] vtkImageStencil problem

liulewes lewes_infor at hotmail.com
Mon Aug 27 13:50:41 EDT 2012


Thanks David, I just tried your suggestions. However, it seems that the latest version does not solve the problem.
Besides, I think line 549 in vtkImageStencilData.cxx should be fixed in V5.10. "if (clist != &this->ExtentListLengths[n + incr])" should be "if (clist != &this->ExtentListLengths[n + 2*incr])"
otherwise will cause run time crash. After this fix, I got the same run time error as when I use V5.8.
Back to the original topic, I cannot provide a concrete example, but I paste the key code segments here,appreciate if someone can take look:

// add/remove stencil
bool Image2DGUITools::AddROIStencil(int isign)
    {
        if (NULL == _iren || NULL == _Renderer || NULL == _Image)
        {
            return false;
        }

        int pos[2] = {0,0};
        _iren->GetEventPosition(pos);
        vtkPointPicker* pp = vtkPointPicker::New();
        bool bflag = false;

        if ((0 != pp->Pick(pos[0],pos[1],0,_Renderer))&&(NULL != pp->GetPickedPositions())&&(0 != pp->GetPickedPositions()->GetNumberOfPoints()))
        {
            double pw[3] = {0,0,0};
            double dradius = 10;
            vtkPoints* pts = pp->GetPickedPositions();
            pts->GetPoint(0,pw);

            vtkROIStencilSource* roistencil = vtkROIStencilSource::New();
            roistencil->SetBounds(pw[0]-dradius,pw[0]+dradius,pw[1]-dradius,pw[1]+dradius,pw[2],pw[2]);
            roistencil->SetInformationInput(_Image);
            roistencil->SetShapeToCylinderZ();
            roistencil->Update();

            if (isign>=0)
            {
                _ROIStencil->GetStencil()->Add(roistencil->GetOutput());
                bflag = true;
            }
            else
            {
                _ROIStencil->GetStencil()->Subtract(roistencil->GetOutput());
                bflag = true;
            }

            roistencil->Delete();
        }

        pp->Delete();

        return bflag;
    }

/** render ROI using image stencil */
    bool Image2DGUITools::ROIBlend(vtkImageData* frg, double* color)
    {
        if (NULL == frg || NULL == color || NULL == _ROIStencil)
        {
            return false;
        }

        vtkImageCast* cast = vtkImageCast::New();
        cast->SetOutputScalarTypeToShort();
        cast->SetInput(frg);

        _ROIStencil->SetInput(cast->GetOutput());
        _ROIStencil->SetBackgroundColor(color);
        _ROIStencil->Update();

        _BlendImage = _ROIStencil->GetOutput();

        return true;
    }

> From: david.gobbi at gmail.com
> Date: Thu, 23 Aug 2012 16:42:16 -0600
> Subject: Re: [vtkusers] vtkImageStencil problem
> To: lewes_infor at hotmail.com
> CC: vtkusers at vtk.org
> 
> Actually, looking through the git log for vtkImageStencilData, there were
> a couple bugs fixed between VTK 5.8 and VTK 5.10.  Both are fixes
> for things that could lead to bad pointers:
> 
> Date:   Tue Nov 15 10:16:47 2011 -0700
> BUG: Fix incorrect code for combining adjacent extents.
> 
> Date:   Sun Oct 16 15:58:20 2011 -0600
> BUG: Fix a valgrind UMC in vtkImageStencilData.
> 
> If you compiled your VTK from source, I suggest that you grab
> a copy of VTK 5.10 and copy vtkImageStencilData.h/.cxx into
> your copy of VTK 5.8.  (If you didn't compile from source, you
> could just do a complete update from VTK 5.8 to VTK 5.10).
> 
>  - David
> 
> 
> On Thu, Aug 23, 2012 at 4:33 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> > Hi Lewes,
> >
> > If there is a bug, I suspect it would be in the Subtract() method, rather
> > than in the vtkImageStencil filter.  I can look through the Subtract()
> > code to see if there is anything that looks wrong.  Is there a way that
> > you can create a minimal program+data that I can run on my own
> > system to duplicate the crash?
> >
> >  - David
> >
> > On Thu, Aug 23, 2012 at 2:52 PM, liulewes <lewes_infor at hotmail.com> wrote:
> >> Hi all, I'm using vtkImageStencil to create ROIs on an image. The
> >> vtkImageStencilData::Add() works well for me, but
> >> vtkImageStencilData::Subtract() will cause my program to crash form time to
> >> time.
> >> By looking at the source code, the program crashes in vtkImageStencil.cxx
> >> line 194 where "tmpPtr" becomes invalid and (outSpanEndPtr - outPtr) becomes
> >> negative. I'm not sure whether vtkImageStencilData::Subtract() causes this
> >> problem or it's sth. else. Can anyone give some suggestions?
> >> Lewes.
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120827/ca673270/attachment.htm>


More information about the vtkusers mailing list