#include #include "vtkPolyData.h" #include "vtkPoints.h" #include "vtkCellArray.h" #include "vtkTriangle.h" void Works(); void DoesntWork(); int main() { Works(); DoesntWork(); return 0; } void Works() { std::cout << std::endl << "Works()" << std::endl; vtkPolyData* polydata = vtkPolyData::New(); vtkPoints* points3D = vtkPoints::New(); for(unsigned int i = 0; i < 10; i++) { points3D->InsertNextPoint(drand48(),drand48(),drand48()); } polydata->SetPoints(points3D); // add triangles vtkCellArray* triangles = vtkCellArray::New(); vtkTriangle* triangle1 = vtkTriangle::New(); triangle1->GetPointIds()->SetId(0,0); triangle1->GetPointIds()->SetId(1,1); triangle1->GetPointIds()->SetId(2,2); triangles->InsertNextCell(triangle1); vtkTriangle* triangle2 = vtkTriangle::New(); triangle2->GetPointIds()->SetId(0,0); triangle2->GetPointIds()->SetId(1,1); triangle2->GetPointIds()->SetId(2,2); triangles->InsertNextCell(triangle2); polydata->SetPolys(triangles); ////////////// vtkTriangle* Tri = vtkTriangle::SafeDownCast(polydata->GetCell(0)); vtkPoints* TriPoints = Tri->GetPoints(); double p0[3]; double p1[3]; double p2[3]; TriPoints->GetPoint(0, p0); TriPoints->GetPoint(1, p1); TriPoints->GetPoint(2, p2); std::cout << "TriPoint[0] = " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; std::cout << "TriPoint[1] = " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; std::cout << "TriPoint[2] = " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; } void DoesntWork() { std::cout << std::endl << "DoesntWork()" << std::endl; vtkPolyData* polydata = vtkPolyData::New(); vtkPoints* points3D = vtkPoints::New(); for(unsigned int i = 0; i < 10; i++) { points3D->InsertNextPoint(drand48(),drand48(),drand48()); } polydata->SetPoints(points3D); // add triangles vtkCellArray* triangles = vtkCellArray::New(); vtkTriangle* triangle1 = vtkTriangle::New(); triangle1->GetPointIds()->SetId(0,0); triangle1->GetPointIds()->SetId(1,1); triangle1->GetPointIds()->SetId(2,2); triangles->InsertNextCell(triangle1); vtkTriangle* triangle2 = vtkTriangle::New(); triangle2->GetPointIds()->SetId(0,0); triangle2->GetPointIds()->SetId(1,1); triangle2->GetPointIds()->SetId(2,2); triangles->InsertNextCell(triangle2); polydata->SetPolys(triangles); ////////////// vtkTriangle* Tri = vtkTriangle::SafeDownCast(polydata->GetCell(0)); vtkPoints* TriPoints = Tri->GetPoints(); double* p0; double* p1; double* p2; p0 = TriPoints->GetPoint(0); p1 = TriPoints->GetPoint(1); p2 = TriPoints->GetPoint(2); std::cout << "TriPoint[0] = " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; std::cout << "TriPoint[1] = " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; std::cout << "TriPoint[2] = " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; }