[VTK] MFC์์ VTK 2D Line Plot ์ฌ์ฉํ๊ธฐ
์ง๋ ํฌ์คํ ์์๋ 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();
}
์์ธํ ๋ด์ฉ์ ์ฒจ๋ถ๋ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
'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 Bar ์ฐจํธ ์ฌ์ฉํ๊ธฐ (0) | 2019.05.28 |
[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 ScalrBar ์ฌ์ฉํ๊ธฐ
[VTK] MFC์์ VTK ScalrBar ์ฌ์ฉํ๊ธฐ
2019.06.12 -
[VTK] MFC์์ VTK 3D ๋ชจ๋ธ ํ์ผ ๋ถ๋ฌ์ Renderingํ๊ธฐ
[VTK] MFC์์ VTK 3D ๋ชจ๋ธ ํ์ผ ๋ถ๋ฌ์ Renderingํ๊ธฐ
2019.06.08 -
[VTK] MFC์์ VTK 2D Bar ์ฐจํธ ์ฌ์ฉํ๊ธฐ
[VTK] MFC์์ VTK 2D Bar ์ฐจํธ ์ฌ์ฉํ๊ธฐ
2019.05.28 -
[VTK] Visual Studio 2015 MFC์์ VTK ์ฌ์ฉ ์ค๋นํ๊ธฐ
[VTK] Visual Studio 2015 MFC์์ VTK ์ฌ์ฉ ์ค๋นํ๊ธฐ
2019.05.26