void LLFloaterOutbox::updateFolderCountStatus() { if (mOutboxInventoryPanel) { switch (mOutboxItemCount) { case 0: setStatusString(getString("OutboxFolderCount0")); break; case 1: setStatusString(getString("OutboxFolderCount1")); break; default: { std::string item_count_str = llformat("%d", mOutboxItemCount); LLStringUtil::format_map_t args; args["[NUM]"] = item_count_str; setStatusString(getString("OutboxFolderCountN", args)); break; } } } mImportButton->setEnabled(mOutboxItemCount > 0); }
void LLFloaterOutbox::importStatusChanged(bool inProgress) { if (mOutboxId.isNull() && (LLMarketplaceInventoryImporter::getInstance()->getMarketPlaceStatus() == MarketplaceStatusCodes::MARKET_PLACE_MERCHANT)) { setupOutbox(); } if (inProgress) { if (mImportBusy) { setStatusString(getString("OutboxImporting")); } else { setStatusString(getString("OutboxInitializing")); } mImportBusy = true; mImportButton->setEnabled(false); mInventoryImportInProgress->setVisible(true); } else { setStatusString(""); mImportBusy = false; mImportButton->setEnabled(mOutboxItemCount > 0); mInventoryImportInProgress->setVisible(false); } updateView(); }
bool SOFM2D::calcSize(const dmatrix& data) { bool b=true; varianceFunctor<double> varFunc; dmatrix cov; varFunc.covarianceMatrixOfRows(data, cov); jacobi<double> eigenFunc; jacobi<double>::parameters jp; jp.sort=true; eigenFunc.setParameters(jp); dvector eva; dmatrix eve; b = eigenFunc.apply(cov, eva, eve); if (b) { eva1=eva.at(0); eva2=eva.at(1); eve1=eve.getColumnCopy(0); eve2=eve.getColumnCopy(1); } else { setStatusString("could not find eigenvalues\n"); b = false; eva1=1; eva2=1; } int area=getParameters().area; if (area<=0) { setStatusString("negative or zero area\n"); return false; } double c=sqrt(double(area)/(eva1*eva2)); int x1=int(eva1*c); int x2=int(ceil(eva1*c)); int y1=int(eva2*c); int y2=int(ceil(eva2*c)); sizeX=x1; if (abs(area-x1*y1)<abs(area-x1*y2)) { sizeY=y1; } else { sizeY=y2; } if (abs(area-x2*y1)<abs(area-sizeX*sizeY)) { sizeX=x2; sizeY=y1; } if (abs(area-x2*y2)<abs(area-sizeX*sizeY)) { sizeX=x2; sizeY=y2; } return b; }
bool brightRGB::getMax(const image& img,dvector& dest) const{ // image empty? if (img.empty()) { setStatusString("image empty"); dest.resize(0); return false; } const rgbPixel transColor = getParameters().transColor; ivector maxV(3,-1); image::const_iterator it = img.begin(); if(getParameters().transparent) { while(it != img.end()) { if(*it != transColor) { if((*it).getRed() > maxV.at(0)) maxV.at(0) = (*it).getRed(); if((*it).getGreen() > maxV.at(1)) maxV.at(1) = (*it).getGreen(); if((*it).getBlue() > maxV.at(2)) maxV.at(2) = (*it).getBlue(); } it++; } // only transparent pixels? if (maxV.at(0)==-1) { setStatusString("only transparent pixels"); dest.resize(0); return false; } } else { // no transparent color while(it != img.end()) { if((*it).getRed() > maxV.at(0)) maxV.at(0) = (*it).getRed(); if((*it).getGreen() > maxV.at(1)) maxV.at(1) = (*it).getGreen(); if((*it).getBlue() > maxV.at(2)) maxV.at(2) = (*it).getBlue(); it++; } } if(maxV.at(0) == -1) return false; dest.castFrom(maxV); // normalize to 0..1 dest.divide(255); return true; };
/* * compute the second and up iterations of a probability map * using the given aPriori probabilites per pixel. */ bool probabilityMap2D::computeMap(const channel8& src1, const channel8& src2, channel& aPrioriDest) const { point chnl1_size = src1.size(); point chnl2_size = src2.size(); // size of src1 equals src2 ? if ( (chnl1_size.x != chnl2_size.x) || (chnl1_size.y != chnl2_size.y) ) { setStatusString("probabilityMap2D: channels do not match"); return false; } else { int y; vector<channel8::value_type>::const_iterator srcIterator1, eit1; vector<channel8::value_type>::const_iterator srcIterator2, eit2; vector<channel::value_type>::iterator destIterator; const parameters& param = getParameters(); const thistogram<double>& objModel = param.getObjectColorModel(); const thistogram<double>& nonObjModel = param.getNonObjectColorModel(); float relObjProb; float relNonObjProb; ivector theBin(2); for (y=0;y<src1.rows();++y) { srcIterator1 = src1.getRow(y).begin(); eit1 = src1.getRow(y).end(); srcIterator2 = src2.getRow(y).begin(); eit2 = src2.getRow(y).end(); destIterator = aPrioriDest.getRow(y).begin(); while (srcIterator1 != eit1) { theBin[0] = lookupTable[0][*srcIterator1]; theBin[1] = lookupTable[1][*srcIterator2]; relObjProb = static_cast<float>(objModel.getProbability(theBin) * (*destIterator)); relNonObjProb = static_cast<float>(nonObjModel.getProbability(theBin)* (1.0f-(*destIterator))); // assume non-object if no entries are given if ((relObjProb == 0.0f) && (relNonObjProb == 0.0f)) { (*destIterator) = 0.0f; } else { // bayes (*destIterator) = relObjProb / (relObjProb + relNonObjProb); } srcIterator1++; srcIterator2++; destIterator++; } } } return true; }
void TransferApi::starting(const Download* aDownload, const string& aStatus, bool aFullUpdate) noexcept { auto t = getTransfer(aDownload->getToken()); if (!t) { return; } t->setStatusString(aStatus); if (aFullUpdate) { starting(t, aDownload); } else { // All flags weren't known when requesting OrderedStringSet flags; aDownload->appendFlags(flags); t->setFlags(flags); // Size was unknown for filelists when requesting t->setSize(aDownload->getSegmentSize()); view.onItemUpdated(t, { TransferUtils::PROP_STATUS, TransferUtils::PROP_FLAGS, TransferUtils::PROP_SIZE }); } }
//--------------------------------------------------------------------------- // receives only one character bool Serial::receive( char & c ) { if ( !isPortOpened_ ) { if ( !openPort() ) { // some error occured by opening port return false; } } int numberOfBytes; numberOfBytes =::read( descriptor_, & c, 1 ); if ( numberOfBytes == 1 ) { return true; } else { setStatusString( "error: could not receive the character" ); return false; } }
/** * Saves the given matrix to the given stream. The header is modified * with appropriate data derived from the matrix structure. */ bool saveMatrix(const std::string& filename, const matrix<T>& theChannel, header& theHeader, const eCompressionType compr, dataCodec* codec) { //open stream std::ofstream out; out.open(filename.c_str(),std::ios::out|std::ios::binary); //stream ok? if (!(out.good() && out.is_open())) { std::string str = "Could not open file " + filename + " for writing."; setStatusString(str.c_str()); out.close(); return false; } theHeader.encoding.contents=getTypeCode(T()); theHeader.encoding.compression=compr; int tmpsize=sizeof(T)*theChannel.rows()*theChannel.columns(); int encsize = codec->estimateEncodedSize(tmpsize); // create the temporary buffer dataCodec::buffer tmp(encsize); // encode the data codec->encode((const ubyte*)&theChannel.at(0,0),tmpsize,&tmp.at(0),encsize); theHeader.size = encsize; theHeader.rows = theChannel.rows(); theHeader.columns = theChannel.columns(); // write the header if (!theHeader.write(out)) { setStatusString("Could not write header."); out.close(); return false; } // write the data out.write((const char*)(&tmp.at(0)),theHeader.size); out.close(); return true; }
/* * read the functor parameters */ bool functor::write(ioHandler& handler, const bool complete) const { if (params != 0) { return params->write(handler,complete); } else { setStatusString("Tried to write <null> parameters object"); return false; } }
/* * read the functor parameters */ bool functor::read(ioHandler& handler, const bool complete) { if (params != 0) { return params->read(handler,complete); } else { setStatusString("Tried to read <null> parameters object"); return false; } }
// merge float channels bool mergeOCPToImage::apply(const matrix<float>& c1, const matrix<float>& c2, const matrix<float>& c3, image& img) const { point p; // coordinates float r,g,b; // unnormed RGB channels float RG, BY, WB; // opponent colour channels if ((c1.size() != c2.size()) || (c1.size() != c3.size())) { setStatusString("sizes of channels do not match"); return false; } img.resize(c1.size(),rgbPixel(),false,false); for (p.y=0;p.y<img.rows();p.y++) { for (p.x=0;p.x<img.columns();p.x++) { RG = c1.at(p); BY = c2.at(p); WB = c3.at(p); b = BY*0.666666666667f; // r = WB + RG - b; g = WB - RG - b; b = WB + BY*1.3333333333333f; // truncate r,g and b if the value is not in intervall [0..1] // can happen due to rounding errors in split operation if (r<0.0f) { r=0.0f; } else if (r>1.0f) { r=1.0f; } if (g<0.0f) { g=0.0f; } else if (g>1.0f) { g=1.0f; } if (b<0.0f) { b=0.0f; } else if (b>1.0f) { b=1.0f; } img.at(p).set(static_cast<ubyte>(255.0f*r), static_cast<ubyte>(255.0f*g), static_cast<ubyte>(255.0f*b), 0); } } return true; };
//--------------------------------------------------------------------------- // close the port void Serial::closePort() { if ( close( descriptor_ ) == -1 ) { setStatusString( "error: the port could not be closed" ); } descriptor_ = -1; isPortOpened_ = false; }
/* * sets the classifier's parameters. * The functor keeps its own copy of the given parameters. */ bool fuzzyCMeans::setParameters(const classifier::parameters& theParams) { bool ok=classifier::setParameters(theParams); if (getParameters().norm!=parameters::L1 || getParameters().norm!=parameters::L2) { ok=false; setStatusString("no valid norm selected; selected L2-norm instead"); } return ok; }
bool loadLTI::load(const std::string& filename, matrix<ubyte>& data) { ioLTIworker<matrix<ubyte>::value_type> worker; if (worker.loadMatrix(filename, data, theHeader)) { return true; } else { setStatusString(worker.getStatusString()); return false; } }
bool SOFM2D::initGrid(const dmatrix& data) { bool b=true; int i,j; const parameters& param=getParameters(); if (param.initType == parameters::Linear) { //eigenvalues already calculated? if (eva1==0.) { varianceFunctor<double> varFunc; dmatrix cov; varFunc.covarianceMatrixOfRows(data, cov); jacobi<double> eigenFunc; jacobi<double>::parameters jp; jp.sort=true; eigenFunc.setParameters(jp); dvector eva; dmatrix eve; b = eigenFunc.apply(cov, eva, eve); if (b) { eva1=eva.at(0); eva2=eva.at(1); eve1=eve.getColumnCopy(0); eve2=eve.getColumnCopy(1); } else { setStatusString("could not find eigenvalues using random points\n"); selectRandomPoints(data, sizeX*sizeY, grid); return false; } } meansFunctor<double> meanFunc; dvector mean; meanFunc.meanOfRows(data, mean); double x,y; dvector deltaX(eve1); deltaX.multiply(eva1/sizeX); dvector deltaY(eve2); deltaY.multiply(eva2/sizeY); dvector delta; for (i=0, y=-(double(sizeY-1)); i<sizeY; i++, y++) { for (j=0, x=-(double(sizeX-1)); j<sizeX; j++, x++) { delta.addScaled(x,deltaX,y,deltaY); grid.getRow(i*sizeX+j).add(mean,delta); } } } else { selectRandomPoints(data, sizeX*sizeY, grid); } return b; }
bool brightRGB::getAverage(const image& img,dvector& dest) const{ const rgbPixel transColor = getParameters().transColor; dvector avg(3,0.0); image::const_iterator it = img.begin(); // check for empty image if (img.columns()==0 || img.rows()==0) { setStatusString("image empty"); dest.resize(0); return false; } if(getParameters().transparent) { int counter = 0; while(it != img.end()) { if(*it != transColor) { avg.at(0) += (*it).getRed(); avg.at(1) += (*it).getGreen(); avg.at(2) += (*it).getBlue(); ++counter; } it++; } // check for completely transparent image if (counter==0) { setStatusString("only transparent pixels"); dest.resize(0); return false; } avg.divide(counter); } else { // no transparent color while(it != img.end()) { avg.at(0) += (*it).getRed(); avg.at(1) += (*it).getGreen(); avg.at(2) += (*it).getBlue(); it++; } avg.divide(img.columns()*img.rows()); } // values between 0 and 1 dest.divide(avg, 255.); return true; };
TransferInfoPtr TransferApi::addTransfer(const ConnectionQueueItem* aCqi, const string& aStatus) noexcept { auto t = std::make_shared<TransferInfo>(aCqi->getUser(), aCqi->getConnType() == ConnectionType::CONNECTION_TYPE_DOWNLOAD, aCqi->getToken()); { WLock l(cs); transfers[aCqi->getToken()] = t; } t->setStatusString(aStatus); return t; }
// On copy apply for type channel! bool huMoments::apply(const channel& src, const rectangle& rect, dvector& dest) const { try { channel tmp(false,*const_cast<channel*>(&src),rect.ul.y,rect.br.y,rect.ul.x,rect.br.x); return apply(tmp,dest); } catch (exception e) { setStatusString("Failed to create submatrix of input channel8!"); return false; } }
bool saveLTI::save(const std::string& filename, const matrix<ubyte>& data) { ioLTIworker<matrix<ubyte>::value_type> worker; if (worker.saveMatrix(filename, data, theHeader, getParameters().compression,codec)) { return true; } else { setStatusString(worker.getStatusString()); return false; } }
void TransferApi::onTick(const Transfer* aTransfer, bool aIsDownload) noexcept { auto t = getTransfer(aTransfer->getToken()); if (!t) { return; } t->setSpeed(aTransfer->getAverageSpeed()); t->setBytesTransferred(aTransfer->getPos()); t->setTimeLeft(aTransfer->getSecondsLeft()); uint64_t timeSinceStarted = GET_TICK() - t->getStarted(); if (timeSinceStarted < 1000) { t->setStatusString("Starting..."); } else { t->setStatusString(STRING_F(RUNNING_PCT, t->getPercentage())); } view.onItemUpdated(t, { TransferUtils::PROP_STATUS, TransferUtils::PROP_BYTES_TRANSFERRED, TransferUtils::PROP_SPEED, TransferUtils::PROP_SECONDS_LEFT }); }
// checkfile bool loadLTI::checkHeader(const std::string& filename, point& imageSize, char& imageType, eCompressionType& compr) { std::ifstream in; in.open(filename.c_str(),std::ios::in|std::ios::binary); if (in.good() && in.is_open()) { if (!theHeader.read(in)) { setStatusString("Wrong header. Is this an LTI file?"); return false; } imageSize.set(theHeader.columns,theHeader.rows); imageType = static_cast<char>(theHeader.encoding.contents); compr = eCompressionType(theHeader.encoding.compression); return true; } std::string str = "Could not open file " + filename; setStatusString(str.c_str()); return false; }
bool cwagmSegmentationEvaluation::segment(const image& img, const imatrix& prevMask, imatrix& mask, channel& certainty) { ivector sizes; if (!segmenter.apply(img,mask,sizes)) { _lti_debug("Error in segmenter: " << segmenter.getStatusString() << std::endl); setStatusString(segmenter.getStatusString()); return false; } certainty.clear(); // no certainty computation in this kind of functors. return true; }
/* * compute cornerness */ bool harrisCorners::getCornerness(const channel& fxx, const channel& fxy, const channel& fyy, const float scale, channel& cornerness, float& maxCornerness) const { // we can assume that all channels are connected, but try it out if not if ((fxx.getMode() != channel::Connected) || (fxy.getMode() != channel::Connected) || (fyy.getMode() != channel::Connected)) { setStatusString("Channels not contigous in getCornerness"); return false; } if (fxx.empty() || fxy.empty() || fyy.empty()) { cornerness.clear(); maxCornerness = 0.0f; return false; } int i; const int end = fxx.rows()*fxx.columns(); const float *const pfxx = &fxx.at(0); const float *const pfxy = &fxy.at(0); const float *const pfyy = &fyy.at(0); cornerness.resize(fxx.size(),0,false,false); float* pcor = &cornerness.at(0); float det,trace,txx,txy,tyy,c; float maxc = 0.0f; for (i=0;i<end;++i) { txx=pfxx[i]; txy=pfxy[i]; tyy=pfyy[i]; det=txx*tyy - txy*txy; trace=txx+tyy; c = det-scale*trace*trace; pcor[i]=c; if (c>maxc) { maxc=c; } } maxCornerness = maxc; return true; }
// On copy apply for type channel! bool huMoments::apply(const channel& src, const rectangle& rect, dvector& dest, dvector& more) const { try { channel tmp(false,*const_cast<channel*>(&src),rect.ul.y,rect.br.y,rect.ul.x,rect.br.x); if (!apply(tmp,dest,more)) { return false; } more[xcog]+=rect.ul.x; more[ycog]+=rect.ul.y; } catch (exception e) { setStatusString("Failed to create submatrix of input channel8!"); return false; } return true; }
void TransferApi::onTransferCompleted(const Transfer* aTransfer, bool aIsDownload) noexcept { auto t = getTransfer(aTransfer->getToken()); if (!t) { return; } t->setStatusString("Finished, idle..."); t->setSpeed(-1); t->setTimeLeft(-1); t->setBytesTransferred(aTransfer->getSegmentSize()); t->setState(TransferInfo::STATE_FINISHED); view.onItemUpdated(t, { TransferUtils::PROP_STATUS, TransferUtils::PROP_SPEED, TransferUtils::PROP_SECONDS_LEFT, TransferUtils::PROP_TIME_STARTED, TransferUtils::PROP_BYTES_TRANSFERRED }); }
bool centroidClustering::classify(const dvector& feature, classifier::outputVector& result) const { dvector dists; l2Distance<double> distFunc; distFunc.apply(centroids, feature, dists); double s=dists.sumOfElements(); dists.divide(s); dists.apply(probabilize); s=dists.sumOfElements(); dists.divide(s); bool rc=outTemplate.apply(dists, result); if (!rc) { setStatusString("The outputTemplate used returned an error.\nMost likely your setting of parameters::multipleMode does not match the information available in the outputTemplate."); } return rc; }
// On copy apply for type matrix<int>! bool labelAdjacencyMap::adjacency(const matrix<int>& src, sparseMatrix<int>& dest) const { adjacencyHelper<int> helper; bool result(false); const parameters& par = getParameters(); if (par.neighborhood == 4) { result = helper.adjacency4(src,dest); } else { result = helper.adjacency8(src,dest); } if (!result) { setStatusString("Invalid labeled mask: negative labels"); return false; } return true; };
bool kNearestNeighFilter::apply(const imatrix& src,imatrix& dest) { if (src.empty()) { dest.clear(); return true; } const parameters& param = getParameters(); if (param.kernelSize <= 1) { dest.copy(src); return true; } sizeOfKernel = param.kernelSize + ((param.kernelSize%2 == 0) ? 1 : 0); histoSize = src.maximum()+1; bool control = false; // return variable // choose border behaviour switch(param.boundaryType) { case lti::Zero: control = histogramMethodZero(src,dest); break; case lti::Mirror: control = histogramMethodMirror(src,dest); break; case lti::Constant: control = histogramMethodConstant(src,dest); break; case lti::Periodic: control = histogramMethodPeriodic(src,dest); break; case lti::NoBoundary: control = histogramMethodNoBoundary(src,dest); break; default: setStatusString("Unknown boundary type"); break; } return control; };
//--------------------------------------------------------------------------- // sends only one character bool Serial::send( const char c ) { if ( !isPortOpened_ ) { if ( !openPort() ) { // some error occured by opening port return false; } } int numberOfBytes; numberOfBytes =::write( descriptor_, & c, 1 ); if ( numberOfBytes == 1 ) { return true; } else { setStatusString( "error: could not send a character" ); return false; } }
/* * shows an lti::mathObject * @param data the object to be shown. */ bool fastViewer::show(const image& img) { // Draw screen onto display if (img.rows()>0 && img.columns()>0) { if (data.size() == img.size()) { data.fill(img); } else { destroyImage(); createImage(img); } } else { setStatusString("empty image"); return false; } if (useShareMemory) { XShmPutImage(display_info.display, display_info.win, display_info.gc, display_info.shmimage, 0, 0, 0, 0, display_info.width, display_info.height, false); } else { XPutImage(display_info.display, display_info.win, display_info.gc, display_info.shmimage, 0, 0, 0, 0, display_info.width, display_info.height); } XSync(display_info.display,0); return true; }