Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: writing data file can be skipped in some circumstances #753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/PlusCommon/Tools/EditSequenceFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -373,39 +373,53 @@ 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"))
&& !useCompression; // hard to carry over compressed data size
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 +794,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