๋ฐ˜์‘ํ˜•

VTK์—์„œ๋„ MFC์ฒ˜๋Ÿผ ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ ์ค‘ ์™ผ์ชฝ ๋ฒ„ํŠผ ํด๋ฆญ(LeftButtonDown) ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.


์•„๋ž˜ ๋งํฌ๋Š” VTK์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ณต์‹ ์˜ˆ์ œ ์‚ฌ์ดํŠธ์ž…๋‹ˆ๋‹ค.

๋งํฌ: https://lorensen.github.io/VTKExamples/site/Cxx


๋™์ž‘์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.


<MFC ScalarBar ์˜ˆ์ œ>


๋จผ์ € ์˜ˆ์ œ๋Š” ์•„๋ž˜ ๋งํฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งํฌ: https://lorensen.github.io/VTKExamples/site/Cxx/Interaction/WorldPointPicker/


์œ„ ์˜ˆ์ œ๋Š” ๋งˆ์šฐ์Šค ํด๋ฆญ ์œ„์น˜์˜ ์ •๋ณด์™€ ํ”ฝ์…€ ๊ฐ’์„ ์ถœ๋ ฅ ์ฐฝ์— ๋ณด์—ฌ์ฃผ๋Š” ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.


์ž, ๋ณธ๊ฒฉ์ ์œผ๋กœ ์˜ˆ์ œ ๋งŒ๋“ค๊ธฐ๋ฅผ ์‹ค์Šตํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
(ํ•ต์‹ฌ ๋ถ€๋ถ„๋งŒ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋ณธ๋ฌธ ํ•˜๋‹จ์˜ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.)

๋จผ์ € Dialog ๊ธฐ๋ฐ˜์œผ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.


๊ทธ๋ฆฌ๊ณ  MFC์—์„œ VTK ์‚ฌ์šฉ์„ ์œ„ํ•ด ์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.


1. VTK ์ดˆ๊ธฐํ™”

Main Dialog header ํŒŒ์ผ์— ์•„๋ž˜์˜ ์ดˆ๊ธฐํ™” ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

#pragma once
#include <vtkautoinit.h>

#define vtkRenderingCore_AUTOINIT 3(vtkRenderingOpenGL2,vtkInteractionStyle, vtkRenderingFreeType)
#define vtkRenderingContext2D_AUTOINIT 1(vtkRenderingContextOpenGL2)

#include <vtksmartpointer.h>
#include <vtkrenderercollection.h>
#include <vtkworldpointpicker.h>
#include <vtkspheresource.h>
#include <vtkpolydatamapper.h>
#include <vtkrenderer.h>
#include <vtkrenderwindow.h>
#include <vtkrenderwindowinteractor.h>
#include <vtkactor.h>
#include <vtkinteractorstyletrackballcamera.h>
#include <vtkobjectfactory.h>


2. Picture Control์— ๊ทธ๋ ค์งˆ vtkRenderWindow๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

<Header File>

public :
	vtkNew<vtkrenderwindow> m_vtkRenderWindow;

	void InitializeVTKWindow(void* hWnd);
	void ResizeVTKWindow();

<Source File>

CExampleWorldPointPickerDlg::InitializeVTKWindow(void* hWnd)
{
	vtkNew<vtkrenderwindowinteractor> interactor;
	
	interactor->SetInteractorStyle(vtkSmartPointer<vtkinteractorstyletrackballcamera>::New());

	vtkNew<vtkrenderer> renderer;
	renderer->SetBackground(0.1, 0.2, 0.3);

	m_vtkRenderWindow->SetParentId(hWnd);
	m_vtkRenderWindow->SetInteractor(interactor);
	m_vtkRenderWindow->AddRenderer(renderer);
	m_vtkRenderWindow->Render();
}

CExampleWorldPointPickerDlg::ResizeVTKWindow()
{
	CRect rc;
	GetDlgItem(IDC_PC_CHART)->GetClientRect(rc);
	m_vtkRenderWindow->SetSize(rc.Width(), rc.Height());
}


3. Button Event์— data๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ฝ”๋“œ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

void CExampleWorldPointPickerDlg::OnBnClickedBtnInitData()
{
	vtkNew<vtkspheresource> sphereSource;
	sphereSource->Update();

	vtkNew<vtkworldpointpicker> worldPointPicker;

	// Create a mapper and actor
	vtkNew<vtkpolydatamapper> mapper;
	mapper->SetInputConnection(sphereSource->GetOutputPort());
	vtkNew<vtkactor> actor;
	actor->SetMapper(mapper);

	// Create a renderer, render window, and interactor
	vtkNew<vtkrenderer> renderer;
	//vtkNew<vtkrenderwindow> renderWindow;
	m_vtkRenderWindow->AddRenderer(renderer);
	vtkNew<vtkrenderwindowinteractor> renderWindowInteractor;
	renderWindowInteractor->SetPicker(worldPointPicker);
	renderWindowInteractor->SetRenderWindow(m_vtkRenderWindow);

	vtkNew<mouseinteractorstyle> style;
	renderWindowInteractor->SetInteractorStyle(style);

	// Add the actor to the scene
	renderer->AddActor(actor);
	renderer->SetBackground(.1, .2, .3); // Background color white

	m_vtkRenderWindow->Render();
}



๊ธฐ๋ณธ C++ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ MFC Dialog ํ”„๋กœ์ ํŠธ๋กœ ๋ณ€๊ฒฝํ•œ ๊ฒƒ ๋ฐ–์— ์—†์œผ๋‹ˆ ๊ฐ„๋‹จํ•˜์ฃ ?

์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฒจ๋ถ€๋œ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

WorldPointPicker.zip

๋ฐ˜์‘ํ˜•