[VTK] MFC์์ VTK 2D Bar ์ฐจํธ ์ฌ์ฉํ๊ธฐ
VTK SDK์๋ ๋ณดํต 3D ์๊ฐํ ๋๊ตฌ๋ผ๊ณ ๋ง ์๊ณ ๊ณ์ค ๊ฒ ๊ฐ์๋ฐ์.
์ฌ์ค VTK SDK๋ 2D, 3D์ ๊ด๋ จ๋ ๋ง์ ๊ธฐ๋ฅ๋ค์ ์ง์ํ๊ณ ์์ต๋๋ค.
์๋ ๋งํฌ๋ VTK์์ ์ ๊ณตํ๋ ๊ณต์ ์์ ์ฌ์ดํธ์ ๋๋ค.
๋งํฌ: https://lorensen.github.io/VTKExamples/site/Cxx
์ค๋ ๋ณด์ฌ๋๋ฆด ์์ ๋ ํ์์ ์ฌ์ฉ๋ ๋งํ ๋๊ตฌ ์ค ํ๋์ธ '์ฐจํธ'์ ๋๋ค.
<MFC BarChart ์์ >
๋จผ์ ์์ ๋ ์๋ ๋งํฌ์์ ํ์ธํ ์ ์์ต๋๋ค.
๋งํฌ: https://lorensen.github.io/VTKExamples/site/Cxx/Plotting/BarChart/
์คํ ๊ฒฐ๊ณผ๋ ์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์๋ฐ์.
๋ง์ฐ์ค ์ด๋ฒคํธ๊ฐ ๋ฑ๋ก๋์ด ์์ด ์ด๋, ํ๋/์ถ์๊ฐ ๊ฐ๋ฅํ๋ฉฐ,
์ฌ์ฉ์ ์
๋ง์ ๋ง๊ฒ ๊ธ์ ํฌ๊ธฐ, ์์, Tick ๊ฐ๊ฒฉ ๋ฑ ๋ชจ๋ ๊ฒ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
MFC UI์๋ Chart๋ผ๋ ๊ฒ์ด ์๊ธฐ ๋๋ฌธ์ ์ฌ์ฉ์๊ฐ ์ง์ ๋ง๋ค์ด์ผ ํ๋๋ฐ์.
์ด๋ฐ ๊ธฐ๋ฅ์ ๊ฐ์ ธ๋ค ์ฌ์ฉํ ์ ์์ผ๋ฉด, ๊ตณ์ด ๋ง๋ค์ง ์์๋ ๋๊ฒ ์ฃ ?
์, ๋ณธ๊ฒฉ์ ์ผ๋ก ์์ ๋ง๋ค๊ธฐ๋ฅผ ์ค์ตํด ๋ณด๊ฒ ์ต๋๋ค.
(ํต์ฌ ๋ถ๋ถ๋ง ์ค๋ช
ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ณธ๋ฌธ ํ๋จ์ ์์ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.)
๋จผ์ Dialog ๊ธฐ๋ฐ์ผ๋ก ํ๋ก์ ํธ๋ฅผ ์์ฑํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ MFC์์ VTK ์ฌ์ฉ์ ์ํด ์๋ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ์ฌ ์ค์ ํฉ๋๋ค.
1. VTK ์ด๊ธฐํ
Main Dialog header ํ์ผ์ ์๋์ ์ด๊ธฐํ ์ฝ๋๋ฅผ ์ถ๊ฐํฉ๋๋ค.
#include <vtkAutoInit.h>
#define vtkRenderingCore_AUTOINIT 3(vtkRenderingOpenGL2,vtkInteractionStyle, vtkRenderingFreeType)
#define vtkRenderingContext2D_AUTOINIT 1(vtkRenderingContextOpenGL2)
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkVersion.h>
#include <vtkChartXY.h>
#include <vtkPlot.h>
#include <vtkAxis.h>
#include <vtkTable.h>
#include <vtkTextProperty.h>
#include <vtkIntArray.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
#include <vtkColorSeries.h>
#include <vtkNamedColors.h>
#include <vtkColor.h>
2. Picture Control์ ๊ทธ๋ ค์ง vtkRenderWindow๋ฅผ ์ด๊ธฐํํฉ๋๋ค.
<Header File>
<Source File>
void CExampleBarChartDlg::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 CExampleBarChartDlg::ResizeVTKWindow()
{
CRect rc;
GetDlgItem(IDC_PC_CHART)->GetClientRect(rc);
m_vtkRenderWindow->SetSize(rc.Width(), rc.Height());
}
3. Button Event์ Chart data๋ฅผ ๋ถ๋ฌ์ค๋ ์ฝ๋๋ฅผ ์ ์ํฉ๋๋ค.
void CExampleBarChartDlg::OnBnClickedBtnInitchart()
{
// Colors
vtkNew<vtkColorSeries> colorSeries;
colorSeries->SetColorScheme(vtkColorSeries::BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_3);
colorSeries->SetColorScheme(vtkColorSeries::BREWER_DIVERGING_SPECTRAL_3);
colorSeries->SetColorScheme(vtkColorSeries::BREWER_DIVERGING_BROWN_BLUE_GREEN_3);
colorSeries->SetColorScheme(vtkColorSeries::BREWER_SEQUENTIAL_BLUE_GREEN_3);
colorSeries->SetColorScheme(vtkColorSeries::BREWER_SEQUENTIAL_BLUE_PURPLE_3);
colorSeries->SetColorScheme(vtkColorSeries::BREWER_DIVERGING_PURPLE_ORANGE_3);
vtkNew<vtkNamedColors> colors;
vtkColor3d backgroundColor = colors->GetColor3d("Sienna");
vtkColor3d axisColor = colors->GetColor3d("Wheat");
vtkColor3d titleColor = colors->GetColor3d("Wheat");
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderer()->SetBackground(backgroundColor.GetData());
view->GetRenderWindow()->SetSize(640, 480);
// ์ถ๊ฐ
view->SetRenderWindow(m_vtkRenderWindow);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart);
// Set various properties
vtkAxis *xAxis = chart->GetAxis(vtkAxis::BOTTOM);
xAxis->SetTitle("Monthly");
xAxis->GetTitleProperties()->SetColor(axisColor.GetData());
xAxis->GetTitleProperties()->SetFontSize(16);
xAxis->GetTitleProperties()->ItalicOn();
xAxis->GetLabelProperties()->SetColor(axisColor.GetData());
vtkAxis *yAxis = chart->GetAxis(vtkAxis::LEFT);
yAxis->SetTitle("Circulation");
yAxis->GetTitleProperties()->SetColor(axisColor.GetData());
yAxis->GetTitleProperties()->SetFontSize(16);
yAxis->GetTitleProperties()->ItalicOn();
yAxis->GetLabelProperties()->SetColor(axisColor.GetData());
chart->SetTitle("Circulation 2008, 2009, 2010");
chart->GetTitleProperties()->SetFontSize(24);
chart->GetTitleProperties()->SetColor(titleColor.GetData());
chart->GetTitleProperties()->BoldOn();
// Create a table with some points in it...
vtkNew<vtkTable> table;
vtkNew<vtkIntArray> arrMonth;
arrMonth->SetName("Month");
table->AddColumn(arrMonth);
vtkNew<vtkIntArray> arr2008;
arr2008->SetName("2008");
table->AddColumn(arr2008);
vtkNew<vtkIntArray> arr2009;
arr2009->SetName("2009");
table->AddColumn(arr2009);
vtkNew<vtkIntArray> arr2010;
arr2010->SetName("2010");
table->AddColumn(arr2010);
table->SetNumberOfRows(12);
for (int i = 0; i < 12; i++)
{
table->SetValue(i, 0, i + 1);
table->SetValue(i, 1, data_2008[i]);
table->SetValue(i, 2, data_2009[i]);
table->SetValue(i, 3, data_2010[i]);
}
// Add multiple line plots, setting the colors etc
vtkPlot *line = 0;
line = chart->AddPlot(vtkChart::BAR);
line->SetColor(colorSeries->GetColor(0).GetRed() / 255.0,
colorSeries->GetColor(0).GetGreen() / 255.0,
colorSeries->GetColor(0).GetBlue() / 255.0);
line->SetInputData(table, 0, 1);
line = chart->AddPlot(vtkChart::BAR);
line->SetColor(colorSeries->GetColor(1).GetRed() / 255.0,
colorSeries->GetColor(1).GetGreen() / 255.0,
colorSeries->GetColor(1).GetBlue() / 255.0);
line->SetInputData(table, 0, 2);
line = chart->AddPlot(vtkChart::BAR);
line->SetColor(colorSeries->GetColor(2).GetRed() / 255.0,
colorSeries->GetColor(2).GetGreen() / 255.0,
colorSeries->GetColor(2).GetBlue() / 255.0);
line->SetInputData(table, 0, 3);
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetRenderWindow()->Render();
view->GetInteractor()->Initialize();
//view->GetInteractor()->Start();
}
๊ธฐ๋ณธ C++ ์์ ์ฝ๋๋ฅผ MFC Dialog ํ๋ก์ ํธ๋ก ๋ณ๊ฒฝํ ๊ฒ ๋ฐ์ ์์ผ๋ ๊ฐ๋จํ์ฃ ?
์์ธํ ๋ด์ฉ์ ์ฒจ๋ถ๋ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
'Programming > VTK' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[VTK] MFC์์ VTK ๋ง์ฐ์ค ์ผ์ชฝ ํด๋ฆญ ์ด๋ฒคํธ ๋ฐ ์ขํ ์ ๋ณด ์ป๊ธฐ (0) | 2019.07.01 |
---|---|
[VTK] MFC์์ VTK ScalrBar ์ฌ์ฉํ๊ธฐ (0) | 2019.06.12 |
[VTK] MFC์์ VTK 3D ๋ชจ๋ธ ํ์ผ ๋ถ๋ฌ์ Renderingํ๊ธฐ (3) | 2019.06.08 |
[VTK] MFC์์ VTK 2D Line Plot ์ฌ์ฉํ๊ธฐ (5) | 2019.05.30 |
[VTK] Visual Studio 2015 MFC์์ VTK ์ฌ์ฉ ์ค๋นํ๊ธฐ (9) | 2019.05.26 |
[VTK] VTK 8.2 ๋ฐ Visual Studio 2015 ํ๊ฒฝ ๊ตฌ์ฑ (22) | 2019.05.15 |
[VTK] VTK SDK ์๊ฐ (2) | 2019.05.13 |
๋๊ธ
์ด ๊ธ ๊ณต์ ํ๊ธฐ
-
๊ตฌ๋
ํ๊ธฐ
๊ตฌ๋ ํ๊ธฐ
-
์นด์นด์คํก
์นด์นด์คํก
-
๋ผ์ธ
๋ผ์ธ
-
ํธ์ํฐ
ํธ์ํฐ
-
Facebook
Facebook
-
์นด์นด์ค์คํ ๋ฆฌ
์นด์นด์ค์คํ ๋ฆฌ
-
๋ฐด๋
๋ฐด๋
-
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
-
Pocket
Pocket
-
Evernote
Evernote
๋ค๋ฅธ ๊ธ
-
[VTK] MFC์์ VTK 3D ๋ชจ๋ธ ํ์ผ ๋ถ๋ฌ์ Renderingํ๊ธฐ
[VTK] MFC์์ VTK 3D ๋ชจ๋ธ ํ์ผ ๋ถ๋ฌ์ Renderingํ๊ธฐ
2019.06.08 -
[VTK] MFC์์ VTK 2D Line Plot ์ฌ์ฉํ๊ธฐ
[VTK] MFC์์ VTK 2D Line Plot ์ฌ์ฉํ๊ธฐ
2019.05.30 -
[VTK] Visual Studio 2015 MFC์์ VTK ์ฌ์ฉ ์ค๋นํ๊ธฐ
[VTK] Visual Studio 2015 MFC์์ VTK ์ฌ์ฉ ์ค๋นํ๊ธฐ
2019.05.26 -
[VTK] VTK 8.2 ๋ฐ Visual Studio 2015 ํ๊ฒฝ ๊ตฌ์ฑ
[VTK] VTK 8.2 ๋ฐ Visual Studio 2015 ํ๊ฒฝ ๊ตฌ์ฑ
2019.05.15