34 #include <vtkImageImport.h>
35 #include <vtkImageData.h>
52 mImageImport = vtkImageImportPtr::New();
54 mImageTimer =
new QTimer(
this);
55 connect(mImageTimer, SIGNAL(timeout()),
this, SLOT(processBuffer()));
56 mBuffer = (uint8_t*)malloc(width * height * 3);
58 mImageImport->SetDataScalarTypeToUnsignedChar();
59 mImageImport->SetNumberOfScalarComponents(3);
60 mImageImport->SetWholeExtent(0, mWidth - 1, 0, mHeight - 1, 0, 0);
61 mImageImport->SetDataExtentToWholeExtent();
72 mResolution = resolution;
73 mImageImport->SetDataSpacing(mResolution, mResolution, 1);
78 return mImageImport->GetOutput();
92 mImageTimer->start(40);
101 static void TestImage(
int width,
int height,
int frames, uint8_t *image,
double mmPerPixel)
103 for (
int x = 0; x < width; ++x)
105 for (
int y = 0; y < height; ++y)
107 uint8_t *pix = &image[(y*width + x) * 3];
108 pix[0] = (x*255/width)+frames;
109 pix[1] = (y*255/height)+frames;
111 double mmPerPixel = 0.1;
112 if ( (
int)(x * mmPerPixel) % 10 == 0)
114 uint8_t *pix = &image[(y*width + x) * 3];
123 void TestVideoSource::processBuffer()
125 TestImage(mWidth, mHeight, mFrames, mBuffer, mResolution);
127 mImageImport->SetImportVoidPointer(mBuffer);
128 mImageImport->Update();
129 mImageImport->Modified();
136 return (
double) mImageImport->GetOutput()->GetMTime();
virtual bool isConnected() const
return true when a connection to the data source is established.
virtual void setConnected(bool state)
virtual void stop()
stop streaming
virtual ~TestVideoSource()
virtual double getTimestamp()
virtual void start()
start streaming
virtual vtkImageDataPtr getVtkImageData()
TestVideoSource(QString uid, QString name, int width, int height)
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
virtual void setResolution(double resolution)