Exemplo n.º 1
0
void buildSO(double *so, const TTextureMesh &mesh,
			 const std::vector<PlasticHandle> &handles, int *faceHints)
{
	int v, vCount = mesh.verticesCount();

	// Build the interpolant function data
	const TRectD &bbox = mesh.getBBox();

	const double len = tmax(bbox.getLx(), bbox.getLy()), val = 1e-8;
	const double k = -log(val) / len;

	// Allocate / initialize arrays
	float *distances = (float *)malloc(vCount * sizeof(float));
	double *wSums = (double *)calloc(vCount, sizeof(double));

	memset(so, 0, vCount * sizeof(double));

	// Iterate handles - for each, add the corresponding interpolant
	int h, hCount = handles.size();
	for (h = 0; h != hCount; ++h) {
		const PlasticHandle &handle = handles[h];

		if (!buildDistances(distances, mesh, handle.m_pos, faceHints ? &faceHints[h] : 0))
			continue;

		for (v = 0; v != vCount; ++v) {
			double w = fabs(distances[v]);

			wSums[v] += w = exp(-k * w) / (1e-3 + w);
			so[v] += w * handle.m_so;
		}
	}

	// Normalize so values by the wSums
	for (v = 0; v != vCount; ++v)
		if (wSums[v] != 0.0)
			so[v] /= wSums[v];

	// Cleanup
	free(wSums);
	free(distances);
}
Exemplo n.º 2
0
bool buildDistances(float *distances, const TTextureMesh &mesh, const TPointD &pos,
					int *faceHint)
{
	using namespace local;

	// First off, find the face containing the specified vertex
	int localF = -1, &f = faceHint ? *faceHint : localF;

	if (f < 0 || f >= mesh.facesCount() || !mesh.faceContains(f, pos))
		f = mesh.faceContaining(pos);

	if (f < 0)
		return false;

	int vCount = mesh.verticesCount();

	// Prepare the interpolation builder
	UCHAR *colorMap = (UCHAR *)calloc(vCount, sizeof(UCHAR));
	BFS_DistanceBuilder visitor(distances, colorMap);

	DistanceGreater gr(distances);
	std::priority_queue<int, std::vector<int>, DistanceGreater> verticesQueue(gr);

	int v0, v1, v2;
	mesh.faceVertices(f, v0, v1, v2);

	// Prepare BFS data
	distances[v0] = distances[v1] = distances[v2] = 0.0f;

	verticesQueue.push(v0), colorMap[v0] = boost::gray_color;
	verticesQueue.push(v1), colorMap[v1] = boost::gray_color;

	// Launch BFS algorithm
	boost::breadth_first_visit((const Graph &)mesh, v2, verticesQueue, visitor, colorMap);

	free(colorMap);
	return true;
}
Exemplo n.º 3
0
 static inline bool hasNon1Rigidity(const TTextureMesh &mesh) {
   int v, vCount = int(mesh.verticesCount());
   for (v = 0; v != vCount; ++v)
     if (mesh.vertex(v).P().rigidity != 1.0) return true;
   return false;
 }