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