www.pudn.com > SurfaceRecon.rar > MITKTestView.cpp


// MITKTestView.cpp : implementation of the CMITKTestView class 
// 
 
#include "stdafx.h" 
#include "MITKTest.h" 
 
#include "MITKTestDoc.h" 
#include "MITKTestView.h" 
 
#include "mitkView.h" 
#include "mitkSurfaceModel.h" 
#include "mitkSurfaceRendererStandard.h" 
#include "mitkSurfaceRendererUseVA.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMITKTestView 
 
IMPLEMENT_DYNCREATE(CMITKTestView, CView) 
 
BEGIN_MESSAGE_MAP(CMITKTestView, CView) 
	//{{AFX_MSG_MAP(CMITKTestView) 
	ON_WM_CREATE() 
	ON_WM_SIZE() 
	ON_WM_DESTROY() 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMITKTestView construction/destruction 
 
CMITKTestView::CMITKTestView() 
{ 
	// TODO: add construction code here 
	m_View = NULL; 
	m_SurfaceModel = NULL; 
 
} 
 
CMITKTestView::~CMITKTestView() 
{ 
} 
 
BOOL CMITKTestView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMITKTestView drawing 
 
void CMITKTestView::OnDraw(CDC* pDC) 
{ 
	CMITKTestDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	// Mesh数据更新,Surface Model也随之更新 
	if (m_SurfaceModel->GetData() != pDoc->GetMesh()) 
	{ 
		m_SurfaceModel->SetData(pDoc->GetMesh()); 
//		m_View->OnDraw(); 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMITKTestView printing 
 
BOOL CMITKTestView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CMITKTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CMITKTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMITKTestView diagnostics 
 
#ifdef _DEBUG 
void CMITKTestView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CMITKTestView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CMITKTestDoc* CMITKTestView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMITKTestDoc))); 
	return (CMITKTestDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMITKTestView message handlers 
 
int CMITKTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CView::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	// TODO: Add your specialized creation code here 
	// 得到当前客户区大小 
	RECT clientRect; 
	this->GetClientRect(&clientRect); 
	int wWidth = clientRect.right - clientRect.left; 
	int wHeight = clientRect.bottom - clientRect.top; 
	 
	// 产生mitkView对象 
	m_View = new mitkView; 
 
	// 设置父窗口句柄 
    m_View->SetParent(GetSafeHwnd()); 
	 
	// 设置mitkView在父窗口中显示的位置和大小 
    m_View->SetLeft(0); 
    m_View->SetTop(0); 
    m_View->SetWidth(wWidth); 
    m_View->SetHeight(wHeight); 
 
	// 设置mitkView的背景颜色(这里将其设置为黑色) 
	m_View->SetBackColor(1.0f, 1.0f, 1.0f); 
 
	// 显示mitkView 
    m_View->Show(); 
	 
	// 生成一个mitkSurfaceModel 
	m_SurfaceModel = new mitkSurfaceModel; 
 
	// 设置表面材质属性(这些属性可以随时调整) 
	m_SurfaceModel->GetProperty()->SetAmbientColor(0.75f, 0.75f, 0.75f, 1.0f); 
	m_SurfaceModel->GetProperty()->SetDiffuseColor(1.0f, 0.57f, 0.04f, 1.0f); 
	m_SurfaceModel->GetProperty()->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); 
	m_SurfaceModel->GetProperty()->SetSpecularPower(100.0f); 
	m_SurfaceModel->GetProperty()->SetEmissionColor(0.0f, 0.0f, 0.0f, 0.0f); 
	m_SurfaceModel->GetProperty()->SetEdgeColor(1.0f, 0.0f, 0.0f, 1.0f); 
	//m_SurfaceModel->GetProperty()->SetRepresentationTypeToWireframe(); 
	//m_SurfaceModel->GetProperty()->SetRepresentationTypeToPoints(); 
	//m_SurfaceModel->SetRenderer(new mitkSurfaceRendererUseVA); 
 
	// 将Model加入到View中 
	m_View->AddModel(m_SurfaceModel); 
	 
	return 0; 
} 
 
void CMITKTestView::OnSize(UINT nType, int cx, int cy)  
{ 
	CView::OnSize(nType, cx, cy); 
	 
	// TODO: Add your message handler code here 
	// 防止对NULL指针操作 
	if (!m_View) return; 
 
	// 更新mitkView在父窗口中的位置和尺寸 
	m_View->SetLeft(0); 
	m_View->SetTop(0); 
	m_View->SetWidth(cx); 
	m_View->SetHeight(cy); 
 
	// 刷新mitkView 
	m_View->Update();	 
} 
 
void CMITKTestView::OnDestroy()  
{ 
	CView::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	if (m_View)  
	{ 
		m_View->Delete(); 
		m_View = NULL; 
	} 
}