std::unique_ptr<Image> shrinkImage(const std::unique_ptr<Image>& image, int w) { int orig_w = image->getWidth(); int orig_h = image->getHeight(); int h = (w * image->getHeight()) / image->getWidth(); auto img_ptr = std::make_unique<Image>(w, h, image->getChannelNum()); for (size_t ch = 0; ch < image->getChannelNum(); ch++) { auto orig_data_ptr = image->getValues(ch); auto res_data_ptr = img_ptr->getValues(ch); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { float posx = static_cast<float>(i * orig_w) / w; float posy = static_cast<float>(j * orig_h) / h; int iposx = static_cast<int>(posx); int iposy = static_cast<int>(posy); float dposx = posx - static_cast<float>(iposx); float dposy = posy - static_cast<float>(iposy); float val = 0; if (iposx + 1 >= orig_w) { if (iposy + 1 >= orig_h) { val += orig_data_ptr[iposy * orig_w + iposx]; } else { val += (1-dposy) * orig_data_ptr[iposy * orig_w + iposx]; val += (dposy) * orig_data_ptr[(iposy+1) * orig_w + iposx]; } } else if (iposy + 1 >= orig_h) { val += (1-dposx) * (orig_data_ptr[iposy * orig_w + iposx]); val += (dposx) * (orig_data_ptr[iposy * orig_w + iposx + 1]); } else { val += (1-dposx) * (1-dposy) * (orig_data_ptr[iposy * orig_w + iposx]); val += (dposx) * (1-dposy) * (orig_data_ptr[iposy * orig_w + iposx + 1]); val += (1-dposx) * (dposy) * (orig_data_ptr[(iposy+1) * orig_w + iposx]); val += (dposx) * (dposy) * (orig_data_ptr[(iposy+1) * orig_w + iposx + 1]); } res_data_ptr[j*w + i] = val; } } } return img_ptr; }
void CSMPrefs::BoolSetting::valueChanged (int value) { { QMutexLocker lock (getMutex()); getValues().setBool (getKey(), getParent()->getKey(), value); } getParent()->getState()->update (*this); }
void CSMPrefs::DoubleSetting::valueChanged (double value) { { QMutexLocker lock (getMutex()); getValues().setFloat (getKey(), getParent()->getKey(), value); } getParent()->getState()->update (*this); }
int main(void){ int x,y; printf("Enter two numbers:"); if(getValues(&x,&y) == 0){ swap(&x,&y); } printf("The smaller number is: %d\n", x); printf("The bigger number is: %d\n", y); }
std::string ColumnTextParser::getValue(unsigned int Line, unsigned int Column) const { std::vector<std::string> LineString = getValues(Line); if (!LineString.empty() && Column < LineString.size()) return LineString.at(Column); return ""; }
void EditStyle::applyToAllParts() { getValues(); QList<Excerpt*>& el = cs->rootScore()->excerpts(); for (Excerpt* e : el) { e->score()->undo(new ChangeStyle(e->score(), lstyle)); e->score()->update(); } }
int main() { int tab[10]; int *point=tab; getValues(point); printf("Wynik: %d\n",substract(point)); }
std::unique_ptr<Image> leastSquarePatch(const std::unique_ptr<Image>& image) { // process grayscale patches only if (image->getChannelNum() > 1) return std::unique_ptr<Image>(); auto data_ptr = image->getValues(0); const auto w = image->getWidth(); const auto h = image->getHeight(); // least square fit to linear plane for light compensation float xsum_orig = 0; float ysum_orig = 0; float csum_orig = 0; for (size_t j = 0; j < h; j++) { for (size_t i = 0; i < w; i++) { xsum_orig += (i * data_ptr[j*w + i]); ysum_orig += (j * data_ptr[j*w + i]); csum_orig += (data_ptr[j*w + i]); } } Eigen::Vector3d vsum(xsum_orig, ysum_orig, csum_orig); float x2sum = 0, y2sum = 0, xysum = 0, xsum = 0, ysum = 0; float csum = w*h; for (size_t j = 0; j < h; j++) { for (size_t i = 0; i < w; i++) { x2sum += (i*i); y2sum += (j*j); xysum += (i*j); xsum += i; ysum += j; } } Eigen::Matrix3d msum; msum << x2sum, xysum, xsum, xysum, y2sum, ysum, xsum, ysum, csum; auto vcoeff = msum.inverse() * vsum; auto newImage = std::make_unique<Image>(w, h, 1); for (size_t j = 0; j < h; j++) { for (size_t i = 0; i < w; i++) { (newImage->getValues(0))[j*w + i] = data_ptr[j*w + i] - i*vcoeff[0] - j*vcoeff[1] - vcoeff[2]; } } return newImage; }
void GamePlay::River() { Setup(); tablehand = hands.dealCards(deck, tablehand, 1); Cards(); //creating the hands getValues(); uiText(); betSystem(); finalCards(); }
Period *Period::multipliedBy(int scalar) { if (this == ZERO || scalar == 1) { return this; } vector<int> values = getValues(); // cloned for (int i = 0; i < values.size(); i++) { values[i] = FieldUtils::safeMultiply(values[i], scalar); } return new Period(values, getPeriodType()); }
/** * @timef * NOTES: * - Only the activity buffer covers the extended frame - this is the frame that * includes boundaries. * - The membrane potential V covers the "real" or "restricted" frame. * - In MPI runs, xLoc and yLoc refer to global coordinates. * writeState is only called by the processor with (xLoc,yLoc) in its * non-extended region. */ int PointProbe::outputState(double timef) { getValues(timef); if (parent->columnId()==0) { return writeState(timef); } else{ return PV_SUCCESS; } }
void JGCClient::unexport(){ lock(); vector<JGCClientEndPointInfo*>* vec=getValues(endPointInfos); unlock(); for (unsigned int i=0;i<vec->size();i++){ JGCClientEndPointInfo* epi=vec->at(i); epi->unexport(); } delete vec; }
static void getValues(symbol *s, char **nameptr, int *numvar, int maxptr, int *i) { varInfo *v; if (s) { getValues(s->left, nameptr, numvar, maxptr, i); if (*i < maxptr) { Rval *r; v = (varInfo *) s->val; r = v->R; if (v->T.basicType == T_REAL) { if (nameptr != NULL)/* if nameptr is 0 count vars */ { nameptr[*i] = (char *) &r->v.r; /* pass address of real */ *i += 1; } *numvar += 1; } else { if (nameptr != NULL)/* if nameptr is null just count vars */ { nameptr[*i] = r->v.s; *i += 1; } *numvar += 1; } if (bgflag > 1) fprintf(stderr, "name: '%s', i = %d, number: %d \n", s->name, *i, *numvar); } else { *numvar = -1; /* mark error */ } getValues(s->right, nameptr, numvar, maxptr, i); } }
//THIS NEEDS ALOT WORK //bet system stuff in here void GamePlay::betSystem() { // method for cpu betting logic, passing in CpuHandValue to determine what it does // storing the variable returned from menu class to bet bet = aesthetics.gameplayMenu(); if (bet == 100) { allin = true; bet = 100; getValues(); Betting(bet); for (size_t i = 0; i < listOfComputerPlayers.size(); i++) { CpuBetting(listOfComputerPlayers[i].CpuHandValue, listOfComputerPlayers[i].name, listOfComputerPlayers[i].cpubet, listOfComputerPlayers[i].cpucash); } finalCards(); } if (bet == 200) { playerFold = true; finalCards(); } //needs a bool if the cpu didnt fold only to do these, if it did fold dont do them getValues(); Betting(bet); // player betting method passing in the value stored at bet for (size_t i = 0; i < listOfComputerPlayers.size(); i++) { CpuBetting(listOfComputerPlayers[i].CpuHandValue, listOfComputerPlayers[i].name, listOfComputerPlayers[i].cpubet, listOfComputerPlayers[i].cpucash); } }
int main(void) { int sum = 0; int grades[SIZE]; sum = getValues(grades); printf("\nNumber of scores entered: %d\n", sum); printValues(grades, sum); return 0; }
void GamePlay::Turn() { Setup(); tablehand = hands.dealCards(deck, tablehand, 1); Cards(); getValues(); uiText(); betSystem(); River(); }
Period *Period::withFieldAdded(DurationFieldType *field, int value) { if (field == NULL) { throw IllegalArgumentException("Field must not be NULL"); } if (value == 0) { return this; } vector<int> newValues = getValues(); // cloned BasePeriod::addFieldInto(newValues, field, value); return new Period(newValues, getPeriodType()); }
void update(const key_type& inKey, const boost::unordered_set<value_type>& inValues) { { boost::unordered_set<value_type> curValues(getValues(inKey)); for (auto it = curValues.begin(); it != curValues.end(); ++it) if (inValues.find(*it) == inValues.end()) drop(inKey, *it); } insert(inKey, inValues); }
SkImageFilter* FEComponentTransfer::createImageFilter(SkiaImageFilterBuilder* builder) { SkImageFilter* input = builder->build(inputEffect(0)); unsigned char rValues[256], gValues[256], bValues[256], aValues[256]; getValues(rValues, gValues, bValues, aValues); SkAutoTUnref<SkColorFilter> colorFilter(SkTableColorFilter::CreateARGB(aValues, rValues, gValues, bValues)); return SkColorFilterImageFilter::Create(colorFilter, input); }
// Sets the properties of the merged object properties* SourceMerger::setProperties(std::vector<std::pair<properties::tagType, properties::iterator> > tags, map<string, streamRecord*>& outStreamRecords, vector<map<string, streamRecord*> >& inStreamRecords, properties* props) { if(props==NULL) props = new properties(); map<string, string> pMap; properties::tagType type = streamRecord::getTagType(tags); if(type==properties::unknownTag) { cerr << "ERROR: inconsistent tag types when merging Scope!"<<endl; exit(-1); } if(type==properties::enterTag) { assert(tags.size()>0); vector<string> names = getNames(tags); assert(allSame<string>(names)); assert(*names.begin() == "source"); vector<long> numRegionsV = str2int(getValues(tags, "numRegions")); assert(allSame<long>(numRegionsV)); int numRegions = *numRegionsV.begin(); pMap["numRegions"] = txt()<<numRegions; for(int i=0; i<numRegions; i++) { vector<string> fName = getValues(tags, txt()<<"fName_"<<i); assert(allSame<string>(fName)); pMap[txt()<<"fName_"<<i] = *fName.begin(); vector<string> startLine = getValues(tags, txt()<<"startLine_"<<i); assert(allSame<string>(startLine)); pMap[txt()<<"startLine_"<<i] = *startLine.begin(); vector<string> endLine = getValues(tags, txt()<<"endLine_"<<i); assert(allSame<string>(endLine)); pMap[txt()<<"endLine_"<<i] = *endLine.begin(); } props->add("source", pMap); } else { props->add("source", pMap); } return props; }
PassRefPtr<SkImageFilter> FEComponentTransfer::createImageFilter(SkiaImageFilterBuilder* builder) { RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace())); unsigned char rValues[256], gValues[256], bValues[256], aValues[256]; getValues(rValues, gValues, bValues, aValues); SkAutoTUnref<SkColorFilter> colorFilter(SkTableColorFilter::CreateARGB(aValues, rValues, gValues, bValues)); SkImageFilter::CropRect cropRect = getCropRect(builder->cropOffset()); return adoptRef(SkColorFilterImageFilter::Create(colorFilter, input.get(), &cropRect)); }
ColorSelectorMerger::ColorSelectorMerger(std::vector<std::pair<properties::tagType, properties::iterator> > tags, std::map<std::string, streamRecord*>& outStreamRecords, std::vector<std::map<std::string, streamRecord*> >& inStreamRecords, properties* props) : Merger(advance(tags), outStreamRecords, inStreamRecords, props) { if(props==NULL) props = new properties(); this->props = props; map<string, string> pMap; properties::tagType type = streamRecord::getTagType(tags); if(type==properties::unknownTag) { cerr << "ERROR: inconsistent tag types when merging Trace!"<<endl; exit(-1); } if(type==properties::enterTag) { assert(tags.size()>0); vector<string> names = getNames(tags); assert(allSame<string>(names)); assert(*names.begin() == "colorSelector"); // Merge the selector IDs along all the streams int mergedSelID = streamRecord::mergeIDs("colorSelector", "selID", pMap, tags, outStreamRecords, inStreamRecords); pMap["selID"] = txt()<<mergedSelID; pMap["startR"] = txt()<<vAvg(str2float(getValues(tags, "startR"))); pMap["endR"] = txt()<<vAvg(str2float(getValues(tags, "endR"))); pMap["startG"] = txt()<<vAvg(str2float(getValues(tags, "startG"))); pMap["endG"] = txt()<<vAvg(str2float(getValues(tags, "endG"))); pMap["startB"] = txt()<<vAvg(str2float(getValues(tags, "startB"))); pMap["endB"] = txt()<<vAvg(str2float(getValues(tags, "endB"))); } props->add("colorSelector", pMap); }
ILOBRANCHCALLBACK1(MyBranch, IloNumVarArray, vars) { if ( getBranchType() != BranchOnVariable ) return; // Branch on var with largest objective coefficient // among those with largest infeasibility IloNumArray x; IloNumArray obj; IntegerFeasibilityArray feas; try { x = IloNumArray(getEnv()); obj = IloNumArray(getEnv()); feas = IntegerFeasibilityArray(getEnv()); getValues(x, vars); getObjCoefs(obj, vars); getFeasibilities(feas, vars); IloInt bestj = -1; IloNum maxinf = 0.0; IloNum maxobj = 0.0; IloInt cols = vars.getSize(); for (IloInt j = 0; j < cols; j++) { if ( feas[j] == Infeasible ) { IloNum xj_inf = x[j] - IloFloor (x[j]); if ( xj_inf > 0.5 ) xj_inf = 1.0 - xj_inf; if ( xj_inf >= maxinf && (xj_inf > maxinf || IloAbs (obj[j]) >= maxobj) ) { bestj = j; maxinf = xj_inf; maxobj = IloAbs (obj[j]); } } } if ( bestj >= 0 ) { makeBranch(vars[bestj], x[bestj], IloCplex::BranchUp, getObjValue()); makeBranch(vars[bestj], x[bestj], IloCplex::BranchDown, getObjValue()); } } catch (...) { x.end(); obj.end(); feas.end(); throw; } x.end(); obj.end(); feas.end(); }
bool SceneLoader::doSphere(istream &str, string &name) { if (!getName(str, "sphere", name)) return false; SceneGroup *n = new SceneGroup(); groups[name] = n; n->_name = name; n->_sphere = new ParametricSphere(); do { int state = findOpenOrClosedParen(str); if (state == ERROR) { SetSphereDefaults(n); return false; } else if (state == CLOSED) { SetSphereDefaults(n); return true; } else if (state == OPEN) { string cmd; vector<ParametricValue*> values; if (readCommand(str, cmd)) { if (cmd == "radius") { if (getValues(str, values) < 1) { *err << "Type with no parameters at "; errLine(str.tellg()); } else { cleanAfter(values, 1); n->_sphere->_radius = values[0]; } } else if (cmd == "material") { string matName = getString(str); if (matName.empty()) { *err << "No material name after material command at "; errLine(str.tellg()); } else if (materials[matName] == NULL) { *err << "Unknown material " << matName << " referenced at "; errLine(str.tellg()); } else { n->_sphere->_material = materials[matName]; } } else { *err << "Error: command " << cmd << " not recognized at "; errLine(str.tellg()); } findCloseParen(str); } } } while (true); }
void cHorizontalScrollbar::setLeftButtonIds(ushort unpressed, ushort pressed, ushort hover) { if (btnLeft) { btnLeft->setStateGump(BS_UNPRESSED, unpressed); btnLeft->setStateGump(BS_PRESSED, pressed); btnLeft->setStateGump(BS_HOVER, hover); setBounds(x_, y_, width_, btnLeft->height()); // Set Width before adding another button // Reposition background background->setBounds(btnLeft->width(), 0, width_ - btnLeft->width() - btnRight->width(), btnLeft->height()); handle->setX(getTrackerXFromPos(pos_)); pixelPerStep = qMax<float>(0, (float)getInnerWidth() / (float)getValues()); } }
void cVerticalScrollbar::setUpButtonIds(ushort unpressed, ushort pressed, ushort hover) { if (btnUp) { btnUp->setStateGump(BS_UNPRESSED, unpressed); btnUp->setStateGump(BS_PRESSED, pressed); btnUp->setStateGump(BS_HOVER, hover); setBounds(x_, y_, btnUp->width(), height_); // Set Width before adding another button // Reposition background background->setBounds(0, btnUp->height(), btnUp->width(), height_ - btnUp->height() - btnDown->height()); handle->setY(getTrackerYFromPos(pos_)); pixelPerStep = qMax<float>(0, (float)getInnerHeight() / (float)getValues()); } }
Json toEsprima_() override { Json::object obj; vector<Json> body; obj["type"] = "BlockStatement"; obj["loc"] = getLocation(); obj["raw"] = raw_; obj["cform"] = toCCode(); for (auto stmt : getValues()) { body.push_back(stmt->toEsprima_()); } obj["body"] = body; return obj; }
/// Get the relevant data from the packet and sent it as Ivy message void decode_and_send_to_ivy() { // get relevant data and convert to SI units // contents of the kestrel S message response: // DT, MG, TR, WS, CW, HW, TP, WC, RH, HI, DP, WB, BP, AL, DA // s, Mag, True, mph, mph, mph, F, F, %, F, F, F, inHg, ft, ft // // where: // // DT is the date and time in seconds since 1st January 2000, // AV is air velocity // AF is air flow // MG is the compass magnetic direction // TR is the compass true direction // WS is the wind speed // CW is the crosswind // HW is the headwind // TP is the temperature, // WC is the wind chill, // RH is the humidity, // EV is the evaporation rate // CT is the concrete temperature // HR, MO (moisture) are the humidity ratio // HI is the heat index, // DP is the dew point, // WB is the wet bulb // AP is absolute pressure // BP is the pressure, // AL is the altitude, // DA is the density altitude // AD is air density // RA is relative air density float values[NUM_PARAMS]; float pstatic_Pa, temp_degC, windspeed_mps, winddir_deg; if (want_alive_msg) IvySendMsg("%d ALIVE 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ac_id); if (getValues(packet + MIN_PACKET_LENGTH, values)){ pstatic_Pa = values[BP] * 3386.4; // original is inches Hg temp_degC = (values[TP] - 32.0) * 5.0/9.0; // original is deg F windspeed_mps = values[WS] * 0.44704; // original is miles per hour winddir_deg = values[MG]; // format has to match declaration in conf/messages.xml IvySendMsg("%d WEATHER %f %f %f %f\n", ac_id, pstatic_Pa, temp_degC, windspeed_mps, winddir_deg); } }
std::unique_ptr<Image> loadPGMImage(const char* filepath) { FILE* fp = fopen(filepath, "rb"); if (!fp) { printf("error loading file %s at loadPGMImage()\n", filepath); return std::unique_ptr<Image>(); } int img_w, img_h; gray max_pval; gray** pixels = pgm_readpgm(fp, &img_w, &img_h, &max_pval); if (!pixels) { printf("error reading image from file %s at loadPGMImage()\n", filepath); fclose(fp); return std::unique_ptr<Image>(); } auto img_ptr = std::make_unique<Image>(img_w, img_h, 3); for (int y = 0; y < img_h; y++) { for (int x = 0; x < img_w; x++) { (img_ptr->getValues(0))[y * img_w + x] = static_cast<float>(pixels[y][x]) / max_pval; (img_ptr->getValues(1))[y * img_w + x] = static_cast<float>(pixels[y][x]) / max_pval; (img_ptr->getValues(2))[y * img_w + x] = static_cast<float>(pixels[y][x]) / max_pval; } } ppm_freearray(pixels, img_h); fclose(fp); return img_ptr; }
task main(){ bool onramp = false; // Wait 0.1 seconds to give some time to initialize the values wait1Msec(100); getValues(); // Turn on the engines... motor[motorD] = 20; motor[motorF] = 20; // ...wait 2 seconds... //wait1Msec(2000); for (int g = 0; g<200; g++) { // 2 sec wait1Msec(10); getValues(); if(x < -60){ onramp = true; g = 2001; } } // ...and disable the engines. // Get the x, y, and z values motor[motorD] = 0; motor[motorF] = 0; getValues(); // The robot is on the ramp // So execute the isOnRamp function if(onramp) { isOnRamp(); } // The robot is on the floor // So execute the isOnGround function else {isOnGround(); } }