using namespace Radar;
#include <vector>
#include <stdexcept>
#include <set>
#include <string>
#include <sstream>
#include <iostream>
#include <memory>
using namespace std;
class OdimH5PVolSplitter
{
protected: std::string inputFilePath;
protected: std::string inputFileName;
protected: std::string outputBasePath;
public: OdimH5PVolSplitter()
:inputFilePath()
,inputFileName()
,outputBasePath()
,factory(NULL)
,inputPVOL(NULL)
{
}
public: virtual ~OdimH5PVolSplitter()
{
closeInput();
}
public:
virtual void split(
const std::string& inputPath,
const std::string& outPath =
"")
{
inputFilePath = inputPath;
}
protected:
virtual void split()
{
try
{
openInput();
exec();
closeInput();
}
catch (...)
{
closeInput();
throw;
}
}
protected: virtual void exec() = 0;
protected: virtual void openInput()
{
}
protected: virtual void closeInput()
{
delete factory;
delete inputPVOL;
factory = NULL;
inputPVOL = NULL;
inputFileName = "";
}
};
class OdimH5PVolScanSplitter : public OdimH5PVolSplitter
{
protected: virtual void exec()
{
for (int s=0; s<scanCount; s++)
{
std::auto_ptr<PolarScan> inputScan ( inputPVOL->getScan(s) );
std::auto_ptr<PolarVolume> outputPVOL ( factory->createPolarVolume(outfilePath) );
std::auto_ptr<PolarScan> outputScan ( outputPVOL->createScan() );
outputPVOL->getWhat()->import( inputPVOL->getWhat() );
outputPVOL->getWhere()->import( inputPVOL->getWhere() );
outputPVOL->getHow()->import( inputPVOL->getHow() );
outputScan->getWhat()->import( inputScan->getWhat() );
outputScan->getWhere()->import( inputScan->getWhere() );
outputScan->getHow()->import( inputScan->getHow() );
std::set<std::string> quantities = inputScan->getStoredQuantities();
for (std::set<std::string>::iterator i = quantities.begin(); i != quantities.end(); i++)
{
std::string qname = *i;
std::auto_ptr<PolarScanData> inputQ ( inputScan->getQuantityData(qname) );
std::auto_ptr<PolarScanData> outputQ ( outputScan->createQuantityData(qname) );
outputQ->getWhat()->import( inputQ->getWhat() );
outputQ->getWhere()->import( inputQ->getWhere() );
outputQ->getHow()->import( inputQ->getHow() );
H5::AtomType type = inputQ->getDataType();
int height = inputQ->getDataHeight();
int width = inputQ->getDataWidth();
std::vector<char> buff ( type.getSize() * height * width );
inputQ->readData(&(buff[0]));
outputQ->writeData(&(buff[0]), width, height, type);
}
}
}
};
class OdimH5PVolQuantitySplitter : public OdimH5PVolSplitter
{
protected: virtual void exec()
{
int scanCount = inputPVOL->getScanCount();
for (int s=0; s<scanCount; s++)
{
std::auto_ptr<PolarScan> inputScan ( inputPVOL->getScan(s) );
std::set<std::string> quantities = inputScan->getStoredQuantities();
for (std::set<std::string>::iterator i = quantities.begin(); i != quantities.end(); i++)
{
std::string qname = *i;
std::auto_ptr<PolarScanData> inputQ ( inputScan->getQuantityData(qname) );
std::string outfilePath = this->outputBasePath +
"/" + inputFileName +
".dataset" +
Radar::stringutils::toString(s+1) +
"." + qname +
".h5";
std::auto_ptr<PolarVolume> outputPVOL ( factory->createPolarVolume(outfilePath) );
std::auto_ptr<PolarScan> outputScan ( outputPVOL->createScan() );
std::auto_ptr<PolarScanData> outputQ ( outputScan->createQuantityData(qname) );
outputPVOL->getWhat()->import( inputPVOL->getWhat() );
outputPVOL->getWhere()->import( inputPVOL->getWhere() );
outputPVOL->getHow()->import( inputPVOL->getHow() );
outputScan->getWhat()->import( inputScan->getWhat() );
outputScan->getWhere()->import( inputScan->getWhere() );
outputScan->getHow()->import( inputScan->getHow() );
outputQ->getWhat()->import( inputQ->getWhat() );
outputQ->getWhere()->import( inputQ->getWhere() );
outputQ->getHow()->import( inputQ->getHow() );
H5::AtomType type = inputQ->getDataType();
int height = inputQ->getDataHeight();
int width = inputQ->getDataWidth();
std::vector<char> buff ( type.getSize() * height * width );
inputQ->readData(&(buff[0]));
outputQ->writeData(&(buff[0]), width, height, type);
}
}
}
};
int main(int argc, char* argv[])
{
if (argc != 2)
{
cout << "Usage: " << argv[0] << " <odimh5file>" << endl;
return -1;
}
try
{
OdimH5PVolQuantitySplitter s;
s.split(argv[1]);
}
catch (std::exception& stde)
{
cerr << "Errore di esecuzione: " << stde.what() << endl;
}
catch (...)
{
cerr << "Errore di esecuzione sconosciuto" << endl;
}
return 0;
}
OdimH5 objects factory.
Definition: odimh5v20_factory.hpp:50
virtual PolarVolume * openPolarVolume(const std::string &path)
Get a OdimH5 PVOL object from an existing file.
Definition: odimh5v20_factory.cpp:260
OdimH5 v2.0 Polar Volume.
Definition: odimh5v20_classes.hpp:846
virtual int getScanCount()
Get the number of scans store in this volume.
Definition: odimh5v20_classes.cpp:1075
static std::string getBasePath(const std::string &path)
Extract the parent directory path of a file or directory indicated.
Definition: io.cpp:532
static std::string getFileName(const std::string &path)
Extract the file or directory name from a generic path.
Definition: io.cpp:540
Namespace related to ODIMH5 version 2.0.
Definition: odimh5v20.hpp:46
void split(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters)
Splits a string into substrings using the chacatars of a given string as tokens separators.
Definition: string.cpp:34
std::string toString(bool value)
Convert a boolean value to its string rapresentation (0/1).
Definition: string.cpp:109
Main header file of the library.