码迷,mamicode.com
首页 > 其他好文 > 详细

VTK初学一,线段的绘制c_Line

时间:2016-11-30 13:54:45      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:property   blog   map   tca   cell   ace   窗口   input   ram   

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

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

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

    anActor->GetProperty()->SetDiffuseColor(0,0,1);
    anActor->GetProperty()->SetLineWidth(5);
    anActor->GetProperty()->SetEdgeColor(1,1,1);
    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();
}


int main()
{
    //几何数据
    float pts[][3]={{0,0,0},{1,1,0}};
    vtkSmartPointer<vtkPoints> linePointes=vtkSmartPointer<vtkPoints>::New();
    linePointes->SetNumberOfPoints(2);
    linePointes->InsertPoint(0,pts[0]);
    linePointes->InsertPoint(1,pts[1]);
    //属性数据
    vtkSmartPointer<vtkFloatArray> lineScalars=vtkSmartPointer<vtkFloatArray>::New();
    lineScalars->SetNumberOfTuples(2);
    lineScalars->InsertValue(0,0);
    lineScalars->InsertValue(1,0);
    //拓扑结构
    vtkSmartPointer<vtkLine> aLine=vtkSmartPointer<vtkLine>::New();
    aLine->GetPointIds()->SetId(0,0);
    aLine->GetPointIds()->SetId(1,1);
    //将以上三部分数据组合成Grid
    vtkSmartPointer<vtkUnstructuredGrid> aLineGrid=vtkSmartPointer<vtkUnstructuredGrid>::New();
    aLineGrid->SetPoints(linePointes);
   aLineGrid->GetPointData()->SetScalars(lineScalars);
    aLineGrid->InsertNextCell(aLine->GetCellType(),aLine->GetPointIds());
/**********在窗口中显示该结构元****************************************、
    myShow(aLineGrid);
    return 0;
}

技术分享

 

VTK初学一,线段的绘制c_Line

标签:property   blog   map   tca   cell   ace   窗口   input   ram   

原文地址:http://www.cnblogs.com/phoenixdsg/p/6117282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!