-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add ability to read MIE4NITF files #59
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,12 @@ | |
#include <QStringList> | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
|
||
#ifdef VISGUI_USE_GDAL | ||
#include <gdal_priv.h> | ||
#include <cpl_conv.h> | ||
#endif | ||
|
||
namespace // anonymous | ||
{ | ||
|
@@ -128,6 +134,57 @@ void vpFileDataSource::setMonitoringEnabled(bool enable) | |
} | ||
} | ||
|
||
bool add_mie4nitf_subdatasets (const QString &path, QStringList &list) { | ||
#ifdef VISGUI_USE_GDAL | ||
GDALAllRegister(); | ||
|
||
GDALDataset *dataset = \ | ||
static_cast<GDALDataset *>(GDALOpen(path.toStdString().c_str(), | ||
GA_ReadOnly)); | ||
|
||
if (!dataset) | ||
{ | ||
qWarning().nospace()<< "GDAL could not load file." << | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is |
||
path.toStdString().c_str(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides that this is the locale-incorrect way to convert to |
||
} | ||
|
||
const char* subdatasets_domain_name = "SUBDATASETS"; | ||
char **str = GDALGetMetadata(dataset, subdatasets_domain_name); | ||
|
||
int num_key_val_pairs = 0; | ||
while((*str) != NULL) { | ||
char *key_c_str= nullptr; | ||
QString key, value; | ||
const char *val_c_str = CPLParseNameValue((*str), &key_c_str); | ||
if (key_c_str != nullptr && val_c_str != nullptr) | ||
{ | ||
key = QString(key_c_str); | ||
value = QString(val_c_str); | ||
|
||
// Subdataset # 2 inside `/A.ntf` would be indicated by: | ||
// SUBDATASET_2_NAME=NITF_IM:1:/A.ntf | ||
// SUBDATASET_2_DESC=Image 2 of A.ntf | ||
|
||
const QRegExp rgx = QRegExp("SUBDATASET_\\d+_NAME"); | ||
|
||
if(key.contains(rgx)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing braces. |
||
list.append(value); | ||
} | ||
CPLFree(key_c_str); | ||
++(str); | ||
++num_key_val_pairs; | ||
} | ||
assert(num_key_val_pairs % 2 == 0); | ||
assert(num_key_val_pairs / 2 == list.size()); | ||
GDALClose(dataset); | ||
return true; | ||
#else | ||
qWarning() << "ERROR: GDAL reader not found to open file: " << | ||
path.toStdString(); | ||
return false; | ||
#endif | ||
|
||
} | ||
//----------------------------------------------------------------------------- | ||
void vpFileDataSource::update() | ||
{ | ||
|
@@ -154,21 +211,54 @@ void vpFileDataSource::update() | |
{ | ||
while (!file.atEnd()) | ||
{ | ||
const auto line = file.readLine(); | ||
QString line = file.readLine().trimmed(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't decrease use of AAA. |
||
if (line.isEmpty()) | ||
{ | ||
continue; | ||
} | ||
|
||
const auto path = baseDir.absoluteFilePath(QString::fromUtf8(line)); | ||
if (!QFileInfo{path}.exists()) | ||
// The path we'd check existence of. It may so happen, like in the case | ||
// of MIE4NITF, that the `path` to a frame doesn't exist on the disk. | ||
// For ex., in MIE4NITF, frame # 3 inside `/A.ntf` (0-indexed) is | ||
// stored in: | ||
// `NITF_IM:2:/A.ntf`. | ||
QString path_to_check; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use camelCase for variable names. |
||
QStringList all_paths; | ||
|
||
// MIE4NITF are a bunch of frames inside an `NITF` file. Just like we | ||
// use glob to get more than one frames, we use the prefix `MIE4NITF:` | ||
// to indicate that this file contains more than one frame in NITF | ||
// format. | ||
const QString mie4nitf_prefix = "MIE4NITF:"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
|
||
if (line.startsWith(mie4nitf_prefix)) | ||
{ | ||
int L = mie4nitf_prefix.length(); | ||
QString p = line.mid(L); | ||
path_to_check = baseDir.absoluteFilePath(p); | ||
|
||
if(!add_mie4nitf_subdatasets(path_to_check, all_paths)) | ||
{ | ||
continue; | ||
} | ||
} | ||
else | ||
{ | ||
path_to_check = baseDir.absoluteFilePath(line); | ||
all_paths.append(path_to_check); | ||
} | ||
|
||
if (!QFileInfo{path_to_check}.exists()) | ||
{ | ||
qWarning() << "Image data file" << path << "does not exist"; | ||
qWarning() << "Image data file" << path_to_check << "does not exist"; | ||
continue; | ||
} | ||
|
||
qDebug() << "Archiving" << path; | ||
d->DataFiles.append(path); | ||
for(auto path: all_paths) | ||
{ | ||
qDebug() << "Archiving" << path; | ||
d->DataFiles.append(path); | ||
} | ||
} | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,7 @@ void vtkGDALReader::vtkGDALReaderInternal::ReadMetaData( | |
this->ReleaseData(); | ||
|
||
this->GDALData = (GDALDataset*) GDALOpen(fileName.c_str(), GA_ReadOnly); | ||
std::cout << "Using GDAL reader to open file: " << fileName << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how useful this is? |
||
|
||
if (this->GDALData == NULL) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh... your code style is rather all over the place. Please try to conform to the existing style. (n.b.
T& x
, notT &x
, and Allman braces. Fortunately this is not one of the files still using historic VTK-style braces. Your indenting is also inconsistent.)