static bool test_values() { bool result = true; const int M = 16; const int N = 32; Mda originalData; fill_mda(originalData, M, N); Mda toFill(originalData.N1(), originalData.N2()); Mda toFillSafe(originalData.N1(), originalData.N2()); for (int n = 0; n < N; ++n) { for (int m = 0; m < M; ++m) { toFill.set(originalData.get(m, n), m, n); if (!qFuzzyCompare(toFill.get(m, n), originalData.get(m, n))) result = false; toFillSafe.setValue(originalData.value(m, n), m, n); if (!qFuzzyCompare(toFill.value(m, n), originalData.value(m, n))) result = false; } } result = result && (0 == std::memcmp(toFill.dataPtr(), originalData.dataPtr(), toFill.totalSize() * sizeof(toFill.dataPtr()[0]))); result = result && (0 == std::memcmp(toFill.dataPtr(), toFillSafe.dataPtr(), toFill.totalSize() * sizeof(toFill.dataPtr()[0]))); return result; }
int main(int argc, char **argv) { OptionsCont &oc = OptionsCont::getOptions(); oc.setApplicationDescription("Importer of polygons and POIs for the road traffic simulation SUMO."); oc.setApplicationName("polyconvert", "SUMO polyconvert Version " + (std::string)VERSION_STRING); int ret = 0; try { // initialise subsystems XMLSubSys::init(false); fillOptions(); OptionsIO::getOptions(true, argc, argv); if (oc.processMetaOptions(argc < 2)) { SystemFrame::close(); return 0; } MsgHandler::initOutputOptions(); // build the projection Boundary origNetBoundary, pruningBoundary; Position2D netOffset; std::string proj; PCNetProjectionLoader::loadIfSet(oc, netOffset, origNetBoundary, pruningBoundary, proj); if (proj != "") { if (oc.isDefault("proj")) { oc.set("proj", proj); } if (oc.isDefault("x-offset-to-apply")) { oc.set("x-offset-to-apply", toString(netOffset.x())); } if (oc.isDefault("y-offset-to-apply")) { oc.set("y-offset-to-apply", toString(netOffset.y())); } } #ifdef HAVE_PROJ unsigned numProjections = oc.getBool("proj.simple") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + (oc.getString("proj").length() > 1); if ((oc.isSet("osm-files") || oc.isSet("dlr-navteq-poly-files") || oc.isSet("dlr-navteq-poi-files")) && numProjections == 0) { oc.set("proj.utm", true); } if ((oc.isSet("dlr-navteq-poly-files") || oc.isSet("dlr-navteq-poi-files")) && oc.isDefault("proj.shift")) { oc.set("proj.shift", std::string("5")); } #endif if (!GeoConvHelper::init(oc)) { throw ProcessError("Could not build projection!"); } // check whether the input shall be pruned bool prune = false; if (oc.getBool("prune.on-net")) { if (!oc.isSet("net")) { throw ProcessError("In order to prune the input on the net, you have to supply a network."); } bool ok = true; // !!! no proper error handling Boundary offsets = GeomConvHelper::parseBoundaryReporting(oc.getString("prune.on-net.offsets"), "--prune.on-net.offsets", 0, ok); pruningBoundary = Boundary( pruningBoundary.xmin()+offsets.xmin(), pruningBoundary.ymin()+offsets.ymin(), pruningBoundary.xmax()+offsets.xmax(), pruningBoundary.ymax()+offsets.ymax()); prune = true; } if (oc.isSet("prune.boundary")) { bool ok = true; // !!! no proper error handling pruningBoundary = GeomConvHelper::parseBoundaryReporting(oc.getString("prune.boundary"), "--prune.boundary", 0, ok); prune = true; } PCPolyContainer toFill(prune, pruningBoundary, oc.getStringVector("remove")); // read in the type defaults PCTypeMap tm; if (oc.isSet("typemap")) { PCTypeDefHandler handler(oc, tm); if (!XMLSubSys::runParser(handler, oc.getString("typemap"))) { // something failed throw ProcessError(); } } // read in the data PCLoaderXML::loadIfSet(oc, toFill, tm); // SUMO-XML PCLoaderOSM::loadIfSet(oc, toFill, tm); // OSM-XML PCLoaderDlrNavteq::loadIfSet(oc, toFill, tm); // Elmar-files PCLoaderVisum::loadIfSet(oc, toFill, tm); // VISUM PCLoaderArcView::loadIfSet(oc, toFill, tm); // shape-files // check whether any errors occured if (!MsgHandler::getErrorInstance()->wasInformed()) { // no? ok, save toFill.save(oc.getString("output")); } else { throw ProcessError(); } } catch (ProcessError &e) { if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { MsgHandler::getErrorInstance()->inform(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); ret = 1; #ifndef _DEBUG } catch (...) { MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); ret = 1; #endif } SystemFrame::close(); // report about ending if (ret==0) { std::cout << "Success." << std::endl; } return ret; }