From 674367044de1f2ee07b6c6b101aad2f0fc43d77f Mon Sep 17 00:00:00 2001 From: Adam Sylvester Date: Sun, 19 Jul 2015 09:28:59 -0400 Subject: [PATCH 1/3] strings should be passed in by const ref. Compiler will generate default constructor. --- modules/c++/six/include/six/Options.h | 20 ++++++++------------ modules/c++/six/source/Options.cpp | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/c++/six/include/six/Options.h b/modules/c++/six/include/six/Options.h index 6c3cd4de5..0fad8146f 100644 --- a/modules/c++/six/include/six/Options.h +++ b/modules/c++/six/include/six/Options.h @@ -43,23 +43,17 @@ namespace six */ class Options { - std::map mParameters; - public: typedef std::map ParameterMap; typedef std::map::const_iterator ParameterIter; - Options() - { - } - virtual ~Options() - { - } + virtual ~Options(); + /*! * Get back the parameter with option key specified in argument * */ - virtual Parameter getParameter(std::string option) const; + virtual Parameter getParameter(const std::string& option) const; /*! * Get back the parameter with option key specified in argument. @@ -67,17 +61,17 @@ class Options * that is passed in */ virtual Parameter - getParameter(std::string option, Parameter defaultValue) const; + getParameter(const std::string& option, Parameter defaultValue) const; /*! * Set a parameter with key given in option parameter */ - virtual void setParameter(std::string option, Parameter value); + virtual void setParameter(const std::string& option, Parameter value); /*! * Is there a parameter of name given in argument */ - virtual bool hasParameter(std::string option) const; + virtual bool hasParameter(const std::string& option) const; //! Allows us to iterate a parameter list ParameterIter begin() const { return mParameters.begin(); } @@ -85,6 +79,8 @@ class Options //! Allows us to compare an iterator against end ParameterIter end() const { return mParameters.end(); } +private: + std::map mParameters; }; } diff --git a/modules/c++/six/source/Options.cpp b/modules/c++/six/source/Options.cpp index 6868d64b5..0a5d342c1 100644 --- a/modules/c++/six/source/Options.cpp +++ b/modules/c++/six/source/Options.cpp @@ -21,11 +21,15 @@ */ #include "six/Options.h" -using namespace six; +namespace six +{ +Options::~Options() +{ +} -Parameter Options::getParameter(std::string option) const +Parameter Options::getParameter(const std::string& option) const { - ParameterIter p = mParameters.find(option); + const ParameterIter p = mParameters.find(option); if (p == mParameters.end()) { throw except::Exception(Ctxt("No such option exists")); @@ -33,9 +37,9 @@ Parameter Options::getParameter(std::string option) const return p->second; } -Parameter Options::getParameter(std::string option, Parameter defaultValue) const +Parameter Options::getParameter(const std::string& option, Parameter defaultValue) const { - ParameterIter p = mParameters.find(option); + const ParameterIter p = mParameters.find(option); if (p == mParameters.end()) { return defaultValue; @@ -43,14 +47,14 @@ Parameter Options::getParameter(std::string option, Parameter defaultValue) cons return p->second; } -void Options::setParameter(std::string option, Parameter value) +void Options::setParameter(const std::string& option, Parameter value) { mParameters[option] = value; } -bool Options::hasParameter(std::string option) const +bool Options::hasParameter(const std::string& option) const { - ParameterIter p = mParameters.find(option); + const ParameterIter p = mParameters.find(option); return (p != mParameters.end()); } - +} From 767b5dac9426ed04a6f5c4ca8eccd54a210a0183 Mon Sep 17 00:00:00 2001 From: Adam Sylvester Date: Sun, 19 Jul 2015 09:31:18 -0400 Subject: [PATCH 2/3] Adding the ability to set the NITF blocking for SIDD --- .../c++/six/include/six/NITFWriteControl.h | 18 ++++++ modules/c++/six/source/NITFWriteControl.cpp | 61 +++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/modules/c++/six/include/six/NITFWriteControl.h b/modules/c++/six/include/six/NITFWriteControl.h index 219f0bd4f..17151a1d8 100644 --- a/modules/c++/six/include/six/NITFWriteControl.h +++ b/modules/c++/six/include/six/NITFWriteControl.h @@ -64,6 +64,13 @@ class NITFWriteControl : public WriteControl static const char OPT_MAX_ILOC_ROWS[]; static const char OPT_J2K_COMPRESSION[]; + //! These determine the NITF blocking + // They only pertain to SIDD + // SICDs are never blocked, so setting this for a SICD will + // result in an error + static const char OPT_NUM_ROWS_PER_BLOCK[]; + static const char OPT_NUM_COLS_PER_BLOCK[]; + //! Buffered IO enum { @@ -274,6 +281,17 @@ class NITFWriteControl : public WriteControl */ void addDataAndWrite(const std::vector& schemaPaths); + /*! + * This function sets the NITF blocking. By default, the product + * will be unblocked, but for SIDDs the user can override this via + * the options. To be pedantic, the SIDD spec defines the NITF + * header such that blocking is not allowed, but this is a typo and + * will cause problems with some ELTs for images > 1 GB. + */ + void setBlocking(const std::string& imode, + const types::RowCol& segmentDims, + nitf::ImageSubheader& subheader); + /*! * This function sets the image security fields in the * given image subheader using the parameters in the diff --git a/modules/c++/six/source/NITFWriteControl.cpp b/modules/c++/six/source/NITFWriteControl.cpp index dce1579a6..3cb6016ef 100644 --- a/modules/c++/six/source/NITFWriteControl.cpp +++ b/modules/c++/six/source/NITFWriteControl.cpp @@ -31,6 +31,8 @@ using namespace six; const char NITFWriteControl::OPT_MAX_PRODUCT_SIZE[] = "MaxProductSize"; const char NITFWriteControl::OPT_MAX_ILOC_ROWS[] = "MaxILOCRows"; const char NITFWriteControl::OPT_J2K_COMPRESSION[] = "J2KCompression"; +const char NITFWriteControl::OPT_NUM_ROWS_PER_BLOCK[] = "NumRowsPerBlock"; +const char NITFWriteControl::OPT_NUM_COLS_PER_BLOCK[] = "NumColsPerBlock"; namespace { @@ -148,7 +150,7 @@ void NITFWriteControl::initialize(Container* container) { NITFImageInfo* info = mInfos[ii]; - std::vector < NITFSegmentInfo > imageSegments + const std::vector imageSegments = info->getImageSegments(); size_t numIS = imageSegments.size(); @@ -229,11 +231,10 @@ void NITFWriteControl::initialize(Container* container) subheader.setPixelInformation(pvtype, nbpp, nbpp, "R", irep, "SAR", bandInfo); - subheader.setBlocking(segmentInfo.numRows, - numCols, - segmentInfo.numRows > 8192 ? 0 - : segmentInfo.numRows, - numCols > 8192 ? 0 : numCols, imode); + setBlocking(imode, + types::RowCol(segmentInfo.numRows, numCols), + subheader); + subheader.getImageSyncCode().set(0); if (jj == 0) { @@ -288,6 +289,54 @@ void NITFWriteControl::initialize(Container* container) updateFileHeaderSecurity(); } +void NITFWriteControl::setBlocking(const std::string& imode, + const types::RowCol& segmentDims, + nitf::ImageSubheader& subheader) +{ + const bool isSICD = (mContainer->getDataType() == DataType::COMPLEX); + + nitf::Uint32 numRowsPerBlock; + if (mOptions.hasParameter(OPT_NUM_ROWS_PER_BLOCK)) + { + if (isSICD) + { + throw except::Exception(Ctxt("SICDs do not support blocking")); + } + + numRowsPerBlock = static_cast( + mOptions.getParameter(OPT_NUM_ROWS_PER_BLOCK)); + } + else + { + // Unblocked (per 2500C, if > 8192, should be set to 0) + numRowsPerBlock = (segmentDims.row > 8192) ? + 0 : segmentDims.row; + } + + nitf::Uint32 numColsPerBlock; + if (mOptions.hasParameter(OPT_NUM_COLS_PER_BLOCK)) + { + if (isSICD) + { + throw except::Exception(Ctxt("SICDs do not support blocking")); + } + + numColsPerBlock = static_cast( + mOptions.getParameter(OPT_NUM_COLS_PER_BLOCK)); + } + else + { + // Unblocked (per 2500C, if > 8192, should be set to 0) + numColsPerBlock = (segmentDims.col > 8192) ? 0 : segmentDims.col; + } + + subheader.setBlocking(segmentDims.row, + segmentDims.col, + numRowsPerBlock, + numColsPerBlock, + imode); +} + void NITFWriteControl::setImageSecurity(const six::Classification& c, nitf::ImageSubheader& subheader) { From 3d02186bcaa5045ab7d71e746aea9fc48c461c29 Mon Sep 17 00:00:00 2001 From: Adam Sylvester Date: Sun, 19 Jul 2015 09:48:06 -0400 Subject: [PATCH 3/3] Replacing tabs with spaces --- .../c++/six/include/six/NITFWriteControl.h | 4 +- modules/c++/six/source/NITFWriteControl.cpp | 92 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/modules/c++/six/include/six/NITFWriteControl.h b/modules/c++/six/include/six/NITFWriteControl.h index 17151a1d8..97161ebfd 100644 --- a/modules/c++/six/include/six/NITFWriteControl.h +++ b/modules/c++/six/include/six/NITFWriteControl.h @@ -289,8 +289,8 @@ class NITFWriteControl : public WriteControl * will cause problems with some ELTs for images > 1 GB. */ void setBlocking(const std::string& imode, - const types::RowCol& segmentDims, - nitf::ImageSubheader& subheader); + const types::RowCol& segmentDims, + nitf::ImageSubheader& subheader); /*! * This function sets the image security fields in the diff --git a/modules/c++/six/source/NITFWriteControl.cpp b/modules/c++/six/source/NITFWriteControl.cpp index 3cb6016ef..d189d9c3b 100644 --- a/modules/c++/six/source/NITFWriteControl.cpp +++ b/modules/c++/six/source/NITFWriteControl.cpp @@ -232,8 +232,8 @@ void NITFWriteControl::initialize(Container* container) bandInfo); setBlocking(imode, - types::RowCol(segmentInfo.numRows, numCols), - subheader); + types::RowCol(segmentInfo.numRows, numCols), + subheader); subheader.getImageSyncCode().set(0); if (jj == 0) @@ -290,51 +290,51 @@ void NITFWriteControl::initialize(Container* container) } void NITFWriteControl::setBlocking(const std::string& imode, - const types::RowCol& segmentDims, - nitf::ImageSubheader& subheader) + const types::RowCol& segmentDims, + nitf::ImageSubheader& subheader) { - const bool isSICD = (mContainer->getDataType() == DataType::COMPLEX); - - nitf::Uint32 numRowsPerBlock; - if (mOptions.hasParameter(OPT_NUM_ROWS_PER_BLOCK)) - { - if (isSICD) - { - throw except::Exception(Ctxt("SICDs do not support blocking")); - } - - numRowsPerBlock = static_cast( - mOptions.getParameter(OPT_NUM_ROWS_PER_BLOCK)); - } - else - { - // Unblocked (per 2500C, if > 8192, should be set to 0) - numRowsPerBlock = (segmentDims.row > 8192) ? - 0 : segmentDims.row; - } - - nitf::Uint32 numColsPerBlock; - if (mOptions.hasParameter(OPT_NUM_COLS_PER_BLOCK)) - { - if (isSICD) - { - throw except::Exception(Ctxt("SICDs do not support blocking")); - } - - numColsPerBlock = static_cast( - mOptions.getParameter(OPT_NUM_COLS_PER_BLOCK)); - } - else - { - // Unblocked (per 2500C, if > 8192, should be set to 0) - numColsPerBlock = (segmentDims.col > 8192) ? 0 : segmentDims.col; - } - - subheader.setBlocking(segmentDims.row, - segmentDims.col, - numRowsPerBlock, - numColsPerBlock, - imode); + const bool isSICD = (mContainer->getDataType() == DataType::COMPLEX); + + nitf::Uint32 numRowsPerBlock; + if (mOptions.hasParameter(OPT_NUM_ROWS_PER_BLOCK)) + { + if (isSICD) + { + throw except::Exception(Ctxt("SICDs do not support blocking")); + } + + numRowsPerBlock = static_cast( + mOptions.getParameter(OPT_NUM_ROWS_PER_BLOCK)); + } + else + { + // Unblocked (per 2500C, if > 8192, should be set to 0) + numRowsPerBlock = (segmentDims.row > 8192) ? + 0 : segmentDims.row; + } + + nitf::Uint32 numColsPerBlock; + if (mOptions.hasParameter(OPT_NUM_COLS_PER_BLOCK)) + { + if (isSICD) + { + throw except::Exception(Ctxt("SICDs do not support blocking")); + } + + numColsPerBlock = static_cast( + mOptions.getParameter(OPT_NUM_COLS_PER_BLOCK)); + } + else + { + // Unblocked (per 2500C, if > 8192, should be set to 0) + numColsPerBlock = (segmentDims.col > 8192) ? 0 : segmentDims.col; + } + + subheader.setBlocking(segmentDims.row, + segmentDims.col, + numRowsPerBlock, + numColsPerBlock, + imode); } void NITFWriteControl::setImageSecurity(const six::Classification& c,