[vtkusers] Freeing memory error!!!

Koning, P.J.H. de (LKEB) P.J.H.de_Koning at lumc.nl
Fri Oct 4 02:57:17 EDT 2002


03-10-02 10:10:12, jose manjon <jmanjon at fis.upv.es> wrote:

>Hi there,
>
>I have made a class for three orthogonal planes visualization and works ok but I can not free the memory after class destruction.
>
>I do all the Delete() for all the objects but it has no response.
>
>can anyone tell me what I am doing wrong??
>
If you don't remove the actors from the renderer the will be deleted when the renderer is deleted and not sooner.

>thanks
>
>jose
>
>the code:
>
>
>CRenderView::CRenderView()
>{
>  opacidad=0;
>}
>
>
>CRenderView::~CRenderView()
>{
>  AfxMessageBox("freeing ...");
>
>  datos1->Delete();
>  datos2->Delete();
>  datos3->Delete();
>  lut->Delete();
>  plane1->Delete();
>  plane2->Delete();
>  plane3->Delete();
>  planeMapper1->Delete();
>  planeMapper2->Delete();
>  planeMapper3->Delete();
>  text1->Delete();
>  text2->Delete();
>  text3->Delete();
>  planeActor1->Delete();
>  planeActor2->Delete();
>  planeActor3->Delete();
>
>  AfxMessageBox("free");
>}
>
>void CRenderView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
>{
>  // ORTHOGONAL VIEWER
>
>        unsigned short * p;
>  C3DFrame* frame;
>     CImageView* v1;
>     CImageView* v2;
>     CImageView* v3;
>        CACRNEMAViewerDoc *pDoc = (CACRNEMAViewerDoc *) GetDocument();
>  frame=((C3DFrame*)GetParentFrame());
>      v1=frame->GetView(0,1);
>     v2=frame->GetView(1,0);
>     v3=frame->GetView(1,1);
>     int nx=v1->IA;
>     int ny=v2->IA;
>  int nz=v3->IA;
>
>
>  lut=vtkLookupTable::New();
>  lut->SetNumberOfColors(256);
>  double B,G,R;
>  for(int i=0;i<1024;i=i+4)
>  {
>    B=(double)v1->ani->m_pDIB[40+i]/255;
>    G=(double)v1->ani->m_pDIB[40+i+1]/255;
>    R=(double)v1->ani->m_pDIB[40+i+2]/255;
>          if(i/4<opacidad) lut->SetTableValue(i/4,R,G,B,0);
>    else lut->SetTableValue(i/4,R,G,B,1);
>  }
>  lut->SetTableRange(0,255);
>
>
>  /////////// PLANO AXIAL  /////////////////////////////////////////////////////
>
>  datos1=vtkStructuredPoints::New();
>  datos1->SetDimensions(v1->ani->Columns,v1->ani->Rows,1);
>  datos1->SetScalarType(VTK_UNSIGNED_SHORT);
>  datos1->SetNumberOfScalarComponents(1);
>  datos1->AllocateScalars();
>        p=(unsigned short *) datos1->GetScalarPointer();
>  for(int y=0;y<v1->ani->Rows;y++)
>  for(int x=0;x<v1->ani->Columns;x++)
>  {
>     *p++ = v1->ani->Bitmap[y*v1->ani->Columns+x];
>  }
>        plane1=vtkPlaneSource::New();
>  plane1->SetNormal(0,0,1);
>        planeMapper1=vtkPolyDataMapper::New();
>        planeMapper1->SetInput(plane1->GetOutput());
>        text1=vtkTexture::New();
>  text1->SetInput(datos1);
>        text1->SetLookupTable(lut);
>  text1->InterpolateOn();
>  planeActor1=vtkActor::New();
>        planeActor1->SetMapper(planeMapper1);
>  planeActor1->SetTexture(text1);
>
>  /////////// PLANO CORONAL  /////////////////////////////////////////////////////
>
>  datos2=vtkStructuredPoints::New();
>  datos2->SetDimensions(pDoc->m_ani[0].Columns,pDoc->fuentes,1);
>  datos2->SetScalarType(VTK_UNSIGNED_SHORT);
>  datos2->SetNumberOfScalarComponents(1);
>  datos2->AllocateScalars();
>        p=(unsigned short *) datos2->GetScalarPointer();
>  for(y=0;y<v2->ani->Rows;y++)
>  for(int x=0;x<v2->ani->Columns;x++)
>  {
>     *p++ = v2->ani->Bitmap[y*v2->ani->Columns+v2->ani->Columns-1-x];
>  }
>
>        double yr=((double)pDoc->fuentes/(double)pDoc->m_ani[0].Rows)/2.0;
>  yr=yr*(pDoc->resz/pDoc->resx);
>
>  plane2=vtkPlaneSource::New();
>  plane2->SetNormal(0,1,0);
>        plane2->SetOrigin(-0.5,0,-yr);
>        plane2->SetPoint1(0.5,0,-yr);
>        plane2->SetPoint2(-0.5,0,yr);
>        plane2->SetXResolution(1);
>        plane2->SetYResolution(1);
>        planeMapper2=vtkPolyDataMapper::New();
>        planeMapper2->SetInput(plane2->GetOutput());
>  text2=vtkTexture::New();
>  text2->SetInput(datos2);
>  text2->SetLookupTable(lut);
>        text2->InterpolateOn();
>        planeActor2=vtkActor::New();
>        planeActor2->SetMapper(planeMapper2);
>        planeActor2->SetTexture(text2);
>
>  /////////// PLANO SAGITAL /////////////////////////////////////////////////////
>
>  datos3=vtkStructuredPoints::New();
>  datos3->SetDimensions(pDoc->m_ani[0].Columns,pDoc->fuentes,1);
>  datos3->SetScalarType(VTK_UNSIGNED_SHORT);
>  datos3->SetNumberOfScalarComponents(1);
>  datos3->AllocateScalars();
>        p=(unsigned short *) datos3->GetScalarPointer();
>  for(y=0;y<v3->ani->Rows;y++)
>  for(int x=0;x<v3->ani->Columns;x++)
>  {
>     *p++ = v3->ani->Bitmap[y*v3->ani->Columns+v3->ani->Columns-1-x];
>  }
>  plane3=vtkPlaneSource::New();
>  plane3->SetNormal(1,0,0);
>  plane3->SetOrigin(0,-0.5,-yr);
>        plane3->SetPoint1(0, 0.5,-yr);
>        plane3->SetPoint2(0,-0.5, yr);
>        plane3->SetXResolution(1);
>        plane3->SetYResolution(1);
>        planeMapper3=vtkPolyDataMapper::New();
>        planeMapper3->SetInput(plane3->GetOutput());
>        text3=vtkTexture::New();
>  text3->SetInput(datos3);
>  text3->SetLookupTable(lut);
>  text3->InterpolateOn();
>  planeActor3=vtkActor::New();
>        planeActor3->SetMapper(planeMapper3);
>        planeActor3->SetTexture(text3);
>
>        /////////// CUBO  /////////////////////////////////////////////////////
>
>  vtkCubeSource * cube=vtkCubeSource::New();
>  cube->SetBounds(-0.5,0.5,-0.5,0.5,-yr,yr);
>  vtkPolyDataMapper *cubeMapper=vtkPolyDataMapper::New();
>        cubeMapper->SetInput(cube->GetOutput());
>  vtkActor *cubeActor=vtkActor::New();
>        cubeActor->SetMapper(cubeMapper);
>  cubeActor->GetProperty()->SetRepresentationToWireframe();
>
>  /////////// RENDER /////////////////////////////////////////////////////
>
>  this->Renderer->SetBackground(0.05,0.15,0.45);
>
>  this->Renderer->AddActor(planeActor1);
>  this->Renderer->AddActor(planeActor2);
>  this->Renderer->AddActor(planeActor3);
>  this->Renderer->AddActor(cubeActor);
>
>  vtkCamera * cam=this->Renderer->GetActiveCamera();
>  cam->Elevation(90);
>  cam->Azimuth(180);
>
>        vtkLight *light1 = vtkLight::New();
>        light1->SetPosition(1,0,1);
>
>        vtkLight *light2 = vtkLight::New();
>        light2->SetPosition(0,1,1);
>
>        vtkLight *light3 = vtkLight::New();
>        light3->SetPosition(-1,0,1);
>
>        vtkLight *light4 = vtkLight::New();
>        light4->SetPosition(0,-1,1);
>
>        this->Renderer->AddLight(light1);
>        this->Renderer->AddLight(light2);
>        this->Renderer->AddLight(light3);
>        this->Renderer->AddLight(light4);
>
>  cube->Delete();
>  cubeMapper->Delete();
>  cubeActor->Delete();
>
>  Actualizar();
>}
>
>
>void CRenderView::Actualizar()
>{
>     this->Renderer->RemoveActor(planeActor1);
>  this->Renderer->RemoveActor(planeActor2);
>  this->Renderer->RemoveActor(planeActor3);
>
>        unsigned short * p;
>  C3DFrame* frame;
>     CImageView* v1;
>     CImageView* v2;
>     CImageView* v3;
>        CACRNEMAViewerDoc *pDoc = (CACRNEMAViewerDoc *) GetDocument();
>  frame=((C3DFrame*)GetParentFrame());
>      v1=frame->GetView(0,1);
>     v2=frame->GetView(1,0);
>     v3=frame->GetView(1,1);
>     int nx=v3->IA;
>     int ny=v2->IA;
>  int nz=v1->IA;
>
>     double B,G,R;
>  for(int i=0;i<1024;i=i+4)
>  {
>    B=(double)v1->ani->m_pDIB[40+i]/255;
>    G=(double)v1->ani->m_pDIB[40+i+1]/255;
>    R=(double)v1->ani->m_pDIB[40+i+2]/255;
>          if(i/4<opacidad) lut->SetTableValue(i/4,R,G,B,0);
>    else lut->SetTableValue(i/4,R,G,B,1);
>  }
>  lut->SetTableRange(0,255);
>
>
>  /////////// PLANO AXIAL  /////////////////////////////////////////////////////
>
>        p=(unsigned short *) datos1->GetScalarPointer();
>  for(int y=0;y<v1->ani->Rows;y++)
>  for(int x=0;x<v1->ani->Columns;x++)
>  {
>     *p++ = v1->ani->Bitmap[y*v1->ani->Columns+x];
>  }
>
>  double yr=((double)pDoc->fuentes/(double)pDoc->m_ani[0].Rows)/2.0;
>  yr=yr*(pDoc->resz/pDoc->resx);
>
>     plane1->SetCenter(0,0,-yr+2*yr*((double)nz/(double)(pDoc->fuentes-1)));
>
>        planeMapper1->SetInput(plane1->GetOutput());
>  text1->SetInput(datos1);
>        text1->SetLookupTable(lut);
>  text1->InterpolateOn();
>        planeActor1->SetMapper(planeMapper1);
>  planeActor1->SetTexture(text1);
>
>  /////////// PLANO CORONAL  /////////////////////////////////////////////////////
>
>        p=(unsigned short *) datos2->GetScalarPointer();
>  for(y=0;y<v2->ani->Rows;y++)
>  for(int x=0;x<v2->ani->Columns;x++)
>  {
>     *p++ = v2->ani->Bitmap[y*v2->ani->Columns+v2->ani->Columns-1-x];
>  }
>
>  plane2->SetCenter(0,0.5-((double)ny/(double)v2->alto),0);
>
>        planeMapper2->SetInput(plane2->GetOutput());
>  text2->SetInput(datos2);
>  text2->SetLookupTable(lut);
>        text2->InterpolateOn();
>        planeActor2->SetMapper(planeMapper2);
>        planeActor2->SetTexture(text2);
>
>  /////////// PLANO SAGITAL /////////////////////////////////////////////////////
>
>        p=(unsigned short *) datos3->GetScalarPointer();
>  for(y=0;y<v3->ani->Rows;y++)
>  for(int x=0;x<v3->ani->Columns;x++)
>  {
>     *p++ = v3->ani->Bitmap[y*v3->ani->Columns+v3->ani->Columns-1-x];
>  }
>
>  plane3->SetCenter(-0.5+((double)nx/(double)v3->ancho),0,0);
>
>        planeMapper3->SetInput(plane3->GetOutput());
>  text3->SetInput(datos3);
>  text3->SetLookupTable(lut);
>  text3->InterpolateOn();
>        planeActor3->SetMapper(planeMapper3);
>        planeActor3->SetTexture(text3);
>
>  this->Renderer->AddActor(planeActor1);
>  this->Renderer->AddActor(planeActor2);
>  this->Renderer->AddActor(planeActor3);
>
>  this->Renderer->GetRenderWindow()->Render();
>}
>
>void CRenderView::SetOpacity(double opa)
>{
>   opacidad=opa*256;
>   Actualizar();
>}
>
>
>
>
>
>
>                            \\|//
>                            (@ @)
> +--------------------oOO----(_)----OOo-----------------------+
> |                                                            |
> |             Prof.  Jose Vicente Manjón Herrera             |
> |                                                            |
> |             Group of Medical Bioinformatics                |
> |             Department of Aplied Physics                   |
> |             Computer Science High School                   |
> |             Technical University of Valencia               |
> |             Spain                                          |
> |                                                            |
> |             Email:jmanjon at fis.upv.es                       |
> |                                                            |
> +------------------------------------------------------------+
>                           |__|__|
>                            || ||
>                           ooO Ooo
>
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers
>





More information about the vtkusers mailing list