POV-Ray : Newsgroups : povray.binaries.images : isoBox macro Server Time
6 Aug 2024 19:30:49 EDT (-0400)
  isoBox macro (Message 1 to 5 of 5)  
From: Ross
Subject: isoBox macro
Date: 17 Nov 2006 15:13:36
Message: <455e17f0@news.povray.org>
In a scene I am working on, I am building it up with just plain primitive
boxes but when I have the layout all done, I'd like to make them isosurfaces
so I can deform them with noise or pigment functions. I couldn't figure out
an easier way than make a macro that takes the same vectors that define the
box, plus some other parameters, resulting in an isosurface.

This may not be usefull for anyone else but me (meaning, it works on the
scale I'm working with, your results may vary... and it's not tested
heavily), but here's the macro and sample output.


// requires the standard f_rounded_box function
#include "functions.inc"

#macro isoBox (vB1, vB2, fRad, vT1, fDeform, fDeformMagnitude, fAccuracy,
fMaxGradient)
// Paramters:
// vB1 = box vector 1
// vB2 = box vector 2
// fRad = radius for f_rounded_box
// vT1 = deformation translate vector (moves the function away from the
origin)
// fDeform = function to deform the box by
// fDeformMagnitude = scale factor for the deformation function
// fAccuracy = isosurface accuracy
// fMaxGradient = isosurface max_gradient

 // X, Y, Z are scales for f_rounded_box
 #local X = abs(vB1.x - vB2.x);
 #local Y = abs(vB1.y - vB2.y);
 #local Z = abs(vB1.z - vB2.z);

 // translate the box so it's back where the
 // box vectors would place it (f_rounded_box
 // places it at the origin it seems)
 #local tX = (vB1.x + vB2.x) / 2;
 #local tY = (vB1.y + vB2.y) / 2;
 #local tZ = (vB1.z + vB2.z) / 2;
 #local vTranslate = <tX, tY, tZ>;

 // amount to translate the deform function by
 #local dX = vT1.x;
 #local dY = vT1.y;
 #local dZ = vT1.z;

 // possibly make this a vector passed as a parameter
 // so that each componant can be applied separatelt.
 // not sure what to call it, but I use it to smooth out
 // the resulting isosurface.
 #local dSmooth = 0.33;

 isosurface {
  function {
    f_rounded_box(x, y, z, fRad, X/2, Y/2, Z/2)-
    fDeform( (x+dX)*dSmooth, (y+dY)*dSmooth,
(z+dZ)*dSmooth).x*fDeformMagnitude
  }

  // this contained_by seems adequate for my needs.
  contained_by { box { -(max(X, Y, Z)-fRad*2), max(X, Y, Z)+fRad*2 } }
  accuracy fAccuracy
  max_gradient fMaxGradient

  translate vTranslate
 }
#end

// example usage:
#declare fnPig2 = function {
 pigment {
  cells
  color_map {
   [0.0 rgb 0.0]
   [0.3 rgb 1.0]
   [0.7 rgb 0.8]
   [0.9 rgb 0.3]
  }
  scale <1, 1, 1> * 0.0085
 }
}

object {
    isoBox(
      <0.085, .085*2, 0.085>,
      <-0.085, 0, -0.085>, 0.005
      <0, 0, 0>,
      fnPig2, 0.01285, 0.001, 4)
 pigment {rgb 0.8}
}


Post a reply to this message


Attachments:
Download 'isobox3.png' (29 KB)

Preview of image 'isobox3.png'
isobox3.png


 

From: povray
Subject: Re: isoBox macro
Date: 18 Nov 2006 15:43:02
Message: <pan.2006.11.18.17.26.29.215251@localhost>
On Fri, 17 Nov 2006 15:13:15 -0500, Ross wrote:

> In a scene I am working on, I am building it up with just plain primitive
> boxes but when I have the layout all done, I'd like to make them isosurfaces
> so I can deform them with noise or pigment functions. I couldn't figure out
> an easier way than make a macro that takes the same vectors that define the
> box, plus some other parameters, resulting in an isosurface.
> 
> This may not be usefull for anyone else but me (meaning, it works on the
> scale I'm working with, your results may vary... and it's not tested
> heavily), but here's the macro and sample output.
> 
> 
> // requires the standard f_rounded_box function
> #include "functions.inc"
> 
> #macro isoBox (vB1, vB2, fRad, vT1, fDeform, fDeformMagnitude, fAccuracy,
> fMaxGradient)
> // Paramters:
> // vB1 = box vector 1
> // vB2 = box vector 2
> // fRad = radius for f_rounded_box
> // vT1 = deformation translate vector (moves the function away from the
> origin)
> // fDeform = function to deform the box by
> // fDeformMagnitude = scale factor for the deformation function
> // fAccuracy = isosurface accuracy
> // fMaxGradient = isosurface max_gradient
> 
>  // X, Y, Z are scales for f_rounded_box
>  #local X = abs(vB1.x - vB2.x);
>  #local Y = abs(vB1.y - vB2.y);
>  #local Z = abs(vB1.z - vB2.z);
> 
>  // translate the box so it's back where the
>  // box vectors would place it (f_rounded_box
>  // places it at the origin it seems)
>  #local tX = (vB1.x + vB2.x) / 2;
>  #local tY = (vB1.y + vB2.y) / 2;
>  #local tZ = (vB1.z + vB2.z) / 2;
>  #local vTranslate = <tX, tY, tZ>;
> 
>  // amount to translate the deform function by
>  #local dX = vT1.x;
>  #local dY = vT1.y;
>  #local dZ = vT1.z;
> 
>  // possibly make this a vector passed as a parameter
>  // so that each componant can be applied separatelt.
>  // not sure what to call it, but I use it to smooth out
>  // the resulting isosurface.
>  #local dSmooth = 0.33;
> 
>  isosurface {
>   function {
>     f_rounded_box(x, y, z, fRad, X/2, Y/2, Z/2)-
>     fDeform( (x+dX)*dSmooth, (y+dY)*dSmooth,
> (z+dZ)*dSmooth).x*fDeformMagnitude
>   }
> 
>   // this contained_by seems adequate for my needs.
>   contained_by { box { -(max(X, Y, Z)-fRad*2), max(X, Y, Z)+fRad*2 } }
>   accuracy fAccuracy
>   max_gradient fMaxGradient
> 
>   translate vTranslate
>  }
> #end
> 
> // example usage:
> #declare fnPig2 = function {
>  pigment {
>   cells
>   color_map {
>    [0.0 rgb 0.0]
>    [0.3 rgb 1.0]
>    [0.7 rgb 0.8]
>    [0.9 rgb 0.3]
>   }
>   scale <1, 1, 1> * 0.0085
>  }
> }
> 
> object {
>     isoBox(
>       <0.085, .085*2, 0.085>,
>       <-0.085, 0, -0.085>, 0.005
>       <0, 0, 0>,
>       fnPig2, 0.01285, 0.001, 4)
>  pigment {rgb 0.8}
> }
  0:00:00 Parsing
File: isobox_macro_posting.pov  Line: 30
File Context (5 lines):
// vB1 = box vector 1
// vB2 = box vector 2
// fRad = radius for f_rounded_box
// vT1 = deformation translate vector (moves the function away from the
origin
Parse Error: Expected 'object', undeclared identifier 'origin' found instead
Total Scene Processing Times
  Parse Time:    0 hours  0 minutes  0 seconds (0 seconds)
  Photon Time:   0 hours  0 minutes  0 seconds (0 seconds)
  Render Time:   0 hours  0 minutes  0 seconds (0 seconds)
  Total Time:    0 hours  0 minutes  0 seconds (0 seconds)


Post a reply to this message

From: Marc
Subject: Re: isoBox macro
Date: 18 Nov 2006 19:12:16
Message: <455fa160@news.povray.org>

news: pan.2006.11.18.17.26.29.215251@localhost...
> Parse Error: Expected 'object', undeclared identifier 'origin' found
instead

it is a broken in line comment (//)
the post broke the line (in the parameters at the beginning of the code)
> // vT1 = deformation translate vector (moves the function away from the
> origin)
(guess if it will be broken again)

just comment "origin" as well or delete the  carriage return and the >
character

Marc


Post a reply to this message

From: Thomas de Groot
Subject: Re: isoBox macro
Date: 20 Nov 2006 03:12:32
Message: <45616370$1@news.povray.org>
Very nice little macro, Ross! Thank you!!

Thomas


Post a reply to this message

From: Ross
Subject: Re: isoBox macro
Date: 20 Nov 2006 11:23:04
Message: <4561d668$1@news.povray.org>
"Marc" <jac### [at] wanadoofr> wrote in message
news:455fa160@news.povray.org...
>

> news: pan.2006.11.18.17.26.29.215251@localhost...
> > Parse Error: Expected 'object', undeclared identifier 'origin' found
> instead
>
> it is a broken in line comment (//)
> the post broke the line (in the parameters at the beginning of the code)
> > // vT1 = deformation translate vector (moves the function away from the
> > origin)
> (guess if it will be broken again)
>
> just comment "origin" as well or delete the  carriage return and the >
> character
>
> Marc
>
>

Yep, thanks for clearing that up Marc


Post a reply to this message

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