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

 程序示例精选

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

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

前言

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


文章目录

        一、所需工具软件

        二、使用步骤

                1. 主要代码

                2. 运行结果

         三在线协助


一、所需工具软件

          1. Visual Studio以上

          2. VTK库

二、使用步骤

1.主要代码

代码如下(示例):

#include <vtkActor.h>
#include <vtkCommand.h>
#include <vtkContourWidget.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOrientedGlyphContourRepresentation.h>
#include <vtkPolyDataCollection.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolygonalSurfacePointPlacer.h>
#include <vtkProperty.h>

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<vtkContourWidget*>(caller);
			vtkContourRepresentation* rep = static_cast<vtkContourRepresentation*>(

		}

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

	private:
		vtkSmartPointer<vtkSphereSource> SphereSource;
	};

} // namespace

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

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

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

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

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

	vtkNew<vtkRenderWindowInteractor> interactor;
	interactor->SetRenderWindow(renderWindow);

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

	vtkNew<vtkContourWidget> contourWidget;
	contourWidget->SetInteractor(interactor);

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

	vtkNew<vtkPolygonalSurfacePointPlacer> 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.运行结果如下: 

 

 

三、在线协助: 

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

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

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
c语言下,vtk包含了多种函数库,方便用户进行3D图形的绘制。其中,vtkPlaneSource就是用来绘制平面的方法之一。 vtkPlaneSource生成一个由四边形构成的平面,可通过设置相关属性对其进行调整。通过vtkRenderer类渲染图形,方便地实现将图形输出到屏幕上,或作为其他应用程序的输入,例如3D建模软件等。 使用vtk绘制平面,可以用以下步骤: 1.包含vtk头文件 #include<vtkPlaneSource.h> #include<vtkSmartPointer.h> #include<vtkPolyDataMapper.h> #include<vtkActor.h> #include<vtkRenderer.h> #include<vtkRenderWindow.h> #include<vtkRenderWindowInteractor.h> 2.新建平面对象 vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New(); 3.设置平面属性 planeSource->SetXResolution(4); //设置X方向上四边形的数目 planeSource->SetYResolution(4); //设置Y方向上四边形的数目 planeSource->SetOrigin(-1, -1, 0);//设置平面的原 planeSource->SetPoint1(1, -1, 0);//设置平面的第一个端 planeSource->SetPoint2(-1, 1, 0);//设置平面的第二个端 4.创建Mapper vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(planeSource->GetOutputPort()); 5.创建Actor vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); 6.创建Renderer vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); renderer->AddActor(actor); 7.创建窗口 vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); renderWindow->SetSize(640, 480); 8.创建交互器 vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); interactor->SetRenderWindow(renderWindow); interactor->Initialize(); 9.开始绘制 renderWindow->Render(); interactor->Start(); 以上就是用vtk绘制平面的全过程,您可以根据实际需求设置平面的大小和位置等属性,使绘制的平面更加符合预期效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荷塘月色2

您的鼓励将是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值