Tag Archives: qt

Using qvtk renderwindoninteractor to load VTK widget

When embedding VTK qt met VTK widget can’t move, began to directly copy the official case inside vtkScalarBarWidget wording, is shown in the QVTKRenderWindowInteractor abnormalities, cannot interact with the widget.
https://vtk.org/Wiki/VTK/Examples/Python/Widgets/ScalarBarWidget
in writing is as follows:

# create the scalar_bar_widget
scalar_bar_widget = vtk.vtkScalarBarWidget()
scalar_bar_widget.SetInteractor(interactor)
scalar_bar_widget.SetScalarBarActor(scalar_bar)
scalar_bar_widget.On()

Changed to:

# create the scalar_bar_widget
self.scalar_bar_widget = vtk.vtkScalarBarWidget()
self.scalar_bar_widget.SetInteractor(self.iren)
self.scalar_bar_widget.SetScalarBarActor(scalar_bar)
self.scalar_bar_widget.On()

This means that the widget should be prefixed with self when loading with classes.

>

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
import vtk
class MainPage(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setObjectName("MainWindow")
        self.resize(603, 553)
        self.centralWidget = QtWidgets.QWidget(self)
        self.gridlayout = QtWidgets.QGridLayout(self.centralWidget)
        self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
        self.gridlayout.addWidget(self.vtkWidget)
        self.setCentralWidget(self.centralWidget)
        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
        # Create source
        source = vtk.vtkSphereSource()
        source.SetCenter(0, 0, 0)
        source.SetRadius(5.0)
        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        self.ren.AddActor(actor)
        # create the scalar_bar
        scalar_bar = vtk.vtkScalarBarActor()
        scalar_bar.SetOrientationToHorizontal()
        lut = vtk.vtkLookupTable()
        lut.Build()
        scalar_bar.SetLookupTable(lut)
        # create the scalar_bar_widget
        self.scalar_bar_widget = vtk.vtkScalarBarWidget()
        self.scalar_bar_widget.SetInteractor(self.iren)
        self.scalar_bar_widget.SetScalarBarActor(scalar_bar)
        self.scalar_bar_widget.On()
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainPage()
    window.show()
    window.iren.Initialize()
    sys.exit(app.exec_())

On the problem of QT program open crash

The problem
Open the packed program found collapse.
program is made up of two interface. After the first interface is login screen, click login will invoke the other main interface
login interface can open, there is no problem, call the main interface will collapse.
screening
I read it first

https://blog.csdn.net/cqltbe131421/article/details/78036684 the bosses of explanation.

Maybe it’s the pointer. Or event.
comments one by one code hou found the root cause again
inside the constructor USES a

program package after infinite collapse.
no problem after the 63 lines of code commented out.
thinking
Because my ExcelViewModel is an empty object. Inside the constructor does not have any code.
I wonder whether the problem.

later
Added a line of setHeaderData () , the main is to set up the command excelViewModel data in it, and set the column number.
then collapse.

Vtk8.2.0 (32bit + 64bit) compilation and installation test (win10 + vs2017 + Qt5)

This article referred to the following articles in the installation process, and I would like to express my thanks to the following bloggers! :
https://blog.csdn.net/anhec/article/details/86777302
I. Preparation before installation
Visual Studio 2017 qt5cmakevtk source (https://vtk.org/download/)
Two. VTK compilation
My compile directory is as follows

Run CMake as follows

Click Configure, select Visual Studio 15 2017 (32bit) or Visual Studio 15 2017 Win64 (64bit), and click Finish.

When configure is complete, manually modify some of the parameters as follows:

    BUILD_SHARED_LIBS, unchecked if static lib generation is needed; BUILD_EXAMPLES, which generate test cases, check the suggested box for easy post-compile testing; CMAKE_DEBUG_POSTFIX, which means that in debug mode the filename is followed by the specified character; VTK_Group_Qt, VTK supports Qt; CMAKE_INSTALL_PREFIX, set the VTK installation directory (D:\libraries\I_VTK\VTK\bin\x86 or D:\libraries\I_VTK\VTK\bin\x64);

Click Configure again to Configure the Qt path

Select the Qt path: (32bit) D:\libraries\Qt\Qt5.12.0\5.12.0\msvc2017\lib\cmake\Qt5
(64 – bit) D: \ libraries \ Qt \ Qt5.12.0\5.12.0 \ msvc2017_64 \ lib \ cmake \ Qt5
Click Configure again (change the red color if it still appears, then click Configure) and click Generate when you’re done.

III. VS2017 compilation
Open vtk.sln with vs2017, then right-click ALL_BUILD, click build, wait for some time, all compile successfully;



Right-click Install again and select Project Only –>; Only generate INSTALL, after completion you can see in the installation directory (D:\libraries\I_VTK\VTK\bin\x86), see the related lib, include, etc


In VS2017, change the configuration from Debug to Release, repeat ALL_BUILD and INSTALL above;
Test three.

Select Cube and run

 
 
 
 
 
 
 
 

VTK + QT + vs compilation and installation configuration

VTK
The VTK, (Visualization Toolkit) is an open source, free software system for 3D computer graphics, image processing, and visualization. VTK is designed and implemented on the basis of object-oriented principles, its kernel is built in C++, contains about 250,000 lines of code, more than 2000 classes, but also contains several conversion interface, so you can also use VTK freely through Java, Tcl/Tk and Python various languages. VTK will be scientific experimental data such as architecture, meteorology, medicine, biology or aerospace, on the body, surface, light source and so on realistic rendering, so as to help people understand those who take the complex and often large scale digital presentation of scientific concepts or results.
purpose
The purpose of this article is to build an application development environment for VTK+ Qt +VS.
Qt version: 5.7.0
VTK version: 7.1.1
VS Version: 2013 (VC12)
Precondition: Cmake are installed in your environment, QT5.7.0 and VS2013 already configured installation, installation configuration is very simple, if there is something wrong with the configuration can refer to http://blog.csdn.net/goodtomsheng/article/details/45719205
VTK compilation and installation
1. Download VTK7.1.1http://www.vtk.org/download/, at present the website is the latest version VTK8.0.1, conservative estimates I chose VTK7.1.1 version, the download file VTK – 7.1.1. Zip, VTKData – 7.1.1. Zip.
2. Create a directory named VTK (name whatever), unzip ctk-7.1.1.zip, vtkdata-7.1.1.zip into VTK directory, and create a vtk_bin_x64 directory to store the generated VTK project after CMake, the directory structure after unzip is shown in the figure.

 
 
 
3. Open cmak-gui, select vtk-7.1.1 from Where is thesource code and vtk_bin_x64 from Where to build the binaries. Click Configure, select Visual Studio12 2013 in the pop-up dialog, and click Finish. After the Configue configuration is complete, there are several macros that need to be configured:
BUILD_SHARED_LIBS – Indicates whether to build a shared library or a static library. Default is the state selected for compilation. We want to build the shared library, so leave the default state.
BUILD_EXAMPLES – Indicates compilation of sample projects, selected here for easy learning.
CMAKE_INSTALL_PREFIX — After the VTK compilation is complete, the installation directory, bin, lib, include, etc., will be copied to its specified directory. The default installation directory for x64 compilation is “C:/ProgramFiles /VTK”, but the real macro is set by VTK7.1.1. INSTALL_BIN_DIR, INSTALL_INC_DIR, INSTALL_LIB_DIR, INSTALL_MAN_DIR, INSTALL_PKGCONFIG_DIR. If you are not an administrator, it will fail to install in the default directory because of permissions issues.
VTK_Group_Qt — Qt supported, not supported by default, we want to support Qt integrated development, so check this item. Also check the module_vtkguisupportQt and module_vtkguisupportQtopengl macros to support Qt.
VTK_QT_VERSION – QT version, I used to QT5 set to 5, so this option is not after the Configure, it doesn’t matter, such as the back after clicking the Generate reports QT version failed, after this time you can find this option and set to Generate was no problem.
VTK_DATA_STORE — VTK data storage location, is the previous from the VTK official website down the VTKData-7.1.1.zip, specified to decompress two layers under the directory, I here is “E:\OpenSource\ VTK \VTKData-7.1.1\VTK-7.1.1\.ExternalData”.
Module_vtkguisupportMFC – Specifies the library that will be generated to integrate with the MFC framework. I don’t need it here, so leave it unchecked.
Click Add Entry, Add CacheEntry, CMAKE_PREFIX_PATH, and set the Value to your Qt installation directory, “D:\Qt\Qt5.7.0\5.7\ MSVC2013_64”.
Click Generate when all of the above options are set. This will fail once due to the version of Qt, and it will be OK to regenerate after VTK_QT_VERSION is set correctly. After the CMAKE work is done, the interface is shown below, where the CMAKE work is finished.
 

 
 
 
4. After Generate is completed, click OpenProject to open the configured VS2013 project. Click the menu to generate ->; Batch build, select ALL_BUILD to build Debug and Release versions. After the build is complete, click on the color when the build ->; Batch build, select Install to build Debug, this will Debug version lib, bin, inlcude and other copies to the “C:/Program Files /VTK” directory set above.
5. Combine with Qt Designer, Copy the qvtkwidgetPlugin.dll and the qvtkwidgetPlugin.lib and the qvtkwidgetPlugin.exp from the bin path generated by the Release to the plugins\designer (my path is D: QT \ qt\ Qt5.7.0\5.7\msvc2013_64\) Plugins \ Designer), do not use the Debug version to compile the generated file, Qt Designer will not read it. After setup, open QTDesigner and you will see QVTKWidget, as shown in the figure below.

 
 
 
 
6. VS project configuration (the official documentation of VTK recommends using CMAKE to manage the project, here will introduce some special attention to not using CMAKE to manage the project)
A) Create a new VS project (either a Qt project or a C++ project)
C:\Program Files\VTK\ Include \ VTK-7.1 \ C:\Program Files\VTK\lib \ C:\Program Files\VTK\lib \ A good way to do this is to open a project under “Examples” and copy it directly from the project configuration input library.
C) at that time if you send the sample program code copy of the Cone to the current engineering (Cone code given below), compiled by anything, while on a running program can not run normally or hang up directly after the operation, debugging to follow up after found vtkPolyDataMapper: : New () returns NULL, and the same code Examples of instances of engineering Cone can run normally and display effect. After analyzing the Cone project, we found that it had a number of preconditioning instructions, and one of the key preconditioning instructions was:
VtkRenderingCore_INCLUDE = “E:/OpenSource/VTK/vtk_bin_x64 CMakeFiles/vtkRenderingCore_AUTOINIT_vtkInteractionStyle_vtkRenderingOpenGL2. H”.
Vtkrenderingcore_autoinit_vtkinteractionstyle_vtkrenderingopengl2.h copy to vtkinteractionstyle_vtkrenderingopengl2.h indluce directory, and then add the preprocessor to your own VS project:
vtkRenderingCore_INCLUDE=”vtkRenderingCore_AUTOINIT_vtkInteractionStyle_vtkRenderingOpenGL2.h”
To see what the preprocessor does, open the.h file and see that it defines only one macro:
# define vtkRenderingCore_AUTOINIT2 (vtkInteractionStyle vtkRenderingOpenGL2), is actually the initialization VTK module, according to the official specification, can define this macro before all include files:
# define vtkRenderingCore_AUTOINIT2 (vtkInteractionStyle vtkRenderingOpenGL2), which can solve the problem. Or, as follows, at the very beginning of the code, before all the header files are included.
#include “vtkAutoInit.h”
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built withvtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
Either of the above methods can solve the problem. More detailed explanation can refer to http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Factories_now_require_defines. The results of the Cone project are shown below. The window closes automatically after the Cone is rotated for a few seconds.

Compiled libraries address: https://pan.baidu.com/s/1pLMChzP wfd6
 
 
 

#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
int main()
{
  // Next we create an instance of vtkConeSource and set some of its
  // properties. The instance of vtkConeSource "cone" is part of a
  // visualization pipeline (it is a source process object); it produces data
  // (output type is vtkPolyData) which other filters may process.
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );
  // In this example we terminate the pipeline with a mapper process object.
  // (Intermediate filters such as vtkShrinkPolyData could be inserted in
  // between the source and the mapper.)  We create an instance of
  // vtkPolyDataMapper to map the polygonal data into graphics primitives. We
  // connect the output of the cone souece to the input of this mapper.
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInputConnection( cone->GetOutputPort() );
  // Create an actor to represent the cone. The actor orchestrates rendering
  // of the mapper's graphics primitives. An actor also refers to properties
  // via a vtkProperty instance, and includes an internal transformation
  // matrix. We set this actor's mapper to be coneMapper which we created
  // above.
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );
   // Create the Renderer and assign actors to it. A renderer is like a
  // viewport. It is part or all of a window on the screen and it is
  // responsible for drawing the actors it has.  We also set the background
  // color here.
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );
  // Finally we create the render window which will show up on the screen.
  // We put our renderer into the render window using AddRenderer. We also
  // set the size to be 300 pixels by 300.
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );
  // Now we loop over 360 degrees and render the cone each time.
  int i;
  for (i = 0; i < 360; ++i)
  {
    // render the image
    renWin->Render();
    // rotate the active camera by one degree
    ren1->GetActiveCamera()->Azimuth( 1 );
  }

  //
  // Free up any objects we created. All instances in VTK are deleted by
  // using the Delete() method.
  //
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  ren1->Delete();
  renWin->Delete();

  return 0;
}

 
 
 
 
 
 
 

Cmake error on qt5core

CMAKE error on Qt5Core

The problem
I’m trying to build a source code using QT5 using CMake. It exits this error:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

CMake Error at CMakeLists.txt:20 (find_package):


By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has


asked CMake to find a package configuration file provided by "Qt5Core", but


CMake did not find one.

 


Could not find a package configuration file provided by "Qt5Core" with any


of the following names:

 


Qt5CoreConfig.cmake


qt5core-config.cmake

 


Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set


"Qt5Core_DIR" to a directory containing one of the above files. If


"Qt5Core" provides a separate development package or SDK, be sure it has


been installed.

solution
I checked the QT5 package and it seems to be installed. The naming of the QT4 and QT5 packages in Ubuntu has been changed and dropped.
All you need is wrapping qtbase5-dev Once I installed it, this bug was resolved:

1

$ sudo apt install qtbase5-dev

Recording some pits of VTK + QT

QAlgorithms. H: QAlgorithms. H: QAlgorithms. H: QAlgorithms. H: QAlgorithms
2. When cmake compiles VTK, select x64, enter the release mode that you want to select when you build VTK (otherwise there will be lib missing)
3. VS remember to start in administrator mode
 

Summary of problems encountered in using OpenGL in QT

Configure environment VS2015 + QT5.9

: Error LNK2019: Unable to parse the external symbol – **.
: Error LNK2019: Unable to parse the external symbol – **.
solution
en cmake, put BUILD_SHARED_LIBS on the box, recompile to generate glfw3.lib and glfw3dll. DLL, add them to Qt’s pro, compile to pass.
Problem – Glad include
in Pro after configuration Glad path, add

#include <glad/glad.h>

If the position is not appropriate, an alarm will appear:

error: C1189: #error:  OpenGL header already included, remove this include, glad already provides it

containing glad must precede all penGL *** h>rs.
GlDrawElements ()
call function drawelements () e> :

Error - 
RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

1. ***Pointer s>uffer error, vertex index out of bounds reference vertex array;
br bb3 GlbindVertexArray (0)

GlbindV>xArray (0)

GlbindVertexArray (0)

GlbindVerTexArray (0)

GlbindVerTexArray (0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
br> <>>



3. Call makeCurrent()fore binding VAO.
(To be continued)

[kimol Jun’s boring little invention] – using Python to write paper downloader (graphical interface)

[Kimol’s Boring Gizz] — Writing Theses in Python (Graphical Interface)
1. Function function 2. Callback function 3. Thread generation function 4. Effect display
Write in the last

preface

Micro cool wind slightly raises a night to night, night, month light into my study ~
when I open the folder to review the past, near many seemingly messy code. As I was sitting there, an idea suddenly occurred to me: “Life is already very boring, it would be better to be boring again.”
so, I decided to open a project, then call the kimol jun boring gizmos .
wonderful... Ah ~ ~ ~

In the process of scientific research and learning, we inevitably need to query the relevant literature, and presumably many partners know the SCI-HUB, which is a great tool, it can help us search the relevant papers and download the original. It can be said that the Sci-Hub has benefited a lot of researchers, and it is also a "pleasure" to use.
The analysis process and the corresponding function code were described in the previous article. I found some problems according to the feedback of my friends. After all, the form of the command box is not so "smooth".

font> (>)
(PS)

(PS)

(PS)

(PS) This is written by Kimol in his crazy squeeze time, so the interface is relatively simple, I hope you can understand it more
I. Instructions for use

:
:
:
:
:
:
:
:
:
:
:
:

    Single Paper Download: Enter the title, DOI or PMID number of the paper in the title bar, and then select the directory of the paper storage. Click Start! Bulk download: select a.txt text in the title of the paper, which contains each paper to be downloaded in the following format:

    en, emmm...
    >
    >
    >
    >
    >
    >
    >
    >
    >

Second, code analysis
This graphical interface development is based on PyQT5, the specific layout of the interface here is not much introduction, mainly to the function of the realization of the description:
The idea is simple. Since we already have a function for the paper download, we just need to define a Button and bind it to the download function.
What's that?Not at all difficult. However, if you try it, the interface is stuttering. This is because it takes a long time to download the function, and if it is executed directly in the main thread, it will conflict with the main program that maintains the interface, resulting in a lag.

br>

Vs2017 FAQs

1. VS2017 could not open included file: “corecrt.h” : No such file or directory/ VS2017 could not open included file: “errno.h” : No such file or directory
Solution: Everything searches for the corresponding “corecrt.h”/” errno.h “header file

Find the corresponding path, and then in VS2017

 
2. ERROR LNK2038: Mismatch of ‘_MSC_VER’ detected: value ‘1600’ Mismatch value ‘1800
 
I encountered this problem because of the conflict of Qt versions, the problem left over from previous installation, the problem of 32-bit Qt and 64-bit Qt, and the installation path of Qt. Before, one was installed on both C and D disks.

 
Delete the other one and leave the same Qt as your computer version.
3. Unable to find entry program anchor point, cannot link dynamic library. The module computer type “X64” conflicts with the target computer type “X86”.
First modification:


At the entry point
Set the entry point to the console, and the console will appear after running. It makes me feel bad.
Second modification:

 

Later, I found that the library call path under UCRT, Tool was set incorrectly. I set it to X64, but I can change it to X86 folder.
 

Compile QT source code error causes and Solutions

Qt source code compilation error:
1. Source code path contains Chinese font
2. No such file or directory can be found at compile time.
Solution:
1. Change to English path
2. When compiling the source code, add QT += widgets at the bottom of the project file. Pro.

Baidu Answer Question 2:
Write in the pro qt + = widgets QtWidget this module, introduced said, qmake will help you to generate a makefile, set up the include path and lib path, when the link set libs.
include

QApplication> Only the declaration is introduced, but there is no lib, so the link will fail.

Solving the problem of Chinese garbled code in qtring

Qt solves the problem of Chinese gibberish

qt generally set in the designer interface Chinese title what can be displayed normally.

but in QString, for example, when QPainter is painting Text, if the char* passed in contains Chinese, it will usually show a garbled code. At this time, two places need to be set:

    in main. CPP set QTextCodecQString using static method fromLocal8Bit(char*)
    for the first place, set in main. CPP as follows:
#include "MainWindow.h"

#include <QApplication>
#include <QTextCodec>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec* codec = QTextCodec::codecForName("GB2312");
    QTextCodec::setCodecForLocale(codec);
    MainWindow w;
    w.show();
    return a.exec();
}

For the second place, use the following method in a char* containing Chinese characters:

QString::fromLocal8Bit(char*)

Where you want to pass in a QString, if Chinese is included, you need to do the above two Settings.