[vtkusers] Problem with window updating in MFC
Henry Zhang
henry.zhang at ualberta.ca
Wed Feb 12 19:27:53 EST 2003
Hello, there,
I want to animate plant growth. There a few
frames every second. I wrote the code in Visual
C++ .Net (application type is SDI). When the
computer is rendering each frame without
interruption (such as clicking on the rendering
window, dragging the rendering window, covering
by some other windows etc), the rendering goes
well. However, if I click the rendering window,
the window becomes blank which is obviously
not desirable for animation. Could some one please
give me some suggestions about how to fix this
problem. thanks, Henry.
part of my testing code is listed below
// UIThread.cpp : implementation file
//
#include "stdafx.h"
#include "vtkSDI2.h"
#include "UIThread.h"
#include "vtkSphereSource.h"
#include "vtkActor.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#pragma comment( lib, "C:\\Program Files\\vtk40\\lib\\vtk\\vtkCommon.lib" )
#pragma comment( lib, "C:\\Program
Files\\vtk40\\lib\\vtk\\vtkRendering.lib" )
#pragma comment( lib, "C:\\Program
Files\\vtk40\\lib\\vtk\\vtkGraphics.lib" )
#pragma comment( lib, "C:\\Program Files\\vtk40\\lib\\vtk\\vtkImaging.lib" )
#pragma comment( lib, "C:\\Program
Files\\vtk40\\lib\\vtk\\vtkFiltering.lib" )
#pragma comment( lib, "C:\\Program Files\\vtk40\\lib\\vtk\\vtkHybrid.lib" )
//class CMainWindow
class CMainWindow:public CFrameWnd {
public:
CMainWindow();
vtkSphereSource *source;
vtkPolyDataMapper *mapper;
vtkActor *actor;
vtkRenderer *ren;
vtkWin32OpenGLRenderWindow *renWin;
vtkWin32RenderWindowInteractor *iren;
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
CMainWindow::CMainWindow(){
Create(NULL,_T("UI Thread testing"));
ren=vtkRenderer::New();
renWin=vtkWin32OpenGLRenderWindow::New();
iren=vtkWin32RenderWindowInteractor::New();
//iren->SetRenderWindow(renWin);
renWin->AddRenderer(ren);
renWin->SetParentId(this->m_hWnd);
}
void CMainWindow::OnLButtonDown(UINT nFlages,CPoint point){
//PostMessage(WM_CLOSE,0,0);
RECT rect;
GetClientRect(&rect);
CClientDC dc(this);
//dc.TextOut(20,25,"What is going on?");
renWin->SetSize(abs(rect.left-rect.right),abs(rect.bottom-rect.top));
source=vtkSphereSource::New();
mapper=vtkPolyDataMapper::New();
mapper->SetInput(source->GetOutput());
actor=vtkActor::New();
actor->SetMapper(mapper);
ren->AddActor(actor);
int i=0;
while(i<=100){
actor->GetProperty()->SetColor(1.0,0.0,0.0);
renWin->Render();
Sleep(1000);
actor->GetProperty()->SetColor(0.0,1.0,0.0);
renWin->Render();
Sleep(1000);
actor->GetProperty()->SetColor(0.0,0.0,1.0);
renWin->Render();
Sleep(1000);
i++;
}
}
// CUIThread
//this is almost the same as CWinApp
IMPLEMENT_DYNCREATE(CUIThread, CWinThread)
CUIThread::CUIThread()
{
}
CUIThread::~CUIThread()
{
}
BOOL CUIThread::InitInstance()
{
// TODO: perform and per-thread initialization here
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return true;
}
int CUIThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CUIThread, CWinThread)
END_MESSAGE_MAP()
// CUIThread message handlers
More information about the vtkusers
mailing list