It probably means that the object has no references holding on to it and is hence destroyed by the GC. Try expanding its scope outside the function.<div><br></div><div><br><div class="gmail_quote">On Sun, Sep 12, 2010 at 3:40 PM, Ali Habib <span dir="ltr">&lt;<a href="mailto:ali.mahmoud.habib@gmail.com">ali.mahmoud.habib@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">Hi,<div>I created my own pipeline to select part of <b>vtkboxwidget </b>and linear transfer it , as a source of linear deformation but the code through error :  trying to delete object with non zero reference count  at vtkobject.cxx</div>

<div><br></div><div>any suggestion to solve that , the code I use is :</div><div><div>        static vtkPolyData gpd;</div><div>        static vtkLODActor selectActor;</div><div>        static vtkLODActor maceActor;</div>

<div>        static vtkLODActor selectActor_cutting;</div><div>        static vtkPlanes planes;</div><div>        static vtkClipPolyData clipper;</div><div>        static vtkClipPolyData clipper_cutting;</div><div>        // static vtkAppendPolyData apd;</div>

<div><br></div><div>        static double[] center_Before = new double[3];</div><div>        static double[] center_After = new double[3];</div><div><br></div><div>        bool IsTransfer = false;</div></div><div><br></div>

<div><div>void AddInputToWindow(vtk.vtkRenderWindow renWin, bool ISFirst)</div><div>        {</div><div>            /* vtk.vtkSphereSource cone = new vtk.vtkSphereSource();</div><div>             cone.SetRadius(1.0f);*/</div>

<div><br></div><div>            vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();</div><div>            VDR.SetDirectoryName(@&quot;E:\Master Degree\DataSet\case2\DICOM\PA1\ST1\SE2&quot;);</div><div>            VDR.SetDataOrigin(0, 0, 0);</div>

<div>            VDR.Update();</div><div><br></div><div>            // decrease the dataset data for large data preprocessing </div><div><br></div><div>            vtkImageShrink3D VIS = new vtkImageShrink3D();</div><div>

            VIS.SetShrinkFactors(2, 2, 2);</div><div>            VIS.SetInputConnection(VDR.GetOutputPort());</div><div>            VIS.Update();</div><div><br></div><div>            vtkImageThreshold VIT = new vtkImageThreshold();</div>

<div>            VIT.ThresholdBetween(200, 2000);</div><div>            VIT.SetInputConnection(VIS.GetOutputPort());</div><div>            VIT.Update();</div><div><br></div><div>            ///// Start the creation of volume rendering </div>

<div><br></div><div>            //1. Gget the range of data </div><div>            vtk.vtkImageChangeInformation VIC = new vtk.vtkImageChangeInformation();</div><div>            VIC.SetInput(VDR.GetOutput());</div><div>            VIC.CenterImageOn();</div>

<div>            VIC.Update();</div><div><br></div><div>            vtk.vtkImageData VoxelData = new vtk.vtkImageData();</div><div>            VoxelData = VIC.GetOutput();</div><div><br></div><div>            double[] metaScalarRange = VoxelData.GetScalarRange();</div>

<div><br></div><div><br></div><div>            // Render the skin - Soft tissue </div><div>            double isovalue = 0.8 * (metaScalarRange[1] + metaScalarRange[0]);</div><div><br></div><div><br></div><div>            vtkContourFilter skinExtractor = new vtkContourFilter();</div>

<div>            skinExtractor.SetInputConnection(VIT.GetOutputPort());</div><div>            skinExtractor.SetValue(0, isovalue);</div><div>            skinExtractor.ComputeGradientsOn();</div><div>            skinExtractor.Update();</div>

<div><br></div><div>            vtkPolyDataConnectivityFilter VPDC = new vtkPolyDataConnectivityFilter();</div><div>            VPDC.SetInput(skinExtractor.GetOutput());</div><div>            VPDC.SetExtractionModeToLargestRegion();</div>

<div>            VPDC.Update();</div><div><br></div><div>            gpd = VPDC.GetOutput();</div><div><br></div><div>            /*gpd.Register(null);</div><div>            gpd.SetSource(null);*/</div><div><br></div><div>

            vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper();</div><div>            coneMapper.SetInput(gpd);</div><div>            coneMapper.ScalarVisibilityOff();</div><div><br></div><div>            maceActor = new vtkLODActor();</div>

<div>            maceActor.SetMapper(coneMapper);</div><div>            maceActor.GetProperty().SetColor(1, 0, 0);</div><div>            //////////////////////// Selection Part /////////////////////////</div><div>            planes = new vtkPlanes();</div>

<div><br></div><div>            clipper = new vtkClipPolyData();</div><div>            clipper.SetInput(gpd);</div><div>            clipper.SetClipFunction(planes);</div><div>            clipper.InsideOutOn();</div><div>
            clipper.Modified();</div>
<div>            vtkPolyDataMapper selectMapper = new vtkPolyDataMapper();</div><div>            selectMapper.SetInput(clipper.GetOutput());</div><div>            selectMapper.ScalarVisibilityOff();</div><div><br></div><div>

            selectActor = new vtkLODActor();</div><div>            selectActor.SetMapper(selectMapper);</div><div>            selectActor.GetProperty().SetColor(0, 1, 0);</div><div>            selectActor.VisibilityOff();</div>

<div>            selectActor.SetScale(1.01, 1.01, 1.01);</div><div><br></div><div>            /////////////////////// End of selection part////////////////////</div><div><br></div><div>            //////////////////////////// Cutting part /////////////////////////////////</div>

<div><br></div><div><br></div><div>            clipper_cutting = new vtkClipPolyData();</div><div>            clipper_cutting.SetInput(gpd);</div><div>            clipper_cutting.SetClipFunction(planes);</div><div>            clipper_cutting.InsideOutOff();</div>

<div>            clipper_cutting.GenerateClippedOutputOff();</div><div>            clipper_cutting.Modified();</div><div>            vtkPolyDataMapper selectMapper_cutting = new vtkPolyDataMapper();</div><div>            selectMapper_cutting.SetInput(clipper_cutting.GetOutput());</div>

<div>            selectMapper_cutting.ScalarVisibilityOff();</div><div><br></div><div>            selectActor_cutting = new vtkLODActor();</div><div>            selectActor_cutting.SetMapper(selectMapper_cutting);</div><div>

            selectActor_cutting.GetProperty().SetColor(1, 0, 0);</div><div>            selectActor_cutting.VisibilityOff();</div><div>            selectActor_cutting.SetScale(1.01, 1.01, 1.01);</div><div><br></div><div>            //////////////////////////// End Cutting part //////////////////////////////////////</div>

<div>            vtk.vtkRenderer ren1 = new vtk.vtkRenderer();</div><div><br></div><div>            renWin.AddRenderer(ren1);</div><div>            //ren1.SetBackground(0.0f, 0.0f, 0.0f);</div><div><br></div><div>            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();</div>

<div>            iren.SetRenderWindow(renWin);</div><div><br></div><div><br></div><div><br></div><div>            //The SetInteractor method is how 3D widgets are associated with the</div><div>            //render window interactor.  Internally, SetInteractor sets up a bunch</div>

<div>            //of callbacks using the Command/Observer mechanism (AddObserver()).</div><div>            vtkBoxWidget boxWidget = new vtkBoxWidget();</div><div>            boxWidget.SetInteractor(iren);</div><div>            boxWidget.SetPlaceFactor(1.25);</div>

<div>            boxWidget.TranslationEnabledOn();</div><div><br></div><div><br></div><div><br></div><div>            ren1.AddActor(maceActor);</div><div>            ren1.AddActor(selectActor);</div><div>            ren1.AddActor(selectActor_cutting);</div>

<div><br></div><div>            boxWidget.SetInput(gpd);</div><div>            boxWidget.PlaceWidget();</div><div><br></div><div>            boxWidget.AddObserver((uint)vtk.EventIds.StartInteractionEvent, new vtk.vtkDotNetCallback(StartInteractionEvent));</div>

<div>            boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent, new vtk.vtkDotNetCallback(InteractionEvent));</div><div>            boxWidget.AddObserver((uint)vtk.EventIds.EndInteractionEvent, new vtk.vtkDotNetCallback(EndInteractionEvent));</div>

<div><br></div><div><br></div><div>            boxWidget.On();</div><div><br></div><div><br></div><div>            renWin.AddRenderer(ren1);</div><div><br></div><div>            GC.Collect();</div><div>        }</div><div>

<br></div><div>        ///////////////////////// Observation Events ///////////////////////////////////////////////////////////////////</div><div>        ///////////////////////// Observation Events ///////////////////////////////////////////////////////////////////</div>

<div>        public void StartInteractionEvent(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)</div><div>        {</div><div>            if (IsTransfer)</div><div>            {</div><div>                vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);</div>

<div><br></div><div>                vtkPolyData before = new vtkPolyData();</div><div>                widget.GetPolyData(before); double[] x = before.GetPoints().GetBounds();</div><div>                center_Before = GetBoundsCenter(before.GetBounds());</div>

<div>            }</div><div><br></div><div><br></div><div>        }</div><div>        public void InteractionEvent(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)</div><div>        {</div><div>            vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);</div>

<div>            widget.GetPlanes(planes);</div><div><br></div><div>            clipper.Modified();</div><div>            clipper_cutting.Modified();</div><div><br></div><div>            selectActor.VisibilityOn();</div>
<div>
            selectActor_cutting.VisibilityOn();</div><div><br></div><div><br></div><div><br></div><div>        }</div><div>        public void EndInteractionEvent(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)</div>

<div>        {</div><div>            if (IsTransfer)</div><div>            {</div><div>                vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);</div><div>                vtkPolyData after = new vtkPolyData();</div>

<div>                widget.GetPolyData(after);</div><div>                center_After = GetBoundsCenter(after.GetBounds());</div><div><br></div><div><br></div><div>                ModifyData();</div><div>                selectActor.VisibilityOff();</div>

<div>            }</div><div><br></div><div><br></div><div>        }</div><div>        </div><div>        private double[] GetBoundsCenter(double[] bounds)</div><div>        {</div><div>            double[] center = new double[3];</div>

<div><br></div><div>            center[0] = (bounds[0] + bounds[1]) / 2.0;</div><div>            center[1] = (bounds[2] + bounds[3]) / 2.0;</div><div>            center[2] = (bounds[4] + bounds[5]) / 2.0;</div><div><br></div>

<div>            return center;</div><div>        }</div><div><br></div><div>        private void ModifyData()</div><div>        {</div><div>            //////////////////////////////////////////////////////Just sugesstion ///////////////////////</div>

<div><br></div><div><br></div><div>            double[] Displacement = { center_After[0] - center_Before[0], center_After[1] - center_Before[1], center_After[2] - center_Before[2] };</div><div><br></div><div>            int NoOfPoints = clipper.GetOutput().GetNumberOfPoints();</div>

<div><br></div><div>            for (int i = 0; i &lt; NoOfPoints; i++)</div><div>            {</div><div>                // get the point data from the clipper</div><div>                double[] ci = clipper.GetOutput().GetPoints().GetPoint(i);</div>

<div>                // get the index of the original data point.</div><div>                int pxi = gpd.FindPoint(ci);</div><div>                // get the value of the poly  data point.</div><div>                double[] ppi = gpd.GetPoints().GetPoint(pxi);</div>

<div>                // transpose the point</div><div>                ppi[0] += Displacement[0];</div><div>                ppi[1] += Displacement[1];</div><div>                ppi[2] += Displacement[2];</div><div>                // replace the point in the poly data</div>

<div>                gpd.GetPoints().InsertPoint(pxi, ppi);</div><div>            }</div><div>            // mark the poly data as modified for the render processing.</div><div><br></div><div>            </div><div>            /*gpd.Register(null);</div>

<div>            gpd.SetSource(null);*/</div><div><br></div><div>            gpd.Modified();</div><div>            GC.Collect();</div><div>        }</div></div><div><br></div><div>Best regards</div><div><br></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>