Adding volume in C++

I’m working on custom slicer app and now I need to understand how to add volume in C++.

For example I have Eigen::MatrixXf that can be represented as vtkImageData.
To display my data I guess I need to call GetScene() (or GetMRMLScene() I don’t know exactly) and then call AddNode(myVtkImage).

If so I cannot understand how to call GetScene() from mainwindow class? What header contains this GetScene?

When your module is instantiated the scene is passed to both the module logic and widget classes and they can be accessed as this->GetMRMLScene() and this->mrmlScene(), respectively.

All other classes should get the scene from these classes (e.g., the module widget sets the scene in its child widgets), but if you need any quick hack anywhere then you can access the application singleton, get the application logic from it, and from that you can get the scene. It is better to avoid getting the scene from the application though, because it adds unnecessary dependencies and assumptions, which make the class less reusable.

1 Like

Thank you!

One another related question that has now appeared:

If my module depends on my SlicerCAT library wich is added via slicerMacroBuildAppLibrary(NAME qColada ...) and thus should be called qColada, how can I find_package(qColada REQUIRED) from my loadable module’s CMakeLists? As I can see slicerMacroBuildAppLibrary() doesn’t produce something like qColadaConfig.cmake inside Slicer-build. (in contrast to SlicerConfig.cmake wich resides in this folder and thus can be easily found).

I guess I need somehow pass -DqColada_DIR=/path/to/ColadaConfig.cmake when configuring my module…

I forgot to notice that I’m trying to build module externally

find_package is for external packages. Within Slicer, the module libraries and headers are available as CMake variables. See for example, here how libraries of Subject Hierarchy and Markups modules are used in a SlicerIGT module.

1 Like

I think now I see how this works. Variables marked mark_as_superbuild(...) are kept in SlicerConfig.cmake and thus I can use them to find my dependencies.

Thank you!

1 Like

Also I can see now that the target qColadaApp is defined as:

if (TARGET qColadaApp)
  message("qColadaApp EXIST")
endif()

prints: qColadaApp EXIST

But when I link this target qColadaApp to my module:

set(MODULE_TARGET_LIBRARIES
  vtkSlicer${MODULE_NAME}ModuleLogic
  qSlicer${MODULE_NAME}ModuleWidgets
  qColadaApp    # my custom Slicer library
  )

#-----------------------------------------------------------------------------
slicerMacroBuildLoadableModule(
  NAME ${MODULE_NAME}
  TITLE ${MODULE_TITLE}
  EXPORT_DIRECTIVE ${MODULE_EXPORT_DIRECTIVE}
  INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
  SRCS ${MODULE_SRCS}
  MOC_SRCS ${MODULE_MOC_SRCS}
  UI_SRCS ${MODULE_UI_SRCS}
  TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES}
  RESOURCES ${MODULE_RESOURCES}
  WITH_GENERIC_TESTS
  )

I see that IDE can’t include headers from that target. Picture below. Probably some target properties are missing?

I guess I have found a solution. I should have manually added include folders to my ColadaApp headers (and export header wich is in Slicer-build/Applications/ColadaApp:

# Current_{source,binary} and Slicer_{Libs,Base} already included
set(MODULE_INCLUDE_DIRECTORIES
  ${CMAKE_CURRENT_SOURCE_DIR}/Logic
  ${CMAKE_CURRENT_BINARY_DIR}/Logic
  ${CMAKE_CURRENT_SOURCE_DIR}/Widgets
  ${CMAKE_CURRENT_BINARY_DIR}/Widgets

  # These two are my dirs
  ${CMAKE_CURRENT_SOURCE_DIR}/../../../Applications/ColadaApp
  ${Slicer_BINARY_DIR}/Applications/ColadaApp
  )

slicerMacroBuildLoadableModule(
...
  INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
...
  )

I hope the number of my questions grows slower than the answers on them :slight_smile:

1 Like

A post was split to a new topic: Change memory layout of images