๋ฐ˜์‘ํ˜•

์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ๋Š” MFC์—์„œ VTK Bar Chart๋ฅผ ๊ทธ๋ ค๋ณด๋Š” ์ž‘์—…์„ ๋ณด์—ฌ๋“œ๋ ธ์Šต๋‹ˆ๋‹ค.


์ด๋ฒˆ์—๋Š” Line Plot์„ ๊ทธ๋ฆฌ๋Š” ์˜ˆ์ œ๋ฅผ ์„ค๋ช… ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.


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

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


์˜ค๋Š˜ ๋ณด์—ฌ๋“œ๋ฆด ์˜ˆ์ œ๋Š” ํ‰์†Œ์— ์‚ฌ์šฉ๋  ๋งŒํ•œ ๋„๊ตฌ ์ค‘ ํ•˜๋‚˜์ธ '์  ๊ทธ๋ž˜ํ”„(Line Plot)'์ž…๋‹ˆ๋‹ค.

<MFC Line Plot ์˜ˆ์ œ>


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

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


์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” ์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€๋ฐ์š”.

์ง€๋‚œ๋ฒˆ BarChart์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ๊ฐ€ ๋“ฑ๋ก๋˜์–ด ์žˆ์–ด ์ด๋™, ํ™•๋Œ€/์ถ•์†Œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋ฉฐ, 
์‚ฌ์šฉ์ž ์ž…๋ง›์— ๋งž๊ฒŒ ๊ธ€์ž ํฌ๊ธฐ, ์ƒ‰์ƒ, Tick ๊ฐ„๊ฒฉ ๋“ฑ ๋ชจ๋“  ๊ฒƒ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


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

๋จผ์ € 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 <vtkChartXY.h>
#include <vtkTable.h>
#include <vtkPlot.h>
#include <vtkFloatArray.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
#include <vtkPen.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์— Chart data๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ฝ”๋“œ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

void CExampleLinePlotDlg::OnBnClickedBtnInitchart()
{
	// Create a table with some points in it
	vtkNew<vtkTable> table;

	vtkNew<vtkFloatArray> arrX;
	arrX->SetName("X Axis");
	table->AddColumn(arrX);

	vtkNew<vtkFloatArray> arrC;
	arrC->SetName("Cosine");
	table->AddColumn(arrC);

	vtkNew<vtkFloatArray> arrS;
	arrS->SetName("Sine");
	table->AddColumn(arrS);

	// Fill in the table with some example values
	int numPoints = 69;
	float inc = 7.5 / (numPoints - 1);
	table->SetNumberOfRows(numPoints);
	for (int i = 0; i < numPoints; ++i)
	{
		table->SetValue(i, 0, i * inc);
		table->SetValue(i, 1, cos(i * inc));
		table->SetValue(i, 2, sin(i * inc));
	}

	// Set up the view
	vtkNew<vtkContextView> view;
	view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);

	// ์ถ”๊ฐ€
	view->SetRenderWindow(m_vtkRenderWindow);

	// Add multiple line plots, setting the colors etc
	vtkNew<vtkChartXY> chart;
	view->GetScene()->AddItem(chart);
	vtkPlot *line = chart->AddPlot(vtkChart::LINE);
	line->SetInputData(table, 0, 1);
	line->SetColor(0, 255, 0, 255);
	line->SetWidth(1.0);
	line = chart->AddPlot(vtkChart::LINE);
	line->SetInputData(table, 0, 2);
	line->SetColor(255, 0, 0, 255);
	line->SetWidth(5.0);

	// For dotted line, the line type can be from 2 to 5 for different dash/dot
	// patterns (see enum in vtkPen containing DASH_LINE, value 2):
#ifndef WIN32
	line->GetPen()->SetLineType(vtkPen::DASH_LINE);
#endif
	// (ifdef-ed out on Windows because DASH_LINE does not work on Windows
	//  machines with built-in Intel HD graphics card...)

	//view->GetRenderWindow()->SetMultiSamples(0);

	// Start interactor
	view->GetRenderWindow()->Render();
	view->GetInteractor()->Initialize();
	//view->GetInteractor()->Start();
}


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

ExampleLinePlot.zip


๋ฐ˜์‘ํ˜•