13 #include <vtkImageImport.h>
14 #include <vtkImageData.h>
32 mImageImport = vtkImageImportPtr::New();
34 mImageTimer =
new QTimer(
this);
35 connect(mImageTimer, SIGNAL(timeout()),
this, SLOT(processBuffer()));
36 mBuffer = (uint8_t*)malloc(width * height * 3);
38 mImageImport->SetDataScalarTypeToUnsignedChar();
39 mImageImport->SetNumberOfScalarComponents(3);
40 mImageImport->SetWholeExtent(0, mWidth - 1, 0, mHeight - 1, 0, 0);
41 mImageImport->SetDataExtentToWholeExtent();
52 mResolution = resolution;
53 mImageImport->SetDataSpacing(mResolution, mResolution, 1);
58 return mImageImport->GetOutput();
72 mImageTimer->start(40);
81 static void TestImage(
int width,
int height,
int frames, uint8_t *image,
double mmPerPixel)
83 for (
int x = 0; x < width; ++x)
85 for (
int y = 0; y < height; ++y)
87 uint8_t *pix = &image[(y*width + x) * 3];
88 pix[0] = (x*255/width)+frames;
89 pix[1] = (y*255/height)+frames;
91 double mmPerPixel = 0.1;
92 if ( (
int)(x * mmPerPixel) % 10 == 0)
94 uint8_t *pix = &image[(y*width + x) * 3];
103 void TestVideoSource::processBuffer()
105 TestImage(mWidth, mHeight, mFrames, mBuffer, mResolution);
107 mImageImport->SetImportVoidPointer(mBuffer);
108 mImageImport->Update();
109 mImageImport->Modified();
116 return (
double) mImageImport->GetOutput()->GetMTime();