コード例 #1
0
SimplifTrian<PFP>::SimplifTrian(MAP& the_map, unsigned int idPos, CRIT* cr):
    m_map(the_map),
    m_crit(cr),
    m_positions(the_map, idPos),
    m_edgeEmb(the_map, EDGE),
    m_valences(the_map, VERTEX),
    m_edgeMarkers(the_map, EDGE << 24),
    m_protectMarker(the_map, EDGE),
    m_passe(0)
{
    computeVerticesValences(false);

    // mesh of triangle, we can compute the number function of number of dart
    m_nbTriangles = the_map.getNbDarts() / the_map.getDartsPerTriangle();

    // local marker to ensure that edges only once in structure
    DartMarker m(m_map);

    for (Dart d = m_map.begin(); d != m_map.end(); m_map.next(d))
    {
        if (!m.isMarked(d))
        {
            // creation of a criteria for the edge
            CRIT* cr = m_crit->create(d);

            // store it in the map
            float key = cr->computeKey(m_map, m_positions);
            CRIT_IT it = m_edgeCrit.insert(std::make_pair(key, cr));
            m_edgeEmb[d] = it;

            // mark cell for traversal
            m.markOrbit<EDGE>(d);
        }
    }
}
コード例 #2
0
ファイル: surface_radiance.cpp プロジェクト: sujithvg/CGoGN
void Surface_Radiance_Plugin::exportPLY(
	const QString& mapName,
	const QString& positionAttributeName,
	const QString& normalAttributeName,
	const QString& filename)
{
	typedef PFP2::MAP MAP;
	typedef PFP2::REAL REAL;
	typedef PFP2::VEC3 VEC3;

	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
	if(mh == NULL)
		return;

	VertexAttribute<VEC3, MAP> position = mh->getAttribute<VEC3, VERTEX>(positionAttributeName);
	if(!position.isValid())
		return;

	VertexAttribute<VEC3, MAP> normal = mh->getAttribute<VEC3, VERTEX>(normalAttributeName);
	if(!normal.isValid())
		return;

	VertexAttribute<Utils::SphericalHarmonics<REAL, VEC3>, MAP> radiance = h_mapParameterSet[mh].radiance;
	if(!radiance.isValid())
		return;

	// open file
	std::ofstream out ;
	out.open(filename.toStdString(), std::ios::out | std::ios::binary) ;

	if (!out.good())
	{
		CGoGNerr << "Unable to open file " << CGoGNendl ;
		return ;
	}

	MAP* map = mh->getMap();

	unsigned int nbDarts = map->getNbDarts() ;
	std::vector<unsigned int> facesSize ;
	std::vector<std::vector<unsigned int> > facesIdx ;
	facesSize.reserve(nbDarts/3) ;
	facesIdx.reserve(nbDarts/3) ;
	std::map<unsigned int, unsigned int> vIndex ;
	unsigned int vCpt = 0 ;
	std::vector<unsigned int> vertices ;
	vertices.reserve(nbDarts/6) ;

	// Go over all faces
	CellMarker<MAP, VERTEX> markV(*map) ;
	TraversorF<MAP> t(*map) ;
	for(Dart d = t.begin(); d != t.end(); d = t.next())
	{
		std::vector<unsigned int> fidx ;
		fidx.reserve(8) ;
		unsigned int degree = 0 ;
		Traversor2FV<MAP> tfv(*map, d) ;
		for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
		{
			++degree ;
			unsigned int vNum = map->getEmbedding<VERTEX>(it) ;
			if(!markV.isMarked(it))
			{
				markV.mark(it) ;
				vIndex[vNum] = vCpt++ ;
				vertices.push_back(vNum) ;
			}
			fidx.push_back(vIndex[vNum]) ;
		}
		facesSize.push_back(degree) ;
		facesIdx.push_back(fidx) ;
	}

	// Start writing the file
	out << "ply" << std::endl ;

	// test endianness
	union
	{
		uint32_t i ;
		char c[4] ;
	} bint = {0x01020304} ;
	if (bint.c[0] == 1) // big endian
		out << "format binary_big_endian 1.0" << std::endl ;
	else
		out << "format binary_little_endian 1.0" << std::endl ;

	out << "comment File generated by the CGoGN library" << std::endl ;
	out << "comment See : http://cgogn.unistra.fr/" << std::endl ;
	out << "comment or contact : [email protected]" << std::endl ;
	// Vertex elements
	out << "element vertex " << vertices.size() << std::endl ;

	std::string nameOfTypePly_REAL(nameOfTypePly(position[0][0])) ;

	out << "property " << nameOfTypePly_REAL << " x" << std::endl ;
	out << "property " << nameOfTypePly_REAL << " y" << std::endl ;
	out << "property " << nameOfTypePly_REAL << " z" << std::endl ;


	out << "property " << nameOfTypePly_REAL << " nx" << std::endl ;
	out << "property " << nameOfTypePly_REAL << " ny" << std::endl ;
	out << "property " << nameOfTypePly_REAL << " nz" << std::endl ;

	int res = Utils::SphericalHarmonics<REAL, VEC3>::get_resolution() ;
	for (int l = 0 ; l <= res ; ++l)
	{
		for (int m = -l ; m <= l ; ++m)
		{
			out << "property " << nameOfTypePly_REAL << " SHcoef_" << l << "_" << m << "_r" << std::endl ;
			out << "property " << nameOfTypePly_REAL << " SHcoef_" << l << "_" << m << "_g" << std::endl ;
			out << "property " << nameOfTypePly_REAL << " SHcoef_" << l << "_" << m << "_b" << std::endl ;
		}
	}

	// Face element
	out << "element face " << facesSize.size() << std::endl ;
	out << "property list uint8 " << nameOfTypePly(facesIdx[0][0]) << " vertex_indices" << std::endl ;
	out << "end_header" << std::endl ;

	// binary vertices
	for(unsigned int i = 0; i < vertices.size(); ++i)
	{
		const VEC3& p = position[vertices[i]] ;
		out.write((char*)(&(p[0])), sizeof(p)) ;
		const VEC3& n = normal[vertices[i]] ;
		out.write((char*)(&(n[0])), sizeof(n)) ;

		for (int l=0 ; l <= res ; ++l)
		{
			for (int m=-l ; m <= l ; ++m)
			{
				const VEC3& r = radiance[vertices[i]].get_coef(l,m) ;
				out.write((char*)(&(r[0])), sizeof(r)) ;
			}
		}
	}

	// binary faces
	for(unsigned int i = 0; i < facesSize.size(); ++i)
	{
		uint8_t nbe = facesSize[i] ;
		out.write((char*)(&nbe), sizeof(uint8_t)) ;
		out.write((char*)(&(facesIdx[i][0])), facesSize[i] * sizeof(facesIdx[i][0])) ;
	}

	out.close() ;

	this->pythonRecording("exportPLY", "", mapName, positionAttributeName, normalAttributeName, filename);
}
コード例 #3
0
ファイル: topo3PrimalRender.hpp プロジェクト: Peiffert/CGoGN
void Topo3PrimalRender<PFP>::updateData(MAP& mapx, const VertexAttribute<VEC3, MAP>& positions, float ke, float kf)
{
	if (m_attIndex.map() != &mapx)
		m_attIndex  = mapx.template getAttribute<unsigned int, DART, MAP>("dart_index");
	if (!m_attIndex.isValid())
		m_attIndex  = mapx.template addAttribute<unsigned int, DART, MAP>("dart_index");

//	m_nbDarts = 0;
//	for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
//	{
//		m_nbDarts++;
//	}

	m_nbDarts = mapx.getNbDarts();

	// beta2/3
	DartAutoAttribute<VEC3, MAP> fv2(mapx);

	m_vbo2->bind();
	glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW);
	GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
	Geom::Vec3f* colorDartBuf = reinterpret_cast<Geom::Vec3f*>(ColorDartsBuffer);

	if (m_bufferDartPosition!=NULL)
		delete m_bufferDartPosition;
	m_bufferDartPosition = new Geom::Vec3f[2*m_nbDarts];
	Geom::Vec3f* positionDartBuf = reinterpret_cast<Geom::Vec3f*>(m_bufferDartPosition);

	unsigned int posDBI = 0;

	int nbf = 0;
	//traverse each face of each volume
	TraversorF<MAP> traFace(mapx);
	for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
	{
		std::vector<VEC3> vecPos;
		vecPos.reserve(16);

		VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx, d, positions);

		//shrink the face
		float okf = 1.0f - kf;
		Dart dd = d;
		do
		{
			VEC3 P = centerFace*okf + positions[dd]*kf;
			vecPos.push_back(P);
			dd = mapx.phi1(dd);
		} while (dd != d);
		
		unsigned int nb = vecPos.size();
		
		vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop

		// compute position of points to use for drawing topo
		float oke = 1.0f - ke;
		for (unsigned int i = 0; i < nb; ++i)
		{
			VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke;
			VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke;

//			VEC3 PP = 0.52f*P + 0.48f*Q;
//			VEC3 QQ = 0.52f*Q + 0.48f*P;

            VEC3 PP = 0.56f*P + 0.44f*Q;
            VEC3 QQ = 0.56f*Q + 0.44f*P;

			*positionDartBuf++ = PFP::toVec3f(P);
			*positionDartBuf++ = PFP::toVec3f(PP);
			if (mapx.template isBoundaryMarked<3>(d))
			{
				*colorDartBuf++ = m_boundaryDartsColor;
				*colorDartBuf++ = m_boundaryDartsColor;
			}
			else
			{
				*colorDartBuf++ = m_dartsColor;
				*colorDartBuf++ = m_dartsColor;
			}

			m_attIndex[d] = posDBI;
			posDBI+=2;
			fv2[d] = (P+PP)*0.5f;

			*positionDartBuf++ = PFP::toVec3f(Q);
			*positionDartBuf++ = PFP::toVec3f(QQ);

			Dart dx = mapx.phi3(d);
			if (mapx.template isBoundaryMarked<3>(dx))
			{
				*colorDartBuf++ = m_boundaryDartsColor;
				*colorDartBuf++ = m_boundaryDartsColor;
			}
			else
			{
				*colorDartBuf++ = m_dartsColor;
				*colorDartBuf++ = m_dartsColor;
			}

			m_attIndex[dx] = posDBI;
			posDBI+=2;
			fv2[dx] = (Q+QQ)*0.5f;

			d = mapx.phi1(d);
		}
		nbf++;
	}
	m_vbo2->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);

	m_vbo0->bind();
	glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), m_bufferDartPosition, GL_STREAM_DRAW);

	// alpha2
	m_vbo1->bind();
	glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW);
	GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);

	Geom::Vec3f* positionF2 = reinterpret_cast<Geom::Vec3f*>(PositionBuffer2);

	m_nbRel2 = 0;

	for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
	{
		Dart e = mapx.phi2(mapx.phi3(d));
		//if (d < e)
		{
			*positionF2++ = PFP::toVec3f(fv2[d]);
			*positionF2++ = PFP::toVec3f(fv2[e]);
			m_nbRel2++;
		}
	}

	m_vbo1->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
}