Skip to content

Commit ce63ebe

Browse files
committed
ENH: writing data file can be skipped in some circumstances
1 parent 0d03704 commit ce63ebe

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/PlusCommon/Tools/EditSequenceFile.cxx

+15-1
Original file line numberDiff line numberDiff line change
@@ -373,39 +373,52 @@ int main(int argc, char** argv)
373373
return EXIT_FAILURE;
374374
}
375375

376+
std::string fileExtension = vtksys::SystemTools::GetFilenameLastExtension(inputFileName);
377+
bool headerOnlyUpdatePossible = (inputFileName == outputFileName) // file overwrite requested
378+
&& (igsioCommon::IsEqualInsensitive(fileExtension, ".mhd") || igsioCommon::IsEqualInsensitive(fileExtension, ".nhdr"));
379+
bool headerOnlyOperation = false; // false by default
380+
376381
// Set operation
377382
if (strOperation.empty())
378383
{
379384
operation = NO_OPERATION;
380385
LOG_INFO("No modification operation has been specified (specify --operation parameter to change the input sequence).");
386+
headerOnlyOperation = true;
381387
}
382388
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FRAME_FIELD_NAME"))
383389
{
384390
operation = UPDATE_FRAME_FIELD_NAME;
391+
headerOnlyOperation = true;
385392
}
386393
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FRAME_FIELD_VALUE"))
387394
{
388395
operation = UPDATE_FRAME_FIELD_VALUE;
396+
headerOnlyOperation = true;
389397
}
390398
else if (igsioCommon::IsEqualInsensitive(strOperation, "DELETE_FRAME_FIELD"))
391399
{
392400
operation = DELETE_FRAME_FIELD;
401+
headerOnlyOperation = true;
393402
}
394403
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FIELD_NAME"))
395404
{
396405
operation = UPDATE_FIELD_NAME;
406+
headerOnlyOperation = true;
397407
}
398408
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FIELD_VALUE"))
399409
{
400410
operation = UPDATE_FIELD_VALUE;
411+
headerOnlyOperation = true;
401412
}
402413
else if (igsioCommon::IsEqualInsensitive(strOperation, "DELETE_FIELD"))
403414
{
404415
operation = DELETE_FIELD;
416+
headerOnlyOperation = true;
405417
}
406418
else if (igsioCommon::IsEqualInsensitive(strOperation, "ADD_TRANSFORM"))
407419
{
408420
operation = ADD_TRANSFORM;
421+
headerOnlyOperation = true;
409422
}
410423
else if (igsioCommon::IsEqualInsensitive(strOperation, "TRIM"))
411424
{
@@ -780,7 +793,8 @@ int main(int argc, char** argv)
780793
// Save output file to file
781794

782795
LOG_INFO("Save output sequence file to: " << outputFileName);
783-
if (vtkPlusSequenceIO::Write(outputFileName, trackedFrameList, trackedFrameList->GetImageOrientation(), useCompression, operation != REMOVE_IMAGE_DATA) != PLUS_SUCCESS)
796+
if (vtkPlusSequenceIO::Write(outputFileName, trackedFrameList, trackedFrameList->GetImageOrientation(),
797+
useCompression, operation != REMOVE_IMAGE_DATA, headerOnlyUpdatePossible && headerOnlyOperation) != PLUS_SUCCESS)
784798
{
785799
LOG_ERROR("Couldn't write sequence file: " << outputFileName);
786800
return EXIT_FAILURE;

src/PlusCommon/vtkPlusSequenceIO.cxx

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
#include <vtkNew.h>
1414

1515
//----------------------------------------------------------------------------
16-
igsioStatus vtkPlusSequenceIO::Write(const std::string& filename, vtkIGSIOTrackedFrameList* frameList, US_IMAGE_ORIENTATION orientationInFile/*=US_IMG_ORIENT_MF*/, bool useCompression/*=true*/, bool enableImageDataWrite/*=true*/)
16+
igsioStatus vtkPlusSequenceIO::Write(const std::string& filename, vtkIGSIOTrackedFrameList* frameList, US_IMAGE_ORIENTATION orientationInFile/*=US_IMG_ORIENT_MF*/, bool useCompression/*=true*/, bool doNotAlterPixelData/*=true*/, bool writeHeaderOnly/*= false*/)
1717
{
1818
std::string outputDirectory = "";
1919
if (!vtksys::SystemTools::FileIsFullPath(filename))
2020
{
2121
outputDirectory = vtkPlusConfig::GetInstance()->GetOutputDirectory();
2222
}
23-
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frameList, orientationInFile, useCompression, enableImageDataWrite);
23+
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frameList, orientationInFile, useCompression, doNotAlterPixelData, writeHeaderOnly);
2424
}
2525

2626
//----------------------------------------------------------------------------
27-
igsioStatus vtkPlusSequenceIO::Write(const std::string& filename, igsioTrackedFrame* frame, US_IMAGE_ORIENTATION orientationInFile /*= US_IMG_ORIENT_MF*/, bool useCompression /*= true*/, bool enableImageDataWrite /*=true*/)
27+
igsioStatus vtkPlusSequenceIO::Write(const std::string& filename, igsioTrackedFrame* frame, US_IMAGE_ORIENTATION orientationInFile /*= US_IMG_ORIENT_MF*/, bool useCompression /*= true*/, bool doNotAlterPixelData/*=true*/, bool writeHeaderOnly/*= false*/)
2828
{
2929
std::string outputDirectory = "";
3030
if (!vtksys::SystemTools::FileIsFullPath(filename))
3131
{
3232
outputDirectory = vtkPlusConfig::GetInstance()->GetOutputDirectory();
3333
}
34-
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frame, orientationInFile, useCompression, enableImageDataWrite);
34+
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frame, orientationInFile, useCompression, doNotAlterPixelData, writeHeaderOnly);
3535
}
3636

3737
//----------------------------------------------------------------------------

src/PlusCommon/vtkPlusSequenceIO.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class vtkPlusCommonExport vtkPlusSequenceIO : public vtkObject
1818
{
1919
public:
2020
/*! Write object contents into file */
21-
static igsioStatus Write(const std::string& filename, igsioTrackedFrame* frame, US_IMAGE_ORIENTATION orientationInFile = US_IMG_ORIENT_MF, bool useCompression = true, bool EnableImageDataWrite = true);
21+
static igsioStatus Write(const std::string& filename, igsioTrackedFrame* frame, US_IMAGE_ORIENTATION orientationInFile = US_IMG_ORIENT_MF, bool useCompression = true, bool doNotAlterPixelData = true, bool writeHeaderOnly = false);
2222

2323
/*! Write object contents into file */
24-
static igsioStatus Write(const std::string& filename, vtkIGSIOTrackedFrameList* frameList, US_IMAGE_ORIENTATION orientationInFile = US_IMG_ORIENT_MF, bool useCompression = true, bool EnableImageDataWrite = true);
24+
static igsioStatus Write(const std::string& filename, vtkIGSIOTrackedFrameList* frameList, US_IMAGE_ORIENTATION orientationInFile = US_IMG_ORIENT_MF, bool useCompression = true, bool doNotAlterPixelData = true, bool writeHeaderOnly = false);
2525

2626
/*! Read file contents into the object */
2727
static igsioStatus Read(const std::string& filename, vtkIGSIOTrackedFrameList* frameList);

0 commit comments

Comments
 (0)