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< int > getTypes () 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< int > types_
 

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
39 {
40  connectivity_.push_back(indices);
41 }
std::vector< std::vector< size_t > > connectivity_
Definition: Kernel/VTKWriter/VTKData.h:128

References connectivity_.

Referenced by writeVTKDataFromVtkContainer(), NurbsWall::writeWallDetailsVTK(), WearableNurbsWall::writeWallDetailsVTK(), and WallHandler::writeWallDetailsVTKBoundingBox().

◆ 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
34 {
35  pointData_[key].push_back(value);
36 }
std::unordered_map< std::string, std::vector< Mdouble > > pointData_
Definition: Kernel/VTKWriter/VTKData.h:123

References pointData_.

Referenced by NurbsWall::writeWallDetailsVTK(), and WearableNurbsWall::writeWallDetailsVTK().

◆ addToPoints()

void VTKData::addToPoints ( Vec3D  point)

Adds a point to the points vector.

Parameters
pointPoint to be added
29 {
30  points_.push_back(point);
31 }
std::vector< Vec3D > points_
Definition: Kernel/VTKWriter/VTKData.h:118

References points_.

Referenced by writeVTKDataFromVtkContainer(), NurbsWall::writeWallDetailsVTK(), WearableNurbsWall::writeWallDetailsVTK(), and WallHandler::writeWallDetailsVTKBoundingBox().

◆ addToTypes()

void VTKData::addToTypes ( int  type)

Adds a type to the types vector.

Parameters
typeType to be added
44 {
45  types_.push_back(type);
46 }
std::vector< int > types_
Definition: Kernel/VTKWriter/VTKData.h:133

References types_.

Referenced by writeVTKDataFromVtkContainer(), NurbsWall::writeWallDetailsVTK(), WearableNurbsWall::writeWallDetailsVTK(), and WallHandler::writeWallDetailsVTKBoundingBox().

◆ getConnectivity()

std::vector< std::vector< size_t > > VTKData::getConnectivity ( ) const
Returns
Vector of vectors with indices
59 {
60  return connectivity_;
61 }

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
54 {
55  return pointData_;
56 }

References pointData_.

Referenced by NurbsWall::writeWallDetailsVTK().

◆ getPoints()

std::vector< Vec3D > VTKData::getPoints ( ) const
Returns
Vector of points
49 {
50  return points_;
51 }

References points_.

Referenced by NurbsWall::writeWallDetailsVTK(), and WearableNurbsWall::writeWallDetailsVTK().

◆ getTypes()

std::vector< int > VTKData::getTypes ( ) const
Returns
Vector of types
64 {
65  return types_;
66 }

References types_.

◆ makeVTKFileWithHeader()

std::fstream VTKData::makeVTKFileWithHeader ( std::string &  fileName) const
private
121 {
122  // Open output file
123  std::fstream file;
124  file.open(fileName.c_str(), std::ios_base::out);
125  if (file.fail())
126  {
127  logger(WARN, "File % could not be opened", fileName);
128  }
129 
130  // Write output file header
131  file << "<?xml version=\"1.0\"?>\n";
132  //file << "<!-- time " << handler_.getDPMBase()->getTime() << "-->\n"; //\todo JWB do we care about time?
133  file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
134  file << "<UnstructuredGrid>\n";
135  return file;
136 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN

References logger, 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
77 {
78  unsigned int nt = connectivity_.size() + n;
79  connectivity_.reserve(nt);
80  types_.reserve(nt);
81 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32

References connectivity_, n, and types_.

Referenced by NurbsWall::writeWallDetailsVTK(), and WearableNurbsWall::writeWallDetailsVTK().

◆ 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
69 {
70  unsigned int nt = points_.size() + n;
71  points_.reserve(nt);
72  for (const std::string& key : keys)
73  pointData_[key].reserve(nt);
74 }

References n, pointData_, and points_.

Referenced by NurbsWall::writeWallDetailsVTK(), and WearableNurbsWall::writeWallDetailsVTK().

◆ writeConnectivity()

void VTKData::writeConnectivity ( std::fstream &  file) const
private
182 {
183  file << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
184 
185  for (const std::vector<size_t>& vec : connectivity_)
186  {
187  file << "\t";
188  for (const int i : vec)
189  {
190  file << i << " ";
191  }
192  file << "\n";
193  }
194 
195  file << " </DataArray>\n";
196 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References connectivity_, and constants::i.

Referenced by writeVTKData().

◆ writeOffsets()

void VTKData::writeOffsets ( std::fstream &  file) const
private
199 {
200  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
201 
202  unsigned int offset = 0;
203  for (const std::vector<size_t>& vec : connectivity_)
204  {
205  offset += vec.size();
206  file << "\t" << offset << "\n";
207  }
208 
209  file << " </DataArray>\n";
210 }

References connectivity_.

Referenced by writeVTKData().

◆ writePointData()

void VTKData::writePointData ( std::fstream &  file) const
private
153 {
154  file << "<PointData Vectors=\"vector\">\n";
155 
156  for (const auto& da : pointData_)
157  {
158  const std::string& name = da.first;
159  const std::vector<Mdouble>& values = da.second;
160 
161  unsigned int numberOfComponents = points_.size() / values.size();
162  file << " <DataArray type=\"Float32\" Name=\"" << name << "\" NumberOfComponents=\"" << numberOfComponents << "\" format=\"ascii\">\n";
163 
164  int i = 0;
165  while (i < values.size())
166  {
167  file << "\t";
168  for (int j = 0; j < numberOfComponents; j++)
169  {
170  file << values[i++] << " ";
171  }
172  file << "\n";
173  }
174 
175  file << " </DataArray>\n";
176  }
177 
178  file << "</PointData>\n";
179 }
std::string name
Definition: MercuryProb.h:48

References constants::i, units::name, pointData_, and points_.

Referenced by writeVTKData().

◆ writePoints()

void VTKData::writePoints ( std::fstream &  file) const
private
139 {
140  file << "<Points>\n";
141  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
142 
143  for (const Vec3D p : points_)
144  {
145  file << "\t" << p << "\n";
146  }
147 
148  file << " </DataArray>\n";
149  file << "</Points>\n";
150 }
Definition: Vector.h:51

References points_.

Referenced by writeVTKData().

◆ writeTypes()

void VTKData::writeTypes ( std::fstream &  file) const
private
213 {
214  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
215 
216  for (const int i : types_)
217  {
218  file << "\t" << i << "\n";
219  }
220 
221  file << " </DataArray>\n";
222 }

References constants::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
84 {
85  std::fstream file = makeVTKFileWithHeader(fileName);
86 
87  file << "<Piece NumberOfPoints=\"" + std::to_string(points_.size()) + "\" NumberOfCells=\"" + std::to_string(connectivity_.size()) + "\">\n";
88  writePoints(file);
89 
90  writePointData(file);
91 
92  file << "<Cells>\n";
93  writeConnectivity(file);
94  writeOffsets(file);
95  writeTypes(file);
96  file << "</Cells>\n";
97 
98  file << "</Piece>\n";
99  file << "</UnstructuredGrid>\n";
100  file << "</VTKFile>\n";
101  // Close output file
102  file.close();
103 }
void writePoints(std::fstream &file) const
Definition: VTKData.cc:138
void writeConnectivity(std::fstream &file) const
Definition: VTKData.cc:181
void writePointData(std::fstream &file) const
Definition: VTKData.cc:152
void writeOffsets(std::fstream &file) const
Definition: VTKData.cc:198
std::fstream makeVTKFileWithHeader(std::string &fileName) const
Definition: VTKData.cc:120
void writeTypes(std::fstream &file) const
Definition: VTKData.cc:212

References connectivity_, makeVTKFileWithHeader(), points_, 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 
)
106 {
107  for (auto& p : points)
108  addToPoints(p);
109  for (auto& c : triangleStrips)
110  {
111  std::vector<size_t> cell;
112  for (auto& cc : c)
113  cell.push_back(static_cast<size_t>(cc));
114  addToConnectivity(cell);
115  addToTypes(6);
116  }
117  writeVTKData(fileName);
118 }
void addToTypes(int type)
Adds a type to the types vector.
Definition: VTKData.cc:43
void writeVTKData(std::string fileName) const
Writes the data to a file with the given file name.
Definition: VTKData.cc:83
void addToPoints(Vec3D point)
Adds a point to the points vector.
Definition: VTKData.cc:28
void addToConnectivity(const std::vector< size_t > &indices)
Adds a vector of indices to the connectivity vector.
Definition: VTKData.cc:38

References addToConnectivity(), addToPoints(), addToTypes(), 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: