void SMPTE::AddSeconds ( char s )
{
    AddSamples (
        GetSampleRateLong() // samples per second times 10
        * s   // number of seconds
        / 10   // compensate for freq*10
    );
}
void SMPTE::AddSubFrames ( char sf )
{
    AddSamples (
        GetSampleRateLong() // samples per second times 10
        * sf   // number of sub frames
        / GetSMPTERateLong() // divide by smpte rate (frames per second) times 100
        / 10   // divide by 10 to get hundredths of a frame
    );
}
void SMPTE::AddFrames ( char f )
{
    AddSamples (
        GetSampleRateLong()  // samples per second times 10
        * f    // number of frames
        * 10   // times 10
        / GetSMPTERateLong() // divide by smpte rate (frames per second) times 100
    );
}
void SMPTE::AddMinutes ( char m )
{
    AddSamples (
        GetSampleRateLong()
        * m * // samples per second times 10
        ( 60   // seconds per minute
          / 10 ) // compensate for freq*10
    );
}
void SMPTE::AddHours ( char h )
{
    AddSamples ( GetSampleRateLong()  // samples per second times 10
                 * h *
                 ( 60   // seconds per minute
                   * 60  // minutes per hour
                   / 10  // compensate for freq*10
                 )
               );
}
Exemple #6
0
/* The main function! */
void Worley(double at[3], long max_order, double *F, double (*delta)[3], unsigned long *ID)
{
  double x2,y2,z2, mx2, my2, mz2;
  double new_at[3];
  long int_at[3], i;
  
  /* Initialize the F values to "huge" so they will be replaced by the
     first real sample tests. Note we'll be storing and comparing the
     SQUARED distance from the feature points to avoid lots of slow
     sqrt() calls. We'll use sqrt() only on the final answer. */
  for (i=0; i<max_order; i++) F[i]=999999.9;
  
  /* Make our own local copy, multiplying to make mean(F[0])==1.0  */
  new_at[0]=DENSITY_ADJUSTMENT*at[0];
  new_at[1]=DENSITY_ADJUSTMENT*at[1];
  new_at[2]=DENSITY_ADJUSTMENT*at[2];

  /* Find the integer cube holding the hit point */
  int_at[0]=LFLOOR(new_at[0]); /* The macro makes this part a lot faster */
  int_at[1]=LFLOOR(new_at[1]);
  int_at[2]=LFLOOR(new_at[2]);

  /* A simple way to compute the closest neighbors would be to test all
     boundary cubes exhaustively. This is simple with code like: 
     {
       long ii, jj, kk;
       for (ii=-1; ii<=1; ii++) for (jj=-1; jj<=1; jj++) for (kk=-1; kk<=1; kk++)
       AddSamples(int_at[0]+ii,int_at[1]+jj,int_at[2]+kk, 
       max_order, new_at, F, delta, ID);
     }
     But this wastes a lot of time working on cubes which are known to be
     too far away to matter! So we can use a more complex testing method
     that avoids this needless testing of distant cubes. This doubles the 
     speed of the algorithm. */

  /* Test the central cube for closest point(s). */
  AddSamples(int_at[0], int_at[1], int_at[2], max_order, new_at, F, delta, ID);

  /* We test if neighbor cubes are even POSSIBLE contributors by examining the
     combinations of the sum of the squared distances from the cube's lower 
     or upper corners.*/
  x2=new_at[0]-int_at[0];
  y2=new_at[1]-int_at[1];
  z2=new_at[2]-int_at[2];
  mx2=(1.0-x2)*(1.0-x2);
  my2=(1.0-y2)*(1.0-y2);
  mz2=(1.0-z2)*(1.0-z2);
  x2*=x2;
  y2*=y2;
  z2*=z2;
  
  /* Test 6 facing neighbors of center cube. These are closest and most 
     likely to have a close feature point. */
  if (x2<F[max_order-1])  AddSamples(int_at[0]-1, int_at[1]  , int_at[2]  , 
				     max_order, new_at, F, delta, ID);
  if (y2<F[max_order-1])  AddSamples(int_at[0]  , int_at[1]-1, int_at[2]  , 
				     max_order, new_at, F, delta, ID);
  if (z2<F[max_order-1])  AddSamples(int_at[0]  , int_at[1]  , int_at[2]-1, 
				     max_order, new_at, F, delta, ID);
  
  if (mx2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]  , int_at[2]  , 
				     max_order, new_at, F, delta, ID);
  if (my2<F[max_order-1]) AddSamples(int_at[0]  , int_at[1]+1, int_at[2]  , 
				     max_order, new_at, F, delta, ID);
  if (mz2<F[max_order-1]) AddSamples(int_at[0]  , int_at[1]  , int_at[2]+1, 
				     max_order, new_at, F, delta, ID);
  
  /* Test 12 "edge cube" neighbors if necessary. They're next closest. */
  if ( x2+ y2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]-1, int_at[2]  , 
					 max_order, new_at, F, delta, ID);
  if ( x2+ z2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]  , int_at[2]-1, 
					 max_order, new_at, F, delta, ID);
  if ( y2+ z2<F[max_order-1]) AddSamples(int_at[0]  , int_at[1]-1, int_at[2]-1, 
					 max_order, new_at, F, delta, ID);  
  if (mx2+my2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]+1, int_at[2]  , 
					 max_order, new_at, F, delta, ID);
  if (mx2+mz2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]  , int_at[2]+1, 
					 max_order, new_at, F, delta, ID);
  if (my2+mz2<F[max_order-1]) AddSamples(int_at[0]  , int_at[1]+1, int_at[2]+1, 
					 max_order, new_at, F, delta, ID);  
  if ( x2+my2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]+1, int_at[2]  , 
					 max_order, new_at, F, delta, ID);
  if ( x2+mz2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]  , int_at[2]+1, 
					 max_order, new_at, F, delta, ID);
  if ( y2+mz2<F[max_order-1]) AddSamples(int_at[0]  , int_at[1]-1, int_at[2]+1, 
					 max_order, new_at, F, delta, ID);  
  if (mx2+ y2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]-1, int_at[2]  , 
					 max_order, new_at, F, delta, ID);
  if (mx2+ z2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]  , int_at[2]-1, 
					 max_order, new_at, F, delta, ID);
  if (my2+ z2<F[max_order-1]) AddSamples(int_at[0]  , int_at[1]+1, int_at[2]-1, 
					 max_order, new_at, F, delta, ID);  
  
  /* Final 8 "corner" cubes */
  if ( x2+ y2+ z2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]-1, int_at[2]-1, 
					     max_order, new_at, F, delta, ID);
  if ( x2+ y2+mz2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]-1, int_at[2]+1, 
					     max_order, new_at, F, delta, ID);
  if ( x2+my2+ z2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]+1, int_at[2]-1, 
					     max_order, new_at, F, delta, ID);
  if ( x2+my2+mz2<F[max_order-1]) AddSamples(int_at[0]-1, int_at[1]+1, int_at[2]+1, 
					     max_order, new_at, F, delta, ID);
  if (mx2+ y2+ z2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]-1, int_at[2]-1, 
					     max_order, new_at, F, delta, ID);
  if (mx2+ y2+mz2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]-1, int_at[2]+1, 
					     max_order, new_at, F, delta, ID);
  if (mx2+my2+ z2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]+1, int_at[2]-1, 
					     max_order, new_at, F, delta, ID);
  if (mx2+my2+mz2<F[max_order-1]) AddSamples(int_at[0]+1, int_at[1]+1, int_at[2]+1, 
					     max_order, new_at, F, delta, ID);
  
  /* We're done! Convert everything to right size scale */
  for (i=0; i<max_order; i++)
    {
      F[i]=sqrt(F[i])*(1.0/DENSITY_ADJUSTMENT);      
      delta[i][0]*=(1.0/DENSITY_ADJUSTMENT);
      delta[i][1]*=(1.0/DENSITY_ADJUSTMENT);
      delta[i][2]*=(1.0/DENSITY_ADJUSTMENT);
    }
  
  return;
}