c++ - VTK Volume Visualization Issue -


i using vtk library c++ generate , visualize synthetic voxel data given color , transparency mapping. example shown below: sample image

as shown in figure, data 3d in general, , works great. however, in specific cases when data becomes 2d, visualization windows shows nothing.

i posting few lines of code may helpful.

imagedata = vtksmartpointer<vtkimagedata>::new(); imagedata->setdimensions(x1, x2, x3); //for 2d, 1 of x1,x2 & x3=1 imagedata->allocatescalars(vtk_int, 1); int* = new int[x1x2x3](); //int x1x2x3 = x1*x2*x3 = static_cast<int*>(imagedata->getscalarpointer()); 

please note 2d, either x1=1 or x2=1 or x3=1. suggestions?

edit: adding equivalent code, demonstrate exact problem facing:

main.cpp

//#include <vtkautoinit.h> // if not using cmake compile, necessary use macro //#define vtkrenderingcore_autoinit 3(vtkinteractionstyle, vtkrenderingfreetype, vtkrenderingopengl2) //#define vtkrenderingvolume_autoinit 1(vtkrenderingvolumeopengl2) //#define vtkrenderingcontext2d_autoinit 1(vtkrenderingcontextopengl2) #include <vtksmartpointer.h> #include <vtkactor.h> #include <vtkrenderwindow.h> #include <vtkrenderer.h> #include <vtkrenderwindowinteractor.h> #include <vtksmartvolumemapper.h> #include <vtkcolortransferfunction.h> #include <vtkvolumeproperty.h> #include <vtksamplefunction.h> #include <vtkpiecewisefunction.h> #include <vtkimagedata.h> #include <stdlib.h> using namespace std;  int main() {     //declaring variables     vtksmartpointer<vtkimagedata> imagedata;     vtksmartpointer<vtkvolumeproperty> volumeproperty;     vtksmartpointer<vtkpiecewisefunction> compositeopacity;     vtksmartpointer<vtkcolortransferfunction> color;     vtksmartpointer<vtkvolume> volume;     vtksmartpointer<vtksmartvolumemapper> mapper;     vtksmartpointer<vtkactor> actor;     vtksmartpointer<vtkrenderer> renderer;     vtksmartpointer<vtkrenderwindowinteractor> renderwindowinteractor;     vtksmartpointer<vtkrenderwindow> renderwindow;     int* i;     int x1, x2, x3, x1x2x3;      //assigning values , allocating memory     x1 = 10;     x2 = 10;     x3 = 10;     x1x2x3 = x1*x2*x3;     = new int[x1x2x3]();     imagedata = vtksmartpointer<vtkimagedata>::new();     volumeproperty = vtksmartpointer<vtkvolumeproperty>::new();     compositeopacity = vtksmartpointer<vtkpiecewisefunction>::new();     color = vtksmartpointer<vtkcolortransferfunction>::new();     volume = vtksmartpointer<vtkvolume>::new();     mapper = vtksmartpointer<vtksmartvolumemapper>::new();     actor = vtksmartpointer<vtkactor>::new();     renderer = vtksmartpointer<vtkrenderer>::new();     renderwindowinteractor = vtksmartpointer<vtkrenderwindowinteractor>::new();     renderwindow = vtksmartpointer<vtkrenderwindow>::new();      volumeproperty->shadeoff();     volumeproperty->setinterpolationtype(0);     volumeproperty->setcolor(color);     volumeproperty->setscalaropacity(compositeopacity);     imagedata->setdimensions(x1, x2, x3);     imagedata->allocatescalars(vtk_int, 1);     = static_cast<int*>(imagedata->getscalarpointer());     renderwindow->addrenderer(renderer);     renderwindowinteractor->setrenderwindow(renderwindow);     renderer->setbackground(0.5, 0.5, 0.5);     renderwindow->setsize(800, 800);         mapper->setblendmodetocomposite();     imagedata->updatecellghostarraycache();     mapper->setrequestedrendermodetoraycast();     mapper->setinputdata(imagedata);     volume->setmapper(mapper);     volume->setproperty(volumeproperty);     renderer->addviewprop(volume);     volumeproperty->shadeoff();      //setting voxel data , properties     (int = 0; < x1x2x3; i++)     {         i[i] = i;         compositeopacity->addpoint(i, 1);         color->addrgbpoint(i, double( rand()) / rand_max, double(rand()) / rand_max, double(rand()) / rand_max);     }      renderer->resetcamera();     renderwindow->render();     renderwindowinteractor->start();     getchar();     return 0; } 

cmakelists.txt

cmake_minimum_required(version 3.0) project(evosim) set(cmake_cxx_standard 14) set(cmake_windows_export_all_symbols on) set(cmake_use_relative_paths on) #grabbing vtk find_package(vtk required) include(${vtk_use_file})  add_executable(main main.cpp) target_link_libraries(main ${vtk_libraries}) 

this leads output below (for, x1=x2=x3=10) enter image description here

however if make x1=1, output window empty.

edit:

i observed number of voxels along dimension, displayed on screen 1 less maximum number of voxels in dimensions. example, if x1=x2=x3=10, number of voxels in each dimensions displayed on vtkwindow 9. not expect. think problem x1=1, makes 1-1=0 voxel display. suggestions??


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -