[vtkusers] "trade" vtkPoints between actors

Renil renilac at gmail.com
Mon Aug 5 23:28:35 EDT 2013


Hello vtk users,

This is my first time posting as I have been using VTK just recently. 
Although VTK is surprisingly resourceful and this forum is amazing and
helped me a lot in experimenting VTK, I need help.

Im trying to pass vtkPoints, or just the coordinates of a point, between
vtkActors as they are inside or not of a boundary.

So in more detail, I have a sphere that follows my mouse (onMouseMove), and
I have 2 data structures (vtkSmartPointer<vtkPoints>), innerList and
outerList. 
As I pass through the many points in the renderer, in the form of spheres,
if one is inside my boundary, I want to remove it from my outer structure
and add it 
to my inner structure.

Reading the forum, it seems there is no deletePoint(), which would really
came in handy, so I tried a suggestion presented in the forum, creating a
new vtkPoints without the ones that I don't want, and using shallowCopy to
replace the previous points, it is really slow.

Can you guys help me with a better way of doing this? Some way to trade
points efficiently between actors?
Although this approach seems to work it always leaves 1 point in the array..
And the method outerList->GetPoint(i, coords) doesn't seem to return the
proper coordinates, as I can't remove all points from one structure.
Also the insertion seems to grow more than I expect.. 

Most likely I'm doing something wrong :), if you guys could give some
alternatives that would be great.
I leave some code below,

And thanks in advance.

The idea is something like this, for each mouse move:
1. get innerList and outerList
2. check if each point in innerList is still inside boundary
3. if not add to vtkIdTypeArray1
4. check if each point in outerList is in boundary
5. if then add to vtkIdTypeArray2

6. remove(innerList, vtkIdTypeArray1)
7. insert(outerList, vtkIdTypeArray1)
8. outerVTKPoints.Modified(), innerVTKPoints.Modified()

9. remove(outerList, vtkIdTypeArray2)
10. insert(innerList, vtkIdTypeArray2)
11. outerVTKPoints.Modified(), innerVTKPoints.Modified()

Also previously I have created all the actors, mappers, sources, etc to
present spheres in the window, and this code is called from a callback 
function onMouseMove. I pass the inner and outer lists too.

*Code* for points that were out and now are in, I do something similar for
points that now are out of the boundary:

...
     for (vtkIdType i = 0; i < outerList->GetNumberOfPoints(); ++i){
		
		        double coords[3];
			outerList->GetPoint(i, coords);
			
			// (x-x0)^2 + (y-y0)^2 + (z-z0)^2 < r^2
			// if is inside focus area, inside of sphere equation
			if((coords[0] - focusCenter[0])*(coords[0] - focusCenter[0]) +
			   (coords[1] - focusCenter[1])*(coords[1] - focusCenter[1]) +
			   (coords[2] - focusCenter[2])*(coords[2] - focusCenter[2]) < (10*10) ){
				
				pointsIds->InsertNextValue(i);
			}
		}
	}

	if(pointsIds->GetNumberOfTuples() > 0){
		// Call insert of same points to inner list
		insertPoint(innerList, pointsIds, outerElementPoints);
		// Call delete of points from outer list
		ReallyDeletePoint(outerList, pointsIds);
		innerList->Modified();
		outerList->Modified();
	}
...

void ReallyDeletePoint(vtkSmartPointer<vtkPoints> points,
vtkSmartPointer<vtkIdTypeArray> ids){
	
	vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
	double coords[3];
	
	for(vtkIdType i = 0 ; i < ids->GetNumberOfTuples(); i++){

		points->GetPoint(i, coords);
		newPoints->InsertNextPoint(coords);
	}
	
	points->ShallowCopy(newPoints);
}

void insertPoint(vtkSmartPointer<vtkPoints> newPoints,
vtkSmartPointer<vtkIdTypeArray> ids, vtkSmartPointer<vtkPoints>
previousPoints){
	
	double coords[3];
	
	for(vtkIdType i = 0 ; i < ids->GetNumberOfTuples(); i++){
		previousPoints->GetPoint(i, coords);
		newPoints->InsertNextPoint(coords);
	}
}

regards,
Renil Lacmane



--
View this message in context: http://vtk.1045678.n5.nabble.com/trade-vtkPoints-between-actors-tp5722498.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list