Kernel/VTKWriter/VTKData.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MERCURYDPM_VTKDATA_H
6 #define MERCURYDPM_VTKDATA_H
7 
8 #include <string>
9 #include <vector>
10 #include <fstream>
11 #include "Math/Vector.h"
12 #include <unordered_map>
13 
14 class VTKData
15 {
16 public:
17  VTKData() = default;
18  ~VTKData() = default;
19 
24  void addToPoints(Vec3D point);
25 
31  void addToPointData(const std::string& key, Mdouble value);
32 
37  void addToConnectivity(const std::vector<size_t>& indices);
38 
43  void addToTypes(int type);
44 
48  std::vector<Vec3D> getPoints() const;
49 
53  std::unordered_map<std::string, std::vector<Mdouble>> getPointData() const;
54 
58  std::vector<std::vector<size_t>> getConnectivity() const;
59 
63  std::vector<int> getTypes() const;
64 
70  void reservePoints(unsigned int n, const std::vector<std::string>& keys = {});
71 
76  void reserveCells(unsigned int n);
77 
82  void writeVTKData(std::string fileName) const;
83 
84  void writeVTKDataFromVtkContainer(std::string fileName, const std::vector<Vec3D>& points, const std::vector<std::vector<double>>& triangleStrips);
85 
86 private:
87  std::fstream makeVTKFileWithHeader(std::string& fileName) const;
88  void writePoints(std::fstream& file) const;
89  void writePointData(std::fstream& file) const;
90  void writeConnectivity(std::fstream& file) const;
91  void writeOffsets(std::fstream& file) const;
92  void writeTypes(std::fstream& file) const;
93 
97  std::vector<Vec3D> points_;
98 
102  std::unordered_map<std::string, std::vector<Mdouble>> pointData_;
103 
107  std::vector<std::vector<size_t>> connectivity_;
108 
112  std::vector<int> types_;
113 };
114 
115 
116 #endif //MERCURYDPM_VTKDATA_H
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Definition: Kernel/VTKWriter/VTKData.h:15
void addToTypes(int type)
Adds a type to the types vector.
Definition: VTKData.cc:22
void writeVTKDataFromVtkContainer(std::string fileName, const std::vector< Vec3D > &points, const std::vector< std::vector< double >> &triangleStrips)
Definition: VTKData.cc:84
void writeVTKData(std::string fileName) const
Writes the data to a file with the given file name.
Definition: VTKData.cc:62
void writePoints(std::fstream &file) const
Definition: VTKData.cc:117
void writeConnectivity(std::fstream &file) const
Definition: VTKData.cc:160
void addToPoints(Vec3D point)
Adds a point to the points vector.
Definition: VTKData.cc:7
VTKData()=default
void writePointData(std::fstream &file) const
Definition: VTKData.cc:131
std::vector< std::vector< size_t > > connectivity_
Definition: Kernel/VTKWriter/VTKData.h:107
std::vector< int > getTypes() const
Definition: VTKData.cc:42
std::vector< Vec3D > points_
Definition: Kernel/VTKWriter/VTKData.h:97
std::unordered_map< std::string, std::vector< Mdouble > > getPointData() const
Definition: VTKData.cc:32
void writeOffsets(std::fstream &file) const
Definition: VTKData.cc:177
~VTKData()=default
void reserveCells(unsigned int n)
Reserves additional memory for connectivity and types vectors.
Definition: VTKData.cc:55
std::fstream makeVTKFileWithHeader(std::string &fileName) const
Definition: VTKData.cc:99
void addToPointData(const std::string &key, Mdouble value)
Adds a value to the pointData values vector corresponding to the given key.
Definition: VTKData.cc:12
std::vector< int > types_
Definition: Kernel/VTKWriter/VTKData.h:112
std::vector< std::vector< size_t > > getConnectivity() const
Definition: VTKData.cc:37
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 pointDa...
Definition: VTKData.cc:47
void writeTypes(std::fstream &file) const
Definition: VTKData.cc:191
std::vector< Vec3D > getPoints() const
Definition: VTKData.cc:27
std::unordered_map< std::string, std::vector< Mdouble > > pointData_
Definition: Kernel/VTKWriter/VTKData.h:102
void addToConnectivity(const std::vector< size_t > &indices)
Adds a vector of indices to the connectivity vector.
Definition: VTKData.cc:17
Definition: Kernel/Math/Vector.h:30
squared absolute value
Definition: GlobalFunctions.h:87
string fileName
Definition: UniformPSDSelfTest.py:10
type
Definition: compute_granudrum_aor.py:141
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286