[vtkusers] Inconsistent behavior when editing polydata

Michael Bell mbell at coventor.com
Wed May 2 16:57:46 EDT 2001


vtkusers,

	I am using java in windows NT and vtk 3.2 to create an interactive
application with one actor made up of polydata (which is created from
points). I want to be able to click the mouse to two points on the screen
and create a new rectangular cell in the poly data. This works great 90% of
the time. 5% of the time, some object is not created correctly, and 5% of
the time, I crash with an internal error or lock up. That is, I run the same
function 10 times and it works 9 of them (but not the same 9 times) and
blows up once (but not at the same place everytime). I will display my code
and then be more specific (I have ommitted irrelevent code):

//first, initialize some cells. This works without problems.

        polyActor = new vtkActor();
        polyData = new vtkPolyData();
        polyMapper = new vtkPolyDataMapper();

        points = new vtkPoints();
        points.SetNumberOfPoints(numPolys * polysize);
        polyData.Allocate(1,10);
        for(yctr=-y;yctr<y;yctr++){
          for(xctr =-x;xctr<x;xctr++){
            poly = new vtkPolygon();
            poly.GetPointIds().SetNumberOfIds(polysize);
            for(int ctr =0;ctr<polysize;ctr++){
              poly.GetPointIds().SetId(ctr,ctr + currentctr);
            }
            polyData.InsertNextCell(poly.GetCellType(),poly.GetPointIds());

            vtkPoints pts[] = new vtkPoints[polysize];
            points.InsertPoint(currentctr,x0,y0,z0);
		points.InsertPoint(currentctr,x1,y1,z1);
		points.InsertPoint(currentctr,x2,y2,z2);
		points.InsertPoint(currentctr,x3,y3,z3);

            currentctr += polysize;
          }
        }
        polyData.SetPoints(points);
        polyMapper.SetInput((vtkPolyData)colorFilter.GetOutput());
        polyActor.SetMapper(polyMapper);
        setActor(polyActor);

//now, add a rectangle defined by the user. I have numbered the problem
lines.

      poly = new vtkPolygon();
1.    poly.GetPointIds().SetNumberOfIds(4);
      for(int ctr =0;ctr<4;ctr++){
        poly.GetPointIds().SetId(ctr,ctr + currentctr);
      }

2.    polyData.InsertNextCell(poly.GetCellType(),poly.GetPointIds());

      points.InsertPoint(currentctr,x1,y1,.1);
      points.InsertPoint(currentctr+1,x2,y1,.1);
      points.InsertPoint(currentctr+2,x2,y2,.1);
      points.InsertPoint(currentctr+3,x1,y2,.1);
      polyData.SetPoints(points);

      ren.RemoveActor(polyActor);
      polyActor = new vtkActor();

      polyMapper.SetInput(polyData);
3.    polyActor.SetMapper(polyMapper);
      setActor(polyActor);

For each of these lines, it seems that poly, poly.GetPointIds(), or
polyActor, is null, even though I just created a new instance of them. If I
put the "new vtkPolygon" into a loop until it isn't null, that works, but I
usually crash on something else later, in a way that I can't debug very
easily. What is strange about this probalem is that the adding of a
rectangle will work several times before I get an exception, then it will
work several times again before another exception. The more code I add, such
as a scalars, or a lookup table, the more places I get null pointer
exceptions or crashes. Can anyone help me?

Thanks,
michael





More information about the vtkusers mailing list