void DirectProcess11(
    std::vector<BinData2<1,3> >& data, const NCell& c1, const Cell& c2,
    const double dsq, const Position2D& r)
{
    xdbg<<std::string(recursen+1,'-')<<"Direct: d = "<<sqrt(dsq)<<std::endl;
    XAssert(c1.getSize()+c2.getSize() < sqrt(dsq)*b + 0.0001);
    XAssert(std::abs(c2.getMeanPos() - c1.getMeanPos() - r) < 0.0001);
    XAssert(std::abs(dsq - std::norm(r)) < 0.0001);

    Assert(dsq >= minsepsq);
    Assert(dsq < maxsepsq);

    std::complex<double> cr(r.getX(),r.getY());
    const std::complex<double> expm2iarg = SQR(conj(cr))/dsq;

    const double logr = log(dsq)/2.;
    Assert(logr >= logminsep);

    const int k = int(floor((logr - logminsep)/binsize));
    Assert(k >= 0); Assert(k<int(data.size()));

    const double nw = c1.getN()*c2.getWeight();
    const std::complex<double> net = -double(c1.getN())*c2.getWE()*expm2iarg;
    const double npairs = c1.getN()*c2.getN();

    BinData2<1,3>& crossbin = data[k];
    crossbin.meangammat += net;
    crossbin.weight += nw;
    crossbin.meanlogr += nw*logr;
    crossbin.npair += npairs;
}
Exemple #2
0
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();
}
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;
}
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();
    }
}
void
Line2D::rotateAtP1(SUMOReal rot) {
    Position2D p = myP2;
    p.sub(myP1);
    p.reshiftRotate(0, 0, rot);
    p.add(myP1);
    myP2 = p;
}
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);
}
// ===========================================================================
// 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());
}
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());
}
void GameEntity::_move(Position2D newPosition, bool lockInWindowScreen)
{
    float x = newPosition.getX();
    float y = newPosition.getY();

    if (lockInWindowScreen)
    {
        _width = this->getINDIEntity()->getRegionWidth() / 2 - 18;
        _height = this->getINDIEntity()->getRegionHeight() / 2 - 15;

        if (x + _width > _masterInstance->_window->getWidth())
            x = _masterInstance->_window->getWidth() - _width;
        if (x - _width < 0)
            x = 0 + _width;
        if (y + _height > _masterInstance->_window->getHeight())
            y = _masterInstance->_window->getHeight() - _height;
        if (y - _height < 0)
            y = _height;
    }

    this->setPosition(Position3D(x, y, this->getPosition().getZ()));
}
void DirectProcess11(
    std::vector<BinData2<3,3> >& data, const Cell& c1, const Cell& c2,
    const double dsq, const Position2D& r)
{
    XAssert(c1.getSize()+c2.getSize() < sqrt(dsq)*b + 0.0001);
    XAssert(Dist(c2.getMeanPos() - c1.getMeanPos(),r) < 0.0001);
    XAssert(std::abs(dsq - DistSq(c1.getMeanPos(),c2.getMeanPos())) < 0.0001);

    Assert(dsq > minsepsq);
    Assert(dsq < maxsepsq);

    std::complex<double> cr(r.getX(),r.getY());
    std::complex<double> expm4iarg = conj(cr*cr)/dsq; // now expm2iarg
    expm4iarg *= expm4iarg; // now expm4iarg

    const double logr = log(dsq)/2.;
    Assert(logr >= logminsep);

    const int k = int(floor((logr - logminsep)/binsize));
    Assert(k >= 0); Assert(k<int(data.size()));

    const double ww = c1.getWeight()*c2.getWeight();
    const std::complex<double> e1 = c1.getWE();
    const std::complex<double> e2 = c2.getWE();

    const std::complex<double> ee = e1*e2*expm4iarg;
    const std::complex<double> eec = e1*conj(e2);

    const double npairs = c1.getN()*c2.getN();

    BinData2<3,3>& bindata = data[k];
    bindata.xiplus += eec;
    bindata.ximinus += ee;
    bindata.weight += ww;
    bindata.meanlogr += ww*logr;
    bindata.npair += npairs;

    ++bincount[k];
}
Exemple #11
0
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;
}
void
Line2D::add(const Position2D &p) {
    myP1.add(p.x(), p.y());
    myP2.add(p.x(), p.y());
}