[vtkusers] "trade" vtkPoints between actors

Jeff Lee jlee1549 at gmail.com
Tue Aug 6 07:47:13 EDT 2013


instead of directly modifying the points, you could create 2 vtkPolyData
representing inner and outer, both referencing the same global vtkpoints,
and then you are simply adjusting the cell array of each polydata to
reference the appropriate subset of points.  it might be fast enough that
you can just build the cell arrays up for both inner and outer on each
mouse move, and if the global set of points in the renderer is large you
could consider using a vtkPointLocator to speed up the test of whether a
given point is within your sphere.


On Mon, Aug 5, 2013 at 11:28 PM, Renil <renilac at gmail.com> wrote:

> 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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130806/3cc53d88/attachment.htm>


More information about the vtkusers mailing list