C++
count_if counts the number of elements that satisfies the specified condition. The result is like the following: 79, 55, 57, 44, 0, 14, -5, 52, 86, 95, -7, 100, 5, -5, 95, 19, 63, 59, 40, 51, numNegative = 3 numNonNegative = 17 numZero = 1…
[code lang="cpp"] Eigen::MatrixXd M = Eigen::MatrixXd(3,10); // make each column homogeneous Eigen::MatrixXd Mh = M.colwise().homogeneous(); // make each column dehomogeneous Eigen::MatrixXd Md = Mh.colwise().hnormalized().topRows(Mh.rows(…
#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #include <Eigen/Geometry> #pragma GCC diagnostic pop</eigen/geometry>
C++11 functions std::to_string(X) converts X to std::string. std::stoi(str) converts std::string str to int type data std::stof(str) converts std::string str to float type data std::stod(str) converts std::string str to double type data
std::iota: assigns successive values to a container include <numeric> std::iota( v.begin, v.end(), val ); // v[0] = val; // v[v.end()-1] = val + v.size()-1; std::random_shuffle: randomizes the order of elements of random access containers. include <algorithm></algorithm></numeric>…
I made a repository that uses CodeSynthesis XSD with CMake. The CMakeLists.txt calls XSD and generates C++ classes so that we can avoid calling XSD from terminal, meaning the compilation is fully automatic. The CMakeLists.txt does find nec…
I implemented a set of random value generator classes and the code is on my github repository The class is used as follows: [code lang="cpp"] // int Uniform distribution [0,100] RandomUniformInt ui(0, 10); // double Normal distribution N(0…
Here's a minimum code of OpenMP with CMake. The code outputs "OpenMP: ON" if OpenMP is available and "OpenMP: OFF" otherwise. CMakeLists.txt: [code lang="cmake"] cmake_minimum_required(VERSION 2.8) set(PROJ_NAME OpenMPtest) PROJECT(${PROJ_…
following the guidance, it's easy to build VTK 6.1.0 on Ubuntu 14.04 [code language="bash"] wget http://www.vtk.org/files/release/6.1/VTK-6.1.0.tar.gz wget http://www.vtk.org/files/release/6.1/VTKData-6.1.0.tar.gz wget http://www.vtk.org/f…
Tensor Power iteration using Blitz++. The following code is too dirty. [code lang="cpp"] include <iostream> include <blitz/array.h> include <random/uniform.h> include <time.h> include <ctime> include <algorithm> ifdef BZ_HAVE_STD include <fstream> else include <fstream.h> endif blitz::firstIndex i1;…</fstream.h></fstream></algorithm></ctime></time.h></random/uniform.h></blitz/array.h></iostream>
I made a repository for enabling PTAM compilable on Ubuntu 14.04 with CMake on github. The script file is based on PTAM-linux-cv2.3(https://github.com/nttputus/PTAM-linux-cv2.3) and assumes that you also use it. The contained files are: PT…
This post is for compiling PTAM (Parallel Tracking and Mapping) on Ubuntu 14.04. As mentioned on the web, a cool guy published a set of script, patch, etc for PTAM easy-compile on Ubuntu and the files are available on this github. However,…
VXL is a C++ library for computer vision researches. The core libraries in VXL are: vnl for numerical algorithms vil for image handling vgl for geometry etc. VXL can be installed via package manager as [code lang="bash"] sudo apt-get insta…
There exist several ways to give a std::vector as an array. Suppose we have a vector std::vector vec. The ways are &vec[0] &vec.front() vec.data() supported by C++11 The following code should output as print integer array: 0,1,2,3,4, print…
I implemented CImg hello world that loads an image, display on a CImg window, and save it. The complete code is available on my github. [code lang="cpp"] include <iostream> include <string> include <CImg.h> int main() { std::cout << "run CImg hello world..." << std</cimg.h></string></iostream>…
I implemented some functions those are explained in Blitz++ documentation. The code is on my github.
PTAM/Build/Linux/VideoSource_Linux_OpenCV.ccThis post is to measure the computation time of the previous post, in which I posted a C++ code using Eigen to select columns with N largest norm. My code is available here. Suppose we define a f…
The following code selects columns with N largest norm. The output should be All data and its norm: data[0] = ( 68.0375 -21.1234) norm = 71.2412 data[1] = (56.6198 59.688) norm = 82.2707 data[2] = ( 82.3295 -60.4897) norm = 102.162 data[3]…
lower bound and upper bound of a std::vector can be found by functions lower_bound and upper_bound. The following code finds lower bound and upper bound of a std::vector data. The output should be Raw data: 0 3 7 2 9 1 5 4 8 3 1 2 Sorted d…
The following code initializes 1 and 2 dimensional std::vector with its size and initial value. The output should be declare 1 dimensional vector of size 4 with initial value 3 generated vector is size 4 vector: vec[0] = 3 vec[1] = 3 vec[2…
[sourcecode language="cpp"] template <typename ValueType> struct funcPtr { typedef ValueType (*func)(const ValueType, const ValueType); }; template <typename ValueType> ValueType add( const ValueType a, const ValueType b ) { return a+b; } template <typename ValueType> ValueType sub( const ValueType</typename></typename></typename>…
./configure make pdfevince ./doc/blitz.pdf
Blitz++ is a c++ template library for array manipulation. I'm planning to use this library for some tensor computation. Fortunately, we can install the library via Ubuntu package manager as [code lang="bash"] sudo apt-get install libblitz-…
With Ubuntu package manager, we can install both CodeSynthesis XSD and Xerces-C as [code lang="bash"] sudo apt-get install libxerces-c-dev sudo apt-get install xsdcxx [/code] To generate a class, the command xsdcxx executes code synthesis …
ceres solver 1.9.0 compilation fails with gcc > 4.8.0. The error happens at line 505 in Eigen/src/Cholesky/LDLT.h and the error is typedef 'Scalar' locally defined but not used [-Werror=unused-local-typedefs]A solution is just to comment t…
mlpack compilation fails when LAPACK is not found by cmake. One solutions is to enable mlpack's CMakeLists.txt to find LAPACK. Namely, the solution is to add FindLAPACK.cmake in the directory mlpack-1.0.9/CMake so that cmake can find LAPAC…
Calling the executable of CodeSynthesis XSD from terminal, we will obtain a set of test.hxx and test.cxx files given an XSD file test.xsd. [sourcecode language="bash"] xsd cxx-tree --generate-doxygen test.xsd doxygen -g test.doxygen doxyge…
Following the wiki, we should be able to use CodeSynthesis XSD with CMake. What the FindXSD.cmake does is that call the executable of CodeSynthesis XSD and give an .xsd file, say test.xsd, the executable. pre-defined function generates a s…
My previous post mentions how to install Boost C++ library 1.53 on Ubuntu, specifically Ubuntu 12.04 LTS since Boost installation using official package manager installs Boost 1.37 (or later but younger than 1.50). Installation on Ubuntu 1…
CodeSynthesis XSD is an XML Schema to C++ data binding compiler, which generates C++ classes representing given xsd file(s) as a pair of cxx and hxx files. We can either build by ourselves or install using package manager, see here. To ins…