POV-Ray : Newsgroups : povray.binaries.scene-files : eval_pigment() and trace() HowTo Server Time: 18 Jun 2019 06:39:41 GMT
  eval_pigment() and trace() HowTo (Message 1 to 10 of 15)  
Goto Latest 10 Messages Next 5 Messages >>>
From: Thomas de Groot
Subject: eval_pigment() and trace() HowTo
Date: 7 Jul 2016 11:57:54
Message: <577e43c2@news.povray.org>
As promised, I have put together two test scenes using eval_pigment() 
and trace(). The other files are used or can be used with the tests. 
Note: For the carpet scene, you need first to write data to file. This 
is explained within the scene file.

Enjoy!

-- 
Thomas


Post a reply to this message


Attachments:
Download 'eval_pigment.zip' (1006 KB)

From: Bald Eagle
Subject: Re: eval_pigment() and trace() HowTo
Date: 7 Jul 2016 14:05:00
Message: <web.577e60ee734cd2575e7df57c0@news.povray.org>
Thanks for that!
Apparently I had an eval_pigment.zip in my download directory already from
3/4/2016 ...  :O
Way too many macros and tools and scene files, etc. to keep up with, which is a
good thing, I guess.

For general information purposes,
eval_pigment is a macro that is defined in functions.inc as shown below.

-----------------------------------------------
#macro eval_pigment(pigm, vec)
    #local fn = function { pigment { pigm } }
    #local result = (fn(vec.x, vec.y, vec.z));
    result
#end
-----------------------------------------------

I think that
jpeg "Oriental Carpets/Carpet_01.jpg"
ought to be
jpeg "Carpet_01.jpg"

I see:
#declare WriteStrands = off; //set to 'on' for the first pass.

Isn't there a way to just check if the file exists, and if not, create it?
I looked - but it's not clear that this is possible.
Seemed like a useful and desirable feature to be added, if that's the case.


Also, something just caught my eye in that older version:
It seems that the Lum macro tries to evaluate the r, g, and b values, take 1/3
of that sum, and if that's less than 0.5, put a RED cylinder instead of a blue.
 But at the left front of the render, there's a red cylinder sitting atop a high
part of the heightfield where everything else is blue.   Seems anomalous.

old zip attached here for those who want to play along.


Post a reply to this message


Attachments:
Download 'eval_pigment.zip' (104 KB)

From: Le Forgeron
Subject: Re: eval_pigment() and trace() HowTo
Date: 7 Jul 2016 14:56:41
Message: <577e6da9$1@news.povray.org>
Le 07/07/2016 16:02, Bald Eagle a écrit :
> Isn't there a way to just check if the file exists, and if not, create it?
> I looked - but it's not clear that this is possible.
> Seemed like a useful and desirable feature to be added, if that's the case.

isn't *file_exists(S)* part of the solution ?

http://wiki.povray.org/content/Reference:Numeric_Expressions


Post a reply to this message

From: Bald Eagle
Subject: Re: eval_pigment() and trace() HowTo
Date: 7 Jul 2016 16:25:00
Message: <web.577e8253734cd2575e7df57c0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> isn't *file_exists(S)* part of the solution ?
>
> http://wiki.povray.org/content/Reference:Numeric_Expressions

Indeed, my friend, it is.

file_exists(S)
Attempts to open the file specified by the string S. The current directory and
all library directories specified by the Library_Path or +L options are also
searched. See Library Paths for details. Returns 1 if successful and 0 if
unsuccessful.

Although I suspected this existed, I did not think to look under "Numeric
Expressions" - I was looking under #read, #write, #append, etc.

I was hoping that there would be a similar example to

#fopen FILE_HANDLE_IDENTIFIER "mydata.txt" read
#while (defined(FILE_HANDLE_IDENTIFIER))
  #read (FILE_HANDLE_IDENTIFIER,Var1,Var2,Var3)
  ...
#end

for the file commands, but alas, no.


So here ya go:
############################################################################


#version 3.7;
global_settings {assumed_gamma 1.0}
#include "debug.inc"
  Set_Debug (true)
#declare FILENAME = "TestFile.txt";
//#declare FILE_HANDLE_IDENTIFIER = 1;

#declare ONE = 0; #declare TWO = 0; #declare THREE = 0; #declare FOUR = 0;
#declare FIVE = 0;

#declare Existence = file_exists (FILENAME);
// Attempts to open the file specified by the string S.
// The current directory and all library directories specified by the
Library_Path or +L options are also searched.
// See Library Paths for details. Returns 1 if successful and 0 if unsuccessful.

#debug "\n"
#debug
"#######################################################################################################\n"

#debug concat("Checking for existence of file ", FILENAME, " ... \n")
#declare Existence = file_exists (FILENAME);
#if (Existence = 1)
 #debug concat ("Directive 'file_exists (FILENAME)' = ", str (Existence, 1, 1),
"    File ", FILENAME, " exists. \n")
#else
 #debug concat ("Directive 'file_exists (FILENAME)' = ", str (Existence, 1, 1),
"    File ", FILENAME, " does not exist. \n")
#end
#debug "\n"

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

#debug concat("Opening file ", FILENAME, " for writing ... \n")
#fopen  FILE_HANDLE_IDENTIFIER FILENAME write
#debug concat("Writing data to file ... \n")
#write (FILE_HANDLE_IDENTIFIER, 1, ", ", 2, ", ", 3, ", ", 4, ", ", 5,  ", \n")
#write (FILE_HANDLE_IDENTIFIER, 6, ", ", 7, ", ", 8, ", ", 9, ", ", 10, "\n")
#debug concat("Closing file ... \n")
#fclose FILE_HANDLE_IDENTIFIER
#debug "\n"

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

#debug concat("Checking for existence of file ", FILENAME, " ... \n")
#declare Existence = file_exists (FILENAME);
#if (Existence = 1)
 #debug concat ("Directive 'file_exists (FILENAME)' = ", str (Existence, 1, 1),
"    File ", FILENAME, " exists. \n")
#else
 #debug concat ("Directive 'file_exists (FILENAME)' = ", str (Existence, 1, 1),
"    File ", FILENAME, " does not exist. \n")
#end
#debug "\n"

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

#declare Existence = file_exists (FILENAME);
#if (Existence = 1)
 #debug concat("Opening file ", FILENAME, " for reading ... \n")
 #debug "\n"
 #fopen  FILE_HANDLE_IDENTIFIER FILENAME read
 // If you attempt to read past end-of-file, the file is automatically closed
and the FILE_HANDLE_IDENTIFIER is deleted from the symbol table.
 // This means that the boolean function defined(FILE_HANDLE_IDENTIFIER) can be
used to detect end-of-file.

 #while (defined (FILE_HANDLE_IDENTIFIER))
  #debug "File open, reading data from file... \n"
  #read (FILE_HANDLE_IDENTIFIER, ONE, TWO, THREE, FOUR, FIVE)
  // output 5-term color expression data
  #declare Vector = <ONE, TWO, THREE, FOUR, FIVE>;
  #debug concat( "Vector.x =        ", str(Vector.x, 3, 0), "\n")
  #debug concat( "Vector.u =        ", str(Vector.u, 3, 0), "\n\n")
  #debug concat( "Vector.y =        ", str(Vector.y, 3, 0), "\n")
  #debug concat( "Vector.v =        ", str(Vector.v, 3, 0), "\n\n")
  #debug concat( "Vector.z =        ", str(Vector.z, 3, 0), "\n\n")
  #debug concat( "Vector.t =        ", str(Vector.t, 3, 0), "\n")
  #debug concat( "Vector.filter =   ", str(Vector.filter, 3, 0), "\n\n")
  #debug concat( "Vector.transmit = ", str(Vector.transmit, 3, 0), "\n\n")
 #end

 #debug "End of file (EOF) reached. File automatically closed. \n"

 #fclose FILE_HANDLE_IDENTIFIER // just to make sure
#else
 #debug "File ", FILENAME, " does not exist. Cannot open for reading. \n"
#end // end if

#debug
"#######################################################################################################\n"
#debug "\n"


Post a reply to this message


Attachments:
Download 'filecommands.pov.txt' (4 KB)

From: Thomas de Groot
Subject: Re: eval_pigment() and trace() HowTo
Date: 8 Jul 2016 07:05:52
Message: <577f50d0$1@news.povray.org>
On 7-7-2016 16:02, Bald Eagle wrote:
> Thanks for that!
> Apparently I had an eval_pigment.zip in my download directory already from
> 3/4/2016 ...  :O
> Way too many macros and tools and scene files, etc. to keep up with, which is a
> good thing, I guess.

I totally forgot about that one...

> [snip]
> I think that
> jpeg "Oriental Carpets/Carpet_01.jpg"
> ought to be
> jpeg "Carpet_01.jpg"

Absolutely. Escaped my scrutiny ;-)

>
> I see:
> #declare WriteStrands = off; //set to 'on' for the first pass.
>
> Isn't there a way to just check if the file exists, and if not, create it?
> I looked - but it's not clear that this is possible.
> Seemed like a useful and desirable feature to be added, if that's the case.
>

LeForgeron gave us the solution. I confess that I had not been aware of 
that possibility. One more reason to play :-)

>
> Also, something just caught my eye in that older version:
> It seems that the Lum macro tries to evaluate the r, g, and b values, take 1/3
> of that sum, and if that's less than 0.5, put a RED cylinder instead of a blue.
>  But at the left front of the render, there's a red cylinder sitting atop a high
> part of the heightfield where everything else is blue.   Seems anomalous.
>

No idea.


-- 
Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: eval_pigment() and trace() HowTo
Date: 9 Jul 2016 06:52:42
Message: <57809f3a@news.povray.org>
On 7-7-2016 16:02, Bald Eagle wrote:
> I see:
> #declare WriteStrands = off; //set to 'on' for the first pass.
>
> Isn't there a way to just check if the file exists, and if not, create it?
> I looked - but it's not clear that this is possible.
> Seemed like a useful and desirable feature to be added, if that's the case.
>

In fact, there is a simple reason why I did not use the file_exists(S) 
function, now that I think about it. It is that you may want to test 
different settings before choosing the final ones (at least that is how 
I work) and so - except for the very first time - there is always a file 
present.

-- 
Thomas


Post a reply to this message

From: clipka
Subject: Re: eval_pigment() and trace() HowTo
Date: 9 Jul 2016 10:38:34
Message: <5780d42a@news.povray.org>
Am 09.07.2016 um 08:52 schrieb Thomas de Groot:
> On 7-7-2016 16:02, Bald Eagle wrote:
>> I see:
>> #declare WriteStrands = off; //set to 'on' for the first pass.
>>
>> Isn't there a way to just check if the file exists, and if not, create
>> it?
>> I looked - but it's not clear that this is possible.
>> Seemed like a useful and desirable feature to be added, if that's the
>> case.
>>
> 
> In fact, there is a simple reason why I did not use the file_exists(S)
> function, now that I think about it. It is that you may want to test
> different settings before choosing the final ones (at least that is how
> I work) and so - except for the very first time - there is always a file
> present.

You could use something like:

    #declare WriteStrands = off; // set to 'on' to force re-writing
    ...
    #if (!file_exists(...)) #declare WriteStrands = on; #end


Post a reply to this message

From: Thomas de Groot
Subject: Re: eval_pigment() and trace() HowTo
Date: 9 Jul 2016 11:17:16
Message: <5780dd3c$1@news.povray.org>
On 9-7-2016 12:38, clipka wrote:
> Am 09.07.2016 um 08:52 schrieb Thomas de Groot:
>> On 7-7-2016 16:02, Bald Eagle wrote:
>>> I see:
>>> #declare WriteStrands = off; //set to 'on' for the first pass.
>>>
>>> Isn't there a way to just check if the file exists, and if not, create
>>> it?
>>> I looked - but it's not clear that this is possible.
>>> Seemed like a useful and desirable feature to be added, if that's the
>>> case.
>>>
>>
>> In fact, there is a simple reason why I did not use the file_exists(S)
>> function, now that I think about it. It is that you may want to test
>> different settings before choosing the final ones (at least that is how
>> I work) and so - except for the very first time - there is always a file
>> present.
>
> You could use something like:
>
>     #declare WriteStrands = off; // set to 'on' to force re-writing
>     ...
>     #if (!file_exists(...)) #declare WriteStrands = on; #end
>

But, that would always set it to on, even when you want it to be off, or 
do I misunderstand this?

-- 
Thomas


Post a reply to this message

From: clipka
Subject: Re: eval_pigment() and trace() HowTo
Date: 9 Jul 2016 11:42:44
Message: <5780e334@news.povray.org>
Am 09.07.2016 um 13:17 schrieb Thomas de Groot:
> On 9-7-2016 12:38, clipka wrote:
>> Am 09.07.2016 um 08:52 schrieb Thomas de Groot:
>>> On 7-7-2016 16:02, Bald Eagle wrote:
>>>> I see:
>>>> #declare WriteStrands = off; //set to 'on' for the first pass.
>>>>
>>>> Isn't there a way to just check if the file exists, and if not, create
>>>> it?
>>>> I looked - but it's not clear that this is possible.
>>>> Seemed like a useful and desirable feature to be added, if that's the
>>>> case.
>>>>
>>>
>>> In fact, there is a simple reason why I did not use the file_exists(S)
>>> function, now that I think about it. It is that you may want to test
>>> different settings before choosing the final ones (at least that is how
>>> I work) and so - except for the very first time - there is always a file
>>> present.
>>
>> You could use something like:
>>
>>     #declare WriteStrands = off; // set to 'on' to force re-writing
>>     ...
>>     #if (!file_exists(...)) #declare WriteStrands = on; #end
>>
> 
> But, that would always set it to on, even when you want it to be off, or
> do I misunderstand this?

It would always set it to on _if_ the file does not already exist, so
you don't need to manually set it to on for the first run.

Of course if there are any use cases where you might want to have _no_
file at all, then this is of no use.


Post a reply to this message

From: Thomas de Groot
Subject: Re: eval_pigment() and trace() HowTo
Date: 10 Jul 2016 07:00:47
Message: <5781f29f$1@news.povray.org>
On 9-7-2016 13:42, clipka wrote:
> Am 09.07.2016 um 13:17 schrieb Thomas de Groot:
>> On 9-7-2016 12:38, clipka wrote:
>>> Am 09.07.2016 um 08:52 schrieb Thomas de Groot:
>>>> On 7-7-2016 16:02, Bald Eagle wrote:
>>>>> I see:
>>>>> #declare WriteStrands = off; //set to 'on' for the first pass.
>>>>>
>>>>> Isn't there a way to just check if the file exists, and if not, create
>>>>> it?
>>>>> I looked - but it's not clear that this is possible.
>>>>> Seemed like a useful and desirable feature to be added, if that's the
>>>>> case.
>>>>>
>>>>
>>>> In fact, there is a simple reason why I did not use the file_exists(S)
>>>> function, now that I think about it. It is that you may want to test
>>>> different settings before choosing the final ones (at least that is how
>>>> I work) and so - except for the very first time - there is always a file
>>>> present.
>>>
>>> You could use something like:
>>>
>>>     #declare WriteStrands = off; // set to 'on' to force re-writing
>>>     ...
>>>     #if (!file_exists(...)) #declare WriteStrands = on; #end
>>>
>>
>> But, that would always set it to on, even when you want it to be off, or
>> do I misunderstand this?
>
> It would always set it to on _if_ the file does not already exist, so
> you don't need to manually set it to on for the first run.
>
> Of course if there are any use cases where you might want to have _no_
> file at all, then this is of no use.
>

I think you misunderstand my use of the on/off switch. The writing away 
of data is only meant as time saving later on when reading the data 
(always faster than having to do the complete calculations for each 
run). So, the switching off of the writing section (once you are 
satisfied with the written data) is essential. A file_exist switch can 
only make sense to check the existence of a file in the "Read" section 
of the macro.

-- 
Thomas


Post a reply to this message

Goto Latest 10 Messages Next 5 Messages >>>

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