[vtkusers] vtk 2D with MFC.

Marek.Wasilewski at dnv.com Marek.Wasilewski at dnv.com
Mon Aug 9 09:10:58 EDT 2004


Hi Ruby
Please find some code below - I think it does what you need.  

You'll need to free the allocated memory, most likely in ~CRubyDlg.  I
used a picture control of type "Frame" for IDC_PIC.

Best regards,

Marek

CRubyDlg::CRubyDlg(CWnd* pParent /*=NULL*/) : 
  CDialog(CRubyDlg::IDD, pParent),
  m_pvtkBMPReader(NULL),
	m_pvtkImageActor(NULL),
	m_pvtkRenderer(NULL),
	m_pvtkWin32OpenGLRenderWindow(NULL)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

In OnitDialog:

  vtkBMPReader* m_pvtkBMPReader = vtkBMPReader::New();
  vtkImageActor* m_pvtkImageActor = vtkImageActor::New();
  vtkRenderer* m_pvtkRenderer = vtkRenderer::New();
  vtkWin32OpenGLRenderWindow* m_pvtkWin32OpenGLRenderWindow =
vtkWin32OpenGLRenderWindow::New();

  m_pvtkBMPReader = vtkBMPReader::New();
 
m_pvtkBMPReader->SetFileName("C:\\VTK\\VTKData-release-4-2\\Data\\masonr
y.bmp");
  m_pvtkBMPReader->Update();

  m_pvtkImageActor->SetInput(m_pvtkBMPReader->GetOutput());
  m_pvtkRenderer->AddActor(m_pvtkImageActor);

  CRect rect;
  CWnd* pWnd = GetDlgItem(IDC_PIC);
  pWnd->GetClientRect(&rect);

  m_pvtkWin32OpenGLRenderWindow->SetSize(rect.Width(), rect.Height());

  m_pvtkWin32OpenGLRenderWindow->SetParentId(pWnd->m_hWnd);
  ::SetParent(m_pvtkWin32OpenGLRenderWindow->GetWindowId(),
this->m_hWnd);

  m_pvtkWin32OpenGLRenderWindow->AddRenderer(m_pvtkRenderer);
  m_pvtkWin32OpenGLRenderWindow->Render();

-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
Behalf Of Ruby Shamir
Sent: 09 August 2004 10:50
To: vtkusers at vtk.org
Subject: [vtkusers] vtk 2D with MFC.

Hello,

We tried to display 2D image in a picture element with MFC.

The image displayed fine when we did not changed the window's ID, what
is the problem?

Here is the code:

	bmpReader = vtkBMPReader::New();
      bmpReader->SetFileName("D:\\vtkExp\\femur1.bmp");

	vtkImageActor* act = vtkImageActor::New();
      act->SetInput(bmpReader->GetOutput());

	vtkRenderer* renderer = vtkRenderer::New();
	renderer->AddActor(act);

	CWnd* wind = GetDlgItem(IDC_PIC); // this is the inner element
which the image will display in

	vtkWin32OpenGLRenderWindow* renwin =
vtkWin32OpenGLRenderWindow::New();
	renwin->SetWindowId(wind->m_hWnd); // when deleting this line it
displays good but in other window.

	renwin->AddRenderer(renderer);
	renwin->Render();

Best regards,

   Ruby

_______________________________________________
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://www.vtk.org/mailman/listinfo/vtkusers


**************************************************************
Neither the confidentiality nor the integrity of this message can be guaranteed following transmission on the Internet. 
All messages sent to a DNV email addressee are swept by Sybari Antigen for the presence of computer viruses. 
DNV acknowledges that SPAM email represents a potential security risk, and DNVs filters to block unwanted emails are therefore continuously adjusted. DNV has disabled "out of office" replies to the Internet 
************************************************************** 




More information about the vtkusers mailing list