VTKData Class Reference

#include <VTKData.h>

Public Member Functions

 VTKData ()=default
 
 ~VTKData ()=default
 
void addToPoints (Vec3D point)
 Adds a point to the points vector. More...
 
void addToPointData (const std::string &key, Mdouble value)
 Adds a value to the pointData values vector corresponding to the given key. More...
 
void addToConnectivity (const std::vector< size_t > &indices)
 Adds a vector of indices to the connectivity vector. More...
 
void addToTypes (int type)
 Adds a type to the types vector. More...
 
std::vector< Vec3DgetPoints () const
 
std::unordered_map< std::string, std::vector< Mdouble > > getPointData () const
 
std::vector< std::vector< size_t > > getConnectivity () const
 
std::vector< intgetTypes () const
 
void reservePoints (unsigned int n, const std::vector< std::string > &keys={})
 Reserves additional memory for the points vector and optionally for the values vectors of the pointData. More...
 
void reserveCells (unsigned int n)
 Reserves additional memory for connectivity and types vectors. More...
 
void writeVTKData (std::string fileName) const
 Writes the data to a file with the given file name. More...
 
void writeVTKDataFromVtkContainer (std::string fileName, const std::vector< Vec3D > &points, const std::vector< std::vector< double >> &triangleStrips)
 

Private Member Functions

std::fstream makeVTKFileWithHeader (std::string &fileName) const
 
void writePoints (std::fstream &file) const
 
void writePointData (std::fstream &file) const
 
void writeConnectivity (std::fstream &file) const
 
void writeOffsets (std::fstream &file) const
 
void writeTypes (std::fstream &file) const
 

Private Attributes

std::vector< Vec3Dpoints_
 
std::unordered_map< std::string, std::vector< Mdouble > > pointData_
 
std::vector< std::vector< size_t > > connectivity_
 
std::vector< inttypes_
 

Constructor & Destructor Documentation

◆ VTKData()

VTKData::VTKData ( )
default

◆ ~VTKData()

VTKData::~VTKData ( )
default

Member Function Documentation

◆ addToConnectivity()

void VTKData::addToConnectivity ( const std::vector< size_t > &  indices)

Adds a vector of indices to the connectivity vector.

Parameters
indicesVector of indices to be added
18 {
19  connectivity_.push_back(indices);
20 }
std::vector< std::vector< size_t > > connectivity_
Definition: Kernel/VTKWriter/VTKData.h:107

References connectivity_.

Referenced by writeVTKDataFromVtkContainer().

◆ addToPointData()

void VTKData::addToPointData ( const std::string &  key,
Mdouble  value 
)

Adds a value to the pointData values vector corresponding to the given key.

Parameters
keyTo which pointData values vector to add
valueValue to be added
13 {
14  pointData_[key].push_back(value);
15 }
std::unordered_map< std::string, std::vector< Mdouble > > pointData_
Definition: Kernel/VTKWriter/VTKData.h:102
squared absolute value
Definition: GlobalFunctions.h:87

References pointData_, and Eigen::value.

◆ addToPoints()

void VTKData::addToPoints ( Vec3D  point)

Adds a point to the points vector.

Parameters
pointPoint to be added
8 {
9  points_.push_back(point);
10 }
std::vector< Vec3D > points_
Definition: Kernel/VTKWriter/VTKData.h:97

References points_.

Referenced by writeVTKDataFromVtkContainer().

◆ addToTypes()

void VTKData::addToTypes ( int  type)

Adds a type to the types vector.

Parameters
typeType to be added
23 {
24  types_.push_back(type);
25 }
std::vector< int > types_
Definition: Kernel/VTKWriter/VTKData.h:112
type
Definition: compute_granudrum_aor.py:141

References compute_granudrum_aor::type, and types_.

Referenced by writeVTKDataFromVtkContainer().

◆ getConnectivity()

std::vector< std::vector< size_t > > VTKData::getConnectivity ( ) const
Returns
Vector of vectors with indices
38 {
39  return connectivity_;
40 }

References connectivity_.

◆ getPointData()

std::unordered_map< std::string, std::vector< Mdouble > > VTKData::getPointData ( ) const
Returns
Map of pointData, each having a key and a vector of values
33 {
34  return pointData_;
35 }

References pointData_.

◆ getPoints()

std::vector< Vec3D > VTKData::getPoints ( ) const
Returns
Vector of points
28 {
29  return points_;
30 }

References points_.

◆ getTypes()

std::vector< int > VTKData::getTypes ( ) const
Returns
Vector of types
43 {
44  return types_;
45 }

References types_.

◆ makeVTKFileWithHeader()

std::fstream VTKData::makeVTKFileWithHeader ( std::string &  fileName) const
private
100 {
101  // Open output file
102  std::fstream file;
103  file.open(fileName.c_str(), std::ios_base::out);
104  if (file.fail())
105  {
106  logger(WARN, "File % could not be opened", fileName);
107  }
108 
109  // Write output file header
110  file << "<?xml version=\"1.0\"?>\n";
111  //file << "<!-- time " << handler_.getDPMBase()->getTime() << "-->\n"; //\todo JWB do we care about time?
112  file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
113  file << "<UnstructuredGrid>\n";
114  return file;
115 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
string fileName
Definition: UniformPSDSelfTest.py:10
std::ofstream out("Result.txt")

References UniformPSDSelfTest::fileName, logger, out(), and WARN.

Referenced by writeVTKData().

◆ reserveCells()

void VTKData::reserveCells ( unsigned int  n)

Reserves additional memory for connectivity and types vectors.

Parameters
nNumber of new cells to reserve memory for
56 {
57  unsigned int nt = connectivity_.size() + n;
58  connectivity_.reserve(nt);
59  types_.reserve(nt);
60 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11

References connectivity_, n, and types_.

◆ reservePoints()

void VTKData::reservePoints ( unsigned int  n,
const std::vector< std::string > &  keys = {} 
)

Reserves additional memory for the points vector and optionally for the values vectors of the pointData.

Parameters
nNumber of new points to reserve memory for
keysKeys for pointData values vectors to reserve memory for
48 {
49  unsigned int nt = points_.size() + n;
50  points_.reserve(nt);
51  for (const std::string& key : keys)
52  pointData_[key].reserve(nt);
53 }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References n, pointData_, points_, and oomph::Global_string_for_annotation::string().

◆ writeConnectivity()

void VTKData::writeConnectivity ( std::fstream &  file) const
private
161 {
162  file << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
163 
164  for (const std::vector<size_t>& vec : connectivity_)
165  {
166  file << "\t";
167  for (const int i : vec)
168  {
169  file << i << " ";
170  }
171  file << "\n";
172  }
173 
174  file << " </DataArray>\n";
175 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References connectivity_, and i.

Referenced by writeVTKData().

◆ writeOffsets()

void VTKData::writeOffsets ( std::fstream &  file) const
private
178 {
179  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
180 
181  unsigned int offset = 0;
182  for (const std::vector<size_t>& vec : connectivity_)
183  {
184  offset += vec.size();
185  file << "\t" << offset << "\n";
186  }
187 
188  file << " </DataArray>\n";
189 }

References connectivity_.

Referenced by writeVTKData().

◆ writePointData()

void VTKData::writePointData ( std::fstream &  file) const
private
132 {
133  file << "<PointData Vectors=\"vector\">\n";
134 
135  for (const auto& da : pointData_)
136  {
137  const std::string& name = da.first;
138  const std::vector<Mdouble>& values = da.second;
139 
140  unsigned int numberOfComponents = points_.size() / values.size();
141  file << " <DataArray type=\"Float32\" Name=\"" << name << "\" NumberOfComponents=\"" << numberOfComponents << "\" format=\"ascii\">\n";
142 
143  int i = 0;
144  while (i < values.size())
145  {
146  file << "\t";
147  for (int j = 0; j < numberOfComponents; j++)
148  {
149  file << values[i++] << " ";
150  }
151  file << "\n";
152  }
153 
154  file << " </DataArray>\n";
155  }
156 
157  file << "</PointData>\n";
158 }
string name
Definition: plotDoE.py:33
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, j, plotDoE::name, pointData_, points_, and oomph::Global_string_for_annotation::string().

Referenced by writeVTKData().

◆ writePoints()

void VTKData::writePoints ( std::fstream &  file) const
private
118 {
119  file << "<Points>\n";
120  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
121 
122  for (const Vec3D p : points_)
123  {
124  file << "\t" << p << "\n";
125  }
126 
127  file << " </DataArray>\n";
128  file << "</Points>\n";
129 }
float * p
Definition: Tutorial_Map_using.cpp:9
Definition: Kernel/Math/Vector.h:30

References p, and points_.

Referenced by writeVTKData().

◆ writeTypes()

void VTKData::writeTypes ( std::fstream &  file) const
private
192 {
193  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
194 
195  for (const int i : types_)
196  {
197  file << "\t" << i << "\n";
198  }
199 
200  file << " </DataArray>\n";
201 }

References i, and types_.

Referenced by writeVTKData().

◆ writeVTKData()

void VTKData::writeVTKData ( std::string  fileName) const

Writes the data to a file with the given file name.

Parameters
fileNameFull filename, e.g. Example.vtu
63 {
64  std::fstream file = makeVTKFileWithHeader(fileName);
65 
66  file << "<Piece NumberOfPoints=\"" + std::to_string(points_.size()) + "\" NumberOfCells=\"" + std::to_string(connectivity_.size()) + "\">\n";
67  writePoints(file);
68 
69  writePointData(file);
70 
71  file << "<Cells>\n";
72  writeConnectivity(file);
73  writeOffsets(file);
74  writeTypes(file);
75  file << "</Cells>\n";
76 
77  file << "</Piece>\n";
78  file << "</UnstructuredGrid>\n";
79  file << "</VTKFile>\n";
80  // Close output file
81  file.close();
82 }
void writePoints(std::fstream &file) const
Definition: VTKData.cc:117
void writeConnectivity(std::fstream &file) const
Definition: VTKData.cc:160
void writePointData(std::fstream &file) const
Definition: VTKData.cc:131
void writeOffsets(std::fstream &file) const
Definition: VTKData.cc:177
std::fstream makeVTKFileWithHeader(std::string &fileName) const
Definition: VTKData.cc:99
void writeTypes(std::fstream &file) const
Definition: VTKData.cc:191
std::string to_string(T object, unsigned float_precision=8)
Definition: oomph_utilities.h:189

References connectivity_, UniformPSDSelfTest::fileName, makeVTKFileWithHeader(), points_, oomph::StringConversion::to_string(), writeConnectivity(), writeOffsets(), writePointData(), writePoints(), and writeTypes().

Referenced by WallDetailsVTKWriter::writeVTK(), and writeVTKDataFromVtkContainer().

◆ writeVTKDataFromVtkContainer()

void VTKData::writeVTKDataFromVtkContainer ( std::string  fileName,
const std::vector< Vec3D > &  points,
const std::vector< std::vector< double >> &  triangleStrips 
)
85 {
86  for (auto& p : points)
87  addToPoints(p);
88  for (auto& c : triangleStrips)
89  {
90  std::vector<size_t> cell;
91  for (auto& cc : c)
92  cell.push_back(static_cast<size_t>(cc));
93  addToConnectivity(cell);
94  addToTypes(6);
95  }
97 }
void addToTypes(int type)
Adds a type to the types vector.
Definition: VTKData.cc:22
void writeVTKData(std::string fileName) const
Writes the data to a file with the given file name.
Definition: VTKData.cc:62
void addToPoints(Vec3D point)
Adds a point to the points vector.
Definition: VTKData.cc:7
void addToConnectivity(const std::vector< size_t > &indices)
Adds a vector of indices to the connectivity vector.
Definition: VTKData.cc:17
int c
Definition: calibrate.py:100

References addToConnectivity(), addToPoints(), addToTypes(), calibrate::c, UniformPSDSelfTest::fileName, p, and writeVTKData().

Member Data Documentation

◆ connectivity_

std::vector<std::vector<size_t> > VTKData::connectivity_
private

The connectivity 2D vector, connecting points

Referenced by addToConnectivity(), getConnectivity(), reserveCells(), writeConnectivity(), writeOffsets(), and writeVTKData().

◆ pointData_

std::unordered_map<std::string, std::vector<Mdouble> > VTKData::pointData_
private

The point data, corresponding to each point

Referenced by addToPointData(), getPointData(), reservePoints(), and writePointData().

◆ points_

std::vector<Vec3D> VTKData::points_
private

◆ types_

std::vector<int> VTKData::types_
private

The types, corresponding to each row of the connectivity 2D vector

Referenced by addToTypes(), getTypes(), reserveCells(), and writeTypes().


The documentation for this class was generated from the following files: