/** * Project an input pixel onto an arbitrary reference line at a reference angle. * The projection is done along lines of constant Q, which emanate from the * horizon angle at wavelength = 0. The top-left and bottom-right corners of * the pixel are projected, resulting in an output range in "virtual" lambda. * * For a description of this projection, see: * R. Cubitt, T. Saerbeck, R.A. Campbell, R. Barker, P. Gutfreund * J. Appl. Crystallogr., 48 (6) (2015) * * @param wavelengthRange [in] :: the bin edges of the input bin * @param twoThetaRange [in] :: the 2theta width of the pixel * @param refAngles [in] :: the reference angles * @return :: the projected wavelength range */ ReflectometrySumInQ::MinMax ReflectometrySumInQ::projectedLambdaRange(const MinMax &wavelengthRange, const MinMax &twoThetaRange, const Angles &refAngles) { // We cannot project pixels below the horizon angle if (twoThetaRange.min <= refAngles.horizon) { const auto twoTheta = (twoThetaRange.min + twoThetaRange.max) / 2.; throw std::runtime_error( "Cannot process twoTheta=" + std::to_string(twoTheta * Geometry::rad2deg) + " as it is below the horizon angle=" + std::to_string(refAngles.horizon * Geometry::rad2deg)); } // Calculate the projected wavelength range MinMax range; try { const double lambdaTop = projectToReference(wavelengthRange.max, twoThetaRange.min, refAngles); const double lambdaBot = projectToReference(wavelengthRange.min, twoThetaRange.max, refAngles); range.testAndSet(lambdaBot); range.testAndSet(lambdaTop); } catch (std::exception &ex) { const auto twoTheta = (twoThetaRange.min + twoThetaRange.max) / 2.; const auto lambda = (wavelengthRange.min + wavelengthRange.max) / 2.; throw std::runtime_error( "Failed to project (lambda, twoTheta) = (" + std::to_string(lambda) + "," + std::to_string(twoTheta * Geometry::rad2deg) + ") onto twoThetaR = " + std::to_string(refAngles.twoTheta) + ": " + ex.what()); } return range; }
int main(){ MinMax m; int a = 4; int b = 2; int c = 7; cout << a << "と" << b << "と" << c << "のうち、最大のものは" << m.max(a,b,c) << endl; cout << a << "と" << b << "と" << c << "のうち、最小のものは" << m.min(a,b,c) << endl; return 0; }
const MinMax Engine::findFrameRotation( const int nbit ) const { MinMax minmax; Skeleton skelWork = skel; for ( int k = -framesPerCycle; k < framesPerCycle; ++k ) { skelWork.rotate( 2*M_PI/(2*framesPerCycle) ); minmax.candidate( skelWork.findFrame( nbit, _x, _y, _color ) ); } minmax.build(); return minmax; }
const MinMax Engine::findFrameTransition( const int nbit ) const { MinMax minmax; Skeleton skelWork( skel1.size() ); for ( int k = -framesPerCycle; k <= 0; ++k ) { const float rate = ( 1 - cos( M_PI*k/framesPerCycle ) ) / 2; skelWork.weightedMix( skel1, skel2, rate ); minmax.candidate( skelWork.findFrame( nbit, _x, _y, _color ) ); } minmax.build(); return minmax; }
int main() { MinMax m1(10, 15); MinMax m2(8, 11); MinMax m3(3, 12); MinMax mFinal = m1 + m2 + 5 + 8 + m3 + 16; std::cout << "Result: (" << mFinal.getMin() << ", " << mFinal.getMax() << ")\n"; return 0; }
MinMax VectorFloat::getMinMax() const { const size_type N = this->size(); MinMax range; if( N == 0 ) return range; const Float *data = getData(); for(size_type i=0; i<N; i++){ range.updateMinMax( data[ i ] ); } return range; }
MonteCarloRun::MonteCarloRun( const MinMax<double> & modIndex, const MinMax<double> & fmModIndex, const MinMax<double> & freq, const MinMax<double> & digiFreq, const MinMax<double> & fc, const double & rate, const double & gain, const double & timePerSchemeSec, const size_t & frameSize, const size_t & N) : _modType(AMC::ModType::AM_DSB_FC), _dataStream(new UhdMock(new StreamFunction(), rate, gain, frameSize)), _buffer(_dataStream->getBuffer()), _featureExtractor(new AMC::FeatureExtractor(_buffer, N, rate)), _rate(rate), _timePerScheme(timePerSchemeSec * 1e9), _frameSize(frameSize), _N(N), _modIndex(rng_gen_type(std::time(0) + 100), boost::uniform_real<>(modIndex.getMin(), modIndex.getMax())), _fmModIndex(rng_gen_type(std::time(0) + 125), boost::uniform_real<>(fmModIndex.getMin(), fmModIndex.getMax())), _freq(rng_gen_type(std::time(0) + 259), boost::uniform_real<>(freq.getMin(), freq.getMax())), _digiFreq(rng_gen_type(std::time(0) - 9), boost::uniform_real<>(digiFreq.getMin(), digiFreq.getMax())), _fc(rng_gen_type(std::time(0) - 214), boost::uniform_real<>(fc.getMin(), fc.getMax())), _constSize(rng_gen_type(std::time(0) + 169), boost::uniform_int<>(2, 8)), _timer(), _thread(), _isRunning(false) { }
MonteCarloRun::MonteCarloRun( const MinMax<double> & modIndex, const MinMax<double> & fmModIndex, const MinMax<double> & freq, const MinMax<double> & digiFreq, const MinMax<double> & snr, const double & fc, const double & rate, const double & gain, const double & timePerSchemeSec, const size_t & frameSize, const size_t & N) : _modType(new SharedType<AMC::ModType>(AMC::ModType::AM_DSB_FC)), _dataStream(new UhdMock(new StreamFunction(), rate, gain, frameSize)), _buffer(_dataStream->getBuffer()), _featureExtractor(new AMC::FeatureExtractor(_buffer, new AmcCvDecisionTree(), rate, _dataStream->getFc(), _dataStream->getWindow(), N)), _rate(rate), _timePerScheme(timePerSchemeSec * 1e9), _frameSize(frameSize), _N(N), _fc(_dataStream->getFc()), _firWindow(_dataStream->getWindow()), _modIndex(rng_gen_type(std::time(0) + 100), boost::uniform_real<>(modIndex.getMin(), modIndex.getMax())), _fmModIndex(rng_gen_type(std::time(0) + 125), boost::uniform_real<>(fmModIndex.getMin(), fmModIndex.getMax())), _freq(rng_gen_type(std::time(0) + 259), boost::uniform_real<>(freq.getMin(), freq.getMax())), _digiFreq(rng_gen_type(std::time(0) - 9), boost::uniform_real<>(digiFreq.getMin(), digiFreq.getMax())), _snr(rng_gen_type(std::time(0) - 206), boost::uniform_real<>(snr.getMin(), snr.getMax())), _constSize(rng_gen_type(std::time(0) + 169), boost::uniform_int<>(2, 8)), _timer(), _thread(), _isRunning(false) { boost::unique_lock<boost::shared_mutex> fcLock(*_fc->getMutex()); _fc->getData() = fc; fcLock.unlock(); double maxWin = std::max(freq.getMax() / rate, digiFreq.getMax()); maxWin = std::max(maxWin, fmModIndex.getMax()); boost::unique_lock<boost::shared_mutex> firLock(*_firWindow->getMutex()); _firWindow->getData() = maxWin * 2.1; firLock.unlock(); }
/** * Return the wavelength range of the output histogram. * @param detectorWS [in] :: the input workspace * @param indices [in] :: the workspace indices of foreground histograms * @param refAngles [in] :: the reference angles * @return :: the minimum and maximum virtual wavelengths */ ReflectometrySumInQ::MinMax ReflectometrySumInQ::findWavelengthMinMax( const API::MatrixWorkspace &detectorWS, const Indexing::SpectrumIndexSet &indices, const Angles &refAngles) { const API::SpectrumInfo &spectrumInfo = detectorWS.spectrumInfo(); // Get the new max and min X values of the projected (virtual) lambda range const bool includePartialBins = getProperty(Prop::PARTIAL_BINS); // Find minimum and maximum 2thetas and the corresponding indices. // It cannot be assumed that 2theta increases with indices, check for example // D17 at ILL MinMax inputLambdaRange; MinMax inputTwoThetaRange; for (const auto i : indices) { const auto twoThetas = twoThetaWidth(i, spectrumInfo); inputTwoThetaRange.testAndSetMin(includePartialBins ? twoThetas.min : twoThetas.max); inputTwoThetaRange.testAndSetMax(includePartialBins ? twoThetas.max : twoThetas.min); const auto &edges = detectorWS.binEdges(i); for (size_t xIndex = 0; xIndex < edges.size(); ++xIndex) { // It is common for the wavelength to have negative values at ILL. const auto x = edges[xIndex + (includePartialBins ? 0 : 1)]; if (x > 0.) { inputLambdaRange.testAndSet(x); break; } } if (includePartialBins) { inputLambdaRange.testAndSet(edges.back()); } else { inputLambdaRange.testAndSet(edges[edges.size() - 2]); } } MinMax outputLambdaRange; outputLambdaRange.min = projectToReference(inputLambdaRange.min, inputTwoThetaRange.max, refAngles); outputLambdaRange.max = projectToReference(inputLambdaRange.max, inputTwoThetaRange.min, refAngles); if (outputLambdaRange.min > outputLambdaRange.max) { throw std::runtime_error( "Error projecting lambda range to reference line; projected range (" + std::to_string(outputLambdaRange.min) + "," + std::to_string(outputLambdaRange.max) + ") is negative."); } return outputLambdaRange; }
Zoom::Zoom( const MinMax& minmax, const int w, const int h, const Function& f, int nbFrames ) : zoomFunction(f), framingCorrection(0.96) { if ( f.modified() ) { zoomFunctionModified = true; zoomFunction.calculateTemp(); } else { zoomFunctionModified = false; } float inter; if ( minmax.w() * h > minmax.h() * w ) { inter = framingCorrection*w/(minmax.w()+0.00001); // to avoid division by 0 } else { inter = framingCorrection*h/(minmax.h()+0.00001); } centerX = (int)(w/2 - minmax.centerX()*inter); centerY = (int)(h/2 + minmax.centerY()*inter); fx = inter; fy = -inter; julia.start(nbFrames); }
Image amplify(Image img) { class MinMax { public: MinMax() : min(-1) , max(0) , dist(0.0) {} void set(SubPixel p) { if (p < min) min = p; if (p > max) max = p; } void setdist() { if (max-min == 0) return; dist = 255.0/(max-min); } SubPixel min; SubPixel max; double dist; }; MinMax red; MinMax green; MinMax blue; MinMax alpha; for (int r=0; r<img.height; ++r) { for (int c=0; c<img.width; ++c) { auto&& p = img.at(c, r); red .set(p.r()); green.set(p.g()); blue .set(p.b()); alpha.set(p.a()); } } red .setdist(); green.setdist(); blue .setdist(); alpha.setdist(); auto calc = [](const MinMax& mm, SubPixel& p) { if (mm.dist == 0.0) return; p = double(p-mm.min)/mm.dist; }; for (int r=0; r<img.height; ++r) { for (int c=0; c<img.width; ++c) { auto&& p = img.at(c, r); calc(red , p.r()); calc(green, p.g()); calc(blue , p.b()); calc(alpha, p.a()); } } return img; }
void GSquare::button_released(QAbstractButton *sender) { GCase *tmp_btn = (GCase *)sender; // TODO récupérer le resultat de l'ia JudgeDredd judge; coord_t coord; coord.x = tmp_btn->getX(); coord.y = tmp_btn->getY(); try { if (tmp_btn->isTaken() == false) { judge.putPieceOnMap(info, coord); change_btn_state(tmp_btn); change_currentPlayer(); MinMax ia; coord = ia.launch(info); judge.putPieceOnMap(info, coord); if ((tmp_btn = static_cast<GCase*>(group_pions->button(coord.x * 100 + coord.y)))); change_btn_state(tmp_btn); change_currentPlayer(); } } catch (GameExceptionWinByScore& e) { change_btn_state(tmp_btn); this->animation_victory(); } catch (GameExceptionWinByAlignement& e) { change_btn_state(tmp_btn); this->animation_victory(); } catch (const GameExceptionTwinTriple& e) { box.setText("Vous ne pouvez pas effectuer ce coup"); box.setWindowTitle("Coup Interdit"); box.exec(); QTimer::singleShot(300, this, SLOT(end_of_box())); } catch (InvalidMapException e) { // box(this); box.setText("Exception InvalidMap"); box.setWindowTitle("Coup Interdit"); box.exec(); QTimer::singleShot(300, this, SLOT(end_of_box())); } catch (GameInfo e) { //box(this); box.setText("Exception GameInfo"); box.setWindowTitle("Coup Interdit"); box.exec(); QTimer::singleShot(300, this, SLOT(end_of_box())); } //afficher le résultat }