[vtkusers] Fw: vtkTubeFilter memory leak problem

Nigel Nunn nNunn at ausport.gov.au
Mon Mar 17 06:34:47 EST 2003


Hi, 
I guess from your code that each time you call the loop, 
you want to rebuild the current version of the bent tube? 
If so, how about explicitly "Deleting" and creating the 
structure. (Initialize() remains mysterious to me :-)
If you can make this (inefficient) version work without 
leaks, then you could tweak for efficiency later. 

--------------------------------------- 
class MyClass {

  // ...

protected:
  vtkPoints*      m_pts;
  vtkCellArray    m_lines;
  vtkPolydata*    m_curve;
  vtkTubeFilter*  m_pvtkTubeFilter;
};

void MyClass::InitData()
{
  m_pts = NULL;
  m_lines = NULL;
  m_curve = NULL;
  m_pvtkTubeFilter = NULL
}

void MyClass::ClearObjects()
{
  if (m_pts)   { m_pts->Delete();   m_pts=NULL; }
  if (m_lines) { m_lines->Delete(); m_lines=NULL; }
  if (m_curve) { m_curve->Delete(); m_curve=NULL; }
  if (m_pvtkTubeFilter) { 
    m_pvtkTubeFilter->Delete(); 
    m_pvtkTubeFilter=NULL; 
  }
  
}

void MyClass::RebuildBentTube()
{
  void ClearObjects();

  int nCount(0);

  m_pts = vtkPoints::New();
  for (nCount=0; nCount<nCountOfPoints; ++nCount) {
    m_pts->InsertNextPoint(tempPipePts.fXvalue[nCount],
                           tempPipePts.fYvalue[nCount],
                           tempPipePts.fZvalue[nCount]);
  }

  m_lines = vtkCellArray::New();
  m_lines->InsertNextCell(m_pts->GetNumberOfPoints());
  for (nCount=0; nCount<m_pts->GetNumberOfPoints(); ++nCount) {
    m_lines->InsertCellPoint(nCount);
  }

  m_curve = vtkPolydata::New();
    m_curve->SetPoints(m_pts);
    m_curve->SetLines(m_lines);

  m_pvtkTubeFilter = vtkTubeFilter::New();
    m_pVtkTubeFilter->SetInput(m_curve);
    m_pVtkTubeFilter->SetNumberOfSides(NO_OF_SIDES); 
    m_pVtkTubeFilter->SetRadius(m_fPipeRadius);

  // Trigger the pipeline
  m_pVtkTubeFilter->Update();

  // Access the data
  vtkPolydata* pData = m_pvtkTubeFilter->GetOutput();
  vtkPoints*   pPnts = pData->GetPoints(); 

  // ...
  // ...
}
 
 

**********************************************************************
This message is intended for the addressee named and may contain 
confidential and privileged information. If you are not the intended 
recipient please note that any form of distribution, copying or use of 
this communication or the information in it is strictly prohibited and 
may be unlawful. If you receive this message in error, please delete it 
and notify the sender.

Keep up to date with what's happening in Australian sport.
Visit http://www.ausport.gov.au
**********************************************************************



More information about the vtkusers mailing list