1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkArrayDataWriter.h
5 
6 -------------------------------------------------------------------------
7   Copyright 2008 Sandia Corporation.
8   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9   the U.S. Government retains certain rights in this software.
10 -------------------------------------------------------------------------
11 
12   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13   All rights reserved.
14   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 
16      This software is distributed WITHOUT ANY WARRANTY; without even
17      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18      PURPOSE.  See the above copyright notice for more information.
19 
20 =========================================================================*/
21 
22 /**
23  * @class   vtkArrayDataWriter
24  * @brief   Serialize vtkArrayData to a file or stream.
25  *
26  *
27  * vtkArrayDataWriter serializes vtkArrayData using a text-based
28  * format that is human-readable and easily parsed (default option).  The
29  * WriteBinary array option can be used to serialize the vtkArrayData
30  * using a binary format that is optimized for rapid throughput.
31  *
32  * vtkArrayDataWriter can be used in two distinct ways: first, it can be used as a
33  * normal pipeline filter, which writes its inputs to a file.  Alternatively, static
34  * methods are provided for writing vtkArrayData instances to files or arbitrary c++
35  * streams.
36  *
37  * Inputs:
38  *   Input port 0: (required) vtkArrayData object.
39  *
40  * Output Format:
41  *   See http://www.kitware.com/InfovisWiki/index.php/N-Way_Array_File_Formats for
42  *   details on how vtkArrayDataWriter encodes data.
43  *
44  * @sa
45  * vtkArrayDataReader
46  *
47  * @par Thanks:
48  * Developed by Timothy M. Shead (tshead@sandia.gov) at Sandia National Laboratories.
49 */
50 
51 #ifndef vtkArrayDataWriter_h
52 #define vtkArrayDataWriter_h
53 
54 #include "vtkIOCoreModule.h" // For export macro
55 #include "vtkWriter.h"
56 #include "vtkStdString.h" // For string API
57 
58 class vtkArrayData;
59 
60 class VTKIOCORE_EXPORT vtkArrayDataWriter :
61   public vtkWriter
62 {
63 public:
64   static vtkArrayDataWriter *New();
65   vtkTypeMacro(vtkArrayDataWriter, vtkWriter);
66   void PrintSelf(ostream& os, vtkIndent indent) override;
67 
68   //@{
69   /**
70    * Get / set the filename where data will be stored (when used as a filter).
71    */
72   vtkSetStringMacro(FileName);
73   vtkGetStringMacro(FileName);
74   //@}
75 
76   //@{
77   /**
78    * Get / set whether data will be written in binary format (when used as a filter).
79    */
80   vtkSetMacro(Binary, vtkTypeBool);
81   vtkGetMacro(Binary, vtkTypeBool);
82   vtkBooleanMacro(Binary, vtkTypeBool);
83   //@}
84 
85   /**
86    * The output string. This is only set when WriteToOutputString is set.
87    */
GetOutputString()88   virtual vtkStdString GetOutputString()
89     { return this->OutputString; }
90 
91   //@{
92   /**
93    * Whether to output to a string instead of to a file, which is the default.
94    */
95   vtkSetMacro(WriteToOutputString, bool);
96   vtkGetMacro(WriteToOutputString, bool);
97   vtkBooleanMacro(WriteToOutputString, bool);
98   //@}
99 
100   int Write() override; // This is necessary to get Write() wrapped for scripting languages.
101 
102   /**
103    * Writes input port 0 data to a file, using an arbitrary filename and binary flag.
104    */
105   bool Write(const vtkStdString& FileName, bool WriteBinary = false);
106 
107   /**
108    * Write an arbitrary array to a file, without using the pipeline.
109    */
110   static bool Write(vtkArrayData* array, const vtkStdString& file_name, bool WriteBinary = false);
111 
112   /**
113    * Write input port 0 data to an arbitrary stream.  Note: streams should always be opened in
114    * binary mode, to prevent problems reading files on Windows.
115    */
116   bool Write(ostream& stream, bool WriteBinary = false);
117 
118   /**
119    * Write arbitrary data to a stream without using the pipeline.  Note: streams should always
120    * be opened in binary mode, to prevent problems reading files on Windows.
121    */
122   static bool Write(vtkArrayData* array, ostream& stream, bool WriteBinary = false);
123 
124   /**
125    * Write input port 0 data to a string. Note that the WriteBinary argument is not
126    * optional in order to not clash with the inherited Write() method.
127    */
128   vtkStdString Write(bool WriteBinary);
129 
130   /**
131    * Write arbitrary data to a string without using the pipeline.
132    */
133   static vtkStdString Write(vtkArrayData* array, bool WriteBinary = false);
134 
135 protected:
136   vtkArrayDataWriter();
137   ~vtkArrayDataWriter() override;
138 
139   int FillInputPortInformation(int port, vtkInformation* info) override;
140   void WriteData() override;
141 
142   char* FileName;
143   vtkTypeBool Binary;
144   bool WriteToOutputString;
145   vtkStdString OutputString;
146 
147 private:
148   vtkArrayDataWriter(const vtkArrayDataWriter&) = delete;
149   void operator=(const vtkArrayDataWriter&) = delete;
150 };
151 
152 #endif
153