113 int previousWriteToMemory = this->GetWriteToMemory();
115 this->WriteToMemoryOn();
119 this->SetErrorCode(vtkErrorCode::NoError);
122 if ( this->GetInput() == NULL )
124 vtkErrorMacro(<<
"Write:Please specify an input!");
127 if (!this->WriteToMemory && !this->GetFileName() && !this->GetFilePattern())
129 vtkErrorMacro(<<
"Write:Please specify either a FileName or a file prefix and pattern");
130 this->SetErrorCode(vtkErrorCode::NoFileNameError);
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];
142 this->UpdateInformation();
143 vtkInformation *inInfoImage = this->GetInputPortInformation(0);
144 inInfoImage->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wExtent);
146 this->FileNumber = wExtent[4];
147 this->MinimumFileNumber = this->MaximumFileNumber = this->FileNumber;
148 this->FilesDeleted = 0;
149 this->UpdateProgress(0.0);
151 for (this->FileNumber = wExtent[4]; this->FileNumber <= wExtent[5];
154 this->MaximumFileNumber = this->FileNumber;
155 int updatedExtent[6] = {wExtent[0], wExtent[1],
156 wExtent[2], wExtent[3],
160 if (this->GetFileName())
162 sprintf(this->InternalFileName,
"%s",this->GetFileName());
166 if (this->GetFilePrefix())
168 sprintf(this->InternalFileName, this->GetFilePattern(),
169 this->GetFilePrefix(), this->FileNumber);
173 sprintf(this->InternalFileName, this->GetFilePattern(), this->FileNumber);
179 this->WriteSlice(this->GetInput(), updatedExtent);
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++)
189 for (
int j=0; j<wExtent[1]-wExtent[0]+1; j++)
191 flippedInputArray->SetTuple((wExtent[3]-wExtent[2]-i)*(wExtent[1]-wExtent[0]+1)+j,inputArray->GetTuple(i*(wExtent[1]-wExtent[0]+1)+j));
194 this->WriteSlice(flippedInput, updatedExtent);
195 flippedInput->Delete();
198 if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
203 this->UpdateProgress((this->FileNumber - wExtent[4])/
204 (wExtent[5] - wExtent[4] + 1.0));
206 delete [] this->InternalFileName;
207 this->InternalFileName = NULL;
209 vtkUnsignedCharArray* result = this->GetResult();
210 char* data = (
char*)result->GetPointer(0);
211 int length = result->GetNumberOfTuples() * result->GetNumberOfComponents();
213 char* flipped_data =
new char[length];
216 for (
int i=0; i<length; i++)
218 flipped_data[i] = data[length-i-1];
223 char* encoded_data =
new char[2*length];
227 delete[] encoded_data;
228 delete[] flipped_data;
230 this->SetWriteToMemory(previousWriteToMemory);