vtk 根據3點座標創建三角平面

#include <vtkProperty.h>
#include <vtkAutoInit.h>
#include <vtkObject.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#include <QDebug>
#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkLight.h>
#include <vtkCamera.h>
#include <vtkActor2D.h>
#include <vtkRendererCollection.h>

using namespace std;

int main(int argc, char *argv[])
{
    vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();

    vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    vtkSmartPointer<vtkCellArray> cellArray = vtkSmartPointer<vtkCellArray>::New();

    vtkSmartPointer<vtkPolyDataMapper> planeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    vtkSmartPointer<vtkActor> planeActor = vtkSmartPointer<vtkActor>::New();

    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer( renderer );

    //-----------start create plane------------------
    points->InsertPoint(0, 0, 0, 0);
    points->InsertPoint(1, 1, 0, 0);
    points->InsertPoint(2, 0, 1, 0);
    polyData->SetPoints( points );
    vtkIdType cellId1[3] = { 0, 1, 2 };
    //Create a cell by specifying the number of points and an array of pointid's.  Return the cell id of the cell.
    cellArray->InsertNextCell(3, cellId1);
    polyData->SetPolys( cellArray );
    planeMapper->SetInputData( polyData );
    planeActor->SetMapper( planeMapper );
    planeActor->GetProperty()->SetColor( 1,0,0 );

    renderer->AddActor( planeActor );
    //-----------create plane finished------------------

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
            vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow( renderWindow );

    renderer->GetActiveCamera()->ParallelProjectionOn();
    renderer->ResetCamera();
    renderWindow->Render();
    renderWindowInteractor->Start();

    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章