+ int idx, min, max;
+
+ // if the file is already open then just write to it
+ if( file )
+ {
+ vtkErrorMacro( << "File musn't be open");
+ return;
+ }
+
+ // if we need to open another slice, do it
+ if( (axis + 1) == this->FileDimensionality )
+ {
+ // determine the name
+ if (this->FileName)
+ {
+ sprintf(this->InternalFileName, "%s", this->FileName);
+ }
+ else
+ {
+ if (this->FilePrefix)
+ {
+ sprintf(this->InternalFileName, this->FilePattern,
+ this->FilePrefix, this->FileNumber);
+ }
+ else
+ {
+ sprintf(this->InternalFileName, this->FilePattern,this->FileNumber);
+ }
+// Remove this code in case user is using VTK 4.2...
+#if !(VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION == 2)
+ if (this->FileNumber < this->MinimumFileNumber)
+ {
+ this->MinimumFileNumber = this->FileNumber;
+ }
+ else if (this->FileNumber > this->MaximumFileNumber)
+ {
+ this->MaximumFileNumber = this->FileNumber;
+ }
+#endif
+ }
+
+ // Write the file
+ WriteDcmFile(this->InternalFileName,image);
+ ++this->FileNumber;
+ return;
+ }
+
+ // if the current region is too high a dimension for the file
+ // the we will split the current axis
+ cache->GetAxisUpdateExtent(axis, min, max);
+
+ // if it is the y axis then flip by default
+ if (axis == 1 && !this->FileLowerLeft)
+ {
+ for(idx = max; idx >= min; idx--)
+ {
+ cache->SetAxisUpdateExtent(axis, idx, idx);
+ this->RecursiveWrite(axis - 1, cache, image, file);
+ }
+ }
+ else
+ {
+ for(idx = min; idx <= max; idx++)
+ {
+ cache->SetAxisUpdateExtent(axis, idx, idx);
+ this->RecursiveWrite(axis - 1, cache, image, file);
+ }
+ }
+
+ // restore original extent
+ cache->SetAxisUpdateExtent(axis, min, max);