POV-Ray : Newsgroups : povray.general : Is it possible to convert a text string to a Macro Identifier ??? : Re: Is it possible to convert a text string to a Macro Identifier??? Server Time
1 Aug 2024 16:28:19 EDT (-0400)
  Re: Is it possible to convert a text string to a Macro Identifier???  
From: PM 2Ring
Date: 20 Aug 2005 17:00:00
Message: <web.43079833b67b12baf405c6350@news.povray.org>
"Mike E." <nomail@nomail> wrote:
> "Slime" <fak### [at] emailaddress> wrote:
>
>
> > Parse_String, at least in this case, is sort of a hack that solves an
> > obscure problem (caused by an input file that I'm assuming you have no
> > control over). Don't rely on it all the time because there are generally
> > better ways to do things.
> >
> >  - Slime
> >  [ http://www.slimeland.com/ ]
>
>
> Hmm. Interesting response Mr Slime. It is an input file that I have some
> control over from another pgm. But I find the notion of generating commands
> which are dependent on external files (or even just text strings) very
> useful in many cases,  not just this one - whether I have control over them
> or not.
> This is mainly to avoid long winded code using things like strcmp() or
> switch statements to generate an action based on a large no of variable
> data input.
> Would you care to expand on your ideas about better ways to do things?
>
> M.E.

Have a look at the source for Parse_String():

#macro Parse_String(String)
    #fopen FOut "parse_string.tmp" write
    #write(FOut,String)
    #fclose FOut
    #include "parse_string.tmp"
#end

As you can see, lots of Parse_String() calls in a scene will have lots of
overhead with all that file handling. If you want to do this sort of thing,
its best if you can avoid all that file opening & closing.

For example:

// Persistence of Vision Ray Tracer Scene Description File
// File: Boxes.pov
// Vers: 3.5
// Desc: Show T_Stone textures on numbered superellipsoids in ZX plane
// Date: 24 Apr 2004
// Auth: PM 2Ring
//

global_settings {
  assumed_gamma  1.0
}

#include "colors.inc"
// T_Stone1 - T_Stone44
#include "stones.inc"

camera {
  location  <0.0, 0, -380>
  direction 10*z
  look_at   0
  right     x*image_width/image_height up y
}

light_source { <0, 500, -2000> *2  White }

#declare MI=6;
#declare MJ=7;
#declare MK=44;

//Let's build our own include file,
//since we can't manipulate identifiers directly
#declare FileName = "mydata.inc";
#debug concat("\n\nBuilding include file, ", FileName, "...\n")

#fopen MyFile FileName write
#write (MyFile, "#declare Tex = array[", str(MK,0,0), "]{\n")

#declare K=1;
#while (K<=MK)
  #write (MyFile, concat("  T_Stone", str(K,0,0), ",\n"))
  #declare K=K+1;
#end

#write (MyFile, "}")
#fclose MyFile

#include FileName
#debug "File I/O complete.\n"

#declare Scale = <3, 2, 1>;
#macro Make_SBlock(Str)
union{
  difference{
    superellipsoid {
      <0.4, 0.4>
      scale Scale
    }

    superellipsoid {
      <0.1, 0.1>
      scale <2.5, 1.5, .5>
      translate -1.25*z
    }
  }

  text {
    ttf "timrom.ttf" Str .975, 0
    scale 3
    translate <-1.25, -1.125, -.975>
  }
}
#end

#declare Boxes =
union{
  #declare K=0;
  #declare I=0;
  #while (I<MI)
    #declare J=0;
    #while (J<MJ)
      object{Make_SBlock(str(K+1,2,0))
        translate <2*J-MJ+1, 2*I-MI+1, 0> * (Scale * 1.15 * <1, 1.2, 1>)
        texture{Tex[K] scale Scale}
      }
      #declare J=J+1;
      #declare K=mod(K+1, MK);
    #end
    #declare I=I+1;
  #end
}

object{
  Boxes
}

background{rgb .5}

//-------------------------------------------------------------


Post a reply to this message

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