int checksum(char *cp,int count) { char *scp; int cksum; int dum; scp=cp; while(*scp) { if (!isxdigit(*scp++)) return(SRLerrorout("Invalid hex digits",cp)); } scp=cp; cksum=count; while(count) { cksum += gh(scp,2); if (count == 2) dum = ~cksum; scp += 2; count--; } cksum&=0x0ff; // printf("\nCk:%02x",cksum); return(cksum==0x0ff); }
int main() { graph g("graph.txt"); DFS dfs(g); BFS bfs(g); dfs.set_discovered_action(new default_discovered()); dfs.set_exploring_action(new default_exploring()); dfs.set_explored_action(new default_explored()); bfs.set_discovered_action(new default_discovered()); bfs.set_exploring_action(new default_exploring()); bfs.set_explored_action(new default_explored()); std::cout << "running depth first search " << std::endl; dfs(0); std::cout << "running breadth first search " << std::endl; bfs(0); std::cout << "running kruskal algorithm " << std::endl; mst *kal = new kruskal(g); (*kal)(); delete kal; std::cout << "running prim algorithm " << std::endl; mst *pral = new prim(g); (*pral)(); delete pral; graph gh("graph.txt", true); kosaraju ko(gh); ko.run(); return 0; }
void MainWindow::UpdateItemList() { ListItem *li; sGridFrameHelper gh(ItemWin); sFORALL(Items,li) if(li->Select || li->Select2 || li->Select3) li->AddGui(gh); }
WinFrame::WinFrame() { Grid = new sGridFrame; AddChild(Grid); Grid->Columns = 12; ClearNotify(); // AddNotify(App->ints,sizeof(App->ints); // AddNotify(App->strings,sizeof(App->strings); // AddNotify(App->floats,sizeof(App->floats); sGridFrameHelper gh(Grid); gh.DoneMsg = sMessage(App,&MainWindow::UpdateText,1000); gh.ChangeMsg = sMessage(App,&MainWindow::UpdateText,1001); gh.Reset(); gh.Group(L"Buttons"); gh.Label(L"pushbuttons"); gh.PushButton(L"push A",sMessage(App,&MainWindow::UpdateText,1)); gh.PushButton(L"push B",sMessage(App,&MainWindow::UpdateText,2)); gh.Box(L"->",sMessage(App,&MainWindow::UpdateText,3)); gh.Box(L"...",sMessage(App,&MainWindow::UpdateText,4)); gh.Label(L"radio buttons"); gh.Radio(&App->ints[2],L"A|B|C|D|E|F|G",2); gh.Label(L"choices"); gh.Choice(&App->ints[0],L"off|on"); gh.Choice(&App->ints[1],L" 0| 1| 2| 3"); gh.Choice(&App->ints[1],L"*4bli|bla|blub"); gh.Label(L"Flags"); gh.Flags(&App->ints[3],L"on|off:*1zero|one:*2A|B|C|:*4-|action"); gh.Group(L"Text"); gh.Label(L"String"); gh.String(App->strings[0]); gh.Label(L"int"); gh.Int(&App->ints[4],0,16,0.25f); gh.Int(&App->ints[5],-1024,1024,16); gh.Label(L"float"); gh.Float(&App->floats[0],0,16,0.25f); gh.Float(&App->floats[1],-1024,1024,16); gh.Label(L"byte"); gh.Byte((sU8*)&App->ints[6],0,16,0.25f); gh.Byte((sU8*)&App->ints[7],0,255,16); gh.Group(L"Colors"); gh.Label(L"byte rgb"); gh.Color((sU32 *)&App->ints[8],L"rgb"); gh.Label(L"byte rgba"); gh.Color((sU32 *)&App->ints[9],L"rgba"); gh.Label(L"float rgb"); gh.ColorF(&App->floats[8],L"rgb"); gh.Label(L"float rgba"); gh.ColorF(&App->floats[12],L"rgba"); sWire->AddDrag(L"Frame",L"Scroll",sMessage(this,&WinFrame::DragScroll,0)); Default = 0; }
int main(){ freopen("D.txt", "r", stdin); LL t, a, b, k; dp(); scanf("%lld", &t); while(t--){ scanf("%lld%lld%lld", &a, &b, &k); gh(a, b, k); } return 0; }
QSharedPointer<Node> Node::CreateClientServer(const PrivateIdentity &ident, const Group &group, const QList<Address> &local, const QList<Address> &remote, const QSharedPointer<ISink> &sink, SessionFactory::SessionType session, AuthFactory::AuthType auth, const QSharedPointer<KeyShare> &keys) { QSharedPointer<GroupHolder> gh(new GroupHolder(group)); QSharedPointer<ClientServer::Overlay> overlay(new ClientServer::Overlay( ident.GetLocalId(), local, remote, QList<Connections::Id>(), ident.GetSuperPeer())); QObject::connect(gh.data(), SIGNAL(GroupUpdated()), overlay.data(), SLOT(GroupUpdated())); QSharedPointer<Network> network(new CSNetwork(overlay)); return QSharedPointer<Node>(new Node(ident, gh, overlay, network, sink, session, auth, keys)); }
QSharedPointer<Node> Node::CreateBasicGossip(const PrivateIdentity &ident, const Group &group, const QList<Address> &local, const QList<Address> &remote, const QSharedPointer<ISink> &sink, SessionFactory::SessionType session, AuthFactory::AuthType auth, const QSharedPointer<KeyShare> &keys) { QSharedPointer<GroupHolder> gh(new GroupHolder(group)); QSharedPointer<BaseOverlay> overlay(new BasicGossip(ident.GetLocalId(), local, remote)); QSharedPointer<Network> network(new DefaultNetwork( overlay->GetConnectionManager(), overlay->GetRpcHandler())); return QSharedPointer<Node>(new Node(ident, gh, overlay, network, sink, session, auth, keys)); }
MainWindow::MainWindow() { AddKey("Exit",sKEY_Escape|sKEYQ_Shift,sGuiMsg(this,&sWindow::CmdExit)); AddHelp(); // grid sGridFrame *g = new sGridFrame(); g->AddBorder(new sFocusBorder); g->AddScrolling(0,1); AddChild(g); sGridFrameHelper gh(g); gh.Label("Buttons"); gh.UpdatePool = 0; gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,0),"A"); gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,1),"B"); gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,2),"C"); gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,3),"D"); InitSound(); }
void EstimateLongPath(Map *m) { Graph *g = GraphSearchConstants::GetGraph(m); GraphMapHeuristic gh(m, g); double heur = 0; double dist = 0; graphState from, to; for (int x = 0; x < 20; x++) { node *n = g->GetRandomNode(); double newDist = FindFarDist(g, n, from, to); if (newDist > dist) { dist = newDist; heur = gh.HCost(from, to); } printf("%f\t%f\t%f\t%f\n", dist, dist/g->GetNumNodes(), heur, dist/heur); } }
virtual void SetUp() { sockaddr_x sa; int sock = Xsocket(AF_XIA, SOCK_STREAM, 0); XreadLocalHostAddr(sock, ad, XID_LEN, hid, XID_LEN, fid, XID_LEN); sprintf(fdag, FULL_DAG, ad, hid, SID); Graph gf(fdag); gf.fill_sockaddr(&sa); XregisterName(FULL_NAME, &sa); sprintf(hdag, HOST_DAG, ad, hid); Graph gh(hdag); gh.fill_sockaddr(&sa); XregisterName(HOST_NAME, &sa); Xclose(sock); nad = new Node(ad); nhid = new Node(hid); nsid = new Node(SID); ai = NULL; }
int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" #include "readEnvironmentalProperties.H" #include "readPISOControls.H" #include "initContinuityErrs.H" #include "createFields.H" #include "readTimeControls.H" #include "correctPhi.H" #include "CourantNo.H" #include "setInitialDeltaT.H" #include "initializeForceBalance.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // bool firstTimeStep = true; static vector CgCenter0 = vector(0,0,0); scalar myTimeStep = 0; /* * Open an output stream, to write the position of the COG into a file. * This should be able to be disabled in the future. */ OFstream of(runTime.path()/"cog.dat"); of << "# time" << tab << "CgCenter" << tab << "rotationCenter" << tab << "thetaAccel" << tab << "accelMass" << endl; OFstream angles(runTime.path()/"angles.dat"); angles << "# time" << tab << "thetaDiste" << endl; Info<< "\nStarting time loop\n" << endl; while (runTime.run()) { #include "readForceBalanceControls.H" #include "readControls.H" #include "CourantNo.H" // Make the fluxes absolute fvc::makeAbsolute(phi, U); #include "setDeltaT.H" runTime++; Info<< "Time = " << runTime.timeName() << nl << endl; scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime(); Info<< "Balance"<< endl; # include "krafter.H" // Does mesh change? //#include "krafter.H" //runTime.write(); //return(0); mesh.update(); //runTime.write(); //return(0); //bool meshChanged = mesh.update(); //if(mesh.moving() || meshChanged) if (mesh.changing()) { Info<< "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << endl; } volScalarField gh("gh", g & mesh.C()); surfaceScalarField ghf("ghf", g & mesh.Cf()); if (mesh.changing() && correctPhi) { #include "correctPhi.H" } // Make the fluxes relative to the mesh motion fvc::makeRelative(phi, U); if (mesh.changing() && checkMeshCourantNo) { #include "meshCourantNo.H" } twoPhaseProperties.correct(); #include "gammaEqnSubCycle.H" #include "UEqn.H" Info << " ueqn... " << endl; // --- PISO loop for (int corr=0; corr<nCorr; corr++) { #include "pEqn.H" } p = pd + rho*gh; if (pd.needReference()) { p += dimensionedScalar ( "p", p.dimensions(), pRefValue - pRefProbe->sample<scalar>("p")()[0] ); } turbulence->correct(); //this gravity maybe commented, not sure how well it works! #include"pEqnGravity.H" #include "continuityErrs.H" runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; firstTimeStep = false; myTimeStep++; } Info<< "End\n" << endl; return(0); }
GPGME_Error GPGME::init(const QString & gpgHomeDir) { if (instancesStore.contains(gpgHomeDir)) { return GPG_ERR_NO_ERROR; } setlocale(LC_ALL, ""); gpgme_check_version(NULL); gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); #ifdef LC_MESSAGES gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif gpgme_error_t err; gpgme_ctx_t context; err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); if (err != GPG_ERR_NO_ERROR) { return err; } QString protocolName = gpgme_get_protocol_name(GPGME_PROTOCOL_OpenPGP); qDebug() << "protocol: " << protocolName; gpgme_engine_info_t engineInfo; err = gpgme_get_engine_info(&engineInfo); if (err != GPG_ERR_NO_ERROR) { return err; } qDebug() << "Backend info"; qDebug() << "filename: " << engineInfo->file_name << ", homedir: " << engineInfo->home_dir; err = gpgme_new(&context); if (err != GPG_ERR_NO_ERROR) { return err; } err = gpgme_set_protocol(context, GPGME_PROTOCOL_OpenPGP); if (err != GPG_ERR_NO_ERROR) { return err; } // we don't need to set gnupg home dir explicitly QString gnupgHome; if (gpgHomeDir.isEmpty()) { // i.e. use default gnupg directory or one from environment QString gnupgHomeEnv = QString::fromLatin1(qgetenv("GNUPGHOME")); if (!gnupgHomeEnv.isEmpty()) { gnupgHome = gnupgHomeEnv; } else { // use default path: "~/.gnupg" QDir gh = QDir::home(); gh.cd(".gnupg"); gnupgHome = gh.canonicalPath(); } } else { QDir gh(gpgHomeDir); gnupgHome = gh.canonicalPath(); } qDebug() << "GNUPGHOME" << gnupgHome; err = gpgme_ctx_set_engine_info(context, GPGME_PROTOCOL_OpenPGP, engineInfo->file_name, gnupgHome.toLatin1().data() ); if (err != GPG_ERR_NO_ERROR) { return err; } GPGME * inst = new GPGME(context, gnupgHome); instancesStore[gpgHomeDir] = inst; qDebug() << "gpgme initalized for the directory " << gnupgHome << "[store key: " << gpgHomeDir << "]"; return GPG_ERR_NO_ERROR; }
int main(int argc, char *argv[]) { # include "setRootCase.H" # include "createTime.H" # include "createDynamicFvMesh.H" # include "readGravitationalAcceleration.H" # include "readPIMPLEControls.H" # include "initContinuityErrs.H" # include "createFields.H" # include "readTimeControls.H" # include "correctPhi.H" # include "CourantNo.H" # include "setInitialDeltaT.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; while (runTime.run()) { # include "readControls.H" # include "CourantNo.H" // Make the fluxes absolute fvc::makeAbsolute(phi, U); # include "setDeltaT.H" runTime++; Info<< "Time = " << runTime.timeName() << nl << endl; bool meshChanged = mesh.update(); reduce(meshChanged, orOp<bool>()); # include "volContinuity.H" volScalarField gh("gh", g & mesh.C()); surfaceScalarField ghf("ghf", g & mesh.Cf()); if (correctPhi && meshChanged) { # include "correctPhi.H" } // Make the fluxes relative to the mesh motion fvc::makeRelative(phi, U); if (checkMeshCourantNo) { # include "meshCourantNo.H" } // Pressure-velocity corrector int oCorr = 0; do { twoPhaseProperties.correct(); # include "alphaEqnSubCycle.H" # include "UEqn.H" // --- PISO loop for (int corr = 0; corr < nCorr; corr++) { # include "pEqn.H" } p = pd + rho*gh; if (pd.needReference()) { p += dimensionedScalar ( "p", p.dimensions(), pRefValue - getRefCellValue(p, pdRefCell) ); } turbulence->correct(); } while (++oCorr < nOuterCorr); runTime.write(); // Write Porous Variables if( activePorosity && runTime.outputTime() ) { porosity.write(); porosityIndex.write(); } Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return 0; }
int srecLine(char *pSrecLine) { char *scp,ch; int itmp,count,dat; bit32u adr; static bit32u RecordCounter=0; cur_line++; scp=pSrecLine; if (*pSrecLine!='S') return(SRLerrorout("Not an Srecord file",scp)); pSrecLine++; if (strlen(pSrecLine)<4) return(SRLerrorout("Srecord too short",scp)); ch=*pSrecLine++; count=gh(pSrecLine,2); pSrecLine += 2; // if(debug) // printf("count %d, strlen(pSrecLine) = %d, pSrecLine =[%s]\n", count, strlen(pSrecLine), pSrecLine); RecordCounter++; DispHex(RecordCounter); if ((count*2) != strlen(pSrecLine)) return(SRLerrorout("Count field larger than record",scp)); if (!checksum(pSrecLine, count)) return(SRLerrorout("Bad Checksum",scp)); switch(ch) { case '0': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2; if (itmp) return(SRLerrorout("Srecord 1 address not zero",scp)); break; case '1': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); return(SRLerrorout("Srecord Not valid for MIPS",scp)); break; case '2': if (count<4) return(SRLerrorout("Invalid Srecord count field",scp)); return(SRLerrorout("Srecord Not valid for MIPS",scp)); break; case '3': if (count<5) return(SRLerrorout("Invalid Srecord count field",scp)); adr=gh(pSrecLine,8); pSrecLine+=8; count-=4; count--; while(count) { dat=gh(pSrecLine,2); pSrecLine+=2; count--; binRecOutByte(adr, (char) (dat & 0xFF)); adr++; } s1s2s3_total++; break; case '4': return(SRLerrorout("Invalid Srecord type",scp)); break; case '5': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2; if (itmp|=s1s2s3_total) return(SRLerrorout("Incorrect number of S3 Record processed",scp)); break; case '6': return(SRLerrorout("Invalid Srecord type",scp)); break; case '7': // PROGRAM START if (count<5) return(SRLerrorout("Invalid Srecord count field",scp)); adr=gh(pSrecLine,8); pSrecLine+=8; count-=4; if (count!=1) return(SRLerrorout("Invalid Srecord count field",scp)); binRecOutProgramStart(adr); break; case '8': if (count<4) return(SRLerrorout("Invalid Srecord count field",scp)); return(SRLerrorout("Srecord Not valid for MIPS",scp)); break; case '9': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); return(SRLerrorout("Srecord Not valid for MIPS",scp)); break; default: break; } return(TRUE); }
int main(int argc, char* argv[]) { GLogHelper gh(argv[0]); LOG(INFO)<<"INFO"; LOG(ERROR)<<"ERROR"; }
BOOL CwebdiscoverApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); GLogHelper gh("webdiscover"); AfxEnableControlContainer(); // Create the shell manager, in case the dialog contains // any shell tree view or shell list view controls. CShellManager *pShellManager = new CShellManager; // Activate "Windows Native" visual manager for enabling themes in MFC controls CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("Local AppWizard-Generated Applications")); CwebdiscoverDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n"); TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n"); } // Delete the shell manager created above. if (pShellManager != NULL) { delete pShellManager; } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
int main(int argc, char *argv[]) { # include "setRootCase.H" # include "createTime.H" //# include "createMesh.H" # include "createDynamicFvMesh.H" // Martin R. Du, Apr 11, 2011 # include "readGravitationalAcceleration.H" # include "readPISOControls.H" # include "initContinuityErrs.H" # include "createFields.H" # include "readTimeControls.H" # include "correctPhi.H" # include "CourantNo.H" # include "setInitialDeltaT.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; while (runTime.run()) { //# include "readPISOControls.H" //# include "readTimeControls.H" # include "readControls.H" # include "CourantNo.H" // Make the fluxes absolute fvc::makeAbsolute(phi, U); // Martin R. Du, Apr 11, 2011 # include "setDeltaT.H" runTime++; Info<< "Time = " << runTime.timeName() << nl << endl; scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime(); // Martin R. Du, Apr 11, 2011 // Martin R. Du, Apr 11, 2011 //////////////////////////////////////////////////////////////////////////////// // Do any mesh changes mesh.update(); if (mesh.changing()) { Info<< "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << endl; } volScalarField gh("gh", g & mesh.C()); surfaceScalarField ghf("ghf", g & mesh.Cf()); if (mesh.changing() && correctPhi) { # include "correctPhi.H" } //# include "fEqn.H" // Make the fluxes relative to the mesh motion fvc::makeRelative(phi, U); if (mesh.changing() && checkMeshCourantNo) { # include "meshCourantNo.H" } //////////////////////////////////////////////////////////////////////////////// // --- Outer-corrector loop for (int oCorr=0; oCorr<nOuterCorr; oCorr++) { #include "alphaEqnSubCycle.H" solve(fvm::ddt(rho) + fvc::div(rhoPhi)); #include "UEqn.H" // --- PISO loop for (int corr=0; corr<nCorr; corr++) { #include "pEqn.H" } } // Correct stress visco.correct(); #include "continuityErrs.H" // p = pd + rho*gh; /* if (pd.needReference()) { p += dimensionedScalar ( "p", p.dimensions(), pRefValue - getRefCellValue(p, pdRefCell) ); } */ strainRate = alpha*Foam::sqrt(2.0)*mag ( symm(fvc::grad(U)) ) + (scalar(1) - alpha)*Foam::sqrt(2.0)*mag ( symm(fvc::grad(U)) ); runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return(0); }
int main(int argc, char *argv[]) { # include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" // Get times list instantList Times = runTime.times(); // set startTime and endTime depending on -time and -latestTime options # include "checkTimeOptions.H" runTime.setTime(Times[startTime], startTime); # include "createMesh.H" # include "readEnvironmentalProperties.H" #include "readThermoProperties.H" Info<< "Creating field g.h at cell centres\n" << endl; volScalarField gh("gh", g & mesh.C()); for (label i=startTime; i<endTime; i++) { runTime.setTime(Times[i], i); Info<< "\nTime = " << runTime.timeName() << endl; //# include "createMesh.H" mesh.readUpdate(); gh = g & mesh.C(); Info << "Reading Exner function" << endl; volScalarField Exner ( IOobject("Exner", runTime.timeName(),mesh,IOobject::MUST_READ), mesh ); Info << "Reading theta" << endl; volScalarField theta ( IOobject("theta", runTime.timeName(),mesh,IOobject::MUST_READ), mesh ); Info << "Calculating pressure, p" << flush; volScalarField p("p", pRef*pow(Exner, 1./kappa)); Info << " goes from " << min(p).value() << " to " << max(p).value() << endl; p.write(); Info << "Calculating temperature, T" << flush; volScalarField T("T", theta*Exner); Info << " goes from " << min(T).value() << " to " << max(T).value() << endl; T.write(); Info << "Calculating density, rho" << flush; volScalarField rho("rho", p/(R*T)); Info << " goes from " << min(rho).value() << " to " << max(rho).value() << endl; rho.write(); Info << "Calculating Brunt Vaiasalla frequency" << flush; volScalarField BruntFreq ( IOobject("BruntFreq", runTime.timeName(), mesh), Foam::sqrt(-(g & fvc::grad(theta))/theta) ); Info << " goes from " << min(BruntFreq).value() << " to " << max(BruntFreq).value() << endl; BruntFreq.write(); } Info << endl; return(0); }
/** process, all real work is done here. */ void process (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, void *ivoid, void *ovoid, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { // this is called for preview and full pipe separately, each with its own pixelpipe piece. // get our data struct: dt_iop_nlmeans_params_t *d = (dt_iop_nlmeans_params_t *)piece->data; // adjust to zoom size: const int P = ceilf(3 * roi_in->scale / piece->iscale); // pixel filter size const int K = ceilf(7 * roi_in->scale / piece->iscale); // nbhood if(P <= 1) { // nothing to do from this distance: memcpy (ovoid, ivoid, sizeof(float)*4*roi_out->width*roi_out->height); return; } // adjust to Lab, make L more important // float max_L = 100.0f, max_C = 256.0f; // float nL = 1.0f/(d->luma*max_L), nC = 1.0f/(d->chroma*max_C); float max_L = 120.0f, max_C = 512.0f; float nL = 1.0f/max_L, nC = 1.0f/max_C; const float norm2[4] = { nL*nL, nC*nC, nC*nC, 1.0f }; float *Sa = dt_alloc_align(64, sizeof(float)*roi_out->width*dt_get_num_threads()); // we want to sum up weights in col[3], so need to init to 0: memset(ovoid, 0x0, sizeof(float)*roi_out->width*roi_out->height*4); // for each shift vector for(int kj=-K;kj<=K;kj++) { for(int ki=-K;ki<=K;ki++) { int inited_slide = 0; // don't construct summed area tables but use sliding window! (applies to cpu version res < 1k only, or else we will add up errors) // do this in parallel with a little threading overhead. could parallelize the outer loops with a bit more memory #ifdef _OPENMP # pragma omp parallel for schedule(static) default(none) firstprivate(inited_slide) shared(kj, ki, roi_out, roi_in, ivoid, ovoid, Sa) #endif for(int j=0; j<roi_out->height; j++) { if(j+kj < 0 || j+kj >= roi_out->height) continue; float *S = Sa + dt_get_thread_num() * roi_out->width; const float *ins = ((float *)ivoid) + 4*(roi_in->width *(j+kj) + ki); float *out = ((float *)ovoid) + 4*roi_out->width*j; const int Pm = MIN(MIN(P, j+kj), j); const int PM = MIN(MIN(P, roi_out->height-1-j-kj), roi_out->height-1-j); // first line of every thread // TODO: also every once in a while to assert numerical precision! if(!inited_slide) { // sum up a line memset(S, 0x0, sizeof(float)*roi_out->width); for(int jj=-Pm;jj<=PM;jj++) { int i = MAX(0, -ki); float *s = S + i; const float *inp = ((float *)ivoid) + 4*i + 4* roi_in->width *(j+jj); const float *inps = ((float *)ivoid) + 4*i + 4*(roi_in->width *(j+jj+kj) + ki); const int last = roi_out->width + MIN(0, -ki); for(; i<last; i++, inp+=4, inps+=4, s++) { for(int k=0;k<3;k++) s[0] += (inp[k] - inps[k])*(inp[k] - inps[k]) * norm2[k]; } } // only reuse this if we had a full stripe if(Pm == P && PM == P) inited_slide = 1; } // sliding window for this line: float *s = S; float slide = 0.0f; // sum up the first -P..P for(int i=0;i<2*P+1;i++) slide += s[i]; for(int i=0; i<roi_out->width; i++) { if(i-P > 0 && i+P<roi_out->width) slide += s[P] - s[-P-1]; if(i+ki >= 0 && i+ki < roi_out->width) { const __m128 iv = { ins[0], ins[1], ins[2], 1.0f }; _mm_store_ps(out, _mm_load_ps(out) + iv * _mm_set1_ps(gh(slide))); } s ++; ins += 4; out += 4; } if(inited_slide && j+P+1+MAX(0,kj) < roi_out->height) { // sliding window in j direction: int i = MAX(0, -ki); float *s = S + i; const float *inp = ((float *)ivoid) + 4*i + 4* roi_in->width *(j+P+1); const float *inps = ((float *)ivoid) + 4*i + 4*(roi_in->width *(j+P+1+kj) + ki); const float *inm = ((float *)ivoid) + 4*i + 4* roi_in->width *(j-P); const float *inms = ((float *)ivoid) + 4*i + 4*(roi_in->width *(j-P+kj) + ki); const int last = roi_out->width + MIN(0, -ki); for(; ((unsigned long)s & 0xf) != 0 && i<last; i++, inp+=4, inps+=4, inm+=4, inms+=4, s++) { float stmp = s[0]; for(int k=0;k<3;k++) stmp += ((inp[k] - inps[k])*(inp[k] - inps[k]) - (inm[k] - inms[k])*(inm[k] - inms[k])) * norm2[k]; s[0] = stmp; } /* Process most of the line 4 pixels at a time */ for(; i<last-4; i+=4, inp+=16, inps+=16, inm+=16, inms+=16, s+=4) { __m128 sv = _mm_load_ps(s); const __m128 inp1 = _mm_load_ps(inp) - _mm_load_ps(inps); const __m128 inp2 = _mm_load_ps(inp+4) - _mm_load_ps(inps+4); const __m128 inp3 = _mm_load_ps(inp+8) - _mm_load_ps(inps+8); const __m128 inp4 = _mm_load_ps(inp+12) - _mm_load_ps(inps+12); const __m128 inp12lo = _mm_unpacklo_ps(inp1,inp2); const __m128 inp34lo = _mm_unpacklo_ps(inp3,inp4); const __m128 inp12hi = _mm_unpackhi_ps(inp1,inp2); const __m128 inp34hi = _mm_unpackhi_ps(inp3,inp4); const __m128 inpv0 = _mm_movelh_ps(inp12lo,inp34lo); sv += inpv0*inpv0 * _mm_set1_ps(norm2[0]); const __m128 inpv1 = _mm_movehl_ps(inp34lo,inp12lo); sv += inpv1*inpv1 * _mm_set1_ps(norm2[1]); const __m128 inpv2 = _mm_movelh_ps(inp12hi,inp34hi); sv += inpv2*inpv2 * _mm_set1_ps(norm2[2]); const __m128 inm1 = _mm_load_ps(inm) - _mm_load_ps(inms); const __m128 inm2 = _mm_load_ps(inm+4) - _mm_load_ps(inms+4); const __m128 inm3 = _mm_load_ps(inm+8) - _mm_load_ps(inms+8); const __m128 inm4 = _mm_load_ps(inm+12) - _mm_load_ps(inms+12); const __m128 inm12lo = _mm_unpacklo_ps(inm1,inm2); const __m128 inm34lo = _mm_unpacklo_ps(inm3,inm4); const __m128 inm12hi = _mm_unpackhi_ps(inm1,inm2); const __m128 inm34hi = _mm_unpackhi_ps(inm3,inm4); const __m128 inmv0 = _mm_movelh_ps(inm12lo,inm34lo); sv -= inmv0*inmv0 * _mm_set1_ps(norm2[0]); const __m128 inmv1 = _mm_movehl_ps(inm34lo,inm12lo); sv -= inmv1*inmv1 * _mm_set1_ps(norm2[1]); const __m128 inmv2 = _mm_movelh_ps(inm12hi,inm34hi); sv -= inmv2*inmv2 * _mm_set1_ps(norm2[2]); _mm_store_ps(s, sv); } for(; i<last; i++, inp+=4, inps+=4, inm+=4, inms+=4, s++) { float stmp = s[0]; for(int k=0;k<3;k++) stmp += ((inp[k] - inps[k])*(inp[k] - inps[k]) - (inm[k] - inms[k])*(inm[k] - inms[k])) * norm2[k]; s[0] = stmp; } } else inited_slide = 0; } } } // normalize and apply chroma/luma blending // bias a bit towards higher values for low input values: const __m128 weight = _mm_set_ps(1.0f, powf(d->chroma, 0.6), powf(d->chroma, 0.6), powf(d->luma, 0.6)); const __m128 invert = _mm_sub_ps(_mm_set1_ps(1.0f), weight); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) shared(ovoid,ivoid,roi_out,d) #endif for(int j=0; j<roi_out->height; j++) { float *out = ((float *)ovoid) + 4*roi_out->width*j; float *in = ((float *)ivoid) + 4*roi_out->width*j; for(int i=0; i<roi_out->width; i++) { _mm_store_ps(out, _mm_add_ps( _mm_mul_ps(_mm_load_ps(in), invert), _mm_mul_ps(_mm_load_ps(out), _mm_div_ps(weight, _mm_set1_ps(out[3]))))); out += 4; in += 4; } } // free shared tmp memory: free(Sa); }