[VTK] imaging and MFC
Klaus Nowikow
knowikow at iac.tuwien.ac.at
Wed Aug 18 06:20:47 EDT 1999
Roland Schwarz wrote:
>
> Dear VTK Users,
> does anyone have an example showing how to do
> imaging using the MFC VC++ framework?
Roland,
the key is to tell vtk to draw into an MFC Window.
I did it that way:
In my View class (CCommon3DView), I defined the following member
variables:
vtkWin32OpenGLRenderWindow *window;
vtkWin32MappedInteractor *interactor;
vtkRenderer *renderer;
then:
int CCommon3DView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
this->renderer = vtkRenderer::New();
this->window = vtkWin32OpenGLRenderWindow::New();
this->window->AddRenderer(this->renderer);
this->window->SwapBuffersOn();
this->interactor = vtkWin32MappedInteractor::New();
this->interactor->SetRenderWindow(this->window);
/* --- [snip] ---*/
return 0;
}
and:
void CCommon3DView::OnDraw(CDC* pDC)
{
if(!this->interactor->GetInitialized())
{
CRect rect;
/* --- [snip] ---*/
camera = this->renderer->GetActiveCamera();
this->GetClientRect(&rect);
this->interactor->Initialize(this->m_hWnd, &rect, this->window);
this->renderer->ResetCamera();
}
camera = this->renderer->GetActiveCamera();
if(pDC->IsPrinting())
{
this->BeginWaitCursor();
// get size of printer page (in pixels)
int cxPage = pDC->GetDeviceCaps(HORZRES);
int cyPage = pDC->GetDeviceCaps(VERTRES);
int *size = this->window->GetSize();
int cxWindow = size[0],
cyWindow = size[1];
float fx = float(cxPage) / float(cxWindow),
fy = float(cyPage) / float(cyWindow);
float scale = min(fx, fy);
int x = int(scale * float(cxWindow)),
y = int(scale * float(cyWindow));
this->window->SetupMemoryRendering(cxWindow, cyWindow,
pDC->GetSafeHdc());
this->window->Render();
HDC memDC = this->window->GetMemoryDC();
StretchBlt(pDC->GetSafeHdc(), 0, 0, x, y, memDC, 0, 0, cxWindow,
cyWindow, SRCCOPY);
this->window->ResumeScreenRendering();
this->EndWaitCursor();
}
else
{
this->interactor->Update();
}
}
--
Klaus Nowikow
Vienna University of Technology
Department of Analytical Chemistry
Getreidemarkt 9/E151
A - 1060 Vienna, Austria
Tel: +43/1/58801 - 15124
email: mailto:knowikow at iac.tuwien.ac.at
-----------------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>. For help, send message body containing
"info vtkusers" to the same address. Live long and prosper.
-----------------------------------------------------------------------------
More information about the vtkusers
mailing list