void Mesh2Cloud::sample(int samplesPerSquareUnit) {
	typedef MeshAnalysis<Traits> MA;
	execute(
		[&] () { 
			MA::sampleOnSurface<Point>(*m_mesh, samplesPerSquareUnit, m_cloud);
		}, 
		[&] () { 
			gui()->log()->info("Sampling finished. Sampled "+lexical_cast<std::string>(m_cloud->size())+" points.");
			addCloud("Main Cloud", rgbaRed(), m_cloud);
			addNormals("Main Cloud Normals", rgbaWhite(), m_cloud, false);
			gui()->properties()->get<File>({"iogroup", "outFile"})->enable();
		}
	);
	//MA::sampleOnSurface<Point>(m_mesh, samplesPerSquareUnit, m_cloud);
}
Exemple #2
0
ofxMesh &ofxMesh::addMesh(ofMesh b) {

    int numVertices = getNumVertices();
    int numIndices = getNumIndices();

    //add b
    addVertices(b.getVertices());
    addNormals(b.getNormals());
    addIndices(b.getIndices());

    //shift indices for b
    for (int i=0; i<b.getNumIndices(); i++) {
        getIndices()[numIndices+i] += numVertices;
    }

    return *this;
}
Exemple #3
0
void MeshData::generateNormals() {
  int   attr, len;
  vec3  nf, e1, e2, *p0, *p1, *p2;
  float *cur, *dst, *normals;

  attr = getAttributeIndex("position");

  if (attr < 0) {
#ifndef PLG_RELEASE
    dprintf(2, "error: can't generateNormals() without position attribute\n");
#endif
    return;
  }

  len     = getVertexCount() * 3;
  normals = (float *) malloc(len * sizeof(float));
  dst     = normals;
  cur     = getVertex(attr, 0);

  while (dst < normals + len) {
    p0 = (vec3 *) &cur[0],
    p1 = (vec3 *) &cur[3];
    p2 = (vec3 *) &cur[6];

    vec3_sub(&e1, p1, p2);
    vec3_sub(&e2, p2, p0);

    vec3_normalize(&e1);
    vec3_normalize(&e2);
    vec3_cross(&nf, &e1, &e2);

    memcpy(dst + 0, &nf, sizeof(vec3));
    memcpy(dst + 3, &nf, sizeof(vec3));
    memcpy(dst + 6, &nf, sizeof(vec3));

    cur += 9;
    dst += 9;
  }

  addNormals(normals, len);
}
Exemple #4
0
void GLC_Sphere::createMesh()
{

	Q_ASSERT(GLC_Mesh::isEmpty());

	GLfloatVector verticeFloat;
	GLfloatVector normalsFloat;
	GLfloatVector texelVector;

	int currentIndex=0;

	float wishedThetaStep= glc::PI / m_Discret;
	float thetaRange= m_ThetaMax-m_ThetaMin;
	int nbThetaSteps= (int) (thetaRange / wishedThetaStep) + 1 ;
	float thetaStep= thetaRange / nbThetaSteps;

	float wishedPhiStep= wishedThetaStep;
	float phiRange= m_PhiMax-m_PhiMin;
	int nbPhiSteps= (int) (phiRange / wishedPhiStep) + 1 ;
	float phiStep= phiRange / nbPhiSteps;

	float cost, sint, cosp, sinp, cospp, sinpp;
	float xi, yi, zi, xf, yf, zf;
	float theta= m_ThetaMin;
	float phi= m_PhiMin;

	GLfloatVector thetaMinWire;
	GLfloatVector thetaMaxWire;
	GLfloatVector phiMinWire;
	GLfloatVector phiMaxWire;

	GLC_Material* pMaterial;
	if (hasMaterial())
		pMaterial= this->firstMaterial();
	else
		pMaterial= new GLC_Material();

	// shaded face
	for (int p= 0; p < nbPhiSteps; ++p)
	{
		cosp= cos (phi);
		sinp= sin (phi);
		cospp= cos (phi + phiStep);
		sinpp= sin (phi + phiStep);

		zi = m_Radius * sinp;
		zf = m_Radius * sinpp;

		IndexList indexFace;

		theta = m_ThetaMin;
		int t;
		for (t= 0; t <= nbThetaSteps; ++t)
		{
			cost= cos( theta );
			sint= sin( theta );

			xi= m_Radius * cost * cosp;
			yi= m_Radius * sint * cosp;
			xf= m_Radius * cost * cospp;
			yf= m_Radius * sint * cospp;

			verticeFloat << xf << yf << zf << xi << yi << zi;
			normalsFloat << cost * cospp << sint * cospp << sinpp << cost * cosp << sint * cosp << sinp;
 			texelVector << static_cast<double>(t) * 1.0 / static_cast<double>(nbThetaSteps)
						<< static_cast<double>(p) * 1.0 / static_cast<double>(nbPhiSteps)
						<< static_cast<double>(t) * 1.0 / static_cast<double>(nbThetaSteps)
						<< static_cast<double>(p+1) * 1.0 / static_cast<double>(nbPhiSteps);

			indexFace << currentIndex + 2 * t << currentIndex + 2 * t + 1 ;
			theta+= thetaStep;

		}

		currentIndex+= 2 * t;
		addTrianglesStrip(pMaterial, indexFace);
		phi+= phiStep;
	}

	addVertice(verticeFloat);
	addNormals(normalsFloat);
	addTexels(texelVector);

	finish();
}
Exemple #5
0
ccPointCloud* sm2ccConverter::getCloud()
{
	if (!m_sm_cloud)
	{
		assert(false);
		return 0;
	}
	
	//get the fields list
	std::list<std::string> fields;
	for (std::vector< PCLScalarField >::const_iterator it = m_sm_cloud->fields.begin(); it != m_sm_cloud->fields.end(); ++it)
	{
		if (it->name != "_") //PCL padding fields
			fields.push_back(it->name);
	}

	//begin with checks and conversions
	//be sure we have x, y, and z fields
	if (!ExistField(m_sm_cloud,"x") || !ExistField(m_sm_cloud,"y") || !ExistField(m_sm_cloud,"z"))
		return 0;

	//create cloud
	ccPointCloud* cloud = new ccPointCloud();

	//push points inside
	if (!addXYZ(cloud))
	{
		delete cloud;
		return 0;
	}

	//remove x,y,z fields from the vector of field names
	fields.remove("x");
	fields.remove("y");
	fields.remove("z");

	//do we have normals?
	if (ExistField(m_sm_cloud,"normal_x") || ExistField(m_sm_cloud,"normal_y") || ExistField(m_sm_cloud,"normal_z"))
	{
		addNormals(cloud);
		
		//remove the corresponding fields
		fields.remove("normal_x");
		fields.remove("normal_y");
		fields.remove("normal_z");
	}

	//The same for colors
	if (ExistField(m_sm_cloud,"rgb"))
	{
		addRGB(cloud);
		
		//remove the corresponding field
		fields.remove("rgb");
	}

	//All the remaining fields will be stored as scalar fields
	for (std::list<std::string>::const_iterator name = fields.begin(); name != fields.end(); ++name)
	{
		addScalarField(cloud, *name);
	}

	return cloud;
}