[vtkusers] memory issue with isosurface

Sean Larkin sean.larkin at lickenbrocktech.com
Tue Jun 14 11:58:36 EDT 2011


I am rendering an isosurface computed from an image volume.  When I compute
the isosurface and then render it once everything works fine.  In the same
session with the same mapper and render window I try to generate the same
isosurface again using the same parameters.  What gets rendered to the
screen is just a 2D image of one part of the surface and then when I go to
rotate it and the screen goes black.  This must be some kind of memory
issue, but I shouldn't be near my memory limit, and I should just be reusing
memory.  Here's the code I use (in C# using Activiz) for the function:

 

            vtkMarchingCubes vMarch = vtkMarchingCubes.New();

            vMarch.SetInputConnection(vResampler.GetOutputPort());

            vMarch.ComputeNormalsOff();

            vMarch.ComputeGradientsOff();

            vMarch.ComputeScalarsOff();

 

            vMarch.SetValue(0, tabbedOptions1.sbIsoThresh.Value);

            vMarch.ReleaseDataFlagOn();

            vMarch.ProgressEvt += new
vtkObject.vtkObjectEventHandler(vMarch_ProgressEvt);

            progressBar.Show();

            progressBar.Message = "Calculating isosurface... Please wait.";

            

            vMarch.Update();

 

            progressBar.Message = "Filtering isosurface... Please wait.";

            vtkPolyDataConnectivityFilter confilter =
vtkPolyDataConnectivityFilter.New();

            confilter.ProgressEvt += new
vtkObject.vtkObjectEventHandler(vMarch_ProgressEvt);

            confilter.SetInputConnection(vMarch.GetOutputPort());

            confilter.SetExtractionModeToAllRegions();

            confilter.ReleaseDataFlagOn();

            confilter.Update();

 

            progressBar.Message = "Smoothing isosurface... Please wait.";

            vtkSmoothPolyDataFilter smoothFilt =
vtkSmoothPolyDataFilter.New();

            smoothFilt.ProgressEvt += new
vtkObject.vtkObjectEventHandler(vMarch_ProgressEvt);

            smoothFilt.SetInputConnection(confilter.GetOutputPort());

            smoothFilt.SetNumberOfIterations(5);

            smoothFilt.SetRelaxationFactor(.1);

            smoothFilt.FeatureEdgeSmoothingOff();

            smoothFilt.BoundarySmoothingOff();

            smoothFilt.SetConvergence(0);

            smoothFilt.ReleaseDataFlagOn();

            smoothFilt.Update();

 

            progressBar.Message = "Calculating surface normals... Please
wait.";

            vtkPolyDataNormals vNorms = vtkPolyDataNormals.New();

            vNorms.ProgressEvt += new
vtkObject.vtkObjectEventHandler(vMarch_ProgressEvt);

            vNorms.SetInputConnection(smoothFilt.GetOutputPort());

            vNorms.ReleaseDataFlagOn();

            vNorms.Update();

 

            if (vPolyMapper==null)

                vPolyMapper = vtkOpenGLPolyDataMapper.New();

 

            vPolyMapper.SetInputConnection(vNorms.GetOutputPort());

            vPolyMapper.ScalarVisibilityOff();

            vPolyMapper.ReleaseDataFlagOn();

            if (vActor == null)

                vActor = vtkActor.New();

 

            vActor.GetProperty().SetColor(tabbedOptions1.IsoColor[0],
tabbedOptions1.IsoColor[1], tabbedOptions1.IsoColor[2]);

            vActor.GetProperty().SetOpacity(.01 *
(double)tabbedOptions1.sbIsoOpacity.Value); 

            vActor.SetMapper(vPolyMapper);

 

            Then I render it with the window's Render() method.

 

As you can see I am using the ReleaseDataFlagOn() , and all the variables
used to create the isosurface are local variables that go out of scope when
this function ends, so there mmemory is freed.  The polymapper and actor are
global variables, and need to be this way to make the rendering work
correctly.  The data from which the isosurface is generated is 512x512x94,
so it's not huge.  Like I mentioned, it works the first time I generate the
isosurface, but why not the second time?  Anyone have any clues or a better
way to do this?  I have also used vtkContourFilter to generate the
isosurface, and it works fine, but I want to have multiple ways to get the
isosurface.  The method above provides a smoother surface, which is why I
like it better than the contour filter.

 

Thanks,

Sean

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110614/4ba8aab7/attachment.htm>


More information about the vtkusers mailing list