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

简介: C++ VTK鼠标网格表面绘制曲线
程序示例精选
C++ VTK鼠标网格表面绘制曲线
如需安装运行环境或远程调试,可点击
博主头像进入个人主页查看博主联系方式,由专业技术人员远程协助!

前言

这篇博客针对《C++ VTK鼠标网格表面绘制曲线》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。

运行结果

文章目录

一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果

三、在线协助

一、所需工具软件

1. VS2019, C++
2. VTK

二、使用步骤

代码如下(示例):


#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;
}

运行结果

三、在线协助:

如需安装运行环境或远程调试,可点击博主头像,进入个人主页查看博主联系方式,由专业技术人员远程协助!

1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作

博主个人主页:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc
博主所有文章点这里:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc
博主联系方式点这里:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc
相关文章
|
11月前
|
算法 C++
|
1月前
|
数据可视化 开发者 C++
Qt(C++)使用QChart静态显示3个设备的温度变化曲线
QChart模块是Qt Charts库的基础,提供了用于创建和显示各种类型图表的类和接口。Qt Charts库是一个功能丰富、易于使用的数据可视化工具库,可以帮助开发者在应用程序中添加漂亮而又交互性强的图表。
34 1
Qt(C++)使用QChart静态显示3个设备的温度变化曲线
|
1月前
|
存储 JSON 数据可视化
Qt(C++)使用QChart动态显示3个设备的温度变化曲线
Qt的QChart是一个用于绘制图表和可视化数据的类。提供了一个灵活的、可扩展的、跨平台的图表绘制解决方案,可以用于各种应用程序,如数据分析、科学计算、金融交易等。
109 1
|
API C++ 计算机视觉
【opencv3】鼠标框选矩形并显示当前像素点坐标和矩形中心点坐标C++
【opencv3】鼠标框选矩形并显示当前像素点坐标和矩形中心点坐标C++
|
小程序 C++
【一个整蛊人的小程序】c++,鼠标控制
【一个整蛊人的小程序】c++,鼠标控制