void SCMapSeries::setSize(double r) { double tol = 1e-2, q; unsigned N = 1000, Nmax, Nmin; generate(N); q = getMaxRadius(); // Find N with multiplication by 2 while ( q > r) { N *= 2; generate(N); q = getMaxRadius(); std::cout << "First loop N=" << N << ", maxR=" << q << std::endl; } Nmax = N; Nmin = std::floor(N / 2); N = std::floor(3 * Nmax / 4); generate(N); q = getMaxRadius(); // Start bisection serch while (std::abs(r - q) > tol) { if (q > r) { Nmin = N; N += (unsigned)std::floor((Nmax - N) / 2); } else { // Chek if difference is less than 1% q = (N - Nmin) / (2.0 * N); //std::cout << "Relative difference in N dN/N=" << q << std::endl; if (q < tol) { q = getMaxRadius(); std::cout << "Final N=" << N << ", Rmax=" << q << std::endl; break; } Nmax = N; N -= std::floor((N - Nmin) / 2); } std::cout << "Bisection loop N=" << N << std::endl; generate(N); q = getMaxRadius(); } }
void AngleRadiusWidget::setAngleRadiusAtPosition(const QPoint& pos) { QPoint center(width()/2, height()/2); QPoint pixelSpacePos = pos - center; // Scale point from pixel coordinates to lie in [-maxRadius maxRadius] // Flip y-coordinate to get it facing upward instead of downward double x = getMaxRadius()*pixelSpacePos.x() / ((double)getMaxPixelSpaceRadius()); double y = -getMaxRadius()*pixelSpacePos.y() / ((double)getMaxPixelSpaceRadius()); double radius = std::sqrt(x*x+y*y); double theta = std::atan2(y, x); // Convert angle to lie within [0 2pi), http://en.wikipedia.org/wiki/Atan2 if (theta < 0.) theta += 2.*M_PI; setAngle(theta); setRadius(radius); }
void BlockFormationShape::calcFormationPositions(Formation& p_formation) { currentFormation_ = &p_formation; rows_ = sqrt(((float)currentFormation_->units.size()) / ROW_LENGTH_RATIO); if(rows_ <= 0) rows_ = 1; rowLength_ = ROW_LENGTH_RATIO * rows_; while(rowLength_ * rows_ < currentFormation_->units.size()) rowLength_++; float maxRadius = getMaxRadius(); float x = (((float) rows_) / 2) * maxRadius; for(int i = 0; i < rows_; ++i) { for(int j = 0; j < rowLength_; ++j) { if(i * rowLength_ + j < currentFormation_->units.size()) { currentFormation_->units[i * rowLength_ + j].position.x = x - i * maxRadius * 2; currentFormation_->units[i * rowLength_ + j].position.y = pow(-1, j) * ((j / 2) * maxRadius * 2 + maxRadius); } } } //formationPlacement_->placeUnits(p_formation); }
void AngleRadiusWidget::setMaxRadius(double radius) { if (maxRadius_ != radius) { maxRadius_ = radius; // Update radius to be within bounds setRadius(std::min(getRadius(), getMaxRadius())); update(); emit radiusMinMaxChanged(); } }
void AngleRadiusWidget::setMinMaxRadius(double minRadius, double maxRadius) { if (minRadius_ != minRadius || maxRadius_ != maxRadius) { minRadius_ = minRadius; maxRadius_ = maxRadius; // Update radius to be within bounds setRadius(glm::clamp(getRadius(), getMinRadius(), getMaxRadius())); update(); emit radiusMinMaxChanged(); } }
void SerpinskiShape::paintEvent(QPaintEvent *) { QPainter painter(this); QPen pen(QBrush(Qt::darkGreen), 2.3f); painter.setPen(pen); painter.setRenderHint(QPainter::Antialiasing, true); drawShape(painter, width() * 0.5, height() * 0.5, getMaxRadius()); painter.setRenderHint(QPainter::Antialiasing, false); }
ZCircleCloud_ptr Worm::toZCircleCloud(hpuint pointsPerTooth) { hpreal maxRadius = getMaxRadius(); hpreal startZ = 0.0; hpreal endZ = m_toothCount * m_module * M_PI; // Determine resolution (important for following simulations) hpuint resolutionZ = m_toothCount * pointsPerTooth; ZCircleCloud_ptr result = ZCircleCloud_ptr(new ZCircleCloud(maxRadius, startZ, endZ, resolutionZ)); return result; }
SCMapSeries::SCMapSeries ( unsigned N, std::vector<double> const& angle, std::vector< std::complex<sc::REAL> > const& prevertex, std::complex<sc::REAL> const& C, double rot ) { if (angle.size() != prevertex.size()) throw std::runtime_error("Size Mismatch: angles and prevertex size does NOT match!"); mM = angle.size(); for (auto a : angle) mvAngle.push_back(1.0 - a); mvPrevertex = prevertex; mC = C; mRotation = rot; generate(N); getMaxRadius(); }
/** * Get the peaks info for a single peak, defined by the row in the peaks table. * @param peaksWorkspace A pointer to a peaks workspace. * @param row The row in the peaks table. * @param position A reference which holds the position of the peak. * @param radius A reference which holds the radius of the peak. * @param specialCoordinateSystem The coordinate system. */ void ConcretePeaksPresenterVsi::getPeaksInfo( Mantid::API::IPeaksWorkspace_sptr peaksWorkspace, int row, Mantid::Kernel::V3D &position, double &radius, Mantid::Kernel::SpecialCoordinateSystem specialCoordinateSystem) const { switch (specialCoordinateSystem) { case (Mantid::Kernel::SpecialCoordinateSystem::QLab): position = peaksWorkspace->getPeak(row).getQLabFrame(); break; case (Mantid::Kernel::SpecialCoordinateSystem::QSample): position = peaksWorkspace->getPeak(row).getQSampleFrame(); break; case (Mantid::Kernel::SpecialCoordinateSystem::HKL): position = peaksWorkspace->getPeak(row).getHKL(); break; default: throw std::invalid_argument("The coordinate system is invalid.\n"); } // Peak radius Mantid::Geometry::PeakShape_sptr shape( peaksWorkspace->getPeakPtr(row)->getPeakShape().clone()); radius = getMaxRadius(shape); }
int main(int argc, char* argv[]) { bgPoint* backgroundData; long numberOfWindows; long maxRadius; bgPoint* background; FILE* windowsFile; char chrom[16]; long chromStart; long chromEnd; double percentId; long number; double backgroundPercentId; long backgroundNumber; double score; long AA; long AC; long AG; long AT; long CA; long CC; long CG; long CT; long GA; long GC; long GG; long GT; long TA; long TC; long TG; long TT; long globalNumber; double globalPercentId; long numWindowsScored = 0; long numWindowsDefaulted = 0; /* make sure that there are the correct number of arguments */ if(argc < 5 || argc > 6) { usage(argv[0]); exit(10); } /* load the data and get the number of windows */ backgroundData = loadBackground(argv[1], &numberOfWindows); maxRadius = 200 * getMaxRadius(backgroundData, numberOfWindows); qsort(backgroundData, numberOfWindows, sizeof(bgPoint), bgPointCompar); globalNumber = atol(argv[3]); // 100516125; globalPercentId = atof(argv[4]); // 0.668947295769709; /*fprintf(stderr, "maxRadius: %ld\n", maxRadius);*/ fprintf(stderr, "loaded %ld background window\n", numberOfWindows - 2); windowsFile = mustOpen(argv[2], "r"); /* see if the first character is a # */ *chrom = fgetc(windowsFile); if(*chrom == '#') { /* read the rest of the line */ while(fgetc(windowsFile) != '\n') ; } else ungetc(*chrom, windowsFile); while(!feof(windowsFile)) { if(fscanf(windowsFile, "%15s\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t" "%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld", chrom, &chromStart, &chromEnd, &number, &AA, &AC, &AG, &AT, &CA, &CC, &CG, &CT, &GA, &GC, &GG, >, &TA, &TC, &TG, &TT) != 20) continue; percentId = (((double)AA) + CC + GG +TT) / (((double)AA) + AC + AG + AT + CA + CC + CG + CT + GA + GC + GG + GT + TA + TC + TG + TT); background = getNearestEnclosing( (chromStart + chromEnd) / 2, backgroundData, numberOfWindows, maxRadius); /* if we didn't find an enclosing window */ if(background == 0 || background->number == -1) { /* used the genome-wide background numbers */ backgroundPercentId = globalPercentId; backgroundNumber = globalNumber; numWindowsDefaulted++; } else { backgroundPercentId = background->score; backgroundNumber = background->number; } /* adjust for the percent identity for the current window */ backgroundPercentId = (backgroundPercentId * backgroundNumber - number * percentId) / (backgroundNumber - number); if(argc == 5) score = number * (percentId - backgroundPercentId) / sqrt(number * backgroundPercentId * (1.0 - backgroundPercentId)); else score = number * (percentId - backgroundPercentId) / sqrt(number); printf("%s\t%ld\t%ld\t%lf\t%ld\n", chrom, chromStart, chromEnd, score, number); numWindowsScored++; } fprintf(stderr, "%ld windows of the %ld total windows scored used the default background\n", numWindowsDefaulted, numWindowsScored); return 0; }
void AngleRadiusWidget::paintEvent(QPaintEvent *) { const int referenceRadius = getMaxPixelSpaceRadius(); const double pixelSpaceRadius = referenceRadius*(getRadius()/getMaxRadius()); const qreal angleIndicatorCircleDiameter = 6.; QPen angleIndicatorPen(palette().midlight(), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); QPen coordinateSystemPen(palette().alternateBase(), 1, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); QPen circleBoundsPen(palette().alternateBase(), 1, Qt::DashLine, Qt::SquareCap, Qt::MiterJoin); // x and y in pixel coordinates auto x = pixelSpaceRadius*std::cos(getAngle()); auto y = -pixelSpaceRadius*std::sin(getAngle()); int side = qMin(width(), height()); QStylePainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.scale(side / (qreal)100., side / (qreal)100.); painter.setPen(coordinateSystemPen); // Draw axes and bounds circle(s) for (int i = 0; i < 4; ++i) { painter.drawLine(0, 0, referenceRadius+5, 0); painter.rotate(90.0); } painter.setPen(circleBoundsPen); // Display angle bounds by drawing a pie (pacman) if min/max is not 0/2pi int innerBoundsCircleRadius = static_cast<int>(static_cast<double>(referenceRadius)*(getMinRadius()/getMaxRadius())); if (getMinAngle() > 0. || getMaxAngle() < 2.*M_PI) { // drawPie wants 16*degrees int pieStart = static_cast<int>( 16*glm::degrees(getMinAngle()) ); int pieEnd = static_cast<int>( 16*(glm::degrees(getMaxAngle())-glm::degrees(getMinAngle())) ); painter.drawPie(-referenceRadius, -referenceRadius, 2*referenceRadius, 2*referenceRadius, pieStart, pieEnd); if (minRadius_ > 0.) { painter.drawPie(-innerBoundsCircleRadius, -innerBoundsCircleRadius, 2*innerBoundsCircleRadius, 2*innerBoundsCircleRadius, pieStart, pieEnd); } } else { painter.drawEllipse(-referenceRadius, -referenceRadius, 2*referenceRadius, 2*referenceRadius); if (minRadius_ > 0.) { painter.drawEllipse(-innerBoundsCircleRadius, -innerBoundsCircleRadius, 2*innerBoundsCircleRadius, 2*innerBoundsCircleRadius); } } // Draw angle and radius painter.setPen(QPen(palette().text().color())); QPainterPath anglePath; // Make sure that angle goes from 0 to 2*pi double sweepAngle = getAngle() < 0. ? 2.*M_PI+getAngle() : getAngle(); // Draw angle arc and text anglePath.arcTo(-10., -10., 20., 20., 0., glm::degrees(sweepAngle)); painter.drawPath(anglePath); std::stringstream angleStream; angleStream.precision(1); angleStream << std::fixed << glm::degrees(sweepAngle); int anglePosX = 5; int anglePosY = -10; QFontMetrics fm(painter.font()); QString angleText = QString::fromStdString(angleStream.str())+ QChar(0260); int angleTextWidth = fm.width(angleText); if (anglePosX+angleTextWidth > referenceRadius) { anglePosX = referenceRadius+2; anglePosY = -2; } // 0260 is the degree symbol painter.drawText(anglePosX, anglePosY, angleText); // Draw radius text std::stringstream radiusStream; radiusStream.precision(2); radiusStream << getRadius(); painter.drawText(static_cast<int>(x+angleIndicatorCircleDiameter+angleIndicatorPen.width()), static_cast<int>(y), QString::fromStdString(radiusStream.str())); // Rotated line and circle painter.setPen(angleIndicatorPen); painter.drawLine(QLineF(QPointF(0., 0.), QPointF(x, y))); painter.setBrush(QBrush(palette().shadow().color(), Qt::SolidPattern)); painter.drawEllipse(QPointF(x, y), angleIndicatorCircleDiameter, angleIndicatorCircleDiameter); }