void FFTEngine::precalculate(const std::vector<boost::shared_ptr<Instrument> >& optionList) { // Group payoffs by expiry date // as with FFT we can compute a bunch of these at once resultMap_.clear(); typedef std::vector<boost::shared_ptr<StrikedTypePayoff> > PayoffList; typedef std::map<Date, PayoffList> PayoffMap; PayoffMap payoffMap; for (std::vector<boost::shared_ptr<Instrument> >::const_iterator optIt = optionList.begin(); optIt != optionList.end(); optIt++) { boost::shared_ptr<VanillaOption> option = boost::dynamic_pointer_cast<VanillaOption>(*optIt); QL_REQUIRE(option, "instrument must be option"); QL_REQUIRE(option->exercise()->type() == Exercise::European, "not an European Option"); boost::shared_ptr<StrikedTypePayoff> payoff = boost::dynamic_pointer_cast<StrikedTypePayoff>(option->payoff()); QL_REQUIRE(payoff, "non-striked payoff given"); payoffMap[option->exercise()->lastDate()].push_back(payoff); } std::complex<Real> i1(0, 1); Real alpha = 1.25; for (PayoffMap::const_iterator payIt = payoffMap.begin(); payIt != payoffMap.end(); payIt++) { Date expiryDate = payIt->first; // Calculate n large enough for maximum strike, and round up to a power of 2 Real maxStrike = 0.0; for (PayoffList::const_iterator it = payIt->second.begin(); it != payIt->second.end(); it++) { boost::shared_ptr<StrikedTypePayoff> payoff = *it; if (payoff->strike() > maxStrike) maxStrike = payoff->strike(); } Real nR = 2.0 * (std::log(maxStrike) + lambda_) / lambda_; Size log2_n = (static_cast<Size>((std::log(nR) / std::log(2.0))) + 1); Size n = 1 << log2_n; // Strike range (equation 19,20) Real b = n * lambda_ / 2.0; // Grid spacing (equation 23) Real eta = 2.0 * M_PI / (lambda_ * n); // Discount factor Real df = discountFactor(expiryDate); Real div = dividendYield(expiryDate); // Input to fourier transform std::vector<std::complex<Real> > fti; fti.resize(n); // Precalculate any discount factors etc. precalculateExpiry(expiryDate); for (Size i=0; i<n; i++) { Real k_u = -b + lambda_ * i; Real v_j = eta * i; Real sw = eta * (3.0 + ((i % 2) == 0 ? -1.0 : 1.0) - ((i == 0) ? 1.0 : 0.0)) / 3.0; std::complex<Real> psi = df * complexFourierTransform(v_j - (alpha + 1)* i1); psi = psi / (alpha*alpha + alpha - v_j*v_j + i1 * (2 * alpha + 1.0) * v_j); fti[i] = std::exp(i1 * b * v_j) * sw * psi; } // Perform fft std::vector<std::complex<Real> > results(n); FastFourierTransform fft(log2_n); fft.transform(fti.begin(), fti.end(), results.begin()); // Call prices std::vector<Real> prices, strikes; prices.resize(n); strikes.resize(n); for (Size i=0; i<n; i++) { Real k_u = -b + lambda_ * i; prices[i] = (std::exp(-alpha * k_u) / M_PI) * results[i].real(); strikes[i] = std::exp(k_u); } for (PayoffList::const_iterator it = payIt->second.begin(); it != payIt->second.end(); it++) { boost::shared_ptr<StrikedTypePayoff> payoff = *it; Real callPrice = LinearInterpolation(strikes.begin(), strikes.end(), prices.begin())(payoff->strike()); switch (payoff->optionType()) { case Option::Call: resultMap_[expiryDate][payoff] = callPrice; break; case Option::Put: resultMap_[expiryDate][payoff] = callPrice - process_->x0() * div + payoff->strike() * df; break; default: QL_FAIL("Invalid option type"); } } } }
int main() { car c("fred"); roadlet *r1, *r2; roadlet *r3, *r4; char *buff; int i; srandom(5); // build a two lane one direction road r1 = new roadlet ("R start"); r3 = new roadlet ("L start"); connect(r1, W, r3, E, return_null); // there but can't move to c.set_location(r1); // a car r1->arrive(&c); for(i=0; i<10; i++) { buff = (char *)malloc(4); sprintf(buff, "R%d", i); r2 = new roadlet(buff); buff = (char *)malloc(4); sprintf(buff, "L%d", i); r4 = new roadlet(buff); connect(r1, N, r2, S, &is_empty); connect(r3, N, r4, S, &is_empty); connect(r1, NW, r4, SE, &lane_switch_ok); connect(r3, NE, r2, SW, &lane_switch_ok); connect(r2, W, r4, E, return_null); // can't more sideways r1 = r2; r3 = r4; } car b2("blocker 2"); b2.set_location(r1); // a car r1->arrive(&b2); cout << b2 << '\n'; intersection_4x4 i1("intersection "); i1.connectSin(r3, r1); broken_light l(3,1,4,1); for(i = 0; i < 100000; i++) { cout << l << "\n"; l.tick(); } for(i=0; i< 100000; i++) { i1.light()->tick(); } r1 = new roadlet ("East Road R "); r3 = new roadlet ("East Road L "); connect(r1, N, r3, S, return_null); // there but can't move to car b("blocker"); b.set_location(r1); // a car r1->arrive(&b); cout << b << '\n'; i1.connectEout(r3, r1); for(i=0; i< 100000; i++) { cout << '\n' << i << ' ' << c << '\n'; c.tick(); } cout << i << ' ' << c << '\n'; }
void calculateTangents( const void* pVertices, size_t numVertices, uint32 posOff, uint32 texOff, uint32 normOff, uint32 vertStride, const void* pIndices, size_t numIndices, gfx::IndexStride indexStride, he::PrimitiveList<vec3>& outTangents) { he::PrimitiveList<vec3> tan1(numVertices); tan1.resize(numVertices); const char* pCharVertices(static_cast<const char*>(pVertices)); const uint16* indicesUShort(nullptr); const uint32* indicesUInt(nullptr); if (indexStride == gfx::IndexStride_UShort) indicesUShort = static_cast<const uint16*>(pIndices); else if (indexStride == gfx::IndexStride_UInt) indicesUInt = static_cast<const uint32*>(pIndices); else LOG(LogType_ProgrammerAssert, "unkown index stride: %d", indexStride); for (uint32 i = 0; i < numIndices; i += 3) //per triangle { uint32 i1(0), i2(0), i3(0); if (indexStride == gfx::IndexStride_UShort) { i1 = indicesUShort[i]; i2 = indicesUShort[i + 1]; i3 = indicesUShort[i + 2]; } else if (indexStride == gfx::IndexStride_UInt) { i1 = indicesUInt[i]; i2 = indicesUInt[i + 1]; i3 = indicesUInt[i + 2]; } const vec3& v1 = *reinterpret_cast<const vec3*>(pCharVertices + (i1 * vertStride + posOff)); const vec3& v2 = *reinterpret_cast<const vec3*>(pCharVertices + (i2 * vertStride + posOff)); const vec3& v3 = *reinterpret_cast<const vec3*>(pCharVertices + (i3 * vertStride + posOff)); const vec2& tx1 = *reinterpret_cast<const vec2*>(pCharVertices + (i1 * vertStride + texOff)); const vec2& tx2 = *reinterpret_cast<const vec2*>(pCharVertices + (i2 * vertStride + texOff)); const vec2& tx3 = *reinterpret_cast<const vec2*>(pCharVertices + (i3 * vertStride + texOff)); float x1 = v2.x - v1.x; float x2 = v3.x - v1.x; float y1 = v2.y - v1.y; float y2 = v3.y - v1.y; float z1 = v2.z - v1.z; float z2 = v3.z - v1.z; float s1 = tx2.x - tx1.x; float s2 = tx3.x - tx1.x; float t1 = tx2.y - tx1.y; float t2 = tx3.y - tx1.y; float r = 1.0f / (s1 * t2 - s2 * t1); vec3 sdir( (t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r ); vec3 tdir( (s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r ); tan1[i1] += sdir; tan1[i2] += sdir; tan1[i3] += sdir; } for (uint32 i = 0; i < numVertices; ++i) { const vec3& n = *reinterpret_cast<const vec3*>(pCharVertices + (i * vertStride + normOff)); const vec3& t = tan1[i]; outTangents.add(normalize(t - n * dot(n, t))); } }
void MarchingCubeTriangulator::Triangulate(ScalarFieldBuilders::ScalarFieldCreator& inData,const SpatialDiscretization::weight_t& volId, progressOperation& mainProcess) { weigh_parameters_t weigh_parameters; weigh_parameters.volId=volId; BeginFeedingFaces(); ivec3 coordinates; long cellCount_m_one(inData.GetDomainSize()-1); ivec3 i1(1,0,0), i2(1,0,1), i3(0,0,1), i4(0,1,0), i5(1,1,0), i6(1,1,1), i7(0,1,1); PolygoniseAlgo::GRIDCELL grid; PolygoniseAlgo::TRIANGLE triList[5]; int nbtri; progressOperation thisProcess(&mainProcess, (unsigned int) (cellCount_m_one * cellCount_m_one)); for(coordinates.x=0;coordinates.x<cellCount_m_one;coordinates.x++) { for(coordinates.y=0;coordinates.y<cellCount_m_one;coordinates.y++) { progressOperation thisSubProcess(&thisProcess,1); if(VariationWithinFourZ(ivec2(coordinates.x,coordinates.y),inData)) { grid.p[3] = inData.GetCenterCellCoordinates(coordinates+i3); grid.p[2] = inData.GetCenterCellCoordinates(coordinates+i2); grid.p[7] = inData.GetCenterCellCoordinates(coordinates+i7); grid.p[6] = inData.GetCenterCellCoordinates(coordinates+i6); grid.val[3]=WeightEvaluation(inData.GetMatrixValue(coordinates),weigh_parameters); grid.val[2]=WeightEvaluation(inData.GetMatrixValue(coordinates+i1),weigh_parameters); grid.val[7]=WeightEvaluation(inData.GetMatrixValue(coordinates+i4),weigh_parameters); grid.val[6]=WeightEvaluation(inData.GetMatrixValue(coordinates+i5),weigh_parameters); for(coordinates.z=0;coordinates.z<cellCount_m_one;coordinates.z++) { //TODO Computation on x,y loop grid.p[0] = grid.p[3]; grid.p[1] = grid.p[2]; grid.p[4]= grid.p[7]; grid.p[5] = grid.p[6]; grid.p[2] = inData.GetCenterCellCoordinates(coordinates+i2); grid.p[3] = inData.GetCenterCellCoordinates(coordinates+i3); grid.p[6] = inData.GetCenterCellCoordinates(coordinates+i6); grid.p[7] = inData.GetCenterCellCoordinates(coordinates+i7); grid.val[0]=grid.val[3]; grid.val[1]=grid.val[2]; grid.val[4]=grid.val[7]; grid.val[5]=grid.val[6]; grid.val[2]=WeightEvaluation(inData.GetMatrixValue(coordinates+i2),weigh_parameters); grid.val[3]=WeightEvaluation(inData.GetMatrixValue(coordinates+i3),weigh_parameters); grid.val[6]=WeightEvaluation(inData.GetMatrixValue(coordinates+i6),weigh_parameters); grid.val[7]=WeightEvaluation(inData.GetMatrixValue(coordinates+i7),weigh_parameters); nbtri=PolygoniseAlgo::Polygonise(grid,0,triList); if(nbtri>0) { for(int idtri=0;idtri<nbtri;idtri++) { AddFace((const decimal *)&(triList[idtri].p[2]), (const decimal *)&(triList[idtri].p[1]), (const decimal *)&(triList[idtri].p[0])); } } } } } } FinishFeedingFaces(); }
void run () { testcase ("add/traverse"); beast::Journal const j; // debug journal tests::TestFamily f(j); // h3 and h4 differ only in the leaf, same terminal node (level 19) uint256 h1, h2, h3, h4, h5; h1.SetHex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); h2.SetHex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe"); h3.SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8"); h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); SHAMap sMap (SHAMapType::FREE, f, beast::Journal()); SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5)); unexpected (!sMap.addItem (i2, true, false), "no add"); unexpected (!sMap.addItem (i1, true, false), "no add"); std::shared_ptr<SHAMapItem const> i; i = sMap.peekFirstItem (); unexpected (!i || (*i != i1), "bad traverse"); i = sMap.peekNextItem (i->key()); unexpected (!i || (*i != i2), "bad traverse"); i = sMap.peekNextItem (i->key()); unexpected (i, "bad traverse"); sMap.addItem (i4, true, false); sMap.delItem (i2.key()); sMap.addItem (i3, true, false); i = sMap.peekFirstItem (); unexpected (!i || (*i != i1), "bad traverse"); i = sMap.peekNextItem (i->key()); unexpected (!i || (*i != i3), "bad traverse"); i = sMap.peekNextItem (i->key()); unexpected (!i || (*i != i4), "bad traverse"); i = sMap.peekNextItem (i->key()); unexpected (i, "bad traverse"); testcase ("snapshot"); uint256 mapHash = sMap.getHash (); std::shared_ptr<SHAMap> map2 = sMap.snapShot (false); unexpected (sMap.getHash () != mapHash, "bad snapshot"); unexpected (map2->getHash () != mapHash, "bad snapshot"); unexpected (!sMap.delItem (sMap.peekFirstItem ()->key()), "bad mod"); unexpected (sMap.getHash () == mapHash, "bad snapshot"); unexpected (map2->getHash () != mapHash, "bad snapshot"); testcase ("build/tear"); { std::vector<uint256> keys(8); keys[0].SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[1].SetHex ("b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[2].SetHex ("b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[3].SetHex ("b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[4].SetHex ("b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[5].SetHex ("b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[6].SetHex ("f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[7].SetHex ("292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); std::vector<uint256> hashes(8); hashes[0].SetHex ("B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C64B6281F7F"); hashes[1].SetHex ("FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A8831845467FB2ECE266"); hashes[2].SetHex ("4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51AE756795B75"); hashes[3].SetHex ("7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC6C74F93E07"); hashes[4].SetHex ("395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596462B0E3A3E"); hashes[5].SetHex ("D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D98A84D9DDE4"); hashes[6].SetHex ("76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF94361143615"); hashes[7].SetHex ("DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA02BBE7230E5"); SHAMap map (SHAMapType::FREE, f, beast::Journal()); expect (map.getHash() == uint256(), "bad initial empty map hash"); for (int i = 0; i < keys.size(); ++i) { SHAMapItem item (keys[i], IntToVUC (i)); map.addItem (item, true, false); expect (map.getHash() == hashes[i], "bad buildup map hash"); } for (int i = keys.size() - 1; i >= 0; --i) { expect (map.getHash() == hashes[i], "bad teardown hash"); map.delItem (keys[i]); } expect (map.getHash() == uint256(), "bad final empty map hash"); } }
static bool exportFaceGroupToShape( shape_t& shape, const std::vector<float> &in_positions, const std::vector<float> &in_normals, const std::vector<float> &in_texcoords, const std::vector<std::vector<vertex_index> >& faceGroup, const material_t &material, const std::string &name, const bool is_material_seted) { if (faceGroup.empty()) { return false; } // Flattened version of vertex data std::vector<float> positions; std::vector<float> normals; std::vector<float> texcoords; std::map<vertex_index, unsigned int> vertexCache; std::vector<unsigned int> indices; // Flatten vertices and indices for (size_t i = 0; i < faceGroup.size(); i++) { const std::vector<vertex_index>& face = faceGroup[i]; vertex_index i0 = face[0]; vertex_index i1(-1); vertex_index i2 = face[1]; size_t npolys = face.size(); // Polygon -> triangle fan conversion for (size_t k = 2; k < npolys; k++) { i1 = i2; i2 = face[k]; unsigned int v0 = updateVertex(vertexCache, positions, normals, texcoords, in_positions, in_normals, in_texcoords, i0); unsigned int v1 = updateVertex(vertexCache, positions, normals, texcoords, in_positions, in_normals, in_texcoords, i1); unsigned int v2 = updateVertex(vertexCache, positions, normals, texcoords, in_positions, in_normals, in_texcoords, i2); indices.push_back(v0); indices.push_back(v1); indices.push_back(v2); } } // // Construct shape. // shape.name = name; shape.mesh.positions.swap(positions); shape.mesh.normals.swap(normals); shape.mesh.texcoords.swap(texcoords); shape.mesh.indices.swap(indices); if(is_material_seted) { shape.material = material; } else { InitMaterial(shape.material); shape.material.diffuse[0] = 1.f; shape.material.diffuse[1] = 1.f; shape.material.diffuse[2] = 1.f; } return true; }
void bench_front_to_surf ( Flux_Pts front_8, Flux_Pts front_4, Flux_Pts surf_with_fr, Flux_Pts surf_without_fr, Fonc_Num fcarac, bool with_fc, bool test_dil, Pt2di sz ) { Im2D_U_INT1 i1(sz.x,sz.y,0); Im2D_U_INT1 i2(sz.x,sz.y,0); INT dif; if (with_fc) { ELISE_COPY(surf_without_fr,1,i1.out()); ELISE_COPY(i2.all_pts(),fcarac,i2.out()); ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif)); BENCH_ASSERT(dif == 0); } else ELISE_COPY(surf_without_fr,1,i1.out()|i2.out()); Neighbourhood v4 (TAB_4_NEIGH,4); Neighbourhood v8 (TAB_8_NEIGH,8); if (test_dil) { bench_fr_front_to_surf(front_8,i1,v4); bench_fr_front_to_surf(front_4,i2,v8); } ELISE_COPY(i1.all_pts(),1,i1.out()); ELISE_COPY(i1.border(1),0,i1.out()); ELISE_COPY(front_8,0,i1.out()); ELISE_COPY(conc(Pt2di(1,1),sel_func(v4,i1.in()==1)),0,i1.out()); ELISE_COPY(i2.all_pts(),0,i2.out()); ELISE_COPY(surf_without_fr,1,i2.out()); ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif)); BENCH_ASSERT(dif == 0); ELISE_COPY(i1.all_pts(),0,i1.out() | i2.out()); ELISE_COPY(surf_with_fr ,1,i1.out()); ELISE_COPY(surf_without_fr,2,i1.histo()); ELISE_COPY(surf_with_fr ,3,i2.out()); ELISE_COPY(front_8 ,1,i2.out()); ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif)); BENCH_ASSERT(dif == 0); }
static void VbTest() { #if !defined (ACE_WIN32) Vb v1; ACE_ASSERT(v1.valid() == 0); ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v1(\"/\") [%s]\n", v1.to_string())); // purpose of this routine?? set_exception_status( &v1, 10); Vb v2(v1); ACE_ASSERT(v2.valid() == 0); Oid o1("1.2.3"), o2; v2.set_oid(o1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v2(\"1.2.3/\") [%s]\n", v2.to_string())); v2.get_oid(o2); ACE_ASSERT(o2 == o1); ACE_ASSERT(v2.valid() == 0); v2.set_null(); ACE_ASSERT(v2.valid() == 0); v2.get_oid(o2); Vb v3; TimeTicks t(0), t1; v3.set_oid(o1); v3.set_value(t); ACE_ASSERT(v3.valid() == 1); v3.get_value(t1); ACE_ASSERT(t == t1); Vb v4; v4.set_oid(o1); v4.set_value(o1); ACE_ASSERT(v4.valid() == 1); v4.get_value(o2); ACE_ASSERT(o1 == o2); Vb v5; Counter32 c1(12), c2; v5.set_oid(o1); v5.set_value(c1); ACE_ASSERT(v5.valid() == 1); v5.get_value(c2); ACE_ASSERT(c1 == c2); Vb v6; Counter64 c3(12345678901234ULL), c4; v6.set_oid(o1); v6.set_value(c3); ACE_ASSERT(v6.valid() == 1); v6.get_value(c4); ACE_ASSERT(c3 == c4); Vb v7; Gauge32 g1(0123456), g2; v7.set_oid(o1); v7.set_value(g1); ACE_ASSERT(v7.valid() == 1); v7.get_value(g2); ACE_ASSERT(g1 == g2); Vb v8; SnmpInt32 i1(0123456), i2; v8.set_oid(o1); v8.set_value(i1); ACE_ASSERT(v8.valid() == 1); v8.get_value(i2); ACE_ASSERT(i1 == i2); Vb v9; SnmpUInt32 u1(0123456), u2; v9.set_oid(o1); v9.set_value(u1); ACE_ASSERT(v9.valid() == 1); v9.get_value(u2); ACE_ASSERT(u1 == u2); Vb v10; OctetStr s1(" abcdefghighlmnopqrstuvwxyz!@#$%^&*()"), s2; v10.set_oid(o1); v10.set_value(s1); ACE_ASSERT(v10.valid() == 1); v10.get_value(s2); ACE_ASSERT(s1 == s2); ACE_ASSERT(s1.length() == s2.length()); // test assignment over all datatypes v10 = v5; ACE_ASSERT(v10 == v5); Vb v11(o1, s1, SNMP_CLASS_SUCCESS); ACE_ASSERT(v11.valid() == 1); v11.get_oid(o2); ACE_ASSERT(o1 == o2); v11.get_value(s2); ACE_ASSERT(s1 == s2); #endif /*if ACE_WIN32*/ }
int main () try { auto usb = usb_open(); std::shared_ptr<libusb_device_handle> dh = usb_device_get (usb.get(), 0x1130, 0x660c); usb_attach_interface a1 (dh, 0); usb_attach_interface a2 (dh, 1); usb_error::check (libusb_set_configuration (dh.get (), 1)); usb_claim_interface i1 (dh, 0); usb_claim_interface i2 (dh, 1); // init { struct dev_info { uint16_t dev_type; uint8_t cal[2][2]; // OpenBSD repeatedly issues the devtype command until this != 0x53 // Maybe this is necessary if the device has just been plugged in // and has not settled yet? uint8_t footer; } dinfo; msg256 dinfo_raw = read_data (dh, cmd_devtype); std::copy (std::begin(dinfo_raw), std::end(dinfo_raw), reinterpret_cast<unsigned char*> (&dinfo)); //int val; switch (dinfo.dev_type) { case dev_type_temper1: send_cmd (dh, cmd_reset0); /*val = (dinfo.cal[0][0] - 0x14) * 100; val += dinfo.cal[0][1] * 10; std::cerr << "calibration: " << val << std::endl;*/ break; default: throw std::runtime_error ("unknwon device type"); } } // read { msg256 d = read_data (dh, cmd_getdata_inner); // raw values /* std::ostringstream h; h << std::hex << "0x" << int (d[0]) << " 0x" << int (d[1]); std::cout << h.str () << std::endl; std::cout << ((d[0] << 8) + (d[1] & 0xff)) << std::endl; */ // from OpenBSD //std::cout << d[0] * 100 + (d[1] >> 4) * 25 / 4 << std::endl; // easy way std::cout << float (d[0]) + float (d[1])/256 << '\n'; } return EXIT_SUCCESS; } catch (std::exception& e) { std::cerr << "exception: " << e.what () << std::endl; return EXIT_FAILURE; }
void KdeObservatory::updateSources() { kDebug(); setBusy(true); QString commitFrom = ""; QString commitTo = ""; if (m_activityRangeType == 2) { commitFrom = m_commitFrom; commitTo = m_commitTo; } else if (m_activityRangeType == 1) { QDate currentDate = QDate::currentDate(); commitTo = currentDate.toString("yyyyMMdd"); commitFrom = currentDate.addDays(-m_commitExtent).toString("yyyyMMdd"); } m_sourceCounter = 0; uint appletId = id(); QListIterator< QPair<QString, bool> > i (m_activeViews); while (i.hasNext()) { const QPair<QString, bool> &pair = i.next(); if (pair.first == i18n("Top Active Projects") && pair.second) { KConfigGroup ops = m_service->operationDescription("topActiveProjects"); ops.writeEntry("appletId", appletId); ops.writeEntry("commitFrom", commitFrom); ops.writeEntry("commitTo" , commitTo); m_service->startOperationCall(ops); ++m_sourceCounter; } if (pair.first == i18n("Top Developers") && pair.second) { QHashIterator<QString, bool> i1(m_topDevelopersViewProjects); while (i1.hasNext()) { i1.next(); if (i1.value()) { KConfigGroup ops = m_service->operationDescription("topProjectDevelopers"); ops.writeEntry("appletId", appletId); ops.writeEntry("project", i1.key()); ops.writeEntry("commitFrom", commitFrom); ops.writeEntry("commitTo" , commitTo); m_service->startOperationCall(ops); ++m_sourceCounter; } } } if (pair.first == i18n("Commit History") && pair.second) { QHashIterator<QString, bool> i2(m_commitHistoryViewProjects); while (i2.hasNext()) { i2.next(); if (i2.value()) { KConfigGroup ops = m_service->operationDescription("commitHistory"); ops.writeEntry("appletId", appletId); ops.writeEntry("project", i2.key()); ops.writeEntry("commitFrom", commitFrom); ops.writeEntry("commitTo" , commitTo); m_service->startOperationCall(ops); ++m_sourceCounter; } } } if (pair.first == i18n("Krazy Report") && pair.second) { QHashIterator<QString, bool> i3(m_krazyReportViewProjects); while (i3.hasNext()) { i3.next(); if (i3.value() && (m_projects[i3.key()].krazyReport.contains("reports") || m_projects[i3.key()].krazyReport.contains("component="))) { KConfigGroup ops = m_service->operationDescription("krazyReport"); ops.writeEntry("appletId", appletId); ops.writeEntry("project", i3.key()); ops.writeEntry("krazyReport", m_projects[i3.key()].krazyReport); ops.writeEntry("krazyFilePrefix", m_projects[i3.key()].krazyFilePrefix); m_service->startOperationCall(ops); ++m_sourceCounter; } } } } m_collectorProgress->setMaximum(m_sourceCounter); m_collectorProgress->setValue(0); }
void KdeObservatory::saveConfig() { // General properties KConfigGroup configGroup = config(); configGroup.writeEntry("activityRangeType", m_activityRangeType); configGroup.writeEntry("commitExtent", m_commitExtent); configGroup.writeEntry("commitFrom", m_commitFrom); configGroup.writeEntry("commitTo" , m_commitTo); configGroup.writeEntry("enableAutoViewChange", m_enableAutoViewChange); configGroup.writeEntry("viewsDelay", m_viewsDelay); QStringList viewNames; QList<bool> viewActives; QListIterator< QPair<QString, bool> > i1(m_activeViews); while (i1.hasNext()) { const QPair<QString, bool> &pair = i1.next(); viewNames << pair.first; viewActives << pair.second; } configGroup.writeEntry("viewNames", viewNames); configGroup.writeEntry("viewActives", viewActives); // Projects properties QStringList projectNames; QStringList projectCommitSubjects; QStringList projectKrazyReports; QStringList projectKrazyFilePrefix; QStringList projectIcons; QMapIterator<QString, Project> i2(m_projects); while (i2.hasNext()) { i2.next(); const Project &project = i2.value(); projectNames << i2.key(); projectCommitSubjects << project.commitSubject; projectKrazyReports << project.krazyReport; projectKrazyFilePrefix << project.krazyFilePrefix; projectIcons << project.icon; } configGroup.writeEntry("projectNames", projectNames); configGroup.writeEntry("projectCommitSubjects", projectCommitSubjects); configGroup.writeEntry("projectKrazyReports", projectKrazyReports); configGroup.writeEntry("projectKrazyFilePrefix", projectKrazyFilePrefix); configGroup.writeEntry("projectIcons", projectIcons); configGroup.writeEntry("topActiveProjectsViewNames", m_topActiveProjectsViewProjects.keys()); configGroup.writeEntry("topActiveProjectsViewActives", m_topActiveProjectsViewProjects.values()); configGroup.writeEntry("topDevelopersViewNames", m_topDevelopersViewProjects.keys()); configGroup.writeEntry("topDevelopersViewActives", m_topDevelopersViewProjects.values()); configGroup.writeEntry("commitHistoryViewNames", m_commitHistoryViewProjects.keys()); configGroup.writeEntry("commitHistoryViewActives", m_commitHistoryViewProjects.values()); configGroup.writeEntry("krazyReportViewNames", m_krazyReportViewProjects.keys()); configGroup.writeEntry("krazyReportViewActives", m_krazyReportViewProjects.values()); emit configNeedsSaving(); }
Matrix TrackThread::getInterpolatedTensor( int id, float inx, float iny, float inz ) { float x = inx / m_dx; float y = iny / m_dy; float z = inz / m_dz; int x0 = (int) x; int y0 = (int) y; int z0 = (int) z; float xd = x - x0; float yd = y - y0; float zd = z - z0; int id_x0y0z0 = id; int id_x1y0z0 = min( m_blockSize - 1, id + 1 ); int id_x0y1z0 = min( m_blockSize - 1, id + m_nx ); int id_x1y1z0 = min( m_blockSize - 1, id + m_nx + 1 ); int id_x0y0z1 = min( m_blockSize - 1, id + m_nx * m_ny ); int id_x1y0z1 = min( m_blockSize - 1, id + m_nx * m_ny + 1 ); int id_x0y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx ); int id_x1y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx + 1 ); Matrix i1( 3, 3 ); Matrix i2( 3, 3 ); Matrix j1( 3, 3 ); Matrix j2( 3, 3 ); Matrix w1( 3, 3 ); Matrix w2( 3, 3 ); Matrix iv( 3, 3 ); for( int i = 1; i < 4; ++i ) { for ( int j = 1; j < 4; ++j ) { i1( i, j ) = m_logTensors->at( id_x0y0z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x0y0z1 )( i, j ) * zd; i2( i, j ) = m_logTensors->at( id_x0y1z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x0y1z1 )( i, j ) * zd; j1( i, j ) = m_logTensors->at( id_x1y0z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x1y0z1 )( i, j ) * zd; j2( i, j ) = m_logTensors->at( id_x1y1z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x1y1z1 )( i, j ) * zd; } } for( int i = 1; i < 4; ++i ) { for ( int j = 1; j < 4; ++j ) { w1( i, j ) = i1( i, j ) * ( 1.0 - yd ) + i2( i, j ) * yd; w2( i, j ) = j1( i, j ) * ( 1.0 - yd ) + j2( i, j ) * yd; } } for( int i = 1; i < 4; ++i ) { for ( int j = 1; j < 4; ++j ) { iv( i, j ) = w1( i, j ) * ( 1.0 - xd ) + w2( i, j ) * xd; } } return FMath::expT( iv ); }
void CIntersection::ApplyNonconvexIntersection(CSkeleton &skeleton, CVertexList &vl, IntersectionQueue &iq, bool bCheckVertexinCurrentContour) { #ifdef FELKELDEBUG VTLOG("ApplyNonconvexIntersection\n"); #endif #if VTDEBUG // Left and right vertices must always be the same point if (!(m_leftVertex == m_rightVertex)) VTLOG("%s %d Assert failed\n", __FILE__, __LINE__); // Check to see of they are the same data structure RFJ !!! if (!(m_leftVertex->m_ID == m_rightVertex->m_ID)) VTLOG("%s %d Assert failed\n", __FILE__, __LINE__); #endif CVertex *leftPointer, *rightPointer; C3DPoint p; CNumber d3 = CN_INFINITY; d3 = m_leftVertex->NearestIntersection(vl, &leftPointer, &rightPointer, p); if (d3 == CN_INFINITY) return; if (p != m_poi) return; if (!m_leftVertex->VertexInCurrentContour(*leftPointer)) { if (bCheckVertexinCurrentContour) // Temporary hack to disable checking in multiple contour buildings !!!! NEEDS FIXING return; else VTLOG("Vertex in current contour check failed - needs to be fixed - this check is not valid if one (or both?) of the contours is clockwise\n"); } // Left and right vertex are actually the same in this case if (!m_rightVertex->VertexInCurrentContour(*rightPointer)) { if (bCheckVertexinCurrentContour) // Temporary hack to disable checking in multiple contour buildings !!!! NEEDS FIXING return; else VTLOG("Vertex in current contour check failed - needs to be fixed - this check is not valid if one (or both?) of the contours is clockwise\n"); } #ifdef FELKELDEBUG VTLOG("left vertex %d left ptr %d right ptr %d right vertex %d\n", m_leftVertex->m_ID, leftPointer->m_ID, rightPointer->m_ID, m_rightVertex->m_ID); #endif // Treat as a split event CVertex v1 (p, *rightPointer, *m_rightVertex); CVertex v2 (p, *m_leftVertex, *leftPointer); #if VTDEBUG if (!(v1.m_point != C3DPoint(CN_INFINITY, CN_INFINITY, CN_INFINITY))) VTLOG("%s %d Assert failed\n", __FILE__, __LINE__); if (!(v2.m_point != C3DPoint(CN_INFINITY, CN_INFINITY, CN_INFINITY))) VTLOG("%s %d Assert failed\n", __FILE__, __LINE__); #endif m_leftVertex->m_done = true; // i.rightVertex -> done = true; CVertex *newNext1 = m_rightVertex->m_nextVertex; CVertex *newPrev1 = leftPointer->Highest(); v1.m_prevVertex = newPrev1; v1.m_nextVertex = newNext1; vl.push_back(v1); CVertex *v1Pointer = &vl.back(); newPrev1->m_nextVertex = v1Pointer; newNext1->m_prevVertex = v1Pointer; m_rightVertex->m_higher = v1Pointer; CVertex *newNext2 = rightPointer->Highest(); CVertex *newPrev2 = m_leftVertex->m_prevVertex; v2.m_prevVertex = newPrev2; v2.m_nextVertex = newNext2; vl.push_back(v2); CVertex *v2Pointer = &vl.back(); newPrev2->m_nextVertex = v2Pointer; newNext2->m_prevVertex = v2Pointer; m_leftVertex->m_higher = v2Pointer; skeleton.push_back(CSkeletonLine(*m_rightVertex, *v1Pointer)); CSkeletonLine *linePtr = &skeleton.back(); skeleton.push_back(CSkeletonLine(*v1Pointer, *v2Pointer)); CSkeletonLine *auxLine1Ptr = &skeleton.back (); skeleton.push_back(CSkeletonLine(*v2Pointer, *v1Pointer)); CSkeletonLine *auxLine2Ptr = &skeleton.back(); linePtr->m_lower.m_right = m_leftVertex->m_leftSkeletonLine; linePtr->m_lower.m_left = m_leftVertex->m_rightSkeletonLine; v1Pointer->m_rightSkeletonLine = v2Pointer->m_leftSkeletonLine = linePtr; v1Pointer->m_leftSkeletonLine = auxLine1Ptr; v2Pointer->m_rightSkeletonLine = auxLine2Ptr; auxLine1Ptr->m_lower.m_right = auxLine2Ptr; auxLine2Ptr->m_lower.m_left = auxLine1Ptr; if (m_leftVertex->m_leftSkeletonLine) m_leftVertex->m_leftSkeletonLine ->m_higher.m_left = linePtr; if (m_leftVertex->m_rightSkeletonLine) m_leftVertex->m_rightSkeletonLine->m_higher.m_right = linePtr; m_leftVertex->m_advancingSkeletonLine = linePtr; if (newNext1 == newPrev1) { v1Pointer->m_done = true; newNext1->m_done = true; skeleton.push_back(CSkeletonLine(*v1Pointer, *newNext1)); CSkeletonLine *linePtr = &skeleton.back(); linePtr->m_lower.m_right = v1Pointer->m_leftSkeletonLine; linePtr->m_lower.m_left = v1Pointer->m_rightSkeletonLine; linePtr->m_higher.m_right = newNext1->m_leftSkeletonLine; linePtr->m_higher.m_left = newNext1->m_rightSkeletonLine; if (v1Pointer->m_leftSkeletonLine) v1Pointer->m_leftSkeletonLine->m_higher.m_left = linePtr; if (v1Pointer->m_rightSkeletonLine) v1Pointer->m_rightSkeletonLine->m_higher.m_right = linePtr; if (newNext1->m_leftSkeletonLine) newNext1->m_leftSkeletonLine->m_higher.m_left = linePtr; if (newNext1->m_rightSkeletonLine) newNext1->m_rightSkeletonLine->m_higher.m_right = linePtr; } else { CIntersection i1(vl, *v1Pointer); if (i1.m_height != CN_INFINITY) iq.push (i1); } if (newNext2 == newPrev2) { v2Pointer->m_done = true; newNext2 ->m_done = true; skeleton.push_back(CSkeletonLine (*v2Pointer, *newNext2)); CSkeletonLine *linePtr = &skeleton.back(); linePtr->m_lower.m_right = v2Pointer->m_leftSkeletonLine; linePtr->m_lower.m_left = v2Pointer->m_rightSkeletonLine; linePtr->m_higher.m_right = newNext2->m_leftSkeletonLine; linePtr->m_higher.m_left = newNext2->m_rightSkeletonLine; if (v2Pointer->m_leftSkeletonLine) v2Pointer->m_leftSkeletonLine->m_higher.m_left = linePtr; if (v2Pointer->m_rightSkeletonLine) v2Pointer->m_rightSkeletonLine->m_higher.m_right = linePtr; if (newNext2->m_leftSkeletonLine) newNext2 ->m_leftSkeletonLine->m_higher.m_left = linePtr; if (newNext2->m_rightSkeletonLine) newNext2->m_rightSkeletonLine->m_higher.m_right = linePtr; } else { CIntersection i2 (vl, *v2Pointer); if (i2.m_height != CN_INFINITY) iq.push(i2); } }
Matrix TWCThread::getInterpolatedTensor( int &id, float &inx, float &iny, float &inz, float &dirX, float &dirY, float &dirZ ) { float x = inx / m_dx; float y = iny / m_dy; float z = inz / m_dz; int x0 = (int) x; int y0 = (int) y; int z0 = (int) z; float xd = x - x0; float yd = y - y0; float zd = z - z0; int id_x0y0z0 = id; int id_x1y0z0 = min( m_blockSize - 1, id + 1 ); int id_x0y1z0 = min( m_blockSize - 1, id + m_nx ); int id_x1y1z0 = min( m_blockSize - 1, id + m_nx + 1 ); int id_x0y0z1 = min( m_blockSize - 1, id + m_nx * m_ny ); int id_x1y0z1 = min( m_blockSize - 1, id + m_nx * m_ny + 1 ); int id_x0y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx ); int id_x1y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx + 1 ); QVector<Matrix>* lt_x0y0z0 = testAngle( id_x0y0z0, dirX, dirY, dirZ ); QVector<Matrix>* lt_x1y0z0 = testAngle( id_x1y0z0, dirX, dirY, dirZ ); QVector<Matrix>* lt_x0y1z0 = testAngle( id_x0y1z0, dirX, dirY, dirZ ); QVector<Matrix>* lt_x1y1z0 = testAngle( id_x1y1z0, dirX, dirY, dirZ ); QVector<Matrix>* lt_x0y0z1 = testAngle( id_x0y0z1, dirX, dirY, dirZ ); QVector<Matrix>* lt_x1y0z1 = testAngle( id_x1y0z1, dirX, dirY, dirZ ); QVector<Matrix>* lt_x0y1z1 = testAngle( id_x0y1z1, dirX, dirY, dirZ ); QVector<Matrix>* lt_x1y1z1 = testAngle( id_x1y1z1, dirX, dirY, dirZ ); Matrix i1( 3, 3 ); Matrix i2( 3, 3 ); Matrix j1( 3, 3 ); Matrix j2( 3, 3 ); Matrix w1( 3, 3 ); Matrix w2( 3, 3 ); Matrix iv( 3, 3 ); for( int i = 1; i < 4; ++i ) { for ( int j = 1; j < 4; ++j ) { i1( i, j ) = lt_x0y0z0->at( id_x0y0z0 )( i, j ) * ( 1.0 - zd ) + lt_x0y0z1->at( id_x0y0z1 )( i, j ) * zd; i2( i, j ) = lt_x0y1z0->at( id_x0y1z0 )( i, j ) * ( 1.0 - zd ) + lt_x0y1z1->at( id_x0y1z1 )( i, j ) * zd; j1( i, j ) = lt_x1y0z0->at( id_x1y0z0 )( i, j ) * ( 1.0 - zd ) + lt_x1y0z1->at( id_x1y0z1 )( i, j ) * zd; j2( i, j ) = lt_x1y1z0->at( id_x1y1z0 )( i, j ) * ( 1.0 - zd ) + lt_x1y1z1->at( id_x1y1z1 )( i, j ) * zd; } } for( int i = 1; i < 4; ++i ) { for ( int j = 1; j < 4; ++j ) { w1( i, j ) = i1( i, j ) * ( 1.0 - yd ) + i2( i, j ) * yd; w2( i, j ) = j1( i, j ) * ( 1.0 - yd ) + j2( i, j ) * yd; } } for( int i = 1; i < 4; ++i ) { for ( int j = 1; j < 4; ++j ) { iv( i, j ) = w1( i, j ) * ( 1.0 - xd ) + w2( i, j ) * xd; } } return FMath::expT( iv ); }
typename Evaluator::EvalResult csConditionEvaluator::EvaluateInternal ( Evaluator& eval, csConditionID condition) { typedef typename Evaluator::EvalResult EvResult; typedef typename Evaluator::BoolType EvBool; typedef typename Evaluator::FloatType EvFloat; typedef typename Evaluator::IntType EvInt; EvResult result (eval.GetDefaultResult()); CondOperation op = conditions.GetCondition (condition); switch (op.operation) { case opAnd: result = eval.LogicAnd (op.left, op.right); break; case opOr: result = eval.LogicOr (op.left, op.right); break; case opEqual: { if ((op.left.type == operandFloat) || (op.left.type == operandSVValueFloat) || (op.left.type == operandSVValueX) || (op.left.type == operandSVValueY) || (op.left.type == operandSVValueZ) || (op.left.type == operandSVValueW) || (op.right.type == operandFloat) || (op.right.type == operandSVValueX) || (op.right.type == operandSVValueY) || (op.right.type == operandSVValueZ) || (op.right.type == operandSVValueW) || (op.right.type == operandSVValueFloat)) { EvFloat f1 (eval.Float (op.left)); EvFloat f2 (eval.Float (op.right)); result = f1 == f2; } else if (OpTypesCompatible (op.left.type, operandBoolean) && OpTypesCompatible (op.right.type, operandBoolean)) { EvBool b1 (eval.Boolean (op.left)); EvBool b2 (eval.Boolean (op.right)); result = b1 == b2; } else { EvInt i1 (eval.Int (op.left)); EvInt i2 (eval.Int (op.right)); result = i1 == i2; } break; } case opNEqual: { if ((op.left.type == operandFloat) || (op.left.type == operandSVValueFloat) || (op.left.type == operandSVValueX) || (op.left.type == operandSVValueY) || (op.left.type == operandSVValueZ) || (op.left.type == operandSVValueW) || (op.right.type == operandFloat) || (op.right.type == operandSVValueX) || (op.right.type == operandSVValueY) || (op.right.type == operandSVValueZ) || (op.right.type == operandSVValueW) || (op.right.type == operandSVValueFloat)) { EvFloat f1 (eval.Float (op.left)); EvFloat f2 (eval.Float (op.right)); result = f1 != f2; } else if (OpTypesCompatible (op.left.type, operandBoolean) && OpTypesCompatible (op.right.type, operandBoolean)) { EvBool b1 (eval.Boolean (op.left)); EvBool b2 (eval.Boolean (op.right)); result = b1 != b2; } else { EvInt i1 (eval.Int (op.left)); EvInt i2 (eval.Int (op.right)); result = i1 != i2; } break; } case opLesser: { if ((op.left.type == operandFloat) || (op.left.type == operandSVValueFloat) || (op.left.type == operandSVValueX) || (op.left.type == operandSVValueY) || (op.left.type == operandSVValueZ) || (op.left.type == operandSVValueW) || (op.right.type == operandFloat) || (op.right.type == operandSVValueX) || (op.right.type == operandSVValueY) || (op.right.type == operandSVValueZ) || (op.right.type == operandSVValueW) || (op.right.type == operandSVValueFloat)) { EvFloat f1 (eval.Float (op.left)); EvFloat f2 (eval.Float (op.right)); result = (f1 < f2); } else { EvInt i1 (eval.Int (op.left)); EvInt i2 (eval.Int (op.right)); result = i1 < i2; } break; } case opLesserEq: { if ((op.left.type == operandFloat) || (op.left.type == operandSVValueFloat) || (op.left.type == operandSVValueX) || (op.left.type == operandSVValueY) || (op.left.type == operandSVValueZ) || (op.left.type == operandSVValueW) || (op.right.type == operandFloat) || (op.right.type == operandSVValueX) || (op.right.type == operandSVValueY) || (op.right.type == operandSVValueZ) || (op.right.type == operandSVValueW) || (op.right.type == operandSVValueFloat)) { EvFloat f1 (eval.Float (op.left)); EvFloat f2 (eval.Float (op.right)); result = (f1 <= f2); } else { EvInt i1 (eval.Int (op.left)); EvInt i2 (eval.Int (op.right)); result = i1 <= i2; } break; } default: CS_ASSERT (false); } return result; }
bool SkDQuadImplicit::Match(const SkDQuad& quad1, const SkDQuad& quad2) { SkDQuadImplicit i1(quad1); // a'xx , b'xy , c'yy , d'x , e'y , f SkDQuadImplicit i2(quad2); return i1.match(i2); }