Example #1
0
 Slot allocate_slot(Id id) {
     if (id > id_to_slot_map_.length()) id_to_slot_map_.resize(id);
     const Slot slot = (Slot) slot_to_id_map_.length();
     slot_to_id_map_.emplace_back(id);
     id_to_slot_map_[id - 1] = slot;
     return slot;
 }
Example #2
0
int DistanceTransform::inOrOut(const dynamic_array<int> &triList, const Point3f& vert, 
							   const Point3f& nearPnt)
{
	int i, j, len = triList.length();
	assert(len > 1);

	Point3f center, cpnt;
	Point3f v0, v1, v2;
	p_Surf->getTriVerts(triList[0], v0, v1, v2);
	double tnear = 1;
	int nearTri = 0;
	for(i = 0; i < 3; i++) {
		center[i] = (v0[i] + v1[i] + v2[i])/ 3;
		cpnt[i] = 0.9 * nearPnt[i] + 0.1 * center[i];
	}
	for(i = 1; i < len; i++) {
		double t = rayTriangleIntersection(triList[i], vert, cpnt);
		if(t < tnear) {
			tnear = t;
			nearTri = i;
		}
	}

	Vector3f trinorm;
	p_Surf->getTriNormal(triList[nearTri], trinorm);
	p_Surf->getTriVerts(triList[nearTri], v0, v1, v2);
	Vector3f diff = vert - v0;
	if (DotProduct(diff, trinorm) < 0) {
		return -1;
	}
	return 1;
}
Example #3
0
 Slot allocated_slot_count() const {
     return (Slot) slot_to_id_map_.length();
 }
Example #4
0
//!! this function doesn't work properly
int DistanceTransform::nearestPlane(const dynamic_array<int>& triList, const Point3f& vert)
{
	int i, j, len = triList.length();
	assert(len > 1);

	for (i = 0; i < len; i++) {
		Vector3f tnorm;
		Point3f v0, v1, v2;
		p_Surf->getTriNormal(triList[i], tnorm);
		p_Surf->getTriVerts(triList[i], v0, v1, v2);
		Vector3f diff = vert - v0;
		float dot = DotProduct(tnorm, diff);
		// it may be unstable if the vert is very close to the nearest corner
		const double TOLERANCE = 1.0e-6;
		if(fabs(dot) < TOLERANCE) {
			//printf("WARNING: ");
			continue;
		}
		bool nearest = true;
		for(j = 0; j < len; j++) {
			if (j == i) {
				continue;
			}
			Point3f anv0, anv1, anv2;
			p_Surf->getTriVerts(triList[j], anv0, anv1, anv2);
			float d0 = DotProduct(tnorm, anv0 - v0);
			float d1 = DotProduct(tnorm, anv1 - v0);
			float d2 = DotProduct(tnorm, anv2 - v0);
			float d;
			if(fabs(d0) > fabs(d1)) {
				if(fabs(d0) > fabs(d2)) {
					d = d0;
				} else {
					d = d2;
				}
			} else {
				if (fabs(d1) > fabs(d2)) {
					d = d1;
				} else {
					d = d2;
				}
			}
			if( d * dot > 0) {	// triangle i is not the nearest plane
				nearest = false;
				break;
			}
		}
		if (nearest) {
			return i;
		}

	}
	// should not come here
	printf("WARNING: trouble in finding the nearest plane\n");
/*
	for(i = 0; i < len; i++) {
		TriId3i tid3 = p_Surf->getTriId(triList[i]);
		printf("vert (%f %f %f) 's %dth triangle has vertices %d %d %d\n", vert[0], vert[1],
				vert[2], i, tid3[0], tid3[1], tid3[2]);
	}
*/	

	return 0;
}