admin管理员组文章数量:1200985
I want to use the open source library vtk-m to calculate pathlines on data in plot3d format, the data format received by this program is vtk in the following format:
Since I couldn't upload a file, I opted for a screenshot.
Because my plot3d data consists of a grid file and a solution(q) file, and while nasa's plot3d_utilities library can read the grid file, it doesn't have the code to handle the solution file. Later I found the vtk open source library which has the code to read plot3d, then I modified it to convert the data to vtk format and then opened it using paraview. The code is as follows:
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkMultiBlockPLOT3DReader.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPlaneSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkStreamTracer.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredGridOutlineFilter.h>
#include <vtkStructuredGridWriter.h>
#include <vtkPolyDataWriter.h>
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
vtkNew<vtkNamedColors> namedColors;
std::string xyzFile = argv[1];
std::string qFile = argv[2];
vtkNew<vtkMultiBlockPLOT3DReader> pl3d;
pl3d->SetXYZFileName(xyzFile.c_str());
pl3d->SetQFileName(qFile.c_str());
pl3d->SetScalarFunctionNumber(0);
pl3d->SetVectorFunctionNumber(0);
pl3d->Update();
if (!pl3d->GetOutput() || pl3d->GetOutput()->GetNumberOfBlocks() == 0)
{
std::cerr << "Failed to load PLOT3D files. Please check the file format and paths."
<< std::endl;
return EXIT_FAILURE;
}
// Check the number of data blocks
int numBlocks = pl3d->GetOutput()->GetNumberOfBlocks();
std::cout << "Number of blocks: " << numBlocks << std::endl;
// Get Grid Data Block
vtkStructuredGrid* grid = vtkStructuredGrid::SafeDownCast(pl3d->GetOutput()->GetBlock(0));
if (!grid)
{
std::cerr << "The first block is not a vtkStructuredGrid. Check your input files."
<< std::endl;
return EXIT_FAILURE;
}
// Save to a .vtk file
vtkNew<vtkStructuredGridWriter> gridWriter;
gridWriter->SetFileName("grid.vtk");
gridWriter->SetInputData(grid);
gridWriter->Write();
std::cout << "Saved streamlines to 'streamlines.vtk', "
<< "outline to 'outline.vtk', and grid to 'grid.vtk'." << std::endl;
return EXIT_SUCCESS;
}
Visualization results for paraview:
The mesh looks normal, but the displayed flow field data (density) doesn't change much, which is obviously not right.
The thing that normally makes me think that there is something wrong with the conversion code is that I use this vtk file and bring it inside the program that solves for StreamLines in the vtk-m library and I get the following results:
So my question is how to convert plot3d type grid file and solution file to vtk file.
how to convert plot3d type grid file and solution file to vtk file.
本文标签: How to convert plot3d format data to vtk formatStack Overflow
版权声明:本文标题:How to convert plot3d format data to vtk format - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738613913a2102793.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论