Skip to content

Instantly share code, notes, and snippets.

@pangyuteng
Last active June 15, 2021 23:09
Show Gist options
  • Save pangyuteng/8b62a6cd7d1beb7bb31dc24216cde997 to your computer and use it in GitHub Desktop.
Save pangyuteng/8b62a6cd7d1beb7bb31dc24216cde997 to your computer and use it in GitHub Desktop.
QVTKWidget vs QVTKWidget2

https://itk.org/pipermail/vtkusers/2016-April/095140.html


docker build -f Dockerfile.qt5vtk7 -t qt5vtk7 .

docker run --rm -it --gpus all \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    -e QT_X11_NO_MITSHM=1 \
    -v $PWD:/workdir -w /workdir \
    qt5vtk7 bash

mkdir build && cd build && cmake .. && make

./foo

# above seems ok

docker build -f Dockerfile.qt5vtk6 -t qt5vtk6 .

docker run --rm -it --gpus all \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    -e QT_X11_NO_MITSHM=1 \
    -v $PWD:/workdir -w /workdir \
    qt5vtk7 bash

mkdir build && cd build && cmake .. && make

./foo

# above seems ok too
qt5vtk7

setup: `x11 over ssh`+windows-wsl2+docker+ubuntu18.04

QVTKWidget:
    working !!!! VTK-7.1.1 and QT-5.10.1
    working !!!! VTK-6.1.0 and QT-5.3.0
QVTKWidget2:
    not working. VTK-7.1.1 and QT-5.10.1
    not working. VTK-6.1.0 and QT-5.3.0

setup: `x11 over ssh`+ubuntu+docker+ubuntu18.04

QVTKWidget:
    working !!!! VTK-7.1.1 and QT-5.10.1
    working !!!! VTK-6.1.0 and QT-5.3.0
QVTKWidget2:
    working !!!! VTK-7.1.1 and QT-5.10.1
    working !!!! VTK-6.1.0 and QT-5.3.0

(py) root@57cd7fd1402c:/workdir# glxinfo
name of display: :1
display: :1  screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif()
PROJECT(foo)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION
VERSION_GREATER "4")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
#find_package(Qt5Widgets REQUIRED QUIET)
find_package(Qt5 CONFIG REQUIRED COMPONENTS Core OpenGL Widgets X11Extras)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
file(GLOB UI_FILES *.ui)
file(GLOB QT_WRAP *.h)
file(GLOB CXX_FILES *.cxx)
if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION
VERSION_GREATER "4")
qt5_wrap_ui(UISrcs ${UI_FILES} )
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(foo MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP})
qt5_use_modules(foo Core Gui)
target_link_libraries(foo ${VTK_LIBRARIES})
else()
QT4_WRAP_UI(UISrcs ${UI_FILES})
QT4_WRAP_CPP(MOCSrcs ${QT_WRAP})
add_executable(vtkdemo MACOSX_BUNDLE ${CXX_FILES} ${UISrcs}
${MOCSrcs})
if(VTK_LIBRARIES)
if(${VTK_VERSION} VERSION_LESS "6")
target_link_libraries(foo ${VTK_LIBRARIES} QVTK)
else()
target_link_libraries(foo ${VTK_LIBRARIES})
endif()
else()
target_link_libraries(foo vtkHybrid QVTK vtkViews
${QT_LIBRARIES})
endif()
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11
support. Please use a different C++ compiler.")
endif()
# https://medium.com/@benjamin.botto/opengl-and-cuda-applications-in-docker-af0eece000f1
FROM ubuntu:18.04
# Dependencies for glvnd and X11.
RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
libglvnd0 \
libgl1 \
libglx0 \
libegl1 \
libxext6 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/*
# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute
FROM ubuntu:18.04
ARG MYPATH=/usr/local/lobseg
ARG MYLIBPATH=$MYPATH/lib
RUN apt-get update && apt-get install -y --no-install-recommends \
autotools-dev \
build-essential \
ca-certificates \
cmake \
git \
wget \
unzip \
libx11-dev \
vim-tiny \
software-properties-common && \
rm -rf /var/lib/apt/lists/*
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && apt update && apt-get install -y gcc-4.8 g++-4.8 gcc-5 g++-5
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 3
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 3
# attempting to fix linker error.
# + set gcc to 5.
# + added CMAKE_CXX_FLAGS -fPIC
# + itk failed to compile
# + upgrade itk to 4
ENV CMAKE_CXX_FLAGS -fPIC
# abuse opt directory.
WORKDIR /opt
# install miniconda.
# create and activate python virtual env with desired version
RUN wget --quiet --no-check-certificate https://repo.continuum.io/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh --no-check-certificate -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p /opt/conda
RUN /opt/conda/bin/conda create -n py python=3.7.2
RUN echo "source /opt/conda/bin/activate py" > ~/.bashrc
ENV PATH /opt/conda/envs/py/bin:$PATH
RUN /bin/bash -c "source /opt/conda/bin/activate py && conda install cython numpy -y && pip install scikit-build"
# build zlib
WORKDIR /opt/sources
RUN wget --quiet https://zlib.net/zlib-1.2.11.tar.gz -O zlib.tar.gz && \
tar xfz zlib.tar.gz
WORKDIR /opt/sources/zlib-1.2.11
RUN ./configure --prefix=$MYPATH && make -j"$(nproc)" && make install -j"$(nproc)"
# build boost
ENV BOOST_DOTTED_VERSION 1.60.0
ENV BOOST_ROOT /usr/local/boost-$BOOST_DOTTED_VERSION
ENV BOOST_LIBRARYDIR /usr/local/boost-$BOOST_DOTTED_VERSION/lib
ENV BOOST_INCLUDEDIR /usr/local/boost-$BOOST_DOTTED_VERSION/include/
ENV LD_LIBRARY_PATH $BOOST_LIBRARYDIR:$LD_LIBRARY_PATH
WORKDIR /opt/sources
RUN apt-get install -y --fix-missing --no-install-recommends \
libbz2-dev \
zlib1g-dev
RUN wget --quiet http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz -O boost.tar.gz && \
tar xfz boost.tar.gz
WORKDIR /opt/sources/boost_1_60_0
ENV CPLUS_INCLUDE_PATH /opt/conda/envs/py/include/python3.7m/
RUN ./bootstrap.sh --prefix=$BOOST_ROOT --with-python=python3.7 --with-libraries=python,filesystem,system,test,iostreams
# PATCH for python 3.7 compliance - see https://github.com/boostorg/python/commit/660487c43fde76f3e64f1cb2e644500da92fe582 for detail
RUN wget --quiet https://raw.githubusercontent.com/boostorg/python/660487c43fde76f3e64f1cb2e644500da92fe582/src/converter/builtin_converters.cpp
RUN mv libs/python/src/converter/builtin_converters.cpp libs/python/src/converter/builtin_converters.BAK
RUN mv builtin_converters.cpp libs/python/src/converter/builtin_converters.cpp
RUN ./b2 install
# build dcmtk
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --fix-missing --no-install-recommends \
libtiff5-dev \
libpng-dev \
libjpeg-dev \
libgif-dev \
libxml2-dev \
libssl-dev \
zlib1g-dev \
libwrap0-dev \
libssl-dev
WORKDIR /opt/sources
RUN wget --quiet https://github.com/DCMTK/dcmtk/archive/DCMTK-3.6.2.tar.gz -O dcmtk.tar.gz && \
tar xfz dcmtk.tar.gz
WORKDIR /opt/sources/dcmtk-DCMTK-3.6.2
RUN mkdir build
WORKDIR /opt/sources/dcmtk-DCMTK-3.6.2/build
ENV CXXFLAGS "-std=c++98 -Wno-error -fpermissive -DUCHAR_TYPE=uint16_t"
RUN cmake .. -DCMAKE_INSTALL_PREFIX=$MYPATH -DCMAKE_LIBRARY_PATH=$MYLIBPATH \
-DDCMTK_FORCE_FPIC_ON_UNIX:BOOL=ON
RUN make -j"$(nproc)" && make install -j"$(nproc)"
WORKDIR /opt/sources
RUN wget --quiet https://www.cs.umd.edu/~mount/ANN/Files/1.1.1/ann_1.1.1.tar.gz -O ann.tar.gz && \
tar xfz ann.tar.gz
WORKDIR /opt/sources/ann_1.1.1
RUN sed -i '1 i\#include <stdlib.h>' src/ANN.cpp
RUN sed -i '1 i\#include <stdlib.h>' src/kd_dump.cpp
RUN sed -i '1 i\#include <stdlib.h>' ann2fig/ann2fig.cpp
RUN sed -i '1 i\#include <string.h>' src/kd_dump.cpp
RUN sed -i '1 i\#include <string.h>' ann2fig/ann2fig.cpp
RUN sed -i '1 i\#include <string.h>' test/ann_test.cpp
RUN make linux-g++
# build qt
# https://doc.qt.io/qt-5/linux-requirements.html
# https://doc.qt.io/archives/qt-4.8/requirements-x11.html
# https://stackoverflow.com/questions/13220499/compiling-qt-4-8-3-on-ubuntu-12-failing/13622201
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --fix-missing --no-install-recommends \
libxt-dev libgl1-mesa-dev libglu1-mesa-dev libfontconfig-dev libncurses5-dev \
python python-dev \
mesa-utils libgl1-mesa-glx \
libxcursor-dev libxcursor1 libxcb-cursor-dev libxcb-cursor0 \
libfontconfig1-dev \
libfreetype6-dev \
libx11-dev \
libx11-xcb-dev \
libxext-dev \
libxfixes-dev \
libxi-dev \
libxrender-dev \
libxcb1-dev \
libxcb-glx0-dev \
libxcb-keysyms1-dev \
libxcb-image0-dev \
libxcb-shm0-dev \
libxcb-icccm4-dev \
libxcb-sync0-dev \
libxcb-xfixes0-dev \
libxcb-shape0-dev \
libxcb-randr0-dev \
libxcb-render-util0-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev
# libxcd-xinerama0-dev \
RUN mkdir /inst
RUN mkdir -p /opt/sources/qt
WORKDIR /inst
RUN wget https://download.qt.io/new_archive/qt/5.3/5.3.0/single/qt-everywhere-opensource-src-5.3.0.tar.xz -O qt.tar.xz && \
tar -xf qt.tar.xz -C /opt/sources/qt --strip-components 1
WORKDIR /opt/sources/qt
RUN ./configure -platform linux-g++ \
-prefix /usr/local/qt -release -opensource -confirm-license \
-openssl -qt-xcb -opengl -nomake examples -nomake tests
RUN apt-get install -yq libssl1.0-dev
RUN make -j"$(nproc)" && make install
# -static -no-qml-debug -qt-xcb -no-glib \
# -no-pulseaudio -no-alsa \
# -skip qtdeclarative \
# -skip qtscript \
# -skip qtmultimedia \
# -skip qtxmlpatterns \
# -skip qtsvg \
# -skip qtwebchannel \
# https://github.com/Kitware/VTK/releases?after=v8.0.0
# build vtk
WORKDIR /opt/sources
RUN wget https://github.com/Kitware/VTK/archive/refs/tags/v6.1.0.tar.gz -O vtk.tar.gz && \
tar xfz vtk.tar.gz
WORKDIR /opt/sources/VTK-6.1.0
#RUN sed -i 's/\[345\]/[34567]/g' CMake/vtkCompilerExtras.cmake
#RUN sed -i 's/\[345\]/[34567]/g' CMake/GenerateExportHeader.cmake
RUN mkdir build
WORKDIR /opt/sources/VTK-6.1.0/build
ENV OPENGL_FLAG OpenGL
RUN cmake .. -DCMAKE_INSTALL_PREFIX=$MYPATH \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS:BOOL=OFF \
-DVTK_RENDERING_BACKEND=$OPENGL_FLAG \
-DCMAKE_C_FLAGS=-DGLX_GLXEXT_LEGACY \
-DCMAKE_CXX_FLAGS=-DGLX_GLXEXT_LEGACY \
-DVTK_Group_Qt:BOOL=OFF \
-DVTK_QT_VERSION:STRING=5 \
-DQT_QMAKE_EXECUTABLE:FILEPATH=/usr/local/qt/bin/qmake \
-DModule_vtkGUISupportQt:BOOL=ON \
-DModule_vtkGUISupportQtOpenGL:BOOL=ON \
-DQt5_DIR:PATH=/usr/local/qt/lib/cmake/Qt5 \
-DQt5Widgets_DIR=/usr/local/qt/lib/cmake/Qt5Widgets \
-DQt5OpenGL_DIR=/usr/local/qt/lib/cmake/Qt5OpenGL
RUN make -j"$(nproc)" && make install -j"$(nproc)"
# build gdcm
# WORKDIR /opt/sources
# RUN wget --quiet https://github.com/malaterre/GDCM/archive/v3.0.4.tar.gz -O gdcm.tar.gz && \
# tar -zxvf gdcm.tar.gz
# WORKDIR /opt/sources/GDCM-3.0.4
# RUN mkdir build
# WORKDIR /opt/sources/GDCM-3.0.4/build
# RUN cmake .. \
# -DCMAKE_INSTALL_RPATH=/local/gdcm/lib \
# -DCMAKE_INSTALL_PREFIX=/local/gdcm \
# -DGDCM_BUILD_APPLICATIONS=1 \
# -DGDCM_BUILD_SHARED_LIBS=1
# RUN make -j"$(nproc)" install
# https://github.com/Kitware/ITK/releases?after=v4.13.0
# build itk
WORKDIR /opt/sources
#RUN wget --quiet https://sourceforge.net/projects/itk/files/itk/3.20/InsightToolkit-3.20.1.tar.gz/download -O itk.tar.gz && \
# tar xfz itk.tar.gz
#WORKDIR /opt/sources/InsightToolkit-3.20.1
#RUN mkdir build
#WORKDIR /opt/sources/InsightToolkit-3.20.1/build
RUN wget --quiet https://github.com/Kitware/ITK/archive/refs/tags/v4.12.2.tar.gz -O itk.tar.gz && \
tar xfz itk.tar.gz
WORKDIR /opt/sources/ITK-4.12.2
RUN mkdir build
WORKDIR /opt/sources/ITK-4.12.2/build
RUN cmake .. \
-DCMAKE_INSTALL_PREFIX=$MYPATH \
-DCMAKE_LIBRARY_PATH=$MYLIBPATH \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_DOXYGEN=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DITK_DYNAMIC_LOADING=OFF \
-DBUILD_TESTING=OFF \
-DCMAKE_BACKWARDS_COMPATIBILITY=3.1 \
-DITK_USE_KWSTYLE=OFF \
-DModule_ITKVtkGlue=ON \
-DITK_USE_REVIEW=ON \
-DITK_BUILD_ALL_MODULES=ON
RUN make -j"$(nproc)" && make install -j"$(nproc)"
# -DITK_USE_SYSTEM_GDCM=ON \
# -DGDCM_DIR=/opt/sources/GDCM-3.0.4/build
ENV MAIN_LIBRARYDIR $MYPATH/lib
ENV LD_LIBRARY_PATH $MAIN_LIBRARYDIR:$LD_LIBRARY_PATH
ENV ITK_LIBRARYDIR $MYPATH/lib/InsightToolkit
ENV LD_LIBRARY_PATH $ITK_LIBRARYDIR:$LD_LIBRARY_PATH
ENV QT_LIBRARYDIR /usr/local/qt/lib
ENV LD_LIBRARY_PATH $QT_LIBRARYDIR:$LD_LIBRARY_PATH
#ENV GDCM_PATH /usr/local/gdcm
#ENV LD_LIBRARY_PATH $GDCM_PATH:$LD_LIBRARY_PATH
ENV LDFLAGS -L$MAIN_LIBRARYDIR:$LDFLAGS
ENV LDFLAGS -L$ITK_LIBRARYDIR:$LDFLAGS
ENV LDFLAGS -L$QT_LIBRARYDIR:$LDFLAGS
ENV QT_GRAPHICSSYSTEM raster
ENV LIBGL_ALWAYS_INDIRECT 1
ENV QT_XKB_CONFIG_ROOT /usr/share/X11/xkb:
WORKDIR /opt
# cd to workdir and build # TODO, move code (move LUNG_SEGMENTATION and PCL to within container??)
#WORKDIR /medqia/LUNG_SEGMENTATION/dev
#RUN rm -rf _skbuild; \
# python setup.py build
RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
libglvnd0 \
libgl1 \
libglx0 \
libegl1 \
libxext6 \
libx11-6
# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute
ENV Qt5_DIR /usr/local/qt/lib/cmake/Qt5
ENV ITK_DIR /opt/sources/ITK-4.12.2/build
ENV VTK_DIR /opt/sources/VTK-6.1.0/build
FROM ubuntu:18.04
ARG MYPATH=/usr/local/lobseg
ARG MYLIBPATH=$MYPATH/lib
RUN apt-get update && apt-get install -y --no-install-recommends \
autotools-dev \
build-essential \
ca-certificates \
cmake \
git \
wget \
unzip \
libx11-dev \
vim-tiny \
software-properties-common && \
rm -rf /var/lib/apt/lists/*
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && apt update && apt-get install -y gcc-4.8 g++-4.8 gcc-5 g++-5
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 3
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 3
ENV CMAKE_CXX_FLAGS -fPIC
# abuse opt directory.
WORKDIR /opt
# install miniconda.
# create and activate python virtual env with desired version
RUN wget --quiet --no-check-certificate https://repo.continuum.io/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh --no-check-certificate -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p /opt/conda
RUN /opt/conda/bin/conda create -n py python=3.7.2
RUN echo "source /opt/conda/bin/activate py" > ~/.bashrc
ENV PATH /opt/conda/envs/py/bin:$PATH
RUN /bin/bash -c "source /opt/conda/bin/activate py && conda install cython numpy -y && pip install scikit-build"
# build zlib
WORKDIR /opt/sources
RUN wget --quiet https://zlib.net/zlib-1.2.11.tar.gz -O zlib.tar.gz && \
tar xfz zlib.tar.gz
WORKDIR /opt/sources/zlib-1.2.11
RUN ./configure --prefix=$MYPATH && make -j"$(nproc)" && make install -j"$(nproc)"
# build boost
ENV BOOST_DOTTED_VERSION 1.60.0
ENV BOOST_ROOT /usr/local/boost-$BOOST_DOTTED_VERSION
ENV BOOST_LIBRARYDIR /usr/local/boost-$BOOST_DOTTED_VERSION/lib
ENV BOOST_INCLUDEDIR /usr/local/boost-$BOOST_DOTTED_VERSION/include/
ENV LD_LIBRARY_PATH $BOOST_LIBRARYDIR:$LD_LIBRARY_PATH
WORKDIR /opt/sources
RUN apt-get install -y --fix-missing --no-install-recommends \
libbz2-dev \
zlib1g-dev
RUN wget --quiet http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz -O boost.tar.gz && \
tar xfz boost.tar.gz
WORKDIR /opt/sources/boost_1_60_0
ENV CPLUS_INCLUDE_PATH /opt/conda/envs/py/include/python3.7m/
RUN ./bootstrap.sh --prefix=$BOOST_ROOT --with-python=python3.7 --with-libraries=python,filesystem,system,test,iostreams
# PATCH for python 3.7 compliance - see https://github.com/boostorg/python/commit/660487c43fde76f3e64f1cb2e644500da92fe582 for detail
RUN wget --quiet https://raw.githubusercontent.com/boostorg/python/660487c43fde76f3e64f1cb2e644500da92fe582/src/converter/builtin_converters.cpp
RUN mv libs/python/src/converter/builtin_converters.cpp libs/python/src/converter/builtin_converters.BAK
RUN mv builtin_converters.cpp libs/python/src/converter/builtin_converters.cpp
RUN ./b2 install
# build dcmtk
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --fix-missing --no-install-recommends \
libtiff5-dev \
libpng-dev \
libjpeg-dev \
libgif-dev \
libxml2-dev \
libssl-dev \
zlib1g-dev \
libwrap0-dev \
libssl-dev
WORKDIR /opt/sources
RUN wget --quiet https://github.com/DCMTK/dcmtk/archive/DCMTK-3.6.2.tar.gz -O dcmtk.tar.gz && \
tar xfz dcmtk.tar.gz
WORKDIR /opt/sources/dcmtk-DCMTK-3.6.2
RUN mkdir build
WORKDIR /opt/sources/dcmtk-DCMTK-3.6.2/build
ENV CXXFLAGS "-std=c++98 -Wno-error -fpermissive -DUCHAR_TYPE=uint16_t"
RUN cmake .. -DCMAKE_INSTALL_PREFIX=$MYPATH -DCMAKE_LIBRARY_PATH=$MYLIBPATH \
-DDCMTK_FORCE_FPIC_ON_UNIX:BOOL=ON
RUN make -j"$(nproc)" && make install -j"$(nproc)"
WORKDIR /opt/sources
RUN wget --quiet https://www.cs.umd.edu/~mount/ANN/Files/1.1.1/ann_1.1.1.tar.gz -O ann.tar.gz && \
tar xfz ann.tar.gz
WORKDIR /opt/sources/ann_1.1.1
RUN sed -i '1 i\#include <stdlib.h>' src/ANN.cpp
RUN sed -i '1 i\#include <stdlib.h>' src/kd_dump.cpp
RUN sed -i '1 i\#include <stdlib.h>' ann2fig/ann2fig.cpp
RUN sed -i '1 i\#include <string.h>' src/kd_dump.cpp
RUN sed -i '1 i\#include <string.h>' ann2fig/ann2fig.cpp
RUN sed -i '1 i\#include <string.h>' test/ann_test.cpp
RUN make linux-g++
# build qt
# https://doc.qt.io/qt-5/linux-requirements.html
# https://doc.qt.io/archives/qt-4.8/requirements-x11.html
# https://stackoverflow.com/questions/13220499/compiling-qt-4-8-3-on-ubuntu-12-failing/13622201
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --fix-missing --no-install-recommends \
libxt-dev libgl1-mesa-dev libglu1-mesa-dev libfontconfig-dev libncurses5-dev \
python python-dev \
mesa-utils libgl1-mesa-glx \
libxcursor-dev libxcursor1 libxcb-cursor-dev libxcb-cursor0 \
libfontconfig1-dev \
libfreetype6-dev \
libx11-dev \
libx11-xcb-dev \
libxext-dev \
libxfixes-dev \
libxi-dev \
libxrender-dev \
libxcb1-dev \
libxcb-glx0-dev \
libxcb-keysyms1-dev \
libxcb-image0-dev \
libxcb-shm0-dev \
libxcb-icccm4-dev \
libxcb-sync0-dev \
libxcb-xfixes0-dev \
libxcb-shape0-dev \
libxcb-randr0-dev \
libxcb-render-util0-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev
RUN mkdir /inst
RUN mkdir -p /opt/sources/qt
WORKDIR /inst
RUN wget https://download.qt.io/new_archive/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz -O qt.tar.xz && \
tar -xf qt.tar.xz -C /opt/sources/qt --strip-components 1
WORKDIR /opt/sources/qt
RUN ./configure -platform linux-g++ \
-prefix /usr/local/qt -release -opensource -confirm-license \
-qt-xcb -opengl -nomake examples -nomake tests
RUN make -j"$(nproc)" && make install
# https://github.com/Kitware/VTK/releases?after=v8.0.0
# build vtk
WORKDIR /opt/sources
RUN wget https://www.vtk.org/files/release/7.1/VTK-7.1.1.tar.gz -O vtk.tar.gz && \
tar xfz vtk.tar.gz
WORKDIR /opt/sources/VTK-7.1.1
RUN mkdir build
WORKDIR /opt/sources/VTK-7.1.1/build
ENV OPENGL_FLAG OpenGL
RUN cmake .. -DCMAKE_INSTALL_PREFIX=$MYPATH \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS:BOOL=OFF \
-DVTK_RENDERING_BACKEND=$OPENGL_FLAG \
-DVTK_Group_Qt:BOOL=ON \
-DModule_vtkGUISupportQt:BOOL=ON \
-DModule_vtkGUISupportQtOpenGL:BOOL=ON \
-DQT_QMAKE_EXECUTABLE:FILEPATH=/usr/local/qt/bin/qmake \
-DQt5_DIR:PATH=/usr/local/qt/lib/cmake/Qt5 \
-DVTK_QT_VERSION:STRING=5
RUN make -j"$(nproc)" && make install -j"$(nproc)"
# https://github.com/Kitware/ITK/releases?after=v4.13.0
# build itk
WORKDIR /opt/sources
RUN wget --quiet https://github.com/Kitware/ITK/archive/refs/tags/v4.12.2.tar.gz -O itk.tar.gz && \
tar xfz itk.tar.gz
WORKDIR /opt/sources/ITK-4.12.2
RUN mkdir build
WORKDIR /opt/sources/ITK-4.12.2/build
RUN cmake .. \
-DCMAKE_INSTALL_PREFIX=$MYPATH \
-DCMAKE_LIBRARY_PATH=$MYLIBPATH \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_DOXYGEN=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DITK_DYNAMIC_LOADING=OFF \
-DBUILD_TESTING=OFF \
-DCMAKE_BACKWARDS_COMPATIBILITY=3.1 \
-DITK_USE_KWSTYLE=OFF \
-DModule_ITKVtkGlue=ON \
-DITK_USE_REVIEW=ON \
-DITK_BUILD_ALL_MODULES=ON
RUN make -j"$(nproc)" && make install -j"$(nproc)"
ENV MAIN_LIBRARYDIR $MYPATH/lib
ENV LD_LIBRARY_PATH $MAIN_LIBRARYDIR:$LD_LIBRARY_PATH
ENV ITK_LIBRARYDIR $MYPATH/lib/InsightToolkit
ENV LD_LIBRARY_PATH $ITK_LIBRARYDIR:$LD_LIBRARY_PATH
ENV QT_LIBRARYDIR /usr/local/qt/lib
ENV LD_LIBRARY_PATH $QT_LIBRARYDIR:$LD_LIBRARY_PATH
ENV LDFLAGS -L$MAIN_LIBRARYDIR:$LDFLAGS
ENV LDFLAGS -L$ITK_LIBRARYDIR:$LDFLAGS
ENV LDFLAGS -L$QT_LIBRARYDIR:$LDFLAGS
ENV QT_GRAPHICSSYSTEM raster
ENV LIBGL_ALWAYS_INDIRECT 1
ENV QT_XKB_CONFIG_ROOT /usr/share/X11/xkb:
WORKDIR /opt
RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
libglvnd0 \
libgl1 \
libglx0 \
libegl1 \
libxext6 \
libx11-6
# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute
ENV Qt5_DIR /usr/local/qt/lib/cmake/Qt5
ENV ITK_DIR /opt/sources/ITK-4.12.2/build
ENV VTK_DIR /opt/sources/VTK-7.1.1/build
/*
https://itk.org/pipermail/vtkusers/2016-April/095140.html
[vtkusers] Using VTK and QT on Linux
myk myk321 at gmail.com
Thu Apr 28 09:09:33 EDT 2016
Previous message: [vtkusers] How to contribute to the wiki with some examples
Next message: [vtkusers] VTK - Progressive loading of mesh ?
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I've been trying to get VTK and Qt working on Linux. I happened on a
setup the other day and thought I would share what worked for me. To
cut to the chase what worked is: VTK 6.1 + Qt 5.3 + QVTKWidget2 +
OpenGL (not OpenGL2) on a non intel-graphics stack. I've tried this
successfully on AMD graphics cards and unsuccessfully on intel graphics
running open source drivers under MESA (Gallium). I tried VTK7.0 in
about 8 combinations (on intel) without success.
I got to this solution based partly with google and of course piles of
experimentation. The rules, as I understand them, are as follows:
(a) QVTKWidget does not work on intel i915 drivers because it does not
return a depth buffer
-> Supposedly using QVTKWidget2 works around this but in my experience
that also does not work - so if you have intel graphics it seems you
need to either add some AMD or Nvidia (aahh!) graphics hardware or get
windows (double aaah!!!)
Ref: http://public.kitware.com/pipermail/vtk-developers/2014-May/014998
.html
(b) When compiling with OpenGL2, the QVTKWidget2 object is not included
in the .so, so you can't link. So to get the object created you need
to build with OpenGL and NOT OpenGL2
http://comments.gmane.org/gmane.comp.lib.vtk.user/78123
(c) QVTKWidget2 requires Qt version of 5.3 or lower
http://stackoverflow.com/questions/26944831/using-qvtkwidget-and-qopeng
lwidget-in-the-same-ui
(d) QVTKWidget2 was broken in VTK 6.2 onwards and thus you need to
build with vtk 6.1. Refer to GitHub to get it.
Ref: http://vtk.1045678.n5.nabble.com/QVTKWidget2-status-td5732729.html
(e) For VTK 6.1 you need to build it special command line parameters
Ref: http://stackoverflow.com/questions/28761702/getting-error-glintptr
-has-not-been-declared-when-building-vtk-on-linux
On Fedora 23 on amd64, I download:
Qt to the default ~/Qt/5.3
VTK 6.1 to ~/VTK-6.1.0
I build in ~/vtk61-qt53
where
~ = /home/myk
I completed the one-off VTK build with following commands:
cd ~/vtk61-qt53
cmake -DVTK_QT_VERSION:STRING=5 \
-DCMAKE_BUILD_TYPE=Release \
-DQT_QMAKE_EXECUTABLE:PATH=/home/myk/Qt/5.3/gcc_64/bin/qmake \
-DVTK_Group_Qt:BOOL=ON \
-DCMAKE_PREFIX_PATH:PATH=/home/myk/Qt/5.3/gcc_64/lib/cmake \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DCMAKE_C_FLAGS=-DGLX_GLXEXT_LEGACY \
-DCMAKE_CXX_FLAGS=-DGLX_GLXEXT_LEGACY \
-Wno-dev \
../VTK-6.1.0
make -j4
sudo make install
For the 'make -j4' replace the '4' with the number of cores on your
machine - in my experience this is worth the effort!
I then use cmake in a .../build directory with the following command:
cmake -DVTK_QT_VERSION:STRING="5"
-DCMAKE_PREFIX_PATH=/home/myk/Qt/5.3/gcc_64/
-DCMAKE_PREFIX_PATH=/home/myk/Qt/5.3/gcc_64/lib/cmake/Qt5Widgets/
-DVTK_DIR=/usr/local/include/vtk-6.1/ -DCMAKE_BUILD_TYPE=Debug ..
make
Finally I've inserted some very basic Qt + VTK code below that creates
a QVKWidget2 so you can test the results (my apologies for my funny c
style programming with C++ comments).
Please call out if you have another combination which works on linux or
have found a way around any of these issues.
Kind regards,
Michael
PS: Some additional pointers:
(1) In my experience you can't have both a QVTKWidget and a QVTKWidget2
displayed on the same window at the same time - the QVTKWidget will
display but not the QVTKWidget2, so you need to be consistent.
(2) If you create two VTKWidget2's and give them both the same
renderer, the first QVTKWidget2 one will display junk and generate
OpenGL errors when you interact with it, while the second QVTKWidget
will work just fine.
(3) If you try any of this with Intel graphics hardware under MESA
expect to just get OpenGL errors.
*/
#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QToolBar>
#include <QDesktopWidget>
#include <QVTKWidget.h>
#include <QVTKWidget2.h>
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkNew.h>
#include <vtkSphereSource.h>
#include <vtkAppendPolyData.h>
#include <vtkCamera.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkProperty.h>
#include <vtkGenericOpenGLRenderWindow.h>
int main(int argc,char* argv[]) {
QApplication app(argc,argv);
QMainWindow MainWindow;
//Give the window a reasonable initial size
QDesktopWidget Desktop;
MainWindow.setFixedSize(Desktop.width()*0.7, Desktop.height()*0.5);
//Create the VTK widgets
QVTKWidget* widget = new QVTKWidget();
QVTKWidget2* widget2 = new QVTKWidget2();
//Layout the VTK widgets in a horizontal format
QHBoxLayout *HorLayout = new QHBoxLayout();
//HorLayout->addWidget(widget);
HorLayout->addWidget(widget2);
// head to `AddRenderer` to un/comment widget/widget2
QWidget *LayoutWidget = new QWidget();
LayoutWidget->setLayout(HorLayout);
MainWindow.setCentralWidget(LayoutWidget);
//Create the spheres to display
vtkSmartPointer<vtkAppendPolyData> translucentGeometry = vtkSmartPointer<vtkAppendPolyData>::New();
for (int i = 0; i < 5; i++) {
vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetThetaResolution(100);
sphereSource->SetPhiResolution(100);
sphereSource->SetRadius(0.5); // all spheres except the center one should have radius = 0.5
switch (i) {
case 0:
sphereSource->SetRadius(1);
sphereSource->SetCenter(0, 0, 0); break;
case 1:
sphereSource->SetCenter(1, 0, 0); break;
case 2:
sphereSource->SetCenter(-1, 0, 0); break;
case 3:
sphereSource->SetCenter(0, 1, 0); break;
case 4:
sphereSource->SetCenter(0, -1, 0); break;
}
sphereSource->Update();
translucentGeometry->AddInputConnection(sphereSource->GetOutputPort());
}
//Create the mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(translucentGeometry->GetOutputPort());
//Create the actor
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetOpacity(1); //1=Spheres are fully opaque; 0 = spheres are fully transparent; 0.5 =transparent
actor->GetProperty()->SetColor(1, 0, 0); //Red spheres
actor->RotateX(-72); // put the objects in a position where it is easy to see
//Create the renderer
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(1, 1, 1); //white background
//Create the renderer2
vtkSmartPointer<vtkRenderer> renderer2 =vtkSmartPointer<vtkRenderer>::New();
renderer2->AddActor(actor);
renderer2->SetBackground(1, 1, 1); //white background
//Add the renderer to the VTK widget
//widget->GetRenderWindow()->AddRenderer(renderer);
widget2->GetRenderWindow()->AddRenderer(renderer2);
//Format everything nicely
//renderer->ResetCamera();
//renderer->GetActiveCamera()->Zoom(2.2); //zoom-in
renderer2->ResetCamera();
renderer2->GetActiveCamera()->Zoom(2.2); //zoom-in
//Display the Qt window
MainWindow.show();
return app.exec();
}
@pangyuteng
Copy link
Author

#ifndef _WIN32
QSurfaceFormat fmt;
fmt.setRenderableType(QSurfaceFormat::OpenGL);
fmt.setVersion(3, 2);
fmt.setProfile(QSurfaceFormat::CoreProfile);
fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
fmt.setRedBufferSize(1);
fmt.setGreenBufferSize(1);
fmt.setBlueBufferSize(1);
fmt.setDepthBufferSize(1);
fmt.setStencilBufferSize(0);
fmt.setAlphaBufferSize(1);
fmt.setStereo(false);
fmt.setSamples( vtkOpenGLRenderWindow::GetGlobalMaximumNumberOfMultiSamples() );
  
QSurfaceFormat::setDefaultFormat(fmt);
#endif

savior of the day. custom QSurfaceFormat for linux from below:
http://quaoar.su/blog/page/the-qvtkwidget-is-dead-long-live-the-qvtkwidget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment