Kernel/VTKWriter/VTKData.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MERCURYDPM_VTKDATA_H
27 #define MERCURYDPM_VTKDATA_H
28 
29 #include <string>
30 #include <vector>
31 #include <fstream>
32 #include "Math/Vector.h"
33 #include <unordered_map>
34 
35 class VTKData
36 {
37 public:
38  VTKData() = default;
39  ~VTKData() = default;
40 
45  void addToPoints(Vec3D point);
46 
52  void addToPointData(const std::string& key, Mdouble value);
53 
58  void addToConnectivity(const std::vector<size_t>& indices);
59 
64  void addToTypes(int type);
65 
69  std::vector<Vec3D> getPoints() const;
70 
74  std::unordered_map<std::string, std::vector<Mdouble>> getPointData() const;
75 
79  std::vector<std::vector<size_t>> getConnectivity() const;
80 
84  std::vector<int> getTypes() const;
85 
91  void reservePoints(unsigned int n, const std::vector<std::string>& keys = {});
92 
97  void reserveCells(unsigned int n);
98 
103  void writeVTKData(std::string fileName) const;
104 
105  void writeVTKDataFromVtkContainer(std::string fileName, const std::vector<Vec3D>& points, const std::vector<std::vector<double>>& triangleStrips);
106 
107 private:
108  std::fstream makeVTKFileWithHeader(std::string& fileName) const;
109  void writePoints(std::fstream& file) const;
110  void writePointData(std::fstream& file) const;
111  void writeConnectivity(std::fstream& file) const;
112  void writeOffsets(std::fstream& file) const;
113  void writeTypes(std::fstream& file) const;
114 
118  std::vector<Vec3D> points_;
119 
123  std::unordered_map<std::string, std::vector<Mdouble>> pointData_;
124 
128  std::vector<std::vector<size_t>> connectivity_;
129 
133  std::vector<int> types_;
134 };
135 
136 
137 #endif //MERCURYDPM_VTKDATA_H
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
Definition: Kernel/VTKWriter/VTKData.h:36
void addToTypes(int type)
Adds a type to the types vector.
Definition: VTKData.cc:43
void writeVTKDataFromVtkContainer(std::string fileName, const std::vector< Vec3D > &points, const std::vector< std::vector< double >> &triangleStrips)
Definition: VTKData.cc:105
void writeVTKData(std::string fileName) const
Writes the data to a file with the given file name.
Definition: VTKData.cc:83
void writePoints(std::fstream &file) const
Definition: VTKData.cc:138
void writeConnectivity(std::fstream &file) const
Definition: VTKData.cc:181
void addToPoints(Vec3D point)
Adds a point to the points vector.
Definition: VTKData.cc:28
VTKData()=default
void writePointData(std::fstream &file) const
Definition: VTKData.cc:152
std::vector< std::vector< size_t > > connectivity_
Definition: Kernel/VTKWriter/VTKData.h:128
std::vector< int > getTypes() const
Definition: VTKData.cc:63
std::vector< Vec3D > points_
Definition: Kernel/VTKWriter/VTKData.h:118
std::unordered_map< std::string, std::vector< Mdouble > > getPointData() const
Definition: VTKData.cc:53
void writeOffsets(std::fstream &file) const
Definition: VTKData.cc:198
~VTKData()=default
void reserveCells(unsigned int n)
Reserves additional memory for connectivity and types vectors.
Definition: VTKData.cc:76
std::fstream makeVTKFileWithHeader(std::string &fileName) const
Definition: VTKData.cc:120
void addToPointData(const std::string &key, Mdouble value)
Adds a value to the pointData values vector corresponding to the given key.
Definition: VTKData.cc:33
std::vector< int > types_
Definition: Kernel/VTKWriter/VTKData.h:133
std::vector< std::vector< size_t > > getConnectivity() const
Definition: VTKData.cc:58
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:68
void writeTypes(std::fstream &file) const
Definition: VTKData.cc:212
std::vector< Vec3D > getPoints() const
Definition: VTKData.cc:48
std::unordered_map< std::string, std::vector< Mdouble > > pointData_
Definition: Kernel/VTKWriter/VTKData.h:123
void addToConnectivity(const std::vector< size_t > &indices)
Adds a vector of indices to the connectivity vector.
Definition: VTKData.cc:38
Definition: Vector.h:51