06-01-2010 07:10 PM
Hi all,
Would it be possible to use the open source C++ library "Computational Geometry Algorithms Library" (here) in LabVIEW?
The package can be downloaded here.
Apparently: "In order to build the Cgal libraries, you need a C++ compiler."
What's involved to get these functions to work in LV?
Thanks,
Battler.
06-02-2010 12:38 AM
It's possible but with two constraints. The first is legal combined with commercial as, as I understand it, only the kernel part of CGAL is LGPL licensable which would allow you to link to a DLL from within LabVIEW without open sourcing your entire application. The rest of the library is what they call QGL licensed, requiring any application making use of its functionality to be fully open sourced.
If this is not a killer criterium already for you then there is the next obstacle. The library has a C++ API. LabVIEW's Call Library Node can only interface to standard C functions (and before you ask, a C++ Interface Node in LabVIEW is no option since each C++ compiler has a rather different idea of how the binary API of its object interfaces should look like).
So you will have to write a wrapper DLL that translates the C++ interface in a clean standard C function interface, or alternatively you could consider writing an ActiveX wrapper and interface it in that way to LabVIEW, however that would limit your use of the library to Windows only. Both of these aren't very difficult to do if you know a bit about C compilers but it could be a lot of work depending on the size of the library API.
06-02-2010 12:53 AM
Thanks Rolf.
I am uncertain as to exactly what has been provided by the package. I see CPP and H files.
Do you have an example of preparing such a "wrapper DLL". I know nothing about C++ compilers (I can read and translate C code) but am certainly prepared to put in the effort.
I need to use the tool for segment intersection. I have written my own but it is not robust for floating point.
I will start researching based on your suggestion. Any further help/direction/examples are appreciated.
Battler.
06-02-2010 01:38 AM - edited 06-02-2010 01:39 AM
Lets take this simple (and fairly useless) C++ API:
class Integer
{
attributes:
int i
methods:
setValue(int n)
Integer getValue(void)
Integer addValue(Integer j)
}
Now we want to wrap it into a C library:
#include <whatever.h>
/* This could be in a seperate header to separate the interface definition from the implementation */
typedef struct _MY_INTEGER *MyInteger;
#define "C" {
MyInteger MyInteger_create(int32 value);
void MyInteger_setValue(MyInteger obj, int32 value);
int32 MyInteger_getValue(MyInteger obj)
int32 MyInteger_addValue(MyInteger obj, int32 j)
}
/* Actual implementation */
MyInteger MyInteger_create(int32 value)
{
return (MyInteger)new(Integer);
}
void MyInteger_setValue(MyInteger obj, int32 value)
{
((Integer)obj)->setValue(value);
}
int32 MyInteger_getValue(MyInteger obj)
{
return ((Integer)obj)->getValue();
}
int32 MyInteger_addValue(MyInteger obj, int32 j)
{
return ((Integer)obj)->addValue(j);
}
This is just an example to show the principle and it has not been compiled or tested or whatever in any way, so there are syntax errors bugs and possible other ugly animals in there
06-02-2010 01:56 AM
Thanks Rolf.
I found this LV Wiki Page which is useful and has an example such as you have provided.
So basically I need to build a DLL using the .CPP files and a compiler. Then I use the .H files to access the functions, but I need to write a wrapper DLL to translate it. Sound right?
Now onto compilers. Has anybody tried to get this GNU compiler to work? It's very confusing. I have to build the compiler??
In order to build the Cgal libraries, you need a C++ compiler. Cgal 3.6 is supported for the following compilers/operating systems:
compiler | operating system |
Gnu g++ 3.4, 4.0, 4.1, 4.2, 4.3, 4.4 10 | Solaris 2.6+ / Linux 2.x / MacOS X |
MS Windows 95/98/2000/XP/NT411 | |
MS Visual C++ 8.0, 9.0 (Visual Studio 2005 and 2008) 12 | MS Windows 95/98/2000/XP/NT4/Vista11 |
Note that neither prerelease versions nor repository snapshots of GCC are supported.
06-02-2010 07:07 AM
I always use Visual C 6.0 to create DLLs for Windows. If you want to create Windows compatible DLLs using GCC you have to get either MinGW or CygWin. Standard GCC even if compiled for Windows platform does not be fully compatible.
I'm positive that there are already precompiled packages of all these compilers so you don't have to copile them yourself.