POV-Ray : Newsgroups : povray.general : Isosurface, box with transformations : Re: Isosurface, box with transformations Server Time
3 Aug 2024 20:18:30 EDT (-0400)
  Re: Isosurface, box with transformations  
From: StephenS
Date: 3 Nov 2003 00:28:35
Message: <3fa5e783@news.povray.org>
Christopher James Huff wrote
...
> Here's a considerably simpler macro which
> is also easier to use:
...
This is much closer to what I was hoping for when I started :-)

I now have the following code.
-box declared with start/finish points and/or scale/translate.
-additional shapes can be added. Shapes that can be easily represented with
a wireframe interest me the most.
-scale and shear have been kept separate for ease of reading.
-bounded_by not calculated from objects used, user inputs values.

// start code
camera {
  location  <-0.5, 2.0, -3.0>
  look_at   <0.5, 0.5,  0.0>
  right     x*image_width/image_height
}

light_source {
  0*x
  color rgb <1.5,1.5,1.5>
  translate <-15, 30, -20>
}

light_source {
  0*x
  color rgb <.5,.5,.5>
  translate <0, -30, -20>
}

light_source {
  0*x
  color rgb <.5,.5,.5>
  translate <20, -5, -20>
}

// possible output from external program
#declare sx=array[4]{0,0,.2,0}; // start
#declare sy=array[4]{0,0,0,0};
#declare sz=array[4]{0,0,0,0};
#declare fx=array[4]{1,.1,1,1}; // finish
#declare fy=array[4]{1,1,1,1};
#declare fz=array[4]{1,1,1,1};

#declare scx=array[4]{1,1,1,1}; // scale
#declare scy=array[4]{1,1,1,1};
#declare scz=array[4]{1,1,1,1};

#declare shxy=array[4]{0,0,0,-.2}; // shear
#declare shxz=array[4]{0,0,0,0};
#declare shyx=array[4]{0,0,0,0};
#declare shyz=array[4]{0,0,0,0};
#declare shzx=array[4]{0,0,0,0};
#declare shzy=array[4]{0,0,0,0};

#declare rx=array[4]{0,0,0,0}; // rotate
#declare ry=array[4]{0,0,0,0};
#declare rz=array[4]{0,-10,0,0};

#declare tx=array[4]{0,.5,-.2,-.6}; // translate
#declare ty=array[4]{0,.5,0,.6};
#declare tz=array[4]{0,-.5,.5,.5};

#declare ob=array[4]{1,1,2,1}

#local Blob_threshold=.000001;
#local maxnum=4; // change from 1 - 4

// Pov code to make blobbed isosurface object
#macro m_object(num)
#switch(ob[num])
  #case(1) // box
  function {
    max(
      (abs(x-(fx[num]-sx[num])/2-sx[num])-abs(fx[num]-sx[num])/2),
      (abs(y-(fy[num]-sy[num])/2-sy[num])-abs(fy[num]-sy[num])/2),
      (abs(z-(fz[num]-sz[num])/2-sz[num])-abs(fz[num]-sz[num])/2)
    )
  }
  #break
  #case(2) // sphere
  function {
    pow(x,2) + pow(y,2) + pow(z,2) - pow(sx[num],2)
  }
  #break
#end // switch
#end // macro

#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

isosurface {
  #local num=0;
  function {
    (1+Blob_threshold)
    #while (num<maxnum)
      #local Trans =
      transform {
        scale     < scx [num], scy [num], scz [num]>
        matrix    < 1        , shyx[num], shzx[num], // shear
                    shxy[num], 1        , shzy[num],
                    shxz[num], shyz[num], 1        ,
                    0        , 0        , 0        >
        rotate    < rx  [num], ry  [num], rz  [num]>
        translate < tx  [num], ty  [num], tz  [num]>
        inverse};
      -pow(Blob_threshold,TransformFn(m_object(num), Trans))
      #declare num=num+1;
    #end // while
  }
  contained_by { box { -1.6, 1.6 } }
  max_gradient (14.1)
  texture { pigment {color red 1} finish{ambient 0.2} }
}
// end code

My question:
Is there a better way to organize my isosurface and macros?

Stephen


Post a reply to this message

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