[vtkusers] insert points! Please help me

wang enmei e.wang at fidia.it
Mon Aug 14 06:57:10 EDT 2006


Hello all,

I wrote an example. I want to draw lines with some points. When I insert some 
points into vtkPoints, the display should be refreshed. But it does not 
display the new lines. Why?  Please help me.

Thanks for any help!



#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkProperty.h>
#include <vtkCommand.h>
#include <vtkCallbackCommand.h>

vtkRenderWindow *g_pRenWin=NULL;
vtkPolyData       *g_pPolyData=NULL;
vtkPoints *g_pPoints=NULL;
vtkCellArray *g_pLineCellArray=NULL;


void InsertPointsTest(int n)
{
    double x,y,z;
    vtkIdType ids[2];

    if(n==0)
    {
        x=0;y=0;z=0;
        x=1;y=0;z=0;
        g_pPoints->InsertNextPoint(x,y,z);

        ids[0]=0;
        ids[1]=1;
        g_pLineCellArray->InsertNextCell(2,ids);       
    }
    if(n==1)
    {
        x=1;y=1;z=0;
        g_pPoints->InsertNextPoint(x,y,z);

        ids[0]=1;
        ids[1]=2;
        g_pLineCellArray->InsertNextCell(2,ids);
    }
}

static void UserEvent(vtkObject *vtkNotUsed( caller ),
                      unsigned long vtkNotUsed(eventId),
                      void *sr, void *) 
{
    InsertPointsTest(1);
    g_pRenWin->Render();
}


int main(void)
{
    g_pPolyData=vtkPolyData::New();
    g_pPoints=vtkPoints::New();
    g_pLineCellArray=vtkCellArray::New();
    g_pPolyData->SetPoints(g_pPoints);
    g_pPolyData->SetLines(g_pLineCellArray);
    InsertPointsTest(0);
     
    vtkPolyDataMapper *mapper=vtkPolyDataMapper::New();
    mapper->SetInput(g_pPolyData);
    mapper->SetScalarModeToUseCellData();
    
    vtkActor *actor=vtkActor::New();
    actor->SetMapper( mapper );
    
    vtkRenderer *ren=vtkRenderer::New();
    ren->AddActor( actor );

    g_pRenWin=vtkRenderWindow::New();
    g_pRenWin->AddRenderer( ren );
    
    vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
    iren->SetRenderWindow( g_pRenWin);
    vtkCallbackCommand *userevent = vtkCallbackCommand::New();
    userevent->SetCallback(UserEvent);
    iren->AddObserver(vtkCommand::UserEvent, userevent);

    iren->Initialize();
    g_pRenWin->Render();
    iren->Start();

    return 0;
}



More information about the vtkusers mailing list