예제 #1
0
/*
** inserts a new key into a hash table; first, check whether key's main
** position is free. If not, check whether colliding node is in its main
** position or not: if it is not, move colliding node to an empty place and
** put new key in its main position; otherwise (colliding node is in its main
** position), new key goes to an empty position.
*/
static TableNode*
table_newkey(Table *t, uint32_t key) {
    TableNode *mp = mainposition(t, key);
    if(!tisnil(mp)) {
        TableNode *n = getfreenode(t);
        if(n == NULL) {
            table_expand(t);
            return table_newkey(t, key);
        }
        TableNode *othern = mainposition(t, mp->key);
        if (othern != mp) {
            int mindex = tindex(t, mp);
            while(othern->next != mindex) {
                othern = tnode(t, othern->next);
            }
            othern->next = tindex(t, n);
            *n = *mp;
            initnode(mp);
        } else {
            n->next = mp->next;
            mp->next = tindex(t, n);
            mp = n;
        }
    }
    mp->key = key;
    mp->flag = 'n';
    return mp;
}
예제 #2
0
void EditorData::pushNewTargetNodeToRoute(QPointF pos)
{
    // Push location to the route
    TargetNodePtr tnode(new TargetNode);
    tnode->setLocation(pos);
    pushTargetNodeToRoute(tnode);
}
예제 #3
0
static TableNode*
table_get(Table *t, uint32_t key) {
    TableNode *n = mainposition(t, key);
    while(!tisnil(n)) {
        if(n->key == key) {
            return n;
        }
        if(n->next < 0) {
            break;
        }
        n = tnode(t, n->next);
    }
    return NULL;
}
예제 #4
0
void DeformationGraph::GenerateRandomNodes()
{
	std::list<PointWithID> pointcoll;
	// compute the sampledelta.
	const double samplelamada = 0.62; // this is a magic num, should not be modified.
	double surfacearea = dmesh.surfaceArea();
	int sizeOfVertices = dmesh.pMesh->n_vertices();
	double sampledelta = sqrt(surfacearea / (samplelamada * samplescale * sizeOfVertices));
	// sample points on surface.
	GenerateDensePointSet(pointcoll, sampledelta);
	// compute the deleteradius.
	const double pi = acos(-1.0);
	const double deleteradius = sqrt(surfacearea / pi / deletearearate);
	// generate nodes.
	edges.reserve(nodenum);
#ifdef DEBUGTRACE
	meshtalent::DebugTrace dt("./pointleft.log");
#endif
	RandUIntGenerator bigrand; 
	bigrand.srand(time(NULL));
	for (int i = 0; i < nodenum; ++i) {
		// adjust nodenum automatically.
		if (pointcoll.empty()) {
			const_cast<int&>(nodenum) = i;
			break;
		}
#ifdef DEBUGTRACE
		dt.Trace("%d\n", pointcoll.size());
#endif
		// randomly select a point.
		int ranindex = bigrand() % static_cast<long>(pointcoll.size());
		std::list<PointWithID>::iterator it = pointcoll.begin();
		advance(it, ranindex);
		// add to Graph.
		GraphNode tnode(it->p, i);
		switch (it->from) {
		case PointWithID::VERTEX:
			tnode.vertexID = it->id;
			break;
		case PointWithID::EDGE:
			moveFromEdgeToVertex(&tnode, *it);
			break;
		case PointWithID::FACE:
			moveFromFaceToVertex(&tnode, *it);
			break;
		default:
			assert(false);
			break;
		}
		edges.push_back(make_pair(tnode, std::vector<int>()));
		pointcoll.remove_if(WithinCircle(it->p, deleteradius)); // remove nearby points.
	}

#ifndef NDEBUG
	// assert the distance between each two Graph nodes is larger than radius.
	for (int i = 0; i < static_cast<int>(edges.size()); ++i) {
		for (int j = i + 1; j < static_cast<int>(edges.size()); ++j) {
			//assert((edges[i].first.g - edges[j].first.g).mag() >= deleteradius);
		}
	}
#endif
	
}