๋ฐ˜์‘ํ˜•

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” VTK Window์— ScalarBar๋ฅผ ๋„์šฐ๋Š” ์˜ˆ์ œ๋ฅผ ์†Œ๊ฐœํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.


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

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


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

<MFC ScalarBar ์˜ˆ์ œ>


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

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


ScalarBar๋Š” Point Cloud Data์˜ Z์ถ• ๋†’์ด ๋ฒ”์œ„์— ๋”ฐ๋ผ ์ƒ‰์ƒ์„ ์ž…ํž ๋•Œ, ๋†’์ด์˜ ๋ฒ”์œ„๋ฅผ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.


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

๋จผ์ € 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 <vtkActor.h>
#include <vtkFloatArray.h>
#include <vtkLookupTable.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkScalarBarActor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkColorSeries.h>
#include <vtkNamedColors.h>


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

<Header File>


public :
	vtkNew<vtkRenderWindow> m_vtkRenderWindow;

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

<Source File>

void CExampleBarChartDlg::InitializeVTKWindow(void* hWnd)
{
	vtkNewGetClientRect(rc);
	m_vtkRenderWindow->SetSize(rc.Width(), rc.Height());
}


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

void CExampleScalarBarDlg::OnBnClickedBtnInitScalar()
{
	vtkNew<vtkNamedColors> colors;

	// Create a sphere fora some geometry
	vtkNew<vtkSphereSource> sphere;
	sphere->SetCenter(0, 0, 0);
	sphere->SetRadius(1);
	sphere->SetPhiResolution(30);
	sphere->SetThetaResolution(60);
	sphere->Update();

	// Create scalar data to associate with the vertices of the sphere
	int numPts = sphere->GetOutput()->GetPoints()->GetNumberOfPoints();
	vtkNew<vtkFloatArray> scalars;
	scalars->SetNumberOfValues(numPts);
	for (int i = 0; i < numPts; ++i)
	{
		scalars->SetValue(i, static_cast<float>(i) / numPts);
	}
	vtkNew<vtkPolyData> poly;
	poly->DeepCopy(sphere->GetOutput());
	poly->GetPointData()->SetScalars(scalars);

	vtkNew<vtkPolyDataMapper> mapper;
	mapper->SetInputData(poly);
	mapper->ScalarVisibilityOn();
	mapper->SetScalarModeToUsePointData();
	mapper->SetColorModeToMapScalars();

	vtkNew<vtkActor> actor;
	actor->SetMapper(mapper);
	actor->GetProperty()->SetInterpolationToFlat();

	vtkNew<vtkScalarBarActor> scalarBar;
	scalarBar->SetLookupTable(mapper->GetLookupTable());
	scalarBar->SetTitle("Beachball");
	scalarBar->SetNumberOfLabels(4);

	// Create a lookup table to share between the mapper and the scalarbar
	vtkNew<vtkLookupTable> seriesLut;

	vtkNew<vtkColorSeries> series;
	int seriesEnum = series->BREWER_QUALITATIVE_SET3;
	series->SetColorScheme(seriesEnum);
	series->BuildLookupTable(seriesLut, series->ORDINAL);

	mapper->SetLookupTable(seriesLut);
	scalarBar->SetLookupTable(seriesLut);

	// Create an interactor
	vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
	renderWindowInteractor->SetRenderWindow(m_vtkRenderWindow);

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

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

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



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

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

ExampleScalarBar.zip

๋ฐ˜์‘ํ˜•