1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPolyDataWriter.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkPolyDataWriter.h"
16
17 #include "vtkInformation.h"
18 #include "vtkObjectFactory.h"
19 #include "vtkPolyData.h"
20
21 #if !defined(_WIN32) || defined(__CYGWIN__)
22 #include <unistd.h> /* unlink */
23 #else
24 #include <io.h> /* unlink */
25 #endif
26
27 vtkStandardNewMacro(vtkPolyDataWriter);
28
WriteData()29 void vtkPolyDataWriter::WriteData()
30 {
31 ostream* fp;
32 vtkPolyData* input = this->GetInput();
33
34 vtkDebugMacro(<< "Writing vtk polygonal data...");
35
36 if (!(fp = this->OpenVTKFile()) || !this->WriteHeader(fp))
37 {
38 if (fp)
39 {
40 if (this->FileName)
41 {
42 vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName);
43 this->CloseVTKFile(fp);
44 unlink(this->FileName);
45 }
46 else
47 {
48 this->CloseVTKFile(fp);
49 vtkErrorMacro("Could not read memory header. ");
50 }
51 }
52 return;
53 }
54 //
55 // Write polygonal data specific stuff
56 //
57 *fp << "DATASET POLYDATA\n";
58
59 //
60 // Write data owned by the dataset
61 int errorOccured = 0;
62 if (!this->WriteDataSetData(fp, input))
63 {
64 errorOccured = 1;
65 }
66 if (!errorOccured && !this->WritePoints(fp, input->GetPoints()))
67 {
68 errorOccured = 1;
69 }
70
71 if (!errorOccured && input->GetVerts())
72 {
73 if (!this->WriteCells(fp, input->GetVerts(), "VERTICES"))
74 {
75 errorOccured = 1;
76 }
77 }
78 if (!errorOccured && input->GetLines())
79 {
80 if (!this->WriteCells(fp, input->GetLines(), "LINES"))
81 {
82 errorOccured = 1;
83 }
84 }
85 if (!errorOccured && input->GetPolys())
86 {
87 if (!this->WriteCells(fp, input->GetPolys(), "POLYGONS"))
88 {
89 errorOccured = 1;
90 }
91 }
92 if (!errorOccured && input->GetStrips())
93 {
94 if (!this->WriteCells(fp, input->GetStrips(), "TRIANGLE_STRIPS"))
95 {
96 errorOccured = 1;
97 }
98 }
99
100 if (!errorOccured && !this->WriteCellData(fp, input))
101 {
102 errorOccured = 1;
103 }
104 if (!errorOccured && !this->WritePointData(fp, input))
105 {
106 errorOccured = 1;
107 }
108
109 if (errorOccured)
110 {
111 if (this->FileName)
112 {
113 vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName);
114 this->CloseVTKFile(fp);
115 unlink(this->FileName);
116 }
117 else
118 {
119 vtkErrorMacro("Error writing data set to memory");
120 this->CloseVTKFile(fp);
121 }
122 return;
123 }
124 this->CloseVTKFile(fp);
125 }
126
FillInputPortInformation(int,vtkInformation * info)127 int vtkPolyDataWriter::FillInputPortInformation(int, vtkInformation* info)
128 {
129 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
130 return 1;
131 }
132
GetInput()133 vtkPolyData* vtkPolyDataWriter::GetInput()
134 {
135 return vtkPolyData::SafeDownCast(this->Superclass::GetInput());
136 }
137
GetInput(int port)138 vtkPolyData* vtkPolyDataWriter::GetInput(int port)
139 {
140 return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port));
141 }
142
PrintSelf(ostream & os,vtkIndent indent)143 void vtkPolyDataWriter::PrintSelf(ostream& os, vtkIndent indent)
144 {
145 this->Superclass::PrintSelf(os, indent);
146 }
147