bool Foam::correlationFunction<Type>::writeAveraged(Ostream& os) const
{
    Field<scalar> averageCF(averaged());

    forAll(averageCF, v)
    {
        os  << v*sampleInterval()
            << token::SPACE
            << averageCF[v]
            << nl;
    }
Example #2
0
std::vector<float> PlaneGenerator::genNormals(int width, int height) const {

	std::vector<glm::vec3> averaged(vertices_.size() / 3);
	glm::vec3 vert[3];
	unsigned ind[3];

	auto it = ++indices_.begin();
	for(int i = 0; i < 3; ++i) {
		ind[i] = *it++;
		vert[i] = getVert(ind[i]);
	}

	for(; it != indices_.end();) {
		glm::vec3 normal = glm::cross(vert[0] - vert[1], vert[0] - vert[2]);
		normal = glm::normalize(normal);

		for(int i = 0; i < 3; ++i) {
			averaged[ind[i]] += normal;
		}

		vert[0] = vert[1];
		vert[1] = vert[2];

		ind[0] = ind[1];
		ind[1] = ind[2];
		if(ind[2] % height == (height - 1) && ind[2] > height && *it < (width * height - 1)) {
			++(++(++it));
		}
		ind[2] = *it++;
		vert[2] = getVert(ind[2]);

	}

	std::vector<float> normals;
	normals.reserve(vertices_.size());
	for(auto& avg : averaged) {
		avg = glm::normalize(avg);

		normals.push_back(avg.x);
		normals.push_back(avg.y);
		normals.push_back(avg.z);
	}

	return normals;
}
Example #3
0
File: kz.c Project: cran/kza
SEXP kz3d(SEXP x, SEXP window, SEXP iterations)
{
	int i, j, l;
	SEXP ans, tmp, dim;
	SEXP index;
	int offset, offset_a;
	int m1, m2, m3;

	if (length(window)<3) {m1 = m2 = m3 = INTEGER_VALUE(window);}
	else {m1 = INTEGER(window)[0]; m2 = INTEGER(window)[1]; m3 = INTEGER(window)[2];}
	
	dim = GET_DIM(x);
	PROTECT(index = allocVector(INTSXP, LENGTH(dim)));
	PROTECT(ans = allocArray(REALSXP, dim));
	PROTECT(tmp = allocArray(REALSXP, dim));
	copyArray(ans, x);

	for(l=0; l<INTEGER_VALUE(iterations); l++) {
   	    copyArray(tmp, ans); 
        for(INTEGER(index)[0]=0; INTEGER(index)[0]<INTEGER(dim)[0]; INTEGER(index)[0]++) {
            for(INTEGER(index)[1]=0; INTEGER(index)[1]<INTEGER(dim)[1]; INTEGER(index)[1]++) {
              for(INTEGER(index)[2]=0; INTEGER(index)[2]<INTEGER(dim)[2]; INTEGER(index)[2]++) {
/*
        offset += INTEGER(index)[0];
        offset += INTEGER(dim)[0]*INTEGER(index)[1];
        offset += INTEGER(dim)[0]*INTEGER(dim)[1]*INTEGER(index)[2];
        offset += INTEGER(dim)[0]*INTEGER(dim)[1]*INTEGER(dim)[2]*INTEGER(index)[3]; 
*/
                    /* find offset into array */
                    for(i=0, offset=0; i<LENGTH(dim); i++) {
                        for(j=0, offset_a=1; j<i; j++) {
                            offset_a *= INTEGER(dim)[j];
                        }
                        offset += offset_a * INTEGER(index)[i];
                    }
                    REAL(ans)[offset] = averaged(tmp, index, m1, m2, m3);
                }
            }
        }
	}
	UNPROTECT(3);
	return ans;
}