[vtkusers] Voxel Data from MATLAB to VTK

Brian Davis bitminer at gmail.com
Mon May 24 14:40:20 EDT 2010


Ok so continuing on with my get my data into vtk from matlab using
vtkMatlabMexAdapter I am a little confused as to how to get volume data 3
Dimensons of doubles  from matlab to vtk.

If I try SetScalars and use
mxArrayTovtkDataArray<http://www.vtk.org/doc/nightly/html/classvtkMatlabMexAdapter.html#ac8bfd9b0924b30a14a687bc3fab5c895>which
takes const mxArray* (note use of keyword const) and coverts to
vtkDataArray* I am told the reason for the errors in the terminal window are
due to the fact that vtkDataArray only takes 2 dimensional data.  If I
try mxArrayTovtkArray
<http://www.vtk.org/doc/nightly/html/classvtkMatlabMexAdapter.html#ae2f0c67e85d760929a64a37f0fe3ab54>which
converts mxArray* I can no longer call SetScalars as it takes type
vtkDataArray.  Now I am sure there is a reason for the use of const in some
functions but not others but to call
mxArrayTovtkArray<http://www.vtk.org/doc/nightly/html/classvtkMatlabMexAdapter.html#ae2f0c67e85d760929a64a37f0fe3ab54>(mxArray
*mxa) I must first cast mxa to mxArray* as the array in Matlab is
of const type : void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]).  If I use mxArrayTovtkArray
<http://www.vtk.org/doc/nightly/html/classvtkMatlabMexAdapter.html#ae2f0c67e85d760929a64a37f0fe3ab54>then
I think I need to dynamic cast to vtkTypedArray<double> or maybe
vtkDenseArray<double> though I cannot include the header files.  I have used
-DVTK_USE_N_WAY_ARRAYS=YES -DVTKSNL_N_WAY_ARRAYS=ON and
-DVTK_USE_MATLAB_MEX=YES in my build of vtk.  If I use mxArrayTovtkArray
<http://www.vtk.org/doc/nightly/html/classvtkMatlabMexAdapter.html#ae2f0c67e85d760929a64a37f0fe3ab54>where
is the means to get this into vtkImageData as 3D of doubles?

Also the calls to create the vtk pipeline are somewhat verbose anyone in vtk
programmer land ever look at using Boost.Dataflow
http://dancinghacker.com/code/dataflow/dataflow/support/examples/new_layer.htmlto
define the pipeline?

my use of vtkImageData requiring use of vtkDataArray
-snip-
vtkImageData* image = vtkImageData::New();

    image->SetDimensions( numeric_cast<int>(y_dim) ,
numeric_cast<int>(x_dim), numeric_cast<int>(z_dim) );
    image->SetOrigin(0.0, 0.0, 0.0);

    #ifndef USE_VTKMATLABMEXADAPTER
    image->GetPointData()->SetScalars(dataArray);
    #else
    image->GetPointData()->SetScalars(volumeData);
    #endif
//    image->GetPointData()->SetScalars(dataArray);

my build of vtk

-snip-
SET( THIRD_PARTY_PACKAGES
    vtk-${VTK_LIB_VERSION}
    VTKEdge-5-4-0
    dcmtk-3.5.4
    ${BOOST_PACKAGE}
)

SET( VTK_DEFINES
    -DVTKEdge_USE_CUDA=YES
    -DVTKEdge_USE_DIRECTX=YES
    -DVTKEdge_BUILD_EXAMPLES=YES
    -DVTK_USE_PARALLEL=YES
    -DBUILD_SHARED_LIBS=YES
    -DVTK_DIR=${INSTALL_PREFIX}
    -DBUILD_SHARED_LIBS=YES
    -DCUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR}
    -DCUDA_SDK_ROOT_DIR=${CUDA_SDK_ROOT_DIR}
#    -DCUDA_CUTIL_INCLUDE_DIR=${CUDA_CUTIL_INCLUDE_DIR}
    -DCUDA_CUTIL_LIBRARY=${CUDA_CUTIL_LIBRARY}
#    -DCUDA_LIBRARIES=${CUDA_LIBRARIES}
    -DVTK_USE_N_WAY_ARRAYS=YES
    -DVTKSNL_N_WAY_ARRAYS=ON
    -DVTK_USE_MATLAB_MEX=YES
    )



foreach( PACKAGE ${THIRD_PARTY_PACKAGES} )

    ExternalProject_Add(
        ${PACKAGE}
        DOWNLOAD_COMMAND ""
        SOURCE_DIR ${TOP}/source/cpp/lib/3rdParty/Win/${PACKAGE}
        BINARY_DIR ${BUILD_DIR}/ouput/bin/${PACKAGE}
        INSTALL_DIR ${INSTALL_PREFIX}
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}
-DINSTALL_PREFIX=${INSTALL_PREFIX}
        ${VTK_DEFINES}
        ${BOOST_PACKAGE_DEFS}
    )
-end snip-

Not sure if I am better served going back to the use of SetVoidArray?

-snip-

    vtkDoubleArray* dataArray = vtkDoubleArray::New();

    // Set the array to point to data
    dataArray->SetVoidArray( (void *) volumeData, y_dim*x_dim*z_dim , 1);

    vtkImageData* image = vtkImageData::New();

    image->SetDimensions( numeric_cast<int>(y_dim) ,
numeric_cast<int>(x_dim), numeric_cast<int>(z_dim) );
    image->SetSpacing(1.0, 1.0, 1.0);
    image->SetOrigin(0.0, 0.0, 0.0);
    image->GetPointData()->SetScalars(dataArray);
-end snip-

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100524/082e5c97/attachment.htm>


More information about the vtkusers mailing list