On 12/24/2012 01:16 PM, Kene Meniru wrote:
Hello: I am writing a program that is made up of a collection of POV-Ray
macros. POV-Ray is available at povray.org. It is a ray-tracing program that
reads a scene description language (SDL) to create photo-realistic images.

I know that program :)

At this time my program (for modeling building information) is so huge that
I am finding it difficult managing the macros and I am not even near
completion.

I never got much further than simple solidly coloured images, but yeah, doing that in native SDL is not much fun.
Even for the simple things I make, I found using a Python program to generate 
the SDL file much nicer.

I am hoping to move this program but first I was considering creating a file
format for input and am wondering the best way to approach this.

The usual apporach is to write first some example files, if possible together with the expected output so you get an idea of what the input language should look like, and what your generator should produce.

In your example, it seems that classes get magically defined, which seems a 
next step to look into.

Basically the user writes a text file using certain key words and numbers
and my proposed python program will read this file and call the classes that

My suggestion would be to first do this in pure Python. Python is very good at reading some data files, so branching out towards loading stuff from a file is easy if you need it.
Your example is not exactly Python, but quite close (ie "Vector(0,0,0)" instead of 
"<0,0,0>" etc).

Doing it like this give you again more experience in what you actually want from the input format, so you can first settle what you want to have without needing to write a PLY parser + input file processor.

On the other hand, if you have never done anything with parsing, spending some time on it is good too, as it gives you an idea of what these tools can do for you.

to another text file in the appropriate format such as POV-Ray SDL, OpenSCAD
script, etc. This file output can then be rendered by the corresponding
program to produce the actual 3D model. The macros I have now currently does

Yep, that's much easier to do :)

An alternative could be to use a better front-end, eg Blender, which can afaik also generate such output.

I have been advised to check out python-ply  but I was wondering if the
format is something I can do with ply or if I am better off using pure
python. Also considering that the text files the proposed program will be
parsing may get quite big, will there be any performance issues? The

PLY works well when you understand what the language should look like, and what it should do. Getting there is imo better done by doing experiments in generating output eg with Python. (Obviously, you can use PLY when you find patterns in your input that you want to move to an input file.)

As for speed issues, don't bother until you have a real problem.
It is good to keep in mind that you should not do computations that you can avoid, but otherwise, it is better to write clean code than it is to write fast code which is unreadable and/or unmaintainable. In my experience, you cannot predict where the problem is going to surface, so it is not useful to anticipate for it, as it will surface at a place where you didn't expect it.

following is a sample of what the text file that will be processed by this
proposed system will contain. I appreciate any pointers and suggestions.
Thank you very much.

------------possible user file content for parsing ------------
// In the following the python interface program reads
//+ the contents of the file "other.file" as if its content
//+ were located at this point.
include other.file

//In the following the python interface makes "snap_size" a
//+  global parameter
snap_size = 10


// In the following "buildingLevel" is a class that is
//+  called and passed the parameters in parenthesis.
buildingLevel("FirstLevel", 3000)

// In the following "snapOffset" is a class that is
//+  called and passed the parameters in parenthesis.
snapOffset("Closet-S1_r1", "Closet-S2_r3",<0,0,0>)
------------end of user file content

Instantiating some classes is the simple part. How do you define 
"buildingLevel" ?
What kind of expressions do you allow, what kind of types do you have, what operations can you perform? (eg "0+true": is that ok, if so what's the result, if not what error do you raise?)

Parsing is just the first step. The real problem is not parsing, it is what you intend to do with the text that you parsed from the input file.

It should also be possible to include comments using double-slashes, etc.

This is trivial (just one definition in PLY).


Albert

--
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to