Example #1
0
double MartinMandelbrot::compute_value(std::complex<double> z) {
    std::complex<double> delta = z - X;
    if (std::norm(delta) != 0 && std::norm(std::pow(delta, 3)) * 1000 > std::norm(std::pow(delta,2))) {
        compute_seed(z);
        delta = 0;
    }
    for (int i = 0; i<maxiter; i++) {
        std::complex<double> diff = A[i] * delta + B[i] * std::pow(delta, 2) + C[i] * std::pow(delta, 3);
        if (std::norm(seed[i] + diff) >= 4) {
            return i;
        }
    }
    return INT_MAX;
}
Example #2
0
File: seed.c Project: nclack/whisk
SHARED_EXPORT
Seed_Vector *decompose_trace_x(Contour *trace, int width, int height, uint8 *value)
{ static Seed       *seedlist = NULL;
  static int         seedmax  = 0;
  static Seed_Vector myseeds;

  static Seed *boo;

  int    *yaster, ypairs;
  Raster *raster;

  int nseeds;
  int ntrk, mtrk, etrk;
  int r, x, x0;

  nseeds = 0;

  yaster = Yaster_Scan(trace,&ypairs,height);
  
  
  // reencode yaster as (x,y) points - in place
  raster = (Raster *) yaster; 
  for (r = 0; r < ypairs; r++)
  { int mj = yaster[r]/height; // x
    int mn = yaster[r]%height; // y
    raster[r].major = mj;      // x
    raster[r].minor = mn;      // y
  }

#ifdef SHOW_BRANCHES
  printf("\nTRACE:\n"); fflush(stdout);
#endif

  ntrk = mtrk = etrk = 0;
  r = 0;
  while (r < ypairs)
  { x0 = x = raster[r].major;  // the x value for this (vertical) raster
#ifdef SHOW_TRACE
    printf("  %d:",x0); fflush(stdout);
#endif

    ntrk = mtrk;   
    mtrk = etrk;
    // advance over vertically aligned intervals in the raster  
    while (x == x0)
    { raster[r].major = 0;     // mark it
#ifdef SHOW_TRACE
      //                      y0              y1
      printf(" (%d,%d)",raster[r].minor,raster[r+1].minor-1); fflush(stdout);
#endif
      r += 2;                  // move to next pair
      if (r >= ypairs) break;
      x = raster[r].major;
    }
    etrk = r;   // remember the end of this sequence of intervals
#ifdef SHOW_TRACE
    printf("\n"); fflush(stdout);
#endif

    { int  m, n;
      int  mb, me;
      int  nb, ne;
      int   c, o;
      Seed *s;

      m = mtrk;
      n = ntrk;
      c = 0;
      while (n < mtrk)
      { if (m >= etrk)            //if the end of this sequence of intervals has been passed...
          mb = me = ne;           //...empty m interval located at end of n
        else                      
        { mb = raster[m].minor;   //beginning of the m'th interval
          me = raster[m+1].minor; //end       of the m'th interval
        }
        nb = raster[n].minor;     //beginning of the n'th interval
        ne = raster[n+1].minor;   //end       of the n'th interval

        // init
        if (me > nb && ne > mb)   //if the intervals have an intersection...
        { raster[m].major += 1;   //...increment m's id
          c += 1;                 //...count
        }

        if (me < ne)              //if m's end is before n's ...
          m += 2;                 //...increment to interval following m and move on
        else                      //else m and n intersect or m is past n
        { raster[n+1].major = -1; //...mark next
          if (c > 1)                  //if there was more than one intersection event...
          { // move o back till all intersection counts are accounted for
            //   and add counts into interval labels
            o = m;
            while (1)
            { if (me > nb && ne > mb) // if m and n intersect ...
              { raster[o].major += 1; // ...increment label
                if (--c <= 0) break;  // ...clear counts
              }
              o -= 2;                 // back up an interval
              mb = raster[o].minor;
              me = raster[o+1].minor;
            }
          }
          else if (c == 1)            // if only one intersection count
          { if (ne > mb)
            { if ((n+2 >= mtrk || raster[n+2].minor >= me) && raster[m].major <= 1)
              raster[n+1].major = m;
            }
            else
            { if (raster[m-2].major <= 1)
              raster[n+1].major = m-2;
            }
          }
#ifdef SHOW_BRANCHES
          if (raster[n+1].major < 0)
            printf("Track (%d,%d) %d expires\n",
                raster[n].minor,raster[n+1].minor-1,raster[n].major);
#endif
          n += 2;
          c  = 0;
        }
      }

      for (m = mtrk; m < etrk; m += 2) //iterate over sequence of vertically aligned intervals
        if (raster[m].major != 1)      //if unlabelled
        {
#ifdef SHOW_BRANCHES
          printf("Track (%d,%d) = %d starts\n",
              raster[m].minor,raster[m+1].minor-1,raster[m].major);
#endif
          raster[m].major = 1;         //...init label
        }

      for (n = ntrk; n < mtrk; n += 2)
      { c = raster[n+1].major;
        raster[n+1].major = x0-1;      // set back to x0
        if (c < 0)                     // if termination...compute seed on n'th
        { if (nseeds >= seedmax)
          { seedmax  = 1.2*nseeds + 10;
            seedlist = (Seed *)
              Guarded_Realloc(seedlist,sizeof(Seed)*seedmax,Program_Name());
          }
          s = compute_seed(raster,n,x0-1,width,value);
          if (s != NULL)
            seedlist[nseeds++] = *s;
        }
        else
          raster[c].major = raster[n].major+1;
      }
    } //end context
  } //end while

  { int   m;
    Seed *s;

    for (m = mtrk; m < etrk; m += 2)
    { if (nseeds >= seedmax)
      { seedmax  = 1.2*nseeds + 10;
        seedlist = (Seed *)
          Guarded_Realloc(seedlist,sizeof(Seed)*seedmax,Program_Name());
      }
      s = compute_seed(raster,m,x0,width,value);
      if (s != NULL)
        seedlist[nseeds++] = *s;
#ifdef SHOW_BRANCHES
      printf("Track (%d,%d) %d = 0 expires\n",
          raster[m].minor,raster[m+1].minor-1,raster[m].major);
#endif
    }
  }

  myseeds.nseeds = nseeds;
  myseeds.seeds  = seedlist;
  return (&myseeds);
}