/**

\page tutorial-install-jetson-quasar Tutorial: Installation from source on a Jetson TX2 equipped with a Quasar Carrier board
\tableofcontents

In this tutorial you will learn how to install ViSP from source on Jetson TX2 equipped with a Connect Tech Quasar Carrier board.

\image html img-jetson-tx2-quasar.jpg

\note ViSP is already packaged for linux Jetson. To know which version is available
\verbatim
$ apt-cache search libvisp
\endverbatim
Installation instructions are provided in \ref tutorial-install-ubuntu-package
\note Concerning ViSP installation, we provide also other \ref tutorial.

\section install_jetson_quasar_required Install prerequisites

This tutorial was tested with NVIDIA Jetson TX2 flashed with `JetPack 4.6(rev3)`.
- The first step is to setup and flash your Jetson for a Connect Tech Carrier Board following this <a href="https://connecttech.com/resource-center/kdb373/">tutorial</a>. This could be achieved from a laptop running ubuntu `16.04` or `18.04`.
- The second step is to install `NVIDIA SDK Components` using this <a href="https://connecttech.com/resource-center/kdb374/">tutorial</a>.

- The third step consists in installing GNU g++ compiler, CMake, git and subversion. To this end connect to the Jetson and run.

\verbatim
$ sudo apt-get install build-essential cmake-curses-gui git subversion wget
\endverbatim

\section install_jetson_quasar_ws Create a workspace

First create a workspace that will contain all ViSP source, build, data set and optional 3rd parties. This workspace is here set to `$HOME/visp-ws` folder, but it could be set to any other location.

In a terminal, run:
\verbatim
$ echo "export VISP_WS=$HOME/visp-ws" >> ~/.bashrc
$ source ~/.bashrc
$ mkdir -p $VISP_WS
\endverbatim

\section install_jetson_quasar_quick Quick ViSP installation

In this section, we give minimal instructions to build ViSP from source just to try ViSP without entering in \ref install_jetson_advanced.

- Install a small number of recommended 3rd parties (knowing that OpenCV should be already installed if you follow this <a href="https://github.com/NVIDIA-Jetson/jetson-trashformers/wiki/Jetson%E2%84%A2-Flashing-and-Setup-Guide-for-a-Connect-Tech-Carrier-Board">tutorial</a>).
\verbatim
$ sudo apt-get install libx11-dev liblapack-dev libeigen3-dev libv4l-dev libzbar-dev libpthread-stubs0-dev libjpeg-dev libpng-dev
\endverbatim

- Get ViSP source code
\verbatim
$ cd $VISP_WS
$ git clone https://github.com/lagadic/visp.git
\endverbatim

- Create a build folder and build ViSP
\verbatim
$ mkdir -p $VISP_WS/visp-build
$ cd $VISP_WS/visp-build
$ cmake ../visp
$ make -j4
\endverbatim

- Set `VISP_DIR` environment variable
\verbatim
$ echo "export VISP_DIR=$VISP_WS/visp-build" >> ~/.bashrc
$ source ~/.bashrc
\endverbatim

To have a trial, just jump to \ref install_jetson_dataset before running some binaries that you just build or jump to \ref install_jetson_next. You can later come back to the \ref install_jetson_advanced.

\section install_jetson_quasar_advanced Advanced ViSP installation

\subsection install_jetson_quasar_3rdparty Install 3rd parties

ViSP is interfaced with several optional 3rd party libraries.
Follow the link to see the complete list of \ref supported-third-parties.

\note ViSP can be used without any third-party since all of them are optional. But obviously in this case, as we do not want to reinvent the wheel, some features implemented in third-party libraries will not be exploitable through ViSP. It is therefore possible to skip in a first time this section and start directly to \ref install_jetson_quick. Later, if you realize that a third-party library is missing, you can still install it, go back to the build folder, configure ViSP with CMake to detect the newly installed third-party library and build ViSP again as explained in \ref install_jetson_tips_new_3rdparty.

\subsubsection install_jetson_quasar_3rdparty_recommended Recommended 3rd parties

We recommend to install the following 3rd parties:

- OpenCV
- libX11 to be able to open a window to display images
- lapack and eigen to benefit from optimized mathematical capabilities
- libv4l to grab images from usb or analogic cameras
- libzbar to be able to detect QR codes
- pthread library

Installation of the other recommended 3rd parties could be performed running:
\verbatim
$ sudo apt-get install libopencv-dev libx11-dev liblapack-dev libeigen3-dev libv4l-dev libzbar-dev libpthread-stubs0-dev libdc1394-22-dev
\endverbatim

\subsubsection install_jetson_quasar_3rdparty_opencv Install OpenCV from source

To be able to run the tutorial, you should install OpenCV from source, since some extra modules are required (`cudev`, `cudaarithm` and `cudawarping` are not included in `libopencv-contrib-dev` package).
To do so, proceed as follows:

- In `VISP_WS`, clone `opencv` and `opencv_contrib` repos:
\code
$ mkdir -p $VISP_WS/3rdparty
$ cd $VISP_WS/3rdparty
$ git clone https://github.com/opencv/opencv
$ git clone https://github.com/opencv/opencv_contrib
\endcode

- Create `build` directory in `opencv` directory
\code
$ cd opencv && mkdir build && cd build
\endcode

- To install opencv with extra modules, execute the following command:
\code
$ cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
        -DWITH_CUDA=ON \
        -DBUILD_opencv_cudev=ON \
        -DBUILD_opencv_cudaarithm=ON \
        -DBUILD_opencv_cudawarping=ON ../
\endcode

- Note that if you want a more advanced way to configure the build process, you can use `ccmake`:
\code
$ ccmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ../
\endcode

- At this point, you can check if `cudev`, `cudaarithm` and `cudawarping` extra modules are enabled as expected:
\verbatim
$ grep cudev version_string.tmp
"    To be built:                 ... cudev ...
$ grep cudaarithm version_string.tmp
"    To be built:                 ... cudaarithm ...
$ grep cudawarping version_string.tmp
"    To be built:                 ... cudawarping ...
\endverbatim
If this is not the case, it means that something is wrong, either in CUDA installation, either in OpenCV configuration with `cmake`.

- Launch build process:
\code
$ make -j$(nproc)
$ sudo make install
\endcode

\subsubsection install_jetson_quasar_3rdparty_realsense librealsense 2.x 3rd party

If you have an Intel RealSense Depth camera (SR300 or D400 series), you may install librealsense 2.x in order to use vpRealSense2 class.
Otherwise you can skip this section.

Installation instructions are given in the <a href="https://github.com/IntelRealSense/librealsense/blob/master/doc/installation.md">tutorial</a>.

\note Since our kernel is 4.12+ streaming Depth/IR/Color is supported and is provided out of the box. This means that the patches are not needed.

Following the <a href="https://github.com/IntelRealSense/librealsense/blob/master/doc/installation.md">tutorial</a>, we recall the main steps here:

1. Unplug any connected Intel RealSense camera.

2. Install the packages required for `librealsense` build:
\verbatim
$ sudo apt-get install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev cmake-curses-gui
$ sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
\endverbatim

3. Get `librealsense` from github:
\verbatim
$ cd $VISP_WS/3rdparty
$ git clone https://github.com/IntelRealSense/librealsense.git
$ cd librealsense
\endverbatim

4. Run Intel Realsense permissions script located in `librealsense` root directory:
\verbatim
$ sudo ./scripts/setup_udev_rules.sh
\endverbatim

5. Build and install librealsense
\verbatim
$ mkdir build
$ cd build
$ cmake .. -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release
$ make -j4
$ sudo make install
\endverbatim

6. Connect your Realsense camera (we are using a D435) and check if you are able to acquire images running:
\verbatim
$ ./examples/capture/rs-capture
\endverbatim

If you are able to visualize the images, it means that you succeed in `librealsense` installation.

\subsubsection install_jetson_quasar_3rdparty_occipital_structure libStructure 3rd party

If you have an Occipital Structure Core sensor (monochrome or color), you may install Occipital Structure SDK in order to use vpOccipitalStructure class.
Otherwise you can skip this section.

Occipital Structure SDK contains `libStructure` pre-built library.

<b>Download the SDK</b>
- Go to https://developer.structure.io/sdk/
- Join the Developper program to be able to download the SDK.
- Retrieve your invitation from https://developer.structure.io/sdk/retrieve
- You'll then receive an email containing the link to the download page,
- Download `Structure SDK (Cross-Platform)`.
- Extract the folder `StructureSDK-CrossPlatform-0.9` from the downloaded file to the already created directory in `$VISP_WS`.

The SDK contains pre-built libraries for Linux, Windows and macOS.
In order that ViSP detects Structure SDK header files and libraries, you have to set `OCCIPITAL_STRUCTURE_DIR` environment
variable. Proceed as follows:
\verbatim
$ echo "export OCCIPITAL_STRUCTURE_DIR=$VISP_WS/StructureSDK-CrossPlatform-0.9" >> ~/.bashrc
$ source ~/.bashrc
\endverbatim

\subsection install_jetson_quasar_visp_get_source Get ViSP source code

Get ViSP from <a href="https://github.com/lagadic/visp">GitHub repository</a> using the following command
\verbatim
$ cd $VISP_WS
$ git clone https://github.com/lagadic/visp.git
\endverbatim

We suppose now that ViSP source is in the directory `$VISP_WS/visp`.

\subsection install_jetson_quasar_visp_config Configure ViSP from source

These are the steps to configure ViSP from source with CMake:

- In the workspace, create first a directory named `visp-build` that will contain all the build material; generated Makefiles, object files, output libraries and binaries.
\verbatim
$ mkdir $VISP_WS/visp-build
\endverbatim

- Enter the `visp-build` folder and configure the build:
\verbatim
$ cd $VISP_WS/visp-build
$ cmake ../visp
\endverbatim
A more versatile way to configure the build is to use `ccmake`, the CMake GUI:
\verbatim
$ ccmake ../visp
\endverbatim
The following image shows that this command allows to configure (just by pressing [c] key) the build in a more advanced way where some options could be easily turned ON/OFF. It allows also to see which are the 3rd parties that will be used. To generate the makefiles, just press [g] key in the ccmake gui.
\image html img-cmake-jetson.png Snapshot of the `ccmake ../visp` command used to configure ViSP.

\subsection install_jetson_quasar_visp_build Build and install ViSP libraries

To build ViSP libraries proceed with:
\verbatim
$ cd $VISP_WS/visp-build
$ make -j4
$ sudo make install
\endverbatim

\subsection install_jetson_quasar_visp_doc Build ViSP documentation

To build ViSP documentation, you have first to install Doxygen package:
\verbatim
$ sudo apt-get install doxygen graphviz texlive-latex-base
\endverbatim
Then you can proceed with:
\verbatim
$ cd $VISP_WS/visp-build
$ cmake ../visp
$ make -j4 visp_doc
\endverbatim
The generated documentation is then available in `$VISP_WS/visp-build/doc/html/index.html`

\note
- To speed up generating online doc, particularly around formula rendering, you can use [MatJax](https://www.mathjax.org). To this end, install MathJax and build doc using:
\verbatim
$ npm install mathjax
$ cmake ../visp -DUSE_MATHJAX=ON
$ make -j4 visp_doc
\endverbatim
\note
- It is also possible to generate a more complete documentation that includes also all the internal classes. This could be achieved setting CMake var `ENABLE_FULL_DOC` to `ON` like:
\verbatim
$ cmake ../visp -DENABLE_FULL_DOC=ON
$ make -j4 visp_doc
\endverbatim

\subsection install_jetson_quasar_visp_dir Set VISP_DIR environment var

In order to ease ViSP detection by CMake when ViSP is used as a 3rd party in an external project, like the one described in the \ref tutorial-getting-started, you may set `VISP_DIR` environment variable with the path to the `VISPConfig.cmake` file:
\verbatim
$ echo "export VISP_DIR=$VISP_WS/visp-build" >> ~/.bashrc
$ source ~/.bashrc
\endverbatim

\section install_jetson_quasar_dataset Install ViSP dataset

Some ViSP examples and tests require a data set that contains images, video, models that is not part of ViSP source code. This data set is available in Github (https://github.com/lagadic/visp-images) or as a release in a separate archive named `visp-images-x.y.z.zip`. This archive could be downloaded from https://visp.inria.fr/download page. Note that ViSP tutorials are not using ViSP data set.

We give hereafter the two ways to get this data set:

<b>Get data set from github</b>

- Use git to get the data set latest version:
\verbatim
$ cd $VISP_WS
 git clone https://github.com/lagadic/visp-images.git
\endverbatim
- Once cloned, you need to set `VISP_INPUT_IMAGE_PATH` environment variable to help ViSP examples and tests to detect automatically the location of the requested data. In our case, this variable should be set to `$VISP_WS%/visp-images`. In a shell run:
\verbatim
$ echo "export VISP_INPUT_IMAGE_PATH=$VISP_WS/visp-images" >> ~/.bashrc
$ source ~/.bashrc
\endverbatim

<b>Test data set usage</b>

- From now, you can try to run ViSP examples and tests. For example you can run `displayX` example that should open a windows with Klimt painting image and some overlay drawings:
\verbatim
$ cd $VISP_WS/visp-build
$ ./example/device/display/displayX

A click to close the windows...

A click to display a cross...
Cross position: 201, 441

A click to exit the program...
Bye
\endverbatim

\section install_jetson_quasar_tips Tips and tricks

\subsection install_jetson_quasar_tips_new_3rdparty How to take into account a newly installed 3rd party

Since all 3rd parties are optional you may have started to install only some of them. Imagine that you just installed a new third-party, or that you upgraded the version of this 3rd party. The next step is to go back to the build folder, configure ViSP with CMake to detect the newly installed third-party library and build again ViSP. This could be achieved with:
\verbatim
$ cd $VISP_WS/visp-build
$ cmake ../visp
\endverbatim

Here you can check the content of the `ViSP-third-party.txt` file and see if the newly installed 3rd party is well detected (see \ref install_jetson_tips_3rd_party).

Finally, you need to rebuild ViSP with:
\verbatim
$ make -j4
\endverbatim

\subsection install_jetson_quasar_tips_install How to install ViSP

Installing ViSP is optional and not recommended, since ViSP could be used as a 3rd party without installation. If you still want to proceed with the installation run:
\verbatim
$ cd $VISP_WS/visp-build
$ sudo make install
\endverbatim
\note The default install location is set to `/usr/local`. This location could be changed modifying `CMAKE_INSTALL_PREFIX` var:
\verbatim
$ cd $VISP_WS/visp-build
$ cmake ../visp -DCMAKE_INSTALL_PREFIX=/usr
$ make -j4
$ sudo make install
\endverbatim

\note If you proceed to ViSP installation in a system folder like `/usr` or `/usr/local` there is no need to \ref install_jetson_visp_dir that helps CMake to find ViSP libraries in an external project that uses ViSP as a 3rd party. If you rather install ViSP in a non "standard" folder, let say `/my/install/folder`, you have to set `VISP_DIR` to `/my/install/folder/lib/cmake/visp` that contains the `VISPConfig.cmake` file:
\verbatim
$ cd $VISP_WS/visp-build
$ cmake ../visp -DCMAKE_INSTALL_PREFIX=/my/install/folder
$ make -j4
$ sudo make install
$ echo "export VISP_DIR=/my/install/folder/lib/cmake/visp" >> ~/.bashrc
$ source ~/.bashrc
\endverbatim

\subsection install_jetson_quasar_tips_uninstall How to uninstall ViSP

After ViSP installation, you can remove installed material using:
\verbatim
$ cd $VISP_WS/visp-build
$ sudo make uninstall
\endverbatim

\subsection install_jetson_quasar_tips_modules How to build only ViSP libraries

If you want to build only ViSP modules libraries, nor the examples, tutorials and tests:
\verbatim
$ cd $VISP_WS/visp-build
$ make -j4 visp_modules
\endverbatim

\subsection install_jetson_quasar_tips_module_once How to build a ViSP specific module

If you want to build a given module and all the dependencies:
\verbatim
$ cd $VISP_WS/visp-build
$ make -j4 visp_<module_name>
\endverbatim

For example to build the model-based tracker module named mbt, run:
\verbatim
$ cd $VISP_WS/visp-build
$ make -j4 visp_mbt
\endverbatim

\subsection install_jetson_quasar_tips_target Which are the targets that could be run with make ?

To know which are the target available with `make`:
\verbatim
$ make help | grep visp
... visp_tests
... visp_modules
... visp_examples
... visp_demos
... visp_tutorials
... visp_clipper
... visp_apriltag
... visp_core
... visp_gui
... visp_imgproc
... visp_io
... gen_visp_java_source
... visp_klt
... visp_me
... visp_sensor
... visp_ar
... visp_blob
... visp_robot
... visp_visual_features
... visp_vs
... visp_vision
... visp_detection
... visp_mbt
... visp_tt
... visp_tt_mi
\endverbatim

\subsection install_jetson_quasar_tips_3rd_party Which are the 3rd party libraries that are used in ViSP ?

To see which are the optional 3rd parties that are found during the configuration stage and that will be used by ViSP during the build you can have a look to the text file named `ViSP-third-party.txt` and located in `$VISP_WS/visp-build`. We provide hereafter an example of a possible content of this file that contains also build info.
\verbatim
$ cat $VISP_WS/visp-build/ViSP-third-party.txt
==========================================================
General configuration information for ViSP 3.4.1

  Version control:               v3.4.0-306-g318d05132-dirty

  Platform:
    Timestamp:                   2022-01-24T16:17:00Z
    Host:                        Linux 4.9.253-tegra aarch64
    CMake:                       3.10.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  C/C++:
    Built as dynamic libs?:      yes
    C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
    C++ flags (Release):         -Wall -Wextra -fopenmp -std=c++11 -fvisibility=hidden -fPIC -O3 -DNDEBUG
    C++ flags (Debug):           -Wall -Wextra -fopenmp -std=c++11 -fvisibility=hidden -fPIC -g
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -Wall -Wextra -fopenmp -std=c++11 -fvisibility=hidden -fPIC -O3 -DNDEBUG
    C flags (Debug):             -Wall -Wextra -fopenmp -std=c++11 -fvisibility=hidden -fPIC -g
    Linker flags (Release):
    Linker flags (Debug):

  ViSP modules:
    To be built:                 core gui imgproc io java_bindings_generator klt me sensor ar blob robot visual_features vs vision detection mbt tt tt_mi
    Disabled:                    -
    Disabled by dependency:      -
    Unavailable:                 java

  Python (for build):            /usr/bin/python

  Java:
    ant:                         NO
    JNI:                         NO

  Build options:
    Build deprecated:            yes
    Build with moment combine:   no

  Mathematics:
    Blas/Lapack:                 yes
    \- Use MKL:                  no
    \- Use OpenBLAS:             no
    \- Use Atlas:                no
    \- Use Netlib:               yes (ver 3.7.1)
    \- Use GSL:                  no
    \- Use Lapack (built-in):    no
    Use Eigen3:                  yes (ver 3.4.0)
    Use OpenCV:                  yes (ver 4.5.5)

  Simulator:
    Ogre simulator:
    \- Use Ogre3D:               yes (ver 1.9.0)
    \- Use OIS:                  no
    Coin simulator:
    \- Use Coin3D:               no
    \- Use SoWin:                no
    \- Use SoXt:                 no
    \- Use SoQt:                 no
    \- Use Qt5:                  no
    \- Use Qt4:                  no
    \- Use Qt3:                  no

  Media I/O:
    Use JPEG:                    yes (ver 80)
    Use PNG:                     yes (ver 1.6.34)
    \- Use ZLIB:                 yes (ver 1.2.11)
    Use OpenCV:                  yes (ver 4.5.5)
    Use stb_image (built-in):    no

  Real robots:
    Use Afma4:                   no
    Use Afma6:                   no
    Use Franka:                  no
    Use Viper650:                no
    Use Viper850:                no
    Use Kinova Jaco:             no
    Use aria (Pioneer):          no
    Use PTU46:                   no
    Use Biclops PTU:             no
    Use Flir PTU SDK:            no
    Use Parrot ARSDK:            no
    \-Use ffmpeg:                no
    Use Virtuose:                no
    Use qbdevice (built-in):     yes (ver 2.6.0)
    Use takktile2 (built-in):    yes (ver 1.0.0)

  GUI:
    Use X11:                     yes
    Use GTK:                     no
    Use OpenCV:                  yes (ver 4.5.5)
    Use GDI:                     no
    Use Direct3D:                no

  Cameras:
    Use DC1394-2.x:              yes (ver 2.2.5)
    Use CMU 1394:                no
    Use V4L2:                    yes (ver 1.14.2)
    Use directshow:              no
    Use OpenCV:                  yes (ver 4.5.5)
    Use FLIR Flycapture:         no
    Use Basler Pylon:            no
    Use IDS uEye:                no

  RGB-D sensors:
    Use Realsense:               no
    Use Realsense2:              yes (ver 2.50.0)
    Use Occipital Structure:     yes
    Use Kinect:                  no
    \- Use libfreenect:          no
    \- Use libusb-1:             yes (ver 1.0.21)
    \- Use pthread:              yes
    Use PCL:                     no
    \- Use VTK:                  no

  F/T sensors:
    Use atidaq (built-in):       no
    Use comedi:                  no
    Use IIT SDK:                 no

  Detection:
    Use zbar:                    yes (ver 0.10)
    Use dmtx:                    no
    Use AprilTag (built-in):     yes (ver 3.1.1)
    \- Use AprilTag big family:  no

  Misc:
    Use Clipper (built-in):      yes (ver 6.4.2)
    Use pugixml (built-in):      yes (ver 1.9.0)
    Use libxml2:                 yes (ver 2.9.4)

  Optimization:
    Use OpenMP:                  yes
    Use pthread:                 yes
    Use pthread (built-in):      no
    Use cxx standard:            11

  DNN:
    Use CUDA Toolkit:            yes (ver 10.2)
    Use TensorRT:                yes (ver 8.0.1.6)

  Documentation:
    Use doxygen:                 no

  Tests and samples:
    Use catch2 (built-in):       yes (ver 2.13.7)
    Tests:                       yes
    Demos:                       yes
    Examples:                    yes
    Tutorials:                   yes

  Install path:                  /usr/local

==========================================================
\endverbatim

\section install_jetson_quasar_next Next tutorial

You are now ready to see the next \ref tutorial-getting-started that will show you how to use ViSP as a 3rd party to build your own project.

*/
