@@ -373,39 +373,53 @@ 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+ && !useCompression; // hard to carry over compressed data size
380+ bool headerOnlyOperation = false ; // false by default
381+
376382 // Set operation
377383 if (strOperation.empty ())
378384 {
379385 operation = NO_OPERATION;
380386 LOG_INFO (" No modification operation has been specified (specify --operation parameter to change the input sequence)." );
387+ headerOnlyOperation = true ;
381388 }
382389 else if (igsioCommon::IsEqualInsensitive (strOperation, " UPDATE_FRAME_FIELD_NAME" ))
383390 {
384391 operation = UPDATE_FRAME_FIELD_NAME;
392+ headerOnlyOperation = true ;
385393 }
386394 else if (igsioCommon::IsEqualInsensitive (strOperation, " UPDATE_FRAME_FIELD_VALUE" ))
387395 {
388396 operation = UPDATE_FRAME_FIELD_VALUE;
397+ headerOnlyOperation = true ;
389398 }
390399 else if (igsioCommon::IsEqualInsensitive (strOperation, " DELETE_FRAME_FIELD" ))
391400 {
392401 operation = DELETE_FRAME_FIELD;
402+ headerOnlyOperation = true ;
393403 }
394404 else if (igsioCommon::IsEqualInsensitive (strOperation, " UPDATE_FIELD_NAME" ))
395405 {
396406 operation = UPDATE_FIELD_NAME;
407+ headerOnlyOperation = true ;
397408 }
398409 else if (igsioCommon::IsEqualInsensitive (strOperation, " UPDATE_FIELD_VALUE" ))
399410 {
400411 operation = UPDATE_FIELD_VALUE;
412+ headerOnlyOperation = true ;
401413 }
402414 else if (igsioCommon::IsEqualInsensitive (strOperation, " DELETE_FIELD" ))
403415 {
404416 operation = DELETE_FIELD;
417+ headerOnlyOperation = true ;
405418 }
406419 else if (igsioCommon::IsEqualInsensitive (strOperation, " ADD_TRANSFORM" ))
407420 {
408421 operation = ADD_TRANSFORM;
422+ headerOnlyOperation = true ;
409423 }
410424 else if (igsioCommon::IsEqualInsensitive (strOperation, " TRIM" ))
411425 {
@@ -780,7 +794,8 @@ int main(int argc, char** argv)
780794 // Save output file to file
781795
782796 LOG_INFO (" Save output sequence file to: " << outputFileName);
783- if (vtkPlusSequenceIO::Write (outputFileName, trackedFrameList, trackedFrameList->GetImageOrientation (), useCompression, operation != REMOVE_IMAGE_DATA) != PLUS_SUCCESS)
797+ if (vtkPlusSequenceIO::Write (outputFileName, trackedFrameList, trackedFrameList->GetImageOrientation (),
798+ useCompression, operation == REMOVE_IMAGE_DATA, headerOnlyUpdatePossible && headerOnlyOperation) != PLUS_SUCCESS)
784799 {
785800 LOG_ERROR (" Couldn't write sequence file: " << outputFileName);
786801 return EXIT_FAILURE;
0 commit comments