The necessity of nerding in smartphone brainscanning

Posted on

Screenshot from Necessitas QT Creator with the smartphone brainscanner running.
Screenshot from Necessitas QT Creator with the smartphone brainscanner running.

So I am trying to get the smartphone brainscanner al la Arek working with the help of Carsten Stahlhut and Arek. The Android QT development may take place in IDE. When you install that in /opt as root you may experience that the file permissions are all messed up. You may require something like “$ sudo find -perm /u=x -exec chmod a+x {} \;” and similar to execute the programs and directories and be able to read the files. Also if “/opt/NecessitasQtSDK/android-sdk/.android” is not readable for the developer then problems around the “debug.keystore” and developer signing of the application may arise.

Arek has nicely setup a github site with some applications. However, the git distributions do not contain all that you need. The sbs2-Brain3D program with the fancy 3D model is not there and an Emotiv decryptor module is also needed, which is (also) not publicly available.

Before you can get the programs running, the smartphone may need to be modified. There is hidraw device reading. The Nexus 7 I have now runs Arek’s 3.1.10-hopbeat-g009b6d1 kernel and has the SuperSU program installed. For unlocking and other steps I followed the description on Nexus 7 (android) on the GitHub smartphone website.

I have not been able to make the program running in the Android development emulator environment. QT is a showstopper as I have not been able to get Ministro working with something like “/opt/NecessitasQtSDK/android-sdk/platform-tools/adb install ~/Downloads/Ministro\ II.apk”. Other older version of Ministro neither worked.

Also I have problems with the program on an Android device, – a Nexus 7.

After building the sbs3-Brain3D program and deployment on the Android device I get a immediate crash with the sbs3-Brain3D program. Among the last thing I hear from the program is: “I/WindowState( 475): WIN DEATH: Window{424d4810 u0 org.kde.necessitas.example.sbs2_Brain3D/org.kde.necessitas.origo.QtActivity}”, “Failed looking up window” and “java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@42aeb818 does not exist”. My googling did not bring me an understanding of what is the problem.

So I tried to enable building for desktop. If compiler is missing: Menu, Options, Kits, Device type: Desktop-QT 4.8.1 in PATH (SYSTEM) and selecting Compiler GCC (x86 64bit). Left panel, Projects, Add kit. Building yields “libudev.h: no such file or directory.” is available in libudev-dev: $ sudo aptitude install libudev-dev.

One step further I get “skipping incompatible sbs2emotivdecryptor-build-…” and subsequent “cannot find -lsbs2emotivdecryptor”. So the decryptor library is not built for desktop? With the sbs2emotivdescriptor in the Necessitas QT Creator I can with projects “Add kit”, but then during compilation run into “Cannot find Makefile. Check your build settings.” However, the Makefile is available in the build directory and an ordinary ‘make’ in the directory compiles and links the library. A right click in the projects and “Run qmake” will also “exited normally”. Erasing automatically insert library inclusion in the .pro file and right click project, “Add library” and adding sbs2emotivdecryptor. With building I get “glmReadOBJ() failed: can’t open data file
“/home/fnielsen/smartphonebrainscanner2_data/mesh_ctx_5124_normals.obj”. So where do this comes from? Are we missing a mesh of the text with 5124 vertices? “$ ln -s projects/smartphonebrainscanner2-core/sbs2_data/
smartphonebrainscanne2_data”? No! “$ locate mesh_ctx”? No! Then what about “$ find . -name “mesh_ctx_5124_normals.obj”. No!

In matlab I try filename = ’emotiv_SPMleadfields’; Semotiv = spm_eeg_load(filename); headmodel = 1; Xvert = Semotiv.inv{headmodel}.mesh.tess_mni.vert / 1000; faces = Semotiv.inv{headmodel}.mesh.tess_mni.face; and there a size(Xvert) reports 5124 x 3.

And a “$ egrep -r “mesh_ctx_5124_normals.obj” ~/projects/sbs2-Brain3D/*” shows the perpetrator to be “~/projects/sbs2-Brain3D/glwidget.cpp”. The loading happens in model.cpp in the “Model::load” method where “glmReadOBJ” is called, so this is the Wavefront .obj file which is in Wikipedia country.

With a new file in the Brede Toolbox called brede_write_obj.m and back in Matlab with S.vertices = Xvert; S.faces = faces; S.type = ‘sur’; S.filename = filename; it is possible to write “brede_write_obj(S, ‘filename’, ‘mesh_ctx_5124_normals.obj’)”

With “$ sudo aptitude install blender” and import obj file I get “IndexError: list index out of range”. I got “grep “v”
mesh_ctx_5124_normals.obj | wc” = 5124 vertices. A Python oneliner tells that my Matlab script is erroneously zero-indexed:
“max(map(lambda s: max(map(int, s.split()[1:])), filter(lambda s: s[0]==’f’, open(‘mesh_ctx_5124_normals.obj’).readlines())))” gives 5123. So with a corrected brede_write_obj.m I can see the surface in blender (it is hiding in the default center box).

But “$ ln -s vertface_brain_reduced.obj mesh_ctx_5124_normals.obj” will apparently also do a trick to make a bluish flickering rotating brain appear.

Back to the android device: “$ /opt/NecessitasQtSDK/android-sdk/platform-tools/adb push
mesh_ctx_5124_normals.obj /mnt/sdcard/smartphonebrainscanner2_data/” and we are running! Well, well, – without the emotiv device attached yet.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s