Compile VTK9.1 with VS2019+PCL1.12.1+Qt5.14.2 (series of joy after suffering)

It took two days to compile VTK9.1, and then display the point cloud through the Qt project created by VS.

The fundamental purpose

VS creates a Qt project and adds a widget to the UI design interface to display point clouds.

text

VTK will also be installed during the installation of PCL, but this VTK is not the most complete, so you need to download the source code of VTK and compile it to supplement the VTK in PCL. Having said that, it is necessary to put a VTK source code download link. Click to select the desired version to download.
Insert image description here
Because the VTK in PCL1.12.1 is version 9.1, it is best to download VTK9.1.0 for compilation.

After downloading, you need to use CMAKE-gui. The version used this time is 3.24.0. Click here to go to the official website to download CMAKE
Insert image description here
and compile VTK. There are many tutorials. It is a bit confusing and I have tried them all. Mainly following this tutorial, I successfully compiled VTK9.1.

It is worth noting that these paths need to be changed. The default path is Qt/5.14.2/mingw73_64/bin/xxx.exe. At first glance, it seems to be exactly the same as the one in the picture below. It has not been changed before. Configure can also Successfully, I kept getting errors when I used VS2019 to generate it. Later I found out that the original mingw73_64 was changed to msvc2017_64 or msvc2019_64. Mine is msvc2017_64. There is no problem with the tutorial. I really need to be careful.
Insert image description here
This tutorial mentioned that for C++ desktop development and .net SDK, MFC seems to be a dependent library of VTK.
Insert image description here
If it is not currently installed in VS2019, you can click Tools->Get Tools and Functions, and the Visual Studio Installer will pop up. Select a single component to complete the installation of MFC and .net SDK. As for which version of MFC to install, please refer to Tutorial 1 and Tutorial 2.

After compilation, you usually get a debug version of VTK and a release version of VTK. Each version has 4 folders as shown in the picture below.
Insert image description here
Many tutorials mention that the three files QVTKWidgetPlugin.dll, QVTKWidgetPlugin.exp and QVTKWidgetPlugin.lib obtained after compilation should be thrown into a folder of Qt. But the problem is that I didn't get it after compiling it, and the entire folder search didn't find it either. After reading many posts later, I found out that VTK9.1.0 will not generate these three files, but the older version seems to be able to. See here for details.
Insert image description here
Then after getting the debug and release versions of VTK, you need to use them to improve the VTK in the previously installed PCL1.12.1 library. This post explains which files should be extracted.
Insert image description here
This post is more direct. It directly provides the compiled VTK library, which can be directly used to replace the VTK in PCL1.12.1. It is extremely fast.
Insert image description here
I’m really grateful, this blogger is a good person.

After the VTK in the PCL library is updated, can it be used? No, I was stuck at this step for a day. I haven't found anyone who made it clear. In fact, there is no need to change the path or anything. But an error will be reported. The error reported is an external command that cannot be parsed, as shown in the figure below.
Insert image description here
Later, I finally discovered that before the PCL library was updated, there were 130 external dependencies on VTK, and after the update, there were 144. Just open the VS linker->Input->Additional Dependencies and add the extra dozen or so items. In fact, these extra .libs are what we need to compile VTK. Here are the 144 .lib file names for debugging. Just overwrite the previous 130. For the release version, you need to remove the d in each .lib file name, that is, change XXX-9.1d.lib to XXX-9.1.lib.

vtkcgns-9.1d.lib
vtkChartsCore-9.1d.lib
vtkCommonColor-9.1d.lib
vtkCommonComputationalGeometry-9.1d.lib
vtkCommonCore-9.1d.lib
vtkCommonDataModel-9.1d.lib
vtkCommonExecutionModel-9.1d.lib
vtkCommonMath-9.1d.lib
vtkCommonMisc-9.1d.lib
vtkCommonSystem-9.1d.lib
vtkCommonTransforms-9.1d.lib
vtkDICOMParser-9.1d.lib
vtkDomainsChemistry-9.1d.lib
vtkDomainsChemistryOpenGL2-9.1d.lib
vtkdoubleconversion-9.1d.lib
vtkexodusII-9.1d.lib
vtkexpat-9.1d.lib
vtkFiltersAMR-9.1d.lib
vtkFiltersCore-9.1d.lib
vtkFiltersExtraction-9.1d.lib
vtkFiltersFlowPaths-9.1d.lib
vtkFiltersGeneral-9.1d.lib
vtkFiltersGeneric-9.1d.lib
vtkFiltersGeometry-9.1d.lib
vtkFiltersHybrid-9.1d.lib
vtkFiltersHyperTree-9.1d.lib
vtkFiltersImaging-9.1d.lib
vtkFiltersModeling-9.1d.lib
vtkFiltersParallel-9.1d.lib
vtkFiltersParallelImaging-9.1d.lib
vtkFiltersPoints-9.1d.lib
vtkFiltersProgrammable-9.1d.lib
vtkFiltersSelection-9.1d.lib
vtkFiltersSMP-9.1d.lib
vtkFiltersSources-9.1d.lib
vtkFiltersStatistics-9.1d.lib
vtkFiltersTexture-9.1d.lib
vtkFiltersTopology-9.1d.lib
vtkFiltersVerdict-9.1d.lib
vtkfmt-9.1d.lib
vtkfreetype-9.1d.lib
vtkGeovisCore-9.1d.lib
vtkgl2ps-9.1d.lib
vtkglew-9.1d.lib
vtkGUISupportQt-9.1d.lib
vtkGUISupportQtQuick-9.1d.lib
vtkGUISupportQtSQL-9.1d.lib
vtkhdf5-9.1d.lib
vtkhdf5_hl-9.1d.lib
vtkImagingColor-9.1d.lib
vtkImagingCore-9.1d.lib
vtkImagingFourier-9.1d.lib
vtkImagingGeneral-9.1d.lib
vtkImagingHybrid-9.1d.lib
vtkImagingMath-9.1d.lib
vtkImagingMorphological-9.1d.lib
vtkImagingSources-9.1d.lib
vtkImagingStatistics-9.1d.lib
vtkImagingStencil-9.1d.lib
vtkInfovisCore-9.1d.lib
vtkInfovisLayout-9.1d.lib
vtkInteractionImage-9.1d.lib
vtkInteractionStyle-9.1d.lib
vtkInteractionWidgets-9.1d.lib
vtkIOAMR-9.1d.lib
vtkIOAsynchronous-9.1d.lib
vtkIOCGNSReader-9.1d.lib
vtkIOChemistry-9.1d.lib
vtkIOCityGML-9.1d.lib
vtkIOCONVERGECFD-9.1d.lib
vtkIOCore-9.1d.lib
vtkIOEnSight-9.1d.lib
vtkIOExodus-9.1d.lib
vtkIOExport-9.1d.lib
vtkIOExportGL2PS-9.1d.lib
vtkIOExportPDF-9.1d.lib
vtkIOGeometry-9.1d.lib
vtkIOHDF-9.1d.lib
vtkIOImage-9.1d.lib
vtkIOImport-9.1d.lib
vtkIOInfovis-9.1d.lib
vtkIOIOSS-9.1d.lib
vtkIOLegacy-9.1d.lib
vtkIOLSDyna-9.1d.lib
vtkIOMINC-9.1d.lib
vtkIOMotionFX-9.1d.lib
vtkIOMovie-9.1d.lib
vtkIONetCDF-9.1d.lib
vtkIOOggTheora-9.1d.lib
vtkIOParallel-9.1d.lib
vtkIOParallelXML-9.1d.lib
vtkIOPLY-9.1d.lib
vtkIOSegY-9.1d.lib
vtkIOSQL-9.1d.lib
vtkioss-9.1d.lib
vtkIOTecplotTable-9.1d.lib
vtkIOVeraOut-9.1d.lib
vtkIOVideo-9.1d.lib
vtkIOXML-9.1d.lib
vtkIOXMLParser-9.1d.lib
vtkjpeg-9.1d.lib
vtkjsoncpp-9.1d.lib
vtkkissfft-9.1d.lib
vtklibharu-9.1d.lib
vtklibproj-9.1d.lib
vtklibxml2-9.1d.lib
vtkloguru-9.1d.lib
vtklz4-9.1d.lib
vtklzma-9.1d.lib
vtkmetaio-9.1d.lib
vtknetcdf-9.1d.lib
vtkogg-9.1d.lib
vtkParallelCore-9.1d.lib
vtkParallelDIY-9.1d.lib
vtkpng-9.1d.lib
vtkpugixml-9.1d.lib
vtkRenderingAnnotation-9.1d.lib
vtkRenderingContext2D-9.1d.lib
vtkRenderingContextOpenGL2-9.1d.lib
vtkRenderingCore-9.1d.lib
vtkRenderingFreeType-9.1d.lib
vtkRenderingGL2PSOpenGL2-9.1d.lib
vtkRenderingImage-9.1d.lib
vtkRenderingLabel-9.1d.lib
vtkRenderingLOD-9.1d.lib
vtkRenderingOpenGL2-9.1d.lib
vtkRenderingQt-9.1d.lib
vtkRenderingSceneGraph-9.1d.lib
vtkRenderingUI-9.1d.lib
vtkRenderingVolume-9.1d.lib
vtkRenderingVolumeOpenGL2-9.1d.lib
vtkRenderingVtkJS-9.1d.lib
vtksqlite-9.1d.lib
vtksys-9.1d.lib
vtkTestingRendering-9.1d.lib
vtktheora-9.1d.lib
vtktiff-9.1d.lib
vtkverdict-9.1d.lib
vtkViewsContext2D-9.1d.lib
vtkViewsCore-9.1d.lib
vtkViewsInfovis-9.1d.lib
vtkViewsQt-9.1d.lib
vtkWrappingTools-9.1d.lib
vtkzlib-9.1d.lib

At this point, you can create a Qt project through VS, then use Qt Creator to add a widget or openGLwidget and upgrade it to QVTKOpenGLNativeWidget. As shown below.
Insert image description here
Then you can control the widget to display the point cloud. This widget is also the so-called qvtkwidget in many posts, but it is just the name of an object. The last example in this post

#include <QSurfaceFormat>
#include <QVTKOpenGLNativeWidget.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkNamedColors.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>

#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);

MyVtk::MyVtk(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MyVtk){
    
    
    ui->setupUi(this);
    
    QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
    vtkNew<vtkNamedColors> colors;
    vtkNew<vtkSphereSource> sphereSource;
    vtkNew<vtkPolyDataMapper> sphereMapper;
    sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
    vtkNew<vtkActor> sphereActor;
    sphereActor->SetMapper(sphereMapper);
    sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData());
    vtkNew<vtkRenderer> renderer;
    renderer->AddActor(sphereActor);
    renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData());
    vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("RenderWindowNoUIFile");
    setCentralWidget(ui->vtkRenderWidget);
    ui->vtkRenderWidget->setRenderWindow(renderWindow);
}

The effect of running out is the same, and that's the end.
Insert image description here
The configuration process was too laborious, but I finally got it done, and I can start learning how to use VTK~

Reference:
Reference Tutorial
Reference Tutorial 2
Reference Tutorial 3

Guess you like

Origin blog.csdn.net/dyk4ever/article/details/126629052