void QScope::drawContents_box(QPainter *qp) { QGraph::drawContents(qp); if (guide_spacing) { // Let's draw zero line and guide lines qp->setPen(zero_pen); int yy = value2y(center); qp->drawLine(xoffset, yy, xoffset+wid-1, yy); qp->setPen(guide_pen); int gs = guide_spacing; for (raw_t y=gs; y<extent; y+=gs) { int yy = value2y(center + y); qp->drawLine(xoffset, yy, xoffset+wid-1, yy); yy = value2y(center-y); qp->drawLine(xoffset, yy, xoffset+wid-1, yy); } } if (!qss.sf) return; if (qss.endtime>0) { // let's draw trace. // I *assume* that there are more data points than pixels, but even if // this is not so, I think this should be OK. qp->setPen(trace_pen); qp->setBrush(trace_pen.color()); timeref_t starttime = (qss.endtime>qss.length)?(qss.endtime-qss.length):0; int tlength = qss.endtime-starttime; int twidth = wid * tlength/qss.length; int lastend; timeref_t time; if (controller || speedy!=AvgOnly) { // I am a satellite or not speedy // -- collect max line -- lastend = 0; time = starttime; int x_end = 2*twidth-1; raw_t maxv=(*qss.sf)[time][qss.channel]; for (int x=0; x<twidth; x++) { raw_t max=(*qss.sf)[time][qss.channel]; int nextend = (x+1)*tlength/twidth; // int n=nextend-lastend; for (; lastend<nextend; lastend++) maxIs(max, (*qss.sf)[time++][qss.channel]); qpa->setPoint(x_end-x, x+xoffset, value2y(max)); //if(qss.channel<126) qpa->setPoint(x_end-x, x+xoffset, value2y(max)); //else qpa->setPoint(x_end-x, x+xoffset, yoffset+(4095-max)*hei/4096); maxIs(maxv,max); } // -- collect min line -- lastend=0; time = starttime; raw_t minv=(*qss.sf)[time][qss.channel]; for (int x=0; x<twidth; x++) { raw_t min=(*qss.sf)[time][qss.channel]; int nextend = (x+1)*tlength/twidth; // int n=nextend-lastend; for (; lastend<nextend; lastend++) minIs(min, (*qss.sf)[time++][qss.channel]); qpa->setPoint(x, x+xoffset, value2y(min)); //if(qss.channel<126) qpa->setPoint(x, x+xoffset, value2y(min)); //else qpa->setPoint(x, x+xoffset, yoffset+(4095-min)*hei/4096); minIs(minv,min); } // -- draw it -- // db need to send qp for allgraphs also, use graphptrs offsets and apply to draw functions /*if (maxv-minv>4000) // do not plot rail-to-rail noisy channels qp->drawLine(xoffset, value2y(center), xoffset+wid, value2y(center)); else*/ if (speedy==MinMax) qp->drawPolyline(*qpa,0,x_end*2); else qp->drawPolygon(*qpa,true,0,x_end*2); } else { // I am a speedy small QMultiGraph member // -- draw average line -- lastend=0; time=starttime; for (int x=0; x<twidth; x++) { float sum=0; int nextend = (x+1)*tlength/twidth; int n=nextend-lastend; for (; lastend<nextend; lastend++) sum += (*qss.sf)[time++][qss.channel]; qpa->setPoint(x, x+xoffset, value2y(raw_t(sum/n))); //if(qss.channel<126) qpa->setPoint(x, x+xoffset, value2y(raw_t(sum/n))); //else qpa->setPoint(x, x+xoffset, yoffset+(4095-raw_t(sum/n))*hei/4096); } qp->drawPolyline(*qpa,0,twidth); } if (controller) { // draw more guide lines QFont f(qp->font()); f.setPointSize(14); qp->setFont(f); qp->setPen(guide_pen); int timelines[4] = { 2, 10, 50, 250 }; bool drawtl[4]; int tlmax=0; for (int n=0; n<4; n++) { drawtl[n] = twidth * timelines[n]*FREQKHZ / tlength > 10; if (timelines[n]*FREQKHZ < tlength) tlmax=n; } bool subtext = tlmax>0 && (twidth * timelines[tlmax-1]*FREQKHZ / tlength)>60; bool hundreds = tlmax>2; bool tens = tlmax>1; int uvlines[2] = { 10, 50 }; bool drawuv[2]; int uvmax=0; float uvpdig = uvpd(); for (int n=0; n<2; n++) { drawuv[n] = halfhei * (uvlines[n]/uvpdig) / extent > 10; if (uvlines[n]/uvpdig < extent) uvmax=n; } timeref_t t0 = qss.sf?qss.sf->first():0; timeref_t t = starttime - t0; t = timeref_t(t/(FREQKHZ*timelines[0])+.99999) * FREQKHZ*timelines[0]; timeref_t t1 = starttime-t0+tlength; while (t<t1) { // sdbx("Time: %.5f / starttime=%.5f t0=%.5f x=%i",t/25000.0,starttime/25000.0,t0/25000.0,time2x(t+t0)); for (int n=0; n<4; n++) { if (t % (FREQKHZ*timelines[n]) == 0) { if (drawtl[n]) { int x = time2x(t+t0); qp->drawLine(x,0,x,10*(n+1)); qp->drawLine(x,hei,x,hei-10*(n+1)); if (n==tlmax) { qp->setPen(black_pen); char buf[100]; sprintf(buf,"%.3f",t/(1000.0*FREQKHZ)); qp->drawText(x-40,hei-70,80,35, Qt::AlignHCenter|Qt::AlignBottom,buf); qp->setPen(guide_pen); } else if (subtext && n==tlmax-1 && t % (FREQKHZ*timelines[n+1]) != 0) { char buf[100]; if (hundreds) sprintf(buf,"%03i",int(t/FREQKHZ)%1000); else if (tens) sprintf(buf,"%02i",int(t/FREQKHZ)%100); else sprintf(buf,"%01i",int(t/FREQKHZ)%10); qp->drawText(x-40,hei-70,80,35, Qt::AlignHCenter|Qt::AlignBottom,buf); } } } else { break; } } t+=FREQKHZ*timelines[0]; } for (int uv=0; uv<uvpdig*extent; uv+=uvlines[0]) { for (int n=0; n<2; n++) { if (uv%uvlines[n] == 0 && drawuv[n]) { int y=coffset - int(uv/uvpdig * halfhei/extent); qp->drawLine(0,y,10*(n+1),y); qp->drawLine(wid,y,wid-10*(n+1),y); if (n==uvmax) { char buf[100]; sprintf(buf,"%i",uv); qp->setPen(black_pen); qp->drawText(wid-110,y-50,80,100, Qt::AlignVCenter|Qt::AlignRight,buf); qp->setPen(guide_pen); } if (uv) { y=coffset + int(uv/uvpdig * halfhei/extent); qp->drawLine(0,y,10*(n+1),y); qp->drawLine(wid,y,wid-10*(n+1),y); if (n==uvmax) { char buf[100]; sprintf(buf,"%i",-uv); qp->setPen(black_pen); qp->drawText(wid-110,y-50,80,100, Qt::AlignVCenter|Qt::AlignRight,buf); qp->setPen(guide_pen); } } } } } } } qp->setPen(aux_pen); qp->setBrush(aux_pen.color()); timeref_t t0 = qss.sf->first(); for (unsigned int i=0; i<nspikes; i++) { Spikeinfo const &si = spikes[i]; int x = time2x(si.time+t0); qp->drawEllipse(x-2, coffset+(si.height>0?-1:1)*halfhei*7/8-2,4,4); } }
void QScope::drawContents_together(QPainter *qp) { ////copied from void QScope::drawContents(QPainter *qp) { QGraph::drawContents(qp); for( int hw=0; hw<TOTALCHANS; hw++){ if (!qss.sf) return; if (qss.endtime>0) { // let's draw trace. /* I *assume* that there are more data points than pixels, but even if this is not so, I think this should be OK. */ qp->setPen(trace_pen); qp->setBrush(trace_pen.color()); timeref_t starttime = (qss.endtime>qss.length)?(qss.endtime-qss.length):0; int tlength = qss.endtime-starttime; //int twidth = wid * tlength/qss.length; int twidth = wid * tlength/qss.length; int lastend; timeref_t time; if (controller || speedy!=AvgOnly) { // I am a satellite or not speedy // -- collect max line -- lastend = 0; time = starttime; int x_end = 2*twidth-1; raw_t maxv=(*qss.sf)[time][hw]; for (int x=0; x<twidth; x++) { raw_t max=(*qss.sf)[time][hw]; int nextend = (x+1)*tlength/twidth; // int n=nextend-lastend; for (; lastend<nextend; lastend++) maxIs(max, (*qss.sf)[time++][hw]); qpa->setPoint(x_end-x, x+xoffset, (4096-max+50)*hei/(4096+100)); //qpa->setPoint(x, x+xoffset, (max+5)*hei/(256+10)); maxIs(maxv,max); } // -- collect min line -- lastend=0; time = starttime; raw_t minv=(*qss.sf)[time][hw]; for (int x=0; x<twidth; x++) { raw_t min=(*qss.sf)[time][hw]; int nextend = (x+1)*tlength/twidth; // int n=nextend-lastend; for (; lastend<nextend; lastend++) minIs(min, (*qss.sf)[time++][hw]); qpa->setPoint(x, x+xoffset, (4096-min+50)*hei/(4096+100)); //qpa->setPoint(x, x+xoffset, (min+5)*hei/(256+10)); minIs(minv,min); } //if(!hw) fprintf(stderr,"twidth:%i tlenth:%i qss.lenth:%i x_end:%i value:%i\n",twidth,tlength,qss.length,x_end,minv); // -- draw it -- // db need to send qp for allgraphs also, use graphptrs offsets and apply to draw functions //fprintf(stderr,"%i ",maxv-minv); if (x0s[hw]<100){} // do not plot channels that are not connected else if (speedy==MinMax) qp->drawPolyline(*qpa,0,x_end); else qp->drawPolygon(*qpa,true,0,x_end); } else { // I am a speedy small QMultiGraph member // -- draw average line -- lastend=0; time=starttime; for (int x=0; x<twidth; x++) { float sum=0; int nextend = (x+1)*tlength/twidth; int n=nextend-lastend; for (; lastend<nextend; lastend++) sum += (*qss.sf)[time++][hw]; qpa->setPoint(x, x+xoffset, (4096-raw_t(sum/n)+50)*hei/(4096+100)); //qpa->setPoint(x, x+xoffset, (raw_t(sum/n)+5)*hei/(256+10)); //qpa->setPoint(x, x+xoffset+x0, 0); } qp->drawPolyline(*qpa,0,twidth); } } }// end for hw ... }
void QScope::drawContents_all(QPainter *qp) { ////copied from void QScope::drawContents(QPainter *qp) { //QGraph::drawContents(qp); for( int hw=0; hw<TOTALCHANS; hw++){ // update channel config using center button in scope // cmos int multipl = 150; int x0 = int(wid/2200.*x0s[hw]); // update for this trace int y0 = int(hei/2200.*y0s[hw]); // update for this trace -- yoffset is defined as r.top, so this may not be right depending on qt directions of x and y int x1 = int(wid*multipl/2200.); int y1 = int(hei*multipl/2200.); //if(!hw) fprintf(stderr,"x %i %i y %i %i wid:%i hei:%i halfhei:%i coffset:%i extent:%i center:%i xoffset:%i yoffset:%i\n",x0,x1,y0,y1,wid,hei,halfhei,coffset,extent,centers[hw],xoffset,yoffset); center=centers[hw]; // update for this trace if (!qss.sf) return; if (qss.endtime>0) { // let's draw trace. /* I *assume* that there are more data points than pixels, but even if this is not so, I think this should be OK. */ qp->setPen(trace_pen); qp->setBrush(trace_pen.color()); timeref_t starttime = (qss.endtime>qss.length)?(qss.endtime-qss.length):0; int tlength = qss.endtime-starttime; //int twidth = wid * tlength/qss.length; int twidth = x1 * tlength/qss.length; int lastend; timeref_t time; if (controller || speedy!=AvgOnly) { // I am a satellite or not speedy // -- collect max line -- lastend = 0; time = starttime; int x_end = 2*twidth-1; raw_t maxv=(*qss.sf)[time][hw]; for (int x=0; x<twidth; x++) { raw_t max=(*qss.sf)[time][hw]; int nextend = (x+1)*tlength/twidth; // int n=nextend-lastend; for (; lastend<nextend; lastend++) maxIs(max, (*qss.sf)[time++][hw]); qpa->setPoint(x_end-x, x+xoffset+x0, value2y(max)/(hei/y1)+y0); maxIs(maxv,max); } // -- collect min line -- lastend=0; time = starttime; raw_t minv=(*qss.sf)[time][hw]; for (int x=0; x<twidth; x++) { raw_t min=(*qss.sf)[time][hw]; int nextend = (x+1)*tlength/twidth; // int n=nextend-lastend; for (; lastend<nextend; lastend++) minIs(min, (*qss.sf)[time++][hw]); qpa->setPoint(x, x+xoffset+x0, value2y(min)/(hei/y1)+y0); minIs(minv,min); } //if(!hw) fprintf(stderr,"twidth:%i tlenth:%i qss.lenth:%i x_end:%i value:%i\n",twidth,tlength,qss.length,x_end,minv); // -- draw it -- // db need to send qp for allgraphs also, use graphptrs offsets and apply to draw functions //fprintf(stderr,"%i ",maxv-minv); if (x0s[hw]<100 && hw<NCHANS){} // do not plot channels that are not connected else if (maxv-minv>4000) // do not plot rail-to-rail noisy channels qp->drawLine(xoffset+x0, value2y(center)/(hei/y1)+y0, xoffset+x0+x1-1, value2y(center)/(hei/y1)+y0); else if (speedy==MinMax) qp->drawPolyline(*qpa,0,x_end); else qp->drawPolygon(*qpa,true,0,x_end); } else { // I am a speedy small QMultiGraph member // -- draw average line -- lastend=0; time=starttime; for (int x=0; x<twidth; x++) { float sum=0; int nextend = (x+1)*tlength/twidth; int n=nextend-lastend; for (; lastend<nextend; lastend++) sum += (*qss.sf)[time++][hw]; qpa->setPoint(x, x+xoffset+x0, value2y(raw_t(sum/n))/(hei/y1)+y0); //qpa->setPoint(x, x+xoffset+x0, 0); } qp->drawPolyline(*qpa,0,twidth); } } //QGraph::drawContents(qp); if(wid>200){ qp->setClipRect(contentsRect()); QFont f(qp->font()); f.setPointSize(8); qp->setFont(f); qp->setPen(black_pen); QString shortname; if( hw<NCHANS ) shortname = Sprintf("%i",hw); else shortname = Sprintf("DAC%i",hw-NCHANS+1); qp->drawText(x0-15,value2y(center)/(hei/y1)+y0,shortname); } }// end for hw ... /* qp->setPen(aux_pen); qp->setBrush(aux_pen.color()); /////////////////////////////////// timeref_t t0 = qss.sf->first(); for (unsigned int i=0; i<nspikes; i++) { Spikeinfo const &si = spikes[i]; int x = time2x(si.time+t0); qp->drawEllipse(x-2, coffset+(si.height>0?-1:1)*halfhei*7/8-2,4,4); }*/ }
void Foam::fieldMinMax::calcMinMaxFields ( const word& fieldName, const modeType& mode ) { typedef GeometricField<Type, fvPatchField, volMesh> fieldType; if (obr_.foundObject<fieldType>(fieldName)) { const label procI = Pstream::myProcNo(); const fieldType& field = obr_.lookupObject<fieldType>(fieldName); const fvMesh& mesh = field.mesh(); const volVectorField::GeometricBoundaryField& CfBoundary = mesh.C().boundaryField(); switch (mode) { case mdMag: { const volScalarField magField(mag(field)); const volScalarField::GeometricBoundaryField& magFieldBoundary = magField.boundaryField(); scalarList minVs(Pstream::nProcs()); List<vector> minCs(Pstream::nProcs()); label minProcI = findMin(magField); minVs[procI] = magField[minProcI]; minCs[procI] = field.mesh().C()[minProcI]; labelList maxIs(Pstream::nProcs()); scalarList maxVs(Pstream::nProcs()); List<vector> maxCs(Pstream::nProcs()); label maxProcI = findMax(magField); maxVs[procI] = magField[maxProcI]; maxCs[procI] = field.mesh().C()[maxProcI]; forAll(magFieldBoundary, patchI) { const scalarField& mfp = magFieldBoundary[patchI]; if (mfp.size()) { const vectorField& Cfp = CfBoundary[patchI]; label minPI = findMin(mfp); if (mfp[minPI] < minVs[procI]) { minVs[procI] = mfp[minPI]; minCs[procI] = Cfp[minPI]; } label maxPI = findMax(mfp); if (mfp[maxPI] > maxVs[procI]) { maxVs[procI] = mfp[maxPI]; maxCs[procI] = Cfp[maxPI]; } } } Pstream::gatherList(minVs); Pstream::gatherList(minCs); Pstream::gatherList(maxVs); Pstream::gatherList(maxCs); if (Pstream::master()) { label minI = findMin(minVs); scalar minValue = minVs[minI]; const vector& minC = minCs[minI]; label maxI = findMax(maxVs); scalar maxValue = maxVs[maxI]; const vector& maxC = maxCs[maxI]; output ( fieldName, word("mag(" + fieldName + ")"), minC, maxC, minI, maxI, minValue, maxValue ); } break; } case mdCmpt: { const typename fieldType::GeometricBoundaryField& fieldBoundary = field.boundaryField(); List<Type> minVs(Pstream::nProcs()); List<vector> minCs(Pstream::nProcs()); label minProcI = findMin(field); minVs[procI] = field[minProcI]; minCs[procI] = field.mesh().C()[minProcI]; Pstream::gatherList(minVs); Pstream::gatherList(minCs); List<Type> maxVs(Pstream::nProcs()); List<vector> maxCs(Pstream::nProcs()); label maxProcI = findMax(field); maxVs[procI] = field[maxProcI]; maxCs[procI] = field.mesh().C()[maxProcI]; forAll(fieldBoundary, patchI) { const Field<Type>& fp = fieldBoundary[patchI]; if (fp.size()) { const vectorField& Cfp = CfBoundary[patchI]; label minPI = findMin(fp); if (fp[minPI] < minVs[procI]) { minVs[procI] = fp[minPI]; minCs[procI] = Cfp[minPI]; } label maxPI = findMax(fp); if (fp[maxPI] > maxVs[procI]) { maxVs[procI] = fp[maxPI]; maxCs[procI] = Cfp[maxPI]; } } } Pstream::gatherList(minVs); Pstream::gatherList(minCs); Pstream::gatherList(maxVs); Pstream::gatherList(maxCs); if (Pstream::master()) { label minI = findMin(minVs); Type minValue = minVs[minI]; const vector& minC = minCs[minI]; label maxI = findMax(maxVs); Type maxValue = maxVs[maxI]; const vector& maxC = maxCs[maxI]; output ( fieldName, fieldName, minC, maxC, minI, maxI, minValue, maxValue ); } break; } default: { FatalErrorInFunction << "Unknown min/max mode: " << modeTypeNames_[mode_] << exit(FatalError); } } } }