您的位置:首页 > 其它

VTK在MFC中实现的小实例

2013-11-24 09:40 211 查看
void CVTKMFCDlg::OnBnClickedButton1()

{

// TODO: 在此添加控件通知处理程序代码

CRect rect;

m_dixing.GetClientRect(&rect); //显示在MFC上的静态文本框中

// create sphere geometry

vtkSphereSource *sphere = vtkSphereSource::New();

sphere->SetRadius(1.0);

sphere->SetThetaResolution(18);

sphere->SetPhiResolution(18);

// map to graphics library

vtkPolyDataMapper *map = vtkPolyDataMapper::New();

map->SetInput(sphere->GetOutput());

// actor coordinates geometry, properties, transformation

vtkActor *aSphere = vtkActor::New();

aSphere->SetMapper(map);

aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue

// a renderer and render window

vtkRenderer *ren1 = vtkRenderer::New();

vtkRenderWindow *renWin = vtkRenderWindow::New();

CWnd *pWnd=GetDlgItem(IDC_dixing);

HWND hwnd =pWnd->GetSafeHwnd();

renWin->SetParentId(hwnd);//设置文本框为要显示的父窗口

renWin->SetSize(rect.Width(),rect.Height());

renWin->AddRenderer(ren1);

// an interactor

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

iren->SetRenderWindow(renWin);

// add the actor to the scene

ren1->AddActor(aSphere);

ren1->SetBackground(1,1,1); // Background color white

// render an image (lights and cameras are created automatically)

renWin->Render();

// begin mouse interaction

iren->Start();

// release memory and return

sphere->Delete();

map->Delete();

aSphere->Delete();

ren1->Delete();

renWin->Delete();

iren->Delete();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: