Ejemplo n.º 1
0
VECTOR3 ButterflyTessellation(OBJECT *o, int e)
{
    int v0EdgeNum = FindEdge(o,o->EdgeList[e].v1,e);
    int v1EdgeNum = FindEdge(o,o->EdgeList[e].v2,e);

    VECTOR3 Buffer=V3_Make(0,0,0);

    int vert0 = o->EdgeList[e].v1;
    int vert1 = o->EdgeList[e].v2;
    int valence0 = o->VertexList[vert0].EdgeNum;
    int valence1 = o->VertexList[vert1].EdgeNum;

    if (valence0 == 6 && valence1 == 6)
    {
        getContributionToVert(o, vert0, v0EdgeNum, &Buffer);
        getContributionToVert(o, vert1, v1EdgeNum, &Buffer);
    }
    else if (valence0 == 6) getContributionToVert(o, vert1, v1EdgeNum, &Buffer);
    else if (valence1 == 6) getContributionToVert(o, vert0, v0EdgeNum, &Buffer);
    else
    {
        getContributionToVert(o, vert0, v0EdgeNum, &Buffer);
        getContributionToVert(o, vert1, v1EdgeNum, &Buffer);
        Buffer=V3_Mults(Buffer,0.5f);
    }

    return Buffer;
}
Ejemplo n.º 2
0
 EdgeIterator
 FindEdgeIndicateIfReverse(const NodeIterator from, const NodeIterator to, bool &result) const
 {
     EdgeIterator current_iterator = FindEdge(from, to);
     if (SPECIAL_NODEID == current_iterator)
     {
         current_iterator = FindEdge(to, from);
         if (SPECIAL_NODEID != current_iterator)
         {
             result = true;
         }
     }
     return current_iterator;
 }
Ejemplo n.º 3
0
Boolean Selection::ExtendToLeftEdge(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 where = FindEdge(text, layout, -1);
    ExtendSelection(text, where);
    return TRUE;
}
Ejemplo n.º 4
0
Boolean Selection::MoveToRightEdge(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 where = FindEdge(text, layout, 1);
    SetSelection(text, where);
    return TRUE;
}
Ejemplo n.º 5
0
CprsErr SuffixTree<Symb,NSymb>::Move(Count c, Symb* str, int& len, Range& rng)
{
	Edge e;
	FindEdge(e, c);
	CprsErr err = GetLabel(e, str, len);
	if(err) return err;
	GetRange(state, e, rng);
	Move(e);
	return CPRS_SUCCESS;
}
Ejemplo n.º 6
0
void SuffixTree<Symb,NSymb>::Move(Symb* str, int& len, Range& rng, Count& total)
{
	Edge e;
	FindEdge(e, str, len);
	len = GetLen(e);
	GetRange(state, e, rng);
	total = GetTotal(state);
	BHASSERT_WITH_NO_PERFORMANCE_IMPACT(rng.high <= total);
	Move(e);
}
Ejemplo n.º 7
0
/*
===============
AddEdge

===============
*/
static void
AddEdge(vec3_t p1, vec3_t p2)
{
    wedge_t *w;
    vec_t t1, t2;

    w = FindEdge(p1, p2, &t1, &t2);
    AddVert(w, t1);
    AddVert(w, t2);
}
Ejemplo n.º 8
0
/*
 * ===============
 * FixFaceEdges
 * 
 * ===============
 */
static void     FixFaceEdges(face_t* f)
{
    int             i;
    int             j;
    int             k;
    wedge_t*        w;
    wvert_t*        v;
    vec_t           t1;
    vec_t           t2;

    *superface = *f;

restart:
    for (i = 0; i < superface->numpoints; i++)
    {
        j = (i + 1) % superface->numpoints;

        w = FindEdge(superface->pts[i], superface->pts[j], &t1, &t2);

        for (v = w->head.next; v->t < t1 + T_EPSILON; v = v->next)
        {
        }

        if (v->t < t2 - T_EPSILON)
        {
            tjuncs++;
            // insert a new vertex here
            for (k = superface->numpoints; k > j; k--)
            {
                VectorCopy(superface->pts[k - 1], superface->pts[k]);
            }
            VectorMA(w->origin, v->t, w->dir, superface->pts[j]);
            superface->numpoints++;
            hlassume(superface->numpoints < MAX_SUPERFACEEDGES, assume_MAX_SUPERFACEEDGES);
            goto restart;
        }
    }

    if (superface->numpoints <= MAXPOINTS)
    {
        *f = *superface;
        f->next = newlist;
        newlist = f;
        return;
    }

    // the face needs to be split into multiple faces because of too many edges

    SplitFaceForTjunc(superface, f);

}
Ejemplo n.º 9
0
void MakeFace (brush_t* b, face_t *f)
{
	winding_t	*w;
	int			i;
	int			pnum[128];

	w = Brush_MakeFaceWinding (b, f);
	if (!w)
		return;
	for (i=0 ; i<w->numpoints ; i++)
		pnum[i] = FindPoint (w->points[i]);
	for (i=0 ; i<w->numpoints ; i++)
		FindEdge (pnum[i], pnum[(i+1)%w->numpoints], f);

	free (w);
}
Ejemplo n.º 10
0
void FixFaceEdges (face_t *f)
{
	int		i, j, k;
	wedge_t	*w;
	wvert_t	*v;
	vec_t	t1, t2;

	if( f->winding->numpoints > MAX_VERTS_ON_SUPERFACE )
		Error( "FixFaceEdges: f->winding->numpoints > MAX_VERTS_ON_SUPERFACE" );

	superface->original = *f;
	superface->numpoints = f->winding->numpoints;
	memcpy( superface->points, f->winding->points, sizeof(vec3_t)*f->winding->numpoints );
	FreeWinding( f->winding );

	// LordHavoc: FIXME: rewrite this mess to find points on edges,
	// rather than finding edges that run into polygons
restart:
	for (i=0 ; i < superface->numpoints ; i++)
	{
		j = (i+1)%superface->numpoints;

		w = FindEdge (superface->points[i], superface->points[j], &t1, &t2);
		if (!w)
			continue;

		for (v=w->head.next ; v->t < t1 + T_EPSILON ; v = v->next)
		{
		}

		if (v->t < t2-T_EPSILON)
		{
			c_tjuncs++;
		// insert a new vertex here
			for (k = superface->numpoints ; k> j ; k--)
				VectorCopy (superface->points[k-1], superface->points[k]);
			VectorMA (w->origin, v->t, w->dir, superface->points[j]);
			superface->numpoints++;
			goto restart;
		}
	}

	// the face might be split into multiple faces because of too many edges
	FaceFromSuperface( f );
}
Ejemplo n.º 11
0
csList<Edge*> psPathNetwork::FindEdgeRoute(Waypoint * start, Waypoint * end, const psPathNetwork::RouteFilter* routeFilter)
{
    csList<Edge*> edges;

    csList<Waypoint*> waypoints = FindWaypointRoute(start, end, routeFilter);
    csList<Waypoint*>::Iterator iter(waypoints);
    Waypoint* last = NULL;
    while (iter.HasNext())
    {
        Waypoint* wp = iter.Next();
        if (last)
        {
            Edge* edge = FindEdge(last,wp);
            edges.PushBack(edge);
        }

        last = wp;
    }
    return edges;
}
Ejemplo n.º 12
0
void MakeFace (face_t *f)
#endif
{
	winding_t	*w;
	int			i;
	int			pnum[128];

#ifdef NEWEDGESEL
	w = Brush_MakeFaceWinding (b, f);
#else
	w = Brush_MakeFaceWinding (selected_brushes.next, f);
#endif
	if (!w)
		return;
	for (i=0 ; i<w->numpoints ; i++)
		pnum[i] = FindPoint (w->points[i]);
	for (i=0 ; i<w->numpoints ; i++)
		FindEdge (pnum[i], pnum[(i+1)%w->numpoints], f);

	free (w);
}
Ejemplo n.º 13
0
void MakeFace (face_t * f)
#endif 
{
	idWinding	*w;
	int			i;
	int			pnum[128];

#ifdef NEWEDGESEL
	w = Brush_MakeFaceWinding(b, f);
#else
	w = Brush_MakeFaceWinding(selected_brushes.next, f);
#endif
	if (!w) {
		return;
	}
	for (i = 0; i < w->GetNumPoints(); i++) {
		pnum[i] = FindPoint( (*w)[i].ToVec3() );
	}
	for (i = 0; i < w->GetNumPoints(); i++) {
		FindEdge(pnum[i], pnum[(i + 1) % w->GetNumPoints()], f);
	}
	delete w;
}
Ejemplo n.º 14
0
void Mesh::CreateSVG(const std::string& filename) const {
  std::ofstream ostr(filename.c_str());
  ostr << "<body bgcolor=dddddd  onLoad=\"render()\" >\n";

  // a few checkboxes at the top of the page to control the visualization
  ostr << "<form name=\"orderForm\">\n";
  ostr << "   <input type=\"checkbox\" name=\"illegal\"   checked  "
       << " onClick=\"render()\">draw illegal (red) & next legal collapse (blue) edges<br>\n";
  ostr << "   <input type=\"checkbox\" name=\"wireframe\"          "
       << " onClick=\"render()\">draw all edges<br>\n";
  ostr << "   <input type=\"checkbox\" name=\"black\"              "
       << " onClick=\"render()\">toggle white vs. black<br>\n";
  ostr << "</form>\n";

  // javascript to actually change the visualization based on the checkboxes
  ostr << "<script language=\"JavaScript\">\n";
  ostr << "  function render() {\n";
  ostr << "    var mysvg = document.getElementById(\"mesh\");\n";
  ostr << "    if (document.orderForm.wireframe.checked == false) {\n";
  ostr << "      var polys = mysvg.children;\n";
  ostr << "      for (var i = 0; i < polys.length; i++) {\n";
  ostr << "        if (polys[i].tagName.toUpperCase() == \"POLYGON\") {\n";
  ostr << "          polys[i].style[\"strokeWidth\"] = \"0\"\n";
  ostr << "        }\n";
  ostr << "      }\n";
  ostr << "    } else if (document.orderForm.black.checked == false) {\n";
  ostr << "      var polys = mysvg.children;\n";
  ostr << "      for (var i = 0; i < polys.length; i++) {\n";
  ostr << "        if (polys[i].tagName.toUpperCase() == \"POLYGON\") {\n";
  ostr << "          polys[i].style.stroke = \"#FFFFFF\"\n";
  ostr << "          polys[i].style[\"strokeWidth\"] = \"1\"\n";
  ostr << "        }\n";
  ostr << "      }\n";
  ostr << "      mysvg.style.background = \"white\"\n";
  ostr << "    } else  {\n";
  ostr << "      var polys = mysvg.children;\n";
  ostr << "      for (var i = 0; i < polys.length; i++) {\n";
  ostr << "        if (polys[i].tagName.toUpperCase() == \"POLYGON\") {\n";
  ostr << "          polys[i].style.stroke = \"#000000\"\n";
  ostr << "          polys[i].style[\"strokeWidth\"] = \"2\"\n";
  ostr << "        }\n";
  ostr << "      }\n";
  ostr << "      mysvg.style.background = \"white\"\n";
  ostr << "    }\n";
  ostr << "    if (document.orderForm.illegal.checked == false) {\n";
  ostr << "      var polys = mysvg.children;\n";
  ostr << "      for (var i = 0; i < polys.length; i++) {\n";
  ostr << "        if (polys[i].tagName.toUpperCase() == \"LINE\") {\n";
  ostr << "          polys[i].style[\"strokeWidth\"] = \"0\"\n";
  ostr << "        }\n";
  ostr << "      }\n";
  ostr << "    } else  {\n";
  ostr << "      var polys = mysvg.children;\n";
  ostr << "      for (var i = 0; i < polys.length; i++) {\n";
  ostr << "        if (polys[i].tagName.toUpperCase() == \"LINE\") {\n";
  ostr << "          polys[i].style[\"strokeWidth\"] = \"5\"\n";
  ostr << "        }\n";
  ostr << "      }\n";
  ostr << "      mysvg.style.background = \"white\"\n";
  ostr << "    }\n";
  ostr << "  }\n";
  ostr << "</script>\n";

  ostr << "<svg  id=\"mesh\" height=\"" << height + 2*BORDER
       << "\" width=\""    << width + 2*BORDER
       << "\" style=\"background:white\" shape-rendering=\"crispEdges\">\n";

  // draw the triangles with the average color of the vertices
  for (triangles_set::const_iterator itr = triangles.begin(); itr != triangles.end(); itr++) {
    Triangle *t = *itr;
    float r = (t->getVertex(0)->r() +t->getVertex(1)->r() +t->getVertex(2)->r()) / 3.0;
    float g = (t->getVertex(0)->g() +t->getVertex(1)->g() +t->getVertex(2)->g()) / 3.0;
    float b = (t->getVertex(0)->b() +t->getVertex(1)->b() +t->getVertex(2)->b()) / 3.0;
    ostr << "<polygon points=\""
         << std::setw(8) << t->getVertex(0)->x() << "," << std::setw(8) << t->getVertex(0)->y() << "  "
         << std::setw(8) << t->getVertex(1)->x() << "," << std::setw(8) << t->getVertex(1)->y() << "  "
         << std::setw(8) << t->getVertex(2)->x() << "," << std::setw(8) << t->getVertex(2)->y()
         << "\" style=\"fill:#" << OutputColor(Vertex(0,0,r,g,b)) 
         << ";stroke:#" << OutputColor(Vertex(0,0,r,g,b)) 
         << ";stroke-width:1"
         << ";stroke-linecap:round\" "
         << ";stroke-linejoin:round\" "
         << "/>" << std::endl;
  }

  // draw the illegal edges in red
  for (edges_map::const_iterator itr = edges.begin(); itr != edges.end(); itr++) {
    const Edge *e = itr->second;
    assert (itr->first.first->getID() < itr->first.second->getID());
    if (!e->isLegal()) {
      ostr << "<line "
           << "x1=\"" << std::setw(8) << e->getV1()->x() << "\" "
           << "y1=\"" << std::setw(8) << e->getV1()->y() << "\" "
           << "x2=\"" << std::setw(8) << e->getV2()->x() << "\" " 
           << "y2=\"" << std::setw(8) << e->getV2()->y() << "\" "
           << " stroke=\"red\" "
           << " stroke-width=\"0\" "
           << " stroke-linecap=\"round\" "
           << "/>" << std::endl;
    }
  }

  // draw the next (legal) edge to collapse in blue
  Edge *e = FindEdge();
  if (e != NULL) {
    ostr << "<line "
         << "x1=\"" << std::setw(8) << e->getV1()->x() << "\" " 
         << "y1=\"" << std::setw(8) << e->getV1()->y() << "\" "
         << "x2=\"" << std::setw(8) << e->getV2()->x() << "\" " 
         << "y2=\"" << std::setw(8) << e->getV2()->y() << "\" "
         << " stroke=\"blue\" "
         << " stroke-width=\"0\" "
         << " stroke-linecap=\"round\" "
         << "/>" << std::endl;
  }
  
  ostr << "</svg>\n";

  // print some simple stats at the bottom of the page
  ostr << "<p>" << *this << "</p>" << std::endl;
  ostr << "</body>\n";
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        // enable logging
        if (argc < 3)
        {
            SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0]
                                             << " <osrm> <osrm.restrictions>";
            return -1;
        }

        SimpleLogger().Write() << "Using restrictions from file: " << argv[2];
        std::ifstream restriction_ifstream(argv[2], std::ios::binary);
        const FingerPrint fingerprint_orig;
        FingerPrint fingerprint_loaded;
        restriction_ifstream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));

        // check fingerprint and warn if necessary
        if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
        {
            SimpleLogger().Write(logWARNING) << argv[2] << " was prepared with a different build. "
                                                           "Reprocess to get rid of this warning.";
        }

        if (!restriction_ifstream.good())
        {
            throw osrm::exception("Could not access <osrm-restrictions> files");
        }
        uint32_t usable_restrictions = 0;
        restriction_ifstream.read((char *)&usable_restrictions, sizeof(uint32_t));
        restriction_list.resize(usable_restrictions);

        // load restrictions
        if (usable_restrictions > 0)
        {
            restriction_ifstream.read((char *)&(restriction_list[0]),
                                      usable_restrictions * sizeof(TurnRestriction));
        }
        restriction_ifstream.close();

        std::ifstream input_stream(argv[1], std::ifstream::in | std::ifstream::binary);
        if (!input_stream.is_open())
        {
            throw osrm::exception("Cannot open osrm file");
        }

        // load graph data
        std::vector<ImportEdge> edge_list;
        const NodeID number_of_nodes = readBinaryOSRMGraphFromStream(input_stream,
                                                                     edge_list,
                                                                     bollard_node_list,
                                                                     traffic_lights_list,
                                                                     &coordinate_list,
                                                                     restriction_list);
        input_stream.close();


        BOOST_ASSERT_MSG(restriction_list.size() == usable_restrictions,
                         "size of restriction_list changed");

        SimpleLogger().Write() << restriction_list.size() << " restrictions, "
                               << bollard_node_list.size() << " bollard nodes, "
                               << traffic_lights_list.size() << " traffic lights";

        traffic_lights_list.clear();
        traffic_lights_list.shrink_to_fit();

        // Building an node-based graph
        DeallocatingVector<TarjanEdge> graph_edge_list;
        for (const NodeBasedEdge &input_edge : edge_list)
        {
            if (input_edge.source == input_edge.target)
            {
                continue;
            }

            if (input_edge.forward)
            {
                graph_edge_list.emplace_back(input_edge.source,
                                       input_edge.target,
                                       (std::max)((int)input_edge.weight, 1),
                                       input_edge.name_id);
            }
            if (input_edge.backward)
            {
                graph_edge_list.emplace_back(input_edge.target,
                                       input_edge.source,
                                       (std::max)((int)input_edge.weight, 1),
                                       input_edge.name_id);
            }
        }
        edge_list.clear();
        edge_list.shrink_to_fit();
        BOOST_ASSERT_MSG(0 == edge_list.size() && 0 == edge_list.capacity(),
                         "input edge vector not properly deallocated");

        tbb::parallel_sort(graph_edge_list.begin(), graph_edge_list.end());
        auto graph = std::make_shared<TarjanDynamicGraph>(number_of_nodes, graph_edge_list);
        edge_list.clear();
        edge_list.shrink_to_fit();

        SimpleLogger().Write() << "Starting SCC graph traversal";

        RestrictionMap restriction_map(restriction_list);
        auto tarjan = osrm::make_unique<TarjanSCC<TarjanDynamicGraph>>(graph,
                                                                       restriction_map,
                                                                       bollard_node_list);
        tarjan->run();
        SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
                           << " many components";
        SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " SCCs of size 1";

        // output
        TIMER_START(SCC_RUN_SETUP);

        // remove files from previous run if exist
        DeleteFileIfExists("component.dbf");
        DeleteFileIfExists("component.shx");
        DeleteFileIfExists("component.shp");

        Percent p(graph->GetNumberOfNodes());

        OGRRegisterAll();

        const char *pszDriverName = "ESRI Shapefile";
        OGRSFDriver *poDriver =
            OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
        if (nullptr == poDriver)
        {
            throw osrm::exception("ESRI Shapefile driver not available");
        }
        OGRDataSource *poDS = poDriver->CreateDataSource("component.shp", nullptr);

        if (nullptr == poDS)
        {
            throw osrm::exception("Creation of output file failed");
        }

        OGRSpatialReference *poSRS = new OGRSpatialReference();
        poSRS->importFromEPSG(4326);

        OGRLayer *poLayer = poDS->CreateLayer("component", poSRS, wkbLineString, nullptr);

        if (nullptr == poLayer)
        {
            throw osrm::exception("Layer creation failed.");
        }
        TIMER_STOP(SCC_RUN_SETUP);
        SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP)/1000. << "s";

        uint64_t total_network_distance = 0;
        p.reinit(graph->GetNumberOfNodes());
        TIMER_START(SCC_OUTPUT);
        for (const NodeID source : osrm::irange(0u, graph->GetNumberOfNodes()))
        {
            p.printIncrement();
            for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
            {
                const TarjanDynamicGraph::NodeIterator target = graph->GetTarget(current_edge);

                if (source < target || graph->EndEdges(target) == graph->FindEdge(target, source))
                {
                    total_network_distance +=
                        100 * FixedPointCoordinate::ApproximateEuclideanDistance(
                                  coordinate_list[source].lat,
                                  coordinate_list[source].lon,
                                  coordinate_list[target].lat,
                                  coordinate_list[target].lon);

                    BOOST_ASSERT(current_edge != SPECIAL_EDGEID);
                    BOOST_ASSERT(source != SPECIAL_NODEID);
                    BOOST_ASSERT(target != SPECIAL_NODEID);

                    const unsigned size_of_containing_component =
                        std::min(tarjan->get_component_size(source),
                                 tarjan->get_component_size(target));

                    // edges that end on bollard nodes may actually be in two distinct components
                    if (size_of_containing_component < 1000)
                    {
                        OGRLineString lineString;
                        lineString.addPoint(coordinate_list[source].lon / COORDINATE_PRECISION,
                                            coordinate_list[source].lat / COORDINATE_PRECISION);
                        lineString.addPoint(coordinate_list[target].lon / COORDINATE_PRECISION,
                                            coordinate_list[target].lat / COORDINATE_PRECISION);

                        OGRFeature *poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());

                        poFeature->SetGeometry(&lineString);
                        if (OGRERR_NONE != poLayer->CreateFeature(poFeature))
                        {
                            throw osrm::exception("Failed to create feature in shapefile.");
                        }
                        OGRFeature::DestroyFeature(poFeature);
                    }
                }
            }
        }
        OGRSpatialReference::DestroySpatialReference(poSRS);
        OGRDataSource::DestroyDataSource(poDS);
        TIMER_STOP(SCC_OUTPUT);
        SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT)/1000. << "s";

        SimpleLogger().Write() << "total network distance: "
                               << (uint64_t)total_network_distance / 100 / 1000. << " km";

        SimpleLogger().Write() << "finished component analysis";
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
    }
    return 0;
}
Ejemplo n.º 16
0
static Bool
xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
{
    xf86EdgePtr edge;
    int tmp;

    if(screenInfo.numScreens == 1)
	return FALSE;

    if(*x < 0) {
        tmp = *y;
	if(tmp < 0) tmp = 0;
	if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1;

	if((edge = xf86ScreenLayout[(*pScreen)->myNum].left))
	   edge = FindEdge(edge, tmp);

	if(!edge) *x = 0;
	else {
	    *x += edge->offset.x;
	    *y += edge->offset.y;
	    *pScreen = xf86Screens[edge->screen]->pScreen;
	}
    }

    if(*x >= (*pScreen)->width) {
        tmp = *y;
	if(tmp < 0) tmp = 0;
	if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1;

	if((edge = xf86ScreenLayout[(*pScreen)->myNum].right))
	   edge = FindEdge(edge, tmp);

	if(!edge) *x = (*pScreen)->width - 1;
	else {
	    *x += edge->offset.x;
	    *y += edge->offset.y;
	    *pScreen = xf86Screens[edge->screen]->pScreen;
	}
    }

    if(*y < 0) {
        tmp = *x;
	if(tmp < 0) tmp = 0;
	if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1;

	if((edge = xf86ScreenLayout[(*pScreen)->myNum].up))
	   edge = FindEdge(edge, tmp);

	if(!edge) *y = 0;
	else {
	    *x += edge->offset.x;
	    *y += edge->offset.y;
	    *pScreen = xf86Screens[edge->screen]->pScreen;
	}
    }

    if(*y >= (*pScreen)->height) {
        tmp = *x;
	if(tmp < 0) tmp = 0;
	if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1;

	if((edge = xf86ScreenLayout[(*pScreen)->myNum].down))
	   edge = FindEdge(edge, tmp);

	if(!edge) *y = (*pScreen)->height - 1;
	else {
	    *x += edge->offset.x;
	    *y += edge->offset.y;
	    (*pScreen) = xf86Screens[edge->screen]->pScreen;
	}
    }


#if 0
    /* This presents problems for overlapping screens when
 	HardEdges is used.  Have to think about the logic more */
    if((*x < 0) || (*x >= (*pScreen)->width) || 
       (*y < 0) || (*y >= (*pScreen)->height)) {
	/* We may have crossed more than one screen */
	xf86CursorOffScreen(pScreen, x, y);
    }
#endif

    return TRUE;
}
Ejemplo n.º 17
0
 EdgeIterator FindEdgeInEitherDirection(const NodeIterator from, const NodeIterator to) const
 {
     EdgeIterator tmp = FindEdge(from, to);
     return (SPECIAL_NODEID != tmp ? tmp : FindEdge(to, from));
 }
Ejemplo n.º 18
0
// This function is symmetric wrt pMain and pOther. It sets up valid neighboring data for
// the relationship between both of them.
static void SetupEdgeNeighbors( 
	const CCoreDispInfo *pListBase,
	CCoreDispInfo *pMain, 
	CCoreDispInfo *pOther )
{
	// Initialize..
	for( int iEdge=0; iEdge < 4; iEdge++ )
	{
		// Setup the edge points and the midpoint.
		Vector pt[2], mid;
		pMain->GetSurface()->GetPoint( iEdge, pt[0] );
		pMain->GetSurface()->GetPoint( (iEdge + 1) & 3, pt[1] );
		mid = (pt[0] + pt[1]) * 0.5f;

		// Find neighbors.
		int iNBEdge;
		if( FindEdge( pOther, pt[1], pt[0], iNBEdge ) )
		{
			AddNeighbor( 
				pListBase, 
				pMain, iEdge, 0, CORNER_TO_CORNER, 
				pOther, iNBEdge, CORNER_TO_CORNER );
		}
		else
		{
			// Look for one that takes up our whole side.
			if( FindEdge( pOther, pt[1], pt[0]*2 - pt[1], iNBEdge ) )
			{
				AddNeighbor( 
					pListBase,
					pMain, iEdge, 0, CORNER_TO_CORNER, 
					pOther, iNBEdge, CORNER_TO_MIDPOINT );
			}
			else if( FindEdge( pOther, pt[1]*2 - pt[0], pt[0], iNBEdge ) )
			{
				AddNeighbor( 
					pListBase,
					pMain, iEdge, 0, CORNER_TO_CORNER, 
					pOther, iNBEdge, MIDPOINT_TO_CORNER );
			}
			else
			{			
				// Ok, look for 1 or two that abut this side.
				if( FindEdge( pOther, mid, pt[0], iNBEdge ) )
				{
					AddNeighbor( 
						pListBase,
						pMain, iEdge, g_bEdgeNeighborFlip[iEdge], CORNER_TO_MIDPOINT, 
						pOther, iNBEdge, CORNER_TO_CORNER );
				}
				
				if( FindEdge( pOther, pt[1], mid, iNBEdge ) )
				{
					AddNeighbor( 
						pListBase,
						pMain, iEdge, !g_bEdgeNeighborFlip[iEdge], MIDPOINT_TO_CORNER, 
						pOther, iNBEdge, CORNER_TO_CORNER );
				}
			}
		}
	}
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
    std::vector<osrm::extractor::QueryNode> coordinate_list;
    osrm::util::LogPolicy::GetInstance().Unmute();

    // enable logging
    if (argc < 2)
    {
        osrm::util::Log(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
        return EXIT_FAILURE;
    }

    std::vector<osrm::tools::TarjanEdge> graph_edge_list;
    auto number_of_nodes =
        osrm::tools::loadGraph(std::string(argv[1]), coordinate_list, graph_edge_list);

    tbb::parallel_sort(graph_edge_list.begin(), graph_edge_list.end());
    const auto graph = std::make_shared<osrm::tools::TarjanGraph>(number_of_nodes, graph_edge_list);
    graph_edge_list.clear();
    graph_edge_list.shrink_to_fit();

    osrm::util::Log() << "Starting SCC graph traversal";

    auto tarjan = std::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
    tarjan->Run();
    osrm::util::Log() << "identified: " << tarjan->GetNumberOfComponents() << " many components";
    osrm::util::Log() << "identified " << tarjan->GetSizeOneCount() << " size 1 SCCs";

    // output
    TIMER_START(SCC_RUN_SETUP);

    // remove files from previous run if exist
    osrm::tools::deleteFileIfExists("component.dbf");
    osrm::tools::deleteFileIfExists("component.shx");
    osrm::tools::deleteFileIfExists("component.shp");

    OGRRegisterAll();

    const char *psz_driver_name = "ESRI Shapefile";
    auto *po_driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(psz_driver_name);
    if (nullptr == po_driver)
    {
        throw osrm::util::exception("ESRI Shapefile driver not available" + SOURCE_REF);
    }
    auto *po_datasource = po_driver->CreateDataSource("component.shp", nullptr);

    if (nullptr == po_datasource)
    {
        throw osrm::util::exception("Creation of output file failed" + SOURCE_REF);
    }

    auto *po_srs = new OGRSpatialReference();
    po_srs->importFromEPSG(4326);

    auto *po_layer = po_datasource->CreateLayer("component", po_srs, wkbLineString, nullptr);

    if (nullptr == po_layer)
    {
        throw osrm::util::exception("Layer creation failed." + SOURCE_REF);
    }
    TIMER_STOP(SCC_RUN_SETUP);
    osrm::util::Log() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000. << "s";

    TIMER_START(SCC_OUTPUT);
    uint64_t total_network_length = 0;
    {
        osrm::util::UnbufferedLog log;
        log << "Constructing geometry ";
        osrm::util::Percent percentage(log, graph->GetNumberOfNodes());
        for (const NodeID source : osrm::util::irange(0u, graph->GetNumberOfNodes()))
        {
            percentage.PrintIncrement();
            for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
            {
                const auto target = graph->GetTarget(current_edge);

                if (source < target || SPECIAL_EDGEID == graph->FindEdge(target, source))
                {
                    total_network_length +=
                        100 * osrm::util::coordinate_calculation::greatCircleDistance(
                                  coordinate_list[source], coordinate_list[target]);

                    BOOST_ASSERT(current_edge != SPECIAL_EDGEID);
                    BOOST_ASSERT(source != SPECIAL_NODEID);
                    BOOST_ASSERT(target != SPECIAL_NODEID);

                    const unsigned size_of_containing_component =
                        std::min(tarjan->GetComponentSize(tarjan->GetComponentID(source)),
                                 tarjan->GetComponentSize(tarjan->GetComponentID(target)));

                    // edges that end on bollard nodes may actually be in two distinct components
                    if (size_of_containing_component < 1000)
                    {
                        OGRLineString line_string;
                        line_string.addPoint(static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[source].lon)),
                                             static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[source].lat)));
                        line_string.addPoint(static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[target].lon)),
                                             static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[target].lat)));

                        OGRFeature *po_feature =
                            OGRFeature::CreateFeature(po_layer->GetLayerDefn());

                        po_feature->SetGeometry(&line_string);
                        if (OGRERR_NONE != po_layer->CreateFeature(po_feature))
                        {
                            throw osrm::util::exception("Failed to create feature in shapefile." +
                                                        SOURCE_REF);
                        }
                        OGRFeature::DestroyFeature(po_feature);
                    }
                }
            }
        }
    }
    OGRSpatialReference::DestroySpatialReference(po_srs);
    OGRDataSource::DestroyDataSource(po_datasource);
    TIMER_STOP(SCC_OUTPUT);
    osrm::util::Log() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000. << "s";

    osrm::util::Log() << "total network distance: "
                      << static_cast<uint64_t>(total_network_length / 100 / 1000.) << " km";

    osrm::util::Log() << "finished component analysis";
    return EXIT_SUCCESS;
}
Ejemplo n.º 20
0
int FindEnds (StisInfo4 *sts, double length,
	double *v, short *qv, int nv,
	double crpix, double cdelt, int verbose,
	double *shift) {

/* arguments:
StisInfo4 *sts     i: calibration switches and info
double length      i: width of slit in spatial direction
double *v          i: array to be cross correlated with template of aperture
short *qv          i: data quality flags for v
int nv             i: size of v and qv arrays
double crpix       i: reference pixel in input data (zero indexed)
double cdelt       i: degrees per pixel
int verbose        i: print individual shifts?
double *shift      o: the shift, in pixels
*/

	int status;

	double scale;		/* arcseconds per pixel */
	double slit_end;	/* pixel location of end of slit */
	double sum;		/* for averaging the shifts */
	int nedges;		/* number of edges included in average */
	double locn0, locn;	/* estimated and actual location of an edge */
	double c7_shift;	/* shift in units of calstis7 pixels */
	double min_shift, max_shift;	/* min & max shifts */

	int FindEdge (StisInfo4 *,
		double *, short *, int, int, double, double *);

	scale = cdelt * ARCSEC_PER_DEGREE;

	/* Get the pixel location of the lower (or left) end of the slit. */
	slit_end = crpix - length / scale / 2.;

	/* Find each edge of the slit, and average the shifts. */
	sum = 0.;
	nedges = 0;

	/* lower edge of slit */
	locn0 = slit_end;
	if ((status = FindEdge (sts, v, qv, nv, LOW_TO_HIGH, locn0, &locn))) {
	    if (status == NO_GOOD_DATA)		/* not fatal yet */
		status = 0;
	    else
		return (status);		/* serious error */
	    if (verbose)
		printf ("         shift of lower edge is undetermined\n");
	} else {
	    nedges++;
	    sum += (locn - locn0);
	    if (verbose)
		printf ("         shift of lower edge is %.2f\n",
			(locn - locn0));
	    UpdateRange (nedges, locn - locn0, &min_shift, &max_shift);
	}

	/* upper edge of slit */
	locn0 = slit_end + length / scale;
	if ((status = FindEdge (sts, v, qv, nv, HIGH_TO_LOW, locn0, &locn))) {
	    if (status == NO_GOOD_DATA)
		status = 0;
	    else
		return (status);
	    if (verbose)
		printf ("         shift of upper edge is undetermined\n");
	} else {
	    nedges++;
	    sum += (locn - locn0);
	    if (verbose)
		printf ("         shift of upper edge is %.2f\n",
			(locn - locn0));
	    UpdateRange (nedges, locn - locn0, &min_shift, &max_shift);
	}

	if (CheckRange (nedges, min_shift, max_shift)) {
	    *shift = 0.;
	    return (NO_GOOD_DATA);
	}

	c7_shift = sum / (double)nedges;

	/* Convert the shift from calstis7 pixels to pixels in raw image. */
	*shift = c7_shift;

	return (0);
}
Ejemplo n.º 21
0
// Read a command from the CRS
uint8_t ReadCmd(void) {
	Command Cmd;
	uint32_t *NewNodeNames;
	pEdgeArray NewEdges;
	uint32_t i;
	pNode NewNode;
	pEdge NewEdge;
	pEdge ExistingEdge;
	uint8_t NodeCount;
	uint32_t *SPT;

	// read in the basic command header
	if (ReadBytes((unsigned char *)&Cmd, sizeof(Command)) != sizeof(Command)) {
		return(0);
	}

	if (Cmd.Action == CMD_SEND_NODES) {
		// read in the indicated number of Nodes
#ifdef PATCHED_1
		if ((Cmd.NumElements + NumNodes) > MAX_NODES) {
#else
		if (Cmd.NumElements > MAX_NODES) {
#endif
			ReadNull(sizeof(uint32_t)*Cmd.NumElements);
			SendErrorResponse(RESP_ERROR_TOO_MANY_NODES);
			return(0);
		}
		if ((NewNodeNames = (uint32_t *)calloc(sizeof(uint32_t)*Cmd.NumElements)) == NULL) {
			DestroyNodes();
			DestroyEdges();
			_terminate(1);
		}
		if (ReadBytes((unsigned char *)NewNodeNames, sizeof(uint32_t)*Cmd.NumElements) != sizeof(uint32_t)*Cmd.NumElements) {
			free(NewNodeNames);
			return(0);
		}

		// make sure none of the new node names exist already
		for (i = 0; i < Cmd.NumElements; i++) {
			if (FindNode(NewNodeNames[i]) != NULL) {
				free(NewNodeNames);
				SendErrorResponse(RESP_ERROR_DUPLICATE_NODE);
				return(0);
			}
		}

		// Create the new nodes 
		for (i = 0; i < Cmd.NumElements; i++) {
			// create a new node
			if ((NewNode = (pNode)calloc(sizeof(Node))) == NULL) {
				free(NewNodeNames);
				DestroyNodes();
				DestroyEdges();
				_terminate(1);
			}
			NewNode->Name = NewNodeNames[i];
			NewNode->Distance = SIZE_MAX;
			// Add it to the graph
			if (!AddNode(NewNode)) {
				free(NewNodeNames);
				DestroyNodes();
				DestroyEdges();
				_terminate(1);
			}
		}

		// done creating new nodes
		free(NewNodeNames);

	} else if (Cmd.Action == CMD_SEND_EDGES) {
		// read in the indicated number of Edges
		if ((Cmd.NumElements + NumEdges) > MAX_EDGES) {
			ReadNull(sizeof(EdgeArray)*Cmd.NumElements);
			SendErrorResponse(RESP_ERROR_TOO_MANY_EDGES);
			return(0);
		}
		if ((NewEdges = (pEdgeArray)calloc(sizeof(EdgeArray)*Cmd.NumElements)) == NULL) {
			DestroyNodes();
			DestroyEdges();
			_terminate(1);
		}
		if (ReadBytes((unsigned char *)NewEdges, sizeof(EdgeArray)*Cmd.NumElements) != sizeof(EdgeArray)*Cmd.NumElements) {
			free(NewEdges);
			return(0);
		}
		
		// Create the new edges 
		for (i = 0; i < Cmd.NumElements; i++) {
			// create a new Edge
			if ((NewEdge = (pEdge)calloc(sizeof(Edge))) == NULL) {
				free(NewEdges);
				DestroyNodes();
				DestroyEdges();
				_terminate(1);
			}
			// make sure the starting and ending nodes exist
			if ((NewEdge->NodeA = FindNode(NewEdges[i].NodeA)) == NULL) {
				SendErrorResponse(RESP_ERROR_INVALID_NODE);
				free(NewEdge);
				free(NewEdges);
				DestroyNodes();
				DestroyEdges();
				_terminate(1);
			}
			if ((NewEdge->NodeZ = FindNode(NewEdges[i].NodeZ)) == NULL) {
				SendErrorResponse(RESP_ERROR_INVALID_NODE);
				free(NewEdge);
				free(NewEdges);
				DestroyNodes();
				DestroyEdges();
				_terminate(1);
			}
			// offset the weight by a fixed magic_page-based value
			NewEdge->Weight = NewEdges[i].Weight + rand_page[NumNodes];

			// see if one already exists
			if ((ExistingEdge = FindEdge(NewEdge->NodeA, NewEdge->NodeZ)) != NULL) {
				if (ExistingEdge->Weight > NewEdge->Weight) {
					ExistingEdge->Weight = NewEdge->Weight;
				}

				// keep the existing edge
				free(NewEdge);
				continue;
			}

			// Add it to the graph
			if (!AddEdge(NewEdge)) {
				free(NewEdge);
				free(NewEdges);
				DestroyNodes();
				DestroyEdges();
				_terminate(1);
			}
		}

	} else if (Cmd.Action == CMD_RUN_SPT) {
		if ((SPT = FindSpt(Cmd.StartingNode, Cmd.EndingNode, &NodeCount)) == NULL) {
			// unable to find SPT
			SendErrorResponse(RESP_ERROR_SPT_FAIL);
			return(0);
		}
		SendResponse(RESP_NODE_SET, NodeCount, SPT);
		free(SPT);

	} else {
		SendErrorResponse(RESP_ERROR_INVALID_CMD);
		return(0);
	}

	return(1);
}
Real ComputeIntersection(const Real p[restrict], const int fid, const Polyhedron *poly,
        Real pi[restrict], Real N[restrict])
{
    const Real zero = 0.0;
    const Real one = 1.0;
    RealVec v0 = {zero}; /* vertices */
    RealVec v1 = {zero};
    RealVec v2 = {zero};
    RealVec e01 = {zero}; /* edges */
    RealVec e02 = {zero};
    RealVec para = {zero}; /* parametric coordinates */
    const IntVec v = {poly->f[fid][0], poly->f[fid][1], poly->f[fid][2]}; /* vertex index in vertex list */
    int e = 0; /* edge index in edge list */
    BuildTriangle(fid, poly, v0, v1, v2, e01, e02);
    const Real distSquare = PointTriangleDistance(p, v0, e01, e02, para);
    if (zero == para[1]) {
        if (zero == para[2]) {
            /* vertex 0 */
            for (int s = 0; s < DIMS; ++s) {
                pi[s] = v0[s];
                N[s] = poly->Nv[v[0]][s];
            }
        } else {
            if (one == para[2]) {
                /* vertex 2 */
                for (int s = 0; s < DIMS; ++s) {
                    pi[s] = v2[s];
                    N[s] = poly->Nv[v[2]][s];
                }
            } else {
                /* edge e02 */
                e = FindEdge(v[0], v[2], poly->edgeN, poly->e);
                for (int s = 0; s < DIMS; ++s) {
                    pi[s] = v0[s] + para[2] * e02[s];
                    N[s] = poly->Ne[e][s];
                }
            }
        }
    } else {
        if (one == para[1]) {
            /* vertex 1 */
            for (int s = 0; s < DIMS; ++s) {
                pi[s] = v1[s];
                N[s] = poly->Nv[v[1]][s];
            }
        } else {
            if (zero == para[2]) {
                /* edge e01 */
                e = FindEdge(v[0], v[1], poly->edgeN, poly->e);
                for (int s = 0; s < DIMS; ++s) {
                    pi[s] = v0[s] + para[1] * e01[s];
                    N[s] = poly->Ne[e][s];
                }
            } else {
                if (zero == para[0]) {
                    /* edge e12 */
                    e = FindEdge(v[1], v[2], poly->edgeN, poly->e);
                    for (int s = 0; s < DIMS; ++s) {
                        pi[s] = v0[s] + para[1] * e01[s] + para[2] * e02[s];
                        N[s] = poly->Ne[e][s];
                    }
                } else {
                    /* complete in the triangle */
                    for (int s = 0; s < DIMS; ++s) {
                        pi[s] = v0[s] + para[1] * e01[s] + para[2] * e02[s];
                        N[s] = poly->Nf[fid][s];
                    }
                }
            }
        }
    }
    return distSquare;
}