Skip to content

Commit 8b184b0

Browse files
committed
ENH: writing data file can be skipped in some circumstances
1 parent 5f6e855 commit 8b184b0

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/PlusCommon/Tools/EditSequenceFile.cxx

+16-1
Original file line numberDiff line numberDiff line change
@@ -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;

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 reduceImageDataToOnePixel/*=false*/, 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, reduceImageDataToOnePixel, 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 reduceImageDataToOnePixel/*=false*/, 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, reduceImageDataToOnePixel, 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 reduceImageDataToOnePixel = false, 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 reduceImageDataToOnePixel = false, 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)