std::string makeFormattedString( const char* aFormat, const A1& a1 = A1(), const A2& a2 = A2(), const A3& a3 = A3(), const A4& a4 = A4(), const A5& a5 = A5(), const A6& a6 = A6(), const A7& a7 = A7(), const A8& a8 = A8(), const A9& a9 = A9(), const A10& a10 = A10(), const A11& a11 = A11(), const A12& a12 = A12(), const A13& a13 = A13(), const A14& a14 = A14(), const A15& a15 = A15(), const A16& a16 = A16(), const A17& a17 = A17(), const A18& a18 = A18(), const A19& a19 = A19(), const A20& a20 = A20() ) { return makeStringByPrintf(aFormat, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 ); }
int get_toa (double *s, double *p, double *phasex, double *errphasex, double psrfreq, int nphase, double *rms, double *bx) // calculate the phase shift between template and simulated (or real) data // error of phase can be calculated // initial guess of phase shift is added // try to do two-dim template matching { //int nphase=1024; int nchn=1; // read a std //puts(argv[1]); //puts(argv[2]); //double t[nphase*nchn],s[nphase*nchn]; //int n; //readfile(name,&n,t,s); //printf ("%d\n", n); //puts(argv[1]); ////////////////////////////////////////////////////////////////////////// // simulate data //double p[nphase*nchn]; //double SNR=atof(argv[2]); //simulate(n,SNR,s,p);//*/ ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // dft profile and template //nchn = n/nphase; //printf ("%d\n", nchn); int k; // k=nphase/2 //double amp_s[nchn][nphase/2],amp_p[nchn][nphase/2]; // elements for calculating A7 //double phi_s[nchn][nphase/2],phi_p[nchn][nphase/2]; params param; allocateMemoryPtime (¶m, nchn, nphase); //double amp_s[nchn][NP],amp_p[nchn][NP]; // elements for calculating A7 //double phi_s[nchn][NP],phi_p[nchn][NP]; // the second dim should be NP, which is large enough for different observations preA7(s, p, nphase, nchn, ¶m); //preA7(&k, amp_s, amp_p, phi_s, phi_p, s, p, nphase, nchn); //printf ("%d\n", nchn); // initial guess of the phase int peak_s, peak_p; find_peak(0, nphase,s,&peak_s); find_peak(0, nphase,p,&peak_p); int d, chn; double step; double ini_phase,up_phase,low_phase; d = InitialGuess (s, p, nphase, 1, &chn); //d=peak_p-peak_s; //printf ("Initial guess: %d\n",d); step=2.0*M_PI/(10.0*nphase); if (d>=nphase/2) { if (d>0) { ini_phase=2.0*M_PI*(nphase-1-d)/nphase; } else { ini_phase=-2.0*M_PI*(nphase-1+d)/nphase; } up_phase=ini_phase+step; low_phase=ini_phase-step; while (A7(up_phase, param)*A7(low_phase, param)>0.0) { up_phase+=step; low_phase-=step; } } else { ini_phase=-2.0*M_PI*d/nphase; up_phase=ini_phase+step; low_phase=ini_phase-step; while (A7(up_phase, param)*A7(low_phase, param)>0.0) { up_phase+=step; low_phase-=step; } } // calculate phase shift, a and b double phase,b; phase=zbrent(A7, low_phase, up_phase, 1.0e-16, param); //phase=zbrent(A7, -1.0, 1.0, 1.0e-16); //phase=zbrent(A7, -0.005, 0.005, 1.0e-16); b=A9(phase, param); //a=A4(b); (*bx) = b; //printf ("Phase shift: %.10lf\n", phase/(2.0*M_PI)); //printf ("%.10lf %.10lf\n", phase, A7(phase)); //printf ("%.10lf \n", ((phase/3.1415926)*5.75/2.0)*1.0e+3); // microseconds //printf ("%.10lf \n", b); //printf ("%.10lf \n", a); //printf ("///////////////////////// \n"); // calculate the errors of phase and b double errphase, errb; error(phase,b,&errphase,&errb, param); //printf ("%.10lf %.10lf\n", ((phase/3.1415926)/(psrfreq*2.0))*1.0e+6, ((errphase/3.1415926)/(psrfreq*2.0))*1.0e+6); // microseconds //printf ("%.10lf %.10lf\n", ((phase/3.1415926)*4.569651/2.0)*1.0e+3, ((errphase/3.1415926)*4.569651/2.0)*1.0e+3); // microseconds //printf ("errphase %.10lf \n", ((errphase/3.1415926)*5.75/2.0)*1.0e+6); //printf ("errb %.10lf \n", errb); (*phasex) = phase; (*errphasex) = errphase; // calculate the rms cal_rms(phase,b,rms, param); deallocateMemoryPtime (¶m, nchn); return 0; }
int main(int argc, char** argv) { const int TARIFFA = 2; Autovettura A1("bj066mx", "benzina", "suv", 6); Autovettura A2("kt887gg", "gpl", "monovolume", 5); Autovettura A3("dh572xc", "metano", "berlina", 5); Autovettura A4("mq111nd", "diesel", "utilitaria", 4); Autobus A5("cc789oi", "benzina", "bus", 50, "Milano", 200); Autobus A6("st230ks", "gpl", "bus", 50, "Roma", 300); Autobus A7("vv234sd", "metano", "bus", 25, "Napoli", 100); Autobus A8("we785ss", "diesel", "bus", 60, "Parma", 400); Autoveicolo * v[8]; v[0] = &A1; v[1] = &A2; v[2] = &A3; v[3] = &A4; v[4] = &A5; v[5] = &A6; v[6] = &A7; v[7] = &A8; cout<<"Polimorfismo:\n"; for(int i=0; i<8; i++) { v[i]->stampaDati(); cout << "\n"; } Coda C1, C2, C3; C1.append(&A1); C1.append(&A2); C1.append(&A3); C1.append(&A4); C1.append(&A5); C1.append(&A6); C1.append(&A7); C1.append(&A8); C2.append(&A1); C2.append(&A2); C2.append(&A3); C2.append(&A4); C2.append(&A5); C2.append(&A6); C2.append(&A7); C3.append(&A1); C3.append(&A2); C3.append(&A3); C3.append(&A4); C3.append(&A5); C3.append(&A6); cout<<"\n\n\nCoda1:\n"; cout<<C1; cout<<"\n\n\nCoda2:\n"; cout<<C2; cout<<"\n\n\nCoda3:\n"; cout<<C3; cout<<"\n\n\n"; int e1, e2, e3; e1 = C1.getNelem(); e2 = C2.getNelem(); e3 = C3.getNelem(); for(int i = 0; i<e1; i++) { Autoveicolo * elem; C1.pop(elem, TARIFFA); cout<<"Elemento rimosso -> "; elem->stampaDati(); cout<<endl; } cout<<"\n\n\n"; for(int i = 0; i<e2; i++) { Autoveicolo * elem; C2.pop(elem, TARIFFA); cout<<"Elemento rimosso -> "; elem->stampaDati(); cout<<endl; } cout<<"\n\n\n"; for(int i = 0; i<e3; i++) { Autoveicolo * elem; C3.pop(elem, TARIFFA); cout<<"Elemento rimosso -> "; elem->stampaDati(); cout<<endl; } if(C1.getIncasso()>100) { cout<<"\n\n\nIncasso totale: "<<C1.getIncasso()<< " bombe!"; } else { cout<<"\n\n\nIncasso totale: "<<C1.getIncasso()<<" frecce!"; } return 0; }
SolidesP ConstruireNormale (FacesP Face) // Construit un solide symbolisant la normale à la face. // Le solide est placé sur le barycentre de la face et peut donc // être hors de la face. // Sa longueur est égale à 5% de la dimension du solide à laquelle la // face appartient s'il existe. Sinon, c'est 10 % de la dimension de la face. { SolidesP Sol = Face.Solide () ; double HauteurTot ; Englobants3D EnglobantFace = Face.Englobant () ; if (Sol.EstInitialise ()) { Englobants3D E = Sol.Englobant () ; Vecteurs3D V (E.BasGauche (),E.HautDroit ()) ; HauteurTot = 0.05*V.Norme () ; ; } else { Vecteurs3D V (EnglobantFace.BasGauche (),EnglobantFace.HautDroit ()) ; HauteurTot = 0.1*V.Norme () ; ; } double LargeurPied = HauteurTot / 24, LargeurTete = HauteurTot / 4, HauteurPied = (7./8.)*HauteurTot ; // Construction d'un repère centré sur le "barycentre" de la face, dont // le (xOy) correspond au plan de la face et dont le z est la normale à // la face. Points3D Origine = 0.5*(EnglobantFace.BasGauche ()+EnglobantFace.HautDroit ()) ; Vecteurs3D K = Face.VecteurNormal ().VecteurNorme (), U (Face.ContourExterieur ().IemeAreteOrientee (0).Origine ().Point3D (), Face.ContourExterieur ().IemeAreteOrientee (0).Extremite ().Point3D ()), I = (K & U).VecteurNorme (), J = (K & I).VecteurNorme () ; SommetsP S1 (Origine-LargeurPied/2*I - LargeurPied/2*J) ; SommetsP S2 (Origine-LargeurPied/2*I + LargeurPied/2*J) ; SommetsP S3 (Origine+LargeurPied/2*I + LargeurPied/2*J) ; SommetsP S4 (Origine+LargeurPied/2*I - LargeurPied/2*J) ; SommetsP S5 (Origine-LargeurPied/2*I - LargeurPied/2*J + HauteurPied*K) ; SommetsP S6 (Origine-LargeurPied/2*I + LargeurPied/2*J + HauteurPied*K) ; SommetsP S7 (Origine+LargeurPied/2*I + LargeurPied/2*J + HauteurPied*K) ; SommetsP S8 (Origine+LargeurPied/2*I - LargeurPied/2*J + HauteurPied*K) ; SommetsP S9 (Origine-LargeurTete/2*I - LargeurTete/2*J + HauteurPied*K) ; SommetsP S10 (Origine-LargeurTete/2*I + LargeurTete/2*J + HauteurPied*K) ; SommetsP S11 (Origine+LargeurTete/2*I + LargeurTete/2*J + HauteurPied*K) ; SommetsP S12 (Origine+LargeurTete/2*I - LargeurTete/2*J + HauteurPied*K) ; SommetsP S13 (Origine+HauteurTot*K) ; AretesP A1 (S1,S2) ; AretesP A2 (S2,S3) ; AretesP A3 (S3,S4) ; AretesP A4 (S4,S1) ; AretesP A5 (S5,S6) ; AretesP A6 (S6,S7) ; AretesP A7 (S7,S8) ; AretesP A8 (S8,S5) ; AretesP A9 (S9,S10) ; AretesP A10 (S10,S11) ; AretesP A11 (S11,S12) ; AretesP A12 (S12,S9) ; AretesP A13 (S1,S5) ; AretesP A14 (S2,S6) ; AretesP A15 (S3,S7) ; AretesP A16 (S4,S8) ; AretesP A17 (S9,S13) ; AretesP A18 (S10,S13) ; AretesP A19 (S11,S13) ; AretesP A20 (S12,S13) ; Listes <AretesP> L1 ; L1.InsertionEnQueue (A1) ; L1.InsertionEnQueue (A2) ; L1.InsertionEnQueue (A3) ; L1.InsertionEnQueue (A4) ; Listes <AretesP> L2 ; L2.InsertionEnQueue (A1) ; L2.InsertionEnQueue (A13) ; L2.InsertionEnQueue (A5) ; L2.InsertionEnQueue (A14) ; Listes <AretesP> L3 ; L3.InsertionEnQueue (A2) ; L3.InsertionEnQueue (A14) ; L3.InsertionEnQueue (A6) ; L3.InsertionEnQueue (A15) ; Listes <AretesP> L4 ; L4.InsertionEnQueue (A3) ; L4.InsertionEnQueue (A15) ; L4.InsertionEnQueue (A7) ; L4.InsertionEnQueue (A16) ; Listes <AretesP> L5 ; L5.InsertionEnQueue (A4) ; L5.InsertionEnQueue (A16) ; L5.InsertionEnQueue (A8) ; L5.InsertionEnQueue (A13) ; Listes <AretesP> L6 ; L6.InsertionEnQueue (A9) ; L6.InsertionEnQueue (A10) ; L6.InsertionEnQueue (A11) ; L6.InsertionEnQueue (A12) ; Listes <AretesP> L7 ; L7.InsertionEnQueue (A8) ; L7.InsertionEnQueue (A7) ; L7.InsertionEnQueue (A6) ; L7.InsertionEnQueue (A5) ; Listes <AretesP> L8 ; L8.InsertionEnQueue (A9) ; L8.InsertionEnQueue (A17) ; L8.InsertionEnQueue (A18) ; Listes <AretesP> L9 ; L9.InsertionEnQueue (A10) ; L9.InsertionEnQueue (A18) ; L9.InsertionEnQueue (A19) ; Listes <AretesP> L10 ; L10.InsertionEnQueue (A11) ; L10.InsertionEnQueue (A19) ; L10.InsertionEnQueue (A20) ; Listes <AretesP> L11 ; L11.InsertionEnQueue (A12) ; L11.InsertionEnQueue (A20) ; L11.InsertionEnQueue (A17) ; Listes <FacesP> ListeFaces ; AttributsFaces *PAF = new AttributsFaces (PMateriauRouge) ; FacesP F1 (ContoursP (L1),PAF) ; ListeFaces.InsertionEnQueue (F1) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L2),PAF)) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L3),PAF)) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L4),PAF)) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L5),PAF)) ; ContoursP C (L6) ; FacesP F (C,PAF) ; F.AjouterContourInterieur (ContoursP (L7)) ; ListeFaces.InsertionEnQueue (F) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L8),PAF)) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L9),PAF)) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L10),PAF)) ; ListeFaces.InsertionEnQueue (FacesP (ContoursP (L11),PAF)) ; return SolidesP (ListeFaces) ; }