1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkXMLUnstructuredGridWriter.h>
#include <vtkUnstructuredGrid.h>
#include <vtkSmartPointer.h>
#include <iostream>
using namespace std;
int main ( int argc, char *argv[] )
{
//Je crée les points de mon maillage
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
for ( unsigned int i = 0; i < 5; i=i+2 )
{
for (unsigned int j = 0 ;j < 3; j=j+2)
{
for (unsigned int k = 0 ;k < 3 ;k=k+2)
{
points->InsertNextPoint ( i, j, k );
}
}
}
for ( unsigned int i = 4; i <6 ; i++ )
{
for (unsigned int j = 0 ;j < 2; j++)
{
for (unsigned int k = 0 ;k < 2 ; k++)
{
cout<<"i "<<i<<" j "<<j<<" k "<<k<<endl;
if (i == 4 && j == 0 && k== 0)
{
printf("ici\n");
}
else
{
points->InsertNextPoint ( i, j, k );
}
}
}
}
//Je crée mon objet unstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
//Je crée mes cellules
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
static vtkIdType cell[3][8]={{0,4,6,2,1,5,7,3},{4,8,10,6,5,9,11,7},{8,15,17,13,12,16,18,14}};
cells->InsertNextCell(8,cell[0]);
cells->InsertNextCell(8,cell[1]);
cells->InsertNextCell(8,cell[2]);
//Je mets mes points et mes cellules
unstructuredGrid->SetPoints(points);
unstructuredGrid->SetCells(12,cells);
//Je crée l 'objet unstructuredgrid xml et j'écris le fichier
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName("test.vtu");
writer->SetInput(unstructuredGrid);
writer->SetDataModeToAscii();
writer->Write();
return EXIT_SUCCESS;
} |
Partager