how do I draw 3D image to a standard 3D file format

16 views
Skip to first unread message

Martin Baker

unread,
Jun 4, 2010, 5:01:26 AM6/4/10
to FriCAS - computer algebra system
I would appreciate any help to work out the best way to output a draw
3D image to a standard 3D file format rather than the x-window.

I would like to do this because there are limitations in what can be
done with the built-in 3D viewer and dedicated 3D editors (such as
'blender') are much more powerful (does it make sense that a computer
algebra program also tries to be a 3D editor?). An additional
advantage is that it would work on computers without x-window. For a
fuller explanation of exactly what I am trying to do and what I have
done already see this page:
http://www.euclideanspace.com/maths/standards/program/mycode/write/

However I can't work out exactly how to do this. The options I am
considering are:

* Writing a stand alone file converter to convert the 'data' file
generated by 'write' into a standard 3D file format that can be read
by 3D editors such as a Wavefront .OBJ file or perhaps a x3d file.
Although, at first glimpse, the format of this 'data' file looks
promising I can't work out its exact format.
* Add a modified 'write' function to
'ThreeDimensionalViewport' (in view3D.spad). Unfortunately most of the
work of the write function is done by lisp calls like:
sendI(VIEW,typeVIEW3D)$Lisp so I would have to write it without help
from existing code.

For the first option it would help to have more documentation for the
'data' file format (there is some information in bookvol8 for 2D graph
and viewfile formats but it does not seem to correspond with the
datafile I have been looking at) and for the second option it would
help to have more documentation about the format of 'ThreeSpace' in
space.spad, especially:

* SUBSPACE ==> SubSpace(3,R)
* REP3D ==> Record(lp:L POINT,llliPt:L L L NNI, llProp:L L PROP,
lProp:L PROP)
* OBJ3D ==> Record(points:NNI, curves:NNI, polygons:NNI,
constructs:NNI)
* Rep := Record( subspaceField:SUBSPACE, compositesField:L
SUBSPACE, _ rep3DField:REP3D, objectsField:OBJ3D, _ converted:B)

Also what is the best way to create and write to a text file?

Thanks,

Martin Baker

Ralf Hemmecke

unread,
Jun 4, 2010, 5:14:38 AM6/4/10
to fricas...@googlegroups.com, axiom-dev
Hi Martin,

In response to
http://groups.google.com/group/fricas-devel/browse_thread/thread/4b341750a4e9301d?hl=en

> Also what is the best way to create and write to a text file?

Have you looked at the File constructor?


If you can work on a more standard graphics format, I think that would
be great.

As for
http://www.euclideanspace.com/maths/standards/program/mycode/write/
you should note that many tools in PanAxiom were done before any other
programmers jumped in and created different and nowadays more often used
formats.

Maybe Tim knows a bit more about the history. Your conversion would
certainly be of interest for all the panAxiom systems.

Ralf

Waldek Hebisch

unread,
Jun 4, 2010, 7:45:40 AM6/4/10
to fricas...@googlegroups.com
Martin Baker wrote:
> I would appreciate any help to work out the best way to output a draw
> 3D image to a standard 3D file format rather than the x-window.
>
> I would like to do this because there are limitations in what can be
> done with the built-in 3D viewer and dedicated 3D editors (such as
> 'blender') are much more powerful (does it make sense that a computer
> algebra program also tries to be a 3D editor?). An additional
> advantage is that it would work on computers without x-window. For a
> fuller explanation of exactly what I am trying to do and what I have
> done already see this page:
> http://www.euclideanspace.com/maths/standards/program/mycode/write/
>

One possiblity is to work with Postscrit. General Postscrit is
hard to edit, but FriCAS generates only very restricted subset,
so for Postscrit expert converting to other formats should be
easy.

If you want to add a new output format place to look is
'src/graph/Gdraws/Gfun.c' which defines "primitives" for
Postscrit (and X11) output -- if you want output in different
format you need to find out how to express each of primitives in
the target language and replace 'printf' statemets with
Postscrit code by statements emmiting your desired format.

Concerning data files, they are essentally dump of internal
data structures used by drawing programs. You can correlate
file format with C data structures looking at
'src/graph/view3D/write3d.c'.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Bill Page

unread,
Jun 4, 2010, 10:13:24 AM6/4/10
to fricas...@googlegroups.com
Martin,

The examples here

http://axiom-wiki.newsynthesis.org/GnuDraw

and associated left sidebar links, might be of some use to you.

Regards,
Bill Page.

> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To post to this group, send email to fricas...@googlegroups.com.
> To unsubscribe from this group, send email to fricas-devel...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/fricas-devel?hl=en.
>
>

Martin Baker

unread,
Jun 5, 2010, 3:23:42 AM6/5/10
to FriCAS - computer algebra system
Thank you very much for all the replies to this thread, there are a
lot of options and it is hard to choose what is best.

As far as I can tell, from the file references, postscript 'flattens'
the 3D data into a 2D image for display in a document? What I wanted
is the full 3D data that can be edited in a program like Blender so I
don't think the postscript file is a viable option.

The second option of modifying 'src/graph/Gdraws/Gfun.c' to change the
postscript code to produce a 3D output format looks viable. However I
don't have any recent experience in writing C code, if this was just a
case of modifying and recompiling a C file I would have a go but I
guess this would have to be linked back into the other code and
everything would have to be rebuilt, which is something I was hoping
to avoid doing.

I had a look at 'src/graph/view3D/write3d.c' to see the format of the
'data' file which I have documented here:
http://www.euclideanspace.com/maths/standards/program/mycode/write/
This appears to contain all the information to reconstruct the 3D mesh
so it would be possible to write a stand alone program to convert into
other formats. However this would be harder to use, as the user would
have to find the .view directory and then fire up another program to
convert it.

I will investigate the approach suggested by Bill Page, this looks
very promising, I can see advantages in avoiding all the mechanisms
for firing up x-window and so on. This would seem to have the least
constraints and so allow for adding additional features, for instance,
it would be good to show more than 3 dimensions by use of colour or
perhaps animation over time.

Martin Baker

Waldek Hebisch

unread,
Jun 8, 2010, 8:38:33 AM6/8/10
to fricas...@googlegroups.com
Martin Baker wrote:
>
> As far as I can tell, from the file references, postscript 'flattens'
> the 3D data into a 2D image for display in a document? What I wanted
> is the full 3D data that can be edited in a program like Blender so I
> don't think the postscript file is a viable option.
>
> The second option of modifying 'src/graph/Gdraws/Gfun.c' to change the
> postscript code to produce a 3D output format looks viable.

This is also projected to 2D (in fact equivalent to data in
postscript file).

> I had a look at 'src/graph/view3D/write3d.c' to see the format of the
> 'data' file which I have documented here:
> http://www.euclideanspace.com/maths/standards/program/mycode/write/
> This appears to contain all the information to reconstruct the 3D mesh
> so it would be possible to write a stand alone program to convert into
> other formats. However this would be harder to use, as the user would
> have to find the .view directory and then fire up another program to
> convert it.
>

It is relatively easy to add statements to create different
file format (I mean easier than writing convertion on
text level). Exactly how much effort it takes depends
on target format.

> I will investigate the approach suggested by Bill Page, this looks
> very promising, I can see advantages in avoiding all the mechanisms
> for firing up x-window and so on. This would seem to have the least
> constraints and so allow for adding additional features, for instance,
> it would be good to show more than 3 dimensions by use of colour or
> perhaps animation over time.


I would say that you probably want to connect close to end of
FriCAS graphic pipeline. I am not sure where exactly
GnuDraw plugs in graphic pipeline but the lines:

writeLine!(f1,concat([unparse(convert(p.1)@InputForm)," ",
unparse(convert(p.2)@InputForm)]))

make me suspicious: if InputForm and unparse are really needed, then
probably it is too early.

To put it differently: the first stage is evalation of functions
(in particular choice of evaluation points), I do not think
you want to re-implement this part. Then the data is transmitted
to C code which performs transformations and renders on final
device. Since you want to use external transformation program
skipping C code makes sense, so you probably want to connect
close to the point where data is transmitted to C.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Martin Baker

unread,
Jun 14, 2010, 10:37:45 AM6/14/10
to fricas...@googlegroups.com, axiom-dev
I don't know if anyone is interested but I have written code to write the
contents of a SubSpace domain to a Wavefront .OBJ file. If you are interested
I have put the code with some documentation an instructions here:

http://www.euclideanspace.com/maths/standards/program/mycode/graph/write/

While doing this I found the Axiom documentation a bit lacking in some areas
(I needed to understand SubSpace, ThreeSpace and so on) so while I was doing
this I took the opportunity to make some notes on existing axiom geometry
related structures and put my notes here:
http://www.euclideanspace.com/maths/standards/program/mycode/graph/existing/

I also have various issues, questions and so on about the more general issues
of working with geometry in axiom here:

http://www.euclideanspace.com/maths/standards/program/mycode/graph/

The motivation is to:

* Export plots (with scales, axes, and so on) into a dedicated 3D editors
(such as 'blender').
* define and transform shapes using Clifford algebra as well as usual
Matrix methods.
* I also find it very helpful to be able to visualise the algebraic
structures and I want to find better ways to do this.
* define shapes and show union and intersection (join and meet)
* slice through shapes and show sections.
* show scales and grids
* combine many graphs in one view
* add annotations in 3D view.
* Use structures that can be extended to n-dimensions and are not specific
to 2 or 3(+ 1 for colour) dimensions.

As one example of the issues on this page : I would like to be able to export
to a X3D file - which is more complicated and standards based than a Wavefront
file since this can do things like text, lines and colour which would be
useful for drawing scales etc. There seem to be many structures in axiom to
implement Open Inventor (IVNodeCategory, RenderTools, IVSimpleInnerNode,
IVSeparator, IVGroup, IVCoordinate3, IVQuadMesh, IVIndexedLineSet,
IVUtilities). Would it be feasible to adapt this to support X3D?

Martin Baker

Reply all
Reply to author
Forward
0 new messages