34 #include <vtkImageImport.h>
35 #include <vtkImageData.h>
53 mImageImport = vtkImageImportPtr::New();
55 mImageTimer =
new QTimer(
this);
56 connect(mImageTimer, SIGNAL(timeout()),
this, SLOT(processBuffer()));
57 mBuffer = (uint8_t*)malloc(width * height * 3);
59 mImageImport->SetDataScalarTypeToUnsignedChar();
60 mImageImport->SetNumberOfScalarComponents(3);
61 mImageImport->SetWholeExtent(0, mWidth - 1, 0, mHeight - 1, 0, 0);
62 mImageImport->SetDataExtentToWholeExtent();
73 mResolution = resolution;
74 mImageImport->SetDataSpacing(mResolution, mResolution, 1);
79 return mImageImport->GetOutput();
93 mImageTimer->start(40);
102 static void TestImage(
int width,
int height,
int frames, uint8_t *image,
double mmPerPixel)
104 for (
int x = 0; x < width; ++x)
106 for (
int y = 0; y < height; ++y)
108 uint8_t *pix = &image[(y*width + x) * 3];
109 pix[0] = (x*255/width)+frames;
110 pix[1] = (y*255/height)+frames;
112 double mmPerPixel = 0.1;
113 if ( (
int)(x * mmPerPixel) % 10 == 0)
115 uint8_t *pix = &image[(y*width + x) * 3];
124 void TestVideoSource::processBuffer()
126 TestImage(mWidth, mHeight, mFrames, mBuffer, mResolution);
128 mImageImport->SetImportVoidPointer(mBuffer);
129 mImageImport->Update();
130 mImageImport->Modified();
137 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 TimeInfo getAdvancedTimeInfo()
virtual void stop()
stop streaming
virtual ~TestVideoSource()
virtual double getTimestamp()
virtual void start()
start streaming
virtual vtkImageDataPtr getVtkImageData()
QDateTime mAcquisitionTime
Possibly modified time stamp.
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)