Exemple #1
0
v_data *delaunay_triangulation(double *x, double *y, int n)
{
    v_data *delaunay;
    GtsSurface* s = tri(x, y, n, NULL, 0, 1);
    int i, nedges;
    int* edges;
    estats stats;

    if (!s) return NULL;

    delaunay = N_GNEW(n, v_data);

    for (i = 0; i < n; i++) {
	delaunay[i].ewgts = NULL;
	delaunay[i].nedges = 1;
    }

    stats.n = 0;
    stats.delaunay = delaunay;
    edgeStats (s, &stats);
    nedges = stats.n;
    edges = N_GNEW(2 * nedges + n, int);

    for (i = 0; i < n; i++) {
	delaunay[i].edges = edges;
	edges += delaunay[i].nedges;
	delaunay[i].edges[0] = i;
	delaunay[i].nedges = 1;
    }
    gts_surface_foreach_edge (s, (GtsFunc) add_edge, delaunay);

    gts_object_destroy (GTS_OBJECT (s));

    return delaunay;
}
Exemple #2
0
/* delaunay_tri:
 * Given n points whose coordinates are in the x[] and y[]
 * arrays, compute a Delaunay triangulation of the points.
 * The number of edges in the triangulation is returned in pnedges.
 * The return value itself is an array e of 2*(*pnedges) integers,
 * with edge i having points whose indices are e[2*i] and e[2*i+1].
 *
 * If the points are collinear, GTS fails with 0 edges.
 * In this case, we sort the points by x coordinates (or y coordinates
 * if the points form a vertical line). We then return a "triangulation"
 * consisting of the n-1 pairs of adjacent points.
 */
int *delaunay_tri(double *x, double *y, int n, int* pnedges)
{
    GtsSurface* s = tri(x, y, n, NULL, 0, 1);
    int nedges;
    int* edges;
    estats stats;
    estate state;

    if (!s) return NULL;

    stats.n = 0;
    stats.delaunay = NULL;
    edgeStats (s, &stats);
    *pnedges = nedges = stats.n;

    if (nedges) {
	edges = N_GNEW(2 * nedges, int);
	state.n = 0;
	state.edges = edges;
	gts_surface_foreach_edge (s, (GtsFunc) addEdge, &state);
    }
    else {
Exemple #3
0
		// Calculate a edge stats for the two groups based on the indexes passed in
		std::vector<std::shared_ptr<Edge>> CalcEdgeComparison(std::vector<int> &idxs, size_t szGrp1)
		{
			auto &edges = _edges;

			// TODO: Probably need to make this thread safe
			std::vector<std::shared_ptr<Edge>> edgeStats(_edgeCount);

			//for(int edgeIndex=0; edgeIndex<_edgeCount; edgeIndex++)
			con::parallel_for((size_t)0, _edgeCount, [=, &idxs, &edgeStats, &edges](int edgeIndex)
			{
				// Pull out a view of the subject values for a single edge
				auto &edgeValues = edges[edgeIndex];

				TStatCalc calcEdgeValue;

				// Loop through the vals we were passed
				for (size_t idx = 0; idx < _subjectCount; ++idx)
				{
					double edgeVal = edgeValues[idxs[idx]]->Value;

					if (idx < szGrp1)
						calcEdgeValue.IncludeValue(0, edgeVal);
					else
						calcEdgeValue.IncludeValue(1, edgeVal);
				}

				auto edge = std::make_shared<Edge>();

				edge->Index = edgeIndex;
				edge->Nodes = _lu->GetEdge(edgeIndex);
				edge->Stats = calcEdgeValue.Calculate();

				edgeStats[edgeIndex] = edge;
			});

			return edgeStats;
		}