// vtkMFCView.cpp : implementation file
//
#include "stdafx.h"
#include "vtkMFCView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// vtkMFCView
IMPLEMENT_DYNCREATE(vtkMFCView, CView)
vtkMFCView::vtkMFCView()
{
pvtkWin32OpenGLRW=NULL;
}
vtkMFCView::~vtkMFCView()
{
this->SetRenderWindow(NULL);
}
BEGIN_MESSAGE_MAP(vtkMFCView, CView)
//{{AFX_MSG_MAP(vtkMFCView)
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_DESTROY()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONUP()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
ON_WM_CHAR()
ON_WM_KEYUP()
ON_WM_KEYDOWN()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// vtkMFCView drawing
void vtkMFCView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
int cxPage = pDC->GetDeviceCaps(HORZRES);
int cyPage = pDC->GetDeviceCaps(VERTRES);
if (pDC->IsPrinting())
{
// Get the size of the window in pixels.
int *size = this->pvtkWin32OpenGLRW->GetSize();
int cxWindow = size[0];
int cyWindow = size[1];
float fx = float(cxPage) / float(cxWindow);
float fy = float(cyPage) / float(cyWindow);
float scale = min(fx,fy);
int x = int(scale * float(cxWindow));
int y = int(scale * float(cyWindow));
this->pvtkWin32OpenGLRW->SetupMemoryRendering(cxWindow, cyWindow, pDC->GetSafeHdc());
this->pvtkWin32OpenGLRW->Render();
HDC memDC = this->pvtkWin32OpenGLRW->GetMemoryDC();
StretchBlt(pDC->GetSafeHdc(),0,0,x,y,memDC,0,0,cxWindow,cyWindow,SRCCOPY);
this->pvtkWin32OpenGLRW->ResumeScreenRendering();
}
}
/////////////////////////////////////////////////////////////////////////////
// vtkMFCView diagnostics
#ifdef _DEBUG
void vtkMFCView::AssertValid() const
{
CView::AssertValid();
}
void vtkMFCView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// vtkMFCView message handlers
void vtkMFCView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (this->GetInteractor() && this->GetInteractor()->GetInitialized())
this->GetInteractor()->UpdateSize(cx, cy);
// TODO: Add your message handler code here
}
void vtkMFCView::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (this->GetInteractor() && this->GetInteractor()->GetInitialized())
{
this->GetInteractor()->Render();
}
// TODO: Add your message handler code here
// Do not call CView::OnPaint() for painting messages
}
void vtkMFCView::OnDestroy()
{
if(this->pvtkWin32OpenGLRW && this->pvtkWin32OpenGLRW->GetMapped())
this->pvtkWin32OpenGLRW->Finalize();
CView::OnDestroy();
}
void vtkMFCView::SetRenderWindow(vtkWin32OpenGLRenderWindow* win)
{
if(this->pvtkWin32OpenGLRW)
{
if(this->pvtkWin32OpenGLRW->GetMapped())
this->pvtkWin32OpenGLRW->Finalize();
this->pvtkWin32OpenGLRW->UnRegister(NULL);
}
this->pvtkWin32OpenGLRW = win;
if(this->pvtkWin32OpenGLRW)
{
this->pvtkWin32OpenGLRW->Register(NULL);
vtkWin32RenderWindowInteractor* iren = vtkWin32RenderWindowInteractor::New();
iren->SetInstallMessageProc(0);
// setup the parent window
this->pvtkWin32OpenGLRW->SetWindowId(this->GetSafeHwnd());
this->pvtkWin32OpenGLRW->SetParentId(::GetParent(this->GetSafeHwnd()));
iren->SetRenderWindow(this->pvtkWin32OpenGLRW);
iren->Initialize();
// update size
CRect cRect = CRect(0,0,1,1);
if(this->GetParent())
this->GetParent()->GetClientRect(&cRect);
if (iren->GetInitialized())
iren->UpdateSize(cRect.Width(), cRect.Height());
// release our hold on interactor
iren->Delete();
}
}
vtkWin32OpenGLRenderWindow* vtkMFCView::GetRenderWindow()
{
return this->pvtkWin32OpenGLRW;
}
vtkRenderWindowInteractor* vtkMFCView::GetInteractor()
{
if(!this->pvtkWin32OpenGLRW)
return NULL;
return this->pvtkWin32OpenGLRW->GetInteractor();
}
BOOL vtkMFCView::OnEraseBkgnd(CDC*)
{
return TRUE;
}
void vtkMFCView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnLButtonDown(this->GetSafeHwnd(), nFlags, point.x, point.y, 1);
}
void vtkMFCView::OnLButtonDown(UINT nFlags, CPoint point)
{
this->SetFocus();
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnLButtonDown(this->GetSafeHwnd(), nFlags, point.x, point.y, 0);
}
void vtkMFCView::OnMButtonDown(UINT nFlags, CPoint point)
{
this->SetFocus();
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMButtonDown(this->GetSafeHwnd(), nFlags, point.x, point.y, 0);
}
void vtkMFCView::OnRButtonDown(UINT nFlags, CPoint point)
{
this->SetFocus();
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnRButtonDown(this->GetSafeHwnd(), nFlags, point.x, point.y, 0);
}
void vtkMFCView::OnLButtonUp(UINT nFlags, CPoint point)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnLButtonUp(this->GetSafeHwnd(), nFlags, point.x, point.y);
}
void vtkMFCView::OnMButtonUp(UINT nFlags, CPoint point)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMButtonUp(this->GetSafeHwnd(), nFlags, point.x, point.y);
}
void vtkMFCView::OnRButtonUp(UINT nFlags, CPoint point)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnRButtonUp(this->GetSafeHwnd(), nFlags, point.x, point.y);
}
void vtkMFCView::OnMouseMove(UINT nFlags, CPoint point)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseMove(this->GetSafeHwnd(), nFlags, point.x, point.y);
}
BOOL vtkMFCView::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
if(zDelta > 0)
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseWheelForward(this->GetSafeHwnd(), nFlags, point.x, point.y);
else
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseWheelBackward(this->GetSafeHwnd(), nFlags, point.x, point.y);
return TRUE;
}
void vtkMFCView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnChar(this->GetSafeHwnd(), nChar, nRepCnt, nFlags);
}
void vtkMFCView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnKeyUp(this->GetSafeHwnd(), nChar, nRepCnt, nFlags);
}
void vtkMFCView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnKeyDown(this->GetSafeHwnd(), nChar, nRepCnt, nFlags);
}
void vtkMFCView::OnTimer(UINT nIDEvent)
{
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnTimer(this->GetSafeHwnd(), nIDEvent);
}
void vtkMFCView::OnInitialUpdate()
{
CView::OnInitialUpdate();
vtkWin32OpenGLRenderWindow* win = vtkWin32OpenGLRenderWindow::New();
this->SetRenderWindow(win);
win->Delete();
// TODO: Add your specialized code here and/or call the base class
}
MFC和VTK结合的程序
4星 · 超过85%的资源 需积分: 49 17 浏览量
2010-11-21
21:49:07
上传
评论 6
收藏 2KB RAR 举报
shaoyouxia
- 粉丝: 2
- 资源: 4
最新资源
- human-pose-estimation-3d.pth
- Python测试Python测试Python测试
- 文档包含python读取csv的四种方法
- 导航菜单横向左右滑动并和下方的控件实现联动 2.zip
- Cube-World-Proto-Series v4.1.unitypackage
- ISAM操作说明,基于segment anything的自动化图片标注工具
- 30-sn22FNOKSNDKFONASKLDFNLNSADN那附近撒旦反抗精神的发
- 中文3DMAX测量标注插件DIMaster v2.0下载
- 第三方接口访问(需要在SpringBoot环境下使用)
- java图书管理系统毕业设计(源代码+论文).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页