[vtkusers] updated to v 5.9 from v 5.6, now experiencing some difficulties displaying crosshairs

Mark Roden mmroden at gmail.com
Fri Feb 11 13:56:22 EST 2011


Hi all,

I was using the following code in order to display crosshairs on 2D
images in vtk 5.6.  How should this be done in 5.9?  There are two
lines that, if left in, cause 5.9 to throw exceptions in java, but in
5.6 work fine.  Without those lines, 5.9 is not displaying crosshairs.

Thanks!
Mark

    private void initCrosshairs() {
        vtkCellArray cells = new vtkCellArray();
        cells.Allocate(2, 2);
        vtkIdList pts = new vtkIdList();
        pts.SetNumberOfIds(2);
        pts.SetId(0,0);
        pts.SetId(1,1);
        cells.InsertNextCell(pts);
        pts.SetId(0,2);
        pts.SetId(1,3);
        cells.InsertNextCell(pts);
        mCursorPolyData.SetLines(cells);

        vtkPolyDataMapper theMapper = new vtkPolyDataMapper();
        theMapper.SetInput(mCursorPolyData);
//THESE TWO LINES: required by 5.6, causing breaks in 5.9
        //theMapper.SetResolveCoincidentTopologyToPolygonOffset();
        //theMapper.SetResolveCoincidentTopologyToShiftZBuffer();

        mCursorActor.SetMapper(theMapper);
        mCursorActor.PickableOff();
        mCursorActor.VisibilityOn();

        mCursorActor.GetProperty().SetAmbient(1);
        mCursorActor.GetProperty().SetColor(1,0,0);
        mCursorActor.GetProperty().SetRepresentationToWireframe();
        mCursorActor.GetProperty().SetInterpolationToFlat();
    }

    private void updateCrosshairs(boolean render) {
        double[] bounds = imageViewer.GetInput().GetBounds();
        double[] pickPosition =
OrthoDataManager.getWorldPosition(selectedDisplayPosition,
imageViewer.GetInput());

        for (int i = 0; i < 3; i++){
            if (pickPosition[i] < bounds[i*2] ||
                pickPosition[i] > bounds[i*2+1])
                return;
        }

        vtkPoints thePoints = new vtkPoints();
        thePoints.SetDataType(11);//double type
        thePoints.SetNumberOfPoints(4);
        switch (orientation){
            case OrthoPanel.ORIENTATION_XY:
                thePoints.SetPoint(0, bounds[0], pickPosition[1],
pickPosition[2]);
                thePoints.SetPoint(1, bounds[1], pickPosition[1],
pickPosition[2]);
                thePoints.SetPoint(2, pickPosition[0], bounds[2],
pickPosition[2]);
                thePoints.SetPoint(3, pickPosition[0], bounds[3],
pickPosition[2]);
                break;
            case OrthoPanel.ORIENTATION_YZ:
                thePoints.SetPoint(0, pickPosition[0], bounds[2],
pickPosition[2]);
                thePoints.SetPoint(1, pickPosition[0], bounds[3],
pickPosition[2]);
                thePoints.SetPoint(2, pickPosition[0],
pickPosition[1], bounds[4]);
                thePoints.SetPoint(3, pickPosition[0],
pickPosition[1], bounds[5]);
                break;
            case OrthoPanel.ORIENTATION_XZ:
                thePoints.SetPoint(0, bounds[0], pickPosition[1],
pickPosition[2]);
                thePoints.SetPoint(1, bounds[1], pickPosition[1],
pickPosition[2]);
                thePoints.SetPoint(2, pickPosition[0],
pickPosition[1], bounds[4]);
                thePoints.SetPoint(3, pickPosition[0],
pickPosition[1], bounds[5]);
                break;
        }

        mCursorPolyData.SetPoints(thePoints);
        mCursorPolyData.Update();

        if (firstTimeShowingCrosshairs)
            crosshairStatusChanged(false, render);

        firstTimeShowingCrosshairs = false;
    }



More information about the vtkusers mailing list