CGAL Point in Polyhedron Algorithm

The “point in polygon” or “point in polyhedron” is a classic computer graphics problem. The goal is to determine whether a given point is inside a polygon (in 2D) or a polyhedron (in 3D).

One solution to the problem is shooting a ray originating from the said point to an arbitrary direction and determine the number of intersections of the ray with the polygon or polyhedron. If the ray intersects the shape an odd number of times, then the point is inside the shape. Otherwise it is outside the shape.

There are problems associated with this approach. An important edge case is when the point is on the surface of the shape. Also, it is commonly advisable to shoot multiple rays instead of just one, and then do a majority voting.

Luckily, in CGAL the point in polyhedron test is very simple and you don’t have to worry about the edge cases! You can do the test using the Side_of_triangle_mesh class. A code snippet is shown below:

 

You can also determine whether the point is on the surface of the polyhedron or not.

Undo a Git Commit on GitHub

In case you’ve pushed an unwanted commit to GitHub (or any upstream Git repository), you can simply undo it. To do so, move the HEAD to the commit that you want to undo to and then run the following command:

git push -f origin HEAD^:master

Prevent Unity 3D Text from Always Appearing on Top while Maintaining Rich-Text Support

The TextMesh component in Unity has an annoyance which causes the text that it displays be rendered always on top. This is useful if you want your GUI elements to always appear on top but if you want to have a 3D text attached to a 3D object, this creates the weirdest results!

There’s already an entry in Unity’s wiki page detailing how the issue can be worked around using a custom shader. This YouTube video shows the application of the mentioned method (it’s quite useful even though the guy is speaking Russian!). Also, if you are not sure how a texture can be built using a font, follow the steps described in this awesome blog post.

The issue with the above method is that it messes with the rich text support of TextMesh. Essentially, all text will be rendered with the specified color of the created material. I found a better custom shader in the Unity 3D forum! This solved my z-depth issues.

SimpleScalar Installation Under Windows

Installing the SimpleScalar simulator is relatively straightforward under Linux. For Windows installation, the Cygwin toolchain is required. Grab the latest Cygwin installer (setup-x86_64) from here: https://cygwin.com/setup-x86_64.exe (note that this is intended for 64-bit machines).

After running the installer, just proceed through the wizard. The default installation directory is C:\cygwin64. When selecting a mirror website, usually mirrors.kernel.org is the fastest mirror. Select where you want the Cygwin packages to be installed. In the package installation window, select the following packages under Devel:

  1. gcc-core
  2. gcc-g++
  3. make

Also, under Web select the w3m package (this will make the download process much easier). The installer will say that additional dependencies are needed. Click “Yes” to install the additional dependency packages.

Note: To install a package, you can simply click on the circular arrows next to the name of the package. The text next to the arrow will cycle between “skip” and the desired version of the package. Feel free to install the latest available version of each of the packages above.

After the installation of Cygwin is finished, simply open a Cygwin bash terminal (by opening “Cygwin64 Terminal” from the installed programs in Start menu) and follow these steps (credits go to Ramya Pradhan):

  1. Download SimpleScalar:
     w3m http://www.simplescalar.com/agreement.php3?simplesim-3v0e.tgz
    Use the arrow keys to navigate to the bottom of the page to accept the terms. Move the cursor to ‘I Agree’ and hit enter. You will see a message ‘(Download) Save file to: simplesim-3v0e.tgz’ at the bottom of the page, hit enter to save file in the current directory. To get out of the browser, press q.
  2. Compile SimpleScalar
     tar xvzf simplesim-3v0e.tgz
     cd simplesim-3.0
     make config-pisa
     make
  3. Test the installation using
     ./sim-safe tests/bin.little/test-math

Installing SciPy, NumPy and matplotlib Under Cygwin

Today I tried installing these modules under Cygwin with pip. The whole thing took a few hours to figure out thanks to crappy bundled packages that pip fetches and lack of consistency between helps available online.

To install pip, you need to have python3-setuptoolsinstalled. Then using the easy_install3 pip command you can install pip.

After that, you need to have liblapack-devel and libopenblas installed via Cygwin’s package manager (SciPy depends on them). You also need to have gcc-fortran, python-gtk2, tcl-tk, libpng, pkg-config and a bunch of other stuff (that pip installer complains about) installed. The dependencies that pip complains about are straightforward (just mark them for installation in Cygwin’s installer).

Running pip -v install numpy and pip -v install matplotlib should get you those packages without much headache. The most important thing is that as of SciPy v 0.16.1, there seems to be some error in SciPy’s C files that prevents compilation and installation. I was able to get it to install using pip -v install scipy==0.15.1.

After installation, you may notice that you can’t plot stuff using mathplotlib’s pyplot module. To fix that, you need to have XWinServer running and should configure matplotlib to use tkagg backend. To do this, locate the file matplotlibrc and change backend      : agg to backend      : tkagg. The plots should show now!

Essential Cygwin Development Packages

Whenever I want to do a new Cygwin install on Windows, I’d have to just keep scrolling the Cygwin installer window to find the packages that I use frequently. I decided to compile a list of packages I use and put them here so that I wouldn’t have to waste time on it again in the future.

  • Devel:
    1. cmake
    2. cmake-gui
    3. gcc-core
    4. gcc-g++
    5. gdb
    6. git
    7. make
  • Libs:
    1. libboost-devel
  • Python:
    1. python3
  • Shells:
    1. chere (for shell integration)
  • X11: (Needed for cmake-gui)
    1. gnu-free-fonts
    2. xinit

Additionally, I let Cygwin’s installer to auto-install additional required packages. These packages should be sufficient for compiling C/C++ code under Windows. In order to enable shell integration for bringing up a Cygwin terminal, this command should be executed from Cygwin terminal (using administrator privileges) after installation:

chere -i -t mintty

“sys/time.h” Replacement for Windows

Some C/C++ code targeted for GNU family compilers fail to compile under Windows due to the dependency on sys/time.h header file. The repository here has provided a neat implementation for it. Basically you need these three files: time.h, times.h and times.cpp. I have included them here (in case the repository ever went dead). Note that this is not my code and the original license of the code was LGPL.

sys/time.h:

sys/times.h:

sys/time.cpp:

 

 

 

CheckedListBox throws “Out of Memory Exception” When Adding New Items

I was using WinForm’s CheckedListBox control a few minutes ago and my application was crashing with an out of memory exception. This was happening on the line where new items were being added to the CheckedListBox. It did not make any sense at all, since I was only adding the second item to the control. Also, I was pretty sure I wasn’t being even close to running out of memory! 😀

By some happy coincidence, I figured out what the problem was. Some of the items I was adding to the list would return null in their ToString() method. Turned out that was what was causing the exception. I simply made sure that ToString() would not return null values and that solved the issue. .NET can sometimes be stupid 😀

I guess it is advisable to always write the ToString() methods with a blank string as the starting point (eg. return "" + this.ID so that it wouldn’t break in case ID is null).

“Unresolved external symbol” Errors when Compiling CGAL 4.7 Under Windows with Visual Studio 2013

I spent hours trying to compile CGAL 4.7 with Visual Studio 2013. Everything compiled on the first try with Visual Studio 2010 but for some reason I was unable to get it working with VS2013. CMake would create the solution files just fine and was able to resolve everything. However, when I attempted to build the confiugured solution I would get lots of “unresolved external” errors like this:

unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)

I followed this guide to the letter. I was sure Boost was being discovered just fine. I had everything in my PATH. After a while I figured out what my problem was! Although I wanted to build 64-bit binaries, I was selecting Visual Studio 12 2013 as my generator!! I was skimming every time I was selecting it so I wasn’t paying attention! I should’ve in fact selected Visual Studio 12 2013 Win64 as my generator. Doing that solved the problems.

Rendering Multiple OpenGL 2D Textures, Only the First One Is Rendered

Exactly a month ago I was dealing with the problem of rendering some text on the screen using the font + texture rendering method. The problem I had was only the first text block was rendered to the screen. After a little bit of digging around I found this question on StackOverflow. Although the answers there did not solve my problem, I realized that the problem was caused by having depth testing enabled while rendering the 2D blocks. All I had to do was place a call to glDisable(GL_DEPTH_TEST).

Older posts «

» Newer posts