Install MITSUBA on Linux 16.04

==============================================================================

wget https://www.mitsuba-renderer.org/repos/mitsuba/archive/tip.zip

unzip tip.zip

cd mitsuba-af602c6fd98a/

cp build/config-linux-gcc.py config.py

apt-get install scons qt4-dev-tools libboost-all-dev libglewmx-dev libpcrecpp0

scons –j 8

**************************************************************************

Compilation error due to introuvable file “bind_member_variable.hpp”

SOLUTION: modify « src/bsdfs/irawan.h » :

Line : #if BOOST_VERSION >= 106000

Becomes : #if BOOST_VERSION >= 105800

RE : http://stackoverflow.com/questions/36807135/how-to-install-bind-member-variable-hpp-in-ubuntu-16-04

**********************************************************************************

Scons –j 8

**********************************************************************************

Error when compiling « DScalar1 »

SOLUTION: modify « include/mitsuba/core/autodiff.h »

Add the following definition in the  “DScalar1”:

inline DScalar1& operator*=(const DScalar1 &v) {

    grad = v.grad * value + grad * v.value;

    value *= v.value;

    return *this;

}

RE : https://github.com/mitsuba-renderer/mitsuba/issues/3

Gram matrix

Let’s say you have a set of vectors U = (u1,u2,u3) and V = (v1, v2,v3). The Gram matrix will be the inner product between one vector and all others (including itself).

Example:

u1 = [1 2 3]; u2 = [4 5 6]; u3 = [7 8 9]

V = [u1′ u2′ u3′] where V’ denotes the transpose of V.

G = V’ * V

G = [ u1*u1 u1*u2 u1*u3
u2*u1 u2*u2 u2*u3
u3*u1 u3*u2 u3*u3]

G = [ 14   32   50
32   77 122
50 122 194]

The determinant of G is 0 since u1 u2 and u3 are linearly dependent.

Get pixels from image given their indexes or subscripts (MATLAB)

Let’s say you have the following image:

im(:,:,1) = [8 1 6; 3 5 7; 4 9 2]
im(:,:,2) = [9 2 7; 4 6 8; 5 10 3]
im(:,:,3) = [10 3 8; 5 7 9; 6 11 4]

and you want the pixels im(1,1), im(2,3), im(3,4). So the vector of subscripts will be:

p_sub = [1 1; 2 3; 3 3];

To convert those subscripts to index run

p_index = sub2ind(size(a),p_sub(:,1),p_sub(:,2));

You can run the following code to get the result:

im = reshape(im(:),[],3);

Now the image has N lines (N is the number of pixels of the original image) by 3 columns (R,G,B). To get the pixels you wanted now you only have to run this:

im(p_index,:)

The result will be

ans =

   8    9   10
   7    8    9
   2    3    4

MatConvNet: libstdc++.so.6: version GLIBCXX not found

If your Matlab is struggling to find the right libstdc++.so.6 you can try the following:

  1. locate libstdc++.so.6
    • $ locate libstdc++.so.6
  2. It can be located in:
/usr/lib/i386-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6

3. Once you’ve found it you can run matlab with the following command (changing the libstdc++.so.6 according to your specific location):

LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" matlab

Point Cloud ptr visualizer

This code allows you to visualise a pointer to a point cloud

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer 
       (new pcl::visualization::PCLVisualizer ("3D Viewer"));

viewer->addPointCloud<pcl::PointXYZRGBA> (pc_xyzrgba, "sample cloud");
viewer->addCoordinateSystem (1.0);
viewer->initCameraParameters ();

while (!viewer->wasStopped ())
{
    viewer->spinOnce (100);
    boost::this_thread::sleep (boost::posix_time::microseconds (100000));
}

Force CMake to find alternative package installation

Let’s say you have a package installed in the standard location (I will use the Point Cloud Library -PCL- version 1.8 as example).  After the find_package command the variable PCL_DIR will be set to “/usr/local/share/pcl-1.8”.

But if you have another installation of PCL in “/home/myname/pcl-1.8.0” for example, you can force find_package to load your alternative installation with

find_package(PCL 1.8.0 
 PATHS /home/myname/pcl-1.8.0/share/pcl-1.8
 NO_DEFAULT_PATH
 )

This way, the variable PCL_DIR will be set to “/home/myname/pcl-1.8.0/share/pcl-1.8”.

Make link between files (ln command) in /usr/lib/x86_64-linux-gnu and /usr/lib64

Let us say you have a bunch of files (shared object files) inside a folder, but some program being installed is looking after them in the wrong place. It would generate an error similar to this:

No rule to make target '/usr/lib64/libICE.so', needed by 'lib/libpcl_io.so.1.7.2'.

If you run the following command

locate libICE.so

and you receive the following output

/usr/lib/i386-linux-gnu/libICE.so.6
/usr/lib/i386-linux-gnu/libICE.so.6.3.0
/usr/lib/x86_64-linux-gnu/libICE.so
/usr/lib/x86_64-linux-gnu/libICE.so.6
/usr/lib/x86_64-linux-gnu/libICE.so.6.3.0

you can then create a link to the actual file with

sudo ln -s /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib64/libICE.so
sudo ldconfig

It`s done!

BONUS PART:

If you have a lot of .so files in /usr/lib/x86_64-linux-gnu and want to create a link for everyone inside it into /usr/lib64, just run

sudo ln -s /usr/lib/x86_64-linux-gnu/* /usr/lib64/
sudo lnconfig

Using CMake (part 3) – Adding Tests

Create a tutorial.cxx file with the following code:

#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(int argc, char* argv[])
{
   if(argc < 2){
       cout<<"Usage: "<<argv[0]<<" number"<<endl;
       return 1;
   }
   cout<<"The sqrt of "<<argv[1]<<" is "<<sqrt(atof(argv[1]))<<endl;
   return 0;
}

Create a CMakeLists.txt in the same folder of tutorial.cxx with the following code:

cmake_minimum_required(VERSION 2.6)
Project(Tutorial)

include(CTest)

include_directories("${PROJECT_SOURCE_DIR}/MathFunctions")
add_subdirectory(MathFunctions)

add_executable(Tutorial tutorial.cxx)
target_link_libraries(Tutorial MathFunctions)

# does the application run 
add_test (TutorialRuns Tutorial 25) 

# does it sqrt of 25 
add_test (TutorialComp25 Tutorial 25) 
set_tests_properties (TutorialComp25 PROPERTIES PASS_REGULAR_EXPRESSION "The sqrt of 25 is 5") 

# does it handle negative numbers 
add_test (TutorialNegative Tutorial -25) 
set_tests_properties (TutorialNegative PROPERTIES PASS_REGULAR_EXPRESSION "The sqrt of -25 is -nan") 

# does it handle small numbers 
add_test (TutorialSmall Tutorial 0.0001) 
set_tests_properties (TutorialSmall PROPERTIES PASS_REGULAR_EXPRESSION "The sqrt of 0.0001 is 0.01") 

# does the usage message work? 
add_test (TutorialUsage Tutorial) 
set_tests_properties (TutorialUsage PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")

In order to keep the build files easy to remove, create a build folder by running

mkdir build && cd build

Run Cmake and then make

cmake .. && make

To do the tests, run

ctest

And the result should be similar to

 Start 1: TutorialRuns
1/5 Test #1: TutorialRuns ..................... Passed 0.00 sec
 Start 2: TutorialComp25
2/5 Test #2: TutorialComp25 ................... Passed 0.00 sec
 Start 3: TutorialNegative
3/5 Test #3: TutorialNegative ................. Passed 0.00 sec
 Start 4: TutorialSmall
4/5 Test #4: TutorialSmall .................... Passed 0.00 sec
 Start 5: TutorialUsage
5/5 Test #5: TutorialUsage .................... Passed 0.00 sec

100% tests passed, 0 tests failed out of 5

Total Test time (real) = 0.05 sec