svFSIplus
VtkData.h
1 /* Copyright (c) Stanford University, The Regents of the University of California, and others.
2  *
3  * All Rights Reserved.
4  *
5  * See Copyright-SimVascular.txt for additional details.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject
13  * to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef VTK_DATA_H
32 #define VTK_DATA_H
33 
34 #include "Array.h"
35 #include "Vector.h"
36 
37 #include <string>
38 
39 class VtkData {
40  public:
41  VtkData();
42  virtual ~VtkData();
43 
44  virtual Array<int> get_connectivity() = 0;
45  virtual Array<double> get_points() = 0;
46  virtual int num_elems() = 0;
47  virtual int np_elem() = 0;
48  virtual int num_points() = 0;
49  virtual void read_file(const std::string& file_name) = 0;
50 
51  virtual void set_element_data(const std::string& data_name, const Array<double>& data) = 0;
52  virtual void set_element_data(const std::string& data_name, const Array<int>& data) = 0;
53 
54  virtual void set_point_data(const std::string& data_name, const Array<double>& data) = 0;
55  virtual void set_point_data(const std::string& data_name, const Array<int>& data) = 0;
56  virtual void set_point_data(const std::string& data_name, const Vector<int>& data) = 0;
57 
58  virtual void set_points(const Array<double>& points) = 0;
59  virtual void set_connectivity(const int nsd, const Array<int>& conn, const int pid = 0) = 0;
60 
61  virtual bool has_point_data(const std::string& data_name) = 0;
62 
63  virtual void copy_points(Array<double>& points) = 0;
64  virtual void copy_point_data(const std::string& data_name, Array<double>& mesh_data) = 0;
65  virtual void copy_point_data(const std::string& data_name, Vector<double>& mesh_data) = 0;
66  virtual void write() = 0;
67 
68  static VtkData* create_reader(const std::string& file_name);
69  static VtkData* create_writer(const std::string& file_name);
70 
71  std::string file_name;
72 };
73 
74 class VtkVtpData : public VtkData {
75  public:
76  VtkVtpData();
77  VtkVtpData(const std::string& file_name, bool reader=true);
78  ~VtkVtpData();
79 
80  virtual Array<int> get_connectivity();
81  virtual Array<double> get_points();
82  virtual int num_elems();
83  virtual int np_elem();
84  virtual int num_points();
85  virtual void read_file(const std::string& file_name);
86 
87  void copy_points(Array<double>& points);
88  void copy_point_data(const std::string& data_name, Array<double>& mesh_data);
89  void copy_point_data(const std::string& data_name, Vector<double>& mesh_data);
90  void copy_point_data(const std::string& data_name, Vector<int>& mesh_data);
91  Array<double> get_point_data(const std::string& data_name);
92  std::vector<std::string> get_point_data_names();
93  bool has_point_data(const std::string& data_name);
94  virtual void set_connectivity(const int nsd, const Array<int>& conn, const int pid = 0);
95 
96  virtual void set_element_data(const std::string& data_name, const Array<double>& data);
97  virtual void set_element_data(const std::string& data_name, const Array<int>& data);
98 
99  virtual void set_point_data(const std::string& data_name, const Array<double>& data);
100  virtual void set_point_data(const std::string& data_name, const Array<int>& data);
101  virtual void set_point_data(const std::string& data_name, const Vector<int>& data);
102 
103  virtual void set_points(const Array<double>& points);
104  virtual void write();
105 
106  private:
107  class VtkVtpDataImpl;
108  VtkVtpDataImpl* impl;
109 };
110 
111 class VtkVtuData : public VtkData {
112  public:
113  VtkVtuData();
114  VtkVtuData(const std::string& file_name, bool reader=true);
115  ~VtkVtuData();
116 
117  virtual Array<int> get_connectivity();
118  virtual int num_elems();
119  virtual int np_elem();
120  virtual int num_points();
121  virtual void read_file(const std::string& file_name);
122 
123  void copy_points(Array<double>& points);
124  void copy_point_data(const std::string& data_name, Array<double>& mesh_data);
125  void copy_point_data(const std::string& data_name, Vector<double>& mesh_data);
126  void copy_point_data(const std::string& data_name, Vector<int>& mesh_data);
127 
128  Array<double> get_point_data(const std::string& data_name);
129  std::vector<std::string> get_point_data_names();
130  virtual Array<double> get_points();
131  bool has_point_data(const std::string& data_name);
132  virtual void set_connectivity(const int nsd, const Array<int>& conn, const int pid = 0);
133 
134  virtual void set_element_data(const std::string& data_name, const Array<double>& data);
135  virtual void set_element_data(const std::string& data_name, const Array<int>& data);
136 
137  virtual void set_point_data(const std::string& data_name, const Array<double>& data);
138  virtual void set_point_data(const std::string& data_name, const Array<int>& data);
139  virtual void set_point_data(const std::string& data_name, const Vector<int>& data);
140 
141  virtual void set_points(const Array<double>& points);
142  virtual void write();
143 
144  private:
145  class VtkVtuDataImpl;
146  VtkVtuDataImpl* impl;
147 };
148 
149 #endif
Definition: VtkData.h:39
Definition: VtkData.cpp:59
Definition: VtkData.h:74
std::vector< std::string > get_point_data_names()
Get a list of point data names.
Definition: VtkData.cpp:700
virtual Array< double > get_points()
Get an array of point data from an unstructured grid.
Definition: VtkData.cpp:715
void copy_point_data(const std::string &data_name, Array< double > &mesh_data)
Copy an array of point data from an polydata mesh into the given Array.
Definition: VtkData.cpp:589
Array< double > get_point_data(const std::string &data_name)
Get an array of point data from an unstructured grid.
Definition: VtkData.cpp:673
void copy_points(Array< double > &points)
Copy points into the given array.
Definition: VtkData.cpp:654
Definition: VtkData.cpp:241
Definition: VtkData.h:111
void copy_point_data(const std::string &data_name, Array< double > &mesh_data)
Copy an array of point data from an unstructured grid into the given Array.
Definition: VtkData.cpp:866
void copy_points(Array< double > &points)
Copy points into the given array.
Definition: VtkData.cpp:932
Array< double > get_point_data(const std::string &data_name)
Get an array of point data from an unstructured grid.
Definition: VtkData.cpp:964
std::vector< std::string > get_point_data_names()
Get a list of point data names.
Definition: VtkData.cpp:851