#include <vector>
#include <stdexcept>
#include <set>
#include <string>
#include <sstream>
#include <iostream>
#include <memory>
using namespace Radar;
class ProductVisitor {
public:
protected:
};
if (type == OdimH5v20::PRODUCT_PPI) {
}
else if (type == OdimH5v20::PRODUCT_CAPPI) {
} else {
visit(*prod);
}
}
class ObjectVisitor {
public:
protected:
};
if (type == OdimH5v20::OBJECT_IMAGE) {
} else if (type == OdimH5v20::OBJECT_COMP) {
} else {
visit(*obj);
}
}
class Object2DSplitter {
private:
int id_max ;
int id_hsp ;
int id_vsp ;
OdimFactory * factory;
public:
OdimObject *root;
Object2DSplitter(){
id_max = -1;
id_hsp = -1;
id_vsp = -1;
}
~Object2DSplitter(){
delete factory;
}
std::string createProductFileName(std::string prodObject,double prodPar, std::string Quantity,time_t prodDateTime){
std::string result;
result=prodObject;
my_time.erase(16,3);
my_time.erase(13,1);
my_time.erase(10,1);
my_time.erase( 7,1);
my_time.erase( 4,1);
result=result+my_time+".h5";
return result;
}
std::string createProductFileName(std::string prodObject,
OdimH5v20::VILHeights prodPar, std::string Quantity,time_t prodDateTime){
std::string result;
result=prodObject;
my_time.erase(16,3);
my_time.erase(13,1);
my_time.erase(10,1);
my_time.erase( 7,1);
my_time.erase( 4,1);
result=result+my_time+".h5";
return result;
}
std::string createProductFileName(std::string prodObject, std::string Quantity,time_t prodDateTime){
std::string result;
result=prodObject;
result=result +"_"+Quantity + "_";
my_time.erase(16,3);
my_time.erase(13,1);
my_time.erase(10,1);
my_time.erase( 7,1);
my_time.erase( 4,1);
result=result+my_time+".h5";
return result;
}
void extractProduct (
OdimH5v20::OdimObject* obj,Product_2D* prod, Product_2D_Data* inputQ,
const std::string & outname,
bool add =
false);
const std::string& objtype = obj->
getObject();
if (not (objtype != OdimH5v20::OBJECT_IMAGE ||
objtype != OdimH5v20::OBJECT_COMP)) {
throw std::logic_error(objtype + " is not supported");
}
const std::string& prod_type = prod->
getProduct();
if (prod_type == OdimH5v20::PRODUCT_MAX ) {
id_max = nprod;
} else if (prod_type == OdimH5v20::PRODUCT_HSP ) {
id_hsp = nprod;
} else if (prod_type == OdimH5v20::PRODUCT_VSP ) {
id_vsp = nprod;
} else {
std::string filename;
std::string quantity ;
if (inputQ->existWhat()){
quantity = inputQ->getWhat()->getStr (ATTRIBUTE_WHAT_QUANTITY);
} else
else
extractProduct( obj, prod, inputQ, filename);
delete inputQ ;
std::cerr<<"ultimo nome definito :"<<filename<<std::endl;
}
}
delete prod;
}
if (id_max >= 0 && (id_hsp >= 0 || id_vsp >=0) ) {
std::string filename;
std::string quantity ;
if (inputQ->existWhat()){
quantity = inputQ->getWhat()->getStr (ATTRIBUTE_WHAT_QUANTITY);
} else
filename = createProductFileName(
"HVMI",quantity,obj->
getDateTime());
extractProduct( obj, prod, inputQ, filename);
if(id_hsp >=0 ) {
extractProduct( obj, prod, inputQ, filename,true);
}
if(id_vsp >=0 ) {
extractProduct( obj, prod, inputQ, filename,true);
}
} else if (id_max >= 0 ) {
std::string filename;
std::string quantity ;
if (inputQ->existWhat()){
quantity = inputQ->getWhat()->getStr (ATTRIBUTE_WHAT_QUANTITY);
} else
extractProduct( obj, prod, inputQ, filename);
}
}
#if 0
protected:
throw std::runtime_error(
"Unsupported object " + obj.
getObject());
}
throw std::runtime_error(
"Unsupported product " + prod.
getProduct());
}
Product_2D* prod = NULL;
visit(prod);
delete prod;
}
}
Product_2D* prod = NULL;
const std::string& prod_type = prod->
getProduct();
if (prod_type == OdimH5v20::PRODUCT_MAX ) {
prod_max = prod;
} else if (prod_type == OdimH5v20::PRODUCT_HSP ) {
prod_hsp = prod;
} else if (prod_type == OdimH5v20::PRODUCT_VSP ) {
prod_VSP = prod;
} else if {
visit(prod);
}
delete prod;
}
}
for (int i = 0; i < obj.getQuantityDataCount(); ++i) {
std::auto_ptr<OdimObject> outputObject ;
std::auto_ptr<OdimDataset> outputDataset ;
const std::string& type = root->getObject();
if (type == OdimH5v20::OBJECT_IMAGE) {
outputObject= factory->createImageObject(outname);
} else if (type == OdimH5v20::OBJECT_COMP) {
outputObject= factory->createCompObject(outname);
}
if (root->existWhat()) outputObject->getWhat()->import( root->getWhat() );
if (root->existHow()) outputObject->getHow()->import( root->getHow() );
if (root->existWhere()) outputObject->getWhere()->import( root->getWhere() );
const std::string& prod_type = prod.
getObject();
if (prod_type == OdimH5v20::PRODUCT_MAX ) {
prod_max = prod;
} else if (prod_type == OdimH5v20::PRODUCT_HSP ) {
prod_hsp = prod;
} else if (prod_type == OdimH5v20::PRODUCT_VSP ) {
prod_VSP = prod;
} else if {
visit(prod);
}
delete prod;
}
}
count++;
}
#endif
};
void Object2DSplitter::extractProduct(
OdimH5v20::OdimObject* obj,Product_2D* prod, Product_2D_Data* inputQ,
const std::string & outname,
bool add){
HorizontalObject_2D* outputObject ;
Product_2D* outputDataset ;
Product_2D_Data* outputQ ;
std::string quantity ;
if (inputQ->existWhat()){
} else
quantity = prod->getWhat()->getStr (ATTRIBUTE_WHAT_QUANTITY);
if (type == OdimH5v20::OBJECT_IMAGE) {
outputObject = (add) ? factory->openImageObject(outname) : factory->createImageObject(outname);
} else if (type == OdimH5v20::OBJECT_COMP) {
outputObject= (add) ? factory->openCompObject(outname) : factory->createCompObject(outname);
}
if (not add && prod->existWhere()) outputObject->getWhere()->import( prod->getWhere() );
outputDataset = outputObject->createProduct2D(prod->getProduct());
if (prod->existWhat()) outputDataset->getWhat()->import( prod->getWhat() );
if (prod->existHow()) outputDataset->getHow()->import( prod->getHow() );
if (prod->existWhere()) outputDataset->getWhere()->import( prod->getWhere() );
outputQ = outputDataset->createQuantityData(quantity);
if (inputQ->existWhat()) outputQ->getWhat()->import(inputQ->getWhat() );
if (inputQ->existHow()) outputQ->getWhere()->import(inputQ->getWhere() );
if (inputQ->existWhere())outputQ->getHow()->import(inputQ->getHow() );
H5::AtomType AtomType = inputQ->getDataType();
int height = inputQ->getDataHeight();
int width = inputQ->getDataWidth();
std::vector<char> buff ( AtomType.getSize() * height * width );
inputQ->readData(&(buff[0]));
outputQ->writeData(&(buff[0]), width, height, AtomType);
for (int nqdata = 0; nqdata < inputQ->getQualityDataCount(); nqdata++) {
OdimQuality * QualOutput (outputQ->createQualityData());
OdimQuality * QualInput (inputQ->getQualityData(nqdata));
QualOutput->getWhat()->import (QualInput->getWhat() );
QualOutput->getWhere()->import(QualInput->getWhere() );
QualOutput->getHow()->import (QualInput->getHow() );
AtomType = QualInput->getQualityType();
std::vector<char> qual( AtomType.getSize() * height * width );
QualInput->readQuality(&(qual[0]));
QualOutput->writeQuality(&(qual[0]), width, height, AtomType);
}
delete outputObject ;
delete outputDataset ;
delete outputQ ;
return ;
}
int main(int argc, const char** argv)
{
Object2DSplitter splitter;
try {
splitter.split(object);
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
OdimH5 v2.0 CompObject.
Definition: odimh5v20_classes.hpp:1698
OdimH5 v2.0 horizontalObject.
Definition: odimh5v20_classes.hpp:1612
OdimH5 v2.0 ImageObject.
Definition: odimh5v20_classes.hpp:1671
virtual int getProductCount()
Get the number of products dataset store in this volume.
Definition: odimh5v20_classes.cpp:2036
virtual Product_2D * getProduct(int index)
Get a pointer to a generic 2D product of the volume.
Definition: odimh5v20_classes.cpp:2318
virtual MetadataGroup * getWhat()
Get the WHAT attributes group.
Definition: odimh5v20_classes.cpp:347
OdimH5 objects factory.
Definition: odimh5v20_factory.hpp:50
virtual OdimObject * open(const std::string &path)
Get a OdimH5 object from an existing file.
Definition: odimh5v20_factory.cpp:112
Generic OdimH5 v2.0 object.
Definition: odimh5v20_classes.hpp:95
virtual time_t getDateTime()
Get the joined value of 'date' and 'time' attributes.
Definition: odimh5v20_classes.cpp:296
virtual MetadataGroup * getWhere()
Get the WHERE attributes group.
Definition: odimh5v20_classes.cpp:179
virtual std::string getObject()
Get the value of 'object' attribute.
Definition: odimh5v20_classes.cpp:292
virtual bool existHow()
Test is the HOW attributes group exist.
Definition: odimh5v20_classes.cpp:203
virtual MetadataGroup * getWhat()
Get the WHAT attributes group.
Definition: odimh5v20_classes.cpp:172
virtual MetadataGroup * getHow()
Get the HOW attributes group.
Definition: odimh5v20_classes.cpp:186
virtual bool existWhere()
Test is the WHERE attributes group exist.
Definition: odimh5v20_classes.cpp:198
virtual bool existWhat()
Test is the WHAT attributes group exist.
Definition: odimh5v20_classes.cpp:193
OdimH5 v2.0 Product_2D Dataset.
Definition: odimh5v20_classes.hpp:1786
virtual VILHeights getProdParVIL()
Get the value of 'prodpar' attribute as VILHeights pair.
Definition: odimh5v20_classes.cpp:2748
virtual double getProdPar()
Get the value of 'prodpar' attribute as double value.
Definition: odimh5v20_classes.cpp:2747
virtual int getQuantityDataCount()
Get number of quantities stored in the scan.
Definition: odimh5v20_classes.cpp:2915
virtual std::string getObject()
Get the value of 'object' attribute.
Definition: odimh5v20_classes.cpp:2711
virtual std::string getProduct()
Get the value of 'product' attribute.
Definition: odimh5v20_classes.cpp:2745
virtual Product_2D_Data * getQuantityData(int index)
Get the data associated to a quantity.
Definition: odimh5v20_classes.cpp:2982
std::set< std::string > getStoredQuantities()
Get the name of all quantities present in this scan.
Definition: odimh5v20_classes.cpp:2960
virtual time_t getDateTime()
Get the joined value of 'date' and 'time' attributes.
Definition: odimh5v20_classes.cpp:2715
OdimH5 v2.0 CAPPI Product Dataset.
Definition: odimh5v20_classes.hpp:2141
OdimH5 v2.0 PPI Product Dataset.
Definition: odimh5v20_classes.hpp:2115
Bottom and top heights (m) of the integration layer.
Definition: odimh5v20_support.hpp:418
double bottom
Lower value in meters.
Definition: odimh5v20_support.hpp:423
double top
Upper value in meters.
Definition: odimh5v20_support.hpp:427
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
std::string absoluteToString(time_t value)
, const char* fmt)
Definition: time.cpp:256
Main header file of the library.