vtk 模型建立 基础入门

 vtk 模型建立 基础入门_第1张图片

 

#include 
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


#include
using namespace std;


int main() {

	vtkSmartPointer points = vtkSmartPointer::New();
	vtkSmartPointer lines = vtkSmartPointer::New();
	vtkSmartPointer profile = vtkSmartPointer::New();

	points->InsertNextPoint(0,0,0);
	points->InsertNextPoint(0,2,0);
	points->InsertNextPoint(2,4,0);
	points->InsertNextPoint(4,4,0);

	lines->InsertNextCell(4);
	lines->InsertCellPoint(0);
	lines->InsertCellPoint(1);
	lines->InsertCellPoint(2);
	lines->InsertCellPoint(3);

	profile->SetLines(lines);
	profile->SetPoints(points);

	//tube
	vtkSmartPointer tube = vtkSmartPointer::New();
	tube->SetInputData(profile);
	tube->SetRadius(.5);
	tube->SetNumberOfSides(12);


	vtkSmartPointer mapper = vtkSmartPointer::New();
	mapper->SetInputData(profile);
	vtkSmartPointer actor = vtkSmartPointer::New();
	actor->SetMapper(mapper);

	
	vtkSmartPointer tubeMapper = vtkSmartPointer::New();
	tubeMapper->SetInputConnection(tube->GetOutputPort());
	vtkSmartPointer tubeActor = vtkSmartPointer::New();
	tubeActor->SetMapper(tubeMapper);


	//Implicit Modeller

	vtkSmartPointer< vtkImplicitModeller> imp = vtkSmartPointer< vtkImplicitModeller>::New();
	imp->SetInputData(profile);
	imp->SetSampleDimensions(100,100,100);
	imp->SetMaximumDistance(0.25);
	imp->SetModelBounds(-10,10, -10, 10, - 10, 10);
	vtkSmartPointer contour = vtkSmartPointer::New();
	contour->SetInputConnection(imp->GetOutputPort());
	contour->SetValue(0,0.5);

	vtkSmartPointer conMapper = vtkSmartPointer::New();
	conMapper->SetInputConnection(contour->GetOutputPort());
	vtkSmartPointer contourActor = vtkSmartPointer::New();
	contourActor->SetMapper(conMapper);
	contourActor->SetPosition(5,0,0);

	vtkSmartPointer renWin = vtkSmartPointer::New();
	vtkSmartPointer renderer = vtkSmartPointer::New();
	vtkSmartPointer interactor = vtkSmartPointer::New();





	renWin->AddRenderer(renderer);
	renderer->SetBackground(0.5, 0.3, 0.4);
    renderer->AddActor(actor);
	renderer->AddActor(tubeActor);
	renderer->AddActor(contourActor);

	
	renWin->SetSize(840, 880);
	renWin->Render();

	interactor->SetRenderWindow(renWin);
	interactor->Initialize();
	interactor->Start();

	return 0;
}

你可能感兴趣的:(VTK,&,ITK,图像处理)