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

VTK窗口默认坐标方向:

#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 "vtkLine.h"
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCellArray.h>

void myShow(vtkPolyData* polydata)
{
    //设置映射器
    vtkSmartPointer<vtkPolyDataMapper> amapper=vtkSmartPointer<vtkPolyDataMapper>::New();
    amapper->SetInputData(polydata);
//    amapper->SetScalarVisibility(0);
    amapper->ScalarVisibilityOn();
    //声明一个演员
    vtkSmartPointer<vtkActor> anActor=vtkSmartPointer<vtkActor>::New();
    anActor->SetMapper(amapper);
    anActor->GetProperty()->SetRepresentationToWireframe();
    anActor->GetProperty()->SetDiffuseColor(0,0,1);
    anActor->GetProperty()->SetLineWidth(5);
    anActor->GetProperty()->SetPointSize(10);
     //创建显示窗口
    vtkSmartPointer<vtkRenderer> ren1=vtkSmartPointer<vtkRenderer>::New();
    ren1->AddActor(anActor);
    vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
    renWin->AddRenderer(ren1);
    vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
    iren->SetRenderWindow(renWin);
    vtkSmartPointer<vtkInteractorStyleTrackballCamera>style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
    iren->SetInteractorStyle(style);

    renWin->SetSize(512,512);
    ren1->ResetCamera();
    iren->Start();

}

int main()
{
    //几何数据
    float pts[][3]={{0,0,0},{1,1,0}};
    vtkSmartPointer<vtkPoints> Pointes=vtkSmartPointer<vtkPoints>::New();
    Pointes->SetNumberOfPoints(2);
    Pointes->InsertPoint(0,pts[0]);
    Pointes->InsertPoint(1,pts[1]);
    //属性数据
    vtkSmartPointer<vtkFloatArray> lineScalars=vtkSmartPointer<vtkFloatArray>::New();
    lineScalars->SetNumberOfTuples(2);
    lineScalars->InsertValue(0,0);
    lineScalars->InsertValue(1,1);
    //拓扑结构
    vtkSmartPointer<vtkLine> aLine=vtkSmartPointer<vtkLine>::New();
    aLine->GetPointIds()->SetNumberOfIds(2);
    aLine->GetPointIds()->SetId(0,0);
    aLine->GetPointIds()->SetId(1,1);
    //创建单元数组
    vtkSmartPointer<vtkCellArray> lineCells=vtkSmartPointer<vtkCellArray>::New();
    lineCells->InsertNextCell(aLine);
    //将以上数据组合成一个vtkPolyData
    vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
    polydata->SetPoints(Pointes);
    polydata->SetLines(lineCells);
    polydata->GetPointData()->SetScalars(lineScalars);
/**********在窗口中显示该结构元****************************************/
        myShow(polydata);
    return 0;
}

				
时间: 2024-10-03 05:07:59

VTK初学一,线段的CellArray绘制c_Line_CellArray的相关文章

VTK初学一,线段的绘制c_Line

#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 &

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

我的开发环境: 系统:win8.1 QT:5.4.2MinGW版 VTK:6.3 按照教程生成一个球体显示在,Qt的QVTKWidget控件中,出现如下ERROR: ERROR: In D:\VTK6.3\VTK-src\Rendering\Core\vtkTextActor.cxx, line 110vtkTextActor (0509BA90): Failed getting the TextRenderer instance! 解决办法: 在头文件中加入VTK_MODULE_INIT(vt

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

#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL) VTK_MODULE_INIT(vtkInteractionStyle) #endif #include <iostream> using namespace std; #include <vtkVersion.h> #include <vtkPolyD

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

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

VTK初学一,a Mesh from vtkImageData

#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL) VTK_MODULE_INIT(vtkInteractionStyle) #endif #include <iostream> using namespace std; #include <vtkVersion.h> #include <vtkPolyD

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

#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 &

pcl-设置多线段宽度和颜色

显示点云有使用vtk的,有使用 ros 中riz ?库的,使用pcl显示点云数据比较方便,但是对于一些模型形状只能固定特定的效果,比如说直线段,只能绘制点到点两点之间的线段.但是项目需要绘制点1到点2到...点n多条线段的连接,并且绘制设置线段宽度. 步骤: 1.把 vtkRenderWindowInteractorFix.cpp vtkRenderWindowInteractorFix.h pcl_visualizer.h pcl_visualizer.cpp shapes.h shapes.

Opengl绘制计算几何库CGAL三角剖分结果的Demo

Ubuntu下改编了一个用CGAL计算输入点的三角剖分,并用OpenGL显示结果的C++程序. 该Demo可作为一个计算几何及绘图的框架. 代码如下: //编译命令:g++ spatial_sort.cpp -lglut -lGL -lGLU -lCGAL -lCGAL_Core -lgmp #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>   #include <CGAL/Triangulation_eucl

OPENGL初学

一.部分常用的实体绘制函数部分常用的实体绘制函数: //以下所有函数中,radius表示球体的半径,slices表示球体纵向分割的数目(经线),主要是设置绘制的细密度,stacks表示球体横向分割的数目(纬线),创建了绘制中心在模型坐标原点,半径为radius的球体 void glutWireSphere(GLdouble radius, GLint slices, GLint stacks); //网状球 void glutSolidSphere(GLdouble radius, GLint