summaryrefslogtreecommitdiff
path: root/openEMS/tools/vtk_file_writer.h
blob: 428d85969ce25940edf4bede9772d44aa380eb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
*	Copyright (C) 2011,2012 Thorsten Liebig (Thorsten.Liebig@gmx.de)
*
*	This program is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License
*	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef VTK_FILE_WRITER_H
#define VTK_FILE_WRITER_H

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <complex>

class vtkDataSet;

class VTK_File_Writer
{
public:
	VTK_File_Writer(std::string filename, int meshType=0);
	virtual ~VTK_File_Writer();

	//! Set the filename
	virtual void SetFilename(std::string filename) {m_filename=filename;}
	//! Set the header information. May not be supported by all file types or setting.
	virtual void SetHeader(std::string header) {m_header=header;}

	//! Tell write to append data. May fail if filename has changed or filetype doesn't support this.
	virtual void SetAppendMode(bool val) {m_AppendMode=val;}
	//! Set binary flag (if the file type supports it)
	virtual void SetBinary(bool val) {m_Binary=val;}
	//! Set compression flag (if the file type supports it)
	virtual void SetCompress(bool val) {m_Compress=val;}

	void SetNativeDump(bool val) {m_NativeDump=val;}

	virtual void SetMeshLines(double const* const* lines, unsigned int const* count, double scaling=1);

	virtual void AddScalarField(std::string fieldname, double const* const* const* field);
	virtual void AddScalarField(std::string fieldname, float const* const* const* field);
	virtual void AddVectorField(std::string fieldname, double const* const* const* const* field);
	virtual void AddVectorField(std::string fieldname, float const* const* const* const* field);

	virtual int GetNumberOfFields() const;
	virtual void ClearAllFields();

	//! Get if timestep file series is active. \sa SetTimestepActive
	virtual bool GetTimestepActive() {return m_ActiveTS;}
	//! Set the timestep file series flag. \sa GetTimestepActive \sa SetTimestep
	virtual void SetTimestepActive(bool val) {m_ActiveTS = val;}
	//! Set the current timestep, this will set the timestep flag to true. \sa SetTimestepActive
	virtual void SetTimestep(unsigned int ts) {m_timestep=ts;SetTimestepActive(true);}

	virtual bool Write();

	virtual bool WriteASCII();
	virtual bool WriteXML();

protected:
	std::string m_filename;
	std::string m_header;

	//timestep properties
	bool m_ActiveTS;
	unsigned int m_timestep;

	vtkDataSet* m_GridData;

	//mesh information
	int m_MeshType;
	std::vector<double> m_MeshLines[3];
	bool m_NativeDump;

	bool m_AppendMode;
	bool m_Binary;
	bool m_Compress;

	virtual std::string GetTimestepFilename(int pad_length=10) const;
};

#endif // VTK_FILE_Writer_H