// Compute per-vertex normals
void TriMesh::need_normals()
{
	if (normals.size() == vertices.size())
		return;
	need_faces();

	dprintf(stderr, "Computing normals... "); dflush(stderr);

	normals.clear();
	normals.resize(vertices.size());

	int nf = faces.size(), nv = vertices.size(), i;
	for (i = 0; i < nf; i++) {
		const point &p0 = vertices[faces[i][0]];
		const point &p1 = vertices[faces[i][1]];
		const point &p2 = vertices[faces[i][2]];
		vec a = p0-p1, b = p1-p2, c = p2-p0;
		float l2a = len2(a), l2b = len2(b), l2c = len2(c);
		vec facenormal = a CROSS b;
		normals[faces[i][0]] += facenormal * (1.0f / (l2a * l2c));
		normals[faces[i][1]] += facenormal * (1.0f / (l2b * l2a));
		normals[faces[i][2]] += facenormal * (1.0f / (l2c * l2b));
	}

	for (i = 0; i < nv; i++)
		normalize(normals[i]);

	dprintf(stderr, "Done.\n");
}
int isProperPipe(char** args){
	int size = len2(args);
	if(countPipes(args) != 1){	//Only a single pipe symbol for 2-stage pipeline
		return 0;
	}
	if(compareStrings(args[0], "|")|| compareStrings(args[size - 1], "|")){
		return 0;				//Make sure pipes aren't in front or back.
	}
	return 1;
}
Example #3
0
void Vector3Util::Clamp(Vector3& vect,Scalar length)
{
    Scalar vecLength = len2(vect);

    if(vecLength <= length * length)
    {
        return;
    }

    vect *= length / sqrt(vecLength);
}
Example #4
0
void Vector3Util::Normalize_s(Vector3& vect)
{
    Scalar vecLength = len2(vect);

    if(vecLength == 0)
    {
        return;
    }

    vect /= sqrt(vecLength);
}
Example #5
0
int main()
{

    printf("Length is %d \n", len(myarray, "char") );

    printf("Length is %d \n", len2(myarray) );


    return 0;

}
/*
int isRedirection()
	Description:
		Tells whether or not a command uses redirections.
	args:
		char** args
			Array of tokens
	return:
		1 if redirections, 0 elsewise.
*/
int isRedirection(char** args){
	
	for(int i = 0; i < len2(args); i++){
		if(args[i][0] == '>' || args[i][0] == '<'){
			return 1;
		}else{
			continue;
		}
	}
	return 0;	
}
Example #7
0
void Vector3Util::SetLength_s(Vector3& vect, Scalar length)
{
    Scalar vecLength = len2(vect);

    if(vecLength == 0)
    {
        return;
    }

    vect *= length / sqrt(vecLength);
}
/*
int isProperRedirection()
	Description:
		Tells whether or not a command is a functioning redirection.
	args:
		char** args
			Array of tokens
	return:
		1 if true, 0 if false.
*/
int isProperRedirection(char** args){
	int size = len2(args);
	if(countRedirections(args) > 2){
		return 0;
	}
	if(compareStrings(args[0],"<") || compareStrings(args[0],">") || 
	   compareStrings(args[size - 1],"<") || compareStrings(args[size - 1],">"))
	{
		return 0;
	}
	return 1;
}
Example #9
0
Vector3 Vector3Util::ToNormalized_s(const Vector3& vect)
{
    Scalar vecLength = len2(vect);

    if(vecLength == 0)
    {
        return vect;
    }

    vecLength = sqrt(vecLength);

    return Vector3(vect.x / vecLength, vect.y / vecLength, vect.z / vecLength);
}
int main()
{
	struct node *start1;
	struct node *start2;
	int l1,l2,x;
	start1=inputList1();
	start2=inputList2();
	l1=len1(start1);
	l2=len2(start2);
	x=findintersection(start1, l1, start2, l2);
	if(x==0)
		printf("\nNo intersection point between the two given lists\n");
	else
		printf("\nIntersection node is %d\n", x);
}
Example #11
0
 float len2( const moon9::vec3 &a, const moon9::vec3 &b )
 {
     return len2( b - a );
 }
Example #12
0
	double len()
	{
		return sqrt(len2());
	}
Example #13
0
// square of distance between two vectors
pType dis2(const Point & p, const Point & q) { return len2(p - q); }
Example #14
0
// Smooth the mesh geometry.
// XXX - this is perhaps not a great way to do this,
// but it seems to work better than most other things I've tried...
void smooth_mesh(TriMesh *themesh, float sigma)
{
	themesh->need_faces();
	diffuse_normals(themesh, 0.5f * sigma);
	int nv = themesh->vertices.size();
	int nf = themesh->faces.size();

	dprintf("\rSmoothing... ");
	timestamp t = now();

	float invsigma2 = 1.0f / sqr(sigma);

	vector<point> dflt(nv), dflt2(nv);
#pragma omp parallel
	{
		// Thread-local flags
		vector<unsigned> flags(nv);
		unsigned flag_curr = 0;

		// Main filtering step
#pragma omp for
		for (int i = 0; i < nv; i++) {
			diffuse_vert_field(themesh, flags, flag_curr,
				AccumVec<vec>(themesh->vertices),
				i, invsigma2, dflt[i]);
			// Just keep the displacement
			dflt[i] -= themesh->vertices[i];
		}

		// Slightly better small-neighborhood approximation
#pragma omp for
		for (int i = 0; i < nf; i++) {
			point c = themesh->vertices[themesh->faces[i][0]] +
				  themesh->vertices[themesh->faces[i][1]] +
				  themesh->vertices[themesh->faces[i][2]];
			c /= 3.0f;
			for (int j = 0; j < 3; j++) {
				int v = themesh->faces[i][j];
				vec d = 0.5f * (c - themesh->vertices[v]);
				dflt[v] += themesh->cornerareas[i][j] /
					   themesh->pointareas[themesh->faces[i][j]] *
					   exp(-0.5f * invsigma2 * len2(d)) * d;
			}
		}

		// Filter displacement field
#pragma omp for
		for (int i = 0; i < nv; i++) {
			diffuse_vert_field(themesh, flags, flag_curr,
				AccumVec<point>(dflt),
				i, invsigma2, dflt2[i]);
		}

		// Update vertex positions
#pragma omp for
		for (int i = 0; i < nv; i++)
			themesh->vertices[i] += dflt[i] - dflt2[i]; // second Laplacian
	} // #pragma omp parallel

	dprintf("Done.  Filtering took %f sec.\n", now() - t);
}
Example #15
0
float Vector2::len() const {
	return sqrt(len2());
}
Example #16
0
	float len() const{  return sqrtf( len2() ); }; 
Example #17
0
	const T len() const noexcept
	{
		return sqrt(len2());
	}