POV-Ray : Newsgroups : povray.general : printing object's identifier Server Time
5 May 2024 12:04:00 EDT (-0400)
  printing object's identifier (Message 11 to 20 of 20)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Bald Eagle
Subject: Re: printing object's identifier
Date: 18 Mar 2016 23:15:01
Message: <web.56ecc3c1374275025e7df57c0@news.povray.org>
jr <cre### [at] gmailcom> wrote:

> the .pov illustrates building object identifiers dynamically via cli.
> the file is commented and works with version 3.7.0.  it does lack visual
> pizzazz but I'm no artist anyway.

Nice!   I like your use of the #error stream interrupt

> also, the newlines in the error messages don't work on my machine.

Yeah - they don't work on mine either. So -
I prefaced the #error directive with #warning messages, and _then_ triggered the
error.  Seems to sorta do what I think you were after.

I was a little confused, since I run POV-Ray on a Winbloze 7 machine and don't
often use CLI.
Don't judge me.   :O
I also rearranged the text a bit to make it somewhat clearer what's going on in
case it gets run without any idea what it's supposed to do.
"Hey, what's this .pov file I have in this directory... ?"

You also forgot to  #declare Whip = "Bald Eagle"   :P


############################################################################

/* parsestr.pov
 * this simple scene demonstrates the use of the 'Parse_String' macro
 * to build Object Identifiers dynamically, at runtime.
 *
 * Parse_String(String): This macro takes a string, writes it to a file, and
then includes that file.
 * This has the effect of parsing that string: "Parse_String("MyColor")" will be
seen by POV-Ray as "MyColor".
 * Parameters:
 * String = The string to be parsed.
 *
 *   command-line:
 *   povray Declare=OBJ=N ...    <<< Necessary for this scene to work!
 *          ^^^^^^^^^^^^^
 *
 * where N is one of the following:
 *  1 - box, 2 - cylinder, 3 - ovus, 4 - sphere, 5 - torus.
 *
 * date: 19.3.2016.
 * author: jr <cre### [at] gmailcom>.
 * license: Creative Commons CC0.
 * thanks to 'Bald Eagle' who provided the inspiration (motivation!).
 */

#version 3.7;

global_settings { assumed_gamma 1.0 }

#include "colors.inc"

// Parse_String.
#include "strings.inc"

light_source { <10,10,-10> White }

camera {
  location <1.5,1.5,-2.5>
  right x*image_width/image_height
  look_at <0,0,0>
}

// objects to select.
#declare the_box = box {<-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5> texture {pigment
{Blue}}};
#declare the_cylinder = cylinder {<0,-0.5, 0>, <0, 0.5, 0>, .65 texture {pigment
{Blue}}};
#declare the_ovus = ovus {.65, .35 texture {pigment {Blue}}};
#declare the_sphere = sphere {<0,0,0>, 1 texture {pigment {Blue}}};
#declare the_torus = torus {1, .35 texture {pigment {Blue}}};

#declare the_help = "1 (box), (2) cylinder, (3) ovus, (4) sphere, or (5) torus";

#declare the_objs = array[5];
#declare the_objs[0] = "box";
#declare the_objs[1] = "cylinder";
#declare the_objs[2] = "ovus";
#declare the_objs[3] = "sphere";
#declare the_objs[4] = "torus";

#declare the_prefix = "the_";

// verify OBJ has been declared and is in range.
#ifndef (OBJ)
 #warning
"**********************************************************************************************************************
******\n"
 #warning concat("*** Missing argument: OBJ
                                                          ***\n")
 #warning concat("*** Need Command-Line statement \"Declare=OBJ=X\", where X = :
", the_help, ".  ***\n")
 #warning "***
                                                   ***\n"
 #warning
"**********************************************************************************************************************
******\n"

 #error concat(" *** Need Command-Line \"Declare=OBJ=X\", where X = : ",
the_help, ".\n")
 //   Try using _____Declare=OBJ=1_____ in the command-line box to the right of
the render resolution drop-down menu

#elseif (1 > OBJ | 5 < OBJ)
 #warning
"**********************************************************************************************************************
******\n"
 #warning concat("*** Bad argument# for: OBJ                       Please select
a different number                                        ***\n")
 #warning concat("*** Need Command-Line statement \"Declare=OBJ=X\", where X = :
", the_help, ".  ***\n")
 #warning "***
                                                   ***\n"
 #warning concat("*** Select (1-5):  ", the_help, ".  You used: _",
str(OBJ,0,0),"_.                            ***\n")
 #warning
"**********************************************************************************************************************
******\n"
 #error concat(" *** Bad argument # for OBJ \n  Select (1-5):  ", the_help, ".
You used: _", str(OBJ,0,0),"_.\n")

#end

// confirm selection.
#debug concat ("\n \n You chose the '", the_objs[OBJ-1], "', \n Now rendering
object '", the_prefix, the_objs[OBJ-1] ,"'.\n")

// use macro.
object { Parse_String (concat (the_prefix, the_objs[OBJ-1]) ) }


Post a reply to this message

From: jr
Subject: Re: printing object's identifier
Date: 19 Mar 2016 12:38:58
Message: <56ed80a2$1@news.povray.org>
hi,

On 19/03/2016 03:13, Bald Eagle wrote:

cool, thank you.  two nits though [cue image of Edvard Munch's "The
Scream" :-)]:

you write:
> I was a little confused, since I run POV-Ray on a Winbloze 7 machine and don't
> often use CLI.

which means that the added comment ("..Try using _____Declare=OBJ=1_____
in the command-line box..") ought to be at the top of the file, along
with the other usage info, to avoid other Windows users getting 'caught
out'.

and wrt the confirmation message, it's one sentence and there's a comma
before the 'now rendering', so the 'now' should be lowercase (unless you
prefer it as two, shorter sentences).


also, given that the .pov is the result of collaborative effort, I think
you ought to rip out the "thank you to" line and add self to authors.

jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: printing object's identifier
Date: 19 Mar 2016 17:30:00
Message: <web.56edc37c374275025e7df57c0@news.povray.org>
jr <cre### [at] gmailcom> wrote:

> cool, thank you.  two nits though [cue image of Edvard Munch's "The
> Scream" :-)]:

Yes, one can't cue the genuine article as it was stolen.

There's _always_ a nit or two.  I do shots of Lagavulin and Rid to keep that to
a minimum when coding...


> which means that the added comment ("..Try using _____Declare=OBJ=1_____
> in the command-line box..") ought to be at the top of the file, along
> with the other usage info, to avoid other Windows users getting 'caught
> out'.

Well, I DO have that arrow pointing to your note
 *   command-line:
 *   povray Declare=OBJ=N ...    <<< Necessary for this scene to work!
 *          ^^^^^^^^^^^^^
to highlight that, up in the green comment block.   I thought that might be
enough.

The line you're referring to is immediately below the yellow highlighted SDL
when the parse error gets triggered, which is where the [new] user's attention
will be at that moment, not at the top of the file.

> and wrt the confirmation message, it's one sentence and there's a comma
> before the 'now rendering', so the 'now' should be lowercase (unless you
> prefer it as two, shorter sentences).

I was just getting my OCD on, and dabbling with the text.

> also, given that the .pov is the result of collaborative effort, I think
> you ought to rip out the "thank you to" line and add self to authors.

Most generous and respectful, but I hardly think that a few minor playful edits
merit that.
I do, however, like very much what you're done with using the array, which is
what caught my attention to begin with.   I had recently been wanting to do
exactly what you illustrate, but didn't _need_ to, and had other things I was
working on (being thwarted by), so I didn't look up the parse string thing,
which I recalled being mentioned in the past.

I think that _THAT_ is the aspect of this that deserves some attention and
development, as I think we could play with it some and produce some valuable
tools and methods.

Two ideas I have - and feel free to pursue these - are a sort of automatic or
randomized code generation - since different string fragments could be strung
together to make a whole functional SDL scene.  :D

More practical though, would be a shorthand method for #declaring lots of
variables.  I was trying to think about a way to do something like:
#declare a=1; b=2; c=3; d=4; ...   and this seems to be the way to accomplish
that.   Either through a loop, or by just arranging the variable names and
values in an array.   That cuts out a ton of hand-typed #declares.

I'm sure there are other things to apply this to, but right now I'm just
brainstorming.

I shall let it all bounce around my head some more.

Well met, Mr. jr.  :)


Post a reply to this message

From: jr
Subject: Re: printing object's identifier
Date: 20 Mar 2016 17:18:22
Message: <56ef139e@news.povray.org>
hi,

On 19/03/2016 21:25, Bald Eagle wrote:

I may get back to the rest of your post, time and inclination
permitting, but the following caught my eye, there appears to be a
certain amount of overlap in interest:

> Two ideas I have - and feel free to pursue these - are a sort of automatic or
> randomized code generation - since different string fragments could be strung
> together to make a whole functional SDL scene.  :D

way ahead of you here (at least wrt design), the idea is a set of GUI
panels[*], one each for camera, light, global_settings, etc.  they're
conceptually stand-alone, so a scene file which is complete bar, say,
the lighting, would have said element inserted when user writes/saves
that scene from the lighting panel.

the benefit, as I see it, is that the modularity allows developing a
complete application piecemeal.

> More practical though, would be a shorthand method for #declaring lots of
> variables.  I was trying to think about a way to do something like:
> #declare a=1; b=2; c=3; d=4; ...   and this seems to be the way to accomplish
> that.   Either through a loop, or by just arranging the variable names and
> values in an array.   That cuts out a ton of hand-typed #declares.

there's the potential problem of having a .pov which won't parse because
of syntax.  and, although the SDL is Turing-complete, I don't think it'd
be on my shortlist of tools when a pre-processor/generator needs
writing.  just a hunch (bearing in mind I'm still fairly new to much of
POv), but I'd keep modified syntax in separate file(s).

jr.


[*] my choice of tool is John Ousterhout's Tool Control Language (Tcl)
and its graphics toolkit.  if not familiar with Tcl, I'd recommend a
visit to https://wiki.tcl.tk.  Tcl is a source distribution but you can
get Windows binaries from www.activestate.com.  and if you feel flush,
the bible aka "Tcl and the Tk Toolkit" by J Ousterhout, now in its 2nd
edition, is very much worth the USD 60 cover price.


Post a reply to this message

From: clipka
Subject: Re: printing object's identifier
Date: 20 Mar 2016 19:47:15
Message: <56ef3683$1@news.povray.org>
Am 19.03.2016 um 22:25 schrieb Bald Eagle:

> More practical though, would be a shorthand method for #declaring lots of
> variables.  I was trying to think about a way to do something like:
> #declare a=1; b=2; c=3; d=4; ...   and this seems to be the way to accomplish
> that.   Either through a loop, or by just arranging the variable names and
> values in an array.   That cuts out a ton of hand-typed #declares.

How about

    #declare (a,b,c,d) = (1,2,3,4);

Besides serving as shorthand for multiple declares, it comes with two
extra benefits that your suggestion doesn't provide:

- The values are grouped together, separate from the list of
identifiers, so that the values can be generated by a single macro
invocation, allowing a macro to return a set of values:

    #macro MyMacro()
        (1,2,3,4)
    #end

    #declare (a,b,c,d) = MyMacro()

- It is already implemented in the current 3.7.1-alpha ;)


Post a reply to this message

From: Bald Eagle
Subject: Re: printing object's identifier
Date: 20 Mar 2016 22:10:00
Message: <web.56ef5744374275025e7df57c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> How about
>
>     #declare (a,b,c,d) = (1,2,3,4);

> - It is already implemented in the current 3.7.1-alpha ;)

http://news.povray.org/povray.beta-test/thread/%3C558b4c09$1@news.povray.org%3E/

I see.   Thanks for the tip :)

Although it's not explicitly stated in your post that I linked, I'm assuming I
can't mix strings and floats and array elements in a single "tuple-style"
declare.

e.g. #declare (a, filename, MyArray[3]) = (4.2, "TestFile", <1, 2, 3>)

or a mix of scalar and vector quantities

#declare (g, h, i) =  (1, <3, 4, 5>, 567.89)

IIRC, someone came up with a way to "trick" POV-Ray to "mix" element types using
arrays of arrays....


Post a reply to this message

From: clipka
Subject: Re: printing object's identifier
Date: 21 Mar 2016 05:37:49
Message: <56efc0ed$1@news.povray.org>
Am 21.03.2016 um 03:07 schrieb Bald Eagle:

> Although it's not explicitly stated in your post that I linked, I'm assuming I
> can't mix strings and floats and array elements in a single "tuple-style"
> declare.
> 
> e.g. #declare (a, filename, MyArray[3]) = (4.2, "TestFile", <1, 2, 3>)
> 
> or a mix of scalar and vector quantities
> 
> #declare (g, h, i) =  (1, <3, 4, 5>, 567.89)

You're assuming wrong there in every respect :)


> IIRC, someone came up with a way to "trick" POV-Ray to "mix" element types using
> arrays of arrays....

In this context, I guess it's worth noting that the above syntax is just
shorthand for multiple declares; there is still no tuple data type, i.e.

    #declare MyTuple = (1,2,3);
    #declare (a,b,c) = MyTuple;

will NOT work.


Post a reply to this message

From: jr
Subject: Re: printing object's identifier
Date: 22 Mar 2016 09:47:51
Message: <56f14d07@news.povray.org>
hi

On 21/03/2016 09:37, clipka wrote:
> Am 21.03.2016 um 03:07 schrieb Bald Eagle:
> 
>> Although it's not explicitly stated in your post that I linked, I'm assuming I
>> can't mix strings and floats and array elements in a single "tuple-style"
>> declare.
>>
>> e.g. #declare (a, filename, MyArray[3]) = (4.2, "TestFile", <1, 2, 3>)
>>
>> or a mix of scalar and vector quantities
>>
>> #declare (g, h, i) =  (1, <3, 4, 5>, 567.89)
> 
> You're assuming wrong there in every respect :)
> 

> In this context, I guess it's worth noting that the above syntax is just
> shorthand for multiple declares; there is still no tuple data type, i.e.
> 
>     #declare MyTuple = (1,2,3);
>     #declare (a,b,c) = MyTuple;
> 
> will NOT work.
> 

do people (still) use CSV files to provide data, because I think the
syntax looks perfect for a record-at-a-time reading of such files.

jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: printing object's identifier
Date: 22 Mar 2016 19:30:00
Message: <web.56f1d47c374275025e7df57c0@news.povray.org>
jr <cre### [at] gmailcom> wrote:

> do people (still) use CSV files to provide data, because I think the
> syntax looks perfect for a record-at-a-time reading of such files.

Sure, it's used all the time.

It's actually the format for POV-Ray's file I/O commands.

http://www.povray.org/documentation/view/3.6.1/238/
"The format of the data to be read must be a series of valid string literals,
float literals, or vector literals separated by commas."


Post a reply to this message

From: jr
Subject: Re: printing object's identifier
Date: 23 Mar 2016 10:09:07
Message: <56f2a383$1@news.povray.org>
hi,

On 22/03/2016 23:25, Bald Eagle wrote:
>> do people (still) use CSV files to provide data, because I think the
>> syntax looks perfect for a record-at-a-time reading of such files.
> 
> Sure, it's used all the time.
> 
> It's actually the format for POV-Ray's file I/O commands.
> 

ouch, I never made the connection.. :-(

jr.


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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