## VTK – Find Connected Lists And Sort All Points In Them

Create two half spheres and save them in a vtp file by ParaView. We will use it to explore an algorithm that finds the two separated cut list and sort all points in every list. The original scene is like the following images. Use vtkCutter to create cut lines that Read more…

## VTK – Stretch The Boundary And Fill The Hole

Create a sphere and clip it as the following image. We will pull down the boundary and close the opening to get a new model. How to pull down the boundary of the hemispheres? Step 1. Find all independent edges which are used by only one cell. Step 2. Connect Read more…

## CPP – Delete Special Elements In Vector

We often need to delete some elements in an STL set. But it causes a strange bug if we are careless sometimes. One newbie in C Plus Plus program language may write the following code to delete all odd numbers in a set. int main() { vector<int> vec{ 1, 3, Read more…

## Python & Algorithm – Equation Solving

I want to get the solution of the equation Bisection Method The first algorithm for the problem is bisection method. The algorithm bisection method doesn’t require derivation for the equation. It just needs a possible solution range [l, r], then calculates the variable mid as , compares the result of Read more…

## CPP – Driven Class Of unary_function

Driven class of unary_function can be used to check a single element based on special condition.Programmer can regard it as some algorithms’ parameter, such as count_if, find_if, and find_if_not.The following code shows how to write a customized unray class and use it. C++ struct Widget { int GetSpeed() const { return speed; } Widget( const Read more…

## 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…

## C++: Accumulate And For_each

accumulate Interval algorithm accumulate supports custom calculate method to count elemeints in the special range. We can use it to get summary, multiple, average and etc of some elements, it’s very convenient and powerful. The syntax and usage example are in the following. Syntax: template< class InputIt, class T > Read more…

## STL Algorithm: Count And Count_if

count STL algorithm count can help us to count the elements that are equal to value.Its syntax is like the following form: C++ template typename iterator_traits::difference_type count( InputIt first, InputIt last, const T &value ); Example: C++ #include #include #include using namespace std; int main(int argc, char *argv[]) { vector 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…

A prohibited operation