creating an image

John Biddiscombe j.biddiscombe at rl.ac.uk
Thu Dec 16 15:15:07 EST 1999


>There is a vtkImageImport class, it didn't make it into VTK 2.4
>but it is in the nightlies.
>
>It allows the vtk imaging pipeline to use a block of C++ memory 
>'in place,' i.e. it simply uses a C++ pointer as the source of
>the imaging pipeline.

Since I just happened to have used this recently, here's a snippet

    Graphics::TBitmap *b = PaintCanvas->Picture->Bitmap;
    b->HandleType  = bmDIB;
    b->PixelFormat = pf8bit;
    int w = b->Width, h = b->Height;
    //
    char *data = new char[w*h];
    for (int r=h; --r>=0; ) {
        char *row = (char*)(b->ScanLine[h-1-r]);
        for (int c=0; c<w; c++) {
            data[c + (r*w)] = row[c];
        }
    }
    vtkImageImport *importer = (vtkImageImport*)process;
    importer->SetDataScalarTypeToUnsignedChar();
    importer->SetImportVoidPointer(data, 0);
    importer->SetDataOrigin(0,0,0);
    importer->SetDataSpacing(1,1,1);
    importer->SetDataExtent (0, w-1, 0, h-1, 0, 0);
    TBCBvtkToolWinProcess::UpdateButtonClick(Sender);

this tells it
    importer->SetImportVoidPointer(data, 0);
to take the data and keep the pointer I think, it is now responsible for
freeing the memory.

Works fine. Took 5 minutes. Liked it.

John B



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list