mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'fixed_point_write'
cad7b593d Fix warning. 7da30d254 Write data in fixed point, not scientific notation. Increase performance by removing buffer flushes. 98dbf7c1a Replace spaces by underscores in SCALAR name field. b3d170f2d Compound datatypes for writer. Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Robert Maynard <robert.maynard@kitware.com> Merge-request: !2001
This commit is contained in:
commit
b6a92c940b
@ -10,6 +10,7 @@
|
||||
#ifndef vtk_m_io_writer_DataSetWriter_h
|
||||
#define vtk_m_io_writer_DataSetWriter_h
|
||||
|
||||
#include <cctype>
|
||||
#include <vtkm/CellShape.h>
|
||||
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
@ -67,7 +68,7 @@ private:
|
||||
{
|
||||
out << " 0";
|
||||
}
|
||||
out << std::endl;
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +106,7 @@ private:
|
||||
{
|
||||
out << (c == 0 ? "" : " ") << VecType::GetComponent(value, c);
|
||||
}
|
||||
out << std::endl;
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +156,7 @@ private:
|
||||
|
||||
vtkm::Id npoints = cdata.GetNumberOfValues();
|
||||
out << "POINTS " << npoints << " "
|
||||
<< vtkm::io::internal::DataTypeName<vtkm::FloatDefault>::Name() << " " << std::endl;
|
||||
<< vtkm::io::internal::DataTypeName<vtkm::FloatDefault>::Name() << " " << '\n';
|
||||
|
||||
detail::OutputPointsFunctor{ out }(cdata);
|
||||
}
|
||||
@ -171,7 +172,7 @@ private:
|
||||
conn_length += 1 + cellSet.GetNumberOfPointsInCell(i);
|
||||
}
|
||||
|
||||
out << "CELLS " << nCells << " " << conn_length << std::endl;
|
||||
out << "CELLS " << nCells << " " << conn_length << '\n';
|
||||
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
@ -182,14 +183,14 @@ private:
|
||||
auto IdPortal = ids.ReadPortal();
|
||||
for (int j = 0; j < nids; ++j)
|
||||
out << " " << IdPortal.Get(j);
|
||||
out << std::endl;
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
out << "CELL_TYPES " << nCells << std::endl;
|
||||
out << "CELL_TYPES " << nCells << '\n';
|
||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||
{
|
||||
vtkm::Id shape = cellSet.GetCellShape(i);
|
||||
out << shape << std::endl;
|
||||
out << shape << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,15 +198,15 @@ private:
|
||||
{
|
||||
vtkm::Id nCells = dataSet.GetCoordinateSystem(0).GetNumberOfPoints();
|
||||
|
||||
out << "CELLS " << nCells << " " << nCells * 2 << std::endl;
|
||||
out << "CELLS " << nCells << " " << nCells * 2 << '\n';
|
||||
for (int i = 0; i < nCells; i++)
|
||||
{
|
||||
out << "1 " << i << std::endl;
|
||||
out << "1 " << i << '\n';
|
||||
}
|
||||
out << "CELL_TYPES " << nCells << std::endl;
|
||||
out << "CELL_TYPES " << nCells << '\n';
|
||||
for (int i = 0; i < nCells; i++)
|
||||
{
|
||||
out << vtkm::CELL_SHAPE_VERTEX << std::endl;
|
||||
out << vtkm::CELL_SHAPE_VERTEX << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,17 +231,26 @@ private:
|
||||
|
||||
if (!wrote_header)
|
||||
{
|
||||
out << "POINT_DATA " << npoints << std::endl;
|
||||
out << "POINT_DATA " << npoints << '\n';
|
||||
wrote_header = true;
|
||||
}
|
||||
|
||||
std::string typeName;
|
||||
vtkm::cont::CastAndCall(field, detail::GetDataTypeName(typeName));
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::GetDataTypeName(typeName));
|
||||
std::string name = field.GetName();
|
||||
for (auto& c : name)
|
||||
{
|
||||
if (std::isspace(c))
|
||||
{
|
||||
c = '_';
|
||||
}
|
||||
}
|
||||
out << "SCALARS " << name << " " << typeName << " " << ncomps << '\n';
|
||||
out << "LOOKUP_TABLE default" << '\n';
|
||||
|
||||
out << "SCALARS " << field.GetName() << " " << typeName << " " << ncomps << std::endl;
|
||||
out << "LOOKUP_TABLE default" << std::endl;
|
||||
|
||||
vtkm::cont::CastAndCall(field, detail::OutputFieldFunctor(out));
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::OutputFieldFunctor(out));
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,23 +273,34 @@ private:
|
||||
|
||||
if (!wrote_header)
|
||||
{
|
||||
out << "CELL_DATA " << ncells << std::endl;
|
||||
out << "CELL_DATA " << ncells << '\n';
|
||||
wrote_header = true;
|
||||
}
|
||||
|
||||
std::string typeName;
|
||||
vtkm::cont::CastAndCall(field, detail::GetDataTypeName(typeName));
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::GetDataTypeName(typeName));
|
||||
|
||||
out << "SCALARS " << field.GetName() << " " << typeName << " " << ncomps << std::endl;
|
||||
out << "LOOKUP_TABLE default" << std::endl;
|
||||
std::string name = field.GetName();
|
||||
for (auto& c : name)
|
||||
{
|
||||
if (std::isspace(c))
|
||||
{
|
||||
c = '_';
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::CastAndCall(field, detail::OutputFieldFunctor(out));
|
||||
out << "SCALARS " << name << " " << typeName << " " << ncomps << '\n';
|
||||
out << "LOOKUP_TABLE default" << '\n';
|
||||
|
||||
vtkm::cont::CastAndCall(field.GetData().ResetTypes(TypeListAll{}),
|
||||
detail::OutputFieldFunctor(out));
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteDataSetAsPoints(std::ostream& out, const vtkm::cont::DataSet& dataSet)
|
||||
{
|
||||
out << "DATASET UNSTRUCTURED_GRID" << std::endl;
|
||||
out << "DATASET UNSTRUCTURED_GRID" << '\n';
|
||||
WritePoints(out, dataSet);
|
||||
WriteVertexCells(out, dataSet);
|
||||
}
|
||||
@ -289,7 +310,7 @@ private:
|
||||
const vtkm::cont::DataSet& dataSet,
|
||||
const CellSetType& cellSet)
|
||||
{
|
||||
out << "DATASET UNSTRUCTURED_GRID" << std::endl;
|
||||
out << "DATASET UNSTRUCTURED_GRID" << '\n';
|
||||
WritePoints(out, dataSet);
|
||||
WriteExplicitCells(out, cellSet);
|
||||
}
|
||||
@ -300,7 +321,7 @@ private:
|
||||
const vtkm::cont::CellSetStructured<DIM>& cellSet)
|
||||
{
|
||||
///\todo: support uniform/rectilinear
|
||||
out << "DATASET STRUCTURED_GRID" << std::endl;
|
||||
out << "DATASET STRUCTURED_GRID" << '\n';
|
||||
|
||||
auto pointDimensions = cellSet.GetPointDimensions();
|
||||
using VTraits = vtkm::VecTraits<decltype(pointDimensions)>;
|
||||
@ -315,9 +336,11 @@ private:
|
||||
|
||||
static void Write(std::ostream& out, const vtkm::cont::DataSet& dataSet, bool just_points = false)
|
||||
{
|
||||
out << "# vtk DataFile Version 3.0" << std::endl;
|
||||
out << "vtk output" << std::endl;
|
||||
out << "ASCII" << std::endl;
|
||||
// The Paraview parser cannot handle scientific notation:
|
||||
out << std::fixed;
|
||||
out << "# vtk DataFile Version 3.0" << '\n';
|
||||
out << "vtk output" << '\n';
|
||||
out << "ASCII" << '\n';
|
||||
|
||||
if (just_points)
|
||||
{
|
||||
|
@ -7,7 +7,10 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
@ -90,11 +93,50 @@ void TestVTKRectilinearWrite()
|
||||
writer.WriteDataSet(tds.Make3DRectilinearDataSet0(), true);
|
||||
}
|
||||
|
||||
void TestVTKCompoundWrite()
|
||||
{
|
||||
double s_min = 0.00001;
|
||||
double s_max = 1.0;
|
||||
double t_min = -2.0;
|
||||
double t_max = 2.0;
|
||||
int s_samples = 16;
|
||||
vtkm::cont::DataSetBuilderUniform dsb;
|
||||
vtkm::Id2 dims(s_samples, s_samples);
|
||||
vtkm::Vec2f_64 origin(t_min, s_min);
|
||||
vtkm::Float64 ds = (s_max - s_min) / vtkm::Float64(dims[0] - 1);
|
||||
vtkm::Float64 dt = (t_max - t_min) / vtkm::Float64(dims[1] - 1);
|
||||
vtkm::Vec2f_64 spacing(dt, ds);
|
||||
vtkm::cont::DataSet dataSet = dsb.Create(dims, origin, spacing);
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
size_t nVerts = static_cast<size_t>(s_samples * s_samples);
|
||||
std::vector<vtkm::Vec2f_64> points(nVerts);
|
||||
|
||||
size_t idx = 0;
|
||||
for (vtkm::Id y = 0; y < dims[0]; ++y)
|
||||
{
|
||||
for (vtkm::Id x = 0; x < dims[1]; ++x)
|
||||
{
|
||||
double s = s_min + static_cast<vtkm::Float64>(y) * ds;
|
||||
double t = t_min + static_cast<vtkm::Float64>(x) * dt;
|
||||
// This function is not meaningful:
|
||||
auto z = std::exp(std::complex<double>(s, t));
|
||||
points[idx] = { std::sqrt(std::norm(z)), std::arg(z) };
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
dsf.AddPointField(dataSet, "z", points.data(), static_cast<vtkm::Id>(points.size()));
|
||||
vtkm::io::writer::VTKDataSetWriter writer("chirp.vtk");
|
||||
writer.WriteDataSet(dataSet);
|
||||
std::remove("chirp.vtk");
|
||||
}
|
||||
|
||||
void TestVTKWrite()
|
||||
{
|
||||
TestVTKExplicitWrite();
|
||||
TestVTKUniformWrite();
|
||||
TestVTKRectilinearWrite();
|
||||
TestVTKCompoundWrite();
|
||||
}
|
||||
|
||||
} //Anonymous namespace
|
||||
|
Loading…
Reference in New Issue
Block a user