Skip to content

Commit

Permalink
ENH: writing data file can be skipped in some circumstances
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Dec 24, 2020
1 parent 0d03704 commit fb1216e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/PlusCommon/Tools/EditSequenceFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -373,39 +373,52 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}

std::string fileExtension = vtksys::SystemTools::GetFilenameLastExtension(inputFileName);
bool headerOnlyUpdatePossible = (inputFileName == outputFileName) // file overwrite requested
&& (igsioCommon::IsEqualInsensitive(fileExtension, ".mhd") || igsioCommon::IsEqualInsensitive(fileExtension, ".nhdr"));
bool headerOnlyOperation = false; // false by default

// Set operation
if (strOperation.empty())
{
operation = NO_OPERATION;
LOG_INFO("No modification operation has been specified (specify --operation parameter to change the input sequence).");
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FRAME_FIELD_NAME"))
{
operation = UPDATE_FRAME_FIELD_NAME;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FRAME_FIELD_VALUE"))
{
operation = UPDATE_FRAME_FIELD_VALUE;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "DELETE_FRAME_FIELD"))
{
operation = DELETE_FRAME_FIELD;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FIELD_NAME"))
{
operation = UPDATE_FIELD_NAME;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "UPDATE_FIELD_VALUE"))
{
operation = UPDATE_FIELD_VALUE;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "DELETE_FIELD"))
{
operation = DELETE_FIELD;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "ADD_TRANSFORM"))
{
operation = ADD_TRANSFORM;
headerOnlyOperation = true;
}
else if (igsioCommon::IsEqualInsensitive(strOperation, "TRIM"))
{
Expand Down Expand Up @@ -780,7 +793,8 @@ int main(int argc, char** argv)
// Save output file to file

LOG_INFO("Save output sequence file to: " << outputFileName);
if (vtkPlusSequenceIO::Write(outputFileName, trackedFrameList, trackedFrameList->GetImageOrientation(), useCompression, operation != REMOVE_IMAGE_DATA) != PLUS_SUCCESS)
if (vtkPlusSequenceIO::Write(outputFileName, trackedFrameList, trackedFrameList->GetImageOrientation(),
useCompression, operation == REMOVE_IMAGE_DATA, headerOnlyUpdatePossible && headerOnlyOperation) != PLUS_SUCCESS)
{
LOG_ERROR("Couldn't write sequence file: " << outputFileName);
return EXIT_FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions src/PlusCommon/vtkPlusSequenceIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
#include <vtkNew.h>

//----------------------------------------------------------------------------
igsioStatus vtkPlusSequenceIO::Write(const std::string& filename, vtkIGSIOTrackedFrameList* frameList, US_IMAGE_ORIENTATION orientationInFile/*=US_IMG_ORIENT_MF*/, bool useCompression/*=true*/, bool enableImageDataWrite/*=true*/)
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*/)
{
std::string outputDirectory = "";
if (!vtksys::SystemTools::FileIsFullPath(filename))
{
outputDirectory = vtkPlusConfig::GetInstance()->GetOutputDirectory();
}
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frameList, orientationInFile, useCompression, enableImageDataWrite);
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frameList, orientationInFile, useCompression, reduceImageDataToOnePixel, writeHeaderOnly);
}

//----------------------------------------------------------------------------
igsioStatus vtkPlusSequenceIO::Write(const std::string& filename, igsioTrackedFrame* frame, US_IMAGE_ORIENTATION orientationInFile /*= US_IMG_ORIENT_MF*/, bool useCompression /*= true*/, bool enableImageDataWrite /*=true*/)
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*/)
{
std::string outputDirectory = "";
if (!vtksys::SystemTools::FileIsFullPath(filename))
{
outputDirectory = vtkPlusConfig::GetInstance()->GetOutputDirectory();
}
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frame, orientationInFile, useCompression, enableImageDataWrite);
return vtkIGSIOSequenceIO::Write(filename, outputDirectory, frame, orientationInFile, useCompression, reduceImageDataToOnePixel, writeHeaderOnly);
}

//----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/PlusCommon/vtkPlusSequenceIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class vtkPlusCommonExport vtkPlusSequenceIO : public vtkObject
{
public:
/*! Write object contents into file */
static igsioStatus Write(const std::string& filename, igsioTrackedFrame* frame, US_IMAGE_ORIENTATION orientationInFile = US_IMG_ORIENT_MF, bool useCompression = true, bool EnableImageDataWrite = true);
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);

/*! Write object contents into file */
static igsioStatus Write(const std::string& filename, vtkIGSIOTrackedFrameList* frameList, US_IMAGE_ORIENTATION orientationInFile = US_IMG_ORIENT_MF, bool useCompression = true, bool EnableImageDataWrite = true);
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);

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

0 comments on commit fb1216e

Please sign in to comment.