Slow mouse interaction due to vtkExtractGrid

pahsieh at usgs.gov pahsieh at usgs.gov
Sun Apr 2 01:23:18 EST 2000


The use of vtkExtractGrid appears to significantly slow down
the mouse interaction.

The problem is illustrated by the attached sample code.
A structured grid data set is created with scalar point
data. Two vtkThreshold filters are applied to the data set
to extract (a) cells above a threshold criterion, and (b) cells
below a threshold criterion. The two groups of cells are rendered
separately as two actors. Everything works fine and the
mouse interaction is at the typical speed.

When the 'u' key is pressed, the interactor's UserMethod
modifies the pipeline so that the structured grid is passed
through a vtkExtractGrid filter prior to thresholding. This
results in fewer cells (faces) to render, but the mouse
interaction is significantly slowed down.

I think this problem occurs when the pipeline has parallel
branches. For example, if the 2 vtkThreshold filters
were replaced by 2 vtkCutters to cut 2 planes, this also
cause slow mouse interaction when vtkExtractGrid is applied.
However, if the pipeline has only a single branch (e.g., one
of the actors is set to visibility off), then the mouse
interaction is normal again.

I would appreciate any help to get around this problem.

Thanks.
Paul


// ===== sample code ======

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkQuadric.h"
#include "vtkStructuredGrid.h"
#include "vtkExtractGrid.h"
#include "vtkThreshold.h"
#include "vtkDataSetMapper.h"
#include "vtkActor.h"

int toggle;
vtkStructuredGrid *sg;
vtkExtractGrid *extractGrid;
vtkThreshold *threshold1;
vtkThreshold *threshold2;
vtkRenderWindow *renWin;

void UserMethod(void *param)
{
    toggle = (toggle + 1) % 2;
    if (toggle == 1)
    {
        // uses an extracted portion of the structured grid.
        // Results in very slow interaction
        threshold1->SetInput(extractGrid->GetOutput());
        threshold2->SetInput(extractGrid->GetOutput());
    }
    else
    {
        // uses the full structured grid.
        // Results in normal interaction.
        threshold1->SetInput(sg);
        threshold2->SetInput(sg);
    }
    renWin->Render();
}

void main()
{
    int i, j, k;

    // Create the rendering stuff
    vtkRenderer *ren = vtkRenderer::New();
    ren->SetBackground(1,1,1);
    renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren);
    renWin->SetSize(300, 300);
    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
    iren->SetUserMethod(UserMethod, 0);
    toggle = 0;

    // Create a structured grid data set with scalar point data
    // generated by a quadric
    sg = vtkStructuredGrid::New();
    sg->SetDimensions(50, 50, 50);
    vtkPoints *points = vtkPoints::New();
    vtkScalars *scalars = vtkScalars::New();
    float x[3];
    vtkQuadric *quadric = vtkQuadric::New();
    quadric->SetCoefficients(.5,1,.2,0,.1,0,0,.2,0,0);
    for (k=0; k<50; k++)
    {
        x[2] = k;
        for (j=0; j<50; j++)
        {
            x[1] = j;
            for (i=0; i<50; i++)
            {
                x[0] = i;
                points->InsertNextPoint(x);
                scalars->InsertNextScalar(quadric->EvaluateFunction(x));
            }
        }
    }
    sg->SetPoints(points);
    sg->GetPointData()->SetScalars(scalars);
    points->Delete();
    scalars->Delete();

    // Perform lower threshold on data set to create actor 1
    threshold1 = vtkThreshold::New();
    threshold1->SetInput(sg);
    threshold1->ThresholdByLower(1000);

    vtkDataSetMapper *mapper1 = vtkDataSetMapper::New();
    mapper1->SetInput(threshold1->GetOutput());
    mapper1->SetScalarRange(0, 4000);

    vtkActor *actor1 = vtkActor::New();
    actor1->SetMapper(mapper1);
    ren->AddActor(actor1);

    // Perform upper threshold on data set to create actor 2
    threshold2 = vtkThreshold::New();
    threshold2->SetInput(sg);
    threshold2->ThresholdByUpper(1500);

    vtkDataSetMapper *mapper2 = vtkDataSetMapper::New();
    mapper2->SetInput(threshold2->GetOutput());
    mapper2->SetScalarRange(0, 4000);

    vtkActor *actor2 = vtkActor::New();
    actor2->SetMapper(mapper2);
    ren->AddActor(actor2);

    // Filter to extract a VOI.
    // Applied when the interactor's UserMethod is invoked.
    extractGrid = vtkExtractGrid::New();
    extractGrid->SetInput(sg);
    extractGrid->SetVOI(10, 40, 10, 40, 10, 40);

    // Render and interact
    renWin->Render();
    iren->Start();

    // Clean up
    ren->Delete();
    renWin->Delete();
    iren->Delete();
    sg->Delete();
    quadric->Delete();
    extractGrid->Delete();
    threshold1->Delete();
    threshold2->Delete();
    mapper1->Delete();
    mapper2->Delete();
    actor1->Delete();
    actor2->Delete();
}

--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list