POV-Ray : Newsgroups : povray.beta-test : HF Macros - serious bug, optimizations and little suggestion Server Time
1 Nov 2024 11:13:32 EDT (-0400)
  HF Macros - serious bug, optimizations and little suggestion (Message 1 to 6 of 6)  
From:
Subject: HF Macros - serious bug, optimizations and little suggestion
Date: 16 May 2002 02:59:03
Message: <28k6eu8aqjsbge8bfgjhgbpk609jd8jp2q@4ax.com>
RC4 for Win

Currently HF Macros works only when resolution <xRes,zRes> is specified with
xRes=zRes. For xRes<>zRes it stops parsing with error in face_indices. It is
becouse little but important mistake in last loop of HFCreate_() macro:
         #local A = (J  )+(K  )*zRes;
         #local B = (J+1)+(K  )*zRes;
         #local C = (J+1)+(K+1)*zRes;
         #local D = (J  )+(K+1)*zRes;
         <A,B,C>,<A,C,D>,
should be:
         #local A = (J  )*zRes+(K  );
         #local B = (J+1)*zRes+(K  );
         #local C = (J+1)*zRes+(K+1);
         #local D = (J  )*zRes+(K+1);
         <A,B,C>,<A,C,D>,
But since I was in this part I started to optimize this stuff. Note that
optimized part is exactly the same as:
         #local A = (J  )*zRes+(K  );
         #local B = A + zRes;
         #local C = A + zRes + 1;
         #local D = A + 1;
         <A,B,C>,<A,C,D>,
But then it is exactly the same as:
         #local A = J*zRes+K;
         <A,A+zRes,A+zRes+1>,<A,A+zRes+1,A+1>,
But then it is exactly the same as:
         #local A = J*zRes+K;
         <0,zRes,zRes+1>+A,<0,zRes+1,1>+A,
But then it is exactly the same as (extending quoted part to whole loop):
   #local F1=<0,zRes,zRes+1>;
   #local F2=<0,zRes+1,1>;
   #local J=0;
   #while (J<xRes-1)
      #local K=0;
      #while (K<zRes-1)
         #local A=J*zRes+K;
         F1+A,F2+A,
         #local K=K+1;
      #end
      #local J=J+1;
   #end
But then A contains constant part J*zRes so why not move it before K-loop :
   #local F1=<0,zRes,zRes+1>;
   #local F2=<0,zRes+1,1>;
   #local J = 0;
   #while (J<xRes-1)
      #local A = J*zRes;
      #local K = 0;
      #while (K<zRes-1)
         F1+A,F2+A,
         #local A = A+1;
         #local K = K+1;
      #end
      #local J = J+1;
   #end
But then do we really need two indexes A and K ?
   #local F1=<0,zRes,zRes+1>;
   #local F2=<0,zRes+1,1>;
   #local J=0;
   #while (J<xRes-1)
      #local A=J*zRes;
      #while (mod(A+1,zRes))
         F1+A,F2+A,
         #local A=A+1;
      #end
      #local J=J+1;
   #end
Now it is little less readable but in my tests decreased parsing time from 36
seconds to 32 seconds. So let's look into two other loops in HFCreate_. Do we
really need to assign exported value to variable and then export it and forget
variable ? Can't we remove assigment ?
            #local Nvect =
            vnormalize(vcross(
               PArr[J][K+1]-PArr[J][K-1],
               PArr[J+1][K]-PArr[J-1][K]
            ));
            Nvect,
could be just:
            vnormalize(vcross(
               PArr[J][K+1]-PArr[J][K-1],
               PArr[J+1][K]-PArr[J-1][K]
            )),
and
            #local UVvect = <(J-1)/(xRes-1),(K-1)/(zRes-1)>;
            UVvect,
could be just:
            <(J-1)/(xRes-1),(K-1)/(zRes-1)>,
This change decreased parsing time for next 2 seconds. So alltogether I saved
~11% of parsing. I measured time of parsing scenes/incdemo/shapes.pov. I have
also little suggestion to this file. Perhaps could be good to additionaly
present UV-mapping on those macros. Just change apropriate parameter of macros
and change pigment{rgb1} to something like pigment{checker scale .1}.

ABX


Post a reply to this message

From: Jérôme Grimbert
Subject: Re: HF Macros - serious bug, optimizations and little suggestion
Date: 16 May 2002 07:44:49
Message: <3CE39BC9.E5F906F1@atosorigin.com>


[About a bug, maybe he is right, I do not know]

>          #local A = (J  )*zRes+(K  );
>          #local B = (J+1)*zRes+(K  );
>          #local C = (J+1)*zRes+(K+1);
>          #local D = (J  )*zRes+(K+1);
>          <A,B,C>,<A,C,D>,
> But since I was in this part I started to optimize this stuff. Note that
> optimized part is exactly the same as:
>          #local A = (J  )*zRes+(K  );
>          #local B = A + zRes;
>          #local C = A + zRes + 1;
>          #local D = A + 1;
>          <A,B,C>,<A,C,D>,

I do not agree.
Mathematically, you are correct.
But Computationaly, you may end up with overlapping part and holes,
because the way you compute the coordinates are not always
exactly the same when you are iterating in the loop.

Maybe I'm just paranoid.


Post a reply to this message

From:
Subject: Re: HF Macros - serious bug, optimizations and little suggestion
Date: 16 May 2002 09:32:59
Message: <n5d7eukjgaek8u1steguvccorcd7dfgqbi@4ax.com>

<jer### [at] atosorigincom> wrote:
> Mathematically, you are correct.
> But Computationaly, you may end up with overlapping part and holes,
> because the way you compute the coordinates are not always
> exactly the same when you are iterating in the loop.

What you mean ? This time I have tested my suggestions.

ABX


Post a reply to this message

From: Mark Weyer
Subject: Re: HF Macros - serious bug, optimizations and little suggestion
Date: 16 May 2002 10:17:55
Message: <3CE3B24B.92CE09BD@frege.mathematik.uni-freiburg.de>
> > Mathematically, you are correct.
> > But Computationaly, you may end up with overlapping part and holes,

> What you mean ? This time I have tested my suggestions.

What I think J'er^ome means is that you assert the distributive law,
ie (a+b)*c=a*c+b*c. This law holds mathemtically but not
numerically. Counterexample:
  (2.01+2.01)*0.5 = 4.02*0.5 = 2.01
  2.01*0.5+2.01*0.5 = 1.00+1.00 = 2.00
or
  2.01*0.5+2.01*0.5 = 1.01+1.01 = 2.02
depending on how you round 1.005. This example uses 3-digit base-10
representation.

  Mark Weyer


Post a reply to this message

From:
Subject: Re: HF Macros - serious bug, optimizations and little suggestion
Date: 16 May 2002 10:33:51
Message: <4hg7eu8ttso70cs3abpbvf06gmli6knftl@4ax.com>
On Thu, 16 May 2002 15:21:15 +0200, Mark Weyer
<wey### [at] fregemathematikuni-freiburgde> wrote:
> 2.01*0.5+2.01*0.5 = 1.01+1.01 = 2.02
> depending on how you round 1.005.

Each of components is integer (or should be becouse everything is float
internally during parsing). If integers are represented with very small
floating point accuracy then such problem appear for original version in
macros as well so my optimizations are still valid.

ABX


Post a reply to this message

From: Rune
Subject: Re: HF Macros - serious bug, optimizations and little suggestion
Date: 16 May 2002 18:49:28
Message: <3ce43778@news.povray.org>
ABX,

thanks for the bug fix and the optimizations.

Rune
--
3D images and anims, include files, tutorials and more:
Rune's World:  http://rsj.mobilixnet.dk (updated Apr 14)
POV-Ray Users: http://rsj.mobilixnet.dk/povrayusers/
POV-Ray Ring:  http://webring.povray.co.uk


Post a reply to this message

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