Write the input image to PNG. If WriteToBase64 is off, this simply forwards to the standard vtkPNGWriter behavior (writing to FileName/FilePattern or to memory). If WriteToBase64 is on, the image is instead (optionally flipped, see FlipImage, and) written to an in-memory PNG buffer which is then base64-encoded and stored in Base64Image.
107{
109 Superclass::Write();
110 return;
111 }
112
113 int previousWriteToMemory = this->GetWriteToMemory();
114
115 this->WriteToMemoryOn();
116
117
118
119 this->SetErrorCode(vtkErrorCode::NoError);
120
121
122 if ( this->GetInput() == NULL )
123 {
124 vtkErrorMacro(<<"Write:Please specify an input!");
125 return;
126 }
127 if (!this->WriteToMemory && !this->GetFileName() && !this->GetFilePattern())
128 {
129 vtkErrorMacro(<<"Write:Please specify either a FileName or a file prefix and pattern");
130 this->SetErrorCode(vtkErrorCode::NoFileNameError);
131 return;
132 }
133
134
135 this->InternalFileName =
136 new char[(this->GetFileName() ? strlen(this->GetFileName()) : 1) +
137 (this->GetFilePrefix() ? strlen(this->GetFilePrefix()) : 1) +
138 (this->GetFilePattern() ? strlen(this->GetFilePattern()) : 1) + 10];
139
140
141 int *wExtent;
142 this->UpdateInformation();
143 vtkInformation *inInfoImage = this->GetInputPortInformation(0);
144 inInfoImage->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wExtent);
145
146 this->FileNumber = wExtent[4];
147 this->MinimumFileNumber = this->MaximumFileNumber = this->FileNumber;
148 this->FilesDeleted = 0;
149 this->UpdateProgress(0.0);
150
151 for (this->FileNumber = wExtent[4]; this->FileNumber <= wExtent[5];
152 ++this->FileNumber)
153 {
154 this->MaximumFileNumber = this->FileNumber;
155 int updatedExtent[6] = {wExtent[0], wExtent[1],
156 wExtent[2], wExtent[3],
157 this->FileNumber,
158 this->FileNumber};
159
160 if (this->GetFileName())
161 {
162 sprintf(this->InternalFileName,"%s",this->GetFileName());
163 }
164 else
165 {
166 if (this->GetFilePrefix())
167 {
168 sprintf(this->InternalFileName, this->GetFilePattern(),
169 this->GetFilePrefix(), this->FileNumber);
170 }
171 else
172 {
173 sprintf(this->InternalFileName, this->GetFilePattern(), this->FileNumber);
174 }
175 }
176
178 {
179 this->WriteSlice(this->GetInput(), updatedExtent);
180 }
181 else
182 {
183 vtkImageData* flippedInput = vtkImageData::New();
184 flippedInput->DeepCopy(this->GetInput());
185 vtkDataArray* inputArray = this->GetInput()->GetPointData()->GetScalars();
186 vtkDataArray* flippedInputArray = flippedInput->GetPointData()->GetScalars();
187 for (int i=0; i<wExtent[3]-wExtent[2]+1; i++)
188 {
189 for (int j=0; j<wExtent[1]-wExtent[0]+1; j++)
190 {
191 flippedInputArray->SetTuple((wExtent[3]-wExtent[2]-i)*(wExtent[1]-wExtent[0]+1)+j,inputArray->GetTuple(i*(wExtent[1]-wExtent[0]+1)+j));
192 }
193 }
194 this->WriteSlice(flippedInput, updatedExtent);
195 flippedInput->Delete();
196 }
197
198 if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
199 {
200 this->DeleteFiles();
201 break;
202 }
203 this->UpdateProgress((this->FileNumber - wExtent[4])/
204 (wExtent[5] - wExtent[4] + 1.0));
205 }
206 delete [] this->InternalFileName;
207 this->InternalFileName = NULL;
208
209 vtkUnsignedCharArray* result = this->GetResult();
210 char* data = (char*)result->GetPointer(0);
211 int length = result->GetNumberOfTuples() * result->GetNumberOfComponents();
212
213 char* flipped_data = new char[length];
215 {
216 for (int i=0; i<length; i++)
217 {
218 flipped_data[i] = data[length-i-1];
219 }
220 data = flipped_data;
221 }
222
223 char* encoded_data = new char[2*length];
226
227 delete[] encoded_data;
228 delete[] flipped_data;
229
230 this->SetWriteToMemory(previousWriteToMemory);
231}
virtual void SetBase64Image(const char *)
long base64_encode(char *to, char *from, unsigned int len)