Remeshing of a triangular mesh for making high quality Delaunay triangulation? - matlab

I have a triangular mesh of the brain surface. I want to remesh it to a high-quality Delaunay triangulation. I'm seeking an easy and straightforward method.

pygalmesh interfaces CGAL and has surface remeshing. Install CGAL, then install pygalmesh with
pip install pygalmesh
Then you can use
pygalmesh-remesh-surface lion-head.off out.vtu -e 0.025 -a 25 -s 0.1 -d 0.001
on the command line.

I'm not sure if C++ is an option for you but the CGAL library provides such a functionality. See this package, see in particular this example.
If you want to use a GUI, you can use the CGAL polyhedron demo. You can compile it yourself by compiling the code in demo/Polyhedron from a release or use the pre-compiled windows demo available: demo + dlls to be extracted in the directory of the demo. Load your input mesh, select it and click on Operations -> Tetrahedral Mesh Generation -> Create a Surface Triangle Mesh

You mean that you want to resample the mesh? I've had some success using the trimesh package: https://github.com/mikedh/trimesh
Check out trimesh.remesh in particular.

You can use JIGSAW for surface (re)meshing. Similarly to CGAL, it offers various Delaunay-based methods to discretise planar/surface/volume domains, with a focus on high quality mesh creation.
Though JIGSAW itself is a c++ code, you can run it directly from either MATLAB or Python. To install, you'll need a c++ compiler and cmake. Click through to GitHub for additional instructions and examples.
**I'm a developer of JIGSAW, so keep this in mind I guess! Otherwise, in addition to CGAL, the MMG or Geogram packages may also be of interest.

Related

How to make a complex robot model in webots?

I make my robot using cyberbotics webots. I can’t figure out how to make a beautiful 3D model. At least at the mantis hexapod level.
I understand that you can import ready-made fraud only in vrml97 format, but it is not supported by fusion 360 and other programs.
But in webots itself, I did not find a way to build a model more complicated than using cubes, pyramids, and other simple objects.
There was also an idea to assemble a model from a large number of rectangles using grouping, but it seems to me that such a model will greatly slow down.
Is it possible to see how the finished robots are made, and make changes to them?
The node you are looking for is the IndexedFaceSet https://www.cyberbotics.com/doc/reference/indexedfaceset, it allows you to efficiently model a shape using a set of triangle faces, you will find an example of this in this simulation world: https://cyberbotics.com/doc/guide/samples-geometries#high_resolution_indexedfaceset-wbt
One possible workflow to do this is to use Blender to create your mesh and then use the Webots exporter to export it to Webots: https://github.com/cyberbotics/blender-webots-exporter

Extracting 2D surface from 3D STEP model

I'm trying to figure out a good way to programmatically generate contours describing a 2D surface, from a 3D STEP model. Application is generating NC code for a laser-cutting program from a 3D model.
Note: it's easy enough to do this in a wide variety of CAD systems. I am writing software that needs to do it automatically.
For example, this (a STEP model):
Needs to become this (a vector file, like an SVG or a DXF):
Perhaps the most obvious way of tackling the problem is to parse the STEP model and run some kind of algorithm to detect planes and select the largest as the cut surface, then generate the contour. Not a simple task!
I've also considered using a pre-existing SDK to render the model using an orthographic camera, capture a high-res image, and then operating on it to generate the appropriate contours. This method would work, but it will be CPU-heavy, and its accuracy will be limited to the pixel resolution of the rendered image - not ideal.
This is perhaps a long shot, but does anyone have thoughts about this? Cheers!
I would use a CAD library to load the STEP file (not a CAD API), look for the planar face with the higher number of edge curves in the face loop and transpose them on the XY plane. Afterward, finding 2D geometry min/max for centering etc. would be pretty easy.
Depending on the programming language you are using I would search for "CAD control" or "CAD component" on Google combining it with "STEP import".

Matlab face alignment code

I am attempting to do some face recognition and hallucination experiments and in order to get the best results, I first need to ensure all the facial images are aligned. I am using several thousand images for experimenting.
I have been scouring the Internet for past few days and have found many different programs which claim to do so, however due to Matlabs poor backwards compatibility, many of the programs no longer work. I have tried several different programs which don't run as they are calling onto Matlab functions which have since been removed.
The closest I found was using the SIFT algorithm, code found here
http://people.csail.mit.edu/celiu/ECCV2008/
Which does help align the images, but unfortunately it also downsamples the image, so the result ends up quite blurry looking which would have a negative effect on any experiments I ran.
Does anyone have any Matlab code samples or be able to point me in the right direction to code that actually aligns faces in a database.
Any help would be much appreciated.
You can find this recent work on Face Detection, Pose Estimation and Landmark Localization in the Wild. It has a working Matlab implementation and it is quite a good method.
Once you identify keypoints on all your faces you can morph them into a single reference and work from there.
The easiest way it with PCA and the eigen vector. To found X and Y most representative data. So you'll get the direction of the face.
You can found explication in this document : PCA Aligment
Do you need to detect the faces first, or are they already cropped? If you need to detect the faces, you can use vision.CascadeObjectDetector object in the Computer Vision System Toolbox.
To align the faces you can try the imregister function in the Image Processing Toolbox. Alternatively, you can use a feature-based approach. The Computer Vision System Toolbox includes a number of interest point detectors, feature descriptors, and a matchFeatures function to match the descriptors between a pair of images. You can then use the estimateGeometricTransform function to estimate an affine or even a projective transformation between two images. See this example for details.

Acquiring coordinates readouts from an optical mouse ala wiimote (MATLAB code)

I plan to get the x-y coordinated reading from an optical mouse. Basically, I want the readout to be something like this but instead of using a Wiimote, I'll be using a standard USB mouse.
I have found quite a good example - [http://www.synbio.org.uk/component/content/article/46-instrumentation-news/1234-interfacing-an-optical-mouse-sensor-to-your-arduino.html]
but sadly it runs on C++ and needs a bridging hardware called Arduino. Though however, it PRINTS out the coordinate rather than putting it into a 'real-time' graphical plot.
I would love if MATLAB can read off the coordinates from the mouse and plot a 'real-time' graph of the coordinates.
Thanks :)
If you have a DLL or DLLs for communicating with your mouse you should be able to persuade Matlab to use it or them. Look at the documentation for loadlibrary.
(Of course, if you are using Linux or Mac OS X replace 'DLL' with 'shared library'.)

iPhone GLGravity example using quaternions

GLGravity iPhone example showing how to use accelerometer and OpenGL suffers from Gimbal Lock problem. I'm wondering is there any code available using quaternion rotation instead of Euler angles? Any help will be greatly appreciated, I'm struggling with this from a long time without having a success ...
It helps to have a good grasp of the theory of things before trying to implement and use it oneself. Below are two introductory articles about using Quaternions for rotations. Both are primarily related to smooth rotation interpolations and avoiding gimbal lock in accumulated rotations:
Gamedev.net - Quaternion Powers
Gamasutra - Rotating Objects Using Quaternions
Now as far as actual code goes, I would suggest getting, and using, an "industry strength" vector math library as opposed to rolling your own. My suggestion would be grabbing the LinearMath part of the Bullet Physics Middleware project. Bullet physics, and the included linear math library, is developed by some of Sony's top engineers and has been in active development for years. It's freely available, not restricted by any license (Zlib license), and is used by professional game developers all over the world. The lib is cross platform/architecture and compiles on anything from iPhone to PS3.
The lib offers a Quaternion class that allows you to create quaternions from euler angles or from rotation about an arbitrary axis, e.g. using setEulerZYX. Once you have your quaternions, there are built in functions for all common operations applicable to them; plus, minus, mul, normalize, slerp and much more.
For actually applying your final quaternion to OpenGL rendering, the Transform class allows you to construct a matrix from a quaternion. The transform class in turn includes a function getOpenGLMatrix that directly gives you a compatible matrix to pass to OpenGL.
The lib also includes a host of other very useful matrix and vector classes and functions.
Grab the latest Bullet dist from google code, or grab just the LinearMath portion of the code directly from subversion using: svn checkout http://bullet.googlecode.com/svn/trunk/src/LinearMath