bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) {
    addDraw(TRANSLATE);
    addScalar(dx);
    addScalar(dy);
    validate();
    return this->INHERITED::translate(dx, dy);
}
bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) {
    addDraw(SCALE);
    addScalar(sx);
    addScalar(sy);
    validate();
    return this->INHERITED::scale(sx, sy);
}
void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
                        const SkPaint* paint = NULL) {
    addDraw(DRAW_BITMAP);
    addPaintPtr(paint);
    addBitmap(bitmap);
    addScalar(left);
    addScalar(top);
    validate();
}
void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, int index,
                                              SkScalar minY, SkScalar maxY) {
    SkFlatData* flat = fPaints.writableFlatData(index);
    if (!flat->isTopBotWritten()) {
        computeFontMetricsTopBottom(paint, flat->writableTopBot());
        SkASSERT(flat->isTopBotWritten());
    }
    addScalar(flat->topBot()[0] + minY);
    addScalar(flat->topBot()[1] + maxY);
}
void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x,
                      SkScalar y, const SkPaint& paint) {
    bool fast = paint.canComputeFastBounds();

    addDraw(fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT);
    addPaint(paint);
    addText(text, byteLength);
    addScalar(x);
    addScalar(y);
    if (fast) {
        addFontMetricsTopBottom(paint, y);
    }
    validate();
}
void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint,
                                              SkScalar baselineY) {
    SkPaint::FontMetrics metrics;
    paint.getFontMetrics(&metrics);
    SkRect bounds;
    // construct a rect so we can see any adjustments from the paint.
    // we use 0,1 for left,right, just so the rect isn't empty
    bounds.set(0, metrics.fTop + baselineY,
               SK_Scalar1, metrics.fBottom + baselineY);
    (void)paint.computeFastBounds(bounds, &bounds);
    // now record the top and bottom
    addScalar(bounds.fTop);
    addScalar(bounds.fBottom);
}
void LeastSquareFilter::genericComputeLinearFunc(float *res, std::vector<float> X, std::vector<float> Y)
{
	int n = Y.size();
	res[0] = 0.0;
	res[1] = 0.0;

	if (n > 0) {
		float meanX = mean(X);
		std::vector<float> x_minus_meanx = addScalar(X, -meanX);
		std::vector<float> x_minus_meanx_square = product(x_minus_meanx, x_minus_meanx);
		float SSxx = sum(x_minus_meanx_square);

		//
		float sumY = sum(Y);
		float sumX = n * (n-1) / 2.0;
		std::vector<float> x_product_y = product(X, Y);
		float SSxy = sum(x_product_y) - sumX * sumY / n;
		//
		float b1 = 0.0;

		if (SSxx != 0.0) {
			b1 = SSxy / SSxx;
		}

		float b0 = sumY / n - b1 * sumX / n;

		res[0] = b0;
		res[1] = b1;
	}
}
void TimeAnalysisWidget::on_applyButton_clicked()
{
    bool low = _ui->lowRadioButton->isChecked();
    int numClusters = _ui->numClustersSpin->value();
    std::vector<Point*> &points = low?_lowPoints.data():_highPoints.data();

    std::vector<Point> centers;
    std::vector<int> assignment;
    PointClusterer::kmeans(PointClusterer::RANDOM,numClusters,
                           PointClusterer::EUCLIDEAN,
                           points, 10, centers, assignment);

    std::ostringstream ss;
    ss << "K-means " << numClusters << (low?" [low]":" [high]");
    Scalar *scalar = addScalar(ss.str());

    // create labels
    scalar->labels().clear();
    for (unsigned i=0; i<centers.size(); ++i) {
        ss.str("");
        ss << "Cluster [" << i << "]";
        scalar->labels().push_back(ss.str());
    }

    // assigne scalar values to points
    for (unsigned i=0; i<assignment.size(); ++i) {
        Point *p = _lowPoints.data()[i];
        p->setScalarValue(scalar, assignment[i]);
    }

    // refill combox
    fillScalarComboBox();
    _ui->colorByComboBox->setCurrentIndex(scalar->index());
}
float* LeastSquareFilter::computeLinearFunc(std::vector<float> Y)
{
	int n = Y.size();
	float res[2];
	res[0] = 0.0;
	res[1] = 0.0;

	if (n > 0) {
		std::vector<float> X = createSimpleVector(n);

		float meanX = mean(X);
		std::vector<float> x_minus_meanx = addScalar(X, -meanX);
		std::vector<float> x_minus_meanx_square = product(x_minus_meanx, x_minus_meanx);
		float SSxx = sum(x_minus_meanx_square);

		//
		float sumY = sum(Y);
		float sumX = n * (n-1) / 2.0;
		std::vector<float> x_product_y = product(X, Y);
		float SSxy = sum(x_product_y) - sumX * sumY / n;
		//
		float b1 = 0.0;

		if (SSxx != 0.0) {
			b1 = SSxy / SSxx;
		}
		float b0 = sumY / n - b1 * sumX / n;

		res[0] = b0;
		res[1] = b1;
	}

	return res;
}
void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength,
                          const SkScalar xpos[], SkScalar constY,
                          const SkPaint& paint) {
    size_t points = paint.countText(text, byteLength);
    if (0 == points)
        return;

    bool fast = paint.canComputeFastBounds();

    addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRAW_POS_TEXT_H);
    addPaint(paint);
    addText(text, byteLength);
    addInt(points);

#ifdef SK_DEBUG_SIZE
    size_t start = fWriter.size();
#endif
    if (fast) {
        addFontMetricsTopBottom(paint, constY);
    }
    addScalar(constY);
    fWriter.writeMul4(xpos, points * sizeof(SkScalar));
#ifdef SK_DEBUG_SIZE
    fPointBytes += fWriter.size() - start;
    fPointWrites += points;
#endif
    validate();
}
void ScriptResource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump) const
{
    Resource::onMemoryDump(levelOfDetail, memoryDump);
    const String name = getMemoryDumpName() + "/decoded_script";
    auto dump = memoryDump->createMemoryAllocatorDump(name);
    dump->addScalar("size", "bytes", m_script.string().sizeInBytes());
    memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
}
Exemple #12
0
int
Transform::
AutoScaleData()
{
    double min=stat.minValue();
    addScalar(-1*min);
    double max=stat.maxValue();
    if (max>0.0) ScaleData(1/max);
    return 0;
}
void TimeAnalysisWidget::loadLowAndHighData(std::string filename)
{
    std::string basename = filename.substr(0, filename.find_last_of('.'));    
    _highPoints.load(basename + ".high");

    //_lowPoints.load(basename + ".low");
    //_lowPoints.load(basename + ".low_normalized_cols");
//    _lowPoints.load(basename + ".low_normalized_rows");
    _lowPoints.load(basename + ".low_standarised");
    //_lowPoints.load(basename + ".low_unnormalized");

    // adding default scalars
    Scalar *noneScalar = addScalar("None");
    noneScalar->labels().push_back("None");

    Scalar *dayScalar = addScalar("Day");
    for (int i=0; i<7; ++i)
        dayScalar->labels().push_back(QDate::longDayName(i+1).toStdString());

    Scalar *wend_wdayScalar = addScalar("Weekend/Weekdays");
    wend_wdayScalar->labels().push_back("Weekdays");
    wend_wdayScalar->labels().push_back("Weekends");

    for (int i=0; i<_lowPoints.numPoints(); ++i) {
        Point *lp = _lowPoints.data()[i];
        Point *hp = _highPoints.data()[i];

        QDate d = lp->getDate();

        lp->setScalarValue(noneScalar, 0);
        lp->setScalarValue(dayScalar, d.dayOfWeek()-1);
        lp->setScalarValue(wend_wdayScalar, d.dayOfWeek()==6||d.dayOfWeek()==7);

        hp->setScalarValue(noneScalar, 0);
        hp->setScalarValue(dayScalar, d.dayOfWeek());
        hp->setScalarValue(wend_wdayScalar, d.dayOfWeek()==6||d.dayOfWeek()==7);
    }
}
void SkPictureRecord::drawPosText(const void* text, size_t byteLength,
                         const SkPoint pos[], const SkPaint& paint) {
    size_t points = paint.countText(text, byteLength);
    if (0 == points)
        return;

    bool canUseDrawH = true;
    // check if the caller really should have used drawPosTextH()
    {
        const SkScalar firstY = pos[0].fY;
        for (size_t index = 1; index < points; index++) {
            if (pos[index].fY != firstY) {
                canUseDrawH = false;
                break;
            }
        }
    }

    bool fast = canUseDrawH && paint.canComputeFastBounds();

    if (fast) {
        addDraw(DRAW_POS_TEXT_H_TOP_BOTTOM);
    } else {
        addDraw(canUseDrawH ? DRAW_POS_TEXT_H : DRAW_POS_TEXT);
    }
    addPaint(paint);
    addText(text, byteLength);
    addInt(points);

#ifdef SK_DEBUG_SIZE
    size_t start = fWriter.size();
#endif
    if (canUseDrawH) {
        if (fast) {
            addFontMetricsTopBottom(paint, pos[0].fY);
        }
        addScalar(pos[0].fY);
        SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar));
        for (size_t index = 0; index < points; index++)
            *xptr++ = pos[index].fX;
    }
    else {
        fWriter.writeMul4(pos, points * sizeof(SkPoint));
    }
#ifdef SK_DEBUG_SIZE
    fPointBytes += fWriter.size() - start;
    fPointWrites += points;
#endif
    validate();
}
Exemple #15
0
int  
Transform::
eqalMinValueRespZ()
{
  if (dataCube->GetDim()==2) return WRONGDIMENSION;
  
  double min=stat.maxValue();

  for (int z=0;z <dataCube->GetSize()[3];z++)
    {
      double minDiff=min-stat.minValue(z);
      addScalar(z,minDiff);
    }
  return 0;
}
Exemple #16
0
void SharedBuffer::onMemoryDump(const String& dumpPrefix,
                                WebProcessMemoryDump* memoryDump) const {
  if (m_buffer.size()) {
    WebMemoryAllocatorDump* dump =
        memoryDump->createMemoryAllocatorDump(dumpPrefix + "/shared_buffer");
    dump->addScalar("size", "bytes", m_buffer.size());
    memoryDump->addSuballocation(
        dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
  } else {
    // If there is data in the segments, then it should have been allocated
    // using fastMalloc.
    const String dataDumpName = dumpPrefix + "/segments";
    auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName);
    dump->addScalar("size", "bytes", m_size);
    memoryDump->addSuballocation(
        dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
  }
}
bool SkPictureRecord::rotate(SkScalar degrees) {
    addDraw(ROTATE);
    addScalar(degrees);
    validate();
    return this->INHERITED::rotate(degrees);
}