Beispiel #1
0
Dart Topo3PrimalRender<PFP>::raySelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax)
{
	float AB2 = rayAB*rayAB;
	Dart dFinal;
	float dm2 = dmax*dmax;
	double dist2 = std::numeric_limits<double>::max();

	for(Dart d = map.begin(); d!=map.end(); map.next(d))
	{
		// get back position of segment PQ
		const Geom::Vec3f& P = m_bufferDartPosition[m_attIndex[d]];
		const Geom::Vec3f& Q =m_bufferDartPosition[m_attIndex[d]+1];
		float ld2 = Geom::squaredDistanceLine2Seg(rayA, rayAB, AB2, P, Q);
		if (ld2 < dm2)
		{
			Geom::Vec3f V = (P+Q)/2.0f - rayA;
			double d2 = double(V*V);
			if (d2 < dist2)
			{
				dist2 = d2;
				dFinal = d;
			}
		}
	}
	return dFinal;
}
Beispiel #2
0
void Topo3PrimalRender<PFP>::computeDartMiddlePositions(MAP& map, DartAttribute<VEC3, MAP>& posExpl)
{
	m_vbo0->bind();
	Geom::Vec3f* positionsPtr = reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));

	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		const Geom::Vec3f& v =(positionsPtr[m_attIndex[d]] + positionsPtr[m_attIndex[d]+1])*0.5f;
		posExpl[d] = PFP::toVec3f(v);
	}

	m_vbo0->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Beispiel #3
0
void Topo3PrimalRender<PFP>::updateColors(MAP& map, const VertexAttribute<VEC3, MAP>& colors)
{
	m_vbo2->bind();
	Geom::Vec3f* colorBuffer =  reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
	unsigned int nb=0;

	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (nb < m_nbDarts)
		{
			colorBuffer[m_attIndex[d]] = colors[d];
			nb++;
		}
		else
		{
			CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
			break;
		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Beispiel #4
0
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);
}
Beispiel #5
0
int main()
{
	// declare a map to handle the mesh
	MAP myMap;

	// add position attribute on vertices and get handler on it
	VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");

	// create a topo grid of 2x2 squares
	Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 4, 4, true);

	// and embed it using position attribute
    grid.embedIntoGrid(position, 1.,1.,0.);

	// ALGO:
	// foreach vertex of the map
	//    print position of the vertex

	// 4 versions 	

	// low level traversal using pure topo
	DartMarker<MAP> dm(myMap);
	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) // traverse all darts of map
	{
		if (!dm.isMarked(d))			// is dart not marked ?
		{
			dm.markOrbit<VERTEX>(d);	// mark all dart of vertex orbit to be sure to not traverse it again
			std::cout << d << " : " << position[d]<< " / ";
		}
	}
	std::cout << std::endl;

	// low level traversal using cell marking (use marker on embedding is available)
	CellMarker<MAP,VERTEX> cm(myMap);
	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
	{
		if (!cm.isMarked(d))	// is dart of the vertex cell not marked ?
		{
			cm.mark(d);			// 
			std::cout << d << " : " << position[d]<< " / ";
		}
	}
	std::cout << std::endl;

	// using traversal
	TraversorV<MAP> tv(myMap);	// alias for Traversor<MAP,VERTEX> 
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " : " << position[d]<< " / ";
	std::cout <<  std::endl;

	//using foreach function (C++11 lambda expression)
	foreach_cell<VERTEX>(myMap, [&] (Vertex v) // for each Vertex v of the MAP myMap
	{
		std::cout << v << " : " << position[v]<< " / ";
	});
	// warning here v is a Vertex and not a Dart (but can cast automatically into)

	std::cout <<  std::endl;

	// example of parallel traversal of cells
	Parallel::foreach_cell<VERTEX>(myMap,[&](Vertex v, unsigned int thread) // for each Vertex v of the MAP myMap
	{
		position[v] += VEC3(0.0, 0.0, PFP::REAL(thread) * 0.1f);
		// WARNING thread vary here from 1 to 4 (and not from 0 to 3) !!!!
	}); // 4:4 thread, false for no need for markers in threaded code.

	std::cout << "After // processing"<< std::endl;

	// last and simple traversal method (new for c++11 syntax)
	for(Vertex v : allVerticesOf(myMap))
	{
		std::cout << position[v] << " / ";
	}
	std::cout <<  std::endl;


	// Example with // accumulation
	// computing the sum of area faces

	// force number of threads to 4 (0 for traverse, 1,2,3 for computation)
	CGoGN::Parallel::NumberOfThreads = 4;

	// init nbthread values with 0
	float surf[3] = { 0.0f, 0.0f, 0.0f };
	// traverse face in //
	Parallel::foreach_cell<FACE>(myMap, [&] (Face f, unsigned int thr)
	{
		// for each face add surface to accumulator (-1 because counter between 1-3 not 0-3)
		surf[thr-1] += Algo::Surface::Geometry::convexFaceArea<PFP>(myMap, f, position);
	});

	std::cout << surf[0]<< "/"<< surf[1]<< "/"<< surf[2]<< "/"<< std::endl;
	std::cout << "Total="<<surf[0]+surf[1]+surf[2]<< std::endl;

	// example of traversal in two pass (optimizing marking/unmarking)

	TraversorV<MAP> tv0(myMap);
	TraversorCellEven<MAP, VERTEX> tv1(tv0);
	TraversorCellOdd<MAP, VERTEX> tv2(tv0);

	std::cout << "PAIR:";
	for (Dart d=tv1.begin(); d!=tv1.end(); d=tv1.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout << std::endl;

	std::cout << "IMPPAIR:";
	for (Dart d=tv2.begin(); d!=tv2.end(); d=tv2.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout <<  std::endl;

	std::cout << "PAIR:";
	for (Dart d=tv1.begin(); d!=tv1.end(); d=tv1.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout << std::endl;

	std::cout << "IMPPAIR:";
	for (Dart d=tv2.begin(); d!=tv2.end(); d=tv2.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout <<  std::endl;
	return 0;
}