POVFileMaker
Simple Explanation

How to use the
POVFileMaker.m

by Hagiwara Youichi (HW41)
s945208@ipe.tsukuba.ac..jp

Copyright© 1998, Hagiwara Youichi.
All rights reserved.

POV-Ray and Mathematica

Do you know POV-Ray ray tracing software? We can generate POV-Ray scene file by POVFileMaker.m.

POV-Ray is FREE but POWERFUL. Description of scene is simple. But I have some inconvenience. For example, it doesn't impliment loop routine (for, while, do, etc), therefore it's a troublesome job to describe many similar objects. And some mathematics functions aren't existence.

This package doesn't implemet loop routine, but Mathematica has many command. Therefore we can repeat operation and use mathematics function. This package impliments ALL POV-Ray commands and some elementary functions!

POV-Ray official home page is http://www.povray.org/. You can get latest version of POV-Ray software from the page.

Style

The style is just about the same as POV-Ray's. Command is too. POVFileMaker's command

POVheader[body]

imports POV-Ray's command

header {body}

. If we write string

"Text means Latin texo text- weave."

, output is

Text means Latin texo text -  weave .

There is usage for all function.

Example

The following is simple example. At first, load package.

<< POVFileMaker.m

We use the scene written in POV-Ray(tm) User's Documentation 3.0.10 at section 4.1.6. Comment is written by POVNewLine. String is written in accordance with it. Number (following, 1 in line 5) does output empty n-lines.

\(\(povexcomment = 
      POVNewLine[
		"This file was generated by", 
		
        "Generator : Mathematica", 
		
        "  Package : "POVFileMaker.m"", 
		
        1,  (*\ make\ 1\ empty\ line\ *) 
		
        "Following example program is written in", 
		
        "     Book : POV-Ray(tm) User's Documentation 3.0.10", 
		
        "  Section : 4.1.6"
]; \)\)

Include file is "colors.inc". Output is "#include "color.inc"". POVString[string] does output string of POV-Ray style.

povexinclude = POVInclude[POVString["colors.inc"]];

Background is "Cyan".

povexbackground = POVBackground[POVColor["Cyan"]];

Camera is ViewPoint. System is left-hand system. POVParameter[command,parameter] does output "command parameter". POVVecter[x,y,z] is "<x,y,z>".

\(\(povexcamera = 
      POVCamera[
		POVParameter["location", POVVector[0, 2, \(-3\)]], 
        
		POVParameter["look_at", POVVector[0, 1, 2]]
]; \)\)

Object is one Yellow Sphere. POVNumber[num or func] alters to number or function of POV-Ray style. Enter number or function into POVNumber[] as far as possible.

\(\(povexobject = 
      POVSphere[
		POVList[POVVector[0, 1, 2], POVNumber[2]], 
		
        POVTexture[POVPigment[POVColor["Yellow"]]]
]; \)\)

LightSource is LightSources.

povexlightsource = 
      POVLightSource[POVVector[2, 4, -3], POVColor["White"]];

Arrange these data. POVNewLine[] generates one empty line.

\(\(povex = {
		povexcomment, 
			POVNewLine[], 
		
        povexinclude, 
			POVNewLine[], 
		povexbackground, 
			
        POVNewLine[], 
		povexcamera, 
			POVNewLine[], 
		
        povexobject, 
			POVNewLine[], 
		povexlightsource
}; \)\)

File named "povex.pov" is made at the same place of Mathematica Kernel. If you want to save into another path, you write FULL path name.

POVMakeFile["povex.pov", povex];

More information

POVMakeFile[filename, commandlines] writes commandlines in POV-Ray format to file. The commandline is nested-list of POVcommand[]. POVMakeFile[stream, commandlines] uses stream for output. When you use number or math function, wrap up it in POVNumber[].

POVNumber[number] generates POV-Ray type number. POVNumber can handle following mathematics functions. Abs[x] ArcCos[x] ArcCosh[x] ArcCot[x] ArcCoth[x] ArcCsc[x] ArcCsch[x] ArcSec[x] ArcSech[x] ArcSin[x] ArcSinh[x] ArcTan[x] ArcTan[x, y] ArcTanh[x] Ceiling[x] Cos[x] Cosh[x] Cot[x] Coth[x] Csc[x] Csch[x] Degree Dot[a, b] E Exp[x] Floor[x] GoldenRatio List[e1, e2, ...] Log[x] Log[b, x] Max[x1, x2, ...] Min[x1, x2, ...] Mod[m, n] Pi Power[x, y] Quotient[n, m] Rational[x, y], Sec[x] Sech[x] SeriesData[x, x0, {a0, a1, ...}, nmin, nmax, den] Sign[x] Sin[x] Sinh[x] Sqrt[x] Tan[x] Tanh[x].

POVString["string"] generates POV-Ray type string.

If you forget command, you can write like "command". For example, "pigment{color \"Yellow\"}}" is equivalent to POVPigment[POVColor["Yellow"]]. Or, general command, POVHeader["header"][body], generates POV-Ray header and body, too. Example is POVHeader["pigment"][POVColor["Yellow"]].

There is a difference of output between POVList, POVParameter and POVVector. POVList[a,b,c,...] is a,b,c,... . POVParameter[a,b,c,...] is a b c ... . POVVector[a,b,c,...] is <a,b,c,...>. And POVBracket[a,b,c,...] is [ a b c ... ].

You can use many color type. RGBColor, GrayLevel, POVColor, POVColorRGB, POVColorRGBF, POVColorRGBT, POVColorRGBFT, and POVColorRGBFT[GrayLevel[i],f,t], POVColorRGBFT[RGBColor[r,g,b],f,t], etc.

You can use 2-type comment. POVComment["comment"] outputs c-like /* comment */. POVNewLine["comment"] outputs c++-like // comment .

Other POVFileMaker functions are following.

More Example

Right-handed-system is set by camera.

\(\(povmrexcamera = 
      POVCamera[
		POVParameter["location", POVVector[1.7, 1.7, 1.7]], 
        
		POVParameter["direction", POVVector[\(-1\), 0, 0]], 
		
        POVParameter["up", POVVector[0, 0, 1]], 
		
        POVParameter["right", POVVector[0, 4\/3, 0]], 
		
        POVParameter["sky", POVVector[0, 0, 1]], 
		
        POVParameter["look_at", POVVector[0.5, 0.5, 0.5]]
]; \)\)

LightSource is at the same place as viewpoint. Color is White.

povmrexlightsource = 
      POVLightSource[POVVector[1.7, 1.7, 1.7], POVColorRGB[1, 1, 1]];

Objects are Balls set at the grids of cubic. Color is RGB of 3-value of position. Number of ball is (11^3).

\(\(povmrexobjs = 
      Module[{positions}, 
		
        positions = 
          Flatten[Table[
					N[{i, j, k}], 

              					{i, 0, 1, 1\/10}, {j, 0, 1, 1\/10}, {k, 0, 1, 1\/10}

              		], 2]; 
		
        Map[\((POVSphere[
			POVList[POVVector@@#, 0.025], 
			
                POVTexture[POVPigment[POVColorRGB@@#]]
		])\)&, 
          positions]]; \)\)

Arrange these data.

\(\(povmrex = {
		povmrexcamera, 
			POVNewLine[], 
		
        povmrexlightsource, 
			POVNewLine[], 
		povmrexobjs
}; 
    \)\)

File named "povmrex.pov" is made at the same place of Mathematica Kernel. If you want to save into another path, you write FULL path name.

POVMakeFile["povmrex.pov", povmrex];