libigl v2.5.0
Loading...
Searching...
No Matches
MshSaver.h
Go to the documentation of this file.
1// based on MSH writer from PyMesh
2
3// Copyright (c) 2015 Qingnan Zhou <qzhou@adobe.com>
4// Copyright (C) 2020 Vladimir Fonov <vladimir.fonov@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9#ifndef IGL_MSH_SAVER_H
10#define IGL_MSH_SAVER_H
11#include "igl_inline.h"
12
13#include <fstream>
14#include <string>
15#include <vector>
16
17namespace igl {
18
22class MshSaver {
23 public:
24 typedef double Float;
25
26 typedef std::vector<int> IndexVector;
27 typedef std::vector<int> IntVector;
28 typedef std::vector<Float> FloatVector;
29 typedef std::vector<FloatVector> FloatField;
30 typedef std::vector<IntVector> IntField;
31 typedef std::vector<std::string> FieldNames;
32
36 MshSaver(const std::string& filename, bool binary=true);
38
39 public:
40 // Only these element types are supported right now
43
44 public:
45 // save mesh geometry
47 const FloatVector& nodes,
48 const IndexVector& elements,
49 const IntVector& element_lengths,
50 const IntVector& element_type,
51 const IntVector& element_tags );
52
53 // save additional fields associated with the mesh
54
55 // add node scalar field
56 void save_scalar_field(const std::string& fieldname, const FloatVector& field);
57 // add node vectot field
58 void save_vector_field(const std::string& fieldname, const FloatVector& field);
59 // add element scalar field
60 void save_elem_scalar_field(const std::string& fieldname, const FloatVector& field);
61 // add element vector field
62 void save_elem_vector_field(const std::string& fieldname, const FloatVector& field);
63 // add element tensor field
64 void save_elem_tensor_field(const std::string& fieldname, const FloatVector& field);
65
66 protected:
68 void save_nodes(const FloatVector& nodes);
69 void save_elements(const IndexVector& elements,
70 const IntVector& element_lengths,
71 const IntVector& element_type,
72 const IntVector& element_tags);
73
74 private:
75 bool m_binary;
76 size_t m_num_nodes;
77 size_t m_num_elements;
78
79 std::ofstream fout;
80};
81} //igl
82
83#ifndef IGL_STATIC_LIBRARY
84# include "MshSaver.cpp"
85#endif
86
87#endif //MSH_SAVER_H
Class for dumping information to .msh file depends only on c++stl library current implementation work...
Definition MshSaver.h:22
void save_vector_field(const std::string &fieldname, const FloatVector &field)
@ ELEMENT_PRISM
Definition MshSaver.h:42
@ ELEMENT_HEX
Definition MshSaver.h:42
@ ELEMENT_TET
Definition MshSaver.h:42
@ ELEMENT_TRI
Definition MshSaver.h:41
@ ELEMENT_LINE
Definition MshSaver.h:41
@ ELEMENT_QUAD
Definition MshSaver.h:41
std::vector< int > IntVector
Definition MshSaver.h:27
std::vector< std::string > FieldNames
Definition MshSaver.h:31
MshSaver(const std::string &filename, bool binary=true)
Write a .msh to a given path.
double Float
Definition MshSaver.h:24
void save_nodes(const FloatVector &nodes)
void save_elem_scalar_field(const std::string &fieldname, const FloatVector &field)
void save_header()
void save_elem_tensor_field(const std::string &fieldname, const FloatVector &field)
std::vector< FloatVector > FloatField
Definition MshSaver.h:29
void save_mesh(const FloatVector &nodes, const IndexVector &elements, const IntVector &element_lengths, const IntVector &element_type, const IntVector &element_tags)
std::vector< int > IndexVector
Definition MshSaver.h:26
void save_scalar_field(const std::string &fieldname, const FloatVector &field)
std::vector< Float > FloatVector
Definition MshSaver.h:28
void save_elements(const IndexVector &elements, const IntVector &element_lengths, const IntVector &element_type, const IntVector &element_tags)
std::vector< IntVector > IntField
Definition MshSaver.h:30
void save_elem_vector_field(const std::string &fieldname, const FloatVector &field)
Definition AABB.h:17