Page 1 of 1

Help needed with C and C++

Posted: Sat Sep 28, 2013 5:39 pm
by Seymour Clufley
I know this is an unusual request, but the program is freeware. It is Triangle by Jonathan Shewchuk. Unfortunately there doesn't seem to be a compiled exe of it anywhere online. The source code is three .c files and an .h file. Obviously I would do this myself but I really don't know where to begin with C and I have no tools with which to compile these programs. If somebody could do this for me, I would be very grateful indeed. Just to show that I am not totally selfish, this is all part of an effort to write Pb code that will convert 2D SVG graphics into 3D models, and the code will be shared on the forum. There is no code for triangulating (also called tessellating) polygons on the forum so I think many PB users could benefit from Triangle.

Thank you,
Seymour.

Re: Could somebody compile this C program for me?

Posted: Sat Sep 28, 2013 5:48 pm
by Tenaja
Seymour,

I am sorry, but I do not have time to take care of it for you. However, I can point you to a few directions so you can. It has been a while, but I have used the Code::Blocks IDE, which has a download bundled with MINGW C compiler. (I believe that is a GCC.) I suggest this one because in one (large) download you will have an IDE and compiler installed and usable. This is most likely a better bet.
http://www.codeblocks.org/

Another which I have read about lately, but not used, is PellesC. Pelles wrote his own IDE, and improved upon the o/s LCC compiler. This one is probably simpler, and more like PB due to their tight integration.
http://www.smorgasbordet.com/pellesc/

Re: Could somebody compile this C program for me?

Posted: Sat Sep 28, 2013 6:15 pm
by IdeasVacuum
.....The c files are pretty old -the code needs updating to compile an exe, requires a fair bit of time to do that. Also, there are some apparently non-standard libs included (non standard in that Triangle was developed on Unix and we want to compile on Windows)
In Triangle.c: sys/time.h Probably not a problem to replace the code that depends on this file.
In ShowMe.c (Seperate project): X11/Xlib.h, X11/Xutil.h, X11/Xatom.h

However Seymour, triangulation of this kind is intended for really complex Objects, mechanical engineering components etc. If you use it for your shapes you will have thousands of unnecessary triangle faces.........

Re: Could somebody compile this C program for me?

Posted: Sat Sep 28, 2013 7:15 pm
by jassing
I got triangle.c to compile no problem, I'll dig up the xlib files and compile the showme.c ... give me a bit.
---

They both compiled w/o issue (no errors or warnings).

Binary (exe) and resultant demo files can be downloaded here
however, when I ran the example, showme was unable to run.
Opening &.node.
Error: Cannot access file &.node.
Error: Cannot open display.
and it exited/returned 1

Re: Help needed with C and C++

Posted: Sat Sep 28, 2013 7:36 pm
by Seymour Clufley
That would be very helpful, Jassing. I did find the QHull utility and got it to work with PB, only to discover that it can't handle concave polygons, only convex ones. That was when I posted this thread about Triangle, which seems to be able to handle anything.
IdeasVacuum wrote:However Seymour, triangulation of this kind is intended for really complex Objects, mechanical engineering components etc. If you use it for your shapes you will have thousands of unnecessary triangle faces...
I'm aware of that danger, IV. This is why I've been looking around for other solutions. I found a library, PolyPartition, and from the images it seems to triangulate polygons very efficiently. And my polygons are simpler than that one.

Using Dev C++ I've managed to compile PolyPartition. But now I need to work out how to use it! There are no examples supplied. The guy just says "For input parameters and return values see method declarations in polypartition.h". Here is the method I'm interested in:
int Triangulate_EC(TPPLPoly *poly, list<TPPLPoly> *triangles);
The program has been compiled as a console DLL. It's been many years since I used a DLL! Can anyone tell me how one would call that function from a PB program?

ED...

Code: Select all

lib = OpenLibrary(#PB_Any,"C:\test\PolyPartition.dll")
If lib
  *func = GetFunction(lib,"Triangulate_EC")
  Debug "FUNC: "+Str(*func)
  CloseLibrary(lib)
Else
  Debug "Could not open DLL!"
EndIf
*func comes out as 0 here.

I've also tried CountLibraryFunctions() and ExamineLibraryFunctions() - both come out as 0.

Re: Help needed with C and C++

Posted: Sat Sep 28, 2013 8:40 pm
by jassing
Seymour Clufley wrote:That would be very helpful, Jassing.
See my previous post for a download link. Unfortunately, showme didn't work as expected... But I'm out of my depths when it comes to x11 stuff....

Re: Help needed with C and C++

Posted: Sat Sep 28, 2013 9:31 pm
by IdeasVacuum
@jassing, did you replace the insecure C functions with secure ones?

Re: Help needed with C and C++

Posted: Sat Sep 28, 2013 9:37 pm
by jassing
IdeasVacuum wrote:@jassing, did you replace the insecure C functions with secure ones?
I changed only the location of the xlib files; otherwise, I changed nothing...

Re: Help needed with C and C++

Posted: Sun Sep 29, 2013 3:12 pm
by kns
Both compiled with a full installation of Cygwin (www.cygwin.com).

1. edit makefile - removing "-DLINUX"
2. type "make"

Re: Help needed with C and C++

Posted: Sun Sep 29, 2013 3:41 pm
by jassing
kns wrote:Both compiled with a full installation of Cygwin (http://www.cygwin.com).

1. edit makefile - removing "-DLINUX"
2. type "make"
did showme work?

Re: Help needed with C and C++

Posted: Sun Sep 29, 2013 3:54 pm
by kns
jassing wrote:
kns wrote:Both compiled with a full installation of Cygwin (http://www.cygwin.com).

1. edit makefile - removing "-DLINUX"
2. type "make"
did showme work?
I haven't looked at what this code is meant to do...however, typing './showme' generates a short help screen of options/arguments. It appears to work, at least to that point.

Edit: Yes, once the Cygwin XServer is started showme works.

Edit2: The Cygwin XServer might be a bit flakey when starting and launching an XTerm. There is also XMing and http://mobaxterm.mobatek.net/ among others.

-- starting xterm: https://www.dropbox.com/s/59jvkep0gxu8q9i/xterm.png

-- showme: https://www.dropbox.com/s/t34n72jnwtxc8 ... 113309.png

Re: Help needed with C and C++

Posted: Sun Sep 29, 2013 4:25 pm
by jassing
well; if you read the readme -- it shows a simple example, in the archive was a test file -- showme would run for me too; it just wouldn't process the file.

Re: Help needed with C and C++

Posted: Sun Sep 29, 2013 4:32 pm
by kns
jassing wrote:well; if you read the readme -- it shows a simple example, in the archive was a test file -- showme would run for me too; it just wouldn't process the file.
See above. You need an XServer running.

Re: Help needed with C and C++

Posted: Mon Sep 30, 2013 12:28 am
by Seymour Clufley
I want to thank everyone who gave advice in this thread or compiled these two programs. When I asked for this help yesterday morning I really did think it was necessary. However, I have since had a go at the triangulation problem myself and I seem to have cracked it.

I do not ask people to compile C++ programs for me very often - in fact it's the first time I've ever done it - so please don't think it was too selfish of me. It just seemed, at the time, the only way to obtain a solution.

Thanks again.

Re: Help needed with C and C++

Posted: Mon Sep 30, 2013 12:39 am
by jassing
glad you got it sorted out.
as it happened, I was working on C code that day, (for helping a friend in a remote research facility, which I think is pretty cool in and of itself) and there was talk of porting to unix; so it was good practice.

if you need help again, feel free to PM me