Repository: kimtaikee/QVTKDemo
Branch: master
Commit: ef62e4fd924f
Files: 508
Total size: 2.2 MB
Directory structure:
gitextract_uerwcxh8/
├── README.md
├── app.pri
├── demos.pri
├── demos.pro
├── lib.pri
├── libs/
│ ├── 3dparty/
│ │ ├── 3dparty.pri
│ │ ├── 3dparty.pro
│ │ ├── 3dparty_dependencies.pri
│ │ ├── 3dparty_global.h
│ │ ├── QRoundProgressBar.cpp
│ │ ├── QRoundProgressBar.h
│ │ ├── flowlayout.cpp
│ │ └── flowlayout.h
│ ├── libs.pro
│ ├── utils/
│ │ ├── colorseries.cpp
│ │ ├── colorseries.h
│ │ ├── doublespinboxdelegate.cpp
│ │ ├── doublespinboxdelegate.h
│ │ ├── iplugin.h
│ │ ├── ivtkplugin.cpp
│ │ ├── ivtkplugin.h
│ │ ├── modeltopointsconverter.cpp
│ │ ├── modeltopointsconverter.h
│ │ ├── modeltovectorsconverter.cpp
│ │ ├── modeltovectorsconverter.h
│ │ ├── point3f.cpp
│ │ ├── point3f.h
│ │ ├── pointsreader.cpp
│ │ ├── pointsreader.h
│ │ ├── pointstomodelconverter.cpp
│ │ ├── pointstomodelconverter.h
│ │ ├── signalblocker.cpp
│ │ ├── signalblocker.h
│ │ ├── signalledrunable.cpp
│ │ ├── signalledrunable.h
│ │ ├── tablemodel.cpp
│ │ ├── tablemodel.h
│ │ ├── utils.cpp
│ │ ├── utils.h
│ │ ├── utils.pri
│ │ ├── utils.pro
│ │ ├── utils_dependencies.pri
│ │ ├── utils_global.h
│ │ ├── vector4f.cpp
│ │ └── vector4f.h
│ ├── vtkutils/
│ │ ├── abstractimageprocessor.cpp
│ │ ├── abstractimageprocessor.h
│ │ ├── abstractwidgetobserver.cpp
│ │ ├── abstractwidgetobserver.h
│ │ ├── actorexporter.cpp
│ │ ├── actorexporter.h
│ │ ├── anglewidgetobserver.cpp
│ │ ├── anglewidgetobserver.h
│ │ ├── boxcutter.cpp
│ │ ├── boxcutter.h
│ │ ├── boxwidgetobserver.cpp
│ │ ├── boxwidgetobserver.h
│ │ ├── contour.cpp
│ │ ├── contour.h
│ │ ├── contourwidgetobserver.cpp
│ │ ├── contourwidgetobserver.h
│ │ ├── custominteractorstyle.cpp
│ │ ├── custominteractorstyle.h
│ │ ├── datafilter.cpp
│ │ ├── datafilter.h
│ │ ├── disablerotationinteractorstyle.cpp
│ │ ├── disablerotationinteractorstyle.h
│ │ ├── distancewidgetobserver.cpp
│ │ ├── distancewidgetobserver.h
│ │ ├── filereaderutils.cpp
│ │ ├── filereaderutils.h
│ │ ├── implicitplanewidgetobserver.cpp
│ │ ├── implicitplanewidgetobserver.h
│ │ ├── interactor.cpp
│ │ ├── interactor.h
│ │ ├── lineprober.cpp
│ │ ├── lineprober.h
│ │ ├── linewidgetobserver.cpp
│ │ ├── linewidgetobserver.h
│ │ ├── modeltovtktableconverter.cpp
│ │ ├── modeltovtktableconverter.h
│ │ ├── moveactorinteractorstyle.cpp
│ │ ├── moveactorinteractorstyle.h
│ │ ├── movelineinteractorstyle.cpp
│ │ ├── movelineinteractorstyle.h
│ │ ├── movepointinteractorstyle.cpp
│ │ ├── movepointinteractorstyle.h
│ │ ├── planecutter.cpp
│ │ ├── planecutter.h
│ │ ├── pointmover.cpp
│ │ ├── pointmover.h
│ │ ├── pointstopolydataconverter.cpp
│ │ ├── pointstopolydataconverter.h
│ │ ├── pointwidgetobserver.cpp
│ │ ├── pointwidgetobserver.h
│ │ ├── rendererslayoutalgo.h
│ │ ├── sliderwidgetobserver.cpp
│ │ ├── sliderwidgetobserver.h
│ │ ├── spherecutter.cpp
│ │ ├── spherecutter.h
│ │ ├── spherewidgetobserver.cpp
│ │ ├── spherewidgetobserver.h
│ │ ├── surface.cpp
│ │ ├── surface.h
│ │ ├── vtkUnstructuredGridRelevantPointsFilter.cpp
│ │ ├── vtkUnstructuredGridRelevantPointsFilter.h
│ │ ├── vtkplot2dwidget.cpp
│ │ ├── vtkplot2dwidget.h
│ │ ├── vtkplot3dwidget.cpp
│ │ ├── vtkplot3dwidget.h
│ │ ├── vtkplotpiewidget.cpp
│ │ ├── vtkplotpiewidget.h
│ │ ├── vtkplotwidget.cpp
│ │ ├── vtkplotwidget.h
│ │ ├── vtkutils.cpp
│ │ ├── vtkutils.h
│ │ ├── vtkutils.pri
│ │ ├── vtkutils.pro
│ │ ├── vtkutils_dependencies.pri
│ │ ├── vtkutils_global.h
│ │ ├── vtkwidget.cpp
│ │ └── vtkwidget.h
│ └── widgets/
│ ├── colorcombobox.cpp
│ ├── colorcombobox.h
│ ├── colorpushbutton.cpp
│ ├── colorpushbutton.h
│ ├── fontpushbutton.cpp
│ ├── fontpushbutton.h
│ ├── gradientcombobox.cpp
│ ├── gradientcombobox.h
│ ├── imagecompareboard.cpp
│ ├── imagecompareboard.h
│ ├── penstylebox.cpp
│ ├── penstylebox.h
│ ├── qtcolorpicker.cpp
│ ├── qtcolorpicker.h
│ ├── tagwidget.cpp
│ ├── tagwidget.h
│ ├── widgets.pro
│ ├── widgets_dependencies.pri
│ └── widgets_global.h
├── plugin.pri
├── plugins/
│ ├── animation/
│ │ ├── animation.pro
│ │ ├── animation_dependencies.pri
│ │ ├── animationplugin.cpp
│ │ ├── animationplugin.h
│ │ ├── animationscenewindow.cpp
│ │ ├── animationscenewindow.h
│ │ ├── animationscenewindow.ui
│ │ ├── basicanimationwindow.cpp
│ │ ├── basicanimationwindow.h
│ │ ├── basicanimationwindow.ui
│ │ └── res.qrc
│ ├── buildinsources/
│ │ ├── buildinsources.pro
│ │ ├── buildinsources_dependencies.pri
│ │ ├── buildinsourcesplugin.cpp
│ │ ├── buildinsourcesplugin.h
│ │ ├── res.qrc
│ │ ├── texturewindow.cpp
│ │ ├── texturewindow.h
│ │ └── texturewindow.ui
│ ├── buildinwidgets/
│ │ ├── anglewidgetconfig.ui
│ │ ├── anglewidgetwindow.cpp
│ │ ├── anglewidgetwindow.h
│ │ ├── basewidgetwindow.cpp
│ │ ├── basewidgetwindow.h
│ │ ├── basewidgetwindow.ui
│ │ ├── buildinwidgets.pro
│ │ ├── buildinwidgets_dependencies.pri
│ │ ├── buildinwidgetsplugin.cpp
│ │ ├── buildinwidgetsplugin.h
│ │ ├── camerawidgetconfig.ui
│ │ ├── camerawidgetwindow.cpp
│ │ ├── camerawidgetwindow.h
│ │ ├── contourwidgetconfig.ui
│ │ ├── contourwidgetwindow.cpp
│ │ ├── contourwidgetwindow.h
│ │ ├── distancewidgetconfig.ui
│ │ ├── distancewidgetwindow.cpp
│ │ ├── distancewidgetwindow.h
│ │ ├── scalarbarwidgetconfig.ui
│ │ ├── scalarbarwidgetwindow.cpp
│ │ ├── scalarbarwidgetwindow.h
│ │ ├── sliderwidgetconfig.ui
│ │ ├── sliderwidgetwindow.cpp
│ │ ├── sliderwidgetwindow.h
│ │ ├── textwidgetconfig.ui
│ │ ├── textwidgetwindow.cpp
│ │ └── textwidgetwindow.h
│ ├── camera/
│ │ ├── axesactorwindow.cpp
│ │ ├── axesactorwindow.h
│ │ ├── axesactorwindow.ui
│ │ ├── camera.pro
│ │ ├── camera_dependencies.pri
│ │ ├── cameraplugin.cpp
│ │ ├── cameraplugin.h
│ │ ├── camerawindow.cpp
│ │ ├── camerawindow.h
│ │ ├── camerawindow.ui
│ │ ├── mainwidget.cpp
│ │ ├── mainwidget.h
│ │ └── mainwidget.ui
│ ├── chart3d/
│ │ ├── bar3dwindow.cpp
│ │ ├── bar3dwindow.h
│ │ ├── chart3d.pro
│ │ ├── chart3d_dependencies.pri
│ │ ├── chart3dplugin.cpp
│ │ ├── chart3dplugin.h
│ │ ├── chart3dwindow.cpp
│ │ ├── chart3dwindow.h
│ │ ├── chart3dwindow.ui
│ │ ├── configpoints3d.ui
│ │ ├── lines3dwindow.cpp
│ │ ├── lines3dwindow.h
│ │ ├── points3dwindow.cpp
│ │ └── points3dwindow.h
│ ├── constructsurface/
│ │ ├── constructsurface.pro
│ │ ├── constructsurface_dependencies.pri
│ │ ├── constructsurfaceplugin.cpp
│ │ ├── constructsurfaceplugin.h
│ │ ├── contourwindow.cpp
│ │ ├── contourwindow.h
│ │ ├── contourwindow.ui
│ │ ├── data.qrc
│ │ ├── datafiles/
│ │ │ ├── demo.txt
│ │ │ └── pit.txt
│ │ ├── dialog.cpp
│ │ ├── dialog.h
│ │ ├── dialog.ui
│ │ ├── quadricwindow.ui
│ │ ├── rendersurface.cpp
│ │ ├── rendersurface.h
│ │ ├── rendersurface.ui
│ │ ├── widget.cpp
│ │ └── widget.h
│ ├── contour2d/
│ │ ├── abstractcontourgenerator.cpp
│ │ ├── abstractcontourgenerator.h
│ │ ├── bandedcontourgenerator.cpp
│ │ ├── bandedcontourgenerator.h
│ │ ├── contour2d.pro
│ │ ├── contour2d_dependencies.pri
│ │ ├── contour2dinteractorstyle.cpp
│ │ ├── contour2dinteractorstyle.h
│ │ ├── contour2dplugin.cpp
│ │ ├── contour2dplugin.h
│ │ ├── contourwindow.cpp
│ │ ├── contourwindow.h
│ │ ├── contourwindow.ui
│ │ ├── data.qrc
│ │ ├── datafiles/
│ │ │ ├── demo.txt
│ │ │ └── pit.txt
│ │ ├── smoothcontourgenerator.cpp
│ │ └── smoothcontourgenerator.h
│ ├── custom3dwidget/
│ │ ├── custom3dwidget.pro
│ │ ├── custom3dwidget_dependencies.pri
│ │ ├── custom3dwidgetplugin.cpp
│ │ ├── custom3dwidgetplugin.h
│ │ ├── customxyplotrepresentation.cpp
│ │ ├── customxyplotrepresentation.h
│ │ ├── customxyplotwidget.cpp
│ │ ├── customxyplotwidget.h
│ │ ├── usearrowwidgetwindow.cpp
│ │ ├── usearrowwidgetwindow.h
│ │ ├── usearrowwidgetwindow.ui
│ │ ├── usecustomwidgetwindow.cpp
│ │ ├── usecustomwidgetwindow.h
│ │ ├── usecustomwidgetwindow.ui
│ │ ├── vtkarrowrepresentation.cpp
│ │ ├── vtkarrowrepresentation.h
│ │ ├── vtkarrowwidget.cpp
│ │ └── vtkarrowwidget.h
│ ├── displaychinese/
│ │ ├── dialog.cpp
│ │ ├── dialog.h
│ │ ├── dialog.ui
│ │ ├── displaychinese.pro
│ │ ├── displaychinese_dependencies.pri
│ │ ├── displaychineseplugin.cpp
│ │ ├── displaychineseplugin.h
│ │ ├── main.cpp
│ │ ├── widget.cpp
│ │ └── widget.h
│ ├── filereader/
│ │ ├── filereader.pro
│ │ ├── filereader_dependencies.pri
│ │ ├── filereaderplugin.cpp
│ │ ├── filereaderplugin.h
│ │ ├── filetree.cpp
│ │ ├── filetree.h
│ │ ├── mainwidget.cpp
│ │ ├── mainwidget.h
│ │ ├── mainwidget.ui
│ │ ├── widget.cpp
│ │ └── widget.h
│ ├── filters/
│ │ ├── clipconfig.ui
│ │ ├── clipwindow.cpp
│ │ ├── clipwindow.h
│ │ ├── cutconfig.ui
│ │ ├── cutwindow.cpp
│ │ ├── cutwindow.h
│ │ ├── decimateconfig.ui
│ │ ├── decimatewindow.cpp
│ │ ├── decimatewindow.h
│ │ ├── filters.pro
│ │ ├── filters_dependencies.pri
│ │ ├── filtersplugin.cpp
│ │ ├── filtersplugin.h
│ │ ├── filterwindow.cpp
│ │ ├── filterwindow.h
│ │ ├── generalfilterwindow.ui
│ │ ├── glyphconfig.ui
│ │ ├── glyphwindow.cpp
│ │ ├── glyphwindow.h
│ │ ├── isosurfaceconfig.ui
│ │ ├── isosurfacewindow.cpp
│ │ ├── isosurfacewindow.h
│ │ ├── probeconfig.ui
│ │ ├── probewindow.cpp
│ │ ├── probewindow.h
│ │ ├── qcustomplot.cpp
│ │ ├── qcustomplot.h
│ │ ├── slicewindow.cpp
│ │ ├── slicewindow.h
│ │ ├── smoothconfig.ui
│ │ ├── smoothwindow.cpp
│ │ ├── smoothwindow.h
│ │ ├── streamlineconfig.ui
│ │ ├── streamlinewindow.cpp
│ │ ├── streamlinewindow.h
│ │ ├── thresholdwindow.cpp
│ │ └── thresholdwindow.h
│ ├── imageprocessing/
│ │ ├── imageprocessing.pro
│ │ ├── imageprocessing_dependencies.pri
│ │ ├── imageprocessingplugin.cpp
│ │ ├── imageprocessingplugin.h
│ │ ├── imagetree.cpp
│ │ ├── imagetree.h
│ │ ├── mainwidget.cpp
│ │ ├── mainwidget.h
│ │ ├── mainwidget.ui
│ │ └── res.qrc
│ ├── light/
│ │ ├── galaxywindow.cpp
│ │ ├── galaxywindow.h
│ │ ├── galaxywindow.ui
│ │ ├── light.pro
│ │ ├── light_dependencies.pri
│ │ ├── lightplugin.cpp
│ │ ├── lightplugin.h
│ │ ├── mainwidget.cpp
│ │ ├── mainwidget.h
│ │ ├── mainwidget.ui
│ │ └── res.qrc
│ ├── miscellaneous/
│ │ ├── backgroundwindow.cpp
│ │ ├── backgroundwindow.h
│ │ ├── backgroundwindow.ui
│ │ ├── colormapwindow.cpp
│ │ ├── colormapwindow.h
│ │ ├── colormapwindow.ui
│ │ ├── conicspiralconfig.ui
│ │ ├── diniconfig.ui
│ │ ├── ellipsoidconfig.ui
│ │ ├── miscellaneous.pro
│ │ ├── miscellaneous_dependencies.pri
│ │ ├── miscellaneousplugin.cpp
│ │ ├── miscellaneousplugin.h
│ │ ├── parametricobjectswindow.cpp
│ │ ├── parametricobjectswindow.h
│ │ ├── parametricobjectswindow.ui
│ │ ├── randomhillsconfig.ui
│ │ ├── representationwidget.cpp
│ │ ├── representationwidget.h
│ │ ├── representationwidget.ui
│ │ ├── romanconfig.ui
│ │ ├── scaleaxeswindow.cpp
│ │ ├── scaleaxeswindow.h
│ │ ├── scaleaxeswindow.ui
│ │ ├── splineconfig.ui
│ │ ├── superellipsoidconfig.ui
│ │ ├── supertoroidconfig.ui
│ │ └── torusconfig.ui
│ ├── picking/
│ │ ├── drawspherewindow.cpp
│ │ ├── drawspherewindow.h
│ │ ├── drawspherewindow.ui
│ │ ├── drawsurfacewindow.cpp
│ │ ├── drawsurfacewindow.h
│ │ ├── drawsurfacewindow.ui
│ │ ├── mouseeventinteractorstyle.cpp
│ │ ├── mouseeventinteractorstyle.h
│ │ ├── pickactorwindow.cpp
│ │ ├── pickactorwindow.h
│ │ ├── pickactorwindow.ui
│ │ ├── pickcellinteractorstyle.cpp
│ │ ├── pickcellinteractorstyle.h
│ │ ├── pickcellwindow.cpp
│ │ ├── pickcellwindow.h
│ │ ├── pickcellwindow.ui
│ │ ├── picking.pro
│ │ ├── picking_dependencies.pri
│ │ ├── pickingplugin.cpp
│ │ ├── pickingplugin.h
│ │ ├── selectareainteractorstyle.cpp
│ │ ├── selectareainteractorstyle.h
│ │ ├── selectareawindow.cpp
│ │ ├── selectareawindow.h
│ │ └── selectareawindow.ui
│ ├── pipeline/
│ │ ├── arrowitem.cpp
│ │ ├── arrowitem.h
│ │ ├── pipeline.pro
│ │ ├── pipeline_dependencies.pri
│ │ ├── pipelineplugin.cpp
│ │ ├── pipelineplugin.h
│ │ ├── pipelinewindow.cpp
│ │ ├── pipelinewindow.h
│ │ └── pipelinewindow.ui
│ ├── plot2d/
│ │ ├── bagplotwidget.cpp
│ │ ├── bagplotwidget.h
│ │ ├── barplotsettings.ui
│ │ ├── barplotwidget.cpp
│ │ ├── barplotwidget.h
│ │ ├── lineplotsettings.ui
│ │ ├── lineplotwidget.cpp
│ │ ├── lineplotwidget.h
│ │ ├── pieplotwidget.cpp
│ │ ├── pieplotwidget.h
│ │ ├── plot2d.pro
│ │ ├── plot2d_dependencies.pri
│ │ ├── plot2dplugin.cpp
│ │ ├── plot2dplugin.h
│ │ ├── plotwidget.cpp
│ │ ├── plotwidget.h
│ │ ├── scatterplotsettings.ui
│ │ ├── scatterplotwidget.cpp
│ │ ├── scatterplotwidget.h
│ │ ├── stackedplotwidget.cpp
│ │ ├── stackedplotwidget.h
│ │ └── tableplotwidget.ui
│ ├── plot3d/
│ │ ├── plot3d.pro
│ │ ├── plot3d_dependencies.pri
│ │ ├── plot3dplugin.cpp
│ │ ├── plot3dplugin.h
│ │ ├── plotline3dwindow.cpp
│ │ ├── plotline3dwindow.h
│ │ ├── plotpoints3dwindow.cpp
│ │ ├── plotpoints3dwindow.h
│ │ ├── plotsurfacewindow.cpp
│ │ ├── plotsurfacewindow.h
│ │ ├── plotwindow.cpp
│ │ ├── plotwindow.h
│ │ └── tablewidgetwindow.ui
│ ├── plotactor/
│ │ ├── barchartactorwindow.cpp
│ │ ├── barchartactorwindow.h
│ │ ├── piechartactorwindow.cpp
│ │ ├── piechartactorwindow.h
│ │ ├── piesettings.ui
│ │ ├── plotactor.pro
│ │ ├── plotactor_dependencies.pri
│ │ ├── plotactorplugin.cpp
│ │ ├── plotactorplugin.h
│ │ ├── plotactorwindow.cpp
│ │ ├── plotactorwindow.h
│ │ ├── plotactorwindow.ui
│ │ ├── spiderplotactorwindow.cpp
│ │ ├── spiderplotactorwindow.h
│ │ ├── spidersettings.ui
│ │ ├── xyplotactorwindow.cpp
│ │ └── xyplotactorwindow.h
│ ├── plugins.pro
│ ├── rendersphere/
│ │ ├── main.cpp
│ │ ├── rendersphere.pro
│ │ ├── rendersphere_dependencies.pri
│ │ ├── rendersphereplugin.cpp
│ │ ├── rendersphereplugin.h
│ │ ├── widget.cpp
│ │ └── widget.h
│ ├── screenshot/
│ │ ├── screenshot.pro
│ │ ├── screenshot_dependencies.pri
│ │ ├── screenshotplugin.cpp
│ │ ├── screenshotplugin.h
│ │ ├── screenshotwindow.cpp
│ │ ├── screenshotwindow.h
│ │ └── screenshotwindow.ui
│ ├── shader/
│ │ ├── editshaderwindow.cpp
│ │ ├── editshaderwindow.h
│ │ ├── editshaderwindow.ui
│ │ ├── shader.pro
│ │ ├── shader_dependencies.pri
│ │ ├── shaderplugin.cpp
│ │ ├── shaderplugin.h
│ │ ├── shaderwindow.cpp
│ │ ├── shaderwindow.h
│ │ └── shaderwindow.ui
│ ├── template/
│ │ ├── template.pro
│ │ ├── template_dependencies.pri
│ │ ├── templateplugin.cpp
│ │ └── templateplugin.h
│ └── volumerendering/
│ ├── volumerendering.pro
│ ├── volumerendering_dependencies.pri
│ ├── volumerenderingplugin.cpp
│ ├── volumerenderingplugin.h
│ ├── volumerenderingwindow.cpp
│ ├── volumerenderingwindow.h
│ └── volumerenderingwindow.ui
├── rpath.pri
├── src/
│ ├── main.cpp
│ ├── mainwindow.cpp
│ ├── mainwindow.h
│ ├── mainwindow.ui
│ ├── src.pro
│ └── src_dependencies.pri
└── vtk_inc.pri
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
# QVTKDemo
Using VTK-Qt binding to demonstrate VTK features.
# Demo snapshots
Sources
Texture
Draw Sphere
Draw Surface
XYPlotActor
PiePlotActor
BarPlotActor
SpiderPlotActor
Parametric Objects
BackgroundColor
Points3D
Lines3D
Bar3D
Render Surface
Contour
Chart Overlay, create custom 3d widget
Arrow Widget, custom 2d widget
Slider Widget
Angle Widget
Contour Widget
Distance Widget
Scale vtkCubeAxesActor2D
================================================
FILE: app.pri
================================================
include($$replace(_PRO_FILE_PWD_, ([^/]+$), \\1/\\1_dependencies.pri))
TARGET = $$APP_NAME
include(demos.pri)
include(rpath.pri)
# 预编译头文件
#isEmpty(PRECOMPILED_HEADER):PRECOMPILED_HEADER = $$PWD/shared/simcube_gui_pch.h
DESTDIR = $$QVTKDEMOS_BINARIES_PATH
TARGET = $$qtLibraryName($$TARGET)
TEMPLATE = app
================================================
FILE: demos.pri
================================================
!isEmpty(QVTKDEMOS_PRI_INCLUDED):error("demos.pri already included")
QVTKDEMOS_PRI_INCLUDED = 1
VERSION = 1.0
QMAKE_TARGET_COMPANY = "JasonZhang Inc"
QMAKE_TARGET_PRODUCT = "QVTKDemos"
QMAKE_TARGET_COPYRIGHT = "Copyright (C) 2016 Jason Zhang"
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
DEFINES += QT_MESSAGELOGCONTEXT
defineReplace(cleanPath) {
return($$clean_path($$1))
}
defineReplace(targetPath) {
return($$shell_path($$1))
}
defineReplace(qtLibraryName) {
unset(LIBRARY_NAME)
LIBRARY_NAME = $$1
CONFIG(debug, debug|release) {
!debug_and_release|build_pass {
mac:RET = $$member(LIBRARY_NAME, 0)_debug
else:win32:RET = $$member(LIBRARY_NAME, 0)d
}
}
isEmpty(RET):RET = $$LIBRARY_NAME
return($$RET)
}
defineReplace(scLibraryName) {
CONFIG(debug, debug|release) {
!debug_and_release|build_pass {
mac:RET = $${1}_debug$$section(VERSION, ., 0, 0)
else:win32:RET = $${1}d$$section(VERSION, ., 0, 0)
}
}
isEmpty(RET):RET = $$1$$section(VERSION, ., 0, 0)
return($$RET)
}
defineTest(minQtVersion) {
maj = $$1
min = $$2
patch = $$3
isEqual(QT_MAJOR_VERSION, $$maj) {
isEqual(QT_MINOR_VERSION, $$min) {
isEqual(QT_PATCH_VERSION, $$patch) {
return(true)
}
greaterThan(QT_PATCH_VERSION, $$patch) {
return(true)
}
}
greaterThan(QT_MINOR_VERSION, $$min) {
return(true)
}
}
greaterThan(QT_MAJOR_VERSION, $$maj) {
return(true)
}
return(false)
}
QVTKDEMOS_SOURCE_TREE = $$PWD
isEmpty(QVTKDEMOS_BUILD_TREE) {
sub_dir = $$_PRO_FILE_PWD_
sub_dir ~= s,^$$re_escape($$PWD),,
QVTKDEMOS_BUILD_TREE = $$cleanPath($$OUT_PWD)
QVTKDEMOS_BUILD_TREE ~= s,$$re_escape($$sub_dir)$,,
}
CONFIG(debug, debug|release) {
DEBUG_RELEASE = DEBUG
} else {
DEBUG_RELEASE = RELEASE
}
#CURRENTHOST = WIN32_GCC
win32-msvc2013:contains(QMAKE_HOST.arch, x86): {
CURRENTHOST = WIN32_VC2013
QVTKDEMOS_BIN = win32
}
win32-msvc2015:contains(QMAKE_HOST.arch, x86): {
CURRENTHOST = WIN32_VC2015
QVTKDEMOS_BIN = win32
}
win32-g++:contains(QMAKE_HOST.arch, x86): {
CURRENTHOST = WIN32_GCC
QVTKDEMOS_BIN = win32
}
win32-msvc2013:isEqual(QT_ARCH, x86_64): {
CURRENTHOST = WIN64_VC2013
QVTKDEMOS_BIN = win64
}
win32-msvc2015:isEqual(QT_ARCH, x86_64): {
CURRENTHOST = WIN64_VC2015
QVTKDEMOS_BIN = win64
}
#win32-g++:isEqual(QT_ARCH, x86_64): {
# CURRENTHOST = WIN64_GCC
#}
win32-g++:contains(QMAKE_HOST.arch, x86_64): {
CURRENTHOST = WIN32_GCC
QVTKDEMOS_BIN = win32
}
unix: isEqual(QT_ARCH, x86_64): {
CURRENTHOST = LINUX64
QVTKDEMOS_BIN = linux64
}
QVTKDEMOS_APP_PATH = $$QVTKDEMOS_SOURCE_TREE/build/bin/$${CURRENTHOST}_$$DEBUG_RELEASE
QVTKDEMOS_BINARIES_PATH = $$QVTKDEMOS_APP_PATH/$${QVTKDEMOS_BIN}
QVTKDEMOS_LIBRARY_PATH = $$QVTKDEMOS_SOURCE_TREE/build/lib/$${CURRENTHOST}_$$DEBUG_RELEASE
QVTKDEMOS_PLUGIN_PATH = $$QVTKDEMOS_APP_PATH/$${QVTKDEMOS_BIN}/plugins
#拷贝一个或多个文件到指定目录, 第一个参数是待拷贝文件列表, 第二个参数是指定目录
defineReplace(copyFile) {
unset(files)
unset(dist)
files = $$1 #文件列表
#dist = $$targetPath($$2) #指定目录
dist = $$2
win32 {
COPY = copy /y
MKDIR = mkdir
} else {
COPY = cp
MKDIR = mkdir -p
}
dist = $$system_path($$dist)
!exists($$dist):system($$MKDIR $$dist)
for (f, files) {
#dist_file = $$dist/$$basename(f)
#强制覆盖已存在的 todo linux下需测试
#!exists($$dist_file): {
f = $$system_path($$f)
system($$COPY $$f "$$dist")
#}
}
return($$files)
}
#拷贝一个目录的所有内容到另一个目录中, 第一个参数是待拷贝目录, 第二个参数是指定目录
defineReplace(copyFolder) {
unset(sourceDir)
unset(dist)
sourceDir = $$system_path($$1)
dist = $$system_path($$2)
win32 {
COPY = xcopy /e /y
MKDIR = mkdir
} else {
COPY = cp -rf
MKDIR = mkdir -p
}
#强制覆盖已存在的 todo linux下需测试
#!exists($$dist) {
system($$MKDIR $$dist)
system($$COPY $$sourceDir $$dist)
#}
return($$dist)
}
INCLUDEPATH *= \
$$QVTKDEMOS_SOURCE_TREE/libs $$QVTKDEMOS_SOURCE_TREE/shared
LIBS *= -L$$QVTKDEMOS_LIBRARY_PATH
!macx:DEFINES += QT_USE_FAST_OPERATOR_PLUS QT_USE_FAST_CONCATENATION
win32-msvc* {
#Don't warn about sprintf, fopen etc being 'unsafe'
DEFINES += _CRT_SECURE_NO_WARNINGS
#编译出可在xp下运行的版本
QMAKE_SUBSYSTEM_SUFFIX = ,5.01
}
contains(QT, core): QT += concurrent
contains(QT, gui): QT += widgets
THIRDPARTYINCLUDE = $$PWD/include/3rdparty
INCLUDEPATH *= $$THIRDPARTYINCLUDE
CONFIG += c++11
# 递归决议库依赖性
done_libs =
for(ever) {
isEmpty(LIB_DEPENDS): \
break()
done_libs += $$LIB_DEPENDS
for(dep, LIB_DEPENDS) {
include($$PWD/libs/$$dep/$${dep}_dependencies.pri) # this depends on your project structure
LIBS += -l$$scLibraryName($$LIB_NAME)
}
LIB_DEPENDS = $$unique(LIB_DEPENDS)
LIB_DEPENDS -= $$unique(done_libs)
}
================================================
FILE: demos.pro
================================================
include(demos.pri)
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += libs \
plugins \
src \
================================================
FILE: lib.pri
================================================
include($$replace(_PRO_FILE_PWD_, ([^/]+$), \\1/\\1_dependencies.pri))
TARGET = $$LIB_NAME
include(demos.pri)
win32 {
DLLDESTDIR = $$QVTKDEMOS_BINARIES_PATH
}
DESTDIR = $$QVTKDEMOS_LIBRARY_PATH
include(rpath.pri)
TARGET = $$qtLibraryName($$TARGET)
TEMPLATE = lib
CONFIG += shared dll
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
QMAKE_TARGET_DESCRIPTION = "QVTKDemo Library"
================================================
FILE: libs/3dparty/3dparty.pri
================================================
contains(QT, core): QT += concurrent
contains(QT, gui): QT += widgets
CONFIG += c++11
================================================
FILE: libs/3dparty/3dparty.pro
================================================
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
include(../../lib.pri)
DEFINES += THIRDPARTY_LIBRARY
HEADERS += 3dparty_global.h \
flowlayout.h \
QRoundProgressBar.h
SOURCES += flowlayout.cpp \
QRoundProgressBar.cpp
================================================
FILE: libs/3dparty/3dparty_dependencies.pri
================================================
LIB_NAME = 3dparty
LIB_DEPENDS +=
================================================
FILE: libs/3dparty/3dparty_global.h
================================================
#ifndef THIRDPARTY_GLOBAL_H
#define THIRDPARTY_GLOBAL_H
#include
#if defined(THIRDPARTY_LIBRARY)
# define THIRDPARTY_EXPORT Q_DECL_EXPORT
#else
# define THIRDPARTY_EXPORT Q_DECL_IMPORT
#endif
#endif // THIRDPARTY_GLOBAL_H
================================================
FILE: libs/3dparty/QRoundProgressBar.cpp
================================================
/*
* QRoundProgressBar - a circular progress bar Qt widget.
*
* Sintegrial Technologies (c) 2015-now
*
* The software is freeware and is distributed "as is" with the complete source codes.
* Anybody is free to use it in any software projects, either commercial or non-commercial.
* Please do not remove this copyright message and remain the name of the author unchanged.
*
* It is very appreciated if you produce some feedback to us case you are going to use
* the software.
*
* Please send your questions, suggestions, and information about found issues to the
*
* sintegrial@gmail.com
*
*/
#include "QRoundProgressBar.h"
#include
QRoundProgressBar::QRoundProgressBar(QWidget *parent) :
QWidget(parent),
m_min(0), m_max(100),
m_value(25),
m_nullPosition(PositionTop),
m_barStyle(StyleDonut),
m_outlinePenWidth(1),
m_dataPenWidth(1),
m_rebuildBrush(false),
m_format("%p%"),
m_decimals(1),
m_updateFlags(UF_PERCENT)
{
}
void QRoundProgressBar::setRange(double min, double max)
{
m_min = min;
m_max = max;
if (m_max < m_min)
qSwap(m_max, m_min);
if (m_value < m_min)
m_value = m_min;
else if (m_value > m_max)
m_value = m_max;
if (!m_gradientData.isEmpty())
m_rebuildBrush = true;
update();
}
void QRoundProgressBar::setMinimum(double min)
{
setRange(min, m_max);
}
void QRoundProgressBar::setMaximum(double max)
{
setRange(m_min, max);
}
void QRoundProgressBar::setValue(double val)
{
if (m_value != val)
{
if (val < m_min)
m_value = m_min;
else if (val > m_max)
m_value = m_max;
else
m_value = val;
update();
}
}
void QRoundProgressBar::setValue(int val)
{
setValue(double(val));
}
void QRoundProgressBar::setNullPosition(double position)
{
if (position != m_nullPosition)
{
m_nullPosition = position;
if (!m_gradientData.isEmpty())
m_rebuildBrush = true;
update();
}
}
void QRoundProgressBar::setBarStyle(QRoundProgressBar::BarStyle style)
{
if (style != m_barStyle)
{
m_barStyle = style;
update();
}
}
void QRoundProgressBar::setOutlinePenWidth(double penWidth)
{
if (penWidth != m_outlinePenWidth)
{
m_outlinePenWidth = penWidth;
update();
}
}
void QRoundProgressBar::setDataPenWidth(double penWidth)
{
if (penWidth != m_dataPenWidth)
{
m_dataPenWidth = penWidth;
update();
}
}
void QRoundProgressBar::setDataColors(const QGradientStops &stopPoints)
{
if (stopPoints != m_gradientData)
{
m_gradientData = stopPoints;
m_rebuildBrush = true;
update();
}
}
void QRoundProgressBar::setFormat(const QString &format)
{
if (format != m_format)
{
m_format = format;
valueFormatChanged();
}
}
void QRoundProgressBar::resetFormat()
{
m_format = QString::null;
valueFormatChanged();
}
void QRoundProgressBar::setDecimals(int count)
{
if (count >= 0 && count != m_decimals)
{
m_decimals = count;
valueFormatChanged();
}
}
void QRoundProgressBar::paintEvent(QPaintEvent* /*event*/)
{
double outerRadius = qMin(width(), height());
QRectF baseRect(1, 1, outerRadius-2, outerRadius-2);
QImage buffer(outerRadius, outerRadius, QImage::Format_ARGB32_Premultiplied);
QPainter p(&buffer);
p.setRenderHint(QPainter::Antialiasing);
// data brush
rebuildDataBrushIfNeeded();
// background
drawBackground(p, buffer.rect());
// base circle
drawBase(p, baseRect);
// data circle
double arcStep = 360.0 / (m_max - m_min) * m_value;
drawValue(p, baseRect, m_value, arcStep);
// center circle
double innerRadius(0);
QRectF innerRect;
calculateInnerRect(baseRect, outerRadius, innerRect, innerRadius);
drawInnerBackground(p, innerRect);
// text
drawText(p, innerRect, innerRadius, m_value);
// finally draw the bar
p.end();
QPainter painter(this);
painter.fillRect(baseRect, palette().background());
painter.drawImage(0,0, buffer);
}
void QRoundProgressBar::drawBackground(QPainter &p, const QRectF &baseRect)
{
p.fillRect(baseRect, palette().background());
}
void QRoundProgressBar::drawBase(QPainter &p, const QRectF &baseRect)
{
switch (m_barStyle)
{
case StyleDonut:
p.setPen(QPen(palette().shadow().color(), m_outlinePenWidth));
p.setBrush(palette().base());
p.drawEllipse(baseRect);
break;
case StylePie:
p.setPen(QPen(palette().base().color(), m_outlinePenWidth));
p.setBrush(palette().base());
p.drawEllipse(baseRect);
break;
case StyleLine:
p.setPen(QPen(palette().base().color(), m_outlinePenWidth));
p.setBrush(Qt::NoBrush);
p.drawEllipse(baseRect.adjusted(m_outlinePenWidth/2, m_outlinePenWidth/2, -m_outlinePenWidth/2, -m_outlinePenWidth/2));
break;
default:;
}
}
void QRoundProgressBar::drawValue(QPainter &p, const QRectF &baseRect, double value, double arcLength)
{
// nothing to draw
if (value == m_min)
return;
// for Line style
if (m_barStyle == StyleLine)
{
p.setPen(QPen(palette().highlight().color(), m_dataPenWidth));
p.setBrush(Qt::NoBrush);
p.drawArc(baseRect.adjusted(m_outlinePenWidth/2, m_outlinePenWidth/2, -m_outlinePenWidth/2, -m_outlinePenWidth/2),
m_nullPosition * 16,
-arcLength * 16);
return;
}
// for Pie and Donut styles
QPainterPath dataPath;
dataPath.setFillRule(Qt::WindingFill);
// pie segment outer
dataPath.moveTo(baseRect.center());
dataPath.arcTo(baseRect, m_nullPosition, -arcLength);
dataPath.lineTo(baseRect.center());
p.setBrush(palette().highlight());
p.setPen(QPen(palette().shadow().color(), m_dataPenWidth));
p.drawPath(dataPath);
}
void QRoundProgressBar::calculateInnerRect(const QRectF &/*baseRect*/, double outerRadius, QRectF &innerRect, double &innerRadius)
{
// for Line style
if (m_barStyle == StyleLine)
{
innerRadius = outerRadius - m_outlinePenWidth;
}
else // for Pie and Donut styles
{
innerRadius = outerRadius * 0.75;
}
double delta = (outerRadius - innerRadius) / 2;
innerRect = QRectF(delta, delta, innerRadius, innerRadius);
}
void QRoundProgressBar::drawInnerBackground(QPainter &p, const QRectF &innerRect)
{
if (m_barStyle == StyleDonut)
{
p.setBrush(palette().alternateBase());
p.drawEllipse(innerRect);
}
}
void QRoundProgressBar::drawText(QPainter &p, const QRectF &innerRect, double innerRadius, double value)
{
if (m_format.isEmpty())
return;
// !!! to revise
QFont f(font());
f.setPixelSize(innerRadius * qMax(0.05, (0.35 - (double)m_decimals * 0.08)));
p.setFont(f);
QRectF textRect(innerRect);
p.setPen(palette().text().color());
p.drawText(textRect, Qt::AlignCenter, valueToText(value));
}
QString QRoundProgressBar::valueToText(double value) const
{
QString textToDraw(m_format);
if (m_updateFlags & UF_VALUE)
textToDraw.replace("%v", QString::number(value, 'f', m_decimals));
if (m_updateFlags & UF_PERCENT)
{
double procent = (value - m_min) / (m_max - m_min) * 100.0;
textToDraw.replace("%p", QString::number(procent, 'f', m_decimals));
}
if (m_updateFlags & UF_MAX)
textToDraw.replace("%m", QString::number(m_max - m_min + 1, 'f', m_decimals));
return textToDraw;
}
void QRoundProgressBar::valueFormatChanged()
{
m_updateFlags = 0;
if (m_format.contains("%v"))
m_updateFlags |= UF_VALUE;
if (m_format.contains("%p"))
m_updateFlags |= UF_PERCENT;
if (m_format.contains("%m"))
m_updateFlags |= UF_MAX;
update();
}
void QRoundProgressBar::rebuildDataBrushIfNeeded()
{
if (m_rebuildBrush)
{
m_rebuildBrush = false;
QConicalGradient dataBrush;
dataBrush.setCenter(0.5,0.5);
dataBrush.setCoordinateMode(QGradient::StretchToDeviceMode);
// invert colors
for (int i = 0; i < m_gradientData.count(); i++)
{
dataBrush.setColorAt(1.0 - m_gradientData.at(i).first, m_gradientData.at(i).second);
}
// angle
dataBrush.setAngle(m_nullPosition);
QPalette p(palette());
p.setBrush(QPalette::Highlight, dataBrush);
setPalette(p);
}
}
================================================
FILE: libs/3dparty/QRoundProgressBar.h
================================================
/*
* QRoundProgressBar - a circular progress bar Qt widget.
*
* Sintegrial Technologies (c) 2015-now
*
* The software is freeware and is distributed "as is" with the complete source codes.
* Anybody is free to use it in any software projects, either commercial or non-commercial.
* Please do not remove this copyright message and remain the name of the author unchanged.
*
* It is very appreciated if you produce some feedback to us case you are going to use
* the software.
*
* Please send your questions, suggestions, and information about found issues to the
*
* sintegrial@gmail.com
*
*/
#ifndef QROUNDPROGRESSBAR_H
#define QROUNDPROGRESSBAR_H
#include
#include "3dparty_global.h"
/**
* @brief The QRoundProgressBar class represents a circular progress bar and maintains its API
* similar to the *QProgressBar*.
*
* ### Styles
* QRoundProgressBar currently supports Donut, Pie and Line styles. See setBarStyle() for more details.
*
* ### Colors
* Generally QRoundProgressBar uses its palette and font attributes to define how it will look.
*
* The following \a QPalette members are considered:
* - *QPalette::Window* background of the whole widget (normally should be set to Qt::NoBrush)
* - *QPalette::Base* background of the non-filled progress bar area (should be set to Qt::NoBrush to make it transparent)
* - *QPalette::AlternateBase* background of the central circle where the text is shown (for \a Donut style)
* - *QPalette::Shadow* foreground of the non-filled progress bar area (i.e. border color)
* - *QPalette::Highlight* background of the filled progress bar area
* - *QPalette::Text* color of the text shown in the center
*
* Create a \a QPalette with given attributes and apply it via `setPalette()`.
*
* ### Color gradient
* \a Donut and \a Pie styles allow to use color gradient for currernt value area instead of plain brush fill.
* See setDataColors() for more details.
*
* ### Value text
* Value text is generally drawn inside the QRoundProgressBar using its `font()` and \a QPalette::Text role from its `palette()`.
*
* To define pattern of the text, use setFormat() function (see Qt's \a QProgressBar for more details).
*
* To define number of decimals to be shown, use setDecimals() function.
*
* ### Font
* To use own font for value text, apply it via `setFont()`.
*
* By default, font size will be adjusted automatically to fit the inner circle of the widget.
*/
class THIRDPARTY_EXPORT QRoundProgressBar : public QWidget
{
Q_OBJECT
public:
explicit QRoundProgressBar(QWidget *parent = 0);
static const int PositionLeft = 180;
static const int PositionTop = 90;
static const int PositionRight = 0;
static const int PositionBottom = -90;
/**
* @brief Return position (in degrees) of minimum value.
* \sa setNullPosition
*/
double nullPosition() const { return m_nullPosition; }
/**
* @brief Defines position of minimum value.
* @param position position on the circle (in degrees) of minimum value
* \sa nullPosition
*/
void setNullPosition(double position);
/**
* @brief The BarStyle enum defines general look of the progress bar.
*/
enum BarStyle
{
/// Donut style (filled torus around the text)
StyleDonut,
/// Pie style (filled pie segment with the text in center)
StylePie,
/// Line style (thin round line around the text)
StyleLine
};
/**
* @brief Sets visual style of the widget.
* \sa barStyle
*/
void setBarStyle(BarStyle style);
/**
* @brief Returns current progree bar style.
* \sa setBarStyle
*/
BarStyle barStyle() const { return m_barStyle; }
/**
* @brief Sets width of the outline circle pen.
* @param penWidth width of the outline circle pen (in pixels)
*/
void setOutlinePenWidth(double penWidth);
/**
* @brief Returns width of the outline circle pen.
*/
double outlinePenWidth() const { return m_outlinePenWidth; }
/**
* @brief Sets width of the data circle pen.
* @param penWidth width of the data circle pen (in pixels)
*/
void setDataPenWidth(double penWidth);
/**
* @brief Returns width of the data circle pen.
*/
double dataPenWidth() const { return m_dataPenWidth; }
/**
* @brief Sets colors of the visible data and makes gradient brush from them.
* Gradient colors can be set for \a Donut and \a Pie styles (see setBarStyle() function).
*
* *Warning*: this function will override widget's `palette()` to set dynamically created gradient brush.
*
* @param stopPoints List of colors (should have at least 2 values, see Qt's \a QGradientStops for more details).
* Color value at point 0 corresponds to the minimum() value, while color value at point 1
* corresponds to the maximum(). Other colors will be distributed accordingly to the defined ranges (see setRange()).
*/
void setDataColors(const QGradientStops& stopPoints);
/**
* @brief Defines the string used to generate the current text.
* If no format is set, no text will be shown.
* @param format see \a QProgressBar's format description
* \sa setDecimals
*/
void setFormat(const QString& format);
/**
* @brief Sets format string to empty string. No text will be shown therefore.
* See setFormat() for more information.
*/
void resetFormat();
/**
* @brief Returns the string used to generate the current text.
*/
QString format() const { return m_format; }
/**
* @brief Sets number of decimals to show after the comma (default is 1).
* \sa setFormat
*/
void setDecimals(int count);
/**
* @brief Returns number of decimals to show after the comma (default is 1).
* \sa setFormat, setDecimals
*/
int decimals() const { return m_decimals; }
/**
* @brief Returns current value shown on the widget.
* \sa setValue()
*/
double value() const { return m_value; }
/**
* @brief Returns minimum of the allowed value range.
* \sa setMinimum, setRange
*/
double minimum() const { return m_min; }
/**
* @brief Returns maximum of the allowed value range.
* \sa setMaximum, setRange
*/
double maximum() const { return m_max; }
public Q_SLOTS:
/**
* @brief Defines minimum und maximum of the allowed value range.
* If the current value does not fit into the range, it will be automatically adjusted.
* @param min minimum of the allowed value range
* @param max maximum of the allowed value range
*/
void setRange(double min, double max);
/**
* @brief Defines minimum of the allowed value range.
* If the current value does not fit into the range, it will be automatically adjusted.
* @param min minimum of the allowed value range
* \sa setRange
*/
void setMinimum(double min);
/**
* @brief Defines maximum of the allowed value range.
* If the current value does not fit into the range, it will be automatically adjusted.
* @param max maximum of the allowed value range
* \sa setRange
*/
void setMaximum(double max);
/**
* @brief Sets a value which will be shown on the widget.
* @param val must be between minimum() and maximum()
*/
void setValue(double val);
/**
* @brief Integer version of the previous slot.
* @param val must be between minimum() and maximum()
*/
void setValue(int val);
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void drawBackground(QPainter& p, const QRectF& baseRect);
virtual void drawBase(QPainter& p, const QRectF& baseRect);
virtual void drawValue(QPainter& p, const QRectF& baseRect, double value, double arcLength);
virtual void calculateInnerRect(const QRectF& baseRect, double outerRadius, QRectF& innerRect, double& innerRadius);
virtual void drawInnerBackground(QPainter& p, const QRectF& innerRect);
virtual void drawText(QPainter& p, const QRectF& innerRect, double innerRadius, double value);
virtual QString valueToText(double value) const;
virtual void valueFormatChanged();
virtual QSize minimumSizeHint() const { return QSize(32,32); }
virtual bool hasHeightForWidth() const { return true; }
virtual int heightForWidth(int w) const { return w; }
void rebuildDataBrushIfNeeded();
double m_min, m_max;
double m_value;
double m_nullPosition;
BarStyle m_barStyle;
double m_outlinePenWidth, m_dataPenWidth;
QGradientStops m_gradientData;
bool m_rebuildBrush;
QString m_format;
int m_decimals;
static const int UF_VALUE = 1;
static const int UF_PERCENT = 2;
static const int UF_MAX = 4;
int m_updateFlags;
};
#endif // QROUNDPROGRESSBAR_H
================================================
FILE: libs/3dparty/flowlayout.cpp
================================================
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
#include "flowlayout.h"
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
: m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::~FlowLayout()
{
clear();
}
void FlowLayout::clear()
{
QLayoutItem *item;
while ((item = takeAt(0)))
delete item;
}
void FlowLayout::addItem(QLayoutItem *item)
{
itemList.append(item);
}
int FlowLayout::horizontalSpacing() const
{
if (m_hSpace >= 0) {
return m_hSpace;
} else {
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
}
}
int FlowLayout::verticalSpacing() const
{
if (m_vSpace >= 0) {
return m_vSpace;
} else {
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
}
}
int FlowLayout::count() const
{
return itemList.size();
}
QLayoutItem *FlowLayout::itemAt(int index) const
{
return itemList.value(index);
}
QLayoutItem *FlowLayout::takeAt(int index)
{
if (index >= 0 && index < itemList.size())
return itemList.takeAt(index);
else
return 0;
}
Qt::Orientations FlowLayout::expandingDirections() const
{
return 0;
}
bool FlowLayout::hasHeightForWidth() const
{
return true;
}
int FlowLayout::heightForWidth(int width) const
{
int height = doLayout(QRect(0, 0, width, 0), true);
return height;
}
void FlowLayout::setGeometry(const QRect &rect)
{
QLayout::setGeometry(rect);
doLayout(rect, false);
}
QSize FlowLayout::sizeHint() const
{
return minimumSize();
}
QSize FlowLayout::minimumSize() const
{
QSize size;
QLayoutItem *item;
foreach (item, itemList)
size = size.expandedTo(item->minimumSize());
size += QSize(2*margin(), 2*margin());
return size;
}
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
int left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
int x = effectiveRect.x();
int y = effectiveRect.y();
int lineHeight = 0;
QLayoutItem *item;
foreach (item, itemList) {
QWidget *wid = item->widget();
int spaceX = horizontalSpacing();
if (spaceX == -1)
spaceX = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
int spaceY = verticalSpacing();
if (spaceY == -1)
spaceY = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
int nextX = x + item->sizeHint().width() + spaceX;
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
x = effectiveRect.x();
y = y + lineHeight + spaceY;
nextX = x + item->sizeHint().width() + spaceX;
lineHeight = 0;
}
if (!testOnly)
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
}
return y + lineHeight - rect.y() + bottom;
}
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
{
QObject *parent = this->parent();
if (!parent) {
return -1;
} else if (parent->isWidgetType()) {
QWidget *pw = static_cast(parent);
return pw->style()->pixelMetric(pm, 0, pw);
} else {
return static_cast(parent)->spacing();
}
}
================================================
FILE: libs/3dparty/flowlayout.h
================================================
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef FLOWLAYOUT_H
#define FLOWLAYOUT_H
#include
#include
#include
#include "3dparty_global.h"
class THIRDPARTY_EXPORT FlowLayout : public QLayout
{
public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void clear();
void addItem(QLayoutItem *item) Q_DECL_OVERRIDE;
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
bool hasHeightForWidth() const Q_DECL_OVERRIDE;
int heightForWidth(int) const Q_DECL_OVERRIDE;
int count() const Q_DECL_OVERRIDE;
QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE;
QSize minimumSize() const Q_DECL_OVERRIDE;
void setGeometry(const QRect &rect) Q_DECL_OVERRIDE;
QSize sizeHint() const Q_DECL_OVERRIDE;
QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE;
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList itemList;
int m_hSpace;
int m_vSpace;
};
#endif // FLOWLAYOUT_H
================================================
FILE: libs/libs.pro
================================================
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
utils \
vtkutils \
widgets \
3dparty
================================================
FILE: libs/utils/colorseries.cpp
================================================
#include "colorseries.h"
namespace Utils
{
typedef QList ColorList;
static inline QColor hexToColor(QRgb num)
{
return QColor(qRed(num), qGreen(num), qBlue(num));
}
class ColorSeriesPrivate
{
public:
static ColorList sSpectrumColorList;
static ColorList sWarmColorList;
static ColorList sCoolColorList;
static ColorList sBluesColorList;
static ColorList sWildFlowerColorList;
static ColorList sCitrusColorList;
ColorSeries::Scheme currentScheme = ColorSeries::Warm;
int colorCounter = 0;
};
ColorList ColorSeriesPrivate::sSpectrumColorList = ColorList()
<< QColor::fromRgb(0x000000) << QColor::fromRgb(0xE41A1C) << QColor::fromRgb(0x377EB8)
<< QColor::fromRgb(0x4DAF4A) << QColor::fromRgb(0x984EA3) << QColor::fromRgb(0xFF7F00) << QColor::fromRgb(0xA65628);
ColorList ColorSeriesPrivate::sWarmColorList = ColorList()
<< QColor::fromRgb(0x791717) << QColor::fromRgb(0xB50101) << QColor::fromRgb(0xEF4719)
<< QColor::fromRgb(0xF98324) << QColor::fromRgb(0xFFB400) << QColor::fromRgb(0xFFE506);
ColorList ColorSeriesPrivate::sCoolColorList = ColorList()
<< QColor::fromRgb(0x75B101) << QColor::fromRgb(0x588029) << QColor::fromRgb(0x50D7BF)
<< QColor::fromRgb(0x1C95CD) << QColor::fromRgb(0x3B68AB) << QColor::fromRgb(0x9A68FF) << QColor::fromRgb(0x5F3380);
ColorList ColorSeriesPrivate::sBluesColorList = ColorList()
<< QColor::fromRgb(0x3B68AB) << QColor::fromRgb(0x1C95CD) << QColor::fromRgb(0x4ED9EA)
<< QColor::fromRgb(0x739AD5) << QColor::fromRgb(0x423DA9) << QColor::fromRgb(0x505487) << QColor::fromRgb(0x102A52);
ColorList ColorSeriesPrivate::sWildFlowerColorList = ColorList()
<< QColor::fromRgb(0x1C95CD) << QColor::fromRgb(0x3B68AB) << QColor::fromRgb(0x663EB7)
<< QColor::fromRgb(0xA254CF) << QColor::fromRgb(0xDE61CE) << QColor::fromRgb(0xDC6195) << QColor::fromRgb(0x3D1052);
ColorList ColorSeriesPrivate::sCitrusColorList = ColorList()
<< QColor::fromRgb(0x657C37) << QColor::fromRgb(0x75B101) << QColor::fromRgb(0xB2BA30)
<< QColor::fromRgb(0xFFE506) << QColor::fromRgb(0xFFB400) << QColor::fromRgb(0xF98324);
ColorSeries::ColorSeries()
{
d_ptr = new ColorSeriesPrivate;
}
ColorSeries::~ColorSeries()
{
delete d_ptr;
}
void ColorSeries::setScheme(ColorSeries::Scheme scheme)
{
if (d_ptr->currentScheme != scheme) {
d_ptr->currentScheme = scheme;
d_ptr->colorCounter = 0;
}
}
ColorSeries::Scheme ColorSeries::scheme() const
{
return d_ptr->currentScheme;
}
QColor ColorSeries::color(int index) const
{
switch (d_ptr->currentScheme) {
case Spectrum:
return d_ptr->sSpectrumColorList.at(index % d_ptr->sSpectrumColorList.size());
case Warm:
return d_ptr->sWarmColorList.at(index % d_ptr->sWarmColorList.size());
case Cool:
return d_ptr->sCoolColorList.at(index % d_ptr->sCoolColorList.size());
case Blues:
return d_ptr->sBluesColorList.at(index % d_ptr->sBluesColorList.size());
case WildFlower:
return d_ptr->sWildFlowerColorList.at(index % d_ptr->sWildFlowerColorList.size());
case Citrus:
return d_ptr->sCitrusColorList.at(index % d_ptr->sCitrusColorList.size());
}
return Qt::black;
}
QColor ColorSeries::nextColor() const
{
return color(d_ptr->colorCounter++);
}
} // namespace Utils
================================================
FILE: libs/utils/colorseries.h
================================================
#ifndef COLORSERIES_H
#define COLORSERIES_H
#include
#include "utils_global.h"
namespace Utils
{
class ColorSeriesPrivate;
class UTILS_EXPORT ColorSeries
{
public:
enum Scheme { Spectrum, Warm, Cool, Blues, WildFlower, Citrus };
ColorSeries();
~ColorSeries();
void setScheme(Scheme scheme);
Scheme scheme() const;
QColor color(int index) const;
QColor nextColor() const;
private:
ColorSeriesPrivate* d_ptr;
Q_DISABLE_COPY(ColorSeries)
};
} // namespace Utils
#endif // COLORSERIES_H
================================================
FILE: libs/utils/doublespinboxdelegate.cpp
================================================
#include "doublespinboxdelegate.h"
#include
namespace Utils
{
DoubleSpinBoxDelegate::DoubleSpinBoxDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
editor->setSingleStep(0.1);
editor->setFrame(false);
editor->setDecimals(2);
editor->setMinimum(-INT_MAX);
editor->setMaximum(INT_MAX);
return editor;
}
void DoubleSpinBoxDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
qreal value = index.model()->data(index, Qt::EditRole).toDouble();
QDoubleSpinBox *spinBox = static_cast(editor);
spinBox->setValue(value);
}
void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QDoubleSpinBox *spinBox = static_cast(editor);
spinBox->interpretText();
qreal value = spinBox->value();
model->setData(index, value, Qt::EditRole);
}
void DoubleSpinBoxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
} // namespace Utils
================================================
FILE: libs/utils/doublespinboxdelegate.h
================================================
#ifndef DOUBLESPINBOXDELEGATE_H
#define DOUBLESPINBOXDELEGATE_H
#include
#include "utils_global.h"
namespace Utils
{
class UTILS_EXPORT DoubleSpinBoxDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
DoubleSpinBoxDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const Q_DECL_OVERRIDE;
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
};
} // namespace Utils
#endif
================================================
FILE: libs/utils/iplugin.h
================================================
#ifndef IPLUGIN_H
#define IPLUGIN_H
#include
namespace Utils {
/*!
* \class IPlugin
* \brief 类 IPlugin 是所有插件的基类.
*
* IPlugin 是一个抽象类, 每一个插件都必须实现它.
*/
class IPlugin
{
public:
virtual ~IPlugin() {}
/*!
* \brief 插件的初始化.
*
* 在这里可以利用动作管理器初始化与插件相关的动作, 快捷键, 菜单等.
* \param arguments 应用启动时带的参数
* \param parent 一般是主窗口对象
* \param errorString 输出参数, 插件初始化出错的描述
* \return 成功初始化返回true, 否则返回false
*/
// virtual bool initialize(const QStringList &arguments, QObject* parent, QString *errorString) = 0;
/*!
* \brief 插件的二次初始化.
*
* 当插件的初始化需花费大量时间时, 可使用二次初始化的方法, 在第一次初始化后, 显示应用的主窗口,
* 然后进行第二次初始化.
* \return 成功初始化返回true, 否则返回false
*/
// virtual bool delayedInitialize() { return false; }
};
}
Q_DECLARE_INTERFACE(Utils::IPlugin, "QVTKDemos.IPlugin")
#endif // IPLUGIN_H
================================================
FILE: libs/utils/ivtkplugin.cpp
================================================
#include "ivtkplugin.h"
namespace Utils
{
IVtkPlugin::IVtkPlugin()
{
}
IVtkPlugin::~IVtkPlugin()
{
}
}
================================================
FILE: libs/utils/ivtkplugin.h
================================================
#ifndef IVTKPLUGIN_H
#define IVTKPLUGIN_H
#include "iplugin.h"
#include "utils_global.h"
namespace Utils
{
class UTILS_EXPORT IVtkPlugin : public IPlugin
{
public:
IVtkPlugin();
virtual ~IVtkPlugin();
virtual QString category() const = 0;
virtual QList examples() const = 0;
virtual QStringList keywords() const = 0;
};
} // namespace Utils
Q_DECLARE_INTERFACE(Utils::IVtkPlugin, "QVTKDemos.IVtkPlugin")
#endif
================================================
FILE: libs/utils/modeltopointsconverter.cpp
================================================
#include "modeltopointsconverter.h"
#include
namespace Utils
{
ModelToPointsConverter::ModelToPointsConverter(TableModel* model) : m_model(model)
{
}
QList ModelToPointsConverter::points() const
{
return m_points;
}
void ModelToPointsConverter::run()
{
if (!m_model) {
qDebug() << "ModelToPointsConverter::run: null model.";
emit finished();
return;
}
int rows = m_model->rowCount();
int cols = m_model->columnCount();
if (cols < 3) {
emit finished();
qDebug() << "ModelToPointsConverter::run: insufficient columns.";
return;
}
for (int i = 0; i < rows; ++i) {
Point3F pot{m_model->data(i, 0), m_model->data(i, 1), m_model->data(i, 2)};
m_points.append(pot);
}
emit finished();
}
} // namespace Utils
================================================
FILE: libs/utils/modeltopointsconverter.h
================================================
#ifndef MODELTOPOINTSCONVERTER_H
#define MODELTOPOINTSCONVERTER_H
#include "signalledrunable.h"
#include "utils.h"
#include "tablemodel.h"
#include "point3f.h"
namespace Utils
{
class UTILS_EXPORT ModelToPointsConverter : public SignalledRunnable
{
Q_OBJECT
public:
explicit ModelToPointsConverter(TableModel* model);
QList points() const;
void run();
private:
TableModel* m_model = nullptr;
QList m_points;
};
} // namespace Utils
#endif // MODELTOPOINTSCONVERTER_H
================================================
FILE: libs/utils/modeltovectorsconverter.cpp
================================================
#include "modeltovectorsconverter.h"
#include "tablemodel.h"
#include
namespace Utils
{
ModelToVectorsConverter::ModelToVectorsConverter(TableModel* model) : m_model(model)
{
}
void ModelToVectorsConverter::run()
{
if (!m_model) {
qDebug() << "ModelToVectorsConverter::run: null model.";
emit finished();
return;
}
int rows = m_model->rowCount();
int cols = m_model->columnCount();
if (cols < 4) {
emit finished();
qDebug() << "ModelToVectorsConverter::run: insufficient columns.";
return;
}
for (int i = 0; i < rows; ++i) {
Vector4F vec{m_model->data(i, 0), m_model->data(i, 1), m_model->data(i, 2), m_model->data(i, 3)};
m_vectors.append(vec);
}
emit finished();
}
QList ModelToVectorsConverter::vectors() const
{
return m_vectors;
}
} // namespace Utils
================================================
FILE: libs/utils/modeltovectorsconverter.h
================================================
#ifndef MODELTOVECTORSCONVERTER_H
#define MODELTOVECTORSCONVERTER_H
#include "signalledrunable.h"
#include "utils.h"
#include "vector4f.h"
namespace Utils
{
class TableModel;
class UTILS_EXPORT ModelToVectorsConverter : public SignalledRunnable
{
Q_OBJECT
public:
ModelToVectorsConverter(TableModel* model);
void run();
QList vectors() const;
private:
QList m_vectors;
TableModel* m_model = nullptr;
};
} // namespace Utils
#endif // MODELTOVECTORSCONVERTER_H
================================================
FILE: libs/utils/point3f.cpp
================================================
#include "point3f.h"
================================================
FILE: libs/utils/point3f.h
================================================
#ifndef POINT3F_H
#define POINT3F_H
#include "utils_global.h"
namespace Utils
{
struct UTILS_EXPORT Point3F
{
qreal x;
qreal y;
qreal z;
} ;
} // namespace Utils
#endif // POINT3F_H
================================================
FILE: libs/utils/pointsreader.cpp
================================================
#include "pointsreader.h"
#include
#include
#include
namespace Utils
{
PointsReader::PointsReader(const QString& file) : m_file(file)
{
}
void PointsReader::run()
{
QFile file(m_file);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << QString("PointsReader::run() : cannot open file \"%1\" for reading.").arg(m_file);
return;
}
QTextStream ts(&file);
QString line;
QStringList parts;
while (!ts.atEnd()) {
line = ts.readLine();
parts = line.split('\t'); // separated by tab
parts.removeAll(QString()); // remove empty strings
if (parts.size() == 3)
m_points.append(Point3F{parts.at(0).toDouble(), parts.at(1).toDouble(), parts.at(2).toDouble()});
}
emit finished();
}
const QList& PointsReader::points() const
{
return m_points;
}
} // namespace Utils
================================================
FILE: libs/utils/pointsreader.h
================================================
#ifndef POINTSREADER_H
#define POINTSREADER_H
#include
#include "signalledrunable.h"
#include "utils.h"
#include "point3f.h"
#include "utils_global.h"
namespace Utils
{
class UTILS_EXPORT PointsReader : public SignalledRunnable
{
Q_OBJECT
public:
explicit PointsReader(const QString& file);
void run();
const QList& points() const;
private:
QString m_file;
QList m_points;
};
} // namespace Utils
#endif // POINTSREADER_H
================================================
FILE: libs/utils/pointstomodelconverter.cpp
================================================
#include "pointstomodelconverter.h"
#include "tablemodel.h"
#include
namespace Utils
{
PointsToModelConverter::PointsToModelConverter(const QList& points, TableModel* model) :
m_points(points), m_model(model)
{
}
void PointsToModelConverter::run()
{
if (!m_model) {
qDebug() << "PointsToModelConverter::run : null model.";
emit finished();
return;
}
m_model->resize(3, m_points.size());
m_model->blockSignals(true);
for (int i = 0; i < m_points.size(); ++i) {
m_model->setData(i, 0, m_points.at(i).x);
m_model->setData(i, 1, m_points.at(i).y);
m_model->setData(i, 2, m_points.at(i).z);
}
m_model->blockSignals(false);
emit finished();
}
} // namespace Utils
================================================
FILE: libs/utils/pointstomodelconverter.h
================================================
#ifndef POINTSTOMODELCONVERTER_H
#define POINTSTOMODELCONVERTER_H
#include
#include
#include "utils.h"
#include "point3f.h"
#include "signalledrunable.h"
#include "utils_global.h"
namespace Utils
{
class TableModel;
class UTILS_EXPORT PointsToModelConverter : public SignalledRunnable
{
Q_OBJECT
public:
PointsToModelConverter(const QList& points, TableModel* model);
void run();
private:
QList m_points;
TableModel* m_model = nullptr;
};
} // namespace Utils
#endif // POINTSTOMODELCONVERTER_H
================================================
FILE: libs/utils/signalblocker.cpp
================================================
#include "signalblocker.h"
namespace Utils
{
SignalBlocker::SignalBlocker(QObject* object)
{
addObject(object);
}
void SignalBlocker::addObject(QObject* object)
{
if (object) {
object->blockSignals(true);
m_objectList.append(object);
}
}
SignalBlocker::~SignalBlocker()
{
foreach (QObject* obj, m_objectList)
obj->blockSignals(false);
}
} // namespace Utils
================================================
FILE: libs/utils/signalblocker.h
================================================
#ifndef SIGNALBLOCKER_H
#define SIGNALBLOCKER_H
#include
#include "utils_global.h"
namespace Utils
{
class UTILS_EXPORT SignalBlocker
{
public:
explicit SignalBlocker(QObject* object = nullptr);
~SignalBlocker();
void addObject(QObject* object);
private:
QObjectList m_objectList;
};
} // namespace Utils
#endif // SIGNALBLOCKER_H
================================================
FILE: libs/utils/signalledrunable.cpp
================================================
#include "signalledrunable.h"
namespace Utils
{
SignalledRunnable::SignalledRunnable()
{
}
} // namespace Utils
================================================
FILE: libs/utils/signalledrunable.h
================================================
#ifndef SIGNALLEDRUNNABLE_H
#define SIGNALLEDRUNNABLE_H
#include
#include
#include "utils_global.h"
namespace Utils
{
class UTILS_EXPORT SignalledRunnable : public QObject, public QRunnable
{
Q_OBJECT
public:
SignalledRunnable();
signals:
void finished();
};
} // namespace Utils
#endif // SIGNALLEDRUNABLE_H
================================================
FILE: libs/utils/tablemodel.cpp
================================================
#include "tablemodel.h"
#include "utils.h"
#include
namespace Utils
{
TableModel::TableModel(int column, int row, QObject* parent) : QAbstractTableModel(parent), m_cols(column), m_rows(row)
{
m_cols = column;
m_rows = row;
// m_data
for (int i = 0; i < m_rows; i++) {
QVector* dataVec = new QVector(m_cols);
for (int k = 0; k < dataVec->size(); k++) {
if (k % 2 == 0)
dataVec->replace(k, i * 50 + qrand() % 20);
else
dataVec->replace(k, qrand() % 100);
}
m_data.append(dataVec);
}
}
TableModel::~TableModel()
{
clear();
}
void TableModel::random(int min, int max)
{
m_randomMin = min;
m_randomMax = max;
for (int r = 0; r < m_rows; ++r) {
for (int c = 0; c < m_cols; ++c) {
auto vecPtr = m_data[r];
vecPtr->replace(c, Utils::random(m_randomMin, m_randomMax));
}
}
emit layoutChanged();
}
void TableModel::resize(int column, int row)
{
if (m_cols == column && m_rows == row) {
// qDebug() << "TableModel::resize: same cols & rows.";
return;
}
if (m_cols != column)
emit columnsChanged(m_cols, column);
if (m_rows != row)
emit rowsChanged(m_rows, row);
qDeleteAll(m_data);
m_data.clear();
m_cols = column;
m_rows = row;
// m_data
for (int i = 0; i < m_rows; i++) {
QVector* dataVec = new QVector(m_cols);
for (int k = 0; k < dataVec->size(); k++)
dataVec->replace(k, qreal());
m_data.append(dataVec);
}
}
void TableModel::clear()
{
qDeleteAll(m_data);
m_data.clear();
m_rows = 0;
m_cols = 0;
emit layoutChanged();
}
int TableModel::randomMin()
{
return m_randomMin;
}
int TableModel::randomMax()
{
return m_randomMax;
}
void TableModel::setHorizontalHeaderData(const QVariantList& data)
{
if (m_horHeaderData != data) {
m_horHeaderData = data;
emit layoutChanged();
}
}
QVariantList TableModel::horizontalHeaderData() const
{
return m_horHeaderData;
}
void TableModel::setVerticalHeaderData(const QVariantList& data)
{
if (m_verHeaderData != data) {
m_verHeaderData = data;
emit layoutChanged();
}
}
QVariantList TableModel::verticalHeaderData() const
{
return m_verHeaderData;
}
int TableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_rows;
}
int TableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_cols;
}
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
if (!m_horHeaderData.isEmpty() && m_horHeaderData.size() > section)
return m_horHeaderData.at(section);
else
return QString("%1").arg(section + 1);
}
if (orientation == Qt::Vertical) {
if (!m_verHeaderData.isEmpty() && m_verHeaderData.size() > section)
return m_verHeaderData.at(section);
else
return QString("%1").arg(section + 1);
}
}
QVariant TableModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole) {
return m_data[index.row()]->at(index.column());
} else if (role == Qt::EditRole) {
return m_data[index.row()]->at(index.column());
}
return QVariant();
}
qreal TableModel::data(int row, int col) const
{
return m_data[row]->at(col);
}
bool TableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole) {
m_data[index.row()]->replace(index.column(), value.toDouble());
emit dataChanged(index, index);
return true;
}
return false;
}
bool TableModel::setData(int row, int column, const QVariant& value)
{
QModelIndex index = this->createIndex(row, column);
return setData(index, value);
}
Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
{
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
} // namespace Utils
================================================
FILE: libs/utils/tablemodel.h
================================================
#ifndef TABLEMODEL_H
#define TABLEMODEL_H
#include
#include "utils_global.h"
namespace Utils
{
class UTILS_EXPORT TableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit TableModel(int column, int row, QObject* parent = nullptr);
virtual ~TableModel();
void random(int min = -5, int max = 5);
void resize(int column, int row);
void clear();
int randomMin();
int randomMax();
void setHorizontalHeaderData(const QVariantList& data);
QVariantList horizontalHeaderData() const;
void setVerticalHeaderData(const QVariantList& data);
QVariantList verticalHeaderData() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
qreal data(int row, int col) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
bool setData(int row, int column, const QVariant& value);
Qt::ItemFlags flags(const QModelIndex &index) const;
signals:
void rowsChanged(int oldRows, int newRows);
void columnsChanged(int oldCols, int newCols);
private:
QList * > m_data;
QVariantList m_horHeaderData;
QVariantList m_verHeaderData;
int m_cols = 3;
int m_rows = 30;
int m_randomMin = -1;
int m_randomMax = 1;
};
} // namespace Utils
#endif // TABLEMODEL_H
================================================
FILE: libs/utils/utils.cpp
================================================
#include "utils.h"
#include
#include
const float Pi = 3.14159f;
namespace Utils
{
QString character(int index)
{
char baseChar = 'x';
QString strChar = QString("%1").arg((char)(baseChar + index % 26));
return strChar;
}
void explorer(const QString &path)
{
#ifdef Q_OS_WIN
QString tmpPath(path);
QStringList params;
params << "/select," << tmpPath.replace("/", "\\");
QProcess::startDetached("explorer.exe", params);
#endif
}
QImage star(const QSize& size)
{
QPainterPath starPath;
starPath.moveTo(30, 15);
for (int i = 1; i < 5; ++i) {
starPath.lineTo(15 + 15 * qCos(0.8 * i * Pi),
15 + 15 * qSin(0.8 * i * Pi));
}
starPath.closeSubpath();
QImage star(size, QImage::Format_ARGB32);
star.fill(Qt::transparent);
QPainter painter(&star);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(QRgb(0xf6a625));
painter.setBrush(painter.pen().color());
painter.drawPath(starPath);
return star;
}
double random(int low, int high)
{
double f = (double)qrand() / RAND_MAX;
return f * (high - low) + low;
}
void vtkColor(const QColor& clr, double* vtkClr)
{
double r = (double)clr.red() / 255;
double g = (double)clr.green() / 255;
double b = (double)clr.blue() / 255;
vtkClr[0] = r;
vtkClr[1] = g;
vtkClr[2] = b;
}
QColor qColor(double* pClr)
{
return QColor(pClr[0] * 255, pClr[1] * 255, pClr[2] * 255);
}
static void RGB2HSV(float r, float g, float b, float *h, float *s, float *v )
{
float min, max, delta;
min = qMin(r, qMin(g, b));
max = qMax(r, qMax(g, b));
*v = max; // v
delta = max - min;
if(max != 0) {
*s = delta / max; // s
} else {
// r = g = b = 0 // s = 0, v is undefined
*s = 0;
*h = -1;
return;
}
if( r == max )
*h = ( g - b ) / delta; // between yellow & magenta
else if( g == max )
*h = 2 + ( b - r ) / delta; // between cyan & yellow
else
*h = 4 + ( r - g ) / delta; // between magenta & cyan
*h *= 60; // degrees
if( *h < 0 )
*h += 360;
}
void qColor2HSV(const QColor& clr, double* hsv)
{
double clrArr[3];
vtkColor(clr, clrArr);
float h, s, v;
RGB2HSV(clrArr[0], clrArr[1], clrArr[2], &h, &s, &v);
hsv[0] = (float) h / 360;
hsv[1] = s;
hsv[2] = v;
}
}
================================================
FILE: libs/utils/utils.h
================================================
#ifndef UTILS_H
#define UTILS_H
#include
#include
#include
#include
#include "utils_global.h"
class vtkActor;
namespace Utils
{
// alphabetical char
QString UTILS_EXPORT character(int index);
void UTILS_EXPORT explorer(const QString& path);
QImage UTILS_EXPORT star(const QSize& size = QSize(30, 30));
// declare some util functions
double UTILS_EXPORT random(int low, int high);
template
inline static std::complex random(int low, int high)
{
std::complex c(random(low, high), random(low, high));
return c;
}
// convert QColor to double[3] clr
void UTILS_EXPORT vtkColor(const QColor& clr, double* vtkClr);
QColor UTILS_EXPORT qColor(double* pClr);
void UTILS_EXPORT qColor2HSV(const QColor& clr, double* hsv);
template
class ArrayComparator
{
public:
bool operator()(const T* lhs, const T* rhs)
{
for (auto i = 0; i < size; ++i) {
if (lhs[i] != rhs[i])
return false;
}
return true;
}
};
template
class ArrayAssigner
{
public:
void operator()(T* lhs, const T* rhs)
{
for (auto i = 0; i < size; ++i)
lhs[i] = rhs[i];
}
};
template
class ArrayInitializer
{
public:
void operator()(T* array, T value = T())
{
for (auto i = 0; i < size; ++i)
array[i] = value;
}
};
class Normalizer
{
public:
void operator()(const double* input, double* output)
{
double mod = qSqrt(input[0] * input[0] +
input[1] * input[1] +
input[2] * input[2]);
if (mod == 0) {
output[0] = input[0];
output[1] = input[1];
output[2] = input[2];
} else {
output[0] = input[0] / mod;
output[1] = input[1] / mod;
output[2] = input[2] / mod;
}
}
};
typedef QList ActorList;
template
inline void vtkSafeDelete(T* obj)
{
if (obj)
obj->Delete();
}
template
inline void vtkSafeDelete(QList& objList)
{
foreach (T* obj, objList)
obj->Delete();
objList.clear();
}
template
inline T boundedValue(const T& value, const T& min, const T& max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}
template
static inline double module(T* vector)
{
return qSqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);
}
template
static inline double distance(T* pot1, T* pot2)
{
double dX = pot2[0] - pot1[0];
double dY = pot2[1] - pot1[1];
double dZ = pot2[2] - pot1[2];
return qSqrt(dX * dX + dY * dY + dZ * dZ);
}
/*!
* \brief 求两点的法向量.
*/
template
static inline void normal(T* inPot1, T* inPot2, T* outPot)
{
outPot[0] = -(inPot2[1] - inPot1[1]);
outPot[1] = inPot2[0] - inPot1[0];
outPot[2] = inPot1[2];
}
} // namespace Utils
#endif
================================================
FILE: libs/utils/utils.pri
================================================
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
DEFINES += UTILS_LIBRARY
HEADERS += $$PWD/utils_global.h \
$$PWD/doublespinboxdelegate.h\
$$PWD/tablemodel.h \
$$PWD/utils.h \
SOURCES += $$PWD/doublespinboxdelegate.cpp \
$$PWD/tablemodel.cpp \
================================================
FILE: libs/utils/utils.pro
================================================
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
include(../../lib.pri)
DEFINES += UTILS_LIBRARY
HEADERS += utils_global.h \
doublespinboxdelegate.h\
tablemodel.h \
utils.h \
iplugin.h \
ivtkplugin.h \
pointsreader.h \
pointstomodelconverter.h \
signalledrunable.h \
modeltopointsconverter.h \
modeltovectorsconverter.h \
signalblocker.h \
colorseries.h \
point3f.h \
vector4f.h \
SOURCES += doublespinboxdelegate.cpp \
tablemodel.cpp \
ivtkplugin.cpp \
utils.cpp \
pointsreader.cpp \
pointstomodelconverter.cpp \
signalledrunable.cpp \
modeltopointsconverter.cpp \
modeltovectorsconverter.cpp \
signalblocker.cpp \
colorseries.cpp \
point3f.cpp \
vector4f.cpp \
================================================
FILE: libs/utils/utils_dependencies.pri
================================================
LIB_NAME = utils
LIB_DEPENDS +=
================================================
FILE: libs/utils/utils_global.h
================================================
#ifndef UTILS_GLOBAL_H
#define UTILS_GLOBAL_H
#include
#if defined(UTILS_LIBRARY)
# define UTILS_EXPORT Q_DECL_EXPORT
#else
# define UTILS_EXPORT Q_DECL_IMPORT
#endif
#endif // UTILS_GLOBAL_H
================================================
FILE: libs/utils/vector4f.cpp
================================================
#include "vector4f.h"
================================================
FILE: libs/utils/vector4f.h
================================================
#ifndef VECTOR4F_H
#define VECTOR4F_H
#include "utils_global.h"
namespace Utils
{
struct UTILS_EXPORT Vector4F
{
qreal x;
qreal y;
qreal z;
qreal v;
};
} // namespace Utils
#endif // VECTOR4F_H
================================================
FILE: libs/vtkutils/abstractimageprocessor.cpp
================================================
#include "abstractimageprocessor.h"
namespace VtkUtils
{
AbstractImageProcessor::AbstractImageProcessor()
{
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/abstractimageprocessor.h
================================================
#ifndef ABSTRACTIMAGEPROCESSOR_H
#define ABSTRACTIMAGEPROCESSOR_H
#include "vtkutils_global.h"
#include
#include
#include
#include
namespace VtkUtils
{
class VTKUTILS_EXPORT AbstractImageProcessor : public Utils::SignalledRunnable
{
public:
AbstractImageProcessor();
void setInputData(vtkImageData* input) { m_imageData = input; }
vtkImageData* inputData() const { return m_imageData; }
protected:
vtkImageData* m_imageData = nullptr;
};
template
class ImageProcessorTempl : public AbstractImageProcessor
{
public:
ImageProcessorTempl()
{
m_algorithm = T::New();
}
T* algorithm() const { return m_algorithm; }
void run()
{
if (!m_imageData) {
emit finished();
return;
}
m_algorithm->SetInputData(m_imageData);
m_algorithm->Update();
emit finished();
}
protected:
T* m_algorithm = nullptr;
};
} // namespace VtkUtils
#endif // ABSTRACTIMAGEPROCESSOR_H
================================================
FILE: libs/vtkutils/abstractwidgetobserver.cpp
================================================
#include "abstractwidgetobserver.h"
#include
namespace VtkUtils
{
AbstractWidgetObserver::AbstractWidgetObserver(QObject *parent) : QObject(parent)
{
}
AbstractWidgetObserver::~AbstractWidgetObserver()
{
}
void AbstractWidgetObserver::attach(vtkInteractorObserver *widget)
{
if (widget && widget != m_widget) {
m_widget = widget;
// we only care about this specific event
m_widget->AddObserver(vtkCommand::EndInteractionEvent, this);
}
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/abstractwidgetobserver.h
================================================
#ifndef ABSTRACTWIDGETOBSERVER_H
#define ABSTRACTWIDGETOBSERVER_H
#include
#include
#include "vtkutils_global.h"
class vtkInteractorObserver;
namespace VtkUtils
{
class VTKUTILS_EXPORT AbstractWidgetObserver : public QObject, public vtkCommand
{
Q_OBJECT
public:
explicit AbstractWidgetObserver(QObject *parent = 0);
virtual ~AbstractWidgetObserver();
void attach(vtkInteractorObserver* widget);
protected:
virtual void Execute(vtkObject *caller, unsigned long eventId, void* callData) = 0;
protected:
vtkInteractorObserver* m_widget = nullptr;
};
} // namespace VtkUtils
#endif // ABSTRACTWIDGETOBSERVER_H
================================================
FILE: libs/vtkutils/actorexporter.cpp
================================================
#include "actorexporter.h"
#include "vtkutils.h"
#include
#include
#include
#include
namespace VtkUtils
{
ActorExporter::ActorExporter(vtkActor* actor, const QString& file) : m_actor(actor), m_exportFile(file)
{
setAutoDelete(true);
}
void ActorExporter::run()
{
if (!m_actor || m_exportFile.isEmpty())
return;
VTK_CREATE(vtkRenderWindow, renderWindow);
VTK_CREATE(vtkRenderer, renderer);
renderer->AddActor(m_actor);
renderWindow->AddRenderer(renderer);
VTK_CREATE(vtkVRMLExporter, exporter);
exporter->SetFileName(m_exportFile.toUtf8().data());
exporter->SetRenderWindow(renderWindow);
exporter->Write();
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/actorexporter.h
================================================
#ifndef ACTOREXPORTER_H
#define ACTOREXPORTER_H
#include
#include
#include "vtkutils_global.h"
class vtkActor;
namespace VtkUtils
{
class VTKUTILS_EXPORT ActorExporter : public QRunnable
{
public:
ActorExporter(vtkActor* actor, const QString& file);
void run();
protected:
vtkActor* m_actor = nullptr;
QString m_exportFile;
};
} // namespace VtkUtils
#endif // ACTOREXPORTER_H
================================================
FILE: libs/vtkutils/anglewidgetobserver.cpp
================================================
#include "anglewidgetobserver.h"
#include
#include
#include
namespace VtkUtils
{
AngleWidgetObserver::AngleWidgetObserver(QObject* parent) : AbstractWidgetObserver(parent)
{
}
void AngleWidgetObserver::Execute(vtkObject *caller, unsigned long eventId, void* callData)
{
Q_UNUSED(eventId)
Q_UNUSED(callData)
vtkAngleWidget* widget = reinterpret_cast(caller);
if (widget) {
vtkAngleRepresentation* angleRep = vtkAngleRepresentation::SafeDownCast(widget->GetRepresentation());
double worldPot1[3];
double worldPot2[3];
double worldCenter[3];
double displayPot1[3];
double displayPot2[3];
double displayCenter[3];
angleRep->GetPoint1WorldPosition(worldPot1);
angleRep->GetPoint2WorldPosition(worldPot2);
angleRep->GetCenterWorldPosition(worldCenter);
angleRep->GetPoint1DisplayPosition(displayPot1);
angleRep->GetPoint2DisplayPosition(displayPot2);
angleRep->GetCenterDisplayPosition(displayCenter);
emit angleChanged(angleRep->GetAngle());
emit worldPoint1Changed(worldPot1);
emit worldPoint2Changed(worldPot2);
emit worldCenterChanged(worldCenter);
emit displayPoint1Changed(displayPot1);
emit displayPoint2Changed(displayPot2);
emit displayCenterChanged(displayCenter);
}
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/anglewidgetobserver.h
================================================
#ifndef ANGLEWIDGETOBSERVER_H
#define ANGLEWIDGETOBSERVER_H
#include "abstractwidgetobserver.h"
namespace VtkUtils
{
class VTKUTILS_EXPORT AngleWidgetObserver : public AbstractWidgetObserver
{
Q_OBJECT
public:
explicit AngleWidgetObserver(QObject* parent = nullptr);
signals:
void angleChanged(double angle);
void worldPoint1Changed(double* pos);
void worldPoint2Changed(double* pos);
void worldCenterChanged(double* pos);
void displayPoint1Changed(double* pos);
void displayPoint2Changed(double* pos);
void displayCenterChanged(double* pos);
protected:
void Execute(vtkObject *caller, unsigned long eventId, void* callData);
};
} // namespace VtkUtils
#endif // ANGLEWIDGETOBSERVER_H
================================================
FILE: libs/vtkutils/boxcutter.cpp
================================================
#include "boxcutter.h"
class BoxCutterPrivate
{
public:
};
BoxCutter::BoxCutter(QObject* parent) : Interactor(parent)
{
d_ptr = new BoxCutterPrivate;
}
BoxCutter::~BoxCutter()
{
delete d_ptr;
}
void BoxCutter::attach(ComDataGui3D::PostProcessor* pp)
{
if (!pp)
return;
Interactor::attach(pp);
}
void BoxCutter::detach()
{
}
void BoxCutter::update()
{
}
int BoxCutter::type() const
{
return BOXCUTTER;
}
void BoxCutter::setVisible(bool visible)
{
}
bool BoxCutter::isVisible() const
{
return Interactor::isVisible();
}
void BoxCutter::setSpecialInteractorStyle()
{
}
================================================
FILE: libs/vtkutils/boxcutter.h
================================================
#ifndef BOXCUTTER_H
#define BOXCUTTER_H
#include "interactor.h"
class BoxCutterPrivate;
class BoxCutter : public Interactor
{
Q_OBJECT
public:
explicit BoxCutter(QObject* parent = nullptr);
~BoxCutter();
void attach(ComDataGui3D::PostProcessor* pp);
void detach();
void update();
int type() const;
void setVisible(bool visible);
bool isVisible() const;
protected:
void setSpecialInteractorStyle();
private:
BoxCutterPrivate* d_ptr;
Q_DISABLE_COPY(BoxCutter)
};
#endif // BOXCUTTER_H
================================================
FILE: libs/vtkutils/boxwidgetobserver.cpp
================================================
#include "boxwidgetobserver.h"
#include
#include
namespace VtkUtils
{
BoxWidgetObserver::BoxWidgetObserver(QObject* parent) : AbstractWidgetObserver(parent)
{
m_planes = vtkPlanes::New();
}
void BoxWidgetObserver::Execute(vtkObject *caller, unsigned long eventId, void* callData)
{
Q_UNUSED(eventId)
Q_UNUSED(callData)
vtkBoxWidget* widget = reinterpret_cast(caller);
if (widget) {
widget->GetPlanes(m_planes);
emit planesChanged(m_planes);
}
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/boxwidgetobserver.h
================================================
#ifndef BOXWIDGETOBSERVER_H
#define BOXWIDGETOBSERVER_H
#include "abstractwidgetobserver.h"
#include
class vtkPlanes;
namespace VtkUtils
{
class VTKUTILS_EXPORT BoxWidgetObserver : public AbstractWidgetObserver
{
Q_OBJECT
public:
explicit BoxWidgetObserver(QObject* parent = nullptr);
signals:
void planesChanged(vtkPlanes* planes);
protected:
void Execute(vtkObject *caller, unsigned long eventId, void* callData);
vtkSmartPointer m_planes;
};
} // namespace VtkUtils
#endif // BOXWIDGETOBSERVER_H
================================================
FILE: libs/vtkutils/contour.cpp
================================================
#include "contour.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace VtkUtils
{
class ContourPrivate
{
public:
QList vectors;
int numberOfContours = 10;
vtkActor* planeActor = nullptr;
vtkContourFilter* contour = nullptr;
};
Contour::Contour(QWidget* parent) : Surface(parent)
{
d_ptr = new ContourPrivate;
}
Contour::~Contour()
{
delete d_ptr;
}
void Contour::setVectors(const QList& vectors)
{
if (vectors.isEmpty())
return;
d_ptr->vectors = vectors;
renderSurface();
}
void Contour::setNumberOfContours(int num)
{
if (d_ptr->numberOfContours != num) {
d_ptr->numberOfContours = num;
if (d_ptr->contour)
d_ptr->contour->GenerateValues(d_ptr->numberOfContours, zMin(), zMax());
}
}
int Contour::numberOfContours() const
{
return d_ptr->numberOfContours;
}
void Contour::setPlaneVisible(bool visible)
{
}
bool Contour::planeVisible() const
{
return false;
}
void Contour::setPlaneDistance(qreal distance)
{
}
bool Contour::planeDistance() const
{
return .0;
}
void Contour::renderSurface()
{
VTK_CREATE(vtkPoints, vtkpoints);
VTK_CREATE(vtkDoubleArray, scalars);
foreach (const Utils::Vector4F& vec, d_ptr->vectors) {
vtkpoints->InsertNextPoint(vec.x, vec.y, vec.z);
scalars->InsertNextTuple1(vec.z);
}
VTK_CREATE(vtkPolyData, polydata);
polydata->SetPoints(vtkpoints);
polydata->GetPointData()->SetScalars(scalars);
double bounds[6];
polydata->GetBounds(bounds);
setBounds(bounds);
VTK_CREATE(vtkDelaunay2D, del);
del->SetInputData(polydata);
del->Update();
// VTK_CREATE(vtkContourFilter, contour);
// contour->SetInputConnection(del->GetOutputPort());
// contour->GenerateValues(10, bounds[4], bounds[5]);
vtkLookupTable* lookupTable = vtkLookupTable::New();
lookupTable->SetTableRange(bounds[4], bounds[5]);
lookupTable->SetHueRange(0.667, 0.0);
lookupTable->Build();
VTK_CREATE(vtkPolyDataMapper, mapper);
mapper->SetInputConnection(del->GetOutputPort());
mapper->SetLookupTable(lookupTable);
surfaceActor()->SetMapper(mapper);
defaultRenderer()->AddActor(surfaceActor());
update();
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/contour.h
================================================
#ifndef CONTOUR_H
#define CONTOUR_H
#include "surface.h"
#include
namespace VtkUtils
{
class ContourPrivate;
class VTKUTILS_EXPORT Contour : public Surface
{
Q_OBJECT
public:
explicit Contour(QWidget* parent = nullptr);
~Contour();
void setVectors(const QList& vectors);
void setNumberOfContours(int num);
int numberOfContours() const;
void setPlaneVisible(bool visible = true);
bool planeVisible() const;
void setPlaneDistance(qreal distance);
bool planeDistance() const;
protected:
void renderSurface();
private:
ContourPrivate* d_ptr;
Q_DISABLE_COPY(Contour)
};
} // namespace VtkUtils
#endif // CONTOUR_H
================================================
FILE: libs/vtkutils/contourwidgetobserver.cpp
================================================
#include "contourwidgetobserver.h"
#include
#include
#include
namespace VtkUtils
{
ContourWidgetObserver::ContourWidgetObserver(QObject* parent) : AbstractWidgetObserver(parent)
{
m_polyData = vtkSmartPointer::New();
}
void ContourWidgetObserver::Execute(vtkObject *caller, unsigned long eventId, void* callData)
{
Q_UNUSED(eventId)
Q_UNUSED(callData)
vtkContourWidget* widget = reinterpret_cast(caller);
if (widget) {
vtkContourRepresentation* rep = vtkContourRepresentation::SafeDownCast(widget->GetRepresentation());
vtkPolyData* pd = rep->GetContourRepresentationAsPolyData();
if (pd) {
m_polyData->DeepCopy(pd);
emit dataChanged(m_polyData);
}
}
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/contourwidgetobserver.h
================================================
#ifndef CONTOURWIDGETOBSERVER_H
#define CONTOURWIDGETOBSERVER_H
#include "abstractwidgetobserver.h"
#include
class vtkPolyData;
namespace VtkUtils
{
class VTKUTILS_EXPORT ContourWidgetObserver : public AbstractWidgetObserver
{
Q_OBJECT
public:
explicit ContourWidgetObserver(QObject* parent = nullptr);
signals:
void dataChanged(vtkPolyData* data);
protected:
void Execute(vtkObject *caller, unsigned long eventId, void* callData);
vtkSmartPointer m_polyData;
};
} // namespace VtkUtils
#endif // CONTOURWIDGETOBSERVER_H
================================================
FILE: libs/vtkutils/custominteractorstyle.cpp
================================================
#include "custominteractorstyle.h"
#include "../graph3d.h"
#include "util.h"
#include
#include
#include
#include
static const QColor HighlightColor = Qt::red;
static const QColor NormalColor = Qt::white;
CustomInteractorStyle::CustomInteractorStyle()
{
}
CustomInteractorStyle::~CustomInteractorStyle()
{
}
void CustomInteractorStyle::OnLeftButtonDown()
{
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
vtkActor* pickActor = this->pickedActor();
if (pickActor)
m_pickedActor = pickActor;
else
m_pickedActor = nullptr;
}
void CustomInteractorStyle::OnLeftButtonUp()
{
if (m_pickedActor)
emit mouseReleased();
m_pickedActor = nullptr;
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}
void CustomInteractorStyle::Rotate()
{
if (m_pickedActor)
return;
vtkInteractorStyleTrackballCamera::Rotate();
}
void CustomInteractorStyle::Spin()
{
if (m_pickedActor)
return;
vtkInteractorStyleTrackballCamera::Spin();
}
void CustomInteractorStyle::OnMouseMove()
{
vtkInteractorStyleTrackballCamera::OnMouseMove();
notifyHoverActor();
}
void CustomInteractorStyle::OnChar()
{
vtkInteractorStyleTrackballCamera::OnChar();
char ch = this->GetInteractor()->GetKeyCode();
}
void CustomInteractorStyle::setGraph(ComDataGui3D::Graph3D *graph)
{
m_graph = graph;
}
void CustomInteractorStyle::setClickPosition(const QPoint& pos)
{
m_clickPos = pos;
}
void CustomInteractorStyle::setMovePosition(const QPoint& pos)
{
m_movePos = pos;
}
void CustomInteractorStyle::setBounds(double bounds[])
{
ComDataGui3D::detail::ArrayAssigner()(m_bounds, bounds);
}
vtkActor* CustomInteractorStyle::pickedActor()
{
int x = m_clickPos.x();
int y = m_graph->height() - m_clickPos.y();
CREATE_VTKOBJ(vtkCellPicker, picker);
picker->SetTolerance(0.001);
picker->Pick(x, y, 0, GetDefaultRenderer());
return picker->GetActor();
}
vtkActor* CustomInteractorStyle::hoverdActor()
{
int x = m_movePos.x();
int y = m_graph->height() - m_movePos.y();
CREATE_VTKOBJ(vtkCellPicker, picker);
picker->SetTolerance(0.001);
picker->Pick(x, y, 0, GetDefaultRenderer());
return picker->GetActor();
}
void CustomInteractorStyle::setPickingCursor()
{
m_graph->setCursor(QCursor(Qt::PointingHandCursor));
}
void CustomInteractorStyle::resetPickingCursor()
{
m_graph->setCursor(QCursor(Qt::ArrowCursor));
}
double* CustomInteractorStyle::computeBoundedPos(double *pos)
{
double x = pos[0];
double y = pos[1];
double z = pos[2];
m_boundedPos[0] = ComDataGui3D::detail::boundedValue(x, m_bounds[0], m_bounds[1]);
m_boundedPos[1] = ComDataGui3D::detail::boundedValue(y, m_bounds[2], m_bounds[3]);
m_boundedPos[2] = ComDataGui3D::detail::boundedValue(z, m_bounds[4], m_bounds[5]);
return m_boundedPos;
}
void CustomInteractorStyle::addWatchActor(vtkActor *actor)
{
m_watchedActorList.append(actor);
}
void CustomInteractorStyle::notifyHoverActor()
{
vtkActor* hoverActor = this->hoverdActor();
bool find = false;
if (hoverActor) {
foreach (vtkActor* actor, m_watchedActorList) {
if (actor == hoverActor) {
find = true;
setPickingCursor();
highlightActor(actor, true);
}
}
} else {
foreach (vtkActor* actor, m_watchedActorList)
highlightActor(actor, false);
}
if (!find)
resetPickingCursor();
}
void CustomInteractorStyle::highlightActor(vtkActor *actor, bool highlight)
{
if (highlight) {
actor->GetProperty()->SetColor(ComDataGui3D::detail::Util::vtkColor(HighlightColor));
} else {
QColor oClr = ComDataGui3D::detail::Util::oppositeColor(this->m_graph->backgroundColor());
actor->GetProperty()->SetColor(ComDataGui3D::detail::Util::vtkColor(oClr));
}
m_graph->update();
}
================================================
FILE: libs/vtkutils/custominteractorstyle.h
================================================
#ifndef CUSTOMINTERACTORSTYLE_H
#define CUSTOMINTERACTORSTYLE_H
#include
#include
#include
namespace ComDataGui3D
{
class Graph3D;
}
class CustomInteractorStyle : public QObject, public vtkInteractorStyleTrackballCamera
{
Q_OBJECT
public:
virtual void OnLeftButtonDown();
virtual void OnLeftButtonUp();
virtual void Rotate();
virtual void Spin();
virtual void OnMouseMove();
virtual void OnChar();
void setGraph(ComDataGui3D::Graph3D* graph);
public slots:
void setClickPosition(const QPoint& pos);
void setMovePosition(const QPoint& pos);
void setBounds(double bounds[6]);
signals:
void mouseReleased();
protected:
explicit CustomInteractorStyle();
virtual ~CustomInteractorStyle();
vtkActor* pickedActor();
vtkActor* hoverdActor();
void setPickingCursor();
void resetPickingCursor();
double* computeBoundedPos(double* pos);
void addWatchActor(vtkActor* actor);
void notifyHoverActor();
void highlightActor(vtkActor* actor, bool highlight);
protected:
ComDataGui3D::Graph3D* m_graph;
QPoint m_clickPos;
QPoint m_movePos;
vtkActor* m_pickedActor = nullptr;
QList m_watchedActorList;
double m_bounds[6];
double m_boundedPos[3];
};
#endif // CUSTOMINTERACTORSTYLE_H
================================================
FILE: libs/vtkutils/datafilter.cpp
================================================
#include "datafilter.h"
namespace VtkUtils
{
QString VTKUTILS_EXPORT filterName(FilterType type)
{
QString strType;
switch (type) {
case FT_Clip:
strType = QObject::tr("Clip");
break;
case FT_Cut:
strType = QObject::tr("Cut");
break;
case FT_Slice:
strType = QObject::tr("Slice");
break;
case FT_Isosurface:
strType = QObject::tr("Isosurface");
break;
case FT_Threshold:
strType = QObject::tr("Threshold");
break;
case FT_Streamline:
strType = QObject::tr("Streamline");
break;
case FT_Smooth:
strType = QObject::tr("Smooth");
break;
case FT_Decimate:
strType = QObject::tr("Decimate");
break;
default:
strType = "none";
}
return strType;
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/datafilter.h
================================================
#ifndef DATAFILTER_H
#define DATAFILTER_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "vtkutils_global.h"
namespace VtkUtils
{
enum FilterType { FT_Clip, FT_Cut, FT_Slice, FT_Isosurface,
FT_Threshold, FT_Streamline, FT_Smooth, FT_Decimate, FT_Count };
QString VTKUTILS_EXPORT filterName(FilterType type);
class VTKUTILS_EXPORT AbstractDataFilter : public Utils::SignalledRunnable
{
public:
AbstractDataFilter() {}
virtual ~AbstractDataFilter() {}
};
template
class DataFilter : public AbstractDataFilter
{
public:
DataFilter()
{
m_filter = Filter::New();
}
virtual void run()
{
m_filter->SetInputData(m_inputData);
m_filter->Update();
emit finished();
}
virtual void setInput(InputDataObject* input)
{
m_inputData = input;
}
OutputDataObject* output() const
{
return m_filter->GetOutput();
}
Filter* filter() const
{
return m_filter;
}
protected:
vtkSmartPointer m_filter;
InputDataObject* m_inputData;
};
class VTKUTILS_EXPORT ClipFilter : public DataFilter {};
class VTKUTILS_EXPORT CutterFilter : public DataFilter {};
class VTKUTILS_EXPORT SliceFilter : public DataFilter {};
class VTKUTILS_EXPORT DecimateProFilter : public DataFilter {};
class VTKUTILS_EXPORT SmoothFilter : public DataFilter {};
class VTKUTILS_EXPORT StreamTracerFilter : public DataFilter {};
class VTKUTILS_EXPORT IsosurfaceFilter : public DataFilter {};
class VTKUTILS_EXPORT ExtractEdgesFilter : public DataFilter {};
class VTKUTILS_EXPORT TubeFilter : public DataFilter {};
class VTKUTILS_EXPORT Delaunay2DFilter : public DataFilter {};
class VTKUTILS_EXPORT Glyph3DFilter : public DataFilter {};
class VTKUTILS_EXPORT RuledSurfaceFilter : public DataFilter {};
class VTKUTILS_EXPORT VertexGlyphFilter : public DataFilter {};
} // namespace VtkUtils
#endif // DATAFILTER_H
================================================
FILE: libs/vtkutils/disablerotationinteractorstyle.cpp
================================================
#include "disablerotationinteractorstyle.h"
#include "../graph3d.h"
#include "util.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace ComDataGui3D;
static const int HoverWidth = 7;
static const int NormalWidth = 5;
static const QColor PlaneHighlightColor = QColor(87, 87, 87);
static const QColor PlaneNormalColor = Qt::white;
static const QColor StickColor = QColor(233, 233, 233);
static const QColor HighlightStickColor = QColor(255, 0, 0);
vtkStandardNewMacro(DisableRotationInteractorStyle);
DisableRotationInteractorStyle::DisableRotationInteractorStyle()
{
ComDataGui3D::detail::ArrayInitializer()(m_topPoint);
ComDataGui3D::detail::ArrayInitializer()(m_bottomPoint);
}
DisableRotationInteractorStyle::~DisableRotationInteractorStyle()
{
}
void DisableRotationInteractorStyle::OnLeftButtonUp()
{
CustomInteractorStyle::OnLeftButtonUp();
notifySpherePosChanged();
m_pickedActor = nullptr;
resetActors();
resetPickingCursor();
if (m_isDirty) {
m_isDirty = false;
emit update();
}
}
void DisableRotationInteractorStyle::OnMouseMove()
{
CustomInteractorStyle::OnMouseMove();
int x = m_movePos.x();
int y = m_graph->height() - m_movePos.y();
if (!m_pickedActor) {
highlightActor();
} else {
m_isDirty = true;
setPickingCursor();
CREATE_VTKOBJ(vtkPointPicker, picker);
picker->Pick(x, y, 0, GetDefaultRenderer());
double* pickPos = picker->GetPickPosition();
if (m_pickedActor == m_planeActor || m_pickedActor == m_frameActor) {
emit planeChanged(computeBoundedPos(pickPos));
} else if (m_pickedActor == m_originActor) {
highlightOrigin(true);
emit originChanged(pickPos);
} else if (m_pickedActor == m_topBallActor ||
m_pickedActor == m_bottomBallActor ||
m_pickedActor == m_stickActor) {
double topBallDis = ComDataGui3D::detail::distance(m_topPoint, pickPos);
double bottomBallDis = ComDataGui3D::detail::distance(m_bottomPoint, pickPos);
bool nearTopBall = topBallDis <= bottomBallDis;
emit normalChanged(nearTopBall, pickPos);
}
}
}
void DisableRotationInteractorStyle::setCutType(Cutter::CutType ct)
{
m_cutType = ct;
}
void DisableRotationInteractorStyle::setSphereActor(vtkActor *sphere)
{
m_sphereActor = sphere;
}
void DisableRotationInteractorStyle::setPlaneActor(vtkActor* plane)
{
m_planeActor = plane;
}
void DisableRotationInteractorStyle::setFrameActor(vtkActor* frame)
{
m_frameActor = frame;
}
void DisableRotationInteractorStyle::setOriginActor(vtkActor* origin)
{
m_originActor = origin;
}
void DisableRotationInteractorStyle::setTopBallActor(vtkActor* topBall)
{
m_topBallActor = topBall;
}
void DisableRotationInteractorStyle::setBottomBallActor(vtkActor* bottomBall)
{
m_bottomBallActor = bottomBall;
}
void DisableRotationInteractorStyle::setStickActor(vtkActor *stick)
{
m_stickActor = stick;
}
void DisableRotationInteractorStyle::setOrigin(double* origin)
{
ComDataGui3D::detail::ArrayAssigner()(m_origin, origin);
}
void DisableRotationInteractorStyle::setNormal(double* normal)
{
ComDataGui3D::detail::ArrayAssigner()(m_normal, normal);
}
void DisableRotationInteractorStyle::onStickPointsChanged(double *topPot, double *bottomPot)
{
ComDataGui3D::detail::ArrayAssigner()(m_topPoint, topPot);
ComDataGui3D::detail::ArrayAssigner()(m_bottomPoint, bottomPot);
}
void DisableRotationInteractorStyle::resetActors()
{
m_frameActor->GetProperty()->SetLineWidth(NormalWidth);
double* clrArr = ComDataGui3D::detail::Util::vtkColor(PlaneNormalColor);
m_planeActor->GetProperty()->SetColor(clrArr);
highlightStick(false);
m_graph->update();
}
void DisableRotationInteractorStyle::highlightStick(bool highlight)
{
double* clrArr = nullptr;
if (highlight)
clrArr = ComDataGui3D::detail::Util::vtkColor(HighlightStickColor);
else
clrArr = ComDataGui3D::detail::Util::vtkColor(StickColor);
m_stickActor->GetProperty()->SetColor(clrArr);
m_topBallActor->GetProperty()->SetColor(clrArr);
m_bottomBallActor->GetProperty()->SetColor(clrArr);
m_originActor->GetProperty()->SetColor(clrArr);
m_graph->update();
}
void DisableRotationInteractorStyle::highlightOrigin(bool highlight)
{
double* clrArr = nullptr;
if (highlight)
clrArr = ComDataGui3D::detail::Util::vtkColor(HighlightStickColor);
else
clrArr = ComDataGui3D::detail::Util::vtkColor(StickColor);
m_originActor->GetProperty()->SetColor(clrArr);
m_graph->update();
}
void DisableRotationInteractorStyle::highlightActor()
{
vtkActor* hoverdActor = this->hoverdActor();
if (hoverdActor == m_planeActor) {
setPickingCursor();
m_planeActor->GetProperty()->SetColor(ComDataGui3D::detail::Util::vtkColor(PlaneHighlightColor));
m_graph->update();
} else if (hoverdActor == m_frameActor) {
setPickingCursor();
m_planeActor->GetProperty()->SetColor(ComDataGui3D::detail::Util::vtkColor(PlaneHighlightColor));
m_graph->update();
} else if (hoverdActor == m_originActor) {
setPickingCursor();
highlightOrigin(true);
} else if (hoverdActor == m_stickActor ||
hoverdActor == m_topBallActor ||
hoverdActor == m_bottomBallActor){
setPickingCursor();
highlightStick(true);
} else if (hoverdActor == m_sphereActor && m_sphereActor && m_sphereActor->GetVisibility()){
setPickingCursor();
} else {
resetActors();
resetPickingCursor();
}
}
void DisableRotationInteractorStyle::notifySpherePosChanged()
{
if (m_sphereActor && m_pickedActor == m_sphereActor && m_sphereActor->GetVisibility()) {
int x = m_movePos.x();
int y = m_graph->height() - m_movePos.y();
CREATE_VTKOBJ(vtkPointPicker, picker);
picker->Pick(x, y, 0, GetDefaultRenderer());
double* pickPos = picker->GetPickPosition();
emit originChanged(pickPos);
}
}
================================================
FILE: libs/vtkutils/disablerotationinteractorstyle.h
================================================
#ifndef DISABLEROTATIONINTERACTORSTYLE_H
#define DISABLEROTATIONINTERACTORSTYLE_H
#include "custominteractorstyle.h"
#include "../cutter.h"
namespace ComDataGui3D
{
class Graph3D;
}
class vtkActor;
class DisableRotationInteractorStyle : public CustomInteractorStyle
{
Q_OBJECT
public:
static DisableRotationInteractorStyle *New();
vtkTypeMacro(DisableRotationInteractorStyle, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonUp();
virtual void OnMouseMove();
void setCutType(ComDataGui3D::Cutter::CutType ct);
void setSphereActor(vtkActor* sphere);
void setPlaneActor(vtkActor* plane);
void setFrameActor(vtkActor* frame);
void setOriginActor(vtkActor* origin);
void setTopBallActor(vtkActor* topBall);
void setBottomBallActor(vtkActor* bottomBall);
void setStickActor(vtkActor* stick);
public slots:
void setOrigin(double* origin);
void setNormal(double* normal);
void onStickPointsChanged(double* topPot, double* bottomPot);
signals:
void graphMoved();
void originChanged(double* origin);
void planeChanged(double* pos);
void normalChanged(bool positive, double* normal);
void update();
private:
void resetActors();
void highlightStick(bool highlight);
void highlightOrigin(bool highlight);
void highlightActor();
void notifySpherePosChanged();
private:
DisableRotationInteractorStyle();
~DisableRotationInteractorStyle();
ComDataGui3D::Cutter::CutType m_cutType;
bool m_isDirty = false;
vtkActor* m_sphereActor = nullptr;
vtkActor* m_planeActor = nullptr;
vtkActor* m_frameActor = nullptr;
vtkActor* m_originActor = nullptr;
vtkActor* m_stickActor = nullptr;
vtkActor* m_topBallActor = nullptr;
vtkActor* m_bottomBallActor = nullptr;
double m_origin[3];
double m_normal[3];
double m_topPoint[3];
double m_bottomPoint[3];
};
#endif // DISABLEROTATIONINTERACTORSTYLE_H
================================================
FILE: libs/vtkutils/distancewidgetobserver.cpp
================================================
#include "distancewidgetobserver.h"
#include
#include
namespace VtkUtils
{
DistanceWidgetObserver::DistanceWidgetObserver(QObject* parent) : AbstractWidgetObserver(parent)
{
}
void DistanceWidgetObserver::Execute(vtkObject *caller, unsigned long eventId, void* callData)
{
Q_UNUSED(eventId)
Q_UNUSED(callData)
vtkDistanceWidget* widget = reinterpret_cast(caller);
if (widget) {
vtkWidgetRepresentation* rep = widget->GetRepresentation();
vtkDistanceRepresentation* distRep = vtkDistanceRepresentation::SafeDownCast(rep);
if (distRep) {
double worldPot1[3];
double worldPot2[3];
double displayPot1[3];
double displayPot2[3];
distRep->GetPoint1WorldPosition(worldPot1);
distRep->GetPoint2WorldPosition(worldPot2);
distRep->GetPoint1DisplayPosition(displayPot1);
distRep->GetPoint2DisplayPosition(displayPot2);
emit distanceChanged(distRep->GetDistance());
emit worldPoint1Changed(worldPot1);
emit worldPoint2Changed(worldPot2);
emit displayPoint1Changed(displayPot1);
emit displayPoint2Changed(displayPot2);
}
}
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/distancewidgetobserver.h
================================================
#ifndef DISTANCEWIDGETOBSERVER_H
#define DISTANCEWIDGETOBSERVER_H
#include "abstractwidgetobserver.h"
namespace VtkUtils
{
class VTKUTILS_EXPORT DistanceWidgetObserver : public AbstractWidgetObserver
{
Q_OBJECT
public:
explicit DistanceWidgetObserver(QObject* parent = nullptr);
signals:
void distanceChanged(double dist);
void worldPoint1Changed(double* pos);
void worldPoint2Changed(double* pos);
void displayPoint1Changed(double* pos);
void displayPoint2Changed(double* pos);
protected:
void Execute(vtkObject *caller, unsigned long eventId, void* callData);
};
} // namespace VtkUtils
#endif // DISTANCEWIDGETOBSERVER_H
================================================
FILE: libs/vtkutils/filereaderutils.cpp
================================================
#include "filereaderutils.h"
#include "vtkUnstructuredGridRelevantPointsFilter.h"
#include
#include
#include
#define USE_POINT_INDICES_TO_INSERT
#define ALL_LINES -1
#define INVALID_MAT_ID -INT_MAX
#if defined(_WIN32)
// for _strnicmp
#include
#define STRNCASECMP _strnicmp
#else
// for strcasecmp
#include
#define STRNCASECMP strncasecmp
#endif
namespace VtkUtils
{
static float Getf(const char *s)
{
char *ends;
double val = 0.0;
// Check for one of these funky 'NASTRAN exponential format' strings.
// This is where a value like '1.2345e-5' is actually represented in the
// file as '1.2345-5' with the 'e' character missing. It is awkward but
// apparently a NASTRAN standard. I guess the rationale is that given
// an 8 character field width limit, removing the 'e' character gives them
// one additional digit of precision. This logic is basically looking for
// the condition of encountering a sign character, '-' or '+', AFTER having
// seen characters that could represent part of a number. In such a case,
// it MUST be the sign of the exponent.
const char *p = s;
char tmps[32];
char *q = tmps;
bool haveSeenNumChars = false;
while (!haveSeenNumChars || (*p != '-' && *p != '+' && *p != '\0')) {
if ('0' <= *p && *p <= '9' || *p == '.' || *p == '+' || *p == '-')
haveSeenNumChars = true;
*q++ = *p++;
}
if (haveSeenNumChars && (*p == '-' || *p == '+')) {
*q++ = 'e';
while (*p != '\0')
*q++ = *p++;
*q++ = '\0';
errno = 0;
val = strtod(tmps, &ends);
} else {
errno = 0;
val = strtod(s, &ends);
}
if (errno != 0)
{
qDebug() << "Error occured at " << __FUNCTION__;
return 0.0;
}
return (float) val;
}
// ****************************************************************************
// Function: Geti
//
// Purpose: Robust way of reading string for integer value
//
// Programmer: Mark C. Miller, Thu Apr 3 16:27:01 PDT 2008
//
// Modifications:
// Jeremy Meredith, Thu Aug 7 13:43:03 EDT 2008
// Format %s doesn't use space modifier.
//
// ****************************************************************************
static int Geti(const char *s)
{
char *ends;
errno = 0;
long val = strtol(s, &ends, 10);
if (errno != 0)
{
qDebug() << "Error occured at " << __FUNCTION__;
return 0;
}
return (int) val;
}
AbstractFileReader::AbstractFileReader(QObject *parent) : QObject(parent)
{
}
void AbstractFileReader::setFileName(const QString& file)
{
if (m_fileName != file)
m_fileName = file;
}
QString AbstractFileReader::fileName() const
{
return m_fileName;
}
void AbstractFileReader::setTitle(const QString& title)
{
if (m_title != title)
m_title = title;
}
QString AbstractFileReader::title() const
{
return m_title;
}
VtkFileReader::VtkFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void VtkFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->ReadAllScalarsOn();
m_reader->ReadAllVectorsOn();
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
emit finished();
}
StlFileReader::StlFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void StlFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
emit finished();
}
ObjFileReader::ObjFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void ObjFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
emit finished();
}
DynaFileReader::DynaFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void DynaFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
emit finished();
}
NastranFileReader::NastranFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void NastranFileReader::run()
{
ifstream ifile(fileName().toLocal8Bit());
if (ifile.fail())
return;
// Determine the file size and come up with an estimate of the
// number of vertices and cells so we can size the points and cells.
int nPoints = 100;
int nCells = 100;
int matCountOpt = 0;
#if !defined(MDSERVER)
vtkPoints *pts = vtkPoints::New();
pts->Allocate(nPoints);
#ifdef USE_POINT_INDICES_TO_INSERT
pts->SetNumberOfPoints(nPoints);
#endif
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
ugrid->SetPoints(pts);
ugrid->Allocate(nCells);
pts->Delete();
pts = ugrid->GetPoints();
#endif // if !defined(MDSERVER)
char line[1024];
float pt[3];
vtkIdType verts[8];
bool recognized = false;
bool titleRead = false;
for(int lineIndex = 0; !ifile.eof(); ++lineIndex)
{
int matid = INVALID_MAT_ID;
// Get the line
ifile.getline(line, 1024);
// Determine what the line is for.
if(line[0] == '$' && !recognized)
{
if(!titleRead)
m_title += line;
}
else if(strncmp(line, "GRID*", 5) == 0)
{
recognized = true;
// These GRID* lines need a second line of data. Read it into
// the same buffer at the end.
ifile.getline(line + 72, 1024-72);
#define LONG_FIELD_WIDTH 16
char *valstart = line + 81 - 1;
pt[2] = Getf(valstart);
valstart = line + 72 - LONG_FIELD_WIDTH+1 - 1;
char *valend = line + 72;
*valend = '\0';
pt[1] = Getf(valstart);
valstart -= LONG_FIELD_WIDTH;
valend -= LONG_FIELD_WIDTH;
*valend = '\0';
pt[0] = Getf(valstart);
#ifdef USE_POINT_INDICES_TO_INSERT
valstart -= (2 * LONG_FIELD_WIDTH);
valend -= (2 * LONG_FIELD_WIDTH);
*valend = '\0';
int psi = Geti(valstart)-1;
#if !defined(MDSERVER)
if(psi < nPoints)
pts->SetPoint(psi, pt);
else
{
int newSize = int(float(nPoints) * 1.1f);
if(newSize < psi)
newSize = int(float(psi) * 1.1f);
if(newSize <= nPoints)
newSize = nPoints + 1;
qDebug() << "Resizing point array from " << nPoints
<< " points to " << newSize
<< " points because we need to insert point index "
<< psi << endl;
nPoints = newSize;
pts->GetData()->Resize(nPoints);
pts->SetNumberOfPoints(nPoints);
pts->SetPoint(psi, pt);
}
#endif // if !defined(MDSERVER)
#else
#if !defined(MDSERVER)
pts->InsertNextPoint(pt);
#endif
#endif
}
else if(strncmp(line, "GRID", 4) == 0)
{
recognized = true;
#define SHORT_FIELD_WIDTH 8
char *valstart = line + 48 - SHORT_FIELD_WIDTH;
char *valend = line + 48;
*valend = '\0';
pt[2] = Getf(valstart);
valstart -= SHORT_FIELD_WIDTH;
valend -= SHORT_FIELD_WIDTH;
*valend = '\0';
pt[1] = Getf(valstart);
valstart -= SHORT_FIELD_WIDTH;
valend -= SHORT_FIELD_WIDTH;
*valend = '\0';
pt[0] = Getf(valstart);
#ifdef USE_POINT_INDICES_TO_INSERT
valstart -= (2 * SHORT_FIELD_WIDTH);
valend -= (2 * SHORT_FIELD_WIDTH);
*valend = '\0';
int psi = Geti(valstart)-1;
#if !defined(MDSERVER)
if(psi < nPoints)
pts->SetPoint(psi, pt);
else
{
int newSize = int(float(nPoints) * 1.1f);
if(newSize < psi)
newSize = int(float(psi) * 1.1f);
if(newSize <= nPoints)
newSize = nPoints + 1;
qDebug() << "Resizing point array from " << nPoints
<< " points to " << newSize
<< " points because we need to insert point index "
<< psi << endl;
nPoints = newSize;
pts->GetData()->Resize(nPoints);
pts->SetNumberOfPoints(nPoints);
pts->SetPoint(psi, pt);
}
#endif // if !defined(MDSERVER)
#else
#if !defined(MDSERVER)
pts->InsertNextPoint(pt);
#endif // if !defined(MDSERVER)
#endif
}
else if(strncmp(line, "CHEXA", 5) == 0)
{
#define INDEX_FIELD_WIDTH 8
// CHEXA requires more point indices so read another line.
ifile.getline(line + 72, 1024-72);
char *valstart = line + 88;
char *valend = valstart;
verts[7] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[6] = Geti(valstart)-1;
// Skip the blank
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[5] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[4] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[3] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[2] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
#if !defined(MDSERVER)
ugrid->InsertNextCell(VTK_HEXAHEDRON, 8, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "CTETRA", 6) == 0)
{
char *valstart = line + 48;
char *valend = valstart;
verts[3] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[2] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
#if !defined(MDSERVER)
ugrid->InsertNextCell(VTK_TETRA, 4, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "CPYRAM", 6) == 0)
{
char *valstart = line + 56;
char *valend = valstart;
verts[4] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[3] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[2] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
#if !defined(MDSERVER)
ugrid->InsertNextCell(VTK_PYRAMID, 5, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "CPENTA", 6) == 0)
{
char *valstart = line + 64;
char *valend = valstart;
verts[5] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[4] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[3] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[2] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
//
// http://www.simcenter.msstate.edu/docs/ug_io/3d_grid_file_type_nastran.html
// says that if 5th and 6th nodes are identical, then its really a 5 noded
// pyramid.
//
#if !defined(MDSERVER)
if (verts[4] == verts[5])
ugrid->InsertNextCell(VTK_PYRAMID, 5, verts);
else
ugrid->InsertNextCell(VTK_WEDGE, 6, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "CQUAD4", 6) == 0)
{
char *valstart = line + 48;
char *valend = valstart;
verts[3] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[2] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
#if !defined(MDSERVER)
ugrid->InsertNextCell(VTK_QUAD, 4, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "CTRIA2", 6) == 0 ||
strncmp(line, "CTRIA3", 6) == 0)
{
char *valstart = line + 40;
char *valend = valstart;
verts[2] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
#if !defined(MDSERVER)
ugrid->InsertNextCell(VTK_TRIANGLE, 3, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "CBAR", 4) == 0)
{
char *valstart = line + 32;
char *valend = valstart;
verts[1] = Geti(valstart)-1;
valstart -= INDEX_FIELD_WIDTH;
*valend = '\0';
verts[0] = Geti(valstart)-1;
if (matCountOpt)
{
valstart -= INDEX_FIELD_WIDTH;
valend -= INDEX_FIELD_WIDTH;
*valend = '\0';
matid = Geti(valstart);
}
#if !defined(MDSERVER)
ugrid->InsertNextCell(VTK_LINE, 2, verts);
if (matCountOpt) m_matList.push_back(matid);
#endif
}
else if(strncmp(line, "TITLE", 5) == 0)
{
titleRead = true;
char *ptr = 0;
if((ptr = strstr(line, "=")) != 0)
m_title = /*std::string(*/++ptr/*)*/;
else
m_title = /*std::string(*/line+5/*)*/;
}
else if(strncmp(line, "CEND", 4) == 0 ||
strncmp(line, "BEGIN BULK", 10) == 0 ||
strncmp(line, "NASTRAN", 7) == 0)
{
recognized = true;
}
if (matid != INVALID_MAT_ID)
m_uniqMatIds[matid] = 1;
}
if(recognized) {
vtkUnstructuredGridRelevantPointsFilter *rpf =
vtkUnstructuredGridRelevantPointsFilter::New();
rpf->SetInputData(ugrid);
rpf->Update();
m_dataObject = vtkUnstructuredGrid::New();
m_dataObject->ShallowCopy(rpf->GetOutput());
ugrid->Delete();
rpf->Delete();
}
emit finished();
}
FluentFileReader::FluentFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void FluentFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
vtkUnstructuredGrid* grid = vtkUnstructuredGrid::SafeDownCast(m_reader->GetOutput()->GetBlock(0));
int num = m_reader->GetNumberOfCellArrays();
for (int i = 0; i < num; ++i) {
QString name(m_reader->GetCellArrayName(i));
m_dataMap.insert(name, grid->GetCellData()->GetArray(m_reader->GetCellArrayName(i)));
}
emit finished();
}
AnsysFileReader::AnsysFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void AnsysFileReader::run()
{
// Open the file.
ifstream ifile(fileName().toLocal8Bit());
if (ifile.fail())
return;
// Determine the file size and come up with an estimate of the
// number of vertices and cells so we can size the points and cells.
int nPoints = 100;
int nCells = 100;
vtkPoints *pts = vtkPoints::New();
pts->Allocate(nPoints);
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
ugrid->SetPoints(pts);
ugrid->Allocate(nCells);
pts->Delete();
#define MAX_ANSYS_LINE 200
char line[MAX_ANSYS_LINE];
float pt[3];
vtkIdType verts[8];
bool recognized = false;
bool fatalError = false;
bool readingCoordinates = false;
bool readingConnectivity = false;
int expectedLineLength = 0;
int firstFieldWidth = 8;
int fieldWidth = 16;
int fieldStart = 56;
for(int lineIndex = 0; !ifile.eof(); ++lineIndex)
{
// Get the line
ifile.getline(line, MAX_ANSYS_LINE);
#if defined(_WIN32)
int linelen = strlen(line);
#else
int linelen = strlen(line)-1; // account for the end of line char.
#endif
// If the line length is less than expected then pad with NULLs.
if(expectedLineLength > 0 && linelen < expectedLineLength)
{
memset(line + linelen + 1, 0, (MAX_ANSYS_LINE - linelen - 1) * sizeof(char));
#if 0
debug5 << "Padding line with NULLs" << endl;
debug5 << line << endl;
#endif
}
// Give it a chance to break out of coordinate reading.
if(readingCoordinates)
{
bool valid = true;
for(int i = 0; i < firstFieldWidth && valid; ++i)
valid &= (line[i] == ' ' || (line[i] >= '0' && line[i] <= '9'));
if(!valid)
{
expectedLineLength = 0;
readingCoordinates = false;
continue;
}
}
if(readingCoordinates)
{
char *valstart = line + fieldStart;
char *valend = valstart + fieldWidth;
pt[2] = atof(valstart);
valstart -= fieldWidth;
valend -= fieldWidth;
*valend = '\0';
pt[1] = atof(valstart);
valstart -= fieldWidth;
valend -= fieldWidth;
*valend = '\0';
pt[0] = atof(valstart);
#if 0
debug4 << pt[0] << ", " << pt[1] << ", " << pt[2] << endl;
#endif
pts->InsertNextPoint(pt);
}
else if(readingConnectivity)
{
// Get whether this cell is real from column 0
line[fieldWidth] = '\0';
bool realCell = atoi(line) > 0;
if(!realCell)
{
expectedLineLength = 0;
readingConnectivity = false;
continue;
}
// Get the number of vertices in this cell from column 9.
static const int ncellsColumn = 9;
line[ncellsColumn * fieldWidth] = '\0';
int nverts = atoi(line + (ncellsColumn-1) * fieldWidth);
if(nverts == 8)
{
char *valstart = line + fieldStart;
char *valend = valstart + fieldWidth;
for(int i = 0; i < 8; ++i)
{
int ivalue = atoi(valstart);
verts[7-i] = (ivalue > 0) ? (ivalue - 1) : ivalue;
valstart -= fieldWidth;
valend -= fieldWidth;
*valend = '\0';
}
#if 0
for(int j = 0; j < 8; ++j)
debug4 << ", " << verts[j];
debug4 << endl;
#endif
ugrid->InsertNextCell(VTK_HEXAHEDRON, 8, verts);
}
else
{
qDebug() << "The file " << fileName() << " contained cells "
"that are not hexes."<< endl;
fatalError = true;
break;
}
}
else if(STRNCASECMP(line, "NBLOCK", 6) == 0)
{
char *comma = strstr(line, ",");
if(comma != 0)
{
char *comma2 = strstr(comma+1, ",");
if(comma2 != 0)
{
*comma2 = '\0';
char *cols = comma + 1;
qDebug() << "Coordinate data stored in "
<< atoi(cols) << " columns." << endl;
recognized = true;
}
}
// Get the field format string. Use it to set expectedLineLength,
// fieldWidth, and fieldStart.
ifile.getline(line, 1024);
if(line[0] == '(')
{
interpretFormatStringEx(line, firstFieldWidth, fieldStart, fieldWidth,
expectedLineLength);
qDebug() << "firstFieldWidth=" << firstFieldWidth
<< ", fieldStart=" << fieldStart
<< ", fieldWidth=" << fieldWidth
<< ", expectedLineLength=" << expectedLineLength
<< endl;
readingCoordinates = true;
}
else
{
qDebug() << "Malformed format string: " << line << endl;
fatalError = true;
}
}
else if(STRNCASECMP(line, "EBLOCK", 6) == 0)
{
char *comma = strstr(line, ",");
if(comma != 0)
{
char *comma2 = strstr(comma+1, ",");
if(comma2 != 0)
{
*comma2 = '\0';
char *cols = comma + 1;
qDebug() << "Connectivity data stored in "
<< atoi(cols) << " columns." << endl;
recognized = true;
}
}
// Get the field format string. Use it to set expectedLineLength,
// fieldWidth, and fieldStart.
ifile.getline(line, 1024);
if(line[0] == '(')
{
interpretFormatStringEx(line, firstFieldWidth, fieldStart, fieldWidth,
expectedLineLength);
qDebug() << "firstFieldWidth=" << firstFieldWidth
<< ", fieldStart=" << fieldStart
<< ", fieldWidth=" << fieldWidth
<< ", expectedLineLength=" << expectedLineLength
<< endl;
readingConnectivity = true;
}
else
{
qDebug() << "Malformed format string: " << line << endl;
fatalError = true;
}
}
else if(STRNCASECMP(line, "/COM", 4) == 0)
{
if(m_title.toStdString() == "")
m_title = /*std::string(*/line+6/*)*/;
recognized = true;
}
else if(STRNCASECMP(line, "/TITLE", 6) == 0)
{
m_title = /*std::string(*/line+8/*)*/;
recognized = true;
}
else if(STRNCASECMP(line, "/BATCH", 6) == 0 ||
STRNCASECMP(line, "/NOPR", 5) == 0 ||
STRNCASECMP(line, "/CONFIG", 7) == 0 ||
STRNCASECMP(line, "/NOLIST", 7) == 0)
{
recognized = true;
}
else
{
expectedLineLength = 0;
readingCoordinates = false;
readingConnectivity = false;
}
}
if(recognized && !fatalError)
m_dataObject = ugrid;
else
ugrid->Delete();
emit finished();
}
void AnsysFileReader::interpretFormatString(char *line, int &fieldStart,
int &fieldWidth, int &expectedLineLength) const
{
char *fmt = line + 1;
char *ptr = 0;
expectedLineLength = 0;
bool keepGoing = true;
while(keepGoing)
{
int linelen = 0;
if((ptr = strstr(fmt, ",")) != 0)
{
*ptr = '\0';
interpret(fmt, fieldWidth, linelen);
expectedLineLength += linelen;
fmt = ptr + 1;
}
else if((ptr = strstr(fmt, ")")) != 0)
{
*ptr = '\0';
interpret(fmt, fieldWidth, linelen);
expectedLineLength += linelen;
keepGoing = false;
}
else
keepGoing = false;
}
fieldStart = expectedLineLength - fieldWidth;
}
void AnsysFileReader::interpretFormatStringEx(char *line, int &firstFieldWidth, int &fieldStart, int &fieldWidth, int &expectedLineLength) const
{
char *fmt = line + 1;
char *ptr = 0;
expectedLineLength = 0;
bool keepGoing = true;
bool first = true;
while(keepGoing)
{
int linelen = 0;
if((ptr = strstr(fmt, ",")) != 0)
{
*ptr = '\0';
interpret(fmt, fieldWidth, linelen);
if(first)
{
first = false;
firstFieldWidth = fieldWidth;
}
expectedLineLength += linelen;
fmt = ptr + 1;
}
else if((ptr = strstr(fmt, ")")) != 0)
{
*ptr = '\0';
interpret(fmt, fieldWidth, linelen);
if(first)
{
first = false;
firstFieldWidth = fieldWidth;
}
expectedLineLength += linelen;
keepGoing = false;
}
else
keepGoing = false;
}
fieldStart = expectedLineLength - fieldWidth;
}
void AnsysFileReader::interpret(const char *fmt, int &fieldWidth,
int &linelen) const
{
int i0, i1, i2;
qDebug() << "avtANSYSFileFormat::Interpret: " << fmt << endl;
// Example: 6e16.9
if(sscanf(fmt, "%de%d.%d", &i0, &i1, &i2) == 3)
{
linelen = i0 * i1 / 2;
fieldWidth = i1;
}
// Example: 19i7
else if(sscanf(fmt, "%di%d", &i0, &i1) == 2)
{
linelen = i0 * i1;
fieldWidth = i1;
}
else
{
qDebug() << "Invalid format string: " << fmt << endl;
}
}
PlyFileReader::PlyFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void PlyFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
emit finished();
}
PdbFileReader::PdbFileReader(QObject *parent) : AbstractFileReader(parent)
{
}
void PdbFileReader::run()
{
vtkInitOnce(&m_reader);
m_reader->SetFileName(fileName().toLocal8Bit());
m_reader->Update();
emit finished();
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/filereaderutils.h
================================================
#ifndef FILEREADERUTILS_H
#define FILEREADERUTILS_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "vtkutils_global.h"
#include "vtkutils.h"
class vtkDataArray;
namespace VtkUtils
{
template
class ReaderTempl
{
public:
// virtual void run() = 0;
virtual P* dataObject() const
{
if (m_reader)
return m_reader->GetOutput();
return nullptr;
}
T* reader() const { return m_reader; }
protected:
T* m_reader = nullptr;
P* m_dataObject = nullptr;
};
class VTKUTILS_EXPORT AbstractFileReader : public QObject, public QRunnable
{
Q_OBJECT
public:
explicit AbstractFileReader(QObject* parent = nullptr);
void setFileName(const QString& file);
QString fileName() const;
void setTitle(const QString& title);
QString title() const;
signals:
void finished();
protected:
QString m_fileName;
QString m_title;
};
class VTKUTILS_EXPORT VtkFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit VtkFileReader(QObject* parent = nullptr);
void run();
};
class VTKUTILS_EXPORT StlFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit StlFileReader(QObject* parent = nullptr);
void run();
};
class VTKUTILS_EXPORT ObjFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit ObjFileReader(QObject* parent = nullptr);
void run();
};
class VTKUTILS_EXPORT DynaFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit DynaFileReader(QObject* parent = nullptr);
void run();
};
class VTKUTILS_EXPORT NastranFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit NastranFileReader(QObject* parent = nullptr);
void run();
protected:
std::vector m_matList;
std::map m_uniqMatIds;
};
class VTKUTILS_EXPORT FluentFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit FluentFileReader(QObject* parent = nullptr);
void run();
protected:
QMap m_dataMap;
};
class VTKUTILS_EXPORT AnsysFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit AnsysFileReader(QObject* parent = nullptr);
void run();
protected:
void interpretFormatString(char *line, int &fieldStart,
int &fieldWidth, int &expectedLineLength) const;
void interpretFormatStringEx(char *line, int &firstFieldWidth, int &fieldStart,
int &fieldWidth, int &expectedLineLength) const;
void interpret(const char *fmt, int &fieldWidth,
int &linelen) const;
};
class VTKUTILS_EXPORT PlyFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit PlyFileReader(QObject* parent = nullptr);
void run();
};
class VTKUTILS_EXPORT PdbFileReader : public AbstractFileReader, public ReaderTempl
{
Q_OBJECT
public:
explicit PdbFileReader(QObject* parent = nullptr);
void run();
};
} // namespace VtkUtils
#endif // FILEREADERUTILS_H
================================================
FILE: libs/vtkutils/implicitplanewidgetobserver.cpp
================================================
#include "implicitplanewidgetobserver.h"
#include
namespace VtkUtils
{
ImplicitPlaneWidgetObserver::ImplicitPlaneWidgetObserver(QObject* parent) : AbstractWidgetObserver(parent)
{
}
void ImplicitPlaneWidgetObserver::Execute(vtkObject *caller, unsigned long eventId, void *callData)
{
Q_UNUSED(eventId)
Q_UNUSED(callData)
vtkImplicitPlaneWidget* widget = reinterpret_cast(caller);
if (widget) {
emit originChanged(widget->GetOrigin());
emit normalChanged(widget->GetNormal());
}
}
} // namespace VtkUtils
================================================
FILE: libs/vtkutils/implicitplanewidgetobserver.h
================================================
#ifndef IMPLICITPLANEWIDGETOBSERVER_H
#define IMPLICITPLANEWIDGETOBSERVER_H
#include "abstractwidgetobserver.h"
namespace VtkUtils
{
class VTKUTILS_EXPORT ImplicitPlaneWidgetObserver : public AbstractWidgetObserver
{
Q_OBJECT
public:
explicit ImplicitPlaneWidgetObserver(QObject* parent = nullptr);
signals:
void originChanged(double* origin);
void normalChanged(double* normal);
protected:
void Execute(vtkObject *caller, unsigned long eventId, void* callData);
};
} // namespace VtkUtils
#endif // IMPLICITPLANEWIDGETOBSERVER_H
================================================
FILE: libs/vtkutils/interactor.cpp
================================================
#include "interactor.h"
#include "../graph3d.h"
#include "../postprocessor.h"
#include "util.h"
#include
#include
#include
#include
class InteractorPrivate
{
public:
ComDataGui3D::Graph3D* graph = nullptr;
ComDataGui3D::PostProcessor* postprocessor = nullptr;
vtkRenderer* renderer = nullptr;
bool isHooked = false;
bool isVisible = false;
};
Interactor::Interactor(QObject* parent) : QObject(parent)
{
d_ptr = new InteractorPrivate;
}
Interactor::~Interactor()
{
delete d_ptr;
}
int Interactor::type() const
{
return DEFAULT;
}
void Interactor::attach(ComDataGui3D::PostProcessor* pp)
{
if (d_ptr->postprocessor != pp) {
d_ptr->postprocessor = pp;
d_ptr->graph = pp->graph();
d_ptr->renderer = pp->renderer();
d_ptr->isHooked = true;
}
}
void Interactor::detach()
{
Q_ASSERT(graph() != nullptr);
setDefaultInteractorStyle();
d_ptr->postprocessor = nullptr;
d_ptr->graph = nullptr;
d_ptr->renderer = nullptr;
d_ptr->isHooked = false;
}
bool Interactor::isHooked() const
{
return d_ptr->isHooked;
}
void Interactor::update()
{
// no impl
d_ptr->graph->update();
}
void Interactor::setVisible(bool visible)
{
if (d_ptr->isVisible != visible) {
if (visible)
setSpecialInteractorStyle();
else
setDefaultInteractorStyle();
graph()->update();
}
}
bool Interactor::isVisible() const
{
return d_ptr->isVisible;
}
ComDataGui3D::Graph3D* Interactor::graph() const
{
return d_ptr->graph;
}
vtkRenderer* Interactor::renderer() const
{
return d_ptr->renderer;
}
ComDataGui3D::PostProcessor* Interactor::processor() const
{
return d_ptr->postprocessor;
}
double* Interactor::bounds() const
{
if (d_ptr->postprocessor)
return d_ptr->postprocessor->bounds();
return nullptr;
}
void Interactor::setDefaultInteractorStyle()
{
vtkInteractorStyleTrackballCamera* style = vtkInteractorStyleTrackballCamera::New();
style->SetDefaultRenderer(renderer());
graph()->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
}
void Interactor::setSpecialInteractorStyle()
{
}
================================================
FILE: libs/vtkutils/interactor.h
================================================
#ifndef INTERACTOR_H
#define INTERACTOR_H
#define DEFAULT 0
#define BOXCUTTER 1
#define LINEPROBER 2
#define PLANECUTTER 3
#define SPHERECUTTER 4
#define POINTMOVER 5
#include
namespace ComDataGui3D
{
class Graph3D;
class PostProcessor;
}
class vtkRenderer;
class InteractorPrivate;
class Interactor : public QObject
{
Q_OBJECT
public:
explicit Interactor(QObject* parent = nullptr);
virtual ~Interactor();
virtual int type() const;
virtual void attach(ComDataGui3D::PostProcessor* pp);
virtual void detach();
bool isHooked() const;
virtual void update();
virtual void setVisible(bool visible);
virtual bool isVisible() const;
protected:
ComDataGui3D::Graph3D* graph() const;
vtkRenderer* renderer() const;
ComDataGui3D::PostProcessor* processor() const;
double* bounds() const;
void setDefaultInteractorStyle();
virtual void setSpecialInteractorStyle();
private:
InteractorPrivate* d_ptr;
Q_DISABLE_COPY(Interactor)
};
#endif // INTERACTOR_H
================================================
FILE: libs/vtkutils/lineprober.cpp
================================================
#include "lineprober.h"
#include "detail/util.h"
#include "qcustomplot.h"
#include "movelineinteractorstyle.h"
#include "../graph3d.h"
#include "../postprocessor.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static const char *DefaultColors[] =
{
"LightSalmon",
"SteelBlue",
"Yellow",
"Fuchsia",
"PaleGreen",
"PaleTurquoise",
"Cornsilk",
"HotPink",
"Peru",
"Maroon"
};
class Plot2DOverlay;
class LineProberPrivate
{
public:
LineProberPrivate();
vtkActor* firstBallActor = nullptr;
vtkActor* secondBallActor = nullptr;
vtkActor* lineActor = nullptr;
double pot1[3];
double pot2[3];
bool isPlotVisible = true;
QCustomPlot* plot = nullptr;
};
LineProberPrivate::LineProberPrivate()
{
}
LineProber::LineProber(QObject* parent) : Interactor(parent)
{
d_ptr = new LineProberPrivate;
}
int LineProber::type() const
{
return LINEPROBER;
}
void LineProber::setPoint1(double* pot)
{
if (ComDataGui3D::detail::ArrayComparator()(d_ptr->pot1, pot))
return;
ComDataGui3D::detail::ArrayAssigner()(d_ptr->pot1, pot);
update();
}
double* LineProber::point1() const
{
return d_ptr->pot1;
}
void LineProber::setPoint2(double* pot)
{
if (ComDataGui3D::detail::ArrayComparator()(d_ptr->pot2, pot))
return;
ComDataGui3D::detail::ArrayAssigner()(d_ptr->pot2, pot);
update();
}
double* LineProber::point2() const
{
return d_ptr->pot2;
}
void LineProber::setPoints(double* pot1, double* pot2)
{
if (ComDataGui3D::detail::ArrayComparator()(d_ptr->pot1, pot1) &&
ComDataGui3D::detail::ArrayComparator