建议先把环境变量里其他编译器的东西删了,例如mingw,msys,qt
编译
https://vtk.org/download/
下载那个source
建立4个文件夹
build用来放cmake生成的东西
src是下载下来的压缩包,解压,改了个名字
debug是最后生成的debug文件
release是生成的的release文件
如果是vtk9.3.0
进入Common/Core/vtkConstantImplicitBackend.h
将
struct VTKCOMMONCORE_EXPORT vtkConstantImplicitBackend final
改成
struct vtkConstantImplicitBackend final
打开cmake
选择source code(就是刚刚的src)
选择build(就是刚刚的build)
点击configure
会弹窗,默认就行
经过一通漫长的等待,就configure好了,但是有很多红的
搜索CMAKE_INSTALL_PREFIX
把右边改成之前的install-debug
搜索BUILD_SHARED_LIBS
勾上
勾上search旁边的Grouped和Advanced
搜索VTK_LEGACY_REMOVE
勾上
勾上search旁边的Grouped和Advanced
搜索qt
全部改成want
再次点击configure
可能会报错,但是没有关系,点击ok
修改Qt5_DIR
路径选择 qt安装的路径/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5
再次Configure
可以看到还有红色
再次configure
这次终于好了(注意下面的是warning,警告==没有)
顺便检查一下,是否出现了msvc以外的编译器,例如mingw,msys,qt
比如下面这个
如果出现了,就把选项全部清空,像这样
点击generate
在刚刚的build里面
打开VTK.sln
点击生成->批生成
勾上ALL_BUILD的Release,点击生成
然后经过漫长的等待,就生成完了
点击生成->批生成
去掉ALL_BUILD前面的勾
勾上INSTALL的release的勾
然后点击生成
这回应该比较快
把install-debug中的文件裁剪到install-release中
变成这样
接着我们生成debug的
点击生成->批生成
勾上ALL_BUILD的DEBUG
勾上INSTALL的Debug
点击生成
经过漫长的等待,debug的也好了
把debug的bin和release的bin加入环境变量(应该有顺序要求
然后重启
用cmake
https://kitware.github.io/vtk-examples/site/Cxx/GeometricObjects/CylinderExample/
下载一下,解压
source code和build调一下
configure
这个install_prefix好像没啥子卵用
注意这个VTK_DIR,因为环境变量中debug在前面,所以先debug了
再点configure
然后点Generate
然后build中应该生成了
双击sln
把中间那个设置为启动项
确认上面是debug x64
运行
就可以了
vs直接写
点开项目属性
VC++目录->包含目录
上面注意一下是Debug和x64
然后加入debug的include的路径
接着是lib
接着打开cmd
cd到刚刚的lib路径
输入
dir /a-d /b *.lib>src.txt
打开lib目录下的src.txt
复制
打开vs
链接器->输入->附加依赖项
把刚刚复制的全部粘贴进去
把上面的debug x64 换成release x64
然后类似地配置release的
然后测试一下
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCylinderSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <array>
int main(int, char* [])
{
vtkNew<vtkNamedColors> colors;
// Set the background color.
std::array<unsigned char, 4> bkg{ {26, 51, 102, 255} };
colors->SetColor("BkgColor", bkg.data());
// This creates a polygonal cylinder model with eight circumferential facets
// (i.e, in practice an octagonal prism).
vtkNew<vtkCylinderSource> cylinder;
cylinder->SetResolution(8);
// The mapper is responsible for pushing the geometry into the graphics
// library. It may also do color mapping, if scalars or other attributes are
// defined.
vtkNew<vtkPolyDataMapper> cylinderMapper;
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
// The actor is a grouping mechanism: besides the geometry (mapper), it
// also has a property, transformation matrix, and/or texture map.
// Here we set its color and rotate it around the X and Y axes.
vtkNew<vtkActor> cylinderActor;
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(
colors->GetColor4d("Tomato").GetData());
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45.0);
// The renderer generates the image
// which is then displayed on the render window.
// It can be thought of as a scene to which the actor is added
vtkNew<vtkRenderer> renderer;
renderer->AddActor(cylinderActor);
renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
// Zoom in a little by accessing the camera and invoking its "Zoom" method.
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);
// The render window is the actual GUI window
// that appears on the computer screen
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300, 300);
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("Cylinder");
// The render window interactor captures mouse events
// and will perform appropriate camera or actor manipulation
// depending on the nature of the events.
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
// This starts the event loop and as a side effect causes an initial render.
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
注意下面代码与官方的例子差了这几句
#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
运行
debug
release
QT
注意vtk9以后是没有QVTKWidget
Qt Creator
先在qt creator里配置msvc2017 64位
https://blog.youkuaiyun.com/qq_39942341/article/details/123357894?spm=1001.2014.3001.5501
这里就配置debug的(release类似)
把下面的base_dir改成你的debug的lib的路径
然后会输出一个src.txt
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import os
import glob
base_dir = r'D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib'
if __name__ == "__main__":
with open('src.txt', 'w') as f:
for path in glob.glob(os.path.join(os.path.abspath(base_dir), '*.lib')):
f.write('LIBS += "{}"\n'.format(path))
打开qt,建立一个msvc2017 64位的项目
打开.pro文件
添加
第一行改成debug的include/vtk
后面的就是刚刚src.txt里的
#For Debug
INCLUDEPATH += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\include\vtk-9.1"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkcgns-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkChartsCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonColor-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonComputationalGeometry-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonDataModel-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonExecutionModel-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonMath-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonMisc-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonSystem-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkCommonTransforms-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkDICOMParser-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkDomainsChemistry-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkDomainsChemistryOpenGL2-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkdoubleconversion-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkexodusII-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkexpat-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersAMR-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersExtraction-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersFlowPaths-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersGeneral-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersGeneric-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersGeometry-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersHybrid-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersHyperTree-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersImaging-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersModeling-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersParallel-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersParallelImaging-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersPoints-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersProgrammable-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersSelection-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersSMP-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersSources-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersStatistics-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersTexture-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersTopology-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkFiltersVerdict-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkfmt-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkfreetype-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkGeovisCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkgl2ps-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkglew-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkGUISupportQt-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkGUISupportQtQuick-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkGUISupportQtSQL-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkhdf5-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkhdf5_hl-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingColor-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingFourier-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingGeneral-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingHybrid-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingMath-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingMorphological-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingSources-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingStatistics-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkImagingStencil-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkInfovisCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkInfovisLayout-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkInteractionImage-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkInteractionStyle-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkInteractionWidgets-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOAMR-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOAsynchronous-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOCGNSReader-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOChemistry-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOCityGML-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOCONVERGECFD-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOEnSight-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOExodus-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOExport-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOExportGL2PS-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOExportPDF-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOGeometry-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOHDF-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOImage-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOImport-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOInfovis-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOIOSS-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOLegacy-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOLSDyna-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOMINC-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOMotionFX-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOMovie-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIONetCDF-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOOggTheora-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOParallel-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOParallelXML-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOPLY-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOSegY-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOSQL-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkioss-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOTecplotTable-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOVeraOut-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOVideo-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOXML-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkIOXMLParser-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkjpeg-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkjsoncpp-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkkissfft-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtklibharu-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtklibproj-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtklibxml2-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkloguru-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtklz4-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtklzma-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkmetaio-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtknetcdf-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkogg-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkParallelCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkParallelDIY-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkpng-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkpugixml-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingAnnotation-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingContext2D-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingContextOpenGL2-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingFreeType-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingGL2PSOpenGL2-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingImage-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingLabel-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingLOD-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingOpenGL2-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingQt-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingSceneGraph-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingUI-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingVolume-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingVolumeOpenGL2-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkRenderingVtkJS-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtksqlite-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtksys-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkTestingRendering-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtktheora-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtktiff-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkverdict-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkViewsContext2D-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkViewsCore-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkViewsInfovis-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkViewsQt-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkWrappingTools-9.1d.lib"
LIBS += "D:\VTK-9.1.0\VTK-9.1.0-install-debug\lib\vtkzlib-9.1d.lib"
在ui文件里加一个OpenGL Widget
右键提升为
在提升的类名称里填QVTKOpenGLNativeWidget
点添加
然后点一下全局包含
提升
可以看到就添加好了
在mainwindow.cpp里
#include "mainwindow.h"
#include "ui_mainwindow.h"
#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);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
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->openGLWidget);
ui->openGLWidget->setRenderWindow(renderWindow);
}
MainWindow::~MainWindow()
{
delete ui;
}
启动
vs
方法1
延续刚刚的
先在vs里装qt插件
https://blog.youkuaiyun.com/qq_39942341/article/details/123304225?spm=1001.2014.3001.5501
打开自己的visual studio installer
点开单个组件
搜索msvc
确保这几个都装了
这里选择继续但无需代码
扩展->Qt VS tools->Open Qt Project File(.pro)…
这里我们选择在pro里配置了vtk的那个文件
启动
方法2
应该是可以直接创建的,回头看看
参考:
https://gitlab.kitware.com/vtk/vtk/-/issues/19166
https://blog.youkuaiyun.com/A112459/article/details/134659851