<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:微软雅黑
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Thanks David, I just tried your suggestions. However, it seems that the latest version does not solve the problem.<br>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])"<br>otherwise will cause run time crash. After this fix, I got the same run time error as when I use V5.8.<br>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:<br><br>// add/remove stencil<br>bool Image2DGUITools::AddROIStencil(int isign)<br> {<br> if (NULL == _iren || NULL == _Renderer || NULL == _Image)<br> {<br> return false;<br> }<br><br> int pos[2] = {0,0};<br> _iren->GetEventPosition(pos);<br> vtkPointPicker* pp = vtkPointPicker::New();<br> bool bflag = false;<br><br> if ((0 != pp->Pick(pos[0],pos[1],0,_Renderer))&&(NULL != pp->GetPickedPositions())&&(0 != pp->GetPickedPositions()->GetNumberOfPoints()))<br> {<br> double pw[3] = {0,0,0};<br> double dradius = 10;<br> vtkPoints* pts = pp->GetPickedPositions();<br> pts->GetPoint(0,pw);<br><br> vtkROIStencilSource* roistencil = vtkROIStencilSource::New();<br> roistencil->SetBounds(pw[0]-dradius,pw[0]+dradius,pw[1]-dradius,pw[1]+dradius,pw[2],pw[2]);<br> roistencil->SetInformationInput(_Image);<br> roistencil->SetShapeToCylinderZ();<br> roistencil->Update();<br><br> if (isign>=0)<br> {<br> _ROIStencil->GetStencil()->Add(roistencil->GetOutput());<br> bflag = true;<br> }<br> else<br> {<br> _ROIStencil->GetStencil()->Subtract(roistencil->GetOutput());<br> bflag = true;<br> }<br><br> roistencil->Delete();<br> }<br><br> pp->Delete();<br><br> return bflag;<br> }<br><br>/** render ROI using image stencil */<br> bool Image2DGUITools::ROIBlend(vtkImageData* frg, double* color)<br> {<br> if (NULL == frg || NULL == color || NULL == _ROIStencil)<br> {<br> return false;<br> }<br><br> vtkImageCast* cast = vtkImageCast::New();<br> cast->SetOutputScalarTypeToShort();<br> cast->SetInput(frg);<br><br> _ROIStencil->SetInput(cast->GetOutput());<br> _ROIStencil->SetBackgroundColor(color);<br> _ROIStencil->Update();<br><br> _BlendImage = _ROIStencil->GetOutput();<br><br> return true;<br> }<br><br><div><div id="SkyDrivePlaceholder"></div>> From: david.gobbi@gmail.com<br>> Date: Thu, 23 Aug 2012 16:42:16 -0600<br>> Subject: Re: [vtkusers] vtkImageStencil problem<br>> To: lewes_infor@hotmail.com<br>> CC: vtkusers@vtk.org<br>> <br>> Actually, looking through the git log for vtkImageStencilData, there were<br>> a couple bugs fixed between VTK 5.8 and VTK 5.10. Both are fixes<br>> for things that could lead to bad pointers:<br>> <br>> Date: Tue Nov 15 10:16:47 2011 -0700<br>> BUG: Fix incorrect code for combining adjacent extents.<br>> <br>> Date: Sun Oct 16 15:58:20 2011 -0600<br>> BUG: Fix a valgrind UMC in vtkImageStencilData.<br>> <br>> If you compiled your VTK from source, I suggest that you grab<br>> a copy of VTK 5.10 and copy vtkImageStencilData.h/.cxx into<br>> your copy of VTK 5.8. (If you didn't compile from source, you<br>> could just do a complete update from VTK 5.8 to VTK 5.10).<br>> <br>> - David<br>> <br>> <br>> On Thu, Aug 23, 2012 at 4:33 PM, David Gobbi <david.gobbi@gmail.com> wrote:<br>> > Hi Lewes,<br>> ><br>> > If there is a bug, I suspect it would be in the Subtract() method, rather<br>> > than in the vtkImageStencil filter. I can look through the Subtract()<br>> > code to see if there is anything that looks wrong. Is there a way that<br>> > you can create a minimal program+data that I can run on my own<br>> > system to duplicate the crash?<br>> ><br>> > - David<br>> ><br>> > On Thu, Aug 23, 2012 at 2:52 PM, liulewes <lewes_infor@hotmail.com> wrote:<br>> >> Hi all, I'm using vtkImageStencil to create ROIs on an image. The<br>> >> vtkImageStencilData::Add() works well for me, but<br>> >> vtkImageStencilData::Subtract() will cause my program to crash form time to<br>> >> time.<br>> >> By looking at the source code, the program crashes in vtkImageStencil.cxx<br>> >> line 194 where "tmpPtr" becomes invalid and (outSpanEndPtr - outPtr) becomes<br>> >> negative. I'm not sure whether vtkImageStencilData::Subtract() causes this<br>> >> problem or it's sth. else. Can anyone give some suggestions?<br>> >> Lewes.<br></div> </div></body>
</html>