[vtkusers] VTK hangs with popen() ???

Martins D Innus minnus at eng.buffalo.edu
Tue Apr 23 17:44:00 EDT 2002


Hi,
	Is there a problem with using popen() in a VTK app?  I've
condensed the problem I've been having down to the code below.  The popen
call appears to never return.  The app just hangs at that point.  This
only happens when there are more than 2 VTK components in the pipeline.
That is, if I remove the vtkThreshold all is well.  I've tried this with
multiple sources (vtkVolume16Reader, etc) and multiple intermediate
filters (vtkImageGaussianSmooth, etc).

Also, it doesn't matter if the popen is set to read from or write to.
There is no output from the popen()'d process.

This is on a Redhat 7.2 box, tried with VTK 4.0 and also the snapshot from
today.

I'd appreciate any help on this, even to say it works somewhere else on a
GNU/Linux box.

Martins



#include <iostream>
#include <stdio.h>
#include "vtkRenderWindowInteractor.h"
#include "vtkImageGridSource.h"
#include "vtkImageViewer.h"
#include "vtkImageThreshold.h"

using namespace std;

void foo_cb(void*){

  cout<<"Before popen"<<endl;
  cout.flush();

  FILE *fp = popen("/bin/date","w");
  cout.flush();

  cout<<"After popen"<<endl;
  cout.flush();
}

int main(int argc, char **argv){

  ios::sync_with_stdio();

  vtkRenderWindowInteractor *inter=vtkRenderWindowInteractor::New();
  inter->SetUserMethod(foo_cb,NULL);

  vtkImageGridSource *grid=vtkImageGridSource::New();
  grid->SetGridSpacing(16, 16, 0);
  grid->SetGridOrigin(0,0,0);
  grid->SetDataExtent(0,511,0,511,0,0);
  grid->SetLineValue(4096);
  grid->SetFillValue(0);
  grid->SetDataScalarTypeToShort();

  vtkImageThreshold *thresh=vtkImageThreshold::New();
  thresh->SetInput(grid->GetOutput());
  thresh->ThresholdBetween(0,4096);
  thresh->SetOutValue(0);
  thresh->ReplaceOutOn();
  thresh->ReplaceInOff();
  
  vtkImageViewer *vwr=vtkImageViewer::New();
  vwr->SetInput(thresh->GetOutput());
  vwr->SetColorWindow(4096);
  vwr->SetColorLevel(2048);
  vwr->SetZSlice(0);
  vwr->SetSize(512,512);
  
  inter->SetRenderWindow(vwr->GetRenderWindow());

  inter->Start();
  
  return 0;

}





More information about the vtkusers mailing list