POV-Ray : Newsgroups : povray.general : Isosurface, box with transformations : Re: Isosurface, box with transformations Server Time
3 Aug 2024 20:20:38 EDT (-0400)
  Re: Isosurface, box with transformations  
From: Christopher James Huff
Date: 24 Oct 2003 22:37:12
Message: <cjameshuff-686248.22350524102003@netplex.aussie.org>
In article <3f99aa40$1@news.povray.org>,
 "StephenS" <ssh### [at] echelonca> wrote:

> Thanks for your reply. I don't completly understand all that you sugested,
> but it gives me a few things to look into. Will have to play with the code
> for awhile :-)

Here's a short explanation of the macro:

#macro TransFn(Comp, Trans)
    #local TmpTransFn = function {transform {Trans}}
    #local C0 = TmpTransFn(0, 0, 0);
    #local CX = TmpTransFn(1, 0, 0) - C0;
    #local CY = TmpTransFn(0, 1, 0) - C0;
    #local CZ = TmpTransFn(0, 0, 1) - C0;
    #switch(Comp)
        #case(0)
            #local X = CX.x;
            #local Y = CY.x;
            #local Z = CZ.x;
            #local T = C0.x;
        #break
        #case(1)
            #local X = CX.y;
            #local Y = CY.y;
            #local Z = CZ.y;
            #local T = C0.y;
        #break
        #case(2)
            #local X = CX.z;
            #local Y = CY.z;
            #local Z = CZ.z;
            #local T = C0.z;
        #break
    #end
    function {x*X + y*Y + z*Z + T}
#end

POV-Ray transformations are stored in 3x4 matrices, basically 3x3 
matrices with translation columns tacked on. Points are transformed by 
the matrix like this:

xOut = m11*x + m12*y + m13*z + m14
yOut = m21*x + m22*y + m23*z + m24
yOut = m31*x + m32*y + m33*z + m34

Transforming < 0, 0, 0> gives the translation column alone. Transforming 
< 1, 0, 0>, < 0, 1, 0>, and < 0, 0, 1> and subtracting the translation 
give the first three columns. Then a function is created with the matrix 
elements of the desired row.

Unfortunately, I've tested it, and this is actually slower than 
evaluating the transform function directly. The test took 28 seconds 
with the transform function, and 32 with the functions produced with 
this macro (7 seconds with no transformations). Removing multiplications 
by 1 and zero terms, I ended up with transformation functions that 
produced an isosurface that rendered in 23 seconds, but this will only 
happen in certain limited cases, so it really isn't worth the effort to 
implement this optimization. Here's a considerably simpler macro which 
is also easier to use:

#macro TransformFn(Func, Trans)
    #ifdef(f_Trans)
        #undef f_Trans
    #end
    #local f_Trans = function {transform {Trans}}
    #local Res = function {Func(f_Trans(x, y, z).x, f_Trans(x, y, z).y, 
f_Trans(x, y, z).z)}
    Res(x, y, z)
#end

#local Trans = transform {scale < 1, 3, 1> translate -y*1 inverse}
isosurface {
    function {1 - TransformFn(f_r, Trans)}

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.