スポンサーリンク
//VTK_MODULE_INITに必要 #include <vtkAutoInit.h> #include <vtkSmartPointer.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkPoints.h> // vtkPoints用 #include <vtkPolygon.h> // vtkPolygon用 #include <vtkPolyData.h> //vtkPolyData用 #include <vtkPolyDataMapper.h> #pragma comment(lib,"vtkCommonCore-9.0.lib") #pragma comment(lib,"vtkRenderingCore-9.0.lib") #pragma comment(lib,"vtkInteractionStyle-9.0.lib") #pragma comment(lib,"vtkFiltersSources-9.0.lib") #pragma comment(lib,"vtkCommonExecutionModel-9.0.lib") #pragma comment(lib,"vtkCommonDataModel-9.0.lib ") // ポリゴン用 //必須 #pragma comment(lib,"vtkRenderingOpenGL2-9.0.lib") //必須 VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); int main(int /*argc*/, char ** /*argv*/) { ////////////////////////////////////// vtkSmartPointer < vtkPoints > points = vtkSmartPointer < vtkPoints >::New(); points->InsertNextPoint(0.0, 0.0, 0.0); points->InsertNextPoint(1.0, 0.0, 0.0); points->InsertNextPoint(1.0, 1.0, 0.0); points->InsertNextPoint(0.0, 0.4, 0.0); ////////////////////////////////////// vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New(); polygon->GetPointIds()->SetNumberOfIds(4);//4頂点 polygon->GetPointIds()->SetId(0, 0); polygon->GetPointIds()->SetId(1, 1); polygon->GetPointIds()->SetId(2, 2); polygon->GetPointIds()->SetId(3, 3); ////////////////////////////////////// vtkSmartPointer<vtkCellArray> polylist = vtkSmartPointer<vtkCellArray>::New(); polylist->InsertNextCell(polygon); ////////////////////////////////////// vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New(); polydata->SetPoints(points); polydata->SetPolys(polylist); ////////////////////////////////////// // Create a mapper and actor vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); //mapper->SetInputConnection(cylinderSource->GetOutputPort()); mapper->SetInputData(polydata); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); ////////////////////////////////////// auto renderer = vtkSmartPointer<vtkRenderer>::New(); renderer->AddActor(actor); renderer->ResetCamera(); ////////////////////////////////////// auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); //vtkInteractorStyleTrackballCamera ////////////////////////////////////// auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); renderWindow->SetInteractor(interactor); renderWindow->Render(); interactor->Start(); //イベントループへ入る return 0; }