CPP – Partial Sort Algorithm

We need not sort all elements sometimes. Here are a few simple examples of STL algorithms partial_sort, nth_element, and partition. partial_sort For example, find the 5 biggest ones in 10 random numbers. #include <iostream> #include <vector> #include <cstdlib> #include <ctime> #include <algorithm> using namespace std; int main() { vector<int> values; Read more…

VTK – Reverse PolyData’s Normals

vtkReverseSense can help us to reverse the direction of point normals and cell normals. The following code shows a simple example which display vertexes’ normals by cones in a sphere. Here is its original geometric states. #include <iostream> #include <vtkSmartPointer.h> #include <vtkSphereSource.h> #include <vtkActor.h> #include <vtkConeSource.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> Read more…

QT – Common Setting For Window

Borderless window: setWindowFlags( Qt::FramelessWindowHint ); Set background color: QPalette pal = mainWin->Getui().qvtkWidget->palette(); pal.setColor( QPalette::Background, Qt::black ); setAutoFillBackground( true ); this->setPalette( pal ); Make window stay on the top level: setWindowFlags(Qt::WindowStaysOnTopHint) Remove maximize button in widget: setWindowFlags( this->windowFlags() & ~Qt::WindowMaximizeButtonHint ); Definite buttons on title bar: setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint); //Only Read more…

QT – QTest event, QSignalSpy and installEventFilter

The interfaces can imitate users’ operations. QTest::keyClick QTest::keyPress QTest::mouseClick QSignalSpy listens for signal emission, it is a list of QVariant lists. It will not shield off signal to make slot invalid. QCheckBox *box = …; QSignalSpy spy(box, SIGNAL(clicked(bool))); //… QList arguments = spy.takeFirst(); // take the first signal QVERIFY(arguments.at(0).toBool() == Read more…

VTK – Update Different Views When Selections Changed

The article shows how to use vtkViewUpdater to update different views when the selections changed. Relevant development environment: VTK-8.1.1; Qt 5.11.2 (x86_64-little_endian-lp64 shared (dynamic) release build; Clang 8.1.0 (clang-802.0.42) (Apple)) on “cocoa”; macOS 10.14 [darwin version 18.5.0]; #include <QApplication> #include <qsurfaceformat.h> #include <QVTKOpenGLWidget.h> #include <vtkRandomGraphSource.h> #include <vtkDataObjectToTable.h> #include <vtkQtTableView.h> #include Read more…

CPP – copy_if

The algorithm copy_if is useful, it can help us to get all elements that meet special conditions. C++ template OutputIt copy_if( InputIt first, InputIt last, OutputIt d_first, UnaryPredicate pred ); Possible implement: C++ template OutputIt copy_if(InputIt first, InputIt last, OutputIt d_first, UnaryPredicate pred) { while (first != last) { if Read more…

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X