Skip to content

Commit

Permalink
option to disable XML validation for SICD too
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 9, 2021
1 parent bc2c97e commit d613234
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ namespace six
const six::NITFReadControl& NITFReadControl() const { return reader; }
six::NITFReadControl& NITFReadControl() { return reader; }

void load(const std::string& fromFile,
const std::vector<std::string>& schemaPaths);
void load(const std::filesystem::path& fromFile,
const std::vector<std::filesystem::path>& schemaPaths);
void load(const std::string& fromFile, const std::vector<std::string>* pSchemaPaths);
void load(const std::filesystem::path& fromFile, const std::vector<std::filesystem::path>* pSchemaPaths);
void load(const std::filesystem::path& fromFile, const std::vector<std::filesystem::path>& schemaPaths)
{
load(fromFile, &schemaPaths);
}
void load(const std::filesystem::path& fromFile)
{
static const std::vector<std::filesystem::path> schemaPaths;
load(fromFile, schemaPaths);
load(fromFile, nullptr /*schemaPaths*/);
}
void load(io::FileInputStream&, const std::vector<std::string>& schemaPaths);

Expand Down
12 changes: 8 additions & 4 deletions six/modules/c++/six.sicd/include/six/sicd/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,16 @@ class Utilities


// c.f. six_sicd.i
extern std::vector<std::byte> readFromNITF(const std::filesystem::path&, const std::vector<std::filesystem::path>& schemaPaths,
std::unique_ptr<ComplexData>& pComplexData);
extern std::vector<std::byte> readFromNITF(const std::filesystem::path& pathname, const std::vector<std::filesystem::path>*,
std::unique_ptr<ComplexData>& pComplexData);
inline std::vector<std::byte> readFromNITF(const std::filesystem::path& pathname, const std::vector<std::filesystem::path>& schemaPaths,
std::unique_ptr<ComplexData>& pComplexData)
{
return readFromNITF(pathname, &schemaPaths, pComplexData);
}
inline std::vector<std::byte> readFromNITF(const std::filesystem::path& pathname, std::unique_ptr<ComplexData>& pComplexData)
{
static const std::vector<std::filesystem::path> schemaPaths;
return readFromNITF(pathname, schemaPaths, pComplexData);
return readFromNITF(pathname, nullptr /*pSchemaPaths*/, pComplexData);
}

// c.f. six_sicd.i
Expand Down
19 changes: 10 additions & 9 deletions six/modules/c++/six.sicd/source/NITFReadComplexXMLControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ six::sicd::NITFReadComplexXMLControl::NITFReadComplexXMLControl()
}

void six::sicd::NITFReadComplexXMLControl::load(const std::string& fromFile,
const std::vector<std::string>& schemaPaths)
const std::vector<std::string>* pSchemaPaths)
{
reader.load(fromFile, schemaPaths);
reader.load(fromFile, pSchemaPaths);
}
void six::sicd::NITFReadComplexXMLControl::load(const std::filesystem::path& fromFile,
const std::vector<std::filesystem::path>& schemaPaths)
const std::vector<std::filesystem::path>* pSchemaPaths)
{
const std::vector<std::string>* pSchemaPaths_ = nullptr;
std::vector<std::string> schemaPaths_;
std::transform(schemaPaths.begin(), schemaPaths.end(), std::back_inserter(schemaPaths_), [](const fs::path& p) { return p.string(); });
load(fromFile.string(), schemaPaths_);
}
void six::sicd::NITFReadComplexXMLControl::load(io::FileInputStream& stream, const std::vector<std::string>& schemaPaths)
{
reader.load(stream, schemaPaths);
if (pSchemaPaths != nullptr)
{
std::transform(pSchemaPaths->begin(), pSchemaPaths->end(), std::back_inserter(schemaPaths_), [](const fs::path& p) { return p.string(); });
pSchemaPaths_ = &schemaPaths_;
}
load(fromFile.string(), pSchemaPaths_);
}

std::shared_ptr<const six::Container> six::sicd::NITFReadComplexXMLControl::getContainer() const
Expand Down
10 changes: 5 additions & 5 deletions six/modules/c++/six.sicd/source/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static void readSicd_(const std::string& sicdPathname,
std::vector<std::complex<float>>& widebandData)
{
six::sicd::NITFReadComplexXMLControl reader;
reader.load(sicdPathname, schemaPaths);
reader.load(sicdPathname, &schemaPaths);

// For SICD, there's only one image (container->size() == 1)
if (reader.getContainer()->size() != 1)
Expand Down Expand Up @@ -640,7 +640,7 @@ static void readSicd_(const std::string& sicdPathname,
TScalarMeshPtr& scalarMesh)
{
six::sicd::NITFReadComplexXMLControl reader;
reader.load(sicdPathname, schemaPaths);
reader.load(sicdPathname, &schemaPaths);

auto complexData_ = reader.getComplexData();
complexData.reset(complexData_.release());
Expand Down Expand Up @@ -728,7 +728,7 @@ mem::auto_ptr<ComplexData> Utilities::getComplexData(
else
{
six::sicd::NITFReadComplexXMLControl reader;
reader.load(pathname, schemaPaths);
reader.load(pathname, &schemaPaths);

auto pComplexData = reader.getComplexData();
return mem::auto_ptr<ComplexData>(pComplexData.release());
Expand Down Expand Up @@ -1553,12 +1553,12 @@ void Utilities::projectPixelsToSlantPlane(
}
}

std::vector<std::byte> six::sicd::readFromNITF(const fs::path& pathname, const std::vector<fs::path>& schemaPaths,
std::vector<std::byte> six::sicd::readFromNITF(const fs::path& pathname, const std::vector<fs::path>* pSchemaPaths,
std::unique_ptr<ComplexData>& pComplexData)
{
six::sicd::NITFReadComplexXMLControl reader;
reader.setLogger();
reader.load(pathname, schemaPaths);
reader.load(pathname, pSchemaPaths);

// For SICD, there's only one image (container->size() == 1)
if (reader.getContainer()->size() != 1)
Expand Down
19 changes: 3 additions & 16 deletions six/modules/c++/six.sicd/unittests/test_valid_six.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,15 @@ TEST_CASE(valid_six_50x50)
{
setNitfPluginPath();

static const std::vector<std::filesystem::path> schemaPaths;
const auto inputPathname = getNitfPath("sicd_50x50.nitf");
std::unique_ptr<six::sicd::ComplexData> pComplexData;
const auto image = six::sicd::readFromNITF(inputPathname, pComplexData);
const auto image = six::sicd::readFromNITF(inputPathname, schemaPaths, pComplexData); // validate XML
const six::Data* pData = pComplexData.get();

TEST_ASSERT_EQ(six::PixelType::RE32F_IM32F, pData->getPixelType());
TEST_ASSERT_EQ(static_cast<size_t>(8), pData->getNumBytesPerPixel());

/*
// UTF-8 characters in 50x50.nitf
#ifdef _WIN32
const std::string classificationText("NON CLASSIFI\xc9 / UNCLASSIFIED"); // ISO8859-1 "NON CLASSIFIÉ / UNCLASSIFIED"
#else
const std::string classificationText("NON CLASSIFI\xc3\x89 / UNCLASSIFIED"); // UTF-8 "NON CLASSIFIÉ / UNCLASSIFIED"
#endif
const auto& classification = pData->getClassification();
const auto actual = classification.getLevel();
//TEST_ASSERT_EQ(actual, classificationText);
*/
const std::string classificationText("NON CLASSIFIE' / UNCLASSIFIED");
const auto& classification = pData->getClassification();
const auto actual = classification.getLevel();
Expand All @@ -197,12 +187,9 @@ TEST_CASE(sicd_French_xml)

const auto inputPathname = getNitfPath("sicd_French_xml.nitf");
std::unique_ptr<six::sicd::ComplexData> pComplexData;
const auto image = six::sicd::readFromNITF(inputPathname, pComplexData);
const auto image = six::sicd::readFromNITF(inputPathname, pComplexData); // no validation
const six::Data* pData = pComplexData.get();

TEST_ASSERT_EQ(six::PixelType::RE32F_IM32F, pData->getPixelType());
TEST_ASSERT_EQ(static_cast<size_t>(8), pData->getNumBytesPerPixel());

// UTF-8 characters in 50x50.nitf
#ifdef _WIN32
const std::string classificationText("NON CLASSIFI\xc9 / UNCLASSIFIED"); // ISO8859-1 "NON CLASSIFIÉ / UNCLASSIFIED"
Expand Down
5 changes: 4 additions & 1 deletion six/modules/c++/six/include/six/NITFReadControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ struct NITFReadControl : public ReadControl
*/
void load(const std::string& fromFile,
const std::vector<std::string>& schemaPaths) override;
void load(const std::string& fromFile,
const std::vector<std::string>* pSchemaPaths);

/*
* \func load
Expand All @@ -139,7 +141,8 @@ struct NITFReadControl : public ReadControl
void load(std::shared_ptr<nitf::IOInterface> ioInterface);
void load(std::shared_ptr<nitf::IOInterface> ioInterface,
const std::vector<std::string>& schemaPaths);

void load(std::shared_ptr<nitf::IOInterface> ioInterface,
const std::vector<std::string>* pSchemaPaths);

using ReadControl::interleaved;
/*!
Expand Down
3 changes: 1 addition & 2 deletions six/modules/c++/six/include/six/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ mem::auto_ptr<Data> parseData(const XMLControlRegistry& xmlReg,
::io::InputStream& xmlStream,
const std::vector<std::string>& schemaPaths,
logging::Logger& log);
std::unique_ptr<Data> parseData(const XMLControlRegistry& xmlReg,
::io::InputStream& xmlStream,
std::unique_ptr<Data> parseData(const XMLControlRegistry&, ::io::InputStream&,
const std::vector<std::filesystem::path>*, logging::Logger&);

/*
Expand Down
23 changes: 21 additions & 2 deletions six/modules/c++/six/source/NITFReadControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ void NITFReadControl::load(const std::string& fromFile,
auto handle(std::make_shared<nitf::IOHandle>(fromFile));
load(handle, schemaPaths);
}
void NITFReadControl::load(const std::string& fromFile,
const std::vector<std::string>* pSchemaPaths)
{
auto handle(std::make_shared<nitf::IOHandle>(fromFile));
load(handle, pSchemaPaths);
}

void NITFReadControl::load(io::SeekableInputStream& stream,
const std::vector<std::string>& schemaPaths)
Expand Down Expand Up @@ -302,8 +308,21 @@ static std::vector<six::NITFImageInfo*> getImageInfos(six::Container& container)
}

void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface,
const std::vector<std::string>& schemaPaths)
const std::vector<std::string>& schemaPaths)
{
load(ioInterface, &schemaPaths);
}
void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface,
const std::vector<std::string>* pSchemaPaths_)
{
const std::vector<std::filesystem::path>* pSchemaPaths = nullptr;
std::vector<std::filesystem::path> schemaPaths;
if (pSchemaPaths_ != nullptr)
{
std::transform(pSchemaPaths_->begin(), pSchemaPaths_->end(), std::back_inserter(schemaPaths), [](const std::string& s) { return s; });
pSchemaPaths = &schemaPaths;
}

reset();
mInterface = ioInterface;

Expand Down Expand Up @@ -331,7 +350,7 @@ void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface,
std::unique_ptr<Data> data(parseData(*mXMLRegistry,
ioAdapter,
dataType,
schemaPaths,
pSchemaPaths,
*mLog));
if (data.get() == nullptr)
{
Expand Down

0 comments on commit d613234

Please sign in to comment.