[vtkusers] creating a VTk in MFC

Asad A. Abu-Tarif tarifa at rpi.edu
Sun Jun 23 11:44:46 EDT 2002


Hi Giancarlo,
You do everything normally except you call
SetParentId(m_hWnd);
of the rendering window instance.

For the more advanced stuf, you can be
as creative as you want. I personally put
the vtk code in a class derived from the
MFC CView class. I trap the screen size
change inside the main CView class and
resize the rendering window accordingly.

Below you can find pieces of code form
my main application. They should be easy
to follow. I use the single-document-single-view
architecture.

Good luck.
Asad

/*********************************************************/
// Code I put in a class derived from CView
// when I want to visualize something.
GetDocument()->m_WindowRenderMode=1;
 // Define the window to render and the renderer.
 //{
 GetDocument()->renderer1 = vtkRenderer::New();
 GetDocument()->renWin = vtkRenderWindow::New();
 GetDocument()->renWin->AddRenderer(GetDocument()->renderer1);
 GetDocument()->renWin->SetParentId(m_hWnd);
 GetDocument()->iren = vtkRenderWindowInteractor::New();
 GetDocument()->iren->SetRenderWindow(GetDocument()->renWin);
// Visualization code.
this->Render();
 //}
/*********************************************************/


/*********************************************************/
// The render functions I have in the main CView class.
void CRegMagicWINGUIView::Render()
{
 RECT ClientRect;
 GetClientRect(&ClientRect);

 Render(ClientRect.right-ClientRect.left,ClientRect.bottom-ClientRect.top);
}

void CRegMagicWINGUIView::Render(int cx,int cy)
{
 if((GetDocument()->renWin)==NULL)
 {
  AfxMessageBox("The redering window is not instantiated....");
  return;
 }
 GetDocument()->renWin->SetSize(cx,cy);
 if(GetDocument()->m_WindowRenderMode==0)
 {
  AfxMessageBox("The redering mode is set to zero....",MB_ICONERROR);
  return;
 }
 if(GetDocument()->m_WindowRenderMode==1)
 {
  if(GetDocument()->renderer1!=NULL)
   GetDocument()->renderer1->SetViewport(0,0,1,1);
 }
 if(GetDocument()->m_WindowRenderMode==2)
 {
  if(GetDocument()->renderer1!=NULL)
   GetDocument()->renderer1->SetViewport(0,0.5,1,1);
  if(GetDocument()->renderer2!=NULL)
   GetDocument()->renderer2->SetViewport(0,0,1,0.5);
 }
 if(GetDocument()->m_WindowRenderMode==3)
 {
  if(GetDocument()->renderer1!=NULL)
   GetDocument()->renderer1->SetViewport(0,0.5,1,1);
  if(GetDocument()->renderer2!=NULL)
   GetDocument()->renderer2->SetViewport(0,0,0.5,0.5);
  if(GetDocument()->renderer3!=NULL)
   GetDocument()->renderer3->SetViewport(0.5,0,1,0.5);
 }
 if(GetDocument()->m_WindowRenderMode==4)
 {
  if(GetDocument()->renderer1!=NULL)
   GetDocument()->renderer1->SetViewport(0,0.5,0.5,1);
  if(GetDocument()->renderer2!=NULL)
   GetDocument()->renderer2->SetViewport(0.5,0.5,1,1);
  if(GetDocument()->renderer3!=NULL)
   GetDocument()->renderer3->SetViewport(0,0,0.5,0.5);
  if(GetDocument()->renderer4!=NULL)
   GetDocument()->renderer4->SetViewport(0.5,0,1,0.5);
 }
 GetDocument()->renWin->Render();
 OnDraw(GetDC());
}
/*********************************************************/

&&&&&&&&&&&&&&&&&
*  Asad A. Abu-Tarif
*  Computer Engineering.
*  PhD Candidate, Rensselaer Polytechnic Institute (RPI).
*  Web-site: http://asad.ods.org/Professional/
*  Registration Toolkit: http://asad.ods.org/RegMagicTKDoc/
*  tarifa at rpi.edu
&&&&&&&&&&&&&&&&&&
* When in charge, ponder
* When in trouble, delegate
* When in doubt, mumble
&&&&&&&&&&&&&&&&&

----- Original Message -----
From: "Giancarlo Amati" <amati at ira.cnr.it>
To: <vtkusers at public.kitware.com>
Sent: Saturday, June 22, 2002 4:59 PM
Subject: [vtkusers] creating a VTk in MFC


> Hello everybody,
>
> I have serious problem in creating a render window in a MFC application, I
> mean that I would like to create a render window in the client area of my
> MFC application, while now I obtained only to create a new window outside
> the main application.
>
> Any body can help me?
>
> thank you
> Giancarlo
>
> --
> ----------------------------------------
> dott. Giancarlo Amati                  |
> (amati at ira.cnr.it)                     |
>                                        |
> National Research Council              |
> RadioAstronomical Institute            |
> office phone n. +39 051 6399405        |
> via Gobetti 101 - Bologna (Italy)      |
> ----------------------------------------
>
> _______________________________________________
> 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