@@ -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;
0 commit comments