zoukankan      html  css  js  c++  java
  • VTK初学一,e_Triangle三角形的绘制

    #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 "vtkTriangle.h"
    #include <vtkInteractorStyleTrackballCamera.h>
    void myShow(vtkUnstructuredGrid* aGrid)
    {
        vtkSmartPointer<vtkDataSetMapper> aMapper=vtkSmartPointer<vtkDataSetMapper>::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);
    
    
        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> trianglePoints=vtkSmartPointer<vtkPoints>::New();
        trianglePoints->SetNumberOfPoints(3);
        trianglePoints->InsertPoint(0,0,0,0);
        trianglePoints->InsertPoint(1,1,0,0);
        trianglePoints->InsertPoint(2,1,1,1);
        //属性数据
        vtkSmartPointer<vtkFloatArray> triangleScalars=vtkSmartPointer<vtkFloatArray>::New();
        triangleScalars->SetNumberOfTuples(3);
        triangleScalars->InsertValue(0,0);
        triangleScalars->InsertValue(1,0);
        triangleScalars->InsertValue(2,1);
        //拓扑结构
        vtkSmartPointer<vtkTriangle> aTriangle=vtkSmartPointer<vtkTriangle>::New();
        aTriangle->GetPointIds()->SetNumberOfIds(3);
        aTriangle->GetPointIds()->SetId(0,0);
        aTriangle->GetPointIds()->SetId(1,1);
        aTriangle->GetPointIds()->SetId(2,2);
        //将以上三部分组装成一个结构
        vtkSmartPointer<vtkUnstructuredGrid> aTriangleGrid=vtkSmartPointer<vtkUnstructuredGrid>::New();
        aTriangleGrid->Allocate(1,1);
        aTriangleGrid->SetPoints(trianglePoints);
        aTriangleGrid->GetPointData()->SetScalars(triangleScalars);
        aTriangleGrid->InsertNextCell(aTriangle->GetCellType(),aTriangle->GetPointIds());
        //显示triangle
        myShow(aTriangleGrid);
        return 0;
    }

    
    
  • 相关阅读:
    利用GitHub和Hexo打造免费的个人博客 coder
    Android基础——项目的文件结构(二) coder
    25个Android酷炫开源UI框架 coder
    MarkDown使用教程(In Atom) coder
    Android基础——项目的文件结构(一) coder
    25类Android常用开源框架 coder
    Android Activity启动黑/白屏原因与解决方式 coder
    我的window phone 开发第一步
    Entity Framework 4 In Action 读书笔记
    最近在制作一套ASP.NET控件,已初见雏形
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6116440.html
Copyright © 2011-2022 走看看