zoukankan      html  css  js  c++  java
  • VTK初学一,e_Triangle_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 "vtkTriangle.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> 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> pointsScalars=vtkSmartPointer<vtkFloatArray>::New();
        pointsScalars->SetNumberOfTuples(3);
        pointsScalars->SetValue(0,0);
        pointsScalars->SetValue(1,1);
        pointsScalars->SetValue(2,0);
        //形成组元数据
        vtkSmartPointer<vtkCellArray> lines=vtkSmartPointer<vtkCellArray>::New();
        lines->InsertNextCell(4);
        lines->InsertCellPoint(0);
        lines->InsertCellPoint(1);
        lines->InsertCellPoint(2);
        lines->InsertCellPoint(0);
        //几何轮廓
        vtkSmartPointer<vtkPolyData> profile=vtkSmartPointer<vtkPolyData>::New();
        profile->SetPoints(trianglePoints);
        profile->SetLines(lines);
        profile->GetPointData()->SetScalars(pointsScalars);
        myShow(profile);
        return 0;
    }

    
    
  • 相关阅读:
    个人工作量
    个人作业
    本周psp
    典型用户和场景总结
    排球比赛计分规则功能说明书
    我与计算机
    个人作业
    《怎样成为一个高手》读后感
    第十八周个人作业
    第十六周 项目耗时记录
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6116452.html
Copyright © 2011-2022 走看看