[vtkusers] Delete vtk objects

Andreas Brüning mail-andi at web.de
Tue Aug 12 09:40:01 EDT 2008


in this case it does not make sense to split the vtk pipeline in different threads. Will this been changed in the near future or do i have to redesign my program?

thank you for the quick answer
Andi



VTK's ref counting mechanism (C++ ++ and -- operators...) is not 
thread safe. All VTK objects that have any chance of being related to 
each other must all be created and destroyed from the same thread. 
The only way you could use VTK objects from another thread would be 
to create them, use them and destroy them completely from that thread 
without relating them to any VTK objects that were created on other 
threads...


Does that make sense?


HTH,
David




On Tue, Aug 12, 2008 at 9:12 AM, Andreas Brüning <mail-andi at web.de> 
wrote:
Hello everyone,

 regarding to my post from beginning of august:

http://www.vtk.org/pipermail/vtkusers/2008-August/096309.html

 i recompiled vtk with VTK_DEBUG_LEAKS flag in CMAKE and with use of 
vtkDebugLeaks i printed out the undeleted vtkobjects right before i 
close the program . I found out that if i create vtk objects in 
different threads the delete funtionality doesnŽt work anymore. When 
i only create vtkobjects in the mainThread they delete completely. 
But when i create different threads and in there new vtkObjects, 
dozens of vtkobjects remain in the memory.Even those i never created 
by myself. I call always the New() and Delete() methods for every 
vtkobject in the thread. And it happens with all kinds of vtkobjects.

 Here is an example of a thread-method:

 UINT __cdecl CImageVtkWnd::ResultView_2dMPR(LPVOID lpParameter )
 {

 //managing class of the threads
 CImageVtkWnd *pThis = static_cast<CImageVtkWnd *>(lpParameter);

 ASSERT(pThis != NULL);


 // Create the the renderer, window and interactor objects.
 vtkRenderer *vtk_Renderer = vtkRenderer::New();

 vtkWin32OpenGLRenderWindow *vtk_Win32OpenGLWindow = vtkWin32OpenGLRend
erWindow::New();
 vtk_Win32OpenGLWindow->AddRenderer(vtk_Renderer);

 double *spacing = pThis->m_vtkvolumedata->GetSpacing();
 vtkImageShiftScale *vtk_scale = vtkImageShiftScale::New();

 vtk_scale->SetInput(pThis->m_vtkvolumedata);
 vtk_scale->SetShift(0.5*pThis->m_dWindow - pThis->m_dLevel);
 vtk_scale->SetScale(255.0/pThis->m_dWindow);
 vtk_scale->ClampOverflowOn();
 vtk_scale->SetOutputScalarTypeToUnsignedChar();

 vtkImageReslice *vtkImageReslicer = vtkImageReslice::New();
 vtkImageReslicer->SetInput(vtk_scale->GetOutput());
 vtkImageReslicer->SetOutputDimensionality(2);
 vtkImageReslicer->SetInterpolationModeToLinear();

 vtkImageReslicer->SetOutputSpacing(spacing);
 vtkImageReslicer->ReleaseDataFlagOn();

 vtkImageActor *vtk_actor = vtkImageActor::New();
 vtk_actor->SetInput(vtkImageReslicer->GetOutput());

 vtkTransform *vtk_slicetransform = vtkTransform::New();

 vtk_Renderer->AddActor(vtk_actor);
 vtk_Renderer->ResetCamera();
 vtk_Renderer->GetActiveCamera()->ParallelProjectionOn();

 DWORD MultiLockObj = 0;

 CSyncObject* pWaitObjects[] = { pThis->m_hRenderEvent, pThis->m_
hTerminateLoopEvent, pThis->m_hResizeEvent };

 CMultiLock MultiLock( pWaitObjects, 3L );

 vtk_slicetransform->Translate(pThis->m_pSliceCenter[0], pThis->m_
pSliceCenter[1], pThis->m_pSliceCenter[2]);
 vtk_slicetransform->RotateZ(-pThis->m_dSliceAngle_z);
 vtk_slicetransform->RotateX(-pThis->m_dSliceAngle_x);
 vtk_slicetransform->RotateY(-pThis->m_dSliceAngle_y);

 CSize *size = new CSize(600,800);

 unsigned char *tmpdata;

 BITMAPINFO bmi={0};
 bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
 bmi.bmiHeader.biPlanes=1;
 bmi.bmiHeader.biCompression=BI_RGB;
 bmi.bmiHeader.biBitCount=24;
 bmi.bmiHeader.biWidth=size->cx;
 bmi.bmiHeader.biHeight=size->cy;
 bmi.bmiHeader.biSizeImage=size->cx * size->cy * 24;

 vtk_Win32OpenGLWindow->SetSize(size->cx,size->cy);
 vtk_Win32OpenGLWindow->OffScreenRenderingOn();

 do
 {
 if(MultiLockObj == (WAIT_OBJECT_0+1))
 {
 break;
 }

 //reslice
 if(MultiLockObj == (WAIT_OBJECT_0+2))
 {
 vtk_slicetransform->Identity();
 vtk_slicetransform->Translate(pThis->m_pSliceCenter[0], pThis->m_
pSliceCenter[1], pThis->m_pSliceCenter[2]);

 vtk_slicetransform->RotateZ(-pThis->m_dSliceAngle_z);
 vtk_slicetransform->RotateX(-pThis->m_dSliceAngle_x);
 vtk_slicetransform->RotateY(-pThis->m_dSliceAngle_y);

 vtkImageReslicer->SetResliceAxes(vtk_slicetransform->GetMatrix());
 }
 vtk_Win32OpenGLWindow->Render();

 vtk_Renderer->ResetCamera();
 ::EnterCriticalSection(&pThis->m_cs);
 tmpdata = vtk_Win32OpenGLWindow->GetPixelData(0,0,size->cx-1, size->
cy,1);

 pThis->m_lbitmap->ConvertFromDIB(&bmi,(L_UCHAR *) tmpdata);
 pThis->m_lbitmap->SetXResolution(pThis->m_iSource_resolution);
 pThis->m_lbitmap->SetYResolution(pThis->m_iSource_resolution);
 pThis->m_lbitmap->CalculateXYRes();
 pThis->m_lbitmap->GrayScale(pThis->m_iGrayscale);

 LeaveCriticalSection(&pThis->m_cs);


 ::PostMessage(pThis->m_cParent->GetSafeHwnd(),WM_VTK_UPDATE_WINDOW,1,
NULL);


 delete tmpdata;


 MultiLockObj = MultiLock.Lock( INFINITE, FALSE );
 }
 while(1);

 //Cleanup
 delete size;


 vtk_Renderer->Delete();
 vtk_Win32OpenGLWindow->Delete();
 vtk_scale->Delete();
 vtkImageReslicer->Delete();
 vtk_actor->Delete();
 vtk_slicetransform->Delete();

 ::AfxEndThread( 0, true );
 return 0L;

 }




 Does anybody has an idea why i cant delete vtk objects in a thread? 
i tried already to cut the connections between vtkobjects in the 
different threads, but it also doesnŽt helped.

 Thanks in advance
 Andi

 _______________________________________________
 This is the private VTK discussion list.
 Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/
Wiki/VTK_FAQ
 Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers





________________________________________________________________________
Schon gehört? Bei WEB.DE gibt' s viele kostenlose Spiele:
http://games.entertainment.web.de/de/entertainment/games/free/index.html




More information about the vtkusers mailing list