๋ฐ˜์‘ํ˜•

VTK๋Š” Visualization ToolKit์˜ ์•ฝ์ž์ด์ฃ ?

์•„์‹œ๋‹ค์‹œํ”ผ VTK์—๋Š” 3D ๋ฐ์ดํ„ฐ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š”๋ฐ ๋ง‰๊ฐ•ํ•œ ๊ธฐ๋Šฅ๋“ค์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ ์ค‘ Point Cloud Data๋ฅผ ํ‘œํ˜„ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ๊ธฐ์ดˆ๋ผ ์ƒ๊ฐ๋˜๋Š”๋ฐ์š”.

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” 3D ๋ชจ๋ธ ํŒŒ์ผ(PLY, STL, OBJ ๋“ฑ)์„ ๋ถˆ๋Ÿฌ์™€ 3D Renderingํ•˜๋Š” ์˜ˆ์ œ๋ฅผ ์†Œ๊ฐœํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.


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

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

<MFC 3D Rendering ์˜ˆ์ œ>


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

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


3D ํ”„๋กœ๊ทธ๋žจ์„ ์ ‘ํ•˜์‹  ๋ถ„์ด๋ผ๋ฉด ์ต์ˆ™ํ•œ ๋™์ž‘์ด๋ผ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.

ํšŒ์ „, ํ™•๋Œ€, ์ถ•์†Œ, ์ด๋™์˜ ๊ฐ„๋‹จํ•œ ๋™์ž‘๋“ค์„ ํ•ฉ๋‹ˆ๋‹ค. ๋ฌผ๋ก  ๋ฒ„ํŠผ์— ๋”ฐ๋ฅธ ๋™์ž‘์ด ์กฐ๊ธˆ ๋‹ค๋ฅผ ์ˆœ ์žˆ์Šต๋‹ˆ๋‹ค.


3D ๋ชจ๋ธ ํŒŒ์ผ์€ ์•„๋ž˜ ๋งํฌ์—์„œ ์ฐธ๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋งํฌ: https://www.laserdesign.com/sample-files/type/ply/


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

๋จผ์ € 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 <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkPLYReader.h>
#include <vtkPolyDataMapper.h>


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

<Header File>


public :
	vtkNew<vtkRenderWindow> m_vtkRenderWindow;

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

<Source File>

void CExampleLinePlotDlg::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();
}

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


3. Button Event์— 3D ๋ชจ๋ธ ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ฝ”๋“œ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋กœ, ์˜ˆ์ œ๋Š” PLY๋งŒ ์‚ฌ์šฉํ–ˆ์ง€๋งŒ 'vtkSTLReader'ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด STL ํŒŒ์ผ๋„ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

void CExample3DRenderingDlg::OnBnClickedBtnLoadply()
{
	vtkNew<vtkPLYReader> pPLYReader;
	pPLYReader->SetFileName("Anno.ply");
	pPLYReader->Update();

	vtkNew<vtkPolyDataMapper> mapper;
	mapper->SetInputConnection(pPLYReader->GetOutputPort());
	
	vtkNew<vtkActor> actor;
	actor->SetMapper(mapper);

	vtkNew<vtkRenderer> renderer;
	renderer->AddActor(actor);
	renderer->SetBackground(.1, .2, .3);
	renderer->ResetCamera();

	m_vtkRenderWindow->AddRenderer(renderer);
	m_vtkRenderWindow->Render();

	renderer->ResetCamera();
	m_vtkRenderWindow->Render();
}


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

Example3DRendering.zip

๋ฐ˜์‘ํ˜•