예제 #1
0
void TranslateSelection(Selector& sel, const typename TAAPosVRT::ValueType& offset,
						TAAPosVRT& aaPos)
{
	if(!sel.grid()){
		throw(UGError("No grid assigned to selector"));
	}

	Grid& grid = *sel.grid();

//	collect all vertices that are adjacent to selected elements
//	we have to make sure that each vertex is only counted once.
//	we do this by using grid::mark.
	grid.begin_marking();

	for(VertexIterator iter = sel.vertices_begin();
		iter != sel.vertices_end(); ++iter)
	{
		VecAdd(aaPos[*iter], aaPos[*iter], offset);
		grid.mark(*iter);
	}

	for(EdgeIterator iter = sel.edges_begin();
		iter != sel.edges_end(); ++iter)
	{
		Edge::ConstVertexArray vrts = (*iter)->vertices();
		for(size_t i = 0; i < (*iter)->num_vertices(); ++i){
			if(!grid.is_marked(vrts[i])){
				grid.mark(vrts[i]);
				VecAdd(aaPos[vrts[i]], aaPos[vrts[i]], offset);
			}
		}
	}

	for(FaceIterator iter = sel.faces_begin();
		iter != sel.faces_end(); ++iter)
	{
		Face::ConstVertexArray vrts = (*iter)->vertices();
		for(size_t i = 0; i < (*iter)->num_vertices(); ++i){
			if(!grid.is_marked(vrts[i])){
				grid.mark(vrts[i]);
				VecAdd(aaPos[vrts[i]], aaPos[vrts[i]], offset);
			}
		}
	}

	for(VolumeIterator iter = sel.volumes_begin();
		iter != sel.volumes_end(); ++iter)
	{
		Volume::ConstVertexArray vrts = (*iter)->vertices();
		for(size_t i = 0; i < (*iter)->num_vertices(); ++i){
			if(!grid.is_marked(vrts[i])){
				grid.mark(vrts[i]);
				VecAdd(aaPos[vrts[i]], aaPos[vrts[i]], offset);
			}
		}
	}

	grid.end_marking();
}
예제 #2
0
bool CalculateCenter(typename TAAPosVRT::ValueType& centerOut,
					 Selector& sel, TAAPosVRT& aaPos)
{
	if(!sel.grid()){
		throw(UGError("No grid assigned to selector"));
	}
	
	Grid& grid = *sel.grid();
	
//	collect all vertices that are adjacent to selected elements
//	we have to make sure that each vertex is only counted once.
//	we do this by using grid::mark.
	grid.begin_marking();

//	std::vector<Vertex*> vrts;
//	vrts.assign(sel.vertices_begin(), sel.vertices_end());
//	grid.mark(sel.vertices_begin(), sel.vertices_end());

	VecSet(centerOut, 0);
	size_t n = 0;
	for(VertexIterator iter = sel.vertices_begin();
		iter != sel.vertices_end(); ++iter)
	{
		VecAdd(centerOut, centerOut, aaPos[*iter]);
		grid.mark(*iter);
		++n;
	}

	for(EdgeIterator iter = sel.edges_begin();
		iter != sel.edges_end(); ++iter)
	{
		Edge::ConstVertexArray vrts = (*iter)->vertices();
		for(size_t i = 0; i < (*iter)->num_vertices(); ++i){
			if(!grid.is_marked(vrts[i])){
				grid.mark(vrts[i]);
				VecAdd(centerOut, centerOut, aaPos[vrts[i]]);
				++n;
			}
		}
	}

	for(FaceIterator iter = sel.faces_begin();
		iter != sel.faces_end(); ++iter)
	{
		Face::ConstVertexArray vrts = (*iter)->vertices();
		for(size_t i = 0; i < (*iter)->num_vertices(); ++i){
			if(!grid.is_marked(vrts[i])){
				grid.mark(vrts[i]);
				VecAdd(centerOut, centerOut, aaPos[vrts[i]]);
				++n;
			}
		}
	}

	for(VolumeIterator iter = sel.volumes_begin();
		iter != sel.volumes_end(); ++iter)
	{
		Volume::ConstVertexArray vrts = (*iter)->vertices();
		for(size_t i = 0; i < (*iter)->num_vertices(); ++i){
			if(!grid.is_marked(vrts[i])){
				grid.mark(vrts[i]);
				VecAdd(centerOut, centerOut, aaPos[vrts[i]]);
				++n;
			}
		}
	}

	grid.end_marking();

	if(n > 0){
		VecScale(centerOut, centerOut, 1. / (number)n);
		return true;
	}
	return false;
}