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

Method WriteFile

IO/MINC/vtkMNITransformWriter.cxx:345–454  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

343
344//------------------------------------------------------------------------------
345int vtkMNITransformWriter::WriteFile()
346{
347 // Check that a transform has been set.
348 if (!this->Transform)
349 {
350 vtkErrorMacro("WriteFile: No input transform has been set.");
351 return 0;
352 }
353 // Check that the file name has been set.
354 if (!this->FileName)
355 {
356 vtkErrorMacro("WriteFile: No file name has been set.");
357 return 0;
358 }
359
360 // Open the file.
361 vtksys::ofstream outfile(this->FileName, ios::out);
362
363 if (outfile.fail())
364 {
365 vtkErrorMacro("WriteFile: Can't create the file " << this->FileName);
366 return 0;
367 }
368
369 // Write the header
370 outfile << "MNI Transform File\n";
371
372 // Get the local time and write as first comment line
373 std::time_t t = std::time(nullptr);
374 tm local;
375#ifdef VTK_COMPILER_MSVC
376 localtime_s(&local, &t);
377#else
378 localtime_r(&t, &local);
379#endif
380 auto date = vtk::format("{:%Y.%m.%d.%H.%M.%S}", local);
381
382 outfile << "% Creation time: " << date << "\n";
383
384 // Write user comments
385 if (this->Comments)
386 {
387 char* cp = this->Comments;
388 while (*cp)
389 {
390 if (*cp != '%')
391 {
392 outfile << "% ";
393 }
394 while (*cp && *cp != '\n')
395 {
396 if (isprint(*cp) || *cp == '\t')
397 {
398 outfile << *cp;
399 }
400 cp++;
401 }
402 outfile << "\n";

Callers 1

ProcessRequestMethod · 0.95

Calls 9

WriteTransformMethod · 0.95
GetItemAsObjectMethod · 0.80
popMethod · 0.80
IsAMethod · 0.80
formatFunction · 0.50
GetNumberOfItemsMethod · 0.45
pushMethod · 0.45
emptyMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected