MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteFile

Method WriteFile

IO/Image/vtkTIFFWriter.cxx:279–337  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

277
278//------------------------------------------------------------------------------
279void vtkTIFFWriter::WriteFile(ostream*, vtkImageData* data, int extent[6], int*)
280{
281 vtkDataArray* scalarArray = this->GetInputArrayToProcess(0, this->GetInput());
282
283 // Make sure we actually have data.
284 if (!scalarArray)
285 {
286 vtkErrorMacro(<< "Could not get data from input.");
287 return;
288 }
289
290 TIFF* tif = reinterpret_cast<TIFF*>(this->TIFFPtr);
291 if (!tif)
292 {
293 vtkErrorMacro("Problem writing file.");
294 this->SetErrorCode(vtkErrorCode::FileFormatError);
295 return;
296 }
297
298 int dataType = scalarArray->GetDataType();
299 // take into consideration the scalar type
300 if (dataType != VTK_UNSIGNED_CHAR && dataType != VTK_UNSIGNED_SHORT && dataType != VTK_FLOAT)
301 {
302 vtkErrorMacro("TIFFWriter only accepts unsigned char/short or float scalars!");
303 return;
304 }
305
306 if (this->Pages > 1)
307 {
308 auto aos = scalarArray->ToAOSDataArray();
309 vtkTIFFWriterWriteVolumeFunctor functor;
310 if (!vtkArrayDispatch::DispatchByArray<vtkArrayDispatch::AOSArrays>::Execute(
311 aos, functor, this))
312 {
313 vtkErrorMacro(<< "UpdateFromFile: Array " << scalarArray->GetClassName()
314 << " not supported.");
315 this->SetErrorCode(vtkErrorCode::UserError);
316 }
317 }
318 else
319 {
320 // Now write the image for the current page/directory element.
321 int row = 0;
322 for (int idx2 = extent[4]; idx2 <= extent[5]; ++idx2)
323 {
324 for (int idx1 = extent[3]; idx1 >= extent[2]; idx1--)
325 {
326 int coords[3] = { extent[0], idx1, idx2 };
327 void* ptr = data->GetArrayPointer(scalarArray, coords);
328 if (TIFFWriteScanline(tif, static_cast<unsigned char*>(ptr), row, 0) < 0)
329 {
330 this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
331 break;
332 }
333 ++row;
334 }
335 }
336 }

Callers 1

vtkTIFFWriter.cxxFile · 0.45

Calls 8

TIFFWriteScanlineFunction · 0.85
ToAOSDataArrayMethod · 0.80
GetArrayPointerMethod · 0.80
ExecuteFunction · 0.50
GetInputMethod · 0.45
GetDataTypeMethod · 0.45
GetClassNameMethod · 0.45

Tested by

no test coverage detected