Example #1
0
void ScorePageSimple::resetAccidentals(Array<int>& accidentals, int keysig) {
   if (keysig == 0) {
      accidentals.zero();
      return;
   }

   if (keysig > 0) {
      if (keysig > 0) accidentals[3] = +1;  // F-sharp
      if (keysig > 1) accidentals[0] = +1;  // C-sharp
      if (keysig > 2) accidentals[4] = +1;  // G-sharp
      if (keysig > 3) accidentals[1] = +1;  // D-sharp
      if (keysig > 4) accidentals[5] = +1;  // A-sharp
      if (keysig > 5) accidentals[2] = +1;  // E-sharp
      if (keysig > 6) accidentals[6] = +1;  // B-sharp
      return;
   }

   if (keysig < 0)  accidentals[6] = -1;  // B-flat
   if (keysig < -1) accidentals[2] = -1;  // E-flat
   if (keysig < -2) accidentals[5] = -1;  // A-flat
   if (keysig < -3) accidentals[1] = -1;  // D-flat
   if (keysig < -4) accidentals[4] = -1;  // G-flat
   if (keysig < -5) accidentals[0] = -1;  // C-flat
   if (keysig < -6) accidentals[3] = -1;  // F-flat
}
Example #2
0
void initialization(void) { 
   eventBuffer.setPollPeriod(10);
   notetimes.reset();
   notetimes.insert(0);
   notetimes.insert(0);
   notes.reset();
   notes.insert(0);
   notes.insert(0);
   noteontimes.zero();
}
Example #3
0
void SubImage::reInitialize(void) {

    memcpy(tmpFT.get(),imgFT.get(),imgSize*imgSize*sizeof(complex_t));                          // make a temporary copy to pass to addDifftoFT below

    copy(img);                                                                                  // copy current cut-out to (double) working copy.

    stats.getStats( img.get(), imgSize*imgSize, ST_VALUES );     // TODO test if this is necessary or if the stats for the larger area is sufficient

    double avg = stats.mean;
    size_t nEl = img.nElements();
    double* imgPtr = img.get();
    const double* winPtr = window.get();
    if( object.fittedPlane.nElements() == nEl ) {
        const float* planePtr = object.fittedPlane.get();
        for( size_t i=0; i<nEl; ++i) {
            // Note: mean(plane) = 0, so subtracting it will not affect the mean value.
            imgPtr[i] = (imgPtr[i]-avg-planePtr[i])*winPtr[i]+avg;
        }
    } else {
        transform(imgPtr, imgPtr+nEl, window.get(), imgPtr,
        [avg](const double& a, const double& b) {
            return (a-avg)*b+avg;
        }
                 );
    }
    transpose(imgPtr,imgSize,imgSize);                                                       // to match MvN

    if (imgSize == otfSize) {                                                                   // imgSize = 2*pupilSize
        imgFT.reset(imgPtr, imgSize, imgSize, FT_FULLCOMPLEX );                              // full-complex for now, perhaps half-complex later for performance
    } else {                                                                                    // imgSize > 2*pupilSize should never happen (cf. calculatePupilSize)
        int offset = (otfSize - imgSize) / 2;
        Array<double> tmp (otfSize, otfSize);
        tmp.zero();
        double* tmpPtr = tmp.get();
        for (int i = 0; i < imgSize; ++i) {
            memcpy (tmpPtr + offset * (otfSize + 1) + i * otfSize, imgPtr + i * imgSize, imgSize * sizeof (double));
        }
        imgFT.reset (tmp.get(), otfSize, otfSize, FT_FULLCOMPLEX );                             // full-complex for now, perhaps half-complex later for performance
    }


    FourierTransform::reorder(imgFT);                                                           // keep FT in centered form
    object.addDiffToFT( imgFT, tmpFT );

}
Example #4
0
void SubImage::newCutout(void) {

    memcpy(tmpFT.get(),imgFT.get(),imgSize*imgSize*sizeof(complex_t));                          // make a temporary copy to pass to addDifftoFT below

    copy(img);                                                                                  // copy current cut-out to (double) working copy.

    stats.getStats( img.get(), imgSize*imgSize, ST_VALUES );     // TODO test if this is necessary or if the stats for the larger area is sufficient

    double avg = stats.mean;
    transform(img.get(), img.get()+img.nElements(), window.get(), img.get(),
    [avg](const double& a, const double& b) {
        return (a-avg)*b+avg;
    }
             );

    transpose(img.get(),imgSize,imgSize);                                                       // to match MvN

    if (imgSize == otfSize) {                                                                   // imgSize = 2*pupilSize
        imgFT.reset(img.get(), imgSize, imgSize, FT_FULLCOMPLEX );                              // full-complex for now, perhaps half-complex later for performance
    } else {                                                                                    // imgSize > 2*pupilSize should never happen (cf. calculatePupilSize)
        int offset = (otfSize - imgSize) / 2;
        Array<double> tmp (otfSize, otfSize);
        tmp.zero();
        double* imgPtr = img.get();
        double* tmpPtr = tmp.get();
        for (int i = 0; i < imgSize; ++i) {
            memcpy (tmpPtr + offset * (otfSize + 1) + i * otfSize, imgPtr + i * imgSize, imgSize * sizeof (double));
        }
        imgFT.reset (tmp.get(), otfSize, otfSize, FT_FULLCOMPLEX );                             // full-complex for now, perhaps half-complex later for performance
    }


    FourierTransform::reorder(imgFT);                                                           // keep FT in centered form
    object.addDiffToFT( imgFT, tmpFT );

}
Example #5
0
dt_t *ArrayInitializer::toDt()
{
    //printf("ArrayInitializer::toDt('%s')\n", toChars());
    Type *tb = type->toBasetype();
    Type *tn = tb->next->toBasetype();

    if (tn->ty == Tbit)
        return toDtBit();

    Array dts;
    unsigned size;
    unsigned length;
    dt_t *dt;
    dt_t *d;
    dt_t **pdtend;

    //printf("\tdim = %d\n", dim);
    dts.setDim(dim);
    dts.zero();

    size = tn->size();

    length = 0;
    for (size_t i = 0; i < index.dim; i++)
    {   Expression *idx;
        Initializer *val;

        idx = (Expression *)index.data[i];
        if (idx)
            length = idx->toInteger();
        //printf("\tindex[%d] = %p, length = %u, dim = %u\n", i, idx, length, dim);

        assert(length < dim);
        val = (Initializer *)value.data[i];
        dt = val->toDt();
        if (dts.data[length])
            error(loc, "duplicate initializations for index %d", length);
        dts.data[length] = (void *)dt;
        length++;
    }

    Expression *edefault = tb->next->defaultInit();
#ifdef IN_GCC
    dt_t * sadefault = NULL;

    if (tn->ty == Tsarray)
        tn->toDt(& sadefault);
    else
        edefault->toDt(& sadefault);
#else
    unsigned n = 1;
    for (Type *tbn = tn; tbn->ty == Tsarray; tbn = tbn->next->toBasetype())
    {   TypeSArray *tsa = (TypeSArray *)tbn;

        n *= tsa->dim->toInteger();
    }
#endif

    d = NULL;
    pdtend = &d;
    for (size_t i = 0; i < dim; i++)
    {
        dt = (dt_t *)dts.data[i];
#ifdef IN_GCC
        pdtend = dtcontainer(pdtend, NULL, dt ? dt : sadefault);
#else
        if (dt)
            pdtend = dtcat(pdtend, dt);
        else
        {
            for (size_t j = 0; j < n; j++)
                pdtend = edefault->toDt(pdtend);
        }
#endif
    }
    switch (tb->ty)
    {
    case Tsarray:
    {   unsigned tadim;
        TypeSArray *ta = (TypeSArray *)tb;

        tadim = ta->dim->toInteger();
        if (dim < tadim)
        {
            if (edefault->isBool(FALSE))
                // pad out end of array
                // (ok for GDC as well)
                pdtend = dtnzeros(pdtend, size * (tadim - dim));
            else
            {
                for (size_t i = dim; i < tadim; i++)
#ifdef IN_GCC
                    pdtend = dtcontainer(pdtend, NULL, sadefault);
#else
                {   for (size_t j = 0; j < n; j++)
                        pdtend = edefault->toDt(pdtend);
                }
#endif
            }
        }
        else if (dim > tadim)
        {
#ifdef DEBUG
            printf("1: ");
#endif
            error(loc, "too many initializers, %d, for array[%d]", dim, tadim);
        }
#ifdef IN_GCC
        dt_t * cdt = NULL;
        dtcontainer(& cdt, type, d);
        d = cdt;
#endif
        break;
    }

    case Tpointer:
    case Tarray:
    {   // Create symbol, and then refer to it
        Symbol *s = static_sym();
        s->Sdt = d;
        outdata(s);

        d = NULL;
        if (tb->ty == Tarray)
            dtsize_t(&d, dim);
        dtxoff(&d, s, 0, TYnptr);
#ifdef IN_GCC
        dt_t * cdt;
        cdt = NULL;
        if (tb->ty == Tarray)
        {
            dtcontainer(& cdt, type, d);
            d = cdt;
        }
#endif
        break;
    }

    default:
        assert(0);
    }
    return d;
}
Example #6
0
dt_t *StructInitializer::toDt()
{
    Array dts;
    dt_t *dt;
    dt_t *d;
    dt_t **pdtend;
    unsigned offset;

    //printf("StructInitializer::toDt('%s')\n", toChars());
    dts.setDim(ad->fields.dim);
    dts.zero();

    for (size_t i = 0; i < vars.dim; i++)
    {
        VarDeclaration *v = (VarDeclaration *)vars.data[i];
        Initializer *val = (Initializer *)value.data[i];

        //printf("vars[%d] = %s\n", i, v->toChars());

        for (size_t j = 0; 1; j++)
        {
            assert(j < dts.dim);
            //printf(" adfield[%d] = %s\n", j, ((VarDeclaration *)ad->fields.data[j])->toChars());
            if ((VarDeclaration *)ad->fields.data[j] == v)
            {
                if (dts.data[j])
                    error(loc, "field %s of %s already initialized", v->toChars(), ad->toChars());
                dts.data[j] = (void *)val->toDt();
                break;
            }
        }
    }

    dt = NULL;
    pdtend = &dt;
    offset = 0;
    for (size_t j = 0; j < dts.dim; j++)
    {
        VarDeclaration *v = (VarDeclaration *)ad->fields.data[j];

        d = (dt_t *)dts.data[j];
        if (!d)
        {   // An instance specific initializer was not provided.
            // Look to see if there's a default initializer from the
            // struct definition
            if (v->init)
            {
                d = v->init->toDt();
            }
            else if (v->offset >= offset)
            {
                unsigned k;
                unsigned offset2 = v->offset + v->type->size();
                // Make sure this field does not overlap any explicitly
                // initialized field.
                for (k = j + 1; 1; k++)
                {
                    if (k == dts.dim)           // didn't find any overlap
                    {
                        v->type->toDt(&d);
                        break;
                    }
                    VarDeclaration *v2 = (VarDeclaration *)ad->fields.data[k];

                    if (v2->offset < offset2 && dts.data[k])
                        break;                  // overlap
                }
            }
        }
        if (d)
        {
            if (v->offset < offset)
                error(loc, "duplicate union initialization for %s", v->toChars());
            else
            {   size_t sz = dt_size(d);
                size_t vsz = v->type->size();
                size_t voffset = v->offset;

                if (sz > vsz)
                {   assert(v->type->ty == Tsarray && vsz == 0);
                    error(loc, "zero length array %s has non-zero length initializer", v->toChars());
                }

                unsigned dim = 1;
                for (Type *vt = v->type->toBasetype();
                        vt->ty == Tsarray;
                        vt = vt->next->toBasetype())
                {   TypeSArray *tsa = (TypeSArray *)vt;
                    dim *= tsa->dim->toInteger();
                }
                //printf("sz = %d, dim = %d, vsz = %d\n", sz, dim, vsz);
                assert(sz == vsz || sz * dim <= vsz);

                for (size_t i = 0; i < dim; i++)
                {
                    if (offset < voffset)
                        pdtend = dtnzeros(pdtend, voffset - offset);
                    if (!d)
                    {
                        if (v->init)
                            d = v->init->toDt();
                        else
                            v->type->toDt(&d);
                    }
                    pdtend = dtcat(pdtend, d);
                    d = NULL;
                    offset = voffset + sz;
                    voffset += vsz / dim;
                    if (sz == vsz)
                        break;
                }
            }
        }
    }
    if (offset < ad->structsize)
        dtnzeros(pdtend, ad->structsize - offset);

#ifdef IN_GCC
    dt_t * cdt = NULL;
    dtcontainer(&cdt, ad->type, dt);
    dt = cdt;
#endif
    return dt;
}
Example #7
0
void ScorePageSimple::analyzeSystems(void) {
   staffsystem.setSize(0);
   int i;
   maxStaffNumber = -1;
   staffCount     = -1;
   systemCount    = -1;
   
   Array<int> stavesfound;
   stavesfound.setSize(1024);
   stavesfound.zero();
   int currentstaff;

   for (i=0; i<data.getSize(); i++) {
      currentstaff = (int)(data[i].getPValue(2));
      if (stavesfound[currentstaff] == 0) {
         if (maxStaffNumber < currentstaff) {
            maxStaffNumber = currentstaff;
         }
         stavesfound[currentstaff] = 1;
      }
   }

   // count the number of staves which actually exist:
   staffCount = 0;
   for (i=1; i<=maxStaffNumber; i++) {
      if (stavesfound[i] != 0) {
         staffCount++;
      }
   }

   // now identify the system groupings
   Array<int> measurelength;
   measurelength.setSize(maxStaffNumber+1);
   measurelength.zero();
   for (i=1; i<data.getSize(); i++) {
      if (data[i].isBarlineItem()) {
         if (measurelength[(int)data[i].getPValue(2)] < 
               (int)data[i].getPValue(4)) {
            measurelength[(int)data[i].getPValue(2)] = 
                  (int)data[i].getPValue(4);
         }
      }
   }   

   staffsystem.setSize(maxStaffNumber+1);
   staffsystem.zero();
   track.setSize(maxStaffNumber+1);
   systemCount = 0;
   int currentStaff = 1;
   while (currentStaff <= maxStaffNumber) {
      systemCount++;
      if (measurelength[currentStaff] <= 1) {
         staffsystem[currentStaff] = systemCount;
         track[currentStaff] = 1;
         currentStaff++;
         continue;
      }
      while (currentStaff <= maxStaffNumber && measurelength[currentStaff]>1) {
         if (measurelength[currentStaff] == 0 ||
               measurelength[currentStaff] == 1) {
            track[currentStaff] = 1;
            staffsystem[currentStaff] = systemCount;
         } else {
            for (i=0; i<measurelength[currentStaff]; i++) {
               track[currentStaff+i] = i+1;
               staffsystem[currentStaff+i] = systemCount;
            }
         }
         currentStaff += measurelength[currentStaff];
      }
   }

   systemAnalysisQ = 1;
 

   // store information about the start and lenght of staves on the page.
   if (!sortQ) {
      sortByStaff();
   }
   staffStart.setAll(-1);
   staffSize.setAll(0);
   int oldStaffIndex;
   int staffIndex;
   for (i=0; i<getSize(); i++) {
      staffIndex = (int)data[i].getPValue(2);
      if (staffStart[staffIndex] == -1) {
         // new staff starts here
         staffStart[staffIndex] = i;
         if (i>0) {
            // store the length of the previous staff
            oldStaffIndex = (int)data[i-1].getPValue(2);
            staffSize[oldStaffIndex] = i-1 - staffStart[oldStaffIndex] + 1;
         }
      }
   }
   // add the last staff size information
   staffIndex = (int)data.last().getPValue(2);
   staffSize[staffIndex] = data.getSize() - staffStart[staffIndex];

   buildSystemIndexDatabase();
}
Example #8
0
int HumdrumFile::measureChordRoot2(Array<double>& scores, 
      Array<double>& parameters, NoteListArray& notelist) {

   int vx[40] = {0, 7, 7, 1000, 4, 4, 4, 4, 4, 1000, 8, 1, 1, 8, 8, 5, 5,
		5, 5, 5, 1000, 9, 2, 2, 2, 9, 1000, 6, 6, 6, 6, 6, 1000, 3,
		3, 3, 3, 10, 7, 7};
   int vy[40] = {0, -2, -4, 1000, 4, 2, 0, -2, -4, 1000, 3, 1, 1, -3, -5, 5,
		3, 1, -1, -3, 1000, 4, 2, 0, -2, -4, 1000, 4, 2, 0, -2, -4,
		1000, 3, 1, -1, -3, -5, 4, 2};

   double& alpha   = parameters[0];
   double& delta   = parameters[1];
   double& lambda  = parameters[2];
   scores.setSize(40);
   scores.zero();

   int i, j;
   int p;
   int count = notelist.getSize();
   double asum, bsum;
   double I;
   int max = 0;

   double offset = 0.0;
   double testv;
   for (i=0; i<notelist.getSize(); i++) {
      testv = -log(notelist[i].getDur())/log(2.0);
      if (testv > offset) {
         offset = testv;
      }
      testv = -log(notelist[i].getLevel())/log(2.0);
      if (testv > offset) {
         offset = testv;
      }
   }
   offset = offset * 2;

// cout << "Notelist size is: " << notelist.getSize() << endl;
// cout << "Scores size is: " << scores.getSize() << endl;
   for (i=0; i<40; i++) {
      asum = bsum = 0.0;
      for (j=0; j<count; j++) {
         p = (notelist[j].getPitch() - 2 - i + 40) % 40;
         I = sqrt(alpha * alpha * vx[p] * vx[p] + vy[p] * vy[p]);
         asum += I * delta * (offset + log(notelist[j].getDur())/log(2.0));
         bsum += I * lambda * (offset + log(notelist[j].getLevel())/log(2.0));
      }
      scores[i] = (asum + bsum)/count;
      if (scores[i] < scores[max]) {
         max = i;
      }
   }

   if (scores[max] == 0.0) {
      return -1;
   } else {
      return max;
   }

   return 0;
}
Example #9
0
int HumdrumFile::measureChordRoot1(Array<double>& scores, 
      Array<double>& parameters, NoteListArray& notelist) {

   int vx[40] = {0, 7, 7, 1000, 4, 4, 4, 4, 4, 1000, 8, 1, 1, 8, 8, 5, 5,
		5, 5, 5, 1000, 9, 2, 2, 2, 9, 1000, 6, 6, 6, 6, 6, 1000, 3,
		3, 3, 3, 10, 7, 7};
   int vy[40] = {0, -2, -4, 1000, 4, 2, 0, -2, -4, 1000, 3, 1, 1, -3, -5, 5,
		3, 1, -1, -3, 1000, 4, 2, 0, -2, -4, 1000, 4, 2, 0, -2, -4,
		1000, 3, 1, -1, -3, -5, 4, 2};

   double& alpha  = parameters[0];
   double& delta  = parameters[1];
   double& lambda = parameters[2];
   scores.setSize(40);
   scores.zero();

   int i, j;
   int p;
   int count = notelist.getSize();
   double asum, bsum;
   double I;
   int max = 0;

// cout << "Notelist size is: " << notelist.getSize() << endl;
// cout << "Scores size is: " << scores.getSize() << endl;

   for (i=0; i<40; i++) {
      asum = bsum = 0.0;
      for (j=0; j<count; j++) {
         p = (notelist[j].getPitch() - i - 2 + 40) % 40;
         I = sqrt(alpha * alpha * vx[p] * vx[p] + vy[p] * vy[p]);
         asum += I * (delta + log(notelist[j].getDur())/log(2.0));
         bsum += I * (lambda + log(notelist[j].getLevel())/log(2.0));
      }
      scores[i] = sqrt(asum * asum + bsum * bsum)/count;
      if (scores[i] < scores[max]) {
         max = i;
      }
   }

   // count the number of major and minor third pitch classes
   // above the identified tonic.  If there are more M3, then 
   // decide that the key is major, otherwise it is minor.
   double M3count = 0.0;
   double m3count = 0.0;
   int majorthird = (max + 6) % 40;
   int minorthird = (max + 5) % 40;
   for (i=0; i<count; i++) {
      if (((notelist[i].getPitch() - max - 2 + 80) % 40) == majorthird) {
         M3count += notelist[i].getDur();
      } else if (((notelist[i].getPitch() - max - 2 + 80) % 40) == minorthird) {
         m3count += notelist[i].getDur();
      }
   }

   // added for distinguishing between major and minor:
   if (m3count > M3count) {
      // indicate minor key by putting up the tonic an octave.
      max = max + 40;
   }

   if (scores[max % 40] == 0.0) {
      return -1;
   } else {
      return max;
   }
}
Example #10
0
void processNote(MidiEvent message, int seqLength, int direction) {
   static Array<char>         notes;
   static Array<char>         velocities;
   static Array<int>          durations;
   static Array<int>          iois;
   static Array<int>          ontimes;
   static CircularBuffer<int> attacktimes;
   static int                 init = 0;
   static TumbleParameters    temparam;
   char vel;

   if (!init) {
      attacktimes.setSize(256);
      attacktimes.reset();
      notes.setSize(0);
      velocities.setSize(0);
      durations.setSize(0);
      iois.setSize(0);
      ontimes.setSize(128);
      ontimes.zero();
      init = 1;
   }

   char note;
   int deltatime;
   int ioi0;
   int ioix;
   if (message.isNoteOn()) {
      attacktimes.insert(message.tick);

      // check to see if the ioi is in the correct range
      if (notes.getSize() == 0) {
         // no notes yet, so don't know the first ioi
      } else {
         deltatime = attacktimes[0] - attacktimes[1];
         iois.append(deltatime);
      }
      if (iois.getSize() > 1) {
         ioi0 = iois[0];
         ioix = iois[iois.getSize()-1];
         if ((ioix < ioi0 * tolerance) || (ioix > ioi0 / tolerance)) {
            goto resettrigger;
         }
      }

      // at this point the note can be added to the sequence
      if (notes.getSize() + 1 >= seqLength) {
         // time to trigger an algorithm
         if (durations.getSize() < notes.getSize()) {
            // if the last note has not yet been turned off, approximate dur.
            deltatime = iois[iois.getSize()-1];
            durations.append(deltatime);
         }

         int i;
         for (i=0; i<seqLength; i++) {
            temparam.v[i] = velocities[i];
            temparam.i[i] = iois[i];
            temparam.d[i] = durations[i];
            temparam.n[i] = notes[i] - notes[0];
         }
         temparam.n[0]    = message.getP1() - notes[0];
         temparam.current = message.getP1();
         temparam.pos     = 1;
         temparam.max     = seqLength;
         temparam.active  = 1;
         
         startAlgorithm(temparam);
         goto resettrigger;
      } else {
         // add the note info to the algorithm pile
         note = message.getP1();
         notes.append(note);
         vel = message.getP2();
         velocities.append(vel);
         attacktimes[message.getP1()] = message.tick;
      }
   } else if (message.isNoteOff()) {
      if (notes.getSize() > 0) {
         if (notes[notes.getSize()-1] == message.getP1()) {
         deltatime = message.tick - ontimes[message.getP1()];
         durations.append(deltatime);
      } else {
         cout << "A funny error ocurred" << endl;
      }
   }

   return;

resettrigger:
   attacktimes.setSize(0);
   notes.setSize(0);
   velocities.setSize(0);
   durations.setSize(0);
   iois.setSize(0);

   if (message.isNoteOn()) {
      note = message.getP1();
      notes.append(note);
      ontimes[message.getP1()] = message.tick;
      vel = message.getP2();
      velocities.append(vel);
   }
}



//////////////////////////////
//
// startAlgorithm -- start playing the tumble algorithm.  Inserts a
//     FunctionEvent into the eventBuffer which plays the tumble
//     algorithm sequence.  The algorithm will die after the notes
//     fall off of the 88-note keyboard.
//

}
Example #11
0
/**
 * get an array of size_t values that indicate possible pointer words in memory 
 *  if interpreted as the type given as argument
 * the first array element is the size of the type for independent interpretation
 *  of the array
 * following elements bits represent one word (4/8 bytes depending on the target 
 *  architecture). If set the corresponding memory might contain a pointer/reference.
 *
 *  [T.sizeof, pointerbit0-31/63, pointerbit32/64-63/128, ...]
 */
Expression *pointerBitmap(TraitsExp *e)
{
    int result = 0;
    if (!e->args || e->args->dim != 1)
    {
        error(e->loc, "a single type expected for trait pointerBitmap");
        return new ErrorExp();
    }
    Type *t = getType((*e->args)[0]);
    if (!t)
    {
        error(e->loc, "%s is not a type", (*e->args)[0]->toChars());
        return new ErrorExp();
    }
    d_uns64 sz = t->size(e->loc);
    if (t->ty == Tclass && !((TypeClass*)t)->sym->isInterfaceDeclaration())
        sz = ((TypeClass*)t)->sym->AggregateDeclaration::size(e->loc);

    d_uns64 sz_size_t = Type::tsize_t->size(e->loc);
    d_uns64 bitsPerWord = sz_size_t * 8;
    d_uns64 cntptr = (sz + sz_size_t - 1) / sz_size_t;
    d_uns64 cntdata = (cntptr + bitsPerWord - 1) / bitsPerWord;
    Array<d_uns64> data;
    data.setDim((size_t)cntdata);
    data.zero();

    class PointerBitmapVisitor : public Visitor
    {
    public:
        PointerBitmapVisitor(Array<d_uns64>* _data, d_uns64 _sz_size_t)
            : data(_data), offset(0), sz_size_t(_sz_size_t) 
        {}
        
        void setpointer(d_uns64 off)
        {
            d_uns64 ptroff = off / sz_size_t;
            (*data)[(size_t)(ptroff / (8 * sz_size_t))] |= 1LL << (ptroff % (8 * sz_size_t));
        }
        virtual void visit(Type *t) 
        {
            Type *tb = t->toBasetype();
            if (tb != t)
                tb->accept(this);
        }
        virtual void visit(TypeError *t) { visit((Type *)t); }
        virtual void visit(TypeNext *t) { assert(0); }
        virtual void visit(TypeBasic *t)
        {
            if (t->ty == Tvoid)
                setpointer(offset);
        }
        virtual void visit(TypeVector *t) { }
        virtual void visit(TypeArray *t) { assert(0); }
        virtual void visit(TypeSArray *t)
        {
            d_uns64 arrayoff = offset;
            d_uns64 nextsize = t->next->size();
            d_uns64 dim = t->dim->toInteger();
            for (d_uns64 i = 0; i < dim; i++)
            {
                offset = arrayoff + i * nextsize;
                t->next->accept(this);
            }
            offset = arrayoff;
        }
        virtual void visit(TypeDArray *t) { setpointer(offset + sz_size_t); } // dynamic array is {length,ptr}
        virtual void visit(TypeAArray *t) { setpointer(offset); }
        virtual void visit(TypePointer *t) 
        {
            if (t->nextOf()->ty != Tfunction) // don't mark function pointers
                setpointer(offset);
        }
        virtual void visit(TypeReference *t) { setpointer(offset); }
        virtual void visit(TypeClass *t) { setpointer(offset); }
        virtual void visit(TypeFunction *t) { }
        virtual void visit(TypeDelegate *t) { setpointer(offset); } // delegate is {context, function}
        virtual void visit(TypeQualified *t) { assert(0); } // assume resolved
        virtual void visit(TypeIdentifier *t) { assert(0); }
        virtual void visit(TypeInstance *t) { assert(0); }
        virtual void visit(TypeTypeof *t) { assert(0); }
        virtual void visit(TypeReturn *t) { assert(0); }
        virtual void visit(TypeEnum *t) { visit((Type *)t); }
        virtual void visit(TypeTuple *t) { visit((Type *)t); }
        virtual void visit(TypeSlice *t) { assert(0); }
        virtual void visit(TypeNull *t) { assert(0); }

        virtual void visit(TypeStruct *t)
        {
            d_uns64 structoff = offset;
            for (size_t i = 0; i < t->sym->fields.dim; i++)
            {
                VarDeclaration *v = t->sym->fields[i];
                offset = structoff + v->offset;
                if (v->type->ty == Tclass)
                    setpointer(offset);
                else
                    v->type->accept(this);
            }
            offset = structoff;
        }

        // a "toplevel" class is treated as an instance, while TypeClass fields are treated as references
        void visitClass(TypeClass* t)
        {
            d_uns64 classoff = offset;

            // skip vtable-ptr and monitor
            if (t->sym->baseClass)
                visitClass((TypeClass*)t->sym->baseClass->type);

            for (size_t i = 0; i < t->sym->fields.dim; i++)
            {
                VarDeclaration *v = t->sym->fields[i];
                offset = classoff + v->offset;
                v->type->accept(this);
            }
            offset = classoff;
        }

        Array<d_uns64>* data;
        d_uns64 offset;
        d_uns64 sz_size_t;
    };

    PointerBitmapVisitor pbv(&data, sz_size_t);
    if (t->ty == Tclass)
        pbv.visitClass((TypeClass*)t);
    else
        t->accept(&pbv);

    Expressions* exps = new Expressions;
    exps->push(new IntegerExp(e->loc, sz, Type::tsize_t));
    for (d_uns64 i = 0; i < cntdata; i++)
        exps->push(new IntegerExp(e->loc, data[(size_t)i], Type::tsize_t));

    ArrayLiteralExp* ale = new ArrayLiteralExp(e->loc, exps);
    ale->type = Type::tsize_t->sarrayOf(cntdata + 1);
    return ale;
}
Example #12
0
void SubImage::init (void) {

    tmpFT.zero();

    copy(img);                    // copy current cut-out to (double) working copy.

    stats.getStats( img.get(), imgSize*imgSize, ST_VALUES );

    double avg = stats.mean;
    size_t nEl = img.nElements();
    double* imgPtr = img.get();
    const double* winPtr = window.get();
    if( object.fittedPlane.nElements() == nEl ) {
        const float* planePtr = object.fittedPlane.get();
        for( size_t i=0; i<nEl; ++i) {
            // Note: mean(plane) = 0, so subtracting it will not affect the mean value.
            imgPtr[i] = (imgPtr[i]-avg-planePtr[i])*winPtr[i]+avg;
        }
    } else {
        transform(imgPtr, imgPtr+nEl, window.get(), imgPtr,
        [avg](const double& a, const double& b) {
            return (a-avg)*b+avg;
        }
                 );
    }
    stats.getStats( img.get(), imgSize*imgSize, ST_VALUES|ST_RMS );     // TODO test if this is necessary or if the stats for the larger area is sufficient
    string str = "Initializing image " + to_string(object.ID) + ":" + to_string(channel.ID) + ":" + to_string(index)
                 + "   mean=" + to_string (stats.mean) + " stddev=" + to_string (stats.stddev);

    transpose(img.get(),imgSize,imgSize);                                                       // to match MvN

    size_t noiseSize = noiseWindow.dimSize(0);
    if (imgSize == noiseSize) {
        img.copy(tmpImg);
        transform(tmpImg.get(), tmpImg.get()+tmpImg.nElements(), noiseWindow.get(), tmpImg.get(),
        [&](const double& a, const double& b) {
            return (a-stats.mean)*b;
        }
                 );
        imgFT.reset(tmpImg.get(), imgSize, imgSize, FT_FULLCOMPLEX);
        stats.noise = imgFT.noise(-1,-1);
    } else {
        size_t offset = (imgSize-noiseSize) / 2;
        Array<double> tmp(img, offset, offset+noiseSize-1, offset ,offset+noiseSize-1);
        tmp.trim();
        transform(tmp.get(), tmp.get()+tmp.nElements(), noiseWindow.get(), tmp.get(),
        [&](const double& a, const double& b) {
            return (a-stats.mean)*b;
        }
                 );
        imgFT.reset(tmp.get(), imgSize, imgSize, FT_FULLCOMPLEX);
        stats.noise = imgFT.noise(-1,-1);
    }

    if (imgSize == otfSize) {                                                                   // imgSize = 2*pupilSize
        imgFT.reset(img.get(), imgSize, imgSize, FT_FULLCOMPLEX); //|FT_NORMALIZE );                 // full-complex for now, perhaps half-complex later for performance
    } else {                                                                                    // imgSize > 2*pupilSize should never happen (cf. calculatePupilSize)
        int offset = (otfSize - imgSize) / 2;
        Array<double> tmp (otfSize, otfSize);
        tmp.zero();
        double* imgPtr = img.get();
        double* tmpPtr = tmp.get();
        for (int i = 0; i < imgSize; ++i) {
            memcpy (tmpPtr + offset * (otfSize + 1) + i * otfSize, imgPtr + i * imgSize, imgSize * sizeof (double));
        }
        imgFT.reset (tmp.get(), otfSize, otfSize, FT_FULLCOMPLEX); //|FT_NORMALIZE );               // full-complex for now, perhaps half-complex later for performance
    }

    FourierTransform::reorder(imgFT);                                                          // keep FT in centered form
    stats.noise *= channel.noiseFudge;
    double rg = stats.noise/stats.stddev;
    str += " noise=" + to_string (stats.noise) + " rg=" + to_string(rg);
    object.addRegGamma( rg );
    object.addToFT( imgFT );

    LOG_DEBUG << str << "  initial shift=" << (string)offsetShift << ende;

}