⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 123doc.cpp

📁 很好的vtk书籍
💻 CPP
字号:
// 123Doc.cpp : implementation of the CMy123Doc class
//

#include "stdafx.h"
#include "123.h"

#include "123Doc.h"
#include "123View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy123Doc

IMPLEMENT_DYNCREATE(CMy123Doc, CDocument)

BEGIN_MESSAGE_MAP(CMy123Doc, CDocument)
	//{{AFX_MSG_MAP(CMy123Doc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy123Doc construction/destruction

CMy123Doc::CMy123Doc()
{
	// TODO: add one-time construction code here
	this->pvtkDataSetReader  = NULL;
	
	// Create the the objects used to form the visualisation.
	this->pvtkDataSetMapper  = vtkDataSetMapper::New();
	this->pvtkActor      = vtkActor::New();
	this->pvtkActor2D    = vtkActor2D::New();
	this->pvtkTextMapper  = vtkTextMapper::New();
}

CMy123Doc::~CMy123Doc()
{
}

BOOL CMy123Doc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	
	// remove old actors
	RemoveActors();
	
	// execute object pipeline
	ExecutePipeline();

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CMy123Doc serialization

void CMy123Doc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMy123Doc diagnostics

#ifdef _DEBUG
void CMy123Doc::AssertValid() const
{
	CDocument::AssertValid();
}

void CMy123Doc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMy123Doc commands
void CMy123Doc::RemoveActors()
{
	// get our renderer first
	POSITION pos = this->GetFirstViewPosition();
	CMy123View *p123View = NULL;
	
	if (pos)
	{
		p123View = (CMy123View *)GetNextView(pos);
	}
	else  // return
	{
		ASSERT(FALSE);
		return;
	}
	
	// remove old actors
	p123View->GetRenderer()->RemoveActor(this->pvtkActor);
	p123View->GetRenderer()->RemoveActor(this->pvtkActor2D);
}

BOOL CMy123Doc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// remove old actors
	RemoveActors();
	
	// create new data reader
	this->pvtkDataSetReader = vtkDataSetReader::New();
	this->pvtkDataSetReader->SetFileName(lpszPathName);
	
	// execute object pipeline
	ExecutePipeline();
	
	return TRUE;
}

void CMy123Doc::OnCloseDocument() 
{
	// delete data

	if (this->pvtkDataSetReader)  	this->pvtkDataSetReader->Delete();
//	AfxMessageBox("lidan dandan.");	
	// Delete the the objects used to form the visualisation.
	if (this->pvtkDataSetMapper)  this->pvtkDataSetMapper->Delete();
	if (this->pvtkActor)      this->pvtkActor->Delete();
	if (this->pvtkActor2D)      this->pvtkActor2D->Delete();
	if (this->pvtkTextMapper)    this->pvtkTextMapper->Delete();
	
	CDocument::OnCloseDocument();
}

void CMy123Doc::ExecutePipeline()
{
	// get our renderer first
	POSITION pos = this->GetFirstViewPosition();
	CMy123View *p123View = NULL;
	
	if (pos)
	{
		p123View = (CMy123View *)GetNextView(pos);
	}
	else  // return
	{
		ASSERT(FALSE);
		return;
	}
	
	if (pvtkDataSetReader)  // have file
	{
		this->pvtkDataSetMapper->SetInput(this->pvtkDataSetReader->GetOutput());
		this->pvtkActor->SetMapper(this->pvtkDataSetMapper);
		
		this->pvtkTextMapper->SetInput(this->pvtkDataSetReader->GetFileName());
		this->pvtkTextMapper->GetTextProperty()->SetFontSize(12);
		this->pvtkActor2D->SetMapper(this->pvtkTextMapper);
		
		p123View->GetRenderer()->SetBackground(0.0,0.0,0.4);
		p123View->GetRenderer()->AddActor(this->pvtkActor);
		p123View->GetRenderer()->AddActor(this->pvtkActor2D);
		p123View->GetRenderer()->ResetCamera();
		this->pvtkDataSetReader->Delete();
		this->pvtkDataSetReader = NULL;
	}
	else  // have no file
	{
		this->pvtkTextMapper->SetInput("Hello World");
		this->pvtkTextMapper->GetTextProperty()->SetFontSize(24);
		this->pvtkActor2D->SetMapper(this->pvtkTextMapper);
		
		p123View->GetRenderer()->SetBackground(0.0,0.0,0.4);
		p123View->GetRenderer()->AddActor(this->pvtkActor2D);
		p123View->GetRenderer()->ResetCamera();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -