zoukankan      html  css  js  c++  java
  • VTK初学一,b_PolyVertex_CellArray多个点的绘制

    #ifndef INITIAL_OPENGL
    #define INITIAL_OPENGL
    #include <vtkAutoInit.h>
    VTK_MODULE_INIT(vtkRenderingOpenGL)
    VTK_MODULE_INIT(vtkInteractionStyle)
    #endif
    
    
    #include <iostream>
    using namespace std;
    #include "vtkPolyDataMapper.h"
    #include "vtkWin32OpenGLRenderWindow.h"
    #include "vtkRenderWindow.h"
    #include "vtkRenderWindowInteractor.h"
    #include "vtkRenderer.h"
    #include "vtkPoints.h"
    #include "vtkWin32RenderWindowInteractor.h"
    #include "vtkProperty.h"
    #include "vtkFloatArray.h"
    #include "vtkPolyData.h"
    #include "vtkDataSetMapper.h"
    #include "vtkActor2D.h"
    #include "vtkContourFilter.h"
    #include "vtkContourValues.h"
    #include "vtkUnstructuredGrid.h"
    #include "vtkPointData.h"
    #include "vtkPolyVertex.h"
    #include <vtkInteractorStyleTrackballCamera.h>
    #include <vtkCellArray.h>
    void myShow(vtkPolyData* aGrid)
    {
        vtkSmartPointer<vtkPolyDataMapper> aMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
        aMapper->SetInputData(aGrid);
        aMapper->ScalarVisibilityOn();
    
    
        vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
        anActor->SetMapper(aMapper);
        anActor->GetProperty()->SetRepresentationToWireframe();
        anActor->GetProperty()->SetDiffuseColor(1,1,1);
        anActor->GetProperty()->SetLineWidth(10);
        anActor->GetProperty()->SetPointSize(30);
    
    
        vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
        vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
        ren1->AddActor(anActor);
        ren1->ResetCamera();
        renWin->AddRenderer(ren1);
        renWin->SetSize(512,512);
    
    
    
    
        vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
        vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
        iren->SetRenderWindow(renWin);
        iren->SetInteractorStyle(style);
        iren->Start();
    }
    int main()
    {
        //几何数据
        vtkSmartPointer<vtkPoints> points=vtkSmartPointer<vtkPoints>::New();
        points->SetNumberOfPoints(5);
        points->InsertPoint(0,0,0,0);
        points->InsertPoint(1,0.5,0.5,0);
        points->InsertPoint(2,-0.3,-0.2,0);
        points->InsertPoint(3,0.8,-0.5,0);
        points->InsertPoint(4,1,0.5,0.3);
        //拓扑结构数据
        vtkSmartPointer<vtkPolyVertex> polyVertex=vtkSmartPointer<vtkPolyVertex>::New();
        polyVertex->GetPointIds()->SetNumberOfIds(5);//必须设置Id个数,否则可以编译,不能运行
        polyVertex->GetPointIds()->SetId(0,0);//第一个参数是几何point的ID号,第2个参数是拓扑中的Id号
        polyVertex->GetPointIds()->SetId(1,1);
        polyVertex->GetPointIds()->SetId(2,2);
        polyVertex->GetPointIds()->SetId(3,3);
        polyVertex->GetPointIds()->SetId(4,4);
    
    
        //以上数据形成单元数组
        vtkSmartPointer<vtkCellArray> vertexCells=vtkSmartPointer<vtkCellArray>::New();
        vertexCells->InsertNextCell(polyVertex);
        //点的属性数据
        vtkSmartPointer<vtkFloatArray> pointsScalars=vtkSmartPointer<vtkFloatArray>::New();
        pointsScalars->SetNumberOfTuples(5);
        pointsScalars->SetValue(0,0);
        pointsScalars->SetValue(1,1);
        pointsScalars->SetValue(2,0);
        pointsScalars->SetValue(3,0);
        pointsScalars->SetValue(4,0);
        //以上数据组装成PolyData
        vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
        polydata->SetPoints(points);
        polydata->SetVerts(vertexCells);
        polydata->GetPointData()->SetScalars(pointsScalars);
        //在窗口中显示
        myShow(polydata);
        return 0;
    }

    
    
    
    
    
    
  • 相关阅读:
    从零开始入门 K8s| 详解 Pod 及容器设计模式
    从零开始入门 K8s| 阿里技术专家详解 K8s 核心概念
    时间和空间的完美统一!阿里云时空数据库正式商业化
    SaaS加速器,到底加速了谁? 剖析阿里云的SaaS战略:企业和ISV不可错过的好文
    来杭州云栖大会,全面了解企业如何实现云上IT治理
    DataV教你如何给可视化应用一键美颜
    Serverless Kubernetes全面升级2.0架构:支持多命名空间、RBAC、CRD、PV/PVC等功能
    基于 APIGateway 打造生产级别的 Knative 服务
    P1434 滑雪
    P1613 跑路
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6116628.html
Copyright © 2011-2022 走看看