## VTK – Separating Meshe By Connectivity

I export scene from ParaView to get a mesh like the following image. Let’s take edge lists from different parts and form two independent meshes. #include <iostream> #include <vtkSmartPointer.h> #include <vtkSphereSource.h> #include <vtkActor.h> #include <vtkConeSource.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkPolyDataMapper.h> #include <vtkRenderWindowInteractor.h> #include <vtkCellData.h> #include <vtkNamedColors.h> #include <vtkColorTransferFunction.h> #include Read more…

## The Stability Of Sorting Algorithm

If two numbers are equal and the relative positions are not changed after sorting, we think the sorting algorithm is stable. Stable sort algorithm: bubble sort, insert sort and merge sort. Unstable sort algorithm: quick sort, heap sort. Introduce an unstable sort algorithm quick sort. Its core thought is divide Read more…

## CPP : typeid.name and initializer_list

typeid.name The function typeid.name can give us the information about variable. Header file: typeinfo #include <typeinfo> int main() { vector<bool> vec{ false, true }; auto ans = vec; cout << typeid(ans).name() << endl; bool tmp = false; cout << typeid(tmp).name() << endl; int value = 12; cout << typeid(value).name() << Read more…

## C++ Exercises: Data Structure II

Exercises: 232. Implement Queue using Stacks Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Solution: take advantage of the features of both stacks #include <iostream> #include <set> #include <vector> #include <algorithm> #include <stack> Read more…

## C++ Exercises: Data Structure I

Exercises: 448. Find All Numbers Disappeared in an Array Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Solution: use set to record all numbers had showed and find the the rest disappeared numbers. #include <iostream> #include <set> Read more…

## C++ Exercises: Bit Operation

Exercises: 461. Hamming Distance Calculate the number of positions at which the corresponding bits are different. Solution: Do XOR and find the number of 1. class Solution { public: int hammingDistance(int x, int y) { int tmp = x ^ y; int ans = 0; while( tmp > 0 ){ if( Read more…

3D Model Viewer: add grid plane and convex hull.