#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 "vtkVertex.h"
#include "vtkPolyVertex.h"
#include "vtkInteractorStyleTrackballCamera.h"

void myShow(vtkSmartPointer<vtkUnstructuredGrid> aGrid);

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<vtkFloatArray>pointsScalars=vtkSmartPointer<vtkFloatArray>::New();
    pointsScalars->SetNumberOfTuples(5);//此行可有可无
    pointsScalars->InsertValue(0,0);//第1个参数是points点的Id,第2个参数是该点的属性值
    pointsScalars->InsertValue(1,0);//第1个参数是points点的Id,第2个参数是该点的属性值
    pointsScalars->InsertValue(2,0);//第1个参数是points点的Id,第2个参数是该点的属性值
    pointsScalars->InsertValue(3,0);//第1个参数是points点的Id,第2个参数是该点的属性值
    pointsScalars->InsertValue(4,0);//第1个参数是points点的Id,第2个参数是该点的属性值
    //将以上三部分数据组合成一个结构vtkUnstructureGrid
    vtkSmartPointer<vtkUnstructuredGrid> aGrid=vtkSmartPointer<vtkUnstructuredGrid>::New();
    aGrid->Allocate(1,1);
    aGrid->SetPoints(points);
    aGrid->GetPointData()->SetScalars(pointsScalars);
    aGrid->InsertNextCell(polyVertex->GetCellType(),polyVertex->GetPointIds());
    //在窗口中显示多个Vertex
    myShow(aGrid);
    return 0;
}

void myShow(vtkSmartPointer<vtkUnstructuredGrid> aGrid)
{
    //设置映射器
    vtkSmartPointer<vtkDataSetMapper> aMapper=vtkSmartPointer<vtkDataSetMapper>::New();
    aMapper->SetInputData(aGrid);
    aMapper->ScalarVisibilityOn();

    vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
    anActor->SetMapper(aMapper);
    anActor->GetProperty()->SetRepresentationToPoints();

    anActor->GetProperty()->SetDiffuseColor(1,0,0);
    anActor->GetProperty()->SetPointSize(10);
 //创建显示窗口
    vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
    ren1->AddActor(anActor);
    renWin->AddRenderer(ren1);

    vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
    vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
    iren->SetInteractorStyle(style);
    iren->SetRenderWindow(renWin);

    renWin->SetSize(700,700);
    ren1->ResetCamera();
    renWin->Render();
    iren->Start();
}

												

VTK初学一,b_PolyVertex多个图形点的绘制的更多相关文章

  1. VTK初学一,b_PolyVertex_CellArray多个点的绘制

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

  2. 借助Photoshop,Illustrator等设计软件进行WPF图形图像的绘制

    原文:借助Photoshop,Illustrator等设计软件进行WPF图形图像的绘制 本文所示例子是借助第三方设计软件,制作复杂的矢量图形,转成与XAML酷似的SVG,再转换成xaml而实现的. 这 ...

  3. VTK初学一,a_Vertex图形点的绘制

    系统:Win8.1 QT版本:2.4.2,Mingw VTK版本:6.3 2. main.cpp #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #incl ...

  4. VTK初学一,比较常见的错误2

    我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6 ...

  5. VTK初学一,c_Line_CellArray线段的CellArray绘制

    VTK窗口默认坐标方向: #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE ...

  6. VTK初学一,动画加AVI录制终于做出来了

      #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRe ...

  7. VTK初学一,vtkDelaunay2D创建球冠曲面

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

  8. VTK初学一,比较常见的错误1

      错误原因: 通常是在文件头部没有初始化 #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> V ...

  9. VTK初学一,a Mesh from vtkImageData—球冠

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

随机推荐

  1. linux ipv6临时地址

    在Ubuntu系统上想要通过ipv6来上网,结果发现通过DHCP获取到了ipv6地址却无法连接外网. ping6 ipv6.google.com 数据包有去无回,100% loss . 奇怪的是通过D ...

  2. [NOIP2013] 普及组

    计数问题 纯模拟 #include<cstdio> #include<iostream> using namespace std; int main(){ int n,x; c ...

  3. Linux WebServer WebRoot Path Identification

    目录 . HTTPD(Apache) . NGINX . TENGINE . JBOSS . TOMCAT . LIGHTTPD 1. HTTPD(Apache) 0x1: 启动参数 Usage: . ...

  4. [iOS Keychain本地长期键值存储]

    目前本地存储方式大致有:Sqlite,Coredata,NSUserdefaults.但他们都是在删除APP后就会被删除,如果长期使用存储,可以使用Keychain钥匙串来实现. CHKeychain ...

  5. 基本概率分布Basic Concept of Probability Distributions 5: Hypergemometric Distribution

    PDF version PMF Suppose that a sample of size $n$ is to be chosen randomly (without replacement) fro ...

  6. Bumped Map And Normal Map

    http://freespace.virgin.net/hugo.elias/graphics/x_polybm.htm 先留着,准备以后开垦

  7. SaltStack与ZeroMQ(二)

    SaltStack与ZeroMQ SaltStack底层是基于ZeroMQ进行高效的网络通信. ZeroMQ简介 ØMQ (也拼写作ZeroMQ,0MQ或ZMQ)是一个为可伸缩的分布式或并发应用程序设 ...

  8. spring-data-jpa Repository的基本知识

    1.项目中的Repository对象的使用 2.Repository 引入的两种方式 继承和使用注解 3.Repository接口的定义 Repository 接口是 spring Data 的一个核 ...

  9. 延时Led灯

    1.代码:#include <reg52.h>typedef unsigned int  u16;typedef unsigned char u8;sbit led = P1^0;void ...

  10. LDA(转发)

    主题模型-LDA浅析 分类: 数据挖掘 机器学习2012-09-03 14:09 24937人阅读 评论(16) 收藏 举报 文档allocationsemanticeach算法网络 上个月参加了在北 ...