コード例 #1
0
SUMOTime
MSVTypeProbe::execute(SUMOTime currentTime) throw(ProcessError) {
    const std::string indent("    ");
    myOutputDevice << indent << "<timestep time=\"" <<time2string(currentTime)<< "\" id=\"" << getID() << "\" vtype=\"" << myVType << "\">" << "\n";
    MSVehicleControl &vc = MSNet::getInstance()->getVehicleControl();
    std::map<std::string, MSVehicle*>::const_iterator it = vc.loadedVehBegin();
    std::map<std::string, MSVehicle*>::const_iterator end = vc.loadedVehEnd();
    for (; it != end; ++it) {
        const MSVehicle *veh=(*it).second;
        if (myVType=="" || myVType==veh->getVehicleType().getID()) {
            if (!veh->isOnRoad()) {
                continue;
            }
            Position2D pos = veh->getPosition();
            myOutputDevice << indent << indent
            << "<vehicle id=\"" << veh->getID()
            << "\" lane=\"" << veh->getLane().getID()
            << "\" pos=\"" << veh->getPositionOnLane()
            << "\" x=\"" << pos.x()
            << "\" y=\"" << pos.y();
            if (GeoConvHelper::usingGeoProjection()) {
                GeoConvHelper::cartesian2geo(pos);
                myOutputDevice.setPrecision(GEO_OUTPUT_ACCURACY);
                myOutputDevice << "\" lat=\"" << pos.y() << "\" lon=\"" << pos.x();
                myOutputDevice.setPrecision();
            }
            myOutputDevice << "\" speed=\"" << veh->getSpeed() << "\"/>" << "\n";
        }

    }
    myOutputDevice << indent << "</timestep>" << "\n";
    return myFrequency;
}
コード例 #2
0
// ===========================================================================
// method definitions
// ===========================================================================
GUIJunctionWrapper::GUIJunctionWrapper(GUIGlObjectStorage &idStorage,
                                       MSJunction &junction) throw()
        : GUIGlObject(idStorage, "junction:"+junction.getID()),
        myJunction(junction) {
    if (myJunction.getShape().size()==0) {
        Position2D pos = myJunction.getPosition();
        myBoundary = Boundary(pos.x()-1., pos.y()-1., pos.x()+1., pos.y()+1.);
    } else {
        myBoundary = myJunction.getShape().getBoxBoundary();
    }
    myMaxSize = MAX2(myBoundary.getWidth(), myBoundary.getHeight());
}
コード例 #3
0
void
GUIJunctionWrapper::drawGL(const GUIVisualizationSettings &s) const throw() {
    // check whether it is not too small
    if (s.scale*myMaxSize<1.) {
        return;
    }
    // (optional) set id
    if (s.needsGlID) {
        glPushName(getGlID());
    }
    glColor3d(0, 0, 0);
    glTranslated(0, 0, .01);
    GLHelper::drawFilledPoly(myJunction.getShape(), true);
    glTranslated(0, 0, -.01);
    // (optional) draw name
    if (s.drawJunctionName) {
        glPushMatrix();
        glTranslated(0, 0, -.06);
        Position2D p = myJunction.getPosition();
        glTranslated(p.x(), p.y(), 0);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        pfSetPosition(0, 0);
        pfSetScale(s.junctionNameSize / s.scale);
        glColor3d(s.junctionNameColor.red(), s.junctionNameColor.green(), s.junctionNameColor.blue());
        SUMOReal w = pfdkGetStringWidth(getMicrosimID().c_str());
        glRotated(180, 1, 0, 0);
        glTranslated(-w/2., 0.4, 0);
        pfDrawString(getMicrosimID().c_str());
        glPopMatrix();
    }
    // (optional) clear id
    if (s.needsGlID) {
        glPopName();
    }
}
コード例 #4
0
ファイル: GUIE3Collector.cpp プロジェクト: NeziheSozen/sumo
void
GUIE3Collector::MyWrapper::drawSingleCrossing(const Position2D &pos,
        SUMOReal rot, SUMOReal upscale) const {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glPushMatrix();
    glScaled(upscale, upscale, 1);
    glTranslated(pos.x(), pos.y(), 0);
    glRotated(rot, 0, 0, 1);
    glBegin(GL_LINES);
    glVertex2d(1.7, 0);
    glVertex2d(-1.7, 0);
    glEnd();
    glBegin(GL_QUADS);
    glVertex2d(-1.7, .5);
    glVertex2d(-1.7, -.5);
    glVertex2d(1.7, -.5);
    glVertex2d(1.7, .5);
    glEnd();
    // arrows
    glTranslated(1.5, 0, 0);
    GUITexturesHelper::drawDirectionArrow(TEXTURE_LINKDIR_STRAIGHT, 1.0);
    glTranslated(-3, 0, 0);
    GUITexturesHelper::drawDirectionArrow(TEXTURE_LINKDIR_STRAIGHT, 1.0);
    glPopMatrix();
}
コード例 #5
0
void
Line2D::rotateAround(const Position2D &at, SUMOReal rot) {
    myP1.add(-at.x(), -at.y());
    myP2.add(-at.x(), -at.y());
    {
        SUMOReal x = myP1.x() * cos(rot) + myP1.y() * sin(rot);
        SUMOReal y = myP1.y() * cos(rot) - myP1.x() * sin(rot);
        myP1 = Position2D(x, y);
    }
    {
        SUMOReal x = myP2.x() * cos(rot) + myP2.y() * sin(rot);
        SUMOReal y = myP2.y() * cos(rot) - myP2.x() * sin(rot);
        myP2 = Position2D(x, y);
    }
    myP1.add(at.x(), at.y());
    myP2.add(at.x(), at.y());
}
コード例 #6
0
Position2D
NIImporter_OpenDrive::calculateStraightEndPoint(double hdg, double length, const Position2D &start) throw() {
    double normx = 1.0f;
    double normy = 0.0f;
    double x2 = normx * cos(hdg) - normy * sin(hdg);
    double y2 = normx * sin(hdg) + normy * cos(hdg);
    normx = x2 * length;
    normy = y2 * length;
    return Position2D(start.x() + normx, start.y() + normy);
}
コード例 #7
0
ファイル: polyconvert_main.cpp プロジェクト: NeziheSozen/sumo
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;
}
コード例 #8
0
void
Line2D::add(const Position2D &p) {
    myP1.add(p.x(), p.y());
    myP2.add(p.x(), p.y());
}