[vtkusers] problem to draw data in qvtk widget, but file writing works

thomas jetzfellner thomas.jetzfellner at gsf.de
Wed Nov 28 10:01:55 EST 2007


hi,

i have a strange problem, i loaded volume data with itk and extracted a 
slice from it. then i move the extracted data to vtk so that qvtk can 
draw it, but it doesn´t work. but if i write the data, with the vtk 
image file writer into file, all looks fine. In the beginning i had the 
problem, that qvtk crashed. When i investigated the problem, i found out 
that the "userData" was invalid, seemed to be deleted. so i decided to 
make a deep copy after the connection of the itk and vtk pipelines. the 
good thing is, the programm did not crash but my gui doesn´t show an data.

thanks

ps: here is the code; i am developing under VS 2005 XP/SP2

    itk::Size<3> extent=slice->getExtent();
    itk::Point<int,3> point=slice->getPoint();
    itk::Image<unsigned char,2>::Pointer xz=slice->getXZSlice() ;

  itk_export->SetInput( xz );

  ConnectPipelines( itk_export, vtk_import );

  vtkImageData* copy=vtkImageData::New() ;

  vtk_import->Update() ;

  //ok
    copy->DeepCopy( vtk_import->GetOutput() );
  copy->Update() ;

    //ok
  vtkBMPWriter* writer1 = vtkBMPWriter::New();
    writer1->SetFileName("copy_xz.bmp");
  writer1->SetInput( copy );
    writer1->Update();

    vtkImageCast *cast=vtkImageCast::New();
    cast->SetInput(0,copy );
    cast->SetOutputScalarTypeToUnsignedChar();
   
    vtkBMPWriter* writer3 = vtkBMPWriter::New();
    writer3->SetFileName("nach_cast_copy_xz.bmp");
  writer3->SetInput( cast->GetOutput() );
    writer3->Update();

    xzmapper->SetInput( cast->GetOutput() );
    xzmapper->SetColorLevel(128);
    xzmapper->SetColorWindow(256);
    xzactor->SetMapper(xzmapper);

    vtkLineSource* verticalLine = vtkLineSource::New();
   
    verticalLine->SetPoint1(0,point[1]+extent[3]/2,point[2]+extent[5]/2);
    
verticalLine->SetPoint2(extent[1],point[1]+extent[3]/2,point[2]+extent[5]/2);
   
    vtkLineSource* horizontalLine = vtkLineSource::New();
  horizontalLine->SetPoint1(point[0]+extent[3]/2,0,point[2]+extent[5]/2);
    
horizontalLine->SetPoint2(point[0]+extent[3]/2,extent[5],point[2]+extent[5]/2);
   
    vtkPolyDataMapper2D* verticallinemapper = vtkPolyDataMapper2D::New();
  verticallinemapper->SetInput(verticalLine->GetOutput());
   
    vtkPolyDataMapper2D* horizontallinemapper = vtkPolyDataMapper2D::New();
  horizontallinemapper->SetInput(horizontalLine->GetOutput());
   
    vtkActor2D* verticallineactor=vtkActor2D::New();
    verticallineactor->SetMapper(verticallinemapper);
       
    vtkActor2D* horizontallineactor=vtkActor2D::New();
    horizontallineactor->SetMapper(horizontallinemapper);

    xzactor->SetDisplayPosition(0,-ui.verticalScrollBar_xz->value());
    xzRenderer->AddActor(xzactor);
    xzRenderer->AddActor(horizontallineactor);
    xzRenderer->AddActor(verticallineactor);
  xzRenderer->SetBackground(0,255,0);

    vtkRenderer* 
exRenderer=ui.qvtkWidget_xz->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
    ui.qvtkWidget_xz->GetRenderWindow()->RemoveRenderer(exRenderer);
    ui.qvtkWidget_xz->GetRenderWindow()->AddRenderer(xzRenderer);
    ui.qvtkWidget_xz->update();
  ui.qvtkWidget_xz->show();

  imported = true ;



More information about the vtkusers mailing list