コード例 #1
0
ファイル: simple_attribs.cpp プロジェクト: Peiffert/CGoGN
/**
 * @brief computeNewPositions Demonstrate  the usage of AutoAttributes
 */
void computeNewPositions(MAP& map, VertexAttribute<VEC3, MAP>& pos)
{
	// here we need new and old positions simultaneously so create temporary attribute position

	VertexAutoAttribute<VEC3, MAP> pos2(map);

	foreach_cell<VERTEX>(map,[&](Vertex v)  // for all vertices
	{
		int nb=0;
		pos2[v] = VEC3(0,0,0);// init with 0,0,0,
		foreach_adjacent2<EDGE>(map,v,[&](Vertex x) // for all its neighbours (by edges)
		{
			pos2[v] += pos[x];
			nb++;
		});
		pos2[v] /= nb;
	});

	// swap attribute position with temporary (constant complexity !)
	// only possible with same type and same orbit attribute.
	map.swapAttributes(pos,pos2);

	// destruction of VertexAutoAttribute handller remove the attribute from the map.
}