C++ VTK鼠标网格表面绘制曲线

 程序示例精选

C++ VTK鼠标表面绘制曲线

如需安装运行环境或远程调试,见文章底部微信名片,由专业技术人员远程协助!

前言

C++ VTK鼠标表面绘制曲线,功能完善,代码整洁,规则,易读。


文章目录

        一、所需工具软件

        二、使用步骤

                1. 主要代码

                2. 运行结果

         三在线协助


一、所需工具软件

          1. Visual Studio以上

          2. VTK库

二、使用步骤

1.主要代码

代码如下(示例):

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

namespace {

	class MyCallback : public vtkCommand
	{
	public:
		static MyCallback* New()
		{
			return new MyCallback;
		}
		MyCallback()
		{
		}

		virtual void Execute(vtkObject* caller, unsigned long, void*)
		{
			vtkContourWidget* contourWidget =
				reinterpret_cast(caller);
			vtkContourRepresentation* rep = static_cast(

		}

		void SetSphereSource(vtkSmartPointer sphere)
		{
			this->SphereSource = sphere;
		}

	private:
		vtkSmartPointer SphereSource;
	};

} // namespace

int main(int, char*[])
{
	vtkNew colors;

	vtkNew sphereSource;
	sphereSource->SetRadius(5);
	sphereSource->Update();

	vtkNew mapper;
	mapper->SetInputConnection(sphereSource->GetOutputPort());

	vtkNew actor;
	actor->SetMapper(mapper);
	actor->GetProperty()->SetColor(colors->GetColor3d("MistyRose").GetData());

	// Create the RenderWindow, Renderer
	vtkNew renderer;
	vtkNew renderWindow;
	renderWindow->AddRenderer(renderer);
	renderWindow->SetWindowName("PolygonalSurfacePointPlacer");

	vtkNew interactor;
	interactor->SetRenderWindow(renderWindow);

	renderer->AddActor(actor);
	renderer->SetBackground(colors->GetColor3d("CadetBlue").GetData());

	vtkNew contourWidget;
	contourWidget->SetInteractor(interactor);

	vtkOrientedGlyphContourRepresentation* rep =
		dynamic_cast(
			contourWidget->GetRepresentation());

	vtkNew pointPlacer;
	pointPlacer->AddProp(actor);
	pointPlacer->GetPolys()->AddItem(sphereSource->GetOutput());

	rep->GetLinesProperty()->SetColor(colors->GetColor3d("Crimson").GetData());
	rep->GetLinesProperty()->SetLineWidth(3.0);
	rep->SetPointPlacer(pointPlacer);

	contourWidget->EnabledOn();
	renderer->ResetCamera();
	renderWindow->Render();

	interactor->Start();

	return EXIT_SUCCESS;
}

4.运行结果如下: 

 C++ VTK鼠标网格表面绘制曲线_第1张图片

 

三、在线协助: 

如需安装运行环境或远程调试,见文章底部微信名片,由专业技术人员远程协助!

我的主页:https://blog.csdn.net/alicema1111?type=blog

你可能感兴趣的:(C++,VTK,开发语言,c++,VTK,visual,studio,VS)