/** * @brief Loads a page, uses the cache if possible * * @param url * * @return */ Page* PageFactory::load(const string& name) { string realName = name; if (!name.empty() and name[0] == '/') { realName = name.substr(1); // Remove the '/' at the front } VidaApp* app = getApp(); Page* result = 0; // Check the cache CacheType::iterator hit = cache.find(realName); if (hit == cache.end()) { // Not found, Load it from the DB ScopedDbConnection db(app->mongoHostname()); auto_ptr<DBClientCursor> cursor = db->query(app->mongoNSFor("page"), BSON( "name" << realName ), 1); if (cursor->more()) { BSONObj data = cursor->next(); // For now, just put it into the cache. TODO: Have a max cache size and do some clever cache managagement CacheType::value_type newVal(name, PageCacheEntry(data)); result = cache.insert(newVal).first->second.createPage(); } else { // Return a 404 page .. will create it if not in cache already. Magic :D if (realName != "404") { result = load("404"); } else { // OK we're being asked to return a 404 because we don't have 404 page .. make up a default one CacheType::value_type newVal("404", PageCacheEntry("404", WString::tr("page-404-title").toUTF8(), WString::tr("page-404-body").toUTF8())); result = cache.insert(newVal).first->second.createPage(); } } db.done(); } else { result = hit->second.createPage(); } return result; }
Var* saito_grassfire(Var* input, int ignore) { // Euclidian distance computation size_t dx = GetX(input); size_t dy = GetY(input); Var* sdt_x = newVal(BSQ, dx, dy, 1, DV_INT32, calloc(dx * dy, sizeof(int))); if (sdt_x == NULL) { parse_error("Unable to allocate memory."); return (NULL); } Var* sdt_xy = newVal(BSQ, dx, dy, 1, DV_INT32, calloc(dx * dy, sizeof(int))); if (sdt_xy == NULL) { parse_error("Unable to allocate memory."); free(sdt_x); return (NULL); } phaseSaitoX(input, ignore, sdt_x); phaseSaitoY(sdt_x, sdt_xy); phaseSaitoZ(sdt_xy, sdt_x); // We reuse sdt_x to store the final result!! mem_claim(sdt_xy); free_var(sdt_xy); return (sdt_x); }
Var* ff_realfft(vfuncptr func, Var* arg) { Var* obj = NULL; int i, n; double *in, *out; Alist alist[3]; alist[0] = make_alist("obj", ID_VAL, NULL, &obj); alist[1].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } n = V_DSIZE(obj); in = (double*)calloc(n, sizeof(double)); out = (double*)calloc(n, sizeof(double)); for (i = 0; i < n; i++) { in[i] = extract_double(obj, i); } if (func->fdata == (void*)1) { realfft(in, n, out); } else { realrft(in, n, out); } return (newVal(BSQ, 1, n, 1, DV_DOUBLE, out)); }
Var* ff_audit(vfuncptr func, Var* arg) { #ifdef _WIN32 parse_error("This function is not supported under windows."); return NULL; #else struct tms faketime; clock_t realtime; void* ptr; Var* s; int* s_data; realtime = times(&faketime); ptr = sbrk(0); s_data = calloc(4, sizeof(int)); s = newVal(BSQ, 4, 1, 1, DV_INT32, s_data); s_data[0] = (long)ptr; s_data[1] = faketime.tms_utime; s_data[2] = faketime.tms_stime; s_data[3] = realtime; return s; #endif /* _WIN32 */ }
void VObjectRegistry::RegisterObject( const VObjectKey& in_Name, VNamedObject& in_Object) { //std::ostringstream str; //str << "Object registered: addr(" << &in_Object << "), name: \"" // << in_Name.ToString().AsCString() << "\"" << std::endl; //V3D_DEBUGMSG(str.str().c_str()); // register object pair<ObjectKeyMap::iterator, bool> res; VNamedObject* pObj = &in_Object; ObjectKeyMap::value_type newVal(in_Name, pObj); res = m_Objects.insert(newVal); if( res.second == false ) { // throw exception V3D_THROW(VObjectRegistryException, "tried to register object \"" + in_Name.ToString() + "\"twice"); } }
MojErr MojDbQuotaEngine::applyOffset(const MojString& kindId, MojInt64 offset, MojDbStorageTxn* txn) { MojAssert(txn); // get old value MojRefCountedPtr<MojDbStorageItem> item; MojInt64 usage = 0; MojErr err = getUsage(kindId, txn, true, usage, item); MojErrCheck(err); if (item.get()) { MojInt64 newUsage = offset + usage; MojAssert(newUsage >= 0); MojObject newVal(newUsage); MojBuffer buf; err = newVal.toBytes(buf); MojErrCheck(err); // insert new record txn->quotaEnabled(false); err = m_usageDb->update(kindId, buf, item.get(), txn); MojErrCheck(err); txn->quotaEnabled(true); } else { err = insertUsage(kindId, offset, txn); MojErrCheck(err); } return MojErrNone; }
bool plAvatarMgr::HandleCoopMsg(plAvCoopMsg *msg) { plAvCoopMsg::Command cmd = msg->fCommand; uint32_t id = msg->fInitiatorID; uint16_t serial = msg->fInitiatorSerial; if(cmd == plAvCoopMsg::kStartNew) { // Currently, there's nothing that removes these coop coordinators when // they're done. Since I can't think of a good way to figure out when // they're done, I'm just going to clear them every time a new one starts. // With the current usage, you should only get one at a time anyway -Colin plCoopMap::iterator it = fActiveCoops.begin(); while (it != fActiveCoops.end()) { plCoopCoordinator* deadCoop = it->second; delete deadCoop; it++; } fActiveCoops.clear(); // start a new coop plCoopCoordinator *coord = msg->fCoordinator; plCoopMap::value_type newVal(id, coord); fActiveCoops.insert(newVal); coord->Run(); return true; } else { // it's a message for an existing coop... return IPassMessageToActiveCoop(msg, id, serial); } }
void TestRegularApi::test() { TNS__TestOperationResponse1 resp; QCOMPARE(resp.out(), QString()); QString newVal("newval"); resp.setOut(newVal); QCOMPARE(resp.out(), newVal); }
void TestBoostApi::test() { TNS__TestOperationResponse1 resp; QCOMPARE(resp.out(), boost::optional<QString>()); QString newVal("newval"); resp.setOut(newVal); QCOMPARE(*resp.out(), newVal); }
void TestPointerApi::test() { TNS__TestOperationResponse1 resp; QCOMPARE(resp.out(), (QString*)0); QString newVal("newval"); resp.setOut(newVal); QCOMPARE(*resp.out(), newVal); }
Var* vw_grassfire(Var* vsrc, int ignore) { size_t dx = GetX(vsrc); size_t dy = GetY(vsrc); int val; int i, j; int* dst = calloc(dx * dy, sizeof(int)); if (dst == NULL) { parse_error("Unable to allocate memory."); return (NULL); } Var* vdst = newVal(BSQ, dx, dy, 1, DV_INT32, dst); // First row j = 0; for (i = 0; i < dx; i++) { val = extract_int(vsrc, cpos(i, j, 0, vsrc)); dst[cpos(i, j, 0, vdst)] = (val == ignore ? 0 : 1); } for (j = 1; j < dy - 1; j++) { // first column i = 0; val = extract_int(vsrc, cpos(i, j, 0, vsrc)); dst[cpos(i, j, 0, vdst)] = (val == ignore ? 0 : 1); // middle columns for (i = 1; i < dx - 1; i++) { val = extract_int(vsrc, cpos(i, j, 0, vsrc)); dst[cpos(i, j, 0, vdst)] = (val == ignore ? 0 : 1 + min(dst[cpos(i - 1, j, 0, vdst)], dst[cpos(i, j - 1, 0, vdst)])); } // last column val = extract_int(vsrc, cpos(i, j, 0, vsrc)); dst[cpos(i, j, 0, vdst)] = (val == ignore ? 0 : 1); } // last row for (i = 0; i < dx; i++) { val = extract_int(vsrc, cpos(i, j, 0, vsrc)); dst[cpos(i, j, 0, vdst)] = (val == ignore ? 0 : 1); } // Now the other direction for (j = dy - 2; j >= 0; --j) { for (i = dx - 2; i >= 0; --i) { if (dst[cpos(i, j, 0, vdst)] != 0) { int m = min(dst[cpos(i + 1, j, 0, vdst)], dst[cpos(i, j + 1, 0, vdst)]); if (m < dst[cpos(i, j, 0, vdst)]) dst[cpos(i, j, 0, vdst)] = m + 1; } } } return (vdst); }
Var* ff_fft(vfuncptr func, Var* arg) { Var *real = NULL, *img = NULL; double* data; int i, j, n, x, y, z; COMPLEX *in, *out; Alist alist[4]; alist[0] = make_alist("real", ID_VAL, NULL, &real); alist[1] = make_alist("img", ID_VAL, NULL, &img); alist[2].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (real == NULL && img == NULL) { parse_error("%s: No real or imaginary objects specified\n", func->name); return (NULL); } x = GetSamples(V_SIZE(real), V_ORG(real)); y = GetLines(V_SIZE(real), V_ORG(real)); z = GetBands(V_SIZE(real), V_ORG(real)); if (img == NULL && x == 2) { n = y * z; in = (COMPLEX*)calloc(n, sizeof(COMPLEX)); out = (COMPLEX*)calloc(n, sizeof(COMPLEX)); for (i = 0; i < y; i++) { for (j = 0; j < z; j++) { in[i].re = extract_double(real, cpos(0, i, j, real)); in[i].im = extract_double(real, cpos(1, i, j, real)); } } } else { n = V_DSIZE(real); in = (COMPLEX*)calloc(n, sizeof(COMPLEX)); out = (COMPLEX*)calloc(n, sizeof(COMPLEX)); for (i = 0; i < n; i++) { in[i].re = extract_double(real, i); in[i].im = (img == NULL ? 0.0 : extract_double(img, i)); } } if (func->fdata == (void*)1) { fft(in, n, out); } else { rft(in, n, out); } data = (double*)calloc(n * 2, sizeof(double)); for (i = 0; i < n; i++) { data[i * 2] = out[i].re; data[i * 2 + 1] = out[i].im; } return (newVal(BSQ, 2, n, 1, DV_DOUBLE, data)); }
Var* ff_radial_symmetry2(vfuncptr func, Var* arg) { Var *obj = NULL, *rval = NULL; float ignore = FLT_MIN; float* out; int x, y, z, i, j; int size = 0; int width = 0, height = 0; Window* w; Alist alist[9]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("x", DV_INT32, NULL, &width); alist[2] = make_alist("y", DV_INT32, NULL, &height); alist[3] = make_alist("size", DV_INT32, NULL, &size); alist[4] = make_alist("ignore", DV_FLOAT, NULL, &ignore); alist[5].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } if (size) { width = size; height = size; } if (width <= 0 || height <= 0) { parse_error("%s: Invalid size specified (%dx%d)\n", func->name, width, height); return (NULL); } x = GetX(obj); y = GetY(obj); z = GetZ(obj); w = create_window(width, height, DV_FLOAT); out = calloc((size_t)x * (size_t)y, sizeof(float)); rval = newVal(BSQ, x, y, 1, DV_FLOAT, out); for (i = 0; i < x; i += 1) { load_window(w, obj, i, 0, ignore); for (j = 0; j < y; j += 1) { if (j) roll_window(w, obj, i, j, ignore); out[cpos(i, j, 0, rval)] = radial_symmetry2(w->row, width, height, ignore); } } free_window(w); return (rval); }
void MeanShiftChopper::floodFillPostprocess(Mat& img, map<Scalar, int>& m, const Scalar& colorDiff) { CV_Assert( !img.empty() ); Mat mask( img.rows+2, img.cols+2, CV_8UC1, Scalar::all(0) ); for( int y = 0; y < img.rows; y++ ) { for( int x = 0; x < img.cols; x++ ) { if( mask.at<uchar>(y+1, x+1) == 0 ) { Scalar newVal( rng(256), rng(256), rng(256) ); floodFill( img, mask, Point(x,y), newVal, 0, colorDiff, colorDiff ); } } } }
bool AbstractBitfieldDataInformation::setData(const QVariant& valueVariant, Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset) { AllPrimitiveTypes oldVal(mValue); bool ok; AllPrimitiveTypes valToWrite = valueVariant.toULongLong(&ok); Q_ASSERT(ok); if (!ok) return false; AllPrimitiveTypes newVal(oldVal); //this handles remaining < size() for us bool wasAbleToWrite = newVal.writeBits(width(), valToWrite, out, effectiveByteOrder(), address, bitsRemaining, &bitOffset); return wasAbleToWrite; }
Var* ff_local_maximum(vfuncptr func, Var* arg) { Var *obj = NULL, *rval = NULL; float ignore = FLT_MIN; float* out; int x, y, i, j; int size = 3; float threshold = FLT_MIN; Window* w; Alist alist[9]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("size", DV_INT32, NULL, &size); alist[2] = make_alist("ignore", DV_FLOAT, NULL, &ignore); alist[3] = make_alist("threshold", DV_FLOAT, NULL, &threshold); alist[4].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } x = GetX(obj); y = GetY(obj); w = create_window(size, size, DV_FLOAT); out = calloc(x * y, sizeof(float)); rval = newVal(BSQ, x, y, 1, DV_FLOAT, out); for (i = 0; i < x; i += 1) { load_window(w, obj, i, 0, ignore); for (j = 0; j < y; j += 1) { if (j) roll_window(w, obj, i, j, ignore); out[cpos(i, j, 0, rval)] = local_maximum(w, threshold, ignore); } } free_window(w); return (rval); }
bool ShortcutModel::setData(const QModelIndex & index, const QVariant & value, int role) { if (role != Qt::EditRole || !index.isValid()) return false; QString newVal(value.toString()); if (index.column() == 0) { // ensure it's unique. Message is handled in the ShortcutEditorDialog QPair<QString, QString> p; foreach (p, m_values) { if (p.first == newVal) { emit keysNotUnique(newVal); return false; } } m_values[index.row()].first = newVal; }
Var* ff_realfft2(vfuncptr func, Var* arg) { Var* obj = NULL; int i, j, n, x; double* in; Alist alist[3]; alist[0] = make_alist("obj", ID_VAL, NULL, &obj); alist[1].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } n = V_DSIZE(obj); for (x = n; (x & 1) == 0; x >>= 1) ; if (x != 1) { parse_error("dimension not a power of 2. Use version 0.\n"); return (NULL); } in = (double*)calloc(n, sizeof(double)); for (i = 0; i < n; i++) { in[i] = extract_double(obj, i); } if (func->fdata == (void*)1) { rdft(n, cos(M_PI / n), sin(M_PI / n), in); } else { rdft(n, cos(M_PI / n), -sin(M_PI / n), in); for (j = 0; j <= n - 1; j++) { in[j] *= 2.0 / n; } } return (newVal(BSQ, 1, n, 1, DV_DOUBLE, in)); }
Var* ff_realfft3(vfuncptr func, Var* arg) { Var* obj = NULL; size_t i, n; double* in; Alist alist[3]; alist[0] = make_alist("obj", ID_VAL, NULL, &obj); alist[1].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } n = V_DSIZE(obj); if (n > INT_MAX) { parse_error("%s: fft function does not handle objects greater than %ld bytes.\n", func->name, INT_MAX); return NULL; } in = (double*)calloc(n, sizeof(double)); if (in == NULL) { parse_error("%s: Unable to alloc %ld bytes.\n", func->name, n * sizeof(double)); return NULL; } for (i = 0; i < n; i++) { in[i] = extract_double(obj, i); } if (func->fdata == (void*)1) { mayer_realfft(n, in); } else { mayer_realifft(n, in); } return (newVal(BSQ, 1, n, 1, DV_DOUBLE, in)); }
Var* ff_drawshape(vfuncptr func, Var* arg) { Var *obj = NULL, *ovar = NULL; size_t x, y, z; char* out; float ignore = FLT_MAX; const char* options[] = {"cross", "box", "circle", NULL}; const char* shape = options[0]; Alist alist[9]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("shape", ID_ENUM, options, &shape); alist[2] = make_alist("ignore", DV_FLOAT, NULL, &ignore); alist[3].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } x = GetX(obj); y = GetY(obj); z = GetZ(obj); out = calloc(x * y, sizeof(char)); ovar = newVal(BSQ, x, y, 1, DV_UINT8, out); if (!strcmp(shape, "cross")) { draw_cross(obj, x, y, ignore, out); } else if (!strcmp(shape, "box")) { draw_box(obj, x, y, ignore, out); } else if (!strcmp(shape, "circle")) { draw_circle(obj, x, y, ignore, out); } return (ovar); }
// This marks all the pixels inside the outermost extents. Not exactly // grassfire, but closely related. Var* bounding_box(Var* vsrc, int ignore) { size_t dx = GetX(vsrc); size_t dy = GetY(vsrc); int left, right, i, j; int val; int* dst = calloc(dx * dy, sizeof(int)); if (dst == NULL) { parse_error("Unable to allocate memory."); return (NULL); } Var* vdst = newVal(BSQ, dx, dy, 1, DV_INT32, dst); for (j = 0; j < dy; j++) { for (left = 0; left < dx; left++) { val = extract_int(vsrc, cpos(left, j, 0, vsrc)); if (val == ignore) { dst[cpos(left, j, 0, vdst)] = 0; } else { break; } } for (right = dx - 1; right >= 0; right--) { val = extract_int(vsrc, cpos(right, j, 0, vsrc)); if (val == ignore) { dst[cpos(right, j, 0, vdst)] = 0; } else { break; } } for (i = left; i < right; i++) { dst[cpos(i, j, 0, vdst)] = 1; } } return (vdst); }
qint64 AbstractBitfieldDataInformation::readData(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8* bitOffset) { Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading if (bitsRemaining < BitCount64(width())) { mWasAbleToRead = false; mValue = 0; return -1; } bool wasValid = mWasAbleToRead; AllPrimitiveTypes oldVal(mValue); AllPrimitiveTypes newVal(mValue); mWasAbleToRead = newVal.readBits(size(), input, effectiveByteOrder(), address, bitsRemaining, bitOffset); if (oldVal != newVal || wasValid != mWasAbleToRead) { topLevelDataInformation()->setChildDataChanged(); mValue = newVal; } return width(); }
Var* ff_unrice(vfuncptr func, Var* arg) { Var* obj = NULL; int x, y, z, nbytes, i, start, len; int bits; unsigned char* in; int header = 1; int npts; unsigned short sx = x, sy = y, sz = z; unsigned char sbits = bits; char hdr[4]; int format; int count = 0; int l; unsigned char *cout, *out; short *sout, *tmp; Alist alist[4]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("header", ID_VAL, NULL, &header); alist[2].name = NULL; if (parse_args(func, arg, alist) == 0) return NULL; if (obj == NULL) { parse_error("%s: No object or size specified", func->name); return NULL; } len = V_DSIZE(obj); in = V_DATA(obj); start = 0; if (header) { /* read our header */ memcpy(hdr, in, 4); start += 4; if (memcmp(hdr, "RICE", 4) != 0) { parse_error("Not a rice header"); return NULL; } memcpy(&sx, in + start, 2); start += 2; memcpy(&sy, in + start, 2); start += 2; memcpy(&sz, in + start, 2); start += 2; memcpy(&sbits, in + start, 1); start += 1; x = sx; y = sy; z = sz; bits = sbits; nbytes = (bits + 7) / 8; npts = x; out = calloc(x * y * z, nbytes); cout = out; sout = (short*)out; tmp = (short*)calloc(x, 2); count = 0; while (start < len) { /* ** we assume that each rice compressed packet is a length of X ** ** We should do some error checking here somewhere. */ l = rice_unauto(in + start, len, npts, bits, tmp); if (l <= 0) { parse_error("Bad return code"); return NULL; } for (i = 0; i < npts; i++) { if (nbytes == 1) { cout[i + count * x] = tmp[i]; } else { sout[i + count * x] = tmp[i]; } } start += l; count++; } format = (nbytes == 1 ? DV_UINT8 : (nbytes == 2 ? DV_INT16 : DV_INT32)); return newVal(BSQ, x, y, z, format, out); } else { parse_error("Data without header not supported yet."); return NULL; } }
Var* ff_rice(vfuncptr func, Var* arg) { Var* obj = NULL; int x, y, z, nbytes, i, j, k, pos, start, len; short* in; unsigned char* out; int header = 1; int bits = -1; Alist alist[4]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("header", DV_INT32, NULL, &header); alist[2] = make_alist("bits", DV_INT32, NULL, &bits); alist[3].name = NULL; if (parse_args(func, arg, alist) == 0) return NULL; if (obj == NULL) { parse_error("%s: No object or size specified", func->name); return NULL; } x = GetX(obj); y = GetY(obj); z = GetZ(obj); nbytes = NBYTES(V_FORMAT(obj)); start = 0; if (bits == -1) bits = nbytes * 8; if (x > 4096) { parse_error("%s: Max buffer length is 4096 elements", func->name); return NULL; } if (nbytes > 2) { parse_error("Only able to compress 2 byte words or less"); return NULL; } if (nbytes == 2 && x > 511) { parse_error("Too many values in a row. Split this up."); return NULL; } in = calloc(x, 2); out = calloc(x * y * z, 2 * nbytes); if (header) { unsigned short sx = x, sy = y, sz = z; unsigned char sbits = bits; /* write out header */ if (x > 65535 || y > 65535 || z > 65535) { parse_error("data block too big for header"); return NULL; } memcpy(out, "RICE", 4); start += 4; memcpy(out + start, &sx, 2); start += 2; memcpy(out + start, &sy, 2); start += 2; memcpy(out + start, &sz, 2); start += 2; memcpy(out + start, &sbits, 1); start += 1; } for (k = 0; k < z; k++) { for (j = 0; j < y; j++) { /* ** Pack a temporary array with a whole line */ for (i = 0; i < x; i++) { pos = cpos(i, j, k, obj); in[i] = extract_int(obj, pos); } len = rice_auto(in, x, bits, out + start, 0); start += (len + 7) / 8; } } return newVal(BSQ, start, 1, 1, DV_UINT8, out); }
Var* ff_radial_symmetry3(vfuncptr func, Var* arg) { Var* obj = NULL; float ignore = FLT_MIN; int width = 0, height = 0; int end = 1; Var* rval = NULL; int x, y; float* out; Window* w; int *distance, d; int dx, dy; double ssxx, ssyy, ssxy; int i, j, p, q, r; int h2, w2; float v1, v2; int total; float *r1, *r2; int start = 0, step = 1; struct dstore { double sumx; double sumy; double sumxx; double sumyy; double sumxy; int count; } * accum, *a1, *a2; Alist alist[6]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("size", DV_INT32, NULL, &end); alist[2] = make_alist("ignore", DV_FLOAT, NULL, &ignore); alist[3] = make_alist("start", DV_INT32, NULL, &start); alist[4] = make_alist("step", DV_INT32, NULL, &step); alist[5].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } if (end <= 0) { parse_error("%s: Invalid end value specified\n", func->name); return (NULL); } x = GetX(obj); y = GetY(obj); width = end * 2 + 1; height = end * 2 + 1; // width = end; // height = end; w = create_window(width, height, DV_FLOAT); /* cache some frequently used computed values */ h2 = height / 2; w2 = width / 2; total = width * height; /* precompute the distance of every point in a given sized window ** to the center of the window. ** ** In theory, this only needs to be 1 quadrant of the window, but that's ** too hard to bookkeep, and doesn't save much. */ distance = calloc(total, sizeof(int)); for (i = 0; i < width; i++) { dx = i - w2; for (j = 0; j < height; j++) { dy = j - h2; distance[i + j * width] = floor(sqrt(dx * dx + dy * dy)); /* precheck for values outside the largest circle */ if (distance[i + j * width] > end) distance[i + j * width] = 0; } } out = calloc((size_t)x * (size_t)y * (size_t)((end - start) / step + 1), sizeof(float)); rval = newVal(BSQ, x, y, ((end - start) / step + 1), DV_FLOAT, out); accum = calloc(end + 1, sizeof(struct dstore)); /* run a window over every pixel and do the math */ for (i = 0; i < x; i += 1) { load_window(w, obj, i, 0, ignore); for (j = 0; j < y; j += 1) { if (j) roll_window(w, obj, i, j, ignore); v1 = ((float**)w->row)[h2][w2]; if (v1 == ignore) { continue; } memset(accum, 0, (end + 1) * sizeof(struct dstore)); /* ** pick a pair of opposing points, and add them to the ** accumulator for their given distance. We'll sum all the ** accumulators later for a complete result from dist 1..N. */ for (q = 0; q <= h2; q++) { /* one of the double-derefs moved to here for speed */ r1 = ((float**)w->row)[q]; r2 = ((float**)w->row)[(height - 1) - q]; for (p = 0; p < width; p++) { if (q == h2 && p == w2) { /* We only run the window up to the center point */ break; } v1 = r1[p]; v2 = r2[(width - 1) - p]; if (v1 == ignore || v2 == ignore) continue; if ((d = distance[p + q * width]) != 0) { a1 = &(accum[d]); a1->sumx += v1; a1->sumy += v2; a1->sumxx += v1 * v1; a1->sumyy += v2 * v2; a1->sumxy += v1 * v2; a1->count++; } } } /* now compute correlation from per-radii accumulators */ for (r = 1; r <= end; r++) { /* sum the values in preceeding bins */ a1 = &accum[r - 1]; a2 = &accum[r]; if (a1->count) { a2->sumx += a1->sumx; a2->sumy += a1->sumy; a2->sumxx += a1->sumxx; a2->sumyy += a1->sumyy; a2->sumxy += a1->sumxy; a2->count += a1->count; } // Don't bother if at least 1/2 the box isn't ignore values // this is M_PI_4 because we're only counting half the pixels // to begin with. if ((r - start) % step == 0) { if (a2->count > r * r * M_PI_4) { double c = a2->count; ssxx = a2->sumxx - a2->sumx * a2->sumx / c; ssyy = a2->sumyy - a2->sumy * a2->sumy / c; ssxy = a2->sumxy - a2->sumx * a2->sumy / c; if (ssxx != 0 && ssyy != 0) { out[cpos(i, j, ((r - start) / step), rval)] = sqrt(ssxy * ssxy / (ssxx * ssyy)); } } } } } printf("%d/%d\r", i, x); fflush(stdout); } free_window(w); free(distance); free(accum); return (rval); }
Var* ff_radial_symmetry(vfuncptr func, Var* arg) { Var *obj = NULL, *rval = NULL; float ignore = FLT_MIN; float* out = NULL; int x, y, z, i, j, k; int size = 10; int xdelta = 0.0, ydelta = 0.0; float* line = NULL; int all = 0; int first = 1; Window* w; Alist alist[9]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("size", DV_INT32, NULL, &size); alist[2] = make_alist("xdelta", DV_INT32, NULL, &xdelta); alist[3] = make_alist("ydelta", DV_INT32, NULL, &ydelta); alist[4] = make_alist("ignore", DV_FLOAT, NULL, &ignore); alist[5] = make_alist("all", DV_INT32, NULL, &all); alist[6] = make_alist("first", DV_INT32, NULL, &first); alist[7].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } if (size < 0) { parse_error("%s: Invalid size specified\n", func->name); return (NULL); } x = GetX(obj); y = GetY(obj); z = GetZ(obj); w = create_window(size, size, DV_FLOAT); if (all) { size_t n = (size_t)x * (size_t)y * (size_t)(size - first + 1); out = (float*)calloc(n, sizeof(float)); rval = newVal(BSQ, x, y, (size - first + 1), DV_FLOAT, out); line = (float*)calloc(size, sizeof(float)); } else { size_t n = (size_t)x * (size_t)y; out = (float*)calloc(n, sizeof(float)); rval = newVal(BSQ, x, y, 1, DV_FLOAT, out); line = NULL; } for (i = 0; i < x; i += 1) { load_window(w, obj, i, 0, ignore); for (j = 0; j < y; j += 1) { if (j) roll_window(w, obj, i, j, ignore); out[cpos(i, j, 0, rval)] = radial_symmetry(w->row, size, size, ignore, xdelta, ydelta, size, line); if (all) { for (k = first; k <= size; k++) { out[cpos(i, j, k - first, rval)] = line[k]; } } } } free_window(w); return (rval); }
// sets this bitmap to map all variables to the given value // returns true if this causes the bitvector to be modified and false otherwise bool VarBitVector::setToVal(bool val) { VarBitVector::boolPlus newVal(val); return setToVal(newVal); }
// maps the given variable to the given value // returns true if this causes the bitvector to be modified and false otherwise bool VarBitVector::setVar(varID var, bool val) { VarBitVector::boolPlus newVal(val); return setVar(var, newVal); }
/* ** compute_windowed_mean() - computes the mean and count of the pixels ** within a wxh window, using a running-sum table. ** Returns the mean and count for each pixel. */ void init_sums(Var* data, int w, int h, int d, Var** rn, Var** rs, Var** rcount, Var** rmean, Var** rsigma, double ignore) { int x, y, z; int i, j, k; size_t p1, p2, p3, p4, p5, p6, p7, p8; size_t nelements; int east, south, north, west, front, back; double *s, *s2; int* n; float* mean; float* sigma; int* c; double value; double sum, sum2; int count; x = GetX(data); y = GetY(data); z = GetZ(data); nelements = V_DSIZE(data); s = calloc(nelements, sizeof(double)); /* running sum */ s2 = calloc(nelements, sizeof(double)); /* running sum */ n = calloc(nelements, sizeof(int)); /* running count */ mean = calloc(nelements, sizeof(float)); sigma = calloc(nelements, sizeof(float)); c = calloc(nelements, sizeof(int)); /* ** compute the running sum and count of V ** ** s(i,j) = f(i,j) +s(i-1,j)+s(i,j-1)-s(i-1,j-1) */ for (k = 0; k < z; k++) { for (j = 0; j < y; j++) { for (i = 0; i < x; i++) { p1 = cpos(i, j, k, data); value = extract_double(data, p1); if (value != ignore) { s[p1] = value; s2[p1] = value * value; n[p1] = 1; } if (i) { p2 = cpos(i - 1, j, k, data); s[p1] += s[p2]; s2[p1] += s2[p2]; n[p1] += n[p2]; } if (j) { p3 = cpos(i, j - 1, k, data); s[p1] += s[p3]; s2[p1] += s2[p3]; n[p1] += n[p3]; } if (i && j) { p4 = cpos(i - 1, j - 1, k, data); s[p1] -= s[p4]; s2[p1] -= s2[p4]; n[p1] -= n[p4]; } if (k) { p5 = cpos(i, j, k - 1, data); s[p1] += s[p5]; s2[p1] += s2[p5]; n[p1] += n[p5]; if (i) { p6 = cpos(i - 1, j, k - 1, data); s[p1] -= s[p6]; s2[p1] -= s2[p6]; n[p1] -= n[p6]; } if (j) { p7 = cpos(i, j - 1, k - 1, data); s[p1] -= s[p7]; s2[p1] -= s2[p7]; n[p1] -= n[p7]; } if (i && j) { p8 = cpos(i - 1, j - 1, k - 1, data); s[p1] += s[p8]; s2[p1] += s2[p8]; n[p1] += n[p8]; } } } } } /* Formula to compute windowed sum from running sum is: ** s(u,v) = s(u+M-1,v+N-1) - s(u-1,v+N-1) - s(u+M-1,v-1) + s(u-1,v-1) ** This is: sum(pt) = s(se) - s(sw) - s(ne) + s(nw). ** Given a 4x3 mask, it's this: ** ** nw -- -- -- ne ** -- pt -- -- -- ** -- -- -- -- -- ** sw -- -- -- se **/ for (k = 0; k < z; k++) { for (j = 0; j < y; j++) { for (i = 0; i < x; i++) { east = min(i + (w / 2), x - 1); south = min(j + (h / 2), y - 1); front = min(k + (d / 2), z - 1); west = i - (w / 2) - 1; north = j - (h / 2) - 1; back = k - (d / 2) - 1; p1 = cpos(east, south, front, data); count = n[p1]; sum = s[p1]; sum2 = s2[p1]; if (west >= 0) { p2 = cpos(west, south, front, data); count -= n[p2]; sum -= s[p2]; sum2 -= s2[p2]; } if (north >= 0) { p3 = cpos(east, north, front, data); count -= n[p3]; sum -= s[p3]; sum2 -= s2[p3]; } if (north >= 0 && west >= 0) { p4 = cpos(west, north, front, data); count += n[p4]; sum += s[p4]; sum2 += s2[p4]; } if (back >= 0) { p5 = cpos(east, south, back, data); count -= n[p5]; sum -= s[p5]; sum2 -= s2[p5]; if (west >= 0) { p6 = cpos(west, south, back, data); count += n[p6]; sum += s[p6]; sum2 += s2[p6]; } if (north >= 0) { p7 = cpos(east, north, back, data); count += n[p7]; sum += s[p7]; sum2 += s2[p7]; } if (north >= 0 && west >= 0) { p8 = cpos(west, north, back, data); count -= n[p8]; sum -= s[p8]; sum2 -= s2[p8]; } } /* sum = s[cpos(min(i+w-1, x-1), min(j+h-1, y-1), k, data)]; sum -= (i ? s[cpos(i-1, min(j+h-1, y-1), k, data)] : 0.0); sum -= (j ? s[cpos(min(i+w-1, x-1), j-1, k, data)] : 0.0); sum += (i == 0 || j == 0 ? 0.0 : s[cpos(i-1,j-1,k,data)]); */ if (count) { p1 = cpos(i, j, k, data); mean[p1] = sum / count; if (count > 1) { sigma[p1] = sqrt((sum2 - (sum * sum / count)) / (count - 1)); } else { sigma[p1] = ignore; } c[p1] = count; } else { mean[cpos(i, j, k, data)] = ignore; sigma[cpos(i, j, k, data)] = ignore; c[p1] = ignore; } } } } free(s2); *rn = newVal(V_ORG(data), V_SIZE(data)[0], V_SIZE(data)[1], V_SIZE(data)[2], DV_INT32, n); *rs = newVal(V_ORG(data), V_SIZE(data)[0], V_SIZE(data)[1], V_SIZE(data)[2], DV_DOUBLE, s); *rcount = newVal(V_ORG(data), V_SIZE(data)[0], V_SIZE(data)[1], V_SIZE(data)[2], DV_INT32, c); *rmean = newVal(V_ORG(data), V_SIZE(data)[0], V_SIZE(data)[1], V_SIZE(data)[2], DV_FLOAT, mean); *rsigma = newVal(V_ORG(data), V_SIZE(data)[0], V_SIZE(data)[1], V_SIZE(data)[2], DV_FLOAT, sigma); }
/* * Constructs a ResampleForm as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ ResampleForm::ResampleForm( RasterInfo input, RasterInfo output, QWidget* parent, bool modal, Qt::WFlags fl ) : QDialog( parent, fl ) { setModal( modal ); //Keeps it from overly expanding since over riding sizeHint didn't work setMaximumSize( 152, 150 ); if ( objectName().isEmpty() ) setObjectName( "ResampleForm" ); setPalette( RESAMPLEFORM_COLOR ); bytesPerRow = (input.cols() * (input.bitCount() / 8)); ResampleFormLayout = new QVBoxLayout( this ); ResampleFormLayout->setSpacing( 6 ); inputLayout = new QVBoxLayout( 0 ); inputLayout->setSpacing( 6 ); resampleBox = new QGroupBox( this ); resampleBoxLayout = new QVBoxLayout( resampleBox ); resampleBoxLayout->setSpacing( 6 ); resampleBoxLayout->setMargin( 11 ); resampleBoxLayout->setAlignment( Qt::AlignTop ); resampleCombo = new QComboBox( resampleBox ); resampleCombo->setMinimumSize( QSize( 125, 0 ) ); resampleCombo->installEventFilter( this ); resampleBoxLayout->addWidget( resampleCombo ); categoricalLayout = new QHBoxLayout( 0 ); categoricalLayout->setParent( resampleBoxLayout ); resampleBoxLayout->addLayout( categoricalLayout ); catconLabel = new QLabel( "", resampleBox ); conRadio = new QRadioButton( "Continuous Data", resampleBox ); catRadio = new QRadioButton( "Categorical Data", resampleBox ); catconButtonGroup = new QGroupBox( resampleBox ); catconButtonGroup->hide(); QHBoxLayout *catconLayout = new QHBoxLayout( catconButtonGroup ); catconLayout->addWidget( catRadio ); catconLayout->addWidget( conRadio ); categoricalLayout->addWidget( catconLabel ); categoricalLayout->addWidget( conRadio ); categoricalLayout->addWidget( catRadio ); inputLayout->addWidget( resampleBox ); ignoreBox = new QGroupBox( this ); ignoreBoxLayout = new QHBoxLayout( ignoreBox ); ignoreBoxLayout->setSpacing( 6 ); ignoreBoxLayout->setMargin( 11 ); ignoreBoxLayout->setAlignment( Qt::AlignTop ); ignoreLayout = new QVBoxLayout( 0 ); ignoreLayout->setSpacing( 6 ); ignoreLabel = new QLabel( "Ignore values cannot be used if an output \"No Data \nValue\" is not provided.", ignoreBox ); ignoreLabel->hide(); ignoreBoxLayout->addWidget( ignoreLabel ); ignoreEdit = new QLineEdit( ignoreBox ); ignoreEdit->setMinimumSize( QSize( 125, 0 ) ); ignoreEdit->setValidator( new MapimgValidator( output.fullDataType(), ignoreEdit ) ); ignoreLayout->addWidget( ignoreEdit ); newButton = new QPushButton( ignoreBox ); newButton->setAutoDefault( false ); ignoreLayout->addWidget( newButton ); delButton = new QPushButton( ignoreBox ); delButton->setEnabled( false ); delButton->setAutoDefault( false ); ignoreLayout->addWidget( delButton ); ingoreSpacer = new QSpacerItem( 31, 91, QSizePolicy::Minimum, QSizePolicy::Expanding ); ignoreLayout->addItem( ingoreSpacer ); ignoreBoxLayout->addLayout( ignoreLayout ); ignoreListBox = new QListWidget( ignoreBox ); ignoreListBox->setMinimumSize( QSize( 125, 0 ) ); ignoreListBox->installEventFilter( this ); ignoreBoxLayout->addWidget( ignoreListBox ); inputLayout->addWidget( ignoreBox ); if( !output.hasNoDataValue() ) { ignoreLabel->show(); ignoreEdit->hide(); newButton->hide(); delButton->hide(); ignoreListBox->hide(); } ResampleFormLayout->addLayout( inputLayout ); memoryBox = new QGroupBox( this ); memoryBoxLayout = new QVBoxLayout( memoryBox ); memoryBoxLayout->setSpacing( 6 ); memoryBoxLayout->setMargin( 11 ); memoryBoxLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop ); memoryLabelResetLayout = new QHBoxLayout(); memoryLabel = new QLabel( memoryBox ); memoryLabel->setAlignment( Qt::AlignCenter ); memoryResetButton = new QPushButton( "Default", memoryBox ); QFontMetrics metrics( memoryResetButton->font() ); memoryResetButton->setMaximumWidth( metrics.width(memoryResetButton->text()) + (metrics.maxWidth()) ); memoryResetButton->setMaximumHeight( (int)(1.5*metrics.height()) ); memoryResetButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); //DEFAULT_Max_Data_Element_Count is defined in imgio.h //minimum computed as the ratio of output to input plus 2% of the input memoryAllocation = new QSlider( Qt::Horizontal, memoryBox ); memoryAllocation->setMinimum( (int)((output.pixelSize()/input.pixelSize()) + 0.02*(float)input.rows()) ); memoryAllocation->setMaximum( input.rows() ); memoryAllocation->setPageStep( 10 ); memoryAllocation->setValue( DEFAULT_Max_Data_Element_Count ); defaultMemory = memoryAllocation->value(); memoryLabelResetLayout->addWidget( memoryLabel ); memoryLabelResetLayout->addWidget( memoryResetButton ); memoryBoxLayout->addLayout( memoryLabelResetLayout ); memoryBoxLayout->addWidget( memoryAllocation ); inputLayout->addWidget( memoryBox ); okLayout = new QHBoxLayout( 0 ); okLayout->setSpacing( 6 ); okSpacer = new QSpacerItem( 141, 21, QSizePolicy::Expanding, QSizePolicy::Minimum ); okLayout->addItem( okSpacer ); okButton = new QPushButton( this ); okButton->setAutoDefault( false ); okLayout->addWidget( okButton ); cancelButton = new QPushButton( this ); cancelButton->setAutoDefault( false ); cancelButton->setShortcut( Qt::Key_Escape ); okLayout->addWidget( cancelButton ); ResampleFormLayout->addLayout( okLayout ); languageChange(); resize( QSize(300, 218).expandedTo(minimumSizeHint()) ); // clearWState( WState_Polished ); connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); connect( resampleCombo, SIGNAL( activated(const QString&) ), this, SLOT( rcodeChanged(const QString&) ) ); connect( ignoreEdit, SIGNAL( returnPressed() ), this, SLOT( newVal() ) ); connect( ignoreEdit, SIGNAL( returnPressed() ), newButton, SLOT( animateClick() ) ); connect( newButton, SIGNAL( clicked() ), this, SLOT( newVal() ) ); connect( delButton, SIGNAL( clicked() ), this, SLOT( delVal() ) ); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect( memoryAllocation, SIGNAL( valueChanged( int ) ), this, SLOT( updateMemoryAllocation() ) ); connect( memoryResetButton, SIGNAL( clicked() ), this, SLOT( resetMemory() ) ); canceled = false; ilist.clear(); rcodeChanged( resampleCombo->currentText() ); }