[vtkusers] Voxel Data from MATLAB to VTK

Brian Davis bitminer at gmail.com
Mon May 17 16:25:44 EDT 2010


-snip from David-
My familiarity with Titan is nil, but "git blame" tells me that the
vtkMatlabMexAdapter.h has been in VTK since 2009-12-14.  It should be
built whenever VTK_USE_MATLAB_MEX is turned ON in CMake.
-end snip-

I searched my tree which includes vtk-5.4 source and there is no
vtkMatlabMexAdapter.h file nor is there any text in files with
"vtkMatlabMexAdapter".  So I think this maybe new at least post 5.4 (the
version I am using).  Not sure why git is reporting this.  I did not check
git for when this was added to release.

A search for vtkMatlabMexAdapter in
http://www.vtk.org/doc/release/5.4/html/classes.html
returns nada, zippo, nil, none, zero.

A search for vtkMatlabMexAdapter in
http://www.vtk.org/doc/release/5.6/html/classes.html
returns ... ding ding ding we have a winner!

My familularity with Titan is also nil except for my little readings on the
topic and this pdf if your interested
http://titan.sandia.gov/media/Information_Visualization_in_VTK.pdf.  It's
got pretty pictures :-)

https://www.kitware.com/InfovisWiki/index.php/Main_Page

-snip from Thomas-
I am the main developer of the Matlab Engine related code in VTK.

Yes, vtkMatlabMexAdapter is the class you need to convert data from VTK to
the Matlab mxArray type and back again.   This class will get compiled when
VTK_USE_MATLAB_MEX is turned on in the Cmake advanced options of VTK.

Are you are trying to build a Matlab mex program (shared library) that takes
input Matlab data and sends it to VTK, and then returns data from VTK to
Matlab?

-end snip-

Yes I am trying to build a Matlab mex program (shared library) that takes
input from Matlab and sends to VTK.  I have this somewhat working and I
think I was able (I am currently verifying) to get this to work in 5.4
without the vtkMatlabMexAdapter, though this seems a much easier approach so
I may very well upgrade to 5.6 and beyond.  The code snipit that I currently
somewhat have working with 5.4 is

-snip-
...

    for (int i = 0; i < nrhs; i++)
    {

        if( mxGetNumberOfDimensions( prhs[i] ) != 3 )
        {
            mexErrMsgTxt("Render volume can only accept matrix of 3
dimensions");
            return;
        }

        // Get the dimensions
        const mwSize* matDimensions = mxGetDimensions( prhs[i] );

        y_dim = matDimensions[0];
        x_dim = matDimensions[1];
        z_dim = matDimensions[2];

        mexPrintf( "y_dim = %d, x_dim = %d, z_dim = %d \n", y_dim, x_dim,
z_dim );

        // Get the data
        volumeData = mxGetPr(prhs[i]);
    }

...
    vtkSmartPointer<vtkDoubleArray> vtkArray =
vtkSmartPointer<vtkDoubleArray>::New();

    vtkArray->SetVoidArray( (void *) volumeData, y_dim*x_dim*z_dim , 0);

    vtkSmartPointer<vtkImageData> vtkImage =
vtkSmartPointer<vtkImageData>::New();

    vtkImage->SetDimensions( numeric_cast<int>(y_dim) ,
numeric_cast<int>(x_dim), numeric_cast<int>(z_dim) );
    vtkImage->SetSpacing(1.0, 1.0, 1.0);
    vtkImage->SetOrigin(0.0, 0.0, 0.0);

    vtkImage->GetPointData()->SetScalars(vtkArray);

    volumeMapper->SetInput( vtkImage );

    // set the volume mapper.
    volume->SetMapper( volumeMapper );

-snip-

The term *somewhat* is defined there to mean: that I can see my volume, but
it locks up Matlab and vtk render window.

Thanks David and Thomas for the input.

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100517/4b1f91f2/attachment.htm>


More information about the vtkusers mailing list