我刚开始学习VTK以获取.vtu格式文件。我正在写WriteVTU,这是VTK的一个例子。 我稍微修改了代码,以便在ParaView中显示两个四面体,但在ParaView中只显示一个四面体。
显然我错过了一些东西,但我无法想象。我会感激任何提示。
这是代码。
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkTetra.h>
#include <vtkCellArray.h>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkXMLUnstructuredGridWriter.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPointData.h>
#include <vtkVertexGlyphFilter.h>
int main(int argc, char *argv[])
{
// Parse command line arguments
if(argc != 2)
{
std::cout << "Required arguments: OutputFilename" << std::endl;
return EXIT_FAILURE;
}
std::string filename = argv[1];
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(1, 1, 0);
points->InsertNextPoint(0, 1, 1);
points->InsertNextPoint(-1, 0, 0);
points->InsertNextPoint(-1, -1, 0);
points->InsertNextPoint(0, -1, -1);
vtkSmartPointer<vtkTetra> tetra =
vtkSmartPointer<vtkTetra>::New();
tetra->GetPointIds()->SetId(0, 0);
tetra->GetPointIds()->SetId(1, 1);
tetra->GetPointIds()->SetId(2, 2);
tetra->GetPointIds()->SetId(3, 3);
vtkSmartPointer<vtkTetra> tetra2 =
vtkSmartPointer<vtkTetra>::New();
tetra->GetPointIds()->SetId(0, 0);
tetra->GetPointIds()->SetId(1, 4);
tetra->GetPointIds()->SetId(2, 5);
tetra->GetPointIds()->SetId(3, 6);
vtkSmartPointer<vtkCellArray> cellArray =
vtkSmartPointer<vtkCellArray>::New();
cellArray->InsertNextCell(tetra);
cellArray->InsertNextCell(tetra2);
vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid =
vtkSmartPointer<vtkUnstructuredGrid>::New();
unstructuredGrid->SetPoints(points);
unstructuredGrid->SetCells(VTK_TETRA, cellArray);
// Write file
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName(filename.c_str());
#if VTK_MAJOR_VERSION <= 5
writer->SetInput(unstructuredGrid);
#else
writer->SetInputData(unstructuredGrid);
#endif
writer->Write();
return EXIT_SUCCESS;
}
这是.vtu文件。
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
<UnstructuredGrid>
<Piece NumberOfPoints="7" NumberOfCells="2" >
<PointData>
</PointData>
<CellData>
</CellData>
<Points>
<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="appended" RangeMin="0" RangeMax="1.4142135624" offset="0" />
</Points>
<Cells>
<DataArray type="Int64" Name="connectivity" format="appended" RangeMin="" RangeMax="" offset="56" />
<DataArray type="Int64" Name="offsets" format="appended" RangeMin="" RangeMax="" offset="108" />
<DataArray type="UInt8" Name="types" format="appended" RangeMin="" RangeMax="" offset="152" />
</Cells>
</Piece>
</UnstructuredGrid>
<AppendedData encoding="base64">
_AQAAAACAAABUAAAAGAAAAA==eJxjYEAGDfaobGz8hv1IYvux8QElFQn3AQAAAACAAABAAAAAFAAAAA==eJxjYIAAFijNCqXZGIgDAAMAABA=AQAAAACAAAAQAAAADgAAAA==eJxjYYAADigNAACQAA0=AQAAAACAAAACAAAACgAAAA==eJzj4gIAACAAFQ==
</AppendedData>
</VTKFile>
答案 0 :(得分:0)
对不起这只是一个错字。
exit