void RenderSVGRoot::layout()
{
    ASSERT(needsLayout());

    // Arbitrary affine transforms are incompatible with LayoutState.
    view()->disableLayoutState();

    LayoutRepainter repainter(*this, checkForRepaintDuringLayout() && selfNeedsLayout());

    int oldWidth = width();
    calcWidth();

    int oldHeight = height();
    calcHeight();

    SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
    setWidth(static_cast<int>(width() * svg->currentScale()));
    setHeight(static_cast<int>(height() * svg->currentScale()));
    calcViewport();

    // RenderSVGRoot needs to take special care to propagate window size changes to the children,
    // if the outermost <svg> is using relative x/y/width/height values. Hence the additonal parameters.
    layoutChildren(this, selfNeedsLayout() || (svg->hasRelativeValues() && (width() != oldWidth || height() != oldHeight)));
    repainter.repaintAfterLayout();

    view()->enableLayoutState();
    setNeedsLayout(false);
}
示例#2
0
void RenderSVGImage::layout()
{
    ASSERT(needsLayout());

    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
    SVGImageElement* image = static_cast<SVGImageElement*>(node());

    if (m_needsTransformUpdate) {
        m_localTransform = image->animatedLocalTransform();
        m_needsTransformUpdate = false;
    }

    // minimum height
    setHeight(errorOccurred() ? intrinsicSize().height() : 0);

    calcWidth();
    calcHeight();

    m_localBounds = FloatRect(image->x().value(image), image->y().value(image), image->width().value(image), image->height().value(image));
    m_cachedLocalRepaintRect = FloatRect();

    repainter.repaintAfterLayout();
    
    setNeedsLayout(false);
}
示例#3
0
void CoreData::recalcAll(const double first, const double last, const int size)
{  
  calcAmplitude(first, last);
  calcClassesNumber(size);
  calcWidth(size);
  return;
}
示例#4
0
void fp_AnnotationRun::recalcValue(void)
{
    _recalcWidth();
    if(!displayAnnotations())
    {
        m_iRealWidth = calcWidth();
    }
}
示例#5
0
CoreData::CoreData(const double first, const double last, const int size, QObject* parent): QObject(parent)
  , m_amplitude((last-first))
{
  calcAmplitude(first,last);
  calcClassesNumber(size);
  calcWidth(size);
  return;
}
示例#6
0
void RenderIndicator::layout()
{
    ASSERT(needsLayout());

    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
    calcWidth();
    calcHeight();
    layoutParts();
    repainter.repaintAfterLayout();
    setNeedsLayout(false);
}
示例#7
0
void RenderSlider::layout()
{
    ASSERT(needsLayout());

    RenderBox* thumb = m_thumb ? toRenderBox(m_thumb->renderer()) : 0;

    IntSize baseSize(borderAndPaddingWidth(), borderAndPaddingHeight());

    if (thumb) {
        // Allow the theme to set the size of the thumb.
        if (thumb->style()->hasAppearance()) {
            // FIXME: This should pass the style, not the renderer, to the theme.
            theme()->adjustSliderThumbSize(thumb);
        }

        baseSize.expand(thumb->style()->width().calcMinValue(0), thumb->style()->height().calcMinValue(0));
    }

    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());

    IntSize oldSize = size();

    setSize(baseSize);
    calcWidth();
    calcHeight();

    if (thumb) {
        if (oldSize != size())
            thumb->setChildNeedsLayout(true, false);

        LayoutStateMaintainer statePusher(view(), this, size());

        IntRect oldThumbRect = thumb->frameRect();

        thumb->layoutIfNeeded();

        IntRect rect = thumbRect();
        thumb->setFrameRect(rect);
        if (thumb->checkForRepaintDuringLayout())
            thumb->repaintDuringLayoutIfMoved(oldThumbRect);

        statePusher.pop();
        addOverflowFromChild(thumb);
    }

    repainter.repaintAfterLayout();    

    setNeedsLayout(false);
}
void RenderReplaced::layout()
{
    ASSERT(needsLayout());

    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());

    setHeight(minimumReplacedHeight());

    calcWidth();
    calcHeight();
    adjustOverflowForBoxShadowAndReflect();

    repainter.repaintAfterLayout();

    setNeedsLayout(false);
}
示例#9
0
void RenderReplaced::layout()
{
    ASSERT(needsLayout());
    
    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
    
    setHeight(minimumReplacedHeight());

    calcWidth();
    calcHeight();

    m_overflow.clear();
    addShadowOverflow();
    
    repainter.repaintAfterLayout();    

    setNeedsLayout(false);
}
示例#10
0
bool fp_AnnotationRun::_recalcWidth(void)
{
    if(!displayAnnotations())
    {
        if(getWidth() == 0)
	    return false;
	clearScreen();
	markAsDirty();
	if(getLine())
	{
	    getLine()->setNeedsRedraw();
	}
	if(getBlock())
	{
	    getBlock()->setNeedsRedraw();
	}
	_setWidth(0);
	return true;
    }
    if(!m_bIsStart)
    {
	_setWidth(0);
	return false;
    }
    UT_sint32 iNewWidth = calcWidth();
    m_iRealWidth = iNewWidth;

    if (iNewWidth != getWidth())
    {
	clearScreen();
	markAsDirty();
	if(getLine())
	  {
	    getLine()->setNeedsRedraw();
	  }
	if(getBlock())
	  {
	    getBlock()->setNeedsRedraw();
	  }
	_setWidth(iNewWidth);
	return true;
    }
    return false;
}
示例#11
0
void RenderSVGContainer::layout()
{
    ASSERT(needsLayout());

    calcViewport();

    // Arbitrary affine transforms are incompatible with LayoutState.
    view()->disableLayoutState();

    IntRect oldBounds;
    IntRect oldOutlineBox;
    bool checkForRepaint = checkForRepaintDuringLayout();
    if (selfNeedsLayout() && checkForRepaint) {
        oldBounds = m_absoluteBounds;
        oldOutlineBox = absoluteOutlineBox();
    }

    RenderObject* child = firstChild();
    while (child) {
        if (!child->isRenderPath() || static_cast<RenderPath*>(child)->hasRelativeValues())
            child->setNeedsLayout(true);

        child->layoutIfNeeded();
        ASSERT(!child->needsLayout());
        child = child->nextSibling();
    }

    calcWidth();
    calcHeight();

    m_absoluteBounds = absoluteClippedOverflowRect();
    if (!parent()->isSVGContainer()) {
        SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
        m_width = static_cast<int>(static_cast<float>(m_width) * svg->currentScale());
        m_height = static_cast<int>(static_cast<float>(m_height) * svg->currentScale());
    }

    if (selfNeedsLayout() && checkForRepaint)
        repaintAfterLayoutIfNeeded(oldBounds, oldOutlineBox);

    view()->enableLayoutState();
    setNeedsLayout(false);
}
示例#12
0
void RenderReplaced::layout()
{
    ASSERT(needsLayout());

    IntRect oldBounds;
    IntRect oldOutlineBox;
    bool checkForRepaint = checkForRepaintDuringLayout();
    if (checkForRepaint) {
        oldBounds = absoluteClippedOverflowRect();
        oldOutlineBox = absoluteOutlineBox();
    }

    m_height = minimumReplacedHeight();

    calcWidth();
    calcHeight();
    adjustOverflowForBoxShadow();

    if (checkForRepaint)
        repaintAfterLayoutIfNeeded(oldBounds, oldOutlineBox);

    setNeedsLayout(false);
}
示例#13
0
void FixedTableLayout::layout()
{
    LayoutUnit tableLogicalWidth = m_table->logicalWidth() - m_table->bordersPaddingAndSpacingInRowDirection();
    int nEffCols = m_table->numEffCols();
    Vector<int> calcWidth(nEffCols, 0);

    int numAuto = 0;
    LayoutUnit autoSpan = 0;
    LayoutUnit totalFixedWidth = 0;
    LayoutUnit totalPercentWidth = 0;
    float totalPercent = 0;

    // Compute requirements and try to satisfy fixed and percent widths.
    // Percentages are of the table's width, so for example
    // for a table width of 100px with columns (40px, 10%), the 10% compute
    // to 10px here, and will scale up to 20px in the final (80px, 20px).
    for (int i = 0; i < nEffCols; i++) {
        if (m_width[i].isFixed()) {
            calcWidth[i] = m_width[i].value();
            totalFixedWidth += calcWidth[i];
        } else if (m_width[i].isPercent()) {
            calcWidth[i] = m_width[i].calcValue(tableLogicalWidth);
            totalPercentWidth += calcWidth[i];
            totalPercent += m_width[i].percent();
        } else if (m_width[i].isAuto()) {
            numAuto++;
            autoSpan += m_table->spanOfEffCol(i);
        }
    }

    LayoutUnit hspacing = m_table->hBorderSpacing();
    LayoutUnit totalWidth = totalFixedWidth + totalPercentWidth;
    if (!numAuto || totalWidth > tableLogicalWidth) {
        // If there are no auto columns, or if the total is too wide, take
        // what we have and scale it to fit as necessary.
        if (totalWidth != tableLogicalWidth) {
            // Fixed widths only scale up
            if (totalFixedWidth && totalWidth < tableLogicalWidth) {
                totalFixedWidth = 0;
                for (int i = 0; i < nEffCols; i++) {
                    if (m_width[i].isFixed()) {
                        calcWidth[i] = calcWidth[i] * tableLogicalWidth / totalWidth;
                        totalFixedWidth += calcWidth[i];
                    }
                }
            }
            if (totalPercent) {
                totalPercentWidth = 0;
                for (int i = 0; i < nEffCols; i++) {
                    if (m_width[i].isPercent()) {
                        calcWidth[i] = m_width[i].percent() * (tableLogicalWidth - totalFixedWidth) / totalPercent;
                        totalPercentWidth += calcWidth[i];
                    }
                }
            }
            totalWidth = totalFixedWidth + totalPercentWidth;
        }
    } else {
        // Divide the remaining width among the auto columns.
        LayoutUnit remainingWidth = tableLogicalWidth - totalFixedWidth - totalPercentWidth - hspacing * (autoSpan - numAuto);
        int lastAuto = 0;
        for (int i = 0; i < nEffCols; i++) {
            if (m_width[i].isAuto()) {
                LayoutUnit span = m_table->spanOfEffCol(i);
                LayoutUnit w = remainingWidth * span / autoSpan;
                calcWidth[i] = w + hspacing * (span - 1);
                remainingWidth -= w;
                if (!remainingWidth)
                    break;
                lastAuto = i;
                numAuto--;
                autoSpan -= span;
            }
        }
        // Last one gets the remainder.
        if (remainingWidth)
            calcWidth[lastAuto] += remainingWidth;
        totalWidth = tableLogicalWidth;
    }

    if (totalWidth < tableLogicalWidth) {
        // Spread extra space over columns.
        LayoutUnit remainingWidth = tableLogicalWidth - totalWidth;
        int total = nEffCols;
        while (total) {
            LayoutUnit w = remainingWidth / total;
            remainingWidth -= w;
            calcWidth[--total] += w;
        }
        if (nEffCols > 0)
            calcWidth[nEffCols - 1] += remainingWidth;
    }

    LayoutUnit pos = 0;
    for (int i = 0; i < nEffCols; i++) {
        m_table->columnPositions()[i] = pos;
        pos += calcWidth[i] + hspacing;
    }
    LayoutUnit colPositionsSize = m_table->columnPositions().size();
    if (colPositionsSize > 0)
        m_table->columnPositions()[colPositionsSize - 1] = pos;
}
示例#14
0
/*
 * initialize(image, params, tol, im_size, n)
 *
 * Initializes fitting things for fitting.
 *
 * image - pointer to the image data.
 * scmos_calibration - sCMOS calibration data, variance/gain^2 for each pixel in the image.
 * params - pointer to the initial values for the parameters for each point.
 *           1. height
 *           2. x-center
 *           3. x-sigma
 *           4. y-center
 *           5. y-sigma
 *           6. background
 *           7. z-center
 *           8. status
 *           9. error
 *               .. repeat ..
 * im_size_x - size of the image in x.
 * im_size_y - size of the image in y.
 * n - number of parameters.
 * zfit - fitting wx, wy based on z?
 */
void initialize(double *image, double *scmos_calibration, double *params, double tol, int im_size_x, int im_size_y, int n, int zfit)
{
  int i,j;

  nfit = n;
  image_size_x = im_size_x;
  image_size_y = im_size_y;
  tolerance = tol;

  x_data = (double *)malloc(sizeof(double)*image_size_x*image_size_y);
  f_data = (double *)malloc(sizeof(double)*image_size_x*image_size_y);
  bg_data = (double *)malloc(sizeof(double)*image_size_x*image_size_y);
  bg_counts = (int *)malloc(sizeof(int)*image_size_x*image_size_y);
  scmos_term = (double *)malloc(sizeof(double)*image_size_x*image_size_y);

  for(i=0;i<(image_size_x*image_size_y);i++){
    x_data[i] = image[i];
    scmos_term[i] = scmos_calibration[i];
  }

  fit = (fitData *)malloc(sizeof(fitData)*nfit);
  for(i=0;i<nfit;i++){
    fit[i].status = (int)(params[i*NRESULTSPAR+STATUS]);
    if(fit[i].status==RUNNING){
      fit[i].error = 0.0;
      fit[i].error_old = 0.0;
    }
    else {
      fit[i].error = params[i*NRESULTSPAR+IERROR];
      fit[i].error_old = fit[i].error;
    }
    
    fit[i].params[HEIGHT]     = params[i*NRESULTSPAR+HEIGHT];
    fit[i].params[XCENTER]    = params[i*NRESULTSPAR+XCENTER];
    fit[i].params[YCENTER]    = params[i*NRESULTSPAR+YCENTER];
    fit[i].params[BACKGROUND] = params[i*NRESULTSPAR+BACKGROUND];
    fit[i].params[ZCENTER]    = params[i*NRESULTSPAR+ZCENTER];

    if(zfit){
      calcWidthsFromZ(&fit[i]);
    }
    else{
      fit[i].params[XWIDTH] = 1.0/(2.0*params[i*NRESULTSPAR+XWIDTH]*params[i*NRESULTSPAR+XWIDTH]);
      fit[i].params[YWIDTH] = 1.0/(2.0*params[i*NRESULTSPAR+YWIDTH]*params[i*NRESULTSPAR+YWIDTH]);
    }

    // printf("%d %.3f %.3f %.2f %.2f\n", i, fit[i].params[XCENTER], fit[i].params[YCENTER], fit[i].params[HEIGHT], fit[i].params[BACKGROUND]);
    fit[i].xc = (int)fit[i].params[XCENTER];
    fit[i].yc = (int)fit[i].params[YCENTER];
    fit[i].wx = calcWidth(fit[i].params[XWIDTH],-10.0);
    fit[i].wy = calcWidth(fit[i].params[YWIDTH],-10.0);

    //
    // FIXME: It would probably better to pass these in.
    //        Currently "tuned" for "standard" STORM images.
    //
    fit[i].clamp[HEIGHT] = 1000.0;
    fit[i].clamp[XCENTER] = 1.0;
    fit[i].clamp[XWIDTH] = 0.3;
    fit[i].clamp[YCENTER] = 1.0;
    fit[i].clamp[YWIDTH] = 0.3;
    fit[i].clamp[BACKGROUND] = 100.0;
    fit[i].clamp[ZCENTER] = 0.1;

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

  calcFit();
  calcErr();
}
示例#15
0
/*
 * update2D()
 *
 * Update current fits given equal width in x and y.
 *
 * This procedure is also responsible for flagging peaks
 * that might be bad & that should be removed from fitting.
 */
void update2D()
{
  // Lapack
  int n = 5, nrhs = 1, lda = 5, ldb = 5, info;

  // Local
  int i,j,k,l,m,wx,wy;
  double fi,xi,xt,ext,yt,eyt,e_t,t1,t2,a1,width;
  double delta[NPEAKPAR];
  double jt[5];
  double jacobian[5];
  double hessian[25];
  fitData *cur;

  for(i=0;i<NPEAKPAR;i++){
    delta[i] = 0.0;
  }

  for(i=0;i<nfit;i++){
    cur = &fit[i];
    if(cur->status==RUNNING){
      for(j=0;j<5;j++){
	jacobian[j] = 0.0;
      }
      for(j=0;j<25;j++){
	hessian[j] = 0.0;
      }
      l = cur->offset;
      wx = cur->wx;
      wy = cur->wy;
      a1 = cur->params[HEIGHT];
      width = cur->params[XWIDTH];
      for(j=-wy;j<=wy;j++){
	yt = cur->yt[j+wy];
	eyt = cur->eyt[j+wy];
	for(k=-wx;k<=wx;k++){
	  m = j*image_size_x+k+l;
	  fi = f_data[m]+bg_data[m]/((double)bg_counts[m]);
	  xi = x_data[m];
	  xt = cur->xt[k+wx];
	  ext = cur->ext[k+wx];
	  e_t = ext*eyt;

	  jt[0] = e_t;
	  jt[1] = 2.0*a1*width*xt*e_t;
	  jt[2] = 2.0*a1*width*yt*e_t;
	  jt[3] = -a1*xt*xt*e_t-a1*yt*yt*e_t;
	  jt[4] = 1.0;
	  
	  // calculate jacobian
	  t1 = 2.0*(1.0 - xi/fi);
	  jacobian[0] += t1*jt[0];
	  jacobian[1] += t1*jt[1];
	  jacobian[2] += t1*jt[2];
	  jacobian[3] += t1*jt[3];
	  jacobian[4] += t1*jt[4];
	  
	  // calculate hessian
	  t2 = 2.0*xi/(fi*fi);

	  // calculate hessian without second derivative terms.
	  hessian[0] += t2*jt[0]*jt[0];
	  hessian[1] += t2*jt[0]*jt[1];
	  hessian[2] += t2*jt[0]*jt[2];
	  hessian[3] += t2*jt[0]*jt[3];
	  hessian[4] += t2*jt[0]*jt[4];
	  
	  // hessian[5]
	  hessian[6] += t2*jt[1]*jt[1];
	  hessian[7] += t2*jt[1]*jt[2];
	  hessian[8] += t2*jt[1]*jt[3];
	  hessian[9] += t2*jt[1]*jt[4];
	    
	  // hessian[10]
	  // hessian[11]
	  hessian[12] += t2*jt[2]*jt[2];
	  hessian[13] += t2*jt[2]*jt[3];
	  hessian[14] += t2*jt[2]*jt[4];
	  
	  // hessian[15]
	  // hessian[16]
	  // hessian[17]
	  hessian[18] += t2*jt[3]*jt[3];
	  hessian[19] += t2*jt[3]*jt[4];

	  // hessian[20]
	  // hessian[21]
	  // hessian[22]
	  // hessian[23]
	  hessian[24] += t2*jt[4]*jt[4];
	}
      }
      

      // subtract the old peak out of the foreground and background arrays.
      subtractPeak(cur);

      // Use Lapack to solve AX=B to calculate update vector
      dposv_( "Lower", &n, &nrhs, hessian, &lda, jacobian, &ldb, &info );

      if(info!=0){
	cur->status = ERROR;
	if(TESTING){
	  printf("fitting error! %d %d %d\n", i, info, ERROR);
	  printf("  %f %f %f %f %f\n", delta[HEIGHT], delta[XCENTER], delta[YCENTER], delta[XWIDTH], delta[BACKGROUND]);
	}
      }
      else{
	// update params
	delta[HEIGHT]     = jacobian[0];
	delta[XCENTER]    = jacobian[1];
	delta[YCENTER]    = jacobian[2];
	delta[XWIDTH]     = jacobian[3];
	delta[YWIDTH]     = jacobian[3];
	delta[BACKGROUND] = jacobian[4];

	fitDataUpdate(cur, delta);

	// add the new peak to the foreground and background arrays.
	// recalculate peak fit area as the peak width may have changed.
	if (cur->status != ERROR){
	  cur->wx = calcWidth(cur->params[XWIDTH],cur->wx);
	  cur->wy = cur->wx;
	  addPeak(cur);
	}
      }
    }
  }
}
示例#16
0
/*
 * updateZ()
 *
 * Update current fits given x, y width determined by z parameter.
 *
 * This procedure is also responsible for flagging peaks
 * that might be bad & that should be removed from fitting.
 */
void updateZ()
{
  // Lapack
  int n = 5, nrhs = 1, lda = 5, ldb = 5, info;

  // Local
  int i,j,k,l,m,wx,wy;
  double fi,xi,xt,ext,yt,eyt,e_t,t1,t2,a1,a3,a5;
  double z0,z1,z2,zt,gx,gy;
  double delta[NPEAKPAR];
  double jt[5];
  double jacobian[5];
  double hessian[25];
  fitData *cur;

  for(i=0;i<NPEAKPAR;i++){
    delta[i] = 0.0;
  }

  for(i=0;i<nfit;i++){
    cur = &fit[i];
    if(cur->status==RUNNING){
      for(j=0;j<5;j++){
	jacobian[j] = 0.0;
      }
      for(j=0;j<25;j++){
	hessian[j] = 0.0;
      }
      l = cur->offset;
      wx = cur->wx;
      wy = cur->wy;
      a1 = cur->params[HEIGHT];
      a3 = cur->params[XWIDTH];
      a5 = cur->params[YWIDTH];

      // dwx/dz calcs
      z0 = (cur->params[ZCENTER]-wx_z_params[1])/wx_z_params[2];
      z1 = z0*z0;
      z2 = z1*z0;
      zt = 2.0*z0+3.0*wx_z_params[3]*z1+4.0*wx_z_params[4]*z2;
      gx = -2.0*zt/(wx_z_params[0]*cur->wx_term);

      // dwy/dz calcs
      z0 = (cur->params[ZCENTER]-wy_z_params[1])/wy_z_params[2];
      z1 = z0*z0;
      z2 = z1*z0;
      zt = 2.0*z0+3.0*wy_z_params[3]*z1+4.0*wy_z_params[4]*z2;
      gy = -2.0*zt/(wy_z_params[0]*cur->wy_term);
      for(j=-wy;j<=wy;j++){
	yt = cur->yt[j+wy];
	eyt = cur->eyt[j+wy];
	for(k=-wx;k<=wx;k++){
	  m = j*image_size_x+k+l;
	  fi = f_data[m]+bg_data[m]/((double)bg_counts[m]);
	  xi = x_data[m];
	  xt = cur->xt[k+wx];
	  ext = cur->ext[k+wx];
	  e_t = ext*eyt;

	  // first derivatives
	  jt[0] = e_t;
	  jt[1] = 2.0*a1*a3*xt*e_t;
	  jt[2] = 2.0*a1*a5*yt*e_t;
	  jt[3] = -a1*xt*xt*gx*e_t-a1*yt*yt*gy*e_t;
	  jt[4] = 1.0;
	  
	  // calculate jacobian
	  t1 = 2.0*(1.0 - xi/fi);
	  jacobian[0] += t1*jt[0];
	  jacobian[1] += t1*jt[1];
	  jacobian[2] += t1*jt[2];
	  jacobian[3] += t1*jt[3];
	  jacobian[4] += t1*jt[4];
	  
	  // calculate hessian
	  t2 = 2.0*xi/(fi*fi);

	  // calculate hessian without second derivative terms.
	  hessian[0] += t2*jt[0]*jt[0];
	  hessian[1] += t2*jt[0]*jt[1];
	  hessian[2] += t2*jt[0]*jt[2];
	  hessian[3] += t2*jt[0]*jt[3];
	  hessian[4] += t2*jt[0]*jt[4];
	  
	  // hessian[5]
	  hessian[6] += t2*jt[1]*jt[1];
	  hessian[7] += t2*jt[1]*jt[2];
	  hessian[8] += t2*jt[1]*jt[3];
	  hessian[9] += t2*jt[1]*jt[4];
	    
	  // hessian[10]
	  // hessian[11]
	  hessian[12] += t2*jt[2]*jt[2];
	  hessian[13] += t2*jt[2]*jt[3];
	  hessian[14] += t2*jt[2]*jt[4];
	  
	  // hessian[15]
	  // hessian[16]
	  // hessian[17]
	  hessian[18] += t2*jt[3]*jt[3];
	  hessian[19] += t2*jt[3]*jt[4];

	  // hessian[20]
	  // hessian[21]
	  // hessian[22]
	  // hessian[23]
	  hessian[24] += t2*jt[4]*jt[4];
	}
      }

      // subtract the old peak out of the foreground and background arrays.
      subtractPeak(cur);
      
      // Use Lapack to solve AX=B to calculate update vector
      dposv_( "Lower", &n, &nrhs, hessian, &lda, jacobian, &ldb, &info );

      /*
      for(j=0;j<5;j++){
	for(k=0;k<5;k++){
	  printf("%.4f ", hessian[j*5+k]);
	}
	printf("\n");
      }
      */

      if(info!=0){
	cur->status = ERROR;
	if(TESTING){
	  printf("fitting error! %d %d %d\n", i, info, ERROR);
	}
      }
      else{
	// update params
	delta[HEIGHT]     = jacobian[0];
	delta[XCENTER]    = jacobian[1];
	delta[YCENTER]    = jacobian[2];
	delta[ZCENTER]    = jacobian[3];
	delta[BACKGROUND] = jacobian[4];

	fitDataUpdate(cur, delta);

	// add the new peak to the foreground and background arrays.
	if (cur->status != ERROR){
	  // calculate new x,y width, update fit area.
	  calcWidthsFromZ(cur);
	  cur->wx = calcWidth(cur->params[XWIDTH],cur->wx);
	  cur->wy = calcWidth(cur->params[YWIDTH],cur->wy);
	  addPeak(cur);
	}
      }
    }
  }
  if(VERBOSE){
    printf("\n");
  }
}
示例#17
0
ExportDialog::ExportDialog(int w, int h, int wsel, int hsel, QString filename_, bool nosel_, QWidget *parent) :
    QDialog(parent)
{

    setCaption(tr("Export graphics"));
    dwidth = w;
    dheight = h;
    dwidthsel = wsel;
    dheightsel = hsel;
    svg = false;
    noselected = nosel_;

    filename = filename_;

    lblFilename = new QLabel(tr("Save to file (Graphics format by extension)"));
    lblResolutionX = new QLabel(tr("Width  in pixels"));
    lblResolutionY = new QLabel(tr("Height in pixels"));
    lblRatio = new QLabel(tr("Scale factor: "));
    lblFormat = new QLabel(tr("Image format:"));

    ExportButt = new QPushButton(tr("Export"));
    connect(ExportButt,SIGNAL(clicked()),this,SLOT(accept()));
    CancelButt = new QPushButton(tr("Cancel"));
    connect(CancelButt,SIGNAL(clicked()),this,SLOT(reject()));
    SaveButt = new QPushButton(tr("File"));
    connect(SaveButt,SIGNAL(clicked()),this,SLOT(setFileName()));

    editFilename = new QLineEdit(filename);
    connect(editFilename,SIGNAL(textChanged(QString)),this,SLOT(setSvg(QString)));

    editResolutionX = new QLineEdit(QString::number(dwidth));
    QIntValidator *val = new QIntValidator(0,64000,this);
    editResolutionX->setValidator(val);
    editResolutionX->setEnabled(false);
    editResolutionY = new QLineEdit(QString::number(dheight));
    editResolutionY->setValidator(val);
    editResolutionY->setEnabled(false);
    editScale = new QLineEdit(QString::number(1.0));
    QDoubleValidator *val1 = new QDoubleValidator(0,20.0,2,this);
    editScale->setValidator(val1);

    cbxImgType = new QComboBox(this);
    QStringList lst;
    lst<<tr("Colour")<<tr("Monochrome");
    cbxImgType->addItems(lst);

    cbRatio = new QCheckBox(tr("Original width to height ratio"));
    cbRatio->setChecked(true);
    connect(cbRatio,SIGNAL(toggled(bool)),this,SLOT(recalcRatio()));

    cbResolution = new QCheckBox(tr("Original size"));
    connect(cbResolution,SIGNAL(toggled(bool)),editResolutionX,SLOT(setDisabled(bool)));
    connect(cbResolution,SIGNAL(toggled(bool)),editResolutionY,SLOT(setDisabled(bool)));
    connect(cbResolution,SIGNAL(toggled(bool)),cbRatio,SLOT(setDisabled(bool)));
    connect(cbResolution,SIGNAL(toggled(bool)),editScale,SLOT(setDisabled(bool)));
    connect(cbResolution,SIGNAL(toggled(bool)),this,SLOT(restoreOriginalWtoH()));
    cbResolution->setChecked(true);

    connect(editResolutionX,SIGNAL(textEdited(QString)),this,SLOT(calcHeight()));
    connect(editResolutionY,SIGNAL(textEdited(QString)),this,SLOT(calcWidth()));
    connect(editScale,SIGNAL(textChanged(QString)),this,SLOT(recalcScale()));

    cbSelected = new QCheckBox(tr("Export selected only"));
    connect(cbSelected,SIGNAL(toggled(bool)),this,SLOT(setSelectedWH()));
    cbSelected->setChecked(false);
    if (noselected) cbSelected->setDisabled(true);

    //cbResolution->setEnabled(false);
    cbRatio->setEnabled(false);


    top = new QVBoxLayout;
    lower1 = new QHBoxLayout;
    lower2 = new QHBoxLayout;
    lower3 = new QHBoxLayout;
    lower4 = new QHBoxLayout;

    top->addWidget(lblFilename);
    lower1->addWidget(editFilename);
    lower1->addWidget(SaveButt);
    top->addLayout(lower1);
    lower4->addWidget(lblFormat);
    lower4->addWidget(cbxImgType);
    top->addLayout(lower4);
    top->addWidget(cbResolution);
    //top->addWidget(cbRatio);
    lower3->addWidget(lblRatio);
    lower3->addWidget(editScale);
    top->addLayout(lower3);
    top->addWidget(lblResolutionX);
    top->addWidget(editResolutionX);
    top->addWidget(lblResolutionY);
    top->addWidget(editResolutionY);
    top->addWidget(cbSelected);

    lower2->addWidget(ExportButt);
    lower2->addWidget(CancelButt);
    top->addLayout(lower2);
    this->setLayout(top);

    this->layout()->setSizeConstraint(QLayout::SetFixedSize);
    this->setWindowTitle(tr("Export schematic to raster or vector image"));

    this->setSvg(editFilename->text());
}
void FixedTableLayout::layout()
{
    int tableLogicalWidth = m_table->logicalWidth() - m_table->bordersPaddingAndSpacingInRowDirection();
    unsigned nEffCols = m_table->numEffCols();

    // FIXME: It is possible to be called without having properly updated our internal representation.
    // This means that our preferred logical widths were not recomputed as expected.
    if (nEffCols != m_width.size()) {
        calcWidthArray();
        // FIXME: Table layout shouldn't modify our table structure (but does due to columns and column-groups).
        nEffCols = m_table->numEffCols();
    }

    Vector<int> calcWidth(nEffCols, 0);

    unsigned numAuto = 0;
    unsigned autoSpan = 0;
    int totalFixedWidth = 0;
    int totalPercentWidth = 0;
    float totalPercent = 0;

    // Compute requirements and try to satisfy fixed and percent widths.
    // Percentages are of the table's width, so for example
    // for a table width of 100px with columns (40px, 10%), the 10% compute
    // to 10px here, and will scale up to 20px in the final (80px, 20px).
    for (unsigned i = 0; i < nEffCols; i++) {
        if (m_width[i].isFixed()) {
            calcWidth[i] = m_width[i].value();
            totalFixedWidth += calcWidth[i];
        } else if (m_width[i].isPercentNotCalculated()) {
            calcWidth[i] = valueForLength(m_width[i], tableLogicalWidth);
            totalPercentWidth += calcWidth[i];
            totalPercent += m_width[i].percent();
        } else if (m_width[i].isAuto()) {
            numAuto++;
            autoSpan += m_table->spanOfEffCol(i);
        }
    }

    int hspacing = m_table->hBorderSpacing();
    int totalWidth = totalFixedWidth + totalPercentWidth;
    if (!numAuto || totalWidth > tableLogicalWidth) {
        // If there are no auto columns, or if the total is too wide, take
        // what we have and scale it to fit as necessary.
        if (totalWidth != tableLogicalWidth) {
            // Fixed widths only scale up
            if (totalFixedWidth && totalWidth < tableLogicalWidth) {
                totalFixedWidth = 0;
                for (unsigned i = 0; i < nEffCols; i++) {
                    if (m_width[i].isFixed()) {
                        calcWidth[i] = calcWidth[i] * tableLogicalWidth / totalWidth;
                        totalFixedWidth += calcWidth[i];
                    }
                }
            }
            if (totalPercent) {
                totalPercentWidth = 0;
                for (unsigned i = 0; i < nEffCols; i++) {
                    if (m_width[i].isPercentNotCalculated()) {
                        calcWidth[i] = m_width[i].percent() * (tableLogicalWidth - totalFixedWidth) / totalPercent;
                        totalPercentWidth += calcWidth[i];
                    }
                }
            }
            totalWidth = totalFixedWidth + totalPercentWidth;
        }
    } else {
        // Divide the remaining width among the auto columns.
        ASSERT(autoSpan >= numAuto);
        int remainingWidth = tableLogicalWidth - totalFixedWidth - totalPercentWidth - hspacing * (autoSpan - numAuto);
        int lastAuto = 0;
        for (unsigned i = 0; i < nEffCols; i++) {
            if (m_width[i].isAuto()) {
                unsigned span = m_table->spanOfEffCol(i);
                int w = remainingWidth * span / autoSpan;
                calcWidth[i] = w + hspacing * (span - 1);
                remainingWidth -= w;
                if (!remainingWidth)
                    break;
                lastAuto = i;
                numAuto--;
                ASSERT(autoSpan >= span);
                autoSpan -= span;
            }
        }
        // Last one gets the remainder.
        if (remainingWidth)
            calcWidth[lastAuto] += remainingWidth;
        totalWidth = tableLogicalWidth;
    }

    if (totalWidth < tableLogicalWidth) {
        // Spread extra space over columns.
        int remainingWidth = tableLogicalWidth - totalWidth;
        int total = nEffCols;
        while (total) {
            int w = remainingWidth / total;
            remainingWidth -= w;
            calcWidth[--total] += w;
        }
        if (nEffCols > 0)
            calcWidth[nEffCols - 1] += remainingWidth;
    }
    
    int pos = 0;
    for (unsigned i = 0; i < nEffCols; i++) {
        m_table->setColumnPosition(i, pos);
        pos += calcWidth[i] + hspacing;
    }
    int colPositionsSize = m_table->columnPositions().size();
    if (colPositionsSize > 0)
        m_table->setColumnPosition(colPositionsSize - 1, pos);
}
示例#19
0
void LcsColumnReader::sync()
{
    // Get batch using column's offset within cluster
    pBatch = &pScan->pRangeBatches[colOrd];
    pValues = pScan->pLeaf + pBatch->oVal;
    pBase = pScan->pLeaf - pScan->delta[colOrd];

    filters.filteringBitmap.resize(0);

    if (batchIsCompressed()) {
        // where the bit vectors start
        const PBuffer pBit = pValues + (sizeof(uint16_t) * pBatch->nVal);
        // # bits per value
        uint nBits = calcWidth(pBatch->nVal);
        // calculate bit vector widths
        iV = bitVecWidth(nBits, width);
        bitVecPtr(pBatch->nRow, iV, width, origin, (PBuffer) pBit);

        uint totWidth;
        if (iV == 1) {
            totWidth = width[0];
        } else if (iV == 2) {
            totWidth = width[0] + width[1];
        } else {
            totWidth = 0;
        }

        // hack to do one switch statement based on both width arguments
        // The switch value is unique for any of the following combos of
        // width 1 and 2:
        //      (8,-), (8,4), (8,2), (8,1), (4,-), (4,2), (4,1), (2,-), (2,1),
        //      (1,-)
        //

        switch (totWidth) {
        // single vector
        case 16:    // width 1 = 16
            pFuncReadBitVec = readBitVec16;
            break;

        case 8: // width 1 = 8
            pFuncReadBitVec = readBitVec8;
            break;

        case 4: // width 1 = 4
            pFuncReadBitVec = readBitVec4;
            break;

        case 2: // width 1 = 2
            pFuncReadBitVec = readBitVec2;
            break;

        case 1: // width 1 = 1
            pFuncReadBitVec = readBitVec1;
            break;

        // dual vector, first vector 8

        case 12:    // width 1 = 8, width 2 = 4
            pFuncReadBitVec = readBitVec12;
            break;

        case 10:    // width 1 = 8, width 2 = 2
            pFuncReadBitVec = readBitVec10;
            break;

        case 9: // width 1 = 8, width 2 = 1
            pFuncReadBitVec = readBitVec9;
            break;

        // dual vector, first vector 4

        case 6: // width 1 = 4, width 2 = 2
            pFuncReadBitVec = readBitVec6;
            break;

        case 5: // width 1 = 4, width 2 = 1
            pFuncReadBitVec = readBitVec5;
            break;

        // dual vector, first vector is 2

        case 3: // width 1 = 2, width 2 = 1
            pFuncReadBitVec = readBitVec3;
            break;

        // no bit vector stored
        case 0:
            pFuncReadBitVec = readBitVec0;
            break;

        default:
            assert(false);
            break;
        }

        // Set function pointer to get data
        pGetCurrentValueFunc = &LcsColumnReader::getCompressedValue;

        if (filters.hasResidualFilters) {
            /*
             * initializes bitmap
             */
            buildContainsMap();
        }

    } else if (batchIsFixed()) {
        // Set function pointer to get data in fixed case
        pGetCurrentValueFunc = &LcsColumnReader::getFixedValue;
    } else {
        // Set function pointer to get data in variable case
        pGetCurrentValueFunc = &LcsColumnReader::getVariableValue;
    }
}
示例#20
0
		/**
			Retain size and translate to a new center location.
		*/
		inline void setCenter( const Vector3& newCenterLoc )
		{
			Vector3 halfSize = Vector3( calcWidth(), calcHeight(), calcDepth() ) * 0.5f ;
			m_Min = newCenterLoc - halfSize;
			m_Max = newCenterLoc + halfSize;
		}
示例#21
0
/*
 * update3D()
 *
 * Update current fits allowing all parameters to change.
 *
 * This procedure is also responsible for flagging peaks
 * that might be bad & that should be removed from fitting.
 */
void update3D()
{
  // Lapack
  int n = 6, nrhs = 1, lda = 6, ldb = 6, info;

  // Local
  int i,j,k,l,m,wx,wy;
  double fi,xi,xt,ext,yt,eyt,e_t,t1,t2,a1,a3,a5;
  double delta[NPEAKPAR];
  double jt[6];
  double jacobian[6];
  double hessian[36];
  fitData *cur;

  for(i=0;i<NPEAKPAR;i++){
    delta[i] = 0.0;
  }

  for(i=0;i<nfit;i++){
    cur = &fit[i];
    if(cur->status==RUNNING){
      for(j=0;j<6;j++){
	jacobian[j] = 0.0;
      }
      for(j=0;j<36;j++){
	hessian[j] = 0.0;
      }
      l = cur->offset;
      wx = cur->wx;
      wy = cur->wy;
      a1 = cur->params[HEIGHT];
      a3 = cur->params[XWIDTH];
      a5 = cur->params[YWIDTH];
      for(j=-wy;j<=wy;j++){
	yt = cur->yt[j+wy];
	eyt = cur->eyt[j+wy];
	for(k=-wx;k<=wx;k++){
	  m = j*image_size_x+k+l;
	  fi = f_data[m]+bg_data[m]/((double)bg_counts[m]);
	  xi = x_data[m];
	  xt = cur->xt[k+wx];
	  ext = cur->ext[k+wx];
	  e_t = ext*eyt;
	  
	  jt[0] = e_t;
	  jt[1] = 2.0*a1*a3*xt*e_t;
	  jt[2] = -a1*xt*xt*e_t;
	  jt[3] = 2.0*a1*a5*yt*e_t;
	  jt[4] = -a1*yt*yt*e_t;
	  jt[5] = 1.0;
	    	  
	  // calculate jacobian
	  t1 = 2.0*(1.0 - xi/fi);
	  jacobian[0] += t1*jt[0];
	  jacobian[1] += t1*jt[1];
	  jacobian[2] += t1*jt[2];
	  jacobian[3] += t1*jt[3];
	  jacobian[4] += t1*jt[4];
	  jacobian[5] += t1*jt[5];

	  // calculate hessian
	  t2 = 2.0*xi/(fi*fi);

	  if (0){
	    // FIXME: not complete
	    // hessian with second derivative terms.
	    hessian[0] += t2*jt[0]*jt[0];
	    hessian[1] += t2*jt[0]*jt[1]+t1*2.0*xt*a3*ext*eyt;
	    hessian[2] += t2*jt[0]*jt[2];
	    hessian[3] += t2*jt[0]*jt[3]+t1*2.0*yt*a5*ext*eyt;
	    hessian[4] += t2*jt[0]*jt[4];
	    hessian[5] += t2*jt[0]*jt[5];
	    
	    // hessian[6]
	    hessian[7]  += t2*jt[1]*jt[1]+t1*(-2.0*a1*a3*ext*eyt+4.0*a1*a3*a3*xt*xt*ext*eyt);
	    hessian[8]  += t2*jt[1]*jt[2]+t1*4.0*a1*xt*yt*a3*a3*ext*eyt;
	    hessian[9]  += t2*jt[1]*jt[3];
	    hessian[10] += t2*jt[1]*jt[4];
	    hessian[11] += t2*jt[1]*jt[5];
	    
	    // hessian[12]
	    // hessian[13]
	    hessian[14] += t2*jt[2]*jt[2]+t1*(-2.0*a1*a3*ext*eyt+4.0*a1*a3*a3*yt*yt*ext*eyt);
	    hessian[15] += t2*jt[2]*jt[3];
	    hessian[16] += t2*jt[2]*jt[4];
	    hessian[17] += t2*jt[2]*jt[5];
	    
	    // hessian[18]
	    // hessian[19]
	    // hessian[20]
	    hessian[21] += t2*jt[3]*jt[3];
	    hessian[22] += t2*jt[3]*jt[4];
	    hessian[23] += t2*jt[3]*jt[5];
	    
	    // hessian[24]
	    // hessian[25]
	    // hessian[26]
	    // hessian[27]
	    hessian[28] += t2*jt[4]*jt[4];
	    hessian[29] += t2*jt[4]*jt[5];

	    // hessian[30]
	    // hessian[31]
	    // hessian[32]
	    // hessian[33]
	    // hessian[34]
	    hessian[35] += t2*jt[5]*jt[5];
	  }
	  else {
	    // hessian without second derivative terms.
	    hessian[0] += t2*jt[0]*jt[0];
	    hessian[1] += t2*jt[0]*jt[1];
	    hessian[2] += t2*jt[0]*jt[2];
	    hessian[3] += t2*jt[0]*jt[3];
	    hessian[4] += t2*jt[0]*jt[4];
	    hessian[5] += t2*jt[0]*jt[5];
	    
	    // hessian[6]
	    hessian[7]  += t2*jt[1]*jt[1];
	    hessian[8]  += t2*jt[1]*jt[2];
	    hessian[9]  += t2*jt[1]*jt[3];
	    hessian[10] += t2*jt[1]*jt[4];
	    hessian[11] += t2*jt[1]*jt[5];
	    
	    // hessian[12]
	    // hessian[13]
	    hessian[14] += t2*jt[2]*jt[2];
	    hessian[15] += t2*jt[2]*jt[3];
	    hessian[16] += t2*jt[2]*jt[4];
	    hessian[17] += t2*jt[2]*jt[5];
	    
	    // hessian[18]
	    // hessian[19]
	    // hessian[20]
	    hessian[21] += t2*jt[3]*jt[3];
	    hessian[22] += t2*jt[3]*jt[4];
	    hessian[23] += t2*jt[3]*jt[5];
	    
	    // hessian[24]
	    // hessian[25]
	    // hessian[26]
	    // hessian[27]
	    hessian[28] += t2*jt[4]*jt[4];
	    hessian[29] += t2*jt[4]*jt[5];

	    // hessian[30]
	    // hessian[31]
	    // hessian[32]
	    // hessian[33]
	    // hessian[34]
	    hessian[35] += t2*jt[5]*jt[5];

	    // Ignore off-diagonal terms.
	    // This approach converges incredibly slowly.
	    /*
	    hessian[0]  += t2*jt[0]*jt[0];
	    hessian[7]  += t2*jt[1]*jt[1];
	    hessian[14] += t2*jt[2]*jt[2];
	    hessian[21] += t2*jt[3]*jt[3];
	    hessian[28] += t2*jt[4]*jt[4];
	    hessian[35] += t2*jt[5]*jt[5];
	    */
	  }
	}

      }
      
      /*
      printf("hessian:\n");
      for(j=0;j<6;j++){
	for(k=0;k<6;k++){
	  printf("%.4f ", hessian[j*6+k]);
	}
	printf("\n");
      }
      printf("\n");
      */
      // subtract the old peak out of the foreground and background arrays.
      subtractPeak(cur);

      // Use Lapack to solve AX=B to calculate update vector
      dposv_( "Lower", &n, &nrhs, hessian, &lda, jacobian, &ldb, &info );

      if(info!=0){
	cur->status = ERROR;
	if(TESTING){
	  printf("fitting error! %d %d %d\n", i, info, ERROR);
	}
      }

      else{
	// update params
	delta[HEIGHT]     = jacobian[0];
	delta[XCENTER]    = jacobian[1];
	delta[XWIDTH]     = jacobian[2];
	delta[YCENTER]    = jacobian[3];
	delta[YWIDTH]     = jacobian[4];
	delta[BACKGROUND] = jacobian[5];

	fitDataUpdate(cur, delta);

	// add the new peak to the foreground and background arrays.
	if (cur->status != ERROR){
	  cur->wx = calcWidth(cur->params[XWIDTH],cur->wx);
	  cur->wy = calcWidth(cur->params[YWIDTH],cur->wy);
	  addPeak(cur);
	}
      }
    }
  }
}