[vtkusers] vtkobject Error trying to delete object with non zero reference count
Ali Habib
ali.mahmoud.habib at gmail.com
Sun Sep 12 06:10:41 EDT 2010
Hi,
I created my own pipeline to select part of *vtkboxwidget *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
any suggestion to solve that , the code I use is :
static vtkPolyData gpd;
static vtkLODActor selectActor;
static vtkLODActor maceActor;
static vtkLODActor selectActor_cutting;
static vtkPlanes planes;
static vtkClipPolyData clipper;
static vtkClipPolyData clipper_cutting;
// static vtkAppendPolyData apd;
static double[] center_Before = new double[3];
static double[] center_After = new double[3];
bool IsTransfer = false;
void AddInputToWindow(vtk.vtkRenderWindow renWin, bool ISFirst)
{
/* vtk.vtkSphereSource cone = new vtk.vtkSphereSource();
cone.SetRadius(1.0f);*/
vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();
VDR.SetDirectoryName(@"E:\Master
Degree\DataSet\case2\DICOM\PA1\ST1\SE2");
VDR.SetDataOrigin(0, 0, 0);
VDR.Update();
// decrease the dataset data for large data preprocessing
vtkImageShrink3D VIS = new vtkImageShrink3D();
VIS.SetShrinkFactors(2, 2, 2);
VIS.SetInputConnection(VDR.GetOutputPort());
VIS.Update();
vtkImageThreshold VIT = new vtkImageThreshold();
VIT.ThresholdBetween(200, 2000);
VIT.SetInputConnection(VIS.GetOutputPort());
VIT.Update();
///// Start the creation of volume rendering
//1. Gget the range of data
vtk.vtkImageChangeInformation VIC = new
vtk.vtkImageChangeInformation();
VIC.SetInput(VDR.GetOutput());
VIC.CenterImageOn();
VIC.Update();
vtk.vtkImageData VoxelData = new vtk.vtkImageData();
VoxelData = VIC.GetOutput();
double[] metaScalarRange = VoxelData.GetScalarRange();
// Render the skin - Soft tissue
double isovalue = 0.8 * (metaScalarRange[1] +
metaScalarRange[0]);
vtkContourFilter skinExtractor = new vtkContourFilter();
skinExtractor.SetInputConnection(VIT.GetOutputPort());
skinExtractor.SetValue(0, isovalue);
skinExtractor.ComputeGradientsOn();
skinExtractor.Update();
vtkPolyDataConnectivityFilter VPDC = new
vtkPolyDataConnectivityFilter();
VPDC.SetInput(skinExtractor.GetOutput());
VPDC.SetExtractionModeToLargestRegion();
VPDC.Update();
gpd = VPDC.GetOutput();
/*gpd.Register(null);
gpd.SetSource(null);*/
vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper();
coneMapper.SetInput(gpd);
coneMapper.ScalarVisibilityOff();
maceActor = new vtkLODActor();
maceActor.SetMapper(coneMapper);
maceActor.GetProperty().SetColor(1, 0, 0);
//////////////////////// Selection Part
/////////////////////////
planes = new vtkPlanes();
clipper = new vtkClipPolyData();
clipper.SetInput(gpd);
clipper.SetClipFunction(planes);
clipper.InsideOutOn();
clipper.Modified();
vtkPolyDataMapper selectMapper = new vtkPolyDataMapper();
selectMapper.SetInput(clipper.GetOutput());
selectMapper.ScalarVisibilityOff();
selectActor = new vtkLODActor();
selectActor.SetMapper(selectMapper);
selectActor.GetProperty().SetColor(0, 1, 0);
selectActor.VisibilityOff();
selectActor.SetScale(1.01, 1.01, 1.01);
/////////////////////// End of selection
part////////////////////
//////////////////////////// Cutting part
/////////////////////////////////
clipper_cutting = new vtkClipPolyData();
clipper_cutting.SetInput(gpd);
clipper_cutting.SetClipFunction(planes);
clipper_cutting.InsideOutOff();
clipper_cutting.GenerateClippedOutputOff();
clipper_cutting.Modified();
vtkPolyDataMapper selectMapper_cutting = new
vtkPolyDataMapper();
selectMapper_cutting.SetInput(clipper_cutting.GetOutput());
selectMapper_cutting.ScalarVisibilityOff();
selectActor_cutting = new vtkLODActor();
selectActor_cutting.SetMapper(selectMapper_cutting);
selectActor_cutting.GetProperty().SetColor(1, 0, 0);
selectActor_cutting.VisibilityOff();
selectActor_cutting.SetScale(1.01, 1.01, 1.01);
//////////////////////////// End Cutting part
//////////////////////////////////////
vtk.vtkRenderer ren1 = new vtk.vtkRenderer();
renWin.AddRenderer(ren1);
//ren1.SetBackground(0.0f, 0.0f, 0.0f);
vtkRenderWindowInteractor iren = new
vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
//The SetInteractor method is how 3D widgets are associated with
the
//render window interactor. Internally, SetInteractor sets up a
bunch
//of callbacks using the Command/Observer mechanism
(AddObserver()).
vtkBoxWidget boxWidget = new vtkBoxWidget();
boxWidget.SetInteractor(iren);
boxWidget.SetPlaceFactor(1.25);
boxWidget.TranslationEnabledOn();
ren1.AddActor(maceActor);
ren1.AddActor(selectActor);
ren1.AddActor(selectActor_cutting);
boxWidget.SetInput(gpd);
boxWidget.PlaceWidget();
boxWidget.AddObserver((uint)vtk.EventIds.StartInteractionEvent,
new vtk.vtkDotNetCallback(StartInteractionEvent));
boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent, new
vtk.vtkDotNetCallback(InteractionEvent));
boxWidget.AddObserver((uint)vtk.EventIds.EndInteractionEvent,
new vtk.vtkDotNetCallback(EndInteractionEvent));
boxWidget.On();
renWin.AddRenderer(ren1);
GC.Collect();
}
///////////////////////// Observation Events
///////////////////////////////////////////////////////////////////
///////////////////////// Observation Events
///////////////////////////////////////////////////////////////////
public void StartInteractionEvent(vtk.vtkObject obj, uint eventId,
Object data, IntPtr clientdata)
{
if (IsTransfer)
{
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
vtkPolyData before = new vtkPolyData();
widget.GetPolyData(before); double[] x =
before.GetPoints().GetBounds();
center_Before = GetBoundsCenter(before.GetBounds());
}
}
public void InteractionEvent(vtk.vtkObject obj, uint eventId, Object
data, IntPtr clientdata)
{
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
widget.GetPlanes(planes);
clipper.Modified();
clipper_cutting.Modified();
selectActor.VisibilityOn();
selectActor_cutting.VisibilityOn();
}
public void EndInteractionEvent(vtk.vtkObject obj, uint eventId,
Object data, IntPtr clientdata)
{
if (IsTransfer)
{
vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
vtkPolyData after = new vtkPolyData();
widget.GetPolyData(after);
center_After = GetBoundsCenter(after.GetBounds());
ModifyData();
selectActor.VisibilityOff();
}
}
private double[] GetBoundsCenter(double[] bounds)
{
double[] center = new double[3];
center[0] = (bounds[0] + bounds[1]) / 2.0;
center[1] = (bounds[2] + bounds[3]) / 2.0;
center[2] = (bounds[4] + bounds[5]) / 2.0;
return center;
}
private void ModifyData()
{
//////////////////////////////////////////////////////Just
sugesstion ///////////////////////
double[] Displacement = { center_After[0] - center_Before[0],
center_After[1] - center_Before[1], center_After[2] - center_Before[2] };
int NoOfPoints = clipper.GetOutput().GetNumberOfPoints();
for (int i = 0; i < NoOfPoints; i++)
{
// get the point data from the clipper
double[] ci = clipper.GetOutput().GetPoints().GetPoint(i);
// get the index of the original data point.
int pxi = gpd.FindPoint(ci);
// get the value of the poly data point.
double[] ppi = gpd.GetPoints().GetPoint(pxi);
// transpose the point
ppi[0] += Displacement[0];
ppi[1] += Displacement[1];
ppi[2] += Displacement[2];
// replace the point in the poly data
gpd.GetPoints().InsertPoint(pxi, ppi);
}
// mark the poly data as modified for the render processing.
/*gpd.Register(null);
gpd.SetSource(null);*/
gpd.Modified();
GC.Collect();
}
Best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100912/88aa53bf/attachment.htm>
More information about the vtkusers
mailing list