void setTemp() { //initalises temp, get sensor readings and sets the local temp to a normalised neural vector clearTemp(); setLeft(); setCentre(); setRight(); normaliseTemp(); }
/** * Fit peak without background i.e, with background removed * inspired from FitPowderDiffPeaks.cpp * copied from PoldiPeakDetection2.cpp * @param workspaceindex :: indice of the row to use @param center :: gaussian parameter - center @param sigma :: gaussian parameter - width @param height :: gaussian parameter - height @param startX :: fit range - start X value @param endX :: fit range - end X value @returns A boolean status flag, true for fit success, false else */ bool ConvertEmptyToTof::doFitGaussianPeak(int workspaceindex, double ¢er, double &sigma, double &height, double startX, double endX) { g_log.debug("Calling doFitGaussianPeak..."); // 1. Estimate sigma = sigma * 0.5; // 2. Use factory to generate Gaussian auto temppeak = API::FunctionFactory::Instance().createFunction("Gaussian"); auto gaussianpeak = boost::dynamic_pointer_cast<API::IPeakFunction>(temppeak); gaussianpeak->setHeight(height); gaussianpeak->setCentre(center); gaussianpeak->setFwhm(sigma); // 3. Constraint double centerleftend = center - sigma * 0.5; double centerrightend = center + sigma * 0.5; std::ostringstream os; os << centerleftend << " < PeakCentre < " << centerrightend; auto *centerbound = API::ConstraintFactory::Instance().createInitialized( gaussianpeak.get(), os.str(), false); gaussianpeak->addConstraint(centerbound); g_log.debug("Calling createChildAlgorithm : Fit..."); // 4. Fit API::IAlgorithm_sptr fitalg = createChildAlgorithm("Fit", -1, -1, true); fitalg->initialize(); fitalg->setProperty( "Function", boost::dynamic_pointer_cast<API::IFunction>(gaussianpeak)); fitalg->setProperty("InputWorkspace", m_inputWS); fitalg->setProperty("WorkspaceIndex", workspaceindex); fitalg->setProperty("Minimizer", "Levenberg-MarquardtMD"); fitalg->setProperty("CostFunction", "Least squares"); fitalg->setProperty("MaxIterations", 1000); fitalg->setProperty("Output", "FitGaussianPeak"); fitalg->setProperty("StartX", startX); fitalg->setProperty("EndX", endX); // 5. Result bool successfulfit = fitalg->execute(); if (!fitalg->isExecuted() || !successfulfit) { // Early return due to bad fit g_log.warning() << "Fitting Gaussian peak for peak around " << gaussianpeak->centre() << '\n'; return false; } // 6. Get result center = gaussianpeak->centre(); height = gaussianpeak->height(); double fwhm = gaussianpeak->fwhm(); return fwhm > 0.0; }
//----Gets local view and processes ready for comparison----// void setTemp() { //initalises temp, get sensor readings and sets the local temp to a normalised neural vector clearTemp(); float rightSonarValue = SensorValue(rightSonar); //obvious float leftSonarValue = SensorValue(leftSonar); float centreSonarValue = SensorValue(centreSonar); setLeft(leftSonarValue); setCentre(centreSonarValue); setRight(rightSonarValue); normaliseTemp(); }
void ofxFourUpDisplay::mouseDragged(ofMouseEventArgs &m) { if(!enabled) return; ofPoint currMouse = ofPoint(m.x, m.y); if(movingCentre) { setCentre(m.x, m.y); return; } if(prevViewport!=NULL) { ofPoint delta = currMouse - prevMouse; prevViewport->mouse (delta, m.button); } prevMouse = currMouse; }
/** * Create a function string from the given parameters and the algorithm inputs * @param peakHeight :: The height of the peak * @param peakLoc :: The location of the peak */ IFunction_sptr GetDetectorOffsets::createFunction(const double peakHeight, const double peakLoc) { FunctionFactoryImpl &creator = FunctionFactory::Instance(); auto background = creator.createFunction("LinearBackground"); auto peak = boost::dynamic_pointer_cast<IPeakFunction>( creator.createFunction(getProperty("PeakFunction"))); peak->setHeight(peakHeight); peak->setCentre(peakLoc); const double sigma(10.0); peak->setFwhm(2.0 * std::sqrt(2.0 * M_LN2) * sigma); auto fitFunc = new CompositeFunction(); // Takes ownership of the functions fitFunc->addFunction(background); fitFunc->addFunction(peak); return boost::shared_ptr<IFunction>(fitFunc); }
ofxFourUpDisplay::ofxFourUpDisplay(ofScene3d *scene, ofRectangle rect) { this->scene = scene; movingCentre = false; x = rect.x; y = rect.y; width = rect.width; height = rect.height; // create 4 viewports viewports.push_back(new OrthoViewport(x, y, width/2, height/2, Viewport_ROTATABLE)); viewports.push_back(new OrthoViewport(width/2, x, width/2, height/2, Viewport_TOP)); viewports.push_back(new OrthoViewport(x, y + height/2, width/2, height/2, Viewport_FRONT)); viewports.push_back(new OrthoViewport(width/2, y + height/2, width/2, height/2, Viewport_LEFT)); setCentre(x + width/2, y + height/2); prevViewport = NULL; overCentre = false; enabled = false; }
void AppsPageComponent::buttonStateChanged(Button* btn) { auto appBtn = (AppIconButton*)btn; auto appIcon = (DrawableImage*)appBtn->getCurrentImage(); auto buttonPopup = launcherComponent->focusButtonPopup.get(); constexpr auto scale = 1.3; // show floating button popup if we're holding downstate and not showing the popup if (btn->isMouseButtonDown() && btn->isMouseOver() && !buttonPopup->isVisible()) { // copy application icon bounds in screen space auto boundsNext = appIcon->getScreenBounds(); auto boundsCentre = boundsNext.getCentre(); // scale and recenter boundsNext.setSize(boundsNext.getWidth()*scale, boundsNext.getHeight()*scale); boundsNext.setCentre(boundsCentre); // translate back to space local to popup parent (local bounds) auto parentPos = launcherComponent->getScreenPosition(); boundsNext.setPosition(boundsNext.getPosition() - parentPos); // show popup icon, hide real button beneath buttonPopup->setImage(appIcon->getImage()); buttonPopup->setBounds(boundsNext); buttonPopup->setVisible(true); appIcon->setVisible(false); appBtn->setColour(DrawableButton::textColourId, Colours::transparentWhite); } // set UI back to default if we can see the popup, but aren't holding the button down else if (btn->isVisible()) { appIcon->setVisible(true); appBtn->setColour(DrawableButton::textColourId, getLookAndFeel().findColour(DrawableButton::textColourId)); buttonPopup->setVisible(false); } }
/** * Gaussian fit to determine peak position if no user position given. * * @return :: detector position of the peak: Gaussian fit and position * of the maximum (serves as start value for the optimization) */ double LoadILLReflectometry::reflectometryPeak() { if (!isDefault("BeamCentre")) { return getProperty("BeamCentre"); } size_t startIndex; size_t endIndex; std::tie(startIndex, endIndex) = fitIntegrationWSIndexRange(*m_localWorkspace); IAlgorithm_sptr integration = createChildAlgorithm("Integration"); integration->initialize(); integration->setProperty("InputWorkspace", m_localWorkspace); integration->setProperty("OutputWorkspace", "__unused_for_child"); integration->setProperty("StartWorkspaceIndex", static_cast<int>(startIndex)); integration->setProperty("EndWorkspaceIndex", static_cast<int>(endIndex)); integration->execute(); MatrixWorkspace_sptr integralWS = integration->getProperty("OutputWorkspace"); IAlgorithm_sptr transpose = createChildAlgorithm("Transpose"); transpose->initialize(); transpose->setProperty("InputWorkspace", integralWS); transpose->setProperty("OutputWorkspace", "__unused_for_child"); transpose->execute(); integralWS = transpose->getProperty("OutputWorkspace"); rebinIntegralWorkspace(*integralWS); // determine initial height: maximum value const auto maxValueIt = std::max_element(integralWS->y(0).cbegin(), integralWS->y(0).cend()); const double height = *maxValueIt; // determine initial centre: index of the maximum value const size_t maxIndex = std::distance(integralWS->y(0).cbegin(), maxValueIt); const double centreByMax = static_cast<double>(maxIndex); g_log.debug() << "Peak maximum position: " << centreByMax << '\n'; // determine sigma const auto &ys = integralWS->y(0); auto lessThanHalfMax = [height](const double x) { return x < 0.5 * height; }; using IterType = HistogramData::HistogramY::const_iterator; std::reverse_iterator<IterType> revMaxValueIt{maxValueIt}; auto revMinFwhmIt = std::find_if(revMaxValueIt, ys.crend(), lessThanHalfMax); auto maxFwhmIt = std::find_if(maxValueIt, ys.cend(), lessThanHalfMax); std::reverse_iterator<IterType> revMaxFwhmIt{maxFwhmIt}; if (revMinFwhmIt == ys.crend() || maxFwhmIt == ys.cend()) { g_log.warning() << "Couldn't determine fwhm of beam, using position of max " "value as beam center.\n"; return centreByMax; } const double fwhm = static_cast<double>(std::distance(revMaxFwhmIt, revMinFwhmIt) + 1); g_log.debug() << "Initial fwhm (full width at half maximum): " << fwhm << '\n'; // generate Gaussian auto func = API::FunctionFactory::Instance().createFunction("CompositeFunction"); auto sum = boost::dynamic_pointer_cast<API::CompositeFunction>(func); func = API::FunctionFactory::Instance().createFunction("Gaussian"); auto gaussian = boost::dynamic_pointer_cast<API::IPeakFunction>(func); gaussian->setHeight(height); gaussian->setCentre(centreByMax); gaussian->setFwhm(fwhm); sum->addFunction(gaussian); func = API::FunctionFactory::Instance().createFunction("LinearBackground"); func->setParameter("A0", 0.); func->setParameter("A1", 0.); sum->addFunction(func); // call Fit child algorithm API::IAlgorithm_sptr fit = createChildAlgorithm("Fit"); fit->initialize(); fit->setProperty("Function", boost::dynamic_pointer_cast<API::IFunction>(sum)); fit->setProperty("InputWorkspace", integralWS); fit->setProperty("StartX", centreByMax - 3 * fwhm); fit->setProperty("EndX", centreByMax + 3 * fwhm); fit->execute(); const std::string fitStatus = fit->getProperty("OutputStatus"); if (fitStatus != "success") { g_log.warning("Fit not successful, using position of max value.\n"); return centreByMax; } const auto centre = gaussian->centre(); g_log.debug() << "Sigma: " << gaussian->fwhm() << '\n'; g_log.debug() << "Estimated peak position: " << centre << '\n'; return centre; }