Download article attachment: DevSample_RenderVolume_DICOM_MDI.zip(93.5kb)
This article demonstrates inserting the generic VTK volume render wrapper discussed in article Volume Rendering DICOM Dataset into a win32 MDI application.
The attached project demonstrates a working example of how to incorporate VTK into a win32 MDI application. The project makes use of the WrapperVtkRenderVolume class (also used in the generic command line application rendering article) to handle rendering. In fact, all the VTK rendering source code is exactly the same thanks to the wrapper class.
One extension class, WrapperVtkRenderVolumeWin32, is used to bridge between generic VTK code and the win32 MDI framework. There are only two important tasks this class needs to handle:
- Call SetParentId(hwnd) to attach the VTK wrapper to the MDI child window.
- Block Start() from being called on the member interactor (this should only be used for non-GUI apps).
The sample application keeps a member instance of WrapperVtkRenderVolumeWin32 in the child view class. These snippets show the only functions that need to be handled for the wrapper member:
CChildView::Create
-
BOOL CChildView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
-
{
-
if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext)) {
-
return -1;
-
}
-
-
// Allocate the VTK wrapper and pass it our hwnd to attach to.
-
m_pVTK = new WrapperVtkRenderVolumeWin32(GetSafeHwnd());
-
-
return TRUE;
-
}
CChildView::LoadVolumeFromFolder
-
BOOL CChildView::LoadVolumeFromFolder(CString strPath,
-
CString& strDetails)
-
{
-
// Handles loading the DICOM directory as set by the end used.
-
if (m_pVTK) {
-
if (m_pVTK->LoadVolumeFromFolder(strPath.GetBuffer())) {
-
return TRUE;
-
}
-
strDetails = m_pVTK->GetDetails().c_str();
-
}
-
return FALSE;
-
}
CChildView::OnSize
-
void CChildView::OnSize(UINT nType, int cx, int cy)
-
{
-
CWnd::OnSize(nType, cx, cy);
-
-
// Handles resizing the attached renderer when the user resizes the child frame.
-
if (m_pVTK) {
-
m_pVTK->ResetSize(cx, cy);
-
}
-
}
Another note, the attached application uses vtkDICOMImageReader which I don't recommend for release code. It suffers from a few limitations. I used it to keep things simple for the purposes of this sample. Some problems include the fact that it won't recursively seach into sub folders, and it will invoke an error event if it encounters a non-DICOM file.
The application was created using visual studio 2005. After compiling, you can open a DICOM folder using File -> New, then select a folder of DICOM files from the folder selection dialog.
Please post any comments or questions.
|