Beispiel #1
0
void Grid::paint(void)
{
    int i;
    int j;
    int k;

    if (mpBox == NULL)
        return;
    printf("Grid::paint entry\n");
    Vec3f minp = mpBox->getMin();
    Vec3f maxp = mpBox->getMax();

    float xBox = maxp.x() - minp.x();
    float yBox = maxp.y() - minp.y();
    float zBox = maxp.z() - minp.z();

    int xSize = getXSize();
    int ySize = getYSize();
    int zSize = getZSize();

    float xDelta = xBox / xSize;
    float yDelta = yBox / ySize;
    float zDelta = zBox / zSize;

    for (k = 0; k < zSize; k++)
    for (j = 0; j < ySize; j++)
    for (i = 0; i < xSize; i++)
    {
        printf("Obj:%d %d %d, num=%d\n", i, j, k, mObjects[offset(i, j, k)].getNumObjects());
        if (mObjects[offset(i, j, k)].getNumObjects() > 0) {
            printf("Paint:%d, %d, %d\n", i, j, k);
            Vec3f curMinPoint(minp.x() + i*xDelta,
                              minp.y() + j*yDelta,
                              minp.z() + k*zDelta );

            Vec3f curMaxPoint(curMinPoint.x() + xDelta,
                              curMinPoint.y() + yDelta,
                              curMinPoint.z() + zDelta );

            glBegin(GL_QUADS);

            //The up plane
            Vec3f normalUp;
            Vec3f::Cross3( normalUp,
                           Vec3f(0.0, curMaxPoint.y() - curMinPoint.y() , 0.0),
                           Vec3f(curMaxPoint.x() - curMinPoint.x(), 0.0, 0.0) );
            glNormal3f(normalUp.x(), normalUp.y(), normalUp.z());

            glVertex3f(curMinPoint.x(), curMinPoint.y(), curMaxPoint.z());
            glVertex3f(curMaxPoint.x(), curMinPoint.y(), curMaxPoint.z());
            glVertex3f(curMaxPoint.x(), curMaxPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMaxPoint.y(), curMaxPoint.z());

            //the down plane
            Vec3f normalDown;
            Vec3f::Cross3( normalDown,
                           Vec3f(curMaxPoint.x() - curMinPoint.x(), 0.0, 0.0),
                           Vec3f(0.0, curMaxPoint.y() - curMinPoint.y(), 0.0) );
            glNormal3f(normalDown.x(), normalDown.y(), normalDown.z());

            glVertex3f(curMinPoint.x(), curMinPoint.y(), curMinPoint.z());
            glVertex3f(curMaxPoint.x(), curMinPoint.y(), curMinPoint.z());
            glVertex3f(curMaxPoint.x(), curMaxPoint.y(), curMinPoint.z());
            glVertex3f(curMinPoint.x(), curMaxPoint.y(), curMinPoint.z());

            //the front plane
            Vec3f normalFront;
            Vec3f::Cross3( normalFront,
                           Vec3f(0.0, curMaxPoint.y() - curMinPoint.y(), 0.0),
                           Vec3f(0.0, 0.0, curMaxPoint.z() - curMinPoint.z()) );
            glNormal3f(normalFront.x(), normalFront.y(), normalFront.z());

            glVertex3f(curMinPoint.x(), curMinPoint.y(), curMinPoint.z());
            glVertex3f(curMinPoint.x(), curMinPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMaxPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMaxPoint.y(), curMinPoint.z());

            //the back plane
            Vec3f normalBack;
            Vec3f::Cross3( normalBack,
                           Vec3f(0.0, 0.0, curMaxPoint.z() - curMinPoint.z()),
                           Vec3f(0.0, curMaxPoint.y() - curMinPoint.y(), 0.0) );
            glNormal3f(normalBack.x(), normalBack.y(), normalBack.z());

            glVertex3f(curMaxPoint.x(), curMinPoint.y(), curMinPoint.z());
            glVertex3f(curMaxPoint.x(), curMinPoint.y(), curMaxPoint.z());
            glVertex3f(curMaxPoint.x(), curMaxPoint.y(), curMaxPoint.z());
            glVertex3f(curMaxPoint.x(), curMaxPoint.y(), curMinPoint.z());

            //the left plane
            Vec3f normalLeft;
            Vec3f::Cross3( normalLeft,
                           Vec3f(curMinPoint.x() - curMaxPoint.x(), 0.0, 0.0),
                           Vec3f(0.0, 0.0, curMaxPoint.z() - curMinPoint.z()) );
            glNormal3f(normalLeft.x(), normalLeft.y(), normalLeft.z());

            glVertex3f(curMaxPoint.x(), curMinPoint.y(), curMinPoint.z());
            glVertex3f(curMaxPoint.x(), curMinPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMinPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMinPoint.y(), curMinPoint.z());

            //the right plane
            Vec3f normalRight;
            Vec3f::Cross3( normalRight,
                           Vec3f(0.0, 0.0, curMaxPoint.z() - curMinPoint.z()),
                           Vec3f(curMinPoint.x() - curMaxPoint.x(), 0.0, 0.0) );
            glNormal3f(normalRight.x(), normalRight.y(), normalRight.z());

            glVertex3f(curMaxPoint.x(), curMaxPoint.y(), curMinPoint.z());
            glVertex3f(curMaxPoint.x(), curMaxPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMaxPoint.y(), curMaxPoint.z());
            glVertex3f(curMinPoint.x(), curMaxPoint.y(), curMinPoint.z());

            glEnd();
        }
    }
    printf("Grid::paint Exit\n");
}
Beispiel #2
0
/*
 * newPeaks()
 *
 * Create initial fit data structures for spline fitting from the peak array. The 
 * format of the initial values is the same as what was used for 3D-DAOSTORM.
 *
 * peaks - pointer to the initial values for the parameters for each peak.
 *           1. height
 *           2. x-center
 *           3. x-sigma
 *           4. y-center
 *           5. y-sigma
 *           6. background
 *           7. z-center
 *           8. status
 *           9. error
 *               .. repeat ..
 * n_peaks - The number of parameters (peaks).
 */
void newPeaks(double *peaks, int n_peaks, int fit_type)
{
  int i,j,n_fit_params,sx,sy,sz;
  double temp;

  if(fit_type == F2D){
    n_fit_params = 4;
  }
  else{
    n_fit_params = 5;
  }

  /* Delete old fit data structures, if they exist. */
  freePeaks();
  
  /* Reset the fit array. */
  resetFit();

  /* Allocate storage for fit data structure. */
  n_fit_data = n_peaks;
  new_fit_data = (fitData *)malloc(sizeof(fitData)*n_peaks);
  old_fit_data = (fitData *)malloc(sizeof(fitData)*n_peaks);
  sx = getXSize()/2 - 1;
  sy = getYSize()/2 - 1;
  sz = getZSize();

  /* Note the assumption here that the splines are square. */
  if((sx%2)==1){
    xoff = (double)(sx/2) - 1.0;
    yoff = (double)(sy/2) - 1.0;
  }
  else{
    xoff = (double)(sx/2) - 1.5;
    yoff = (double)(sy/2) - 1.5;
  }

  //zoff = -(double)(sz/2);
  zoff = 0.0;

  /* Initialize fit data structure. */
  for(i=0;i<n_fit_data;i++){
    new_fit_data[i].index = i;
    new_fit_data[i].n_params = n_fit_params;
    new_fit_data[i].size_x = sx;
    new_fit_data[i].size_y = sy;
    new_fit_data[i].size_z = sz;
    new_fit_data[i].status = (int)(peaks[i*NRESULTSPAR+STATUS]);
    new_fit_data[i].type = fit_type;

    new_fit_data[i].lambda = 1.0;

    mallocFitData(&(new_fit_data[i]), n_fit_params, sx*sy*(n_fit_params+1));

    for(j=0;j<n_fit_params;j++){
      new_fit_data[i].sign[j] = 0;
    }

    new_fit_data[i].clamp[CF_HEIGHT] = 100.0;
    new_fit_data[i].clamp[CF_XCENTER] = 1.0;
    new_fit_data[i].clamp[CF_YCENTER] = 1.0;
    new_fit_data[i].clamp[CF_BACKGROUND] = 20.0;
    if (fit_type == F3D){
      new_fit_data[i].clamp[CF_ZCENTER] = 2.0;
    }

    if (DEBUG){
      printf(" peaks: %.2f %.2f %.2f\n", peaks[i*NRESULTSPAR+XCENTER], peaks[i*NRESULTSPAR+YCENTER], peaks[i*NRESULTSPAR+ZCENTER]);
    }
    new_fit_data[i].params[CF_HEIGHT] = peaks[i*NRESULTSPAR+HEIGHT];
    new_fit_data[i].params[CF_XCENTER] = peaks[i*NRESULTSPAR+XCENTER] - xoff;
    new_fit_data[i].params[CF_YCENTER] = peaks[i*NRESULTSPAR+YCENTER] - yoff;
    new_fit_data[i].params[CF_BACKGROUND] = peaks[i*NRESULTSPAR+BACKGROUND];
    if (fit_type == F3D){
      new_fit_data[i].params[CF_ZCENTER] = peaks[i*NRESULTSPAR+ZCENTER] - zoff;
    }

    new_fit_data[i].xi = (int)(new_fit_data[i].params[CF_XCENTER]);
    new_fit_data[i].yi = (int)(new_fit_data[i].params[CF_YCENTER]);
    if (fit_type == F3D){
      new_fit_data[i].zi = (int)(new_fit_data[i].params[CF_ZCENTER]);
    }

    if (fit_type == F2D){
      updateFitValues2D(&(new_fit_data[i]));
    }
    else{
      updateFitValues3D(&(new_fit_data[i]));
    }

    /*
     * The derivative with respect to background term is always 1.0
     */
    for(j=0;j<(sx*sy);j++){
      new_fit_data[i].values[(CF_BACKGROUND+1)*sx*sy+j] = 1.0;
    }

    addPeak(&(new_fit_data[i]));

    mallocFitData(&(old_fit_data[i]), n_fit_params, sx*sy*(n_fit_params+1));
    copyFitData(&(new_fit_data[i]), &(old_fit_data[i]));

    if(new_fit_data[i].status == RUNNING){
      if (TESTING){
	temp = calcError(&(new_fit_data[i]), new_fit_data[i].params[CF_BACKGROUND]);
	new_fit_data[i].error = temp;
      }
      else{
	new_fit_data[i].error = 1.0e+12;
      }
      old_fit_data[i].error = 1.0e+13;
    }
    else{
      new_fit_data[i].error = peaks[i*NRESULTSPAR+IERROR];
      old_fit_data[i].error = new_fit_data[i].error;
    }
  }
}