// ----------------------------------------------------------------------------- // StillTracking // ----------------------------------------------------------------------------- // Called during tracking. // OSStatus TValuePictControl::StillTracking(TCarbonEvent&inEvent, HIPoint& from) { HIPoint mouse; float deltaX, deltaY; SInt32 mini, maxi; mini = GetMinimum(); maxi = GetMaximum(); inEvent.GetParameter<HIPoint>( kEventParamWindowMouseLocation, typeHIPoint, &mouse ); ConvertToLocal(mouse); SInt32 curVal = GetValue(); deltaX = mouse.x-from.x; deltaY = mouse.y-from.y; SInt32 val = SInt32(rint(curVal + (deltaX - deltaY) * (maxi - mini) / 300.)); if ( val > maxi) val = maxi; if ( val < mini) val = mini; if (val != curVal) { SetValue ( val ); from = mouse; } return noErr; }
void MgFeatureNumericFunctions::CalculateDistribution(VECTOR_INT64& values, VECTOR_INT64& distValues) { INT32 funcCode = -1; // Get the arguments from the FdoFunction bool supported = MgServerFeatureUtil::FindCustomFunction(m_customFunction, funcCode); if (supported) { switch(funcCode) { case MINIMUM: { GetMinimum(values, distValues); break; } case MAXIMUM: { GetMaximum(values, distValues); break; } case UNIQUE: { MgUniqueFunction<INT64>::Execute(values, distValues); break; } } } }
void Minimize1<Real>::GetMinimum (Real t0, Real t1, Real tInitial, Real& tMin, Real& fMin) { assertion(t0 <= tInitial && tInitial <= t1, "Invalid initial t value\n"); mTMin = Math<Real>::MAX_REAL; mFMin = Math<Real>::MAX_REAL; Real f0 = mFunction(t0, mUserData); if (f0 < mFMin) { mTMin = t0; mFMin = f0; } Real fInitial = mFunction(tInitial, mUserData); if (fInitial < mFMin) { mTMin = tInitial; mFMin = fInitial; } Real f1 = mFunction(t1, mUserData); if (f1 < mFMin) { mTMin = t1; mFMin = f1; } GetMinimum(t0, f0, tInitial, fInitial, t1, f1, mMaxLevel); tMin = mTMin; fMin = mFMin; }
//---------------------------------------------------------------------------- void Minimize1D::GetMinimum (float fT0, float fT1, float fTInitial, float& rfTMin, float& rfFMin) { VERIFY( fT0 <= fTInitial && fTInitial <= fT1 ); m_fTMin = flt_max; m_fFMin = flt_max; float fF0 = m_oF(fT0,m_pvUserData); float fFInitial = m_oF(fTInitial,m_pvUserData); float fF1 = m_oF(fT1,m_pvUserData); GetMinimum(fT0,fF0,fTInitial,fFInitial,fT1,fF1,m_iMaxLevel); rfTMin = m_fTMin; rfFMin = m_fFMin; }
void checkpthat(TString fnameevt, TString filename, TString prefix, TString jtptvar) { TFile *f = new TFile(fnameevt); auto nt = (TTree *)f->Get("nt"); auto h = geth(prefix+"mcpthat", 80, 0, 400); nt->Project(h->GetName(),"pthat",""); int minbin = nt->GetMinimum("pthatbin"); int maxbin = nt->GetMaximum("pthatbin"); //assumes ints between min and max int N = maxbin-minbin+1; vector<TString> pthatcuts; pthatcuts = {"pthat>30 && pthat<50","pthat>50 && pthat<80","pthat>80 && pthat<120","pthat>120"}; auto hs = getstack(nt, prefix+"mcpthatstack","pthat",pthatcuts,80,0,400); hs->SetMinimum(1E-2); fout->cd(); hs->Write(); h->Write(); f->Close(); f = new TFile(filename); nt = (TTree *)f->Get("nt"); auto hj = geth(prefix+"mcjtpt", 80, 0, 400); nt->Project(hj->GetName(),jtptvar,"weight*(subid==0)",jtptvar); vector<TString> jtptcuts; jtptcuts = {"pthat>30 && pthat<50 && subid==0","pthat>50 && pthat<80 && subid==0","pthat>80 && pthat<120 && subid==0","pthat>120 && subid==0"}; // for (int i=0;i<N;i++) jtptcuts.push_back(Form("pthatbin==%d",i)); auto hsjtpt = getstack(nt, prefix+"mcjtptstack",jtptvar,jtptcuts,80,0,400); hsjtpt->SetMinimum(1E-2); fout->cd(); hsjtpt->Write(); hj->Write(); // fout->Write(); f->Close(); }
//----------------------------------------------------------------------------------- // ValueChanged //----------------------------------------------------------------------------------- void TMultiPane::ValueChanged() { HIViewRef subPane; SInt32 value = GetValue(); SInt32 min = GetMinimum(); SInt32 max = GetMaximum(); for (SInt32 i = min; i <= max; ++i) { HIViewID id = { kSubPanelSignature + mID, i }; OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane); if (result == noErr) { HIViewSetVisible( subPane, false); } } HIViewID id = { kSubPanelSignature + mID, value }; OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane); if (result == noErr) { HIViewSetVisible( subPane, true); } Invalidate(); }
void Minimize1<Real>::GetBracketedMinimum (Real t0, Real f0, Real tm, Real fm, Real t1, Real f1, int level) { for (int i = 0; i < mMaxBracket; ++i) { // Update minimum value. if (fm < mFMin) { mTMin = tm; mFMin = fm; } // Test for convergence. const Real epsilon = (Real)1e-08; const Real tolerance = (Real)1e-04; if (Math<Real>::FAbs(t1-t0) <= ((Real)2)*tolerance* Math<Real>::FAbs(tm) + epsilon ) { break; } // Compute vertex of interpolating parabola. Real dt0 = t0 - tm; Real dt1 = t1 - tm; Real df0 = f0 - fm; Real df1 = f1 - fm; Real tmp0 = dt0*df1; Real tmp1 = dt1*df0; Real denom = tmp1 - tmp0; if (Math<Real>::FAbs(denom) < epsilon) { return; } Real tv = tm + ((Real)0.5)*(dt1*tmp1 - dt0*tmp0)/denom; assertion(t0 <= tv && tv <= t1, "Vertex not in interval\n"); Real fv = mFunction(tv, mUserData); if (fv < mFMin) { mTMin = tv; mFMin = fv; } if (tv < tm) { if (fv < fm) { t1 = tm; f1 = fm; tm = tv; fm = fv; } else { t0 = tv; f0 = fv; } } else if (tv > tm) { if (fv < fm) { t0 = tm; f0 = fm; tm = tv; fm = fv; } else { t1 = tv; f1 = fv; } } else { // The vertex of parabola is already at middle sample point. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } }
void Minimize1<Real>::GetMinimum (Real t0, Real f0, Real t1, Real f1, int level) { if (level-- == 0) { return; } Real tm = ((Real)0.5)*(t0 + t1); Real fm = mFunction(tm, mUserData); if (fm < mFMin) { mTMin = tm; mFMin = fm; } if (f0 - ((Real)2)*fm + f1 > (Real)0) { // The quadratic fit has positive second derivative at the midpoint. if (f1 > f0) { if (fm >= f0) { // Increasing, repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else if (f1 < f0) { if (fm >= f1) { // Decreasing, repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else { // Constant, repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } else { // The quadratic fit has nonpositive second derivative at the // midpoint. if (f1 > f0) { // Repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else if (f1 < f0) { // Repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } }
int main(int argc, char** argv) { setTDRStyle(); gStyle -> SetOptFit(0000); int nFib = 64; int nCryst = 9; std::string inFileName(argv[1]); //---------- // open file TFile* inFile = TFile::Open(Form("ntuples/tot_capture_%s.root",inFileName.c_str())); TTree* tree = (TTree*)( inFile->Get("tree") ); //--------------------- // set branch addresses std::map<int,std::vector<int>*> t_waveform; std::map<int,std::vector<int>*> t_crystWaveform; for(int fibIt = 0; fibIt < nFib; ++fibIt) { t_waveform[fibIt] = new std::vector<int>; tree -> SetBranchAddress(Form("fib%02d_waveform",fibIt),&t_waveform[fibIt]); } for(int crystIt = 0; crystIt < nCryst; ++crystIt) { t_crystWaveform[crystIt] = new std::vector<int>; tree -> SetBranchAddress(Form("cryst%01d_waveform",crystIt),&t_crystWaveform[crystIt]); } //------------- // define plots std::map<int,int> n_waveform_fib; TGraph** g_waveform_fib = new TGraph*[nFib]; std::map<int,int> n_waveform_cut_fib; TGraph** g_waveform_cut_fib = new TGraph*[nFib]; TH1F** h_ped_fib = new TH1F*[nFib]; TH1F* h_ped_fib_all = new TH1F("h_ped_fib_all","",100,80.,120.); TH1F** h_maximum_fib = new TH1F*[nFib]; TH1F* h_maximum_fib_all = new TH1F("h_maximum_fib_all","",1000,0.,2500.); for(int fibIt = 0; fibIt < nFib; ++fibIt) { g_waveform_fib[fibIt] = new TGraph(); g_waveform_cut_fib[fibIt] = new TGraph(); h_ped_fib[fibIt] = new TH1F(Form("h_ped_fib%02d",fibIt),"",100,80.,120.); h_maximum_fib[fibIt] = new TH1F(Form("h_maximum_fib%02d",fibIt),"",1000,0.,2500.); } TProfile2D* p_fibAveInt = new TProfile2D("p_fibAveInt","",17,-0.5,16.5,18,-0.5,17.5); TProfile2D* p_fibAveMax = new TProfile2D("p_fibAveMax","",17,-0.5,16.5,18,-0.5,17.5); TProfile2D* p_crystAveMax = new TProfile2D("p_crystAveMax","",3,-0.5,2.5,3,-0.5,2.5); TH1F* h_tot_integral = new TH1F("h_tot_integral","",1000,0.,100000.); TH1F* h_tot_maximum = new TH1F("h_tot_maximum", "",1000,0.,1000.); //------------------ // loop over entries for(int entry = 0; entry < tree->GetEntries(); ++entry) { std::cout << ">>> reading entry " << entry << " / " << tree->GetEntries() << "\r" << std::flush; tree -> GetEntry(entry); float tot_integral = 0.; float tot_maximum = 0.; for(int fibIt = 0; fibIt < nFib; ++fibIt) { ++n_waveform_fib[fibIt]; AddWaveform(g_waveform_fib[fibIt],t_waveform[fibIt]); float ped, integral, maximum; CalculateAmplitude(t_waveform[fibIt],ped,integral,maximum); h_ped_fib[fibIt] -> Fill(ped); h_ped_fib_all -> Fill(ped); h_maximum_fib[fibIt] -> Fill(maximum); h_maximum_fib_all -> Fill(maximum); int x = 16-2*int(fibIt/8); int y = (x/2)%2 == 0 ? 16-2*(fibIt%8) : 16-2*(fibIt%8)-1; p_fibAveInt -> Fill(x,y,integral); p_fibAveMax -> Fill(x,y,maximum); if( maximum+ped > 120. ) { tot_integral += integral; tot_maximum += maximum; ++n_waveform_cut_fib[fibIt]; AddWaveform(g_waveform_cut_fib[fibIt],t_waveform[fibIt]); } } for(int crystIt = 0; crystIt < nCryst; ++crystIt) { float ped, integral, maximum; CalculateAmplitude(t_waveform[crystIt],ped,integral,maximum); p_crystAveMax -> Fill(crystIt%3,2-crystIt/3,maximum); } h_tot_integral -> Fill(tot_integral); h_tot_maximum -> Fill(tot_maximum); } TCanvas* c_waveform_fib_all = new TCanvas(); int plotIt = 0; float min = +999999.; float max = -999999.; for(int fibIt = 0; fibIt < nFib; ++fibIt) { TGraph* g = g_waveform_fib[fibIt]; if( g->GetN() == 0 ) continue; NormalizeGraph(g,n_waveform_fib[fibIt]); if( GetMinimum(g) < min ) min = GetMinimum(g); if( GetMaximum(g) > max ) max = GetMaximum(g); } for(int fibIt = 0; fibIt < nFib; ++fibIt) { TGraph* g = g_waveform_fib[fibIt]; if( g->GetN() == 0 ) continue; TCanvas* c_waveform_fib = new TCanvas(); g -> SetMinimum(min-0.05*fabs(max-min)); g -> SetMaximum(max+0.05*fabs(max-min)); g -> SetLineWidth(2); g -> SetLineColor(fibIt+1); g -> SetMarkerSize(0.2); g -> GetXaxis() -> SetTitle("sample time (ns)"); g -> Draw("APL"); c_waveform_fib -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/plotsPerFib/waveform_fib%02d.png",inFileName.c_str(),fibIt),"png"); c_waveform_fib_all -> cd(); if( plotIt == 0 ) g -> Draw("APL"); else g -> Draw("PL,same"); ++plotIt; } c_waveform_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/waveform_fib_all.png",inFileName.c_str()),"png"); TCanvas* c_waveform_cut_fib_all = new TCanvas(); plotIt = 0; min = +999999.; max = -999999.; for(int fibIt = 0; fibIt < nFib; ++fibIt) { TGraph* g = g_waveform_cut_fib[fibIt]; if( g->GetN() == 0 ) continue; NormalizeGraph(g,n_waveform_cut_fib[fibIt]); if( GetMinimum(g) < min ) min = GetMinimum(g); if( GetMaximum(g) > max ) max = GetMaximum(g); } for(int fibIt = 0; fibIt < nFib; ++fibIt) { TGraph* g = g_waveform_cut_fib[fibIt]; if( g->GetN() == 0 ) continue; //g -> SetMinimum(min-0.05*fabs(max-min)); //g -> SetMaximum(max+0.05*fabs(max-min)); g -> SetLineWidth(2); g -> SetLineColor(fibIt+1); g -> SetMarkerSize(0.2); g -> GetXaxis() -> SetTitle("sample time (ns)"); g -> Draw("APL"); c_waveform_cut_fib_all -> cd(); if( plotIt == 0 ) g -> Draw("APL"); else g -> Draw("PL,same"); ++plotIt; } c_waveform_cut_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/waveform_cut_fib_all.png",inFileName.c_str()),"png"); for(int fibIt = 0; fibIt < nFib; ++fibIt) { TH1F* h = h_ped_fib[fibIt]; TCanvas* c_ped_fib = new TCanvas(); c_ped_fib -> SetLogy(); h -> SetLineWidth(2); h -> GetXaxis() -> SetTitle("max sample"); h -> Draw(); h -> Fit("gaus","Q"); TLatex* latex1 = new TLatex(0.60,0.90,Form("RMS = %.1f",h->GetRMS())); latex1 -> SetNDC(); latex1 -> SetTextFont(42); latex1 -> SetTextSize(0.04); latex1 -> Draw("same"); TLatex* latex2 = new TLatex(0.60,0.85,Form("#sigma = %.1f",h->GetFunction("gaus")->GetParameter(2))); latex2 -> SetNDC(); latex2 -> SetTextFont(42); latex2 -> SetTextSize(0.04); latex2 -> Draw("same"); c_ped_fib -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/plotsPerFib/ped_fib%02d.png",inFileName.c_str(),fibIt),"png"); h = h_maximum_fib[fibIt]; TCanvas* c_maximum_fib = new TCanvas(); c_maximum_fib -> SetLogy(); h -> SetLineWidth(2); h -> GetXaxis() -> SetTitle("max sample"); h -> Draw(); c_maximum_fib -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/plotsPerFib/maximum_fib%02d.png",inFileName.c_str(),fibIt),"png"); } TCanvas* c_ped_fib_all = new TCanvas(); c_ped_fib_all -> SetLogy(); h_ped_fib_all -> SetLineWidth(2); h_ped_fib_all -> GetXaxis() -> SetTitle("pedestal"); h_ped_fib_all -> Draw(); h_ped_fib_all -> Fit("gaus","Q"); TLatex* latex1 = new TLatex(0.60,0.90,Form("RMS = %.1f",h_ped_fib_all->GetRMS())); latex1 -> SetNDC(); latex1 -> SetTextFont(42); latex1 -> SetTextSize(0.04); latex1 -> Draw("same"); TLatex* latex2 = new TLatex(0.60,0.85,Form("#sigma = %.1f",h_ped_fib_all->GetFunction("gaus")->GetParameter(2))); latex2 -> SetNDC(); latex2 -> SetTextFont(42); latex2 -> SetTextSize(0.04); latex2 -> Draw("same"); c_ped_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/ped_fib_all.png",inFileName.c_str()),"png"); TCanvas* c_maximum_fib_all = new TCanvas(); c_maximum_fib_all -> SetLogy(); h_maximum_fib_all -> SetLineWidth(2); h_maximum_fib_all -> GetXaxis() -> SetTitle("max sample"); h_maximum_fib_all -> Draw(); c_maximum_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/maximum_fib_all.png",inFileName.c_str()),"png"); TCanvas* c_fibAveInt = new TCanvas(); p_fibAveInt -> Draw("COLZ"); c_fibAveInt -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/fibAveInt.png",inFileName.c_str()),"png"); TCanvas* c_fibAveMax = new TCanvas(); p_fibAveMax -> Draw("COLZ"); c_fibAveMax -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/fibAveMax.png",inFileName.c_str()),"png"); TCanvas* c_crystAveMax = new TCanvas(); p_crystAveMax -> Draw("COLZ"); c_crystAveMax -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/crystAveMax.png",inFileName.c_str()),"png"); TCanvas* c_tot_integral = new TCanvas(); c_tot_integral -> SetLogy(); h_tot_integral -> Draw(); c_tot_integral -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/tot_integral.png",inFileName.c_str()),"png"); TCanvas* c_tot_maximum = new TCanvas(); c_tot_maximum -> SetLogy(); h_tot_maximum -> Draw(); c_tot_maximum -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/tot_maximum.png",inFileName.c_str()),"png"); }
//---------------------------------------------------------------------------- void Minimize1D::GetMinimum (float fT0, float fF0, float fTm, float fFm, float fT1, float fF1, int iLevel) { if ( fF0 < m_fFMin ) { m_fTMin = fT0; m_fFMin = fF0; } if ( fFm < m_fFMin ) { m_fTMin = fTm; m_fFMin = fFm; } if ( fF1 < m_fFMin ) { m_fTMin = fT1; m_fFMin = fF1; } if ( iLevel-- == 0 ) return; if ( (fT1 - fTm)*(fF0 - fFm) > (fTm - fT0)*(fFm - fF1) ) { // quadratic fit has positive second derivative at midpoint if ( fF1 > fF0 ) { if ( fFm >= fF0 ) { // increasing, repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else if ( fF1 < fF0 ) { if ( fFm >= fF1 ) { // decreasing, repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else { // constant, repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } else { // quadratic fit has nonpositive second derivative at midpoint if ( fF1 > fF0 ) { // repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else if ( fF1 < fF0 ) { // repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } }
//---------------------------------------------------------------------------- void Minimize1D::GetBracketedMinimum (float fT0, float fF0, float fTm, float fFm, float fT1, float fF1, int iLevel) { for (int i = 0; i < m_iMaxBracket; i++) { // update minimum value if ( fFm < m_fFMin ) { m_fTMin = fTm; m_fFMin = fFm; } // test for convergence const float fEps = 1e-08f, fTol = 1e-04f; if ( _abs(fT1-fT0) <= 2.0f*fTol*_abs(fTm) + fEps ) break; // compute vertex of interpolating parabola float fDT0 = fT0 - fTm, fDT1 = fT1 - fTm; float fDF0 = fF0 - fFm, fDF1 = fF1 - fFm; float fTmp0 = fDT0*fDF1, fTmp1 = fDT1*fDF0; float fDenom = fTmp1 - fTmp0; if ( _abs(fDenom) < fEps ) return; float fTv = fTm + 0.5f*(fDT1*fTmp1-fDT0*fTmp0)/fDenom; VERIFY( fT0 <= fTv && fTv <= fT1 ); float fFv = m_oF(fTv,m_pvUserData); if ( fTv < fTm ) { if ( fFv < fFm ) { fT1 = fTm; fF1 = fFm; fTm = fTv; fFm = fFv; } else { fT0 = fTv; fF0 = fFv; } } else if ( fTv > fTm ) { if ( fFv < fFm ) { fT0 = fTm; fF0 = fFm; fTm = fTv; fFm = fFv; } else { fT1 = fTv; fF1 = fFv; } } else { // vertex of parabola is already at middle sample point GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } }
CPLErr VRTSourcedRasterBand::ComputeRasterMinMax( int bApproxOK, double* adfMinMax ) { double dfMin = 0.0; double dfMax = 0.0; /* -------------------------------------------------------------------- */ /* Does the driver already know the min/max? */ /* -------------------------------------------------------------------- */ if( bApproxOK ) { int bSuccessMin, bSuccessMax; dfMin = GetMinimum( &bSuccessMin ); dfMax = GetMaximum( &bSuccessMax ); if( bSuccessMin && bSuccessMax ) { adfMinMax[0] = dfMin; adfMinMax[1] = dfMax; return CE_None; } } /* -------------------------------------------------------------------- */ /* If we have overview bands, use them for min/max. */ /* -------------------------------------------------------------------- */ if ( bApproxOK && GetOverviewCount() > 0 && !HasArbitraryOverviews() ) { GDALRasterBand *poBand; poBand = GetRasterSampleOverview( GDALSTAT_APPROX_NUMSAMPLES ); if ( poBand != this ) return poBand->ComputeRasterMinMax( FALSE, adfMinMax ); } /* -------------------------------------------------------------------- */ /* Try with source bands. */ /* -------------------------------------------------------------------- */ if ( bAntiRecursionFlag ) { CPLError( CE_Failure, CPLE_AppDefined, "VRTSourcedRasterBand::ComputeRasterMinMax() called recursively on the same band. " "It looks like the VRT is referencing itself." ); return CE_Failure; } bAntiRecursionFlag = TRUE; adfMinMax[0] = 0.0; adfMinMax[1] = 0.0; for( int iSource = 0; iSource < nSources; iSource++ ) { double adfSourceMinMax[2]; CPLErr eErr = papoSources[iSource]->ComputeRasterMinMax(GetXSize(), GetYSize(), bApproxOK, adfSourceMinMax); if (eErr != CE_None) { eErr = GDALRasterBand::ComputeRasterMinMax(bApproxOK, adfMinMax); bAntiRecursionFlag = FALSE; return eErr; } if (iSource == 0 || adfSourceMinMax[0] < adfMinMax[0]) adfMinMax[0] = adfSourceMinMax[0]; if (iSource == 0 || adfSourceMinMax[1] > adfMinMax[1]) adfMinMax[1] = adfSourceMinMax[1]; } bAntiRecursionFlag = FALSE; return CE_None; }
void MgFeatureNumericFunctions::CalculateDistribution(VECTOR& values, VECTOR& distValues) { STRING funcName; int numCats; double dataMin, dataMax; INT32 funcCode = -1; // Get the arguments from the FdoFunction STRING propertyName; bool supported = MgServerFeatureUtil::FindCustomFunction(m_customFunction, funcCode); if (supported) { switch(funcCode) { case EQUAL_CATEGORY: // Equal Category { MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type); GetEqualCategories(values, numCats, dataMin, dataMax, distValues); break; } case STDEV_CATEGORY: // StdDev Category { MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type); GetStandardDeviationCategories(values, numCats, dataMin, dataMax, distValues); break; } case QUANTILE_CATEGORY: // Quantile Category { MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type); GetQuantileCategories(values, numCats, dataMin, dataMax, distValues); break; } case JENK_CATEGORY: // Jenk Category { MgServerFeatureUtil::GetArguments(m_customFunction, propertyName, numCats, dataMin, dataMax, m_type); GetJenksCategories(values, numCats, dataMin, dataMax, distValues); break; } case MINIMUM: { GetMinimum(values,distValues); break; } case MAXIMUM: { GetMaximum(values,distValues); break; } case MEAN: { GetMeanValue(values,distValues); break; } case STANDARD_DEV: { GetStandardDeviation(values,distValues); break; } case UNIQUE: { MgUniqueFunction<double>::Execute(values, distValues); break; } } } }
void ExtractSES(MinHeapS *mheap, SEEDS *all_seeds, int *heappointer, int xd, int yd, int zd, int *atom_index, int atom_num, ATOM *atomlist, float thresh) { int i,j,k; int m,n,l, num, c; int index,index1; float dist; FLTVECT seed; char visited; xdim1 = xd; ydim1 = yd; zdim1 = zd; atom_list = atomlist; min_heap = mheap; AllSeeds = all_seeds; heap_pointer = heappointer; threshold = thresh; /* Initialize */ index = 0; min_heap->size = 0; for (k=0; k<zdim1; k++) for (j=0; j<ydim1; j++) for (i=0; i<xdim1; i++) { if (atom_index[IndexVect1(i,j,k)] < 0) { for (num = 0; num < MaxAtom; num++) AllSeeds[index].atom[num] = -1; num = 0; for (l=k-1; l<=k+1; l++) for (n=j-1; n<=j+1; n++) for (m=i-1; m<=i+1; m++) { if (m==i||n==j||l==k) { index1 = atom_index[IndexVect1(m,n,l)]; if (index1 < 0) { index1 = -index1-1; visited = 0; for (c=0; c<num; c++) { if (index1 == AllSeeds[index].atom[c]) visited = 1; } if (visited == 0) { AllSeeds[index].atom[num] = index1; num++; if (num == MaxAtom) num--; } } } } seed = FindSeed(i,j,k,index); AllSeeds[index].seedx = seed.x; AllSeeds[index].seedy = seed.y; AllSeeds[index].seedz = seed.z; dist = (seed.x-i)*(seed.x-i) + (seed.y-j)*(seed.y-j) + (seed.z-k)*(seed.z-k); min_seed = index; InsertHeap(i,j,k, dist); index++; } else if (atom_index[IndexVect1(i,j,k)] > 0) { heap_pointer[IndexVect1(i,j,k)] = MaxVal; } else { heap_pointer[IndexVect1(i,j,k)] = -11; } } /* Fast Marching Method */ while (1){ GetMinimum(); if (min_dist >= MaxDist-0.001) break; Marching(); } }
void AARect::Translate(const Vector2 &translation) { SetExtents(GetMinimum() + translation, GetMaximum() + translation); }
//---------------------------------------------------------------------------- void Minimize1D::GetMinimum (float fT0, float fF0, float fT1, float fF1, int iLevel) { if ( fF0 < m_fFMin ) { m_fTMin = fT0; m_fFMin = fF0; } if ( fF1 < m_fFMin ) { m_fTMin = fT1; m_fFMin = fF1; } if ( iLevel-- == 0 ) return; float fTm = 0.5f*(fT0+fT1); float fFm = m_oF(fTm,m_pvUserData); if ( fF0 - 2.0f*fFm + fF1 > 0.0f ) { // quadratic fit has positive second derivative at midpoint if ( fF1 > fF0 ) { if ( fFm >= fF0 ) { // increasing, repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else if ( fF1 < fF0 ) { if ( fFm >= fF1 ) { // decreasing, repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else { // constant, repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } else { // quadratic fit has nonpositive second derivative at midpoint if ( fF1 > fF0 ) { // repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else if ( fF1 < fF0 ) { // repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } }
void Minimize1<Real>::GetMinimum (Real t0, Real f0, Real tm, Real fm, Real t1, Real f1, int level) { if (level-- == 0) { return; } if ((t1 - tm)*(f0 - fm) > (tm - t0)*(fm - f1)) { // The quadratic fit has positive second derivative at the midpoint. if (f1 > f0) { if (fm >= f0) { // Increasing, repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else if (f1 < f0) { if (fm >= f1) { // Decreasing, repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else { // Constant, repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } else { // The quadratic fit has a nonpositive second derivative at the // midpoint. if (f1 > f0) { // Repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else if ( f1 < f0 ) { // Repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } }
void GDALTerrain::init() { dataset = (GDALDataset*) GDALOpen(gdalFile.c_str(), GA_ReadOnly); if(dataset == nullptr) { std::cerr << "Unable to open GDAL File: " << gdalFile << std::endl; exit(1); } auto raster = dataset->GetRasterBand(1); width = raster->GetXSize(); height = raster->GetYSize(); int gotMin, gotMax; float min = (float) raster->GetMinimum(&gotMin); float max = (float) raster->GetMaximum(&gotMax); double minMax[2] = {min, max}; if(!(gotMin && gotMax)) { GDALComputeRasterMinMax((GDALRasterBandH) raster, TRUE, minMax); min = (float) minMax[0]; max = (float) minMax[1]; } if(Engine::getEngine()->getOptions().verbose) { std::cout << "terrain: " << gdalFile << " x: " << width << " y: " << height << " min: " << min << " max: " << max << std::endl; } Vertex vert; vert.normal[0] = 0; vert.normal[1] = 1; vert.normal[2] = 0; float scale = Engine::getEngine()->getOptions().map_scalar; heightScale = 100.0f; gdal_data = std::vector<std::vector<float>>(height, std::vector<float>(width, 0.0f)); float *lineData1 = new float[width]; float *lineData2 = new float[width]; float range = max - min; for(int z = 0; z < height-1; z++) { raster->RasterIO(GF_Read, 0, z, width, 1, lineData1, width, 1, GDT_Float32, 0, 0); raster->RasterIO(GF_Read, 0, z+1, width, 1, lineData2, width, 1, GDT_Float32, 0, 0); gdal_data[z].assign(lineData1, lineData1+width); gdal_data[z+1].assign(lineData2, lineData2+width); for(int x = 0; x < width-1; x++) { vert.pos[0] = x * scale; vert.pos[1] = heightScale * (lineData1[x]-min)/range; vert.pos[2] = z * scale; vert.texture[0] = x;// / float(width); vert.texture[1] = z;// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = (x+1) * scale; vert.pos[1] = heightScale * (lineData1[x+1]-min)/range; vert.pos[2] = z * scale; vert.texture[0] = (x+1);// / float(width); vert.texture[1] = z;// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = x * scale; vert.pos[1] = heightScale * (lineData2[x]-min)/range; vert.pos[2] = (z+1) * scale; vert.texture[0] = x;// / float(width); vert.texture[1] = (z+1);// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = x * scale; vert.pos[1] = heightScale * (lineData2[x]-min)/range; vert.pos[2] = (z+1) * scale; vert.texture[0] = x;// / float(width); vert.texture[1] = (z+1);// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = (x+1) * scale; vert.pos[1] = heightScale * (lineData2[x+1]-min)/range; vert.pos[2] = (z+1) * scale; vert.texture[0] = (x+1);// / float(width); vert.texture[1] = (z+1);// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = (x+1) * scale; vert.pos[1] = heightScale * (lineData1[x+1]-min)/range; vert.pos[2] = z * scale; vert.texture[0] = (x+1);// / float(width); vert.texture[1] = z;// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); } } // for(int i = 0; i < geometry.size(); i++) { // if(i % 6 == 0) // std::cout << i << ": " << geometry[i].pos[1] << std::endl; //} std::cout << "size: " << geometry.size() << std::endl; delete[] lineData1; delete[] lineData2; Vertex *geo = geometry.data(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * geometry.size(), geo, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(program->getLocation("vs_pos"), 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,pos)); glEnableVertexAttribArray(1); glVertexAttribPointer(program->getLocation("vs_norm"), 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,normal)); glEnableVertexAttribArray(2); glVertexAttribPointer(program->getLocation("vs_uv"), 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,texture)); texture = new Texture("../assets/desert.jpg", GL_TEXTURE_2D); //model = glm::translate(model, glm::vec3(width/2, 0, height/2)); }