//void OccupancyGrid::getVoxelsInBox(const geometry_msgs::Pose &pose, const std::vector<double> &dim, std::vector<btVector3> &voxels) void OccupancyGrid::getVoxelsInBox(const geometry_msgs::Pose &pose, const std::vector<double> &dim, std::vector<Eigen::Vector3d> &voxels) { //btVector3 vin, vout, v(pose.position.x, pose.position.y, pose.position.z); //btMatrix3x3 m(btQuaternion(pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w)); Eigen::Vector3d vin, vout, v(pose.position.x, pose.position.y, pose.position.z); Eigen::Matrix3d m(Eigen::Quaterniond(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z)); for (double x=0-dim[0]/2.0; x<=dim[0]/2.0; x+=grid_resolution_) { for (double y=0-dim[1]/2.0; y<=dim[1]/2.0; y+=grid_resolution_) { for (double z=0-dim[2]/2.0; z<=dim[2]/2.0; z+=grid_resolution_) { /* vin.setX(x); vin.setY(y); vin.setZ(z); vout = m*vin; vout += v; */ vin(0) = (x); vin(1) = (y); vin(2) = (z); vout = m*vin; vout += v; voxels.push_back(vout); } } } }
int main() { VCFInputFile vin("noindex.vcf.gz"); vin.setRangeList("1:0"); int lineNo = 0; while (vin.readRecord()) { lineNo ++; VCFRecord& r = vin.getVCFRecord(); VCFPeople& people = r.getPeople(); VCFIndividual* indv; printf("%s:%d\t", r.getChrom(), r.getPos()); // e.g.: get TAG from INFO field // fprintf(stderr, "%s\n", r.getInfoTag("ANNO")); // e.g.: Loop each (selected) people in the same order as in the VCF for (int i = 0; i < people.size(); i++) { indv = people[i]; // get GT index. if you are sure the index will not change, call this function only once! int GTidx = r.getFormatIndex("GT"); if (GTidx >= 0) printf("%s ", indv->justGet(0).toStr()); // [0] meaning the first field of each individual else fprintf(stderr, "Cannot find GT field!\n"); } printf("\n"); }; fprintf(stdout, "Total %d VCF records have converted successfully\n", lineNo); };
main(int argc, char *argv[]) { node gnd; node n1("n1"); node n2("n2"); node n3("n3"); node n4("n4"); node n5("n5"); node n6("n6"); vdc vcc("vcc", n6, gnd, 5.0); vpulse vin("vin", n1, gnd, 0, 5, 2e-9, 2e-9, 2e-9, 10e-9); r rb1("rb1", n1, n2, 10e3); r rc1("rc1", n6, n3, 1e3); qnd q1("q1", n3, n2, gnd); r rb2("rb2", n3, n4, 10e3); qnd q2("q2", n5, n4, gnd); r rc2("rc2", n6, n5, 1e3); op::monitor = 1; op(); plot::output = *argv; plot::add("n1", "n3", "n5"); tran::tsmin = 1.0e-30; tran::monitor = 1; tran(0.2e-9, 20.0e-9); }
bool GFX::project(const vec3 &obj, const mat4 &modelview_matrix, const mat4 &projection_matrix, const int *viewport_matrix, float *winx, float *winy, float *winz) { vec4 vin(obj, 1.0f), vout; vout = vin * modelview_matrix; vin = vout * projection_matrix; if (!vin->w) return false; vin->x /= vin->w; vin->y /= vin->w; vin->z /= vin->w; vin->x = vin->x * 0.5f + 0.5f; vin->y = vin->y * 0.5f + 0.5f; vin->z = vin->z * 0.5f + 0.5f; vin->x = vin->x * viewport_matrix[2] + viewport_matrix[0]; vin->y = vin->y * viewport_matrix[3] + viewport_matrix[1]; *winx = vin->x; *winy = vin->y; *winz = vin->z; return true; }
bool GFX::unproject(const float winx, const float winy, const float winz, const mat4 &modelview_matrix, const mat4 &projection_matrix, const int *viewport_matrix, vec3 &obj) { vec4 vin(winx, winy, winz, 1.0f); for (int i=0; i<2; ++i) vin[i] = (vin[i] - viewport_matrix[i]) / viewport_matrix[i+2]; for (int i=0; i<3; ++i) vin[i] = vin[i] * 2.0f - 1.0f; // Equivalent to operations on vin above. The operations above // are much more efficient but the operations below give the // reader better insight into what the code is actually doing // mathematically. // TStack l; // // l.translate(vec3(-1.0f, -1.0f, -1.0f)); // l.scale(vec3(2.0f, 2.0f, 2.0f)); // l.scale(vec3(1.0f/viewport_matrix[2], 1.0f/viewport_matrix[3], 1.0f)); // l.translate(vec3(-viewport_matrix[0], -viewport_matrix[1], 0.0f)); // vin *= l.back(); vec4 vout = vin / (modelview_matrix * projection_matrix); return vout->w ? obj=vec3(vout),true : false; }
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags) { entry.pushKV("txid", tx.GetHash().GetHex()); entry.pushKV("hash", tx.GetWitnessHash().GetHex()); entry.pushKV("version", tx.nVersion); entry.pushKV("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)); entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR); entry.pushKV("weight", GetTransactionWeight(tx)); entry.pushKV("locktime", (int64_t)tx.nLockTime); UniValue vin(UniValue::VARR); for (unsigned int i = 0; i < tx.vin.size(); i++) { const CTxIn& txin = tx.vin[i]; UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); else { in.pushKV("txid", txin.prevout.hash.GetHex()); in.pushKV("vout", (int64_t)txin.prevout.n); UniValue o(UniValue::VOBJ); o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); in.pushKV("scriptSig", o); if (!tx.vin[i].scriptWitness.IsNull()) { UniValue txinwitness(UniValue::VARR); for (const auto& item : tx.vin[i].scriptWitness.stack) { txinwitness.push_back(HexStr(item.begin(), item.end())); } in.pushKV("txinwitness", txinwitness); } } in.pushKV("sequence", (int64_t)txin.nSequence); vin.push_back(in); } entry.pushKV("vin", vin); UniValue vout(UniValue::VARR); for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.pushKV("value", ValueFromAmount(txout.nValue)); out.pushKV("n", (int64_t)i); UniValue o(UniValue::VOBJ); ScriptPubKeyToUniv(txout.scriptPubKey, o, true); out.pushKV("scriptPubKey", o); vout.push_back(out); } entry.pushKV("vout", vout); if (!hashBlock.IsNull()) entry.pushKV("blockhash", hashBlock.GetHex()); if (include_hex) { entry.pushKV("hex", EncodeHexTx(tx, serialize_flags)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction". } }
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry) { entry.pushKV("txid", tx.GetId().GetHex()); entry.pushKV("hash", tx.GetHash().GetHex()); entry.pushKV("version", tx.nVersion); entry.pushKV("locktime", (int64_t)tx.nLockTime); UniValue vin(UniValue::VARR); for (unsigned int i = 0; i < tx.vin.size(); i++) { const CTxIn &txin = tx.vin[i]; UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) { in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); } else { in.pushKV("txid", txin.prevout.hash.GetHex()); in.pushKV("vout", (int64_t)txin.prevout.n); UniValue o(UniValue::VOBJ); o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); in.pushKV("scriptSig", o); } in.pushKV("sequence", (int64_t)txin.nSequence); vin.push_back(in); } entry.pushKV("vin", vin); UniValue vout(UniValue::VARR); for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut &txout = tx.vout[i]; UniValue out(UniValue::VOBJ); UniValue outValue(UniValue::VNUM, FormatMoney(txout.nValue.GetSatoshis())); out.pushKV("value", outValue); out.pushKV("n", (int64_t)i); UniValue o(UniValue::VOBJ); ScriptPubKeyToUniv(txout.scriptPubKey, o, true); out.pushKV("scriptPubKey", o); vout.push_back(out); } entry.pushKV("vout", vout); if (!hashBlock.IsNull()) { entry.pushKV("blockhash", hashBlock.GetHex()); } // the hex-encoded transaction. used the name "hex" to be consistent with // the verbose output of "getrawtransaction". entry.pushKV("hex", EncodeHexTx(tx)); }
inline void addvec_simd(F * out, const F in, unsigned int n) { const int per_loop = vec<F>::objects_per_cacheline; vec<F> vin(in); n /= per_loop; do { detail::addvec<F, per_loop>::mp_iteration(out, vin); out += per_loop; } while (--n); }
void OccupancyGrid::getOccupiedVoxels(const geometry_msgs::Pose &pose, const std::vector<double> &dim, std::vector<Eigen::Vector3d> &voxels) { Eigen::Vector3d vin, vout, v(pose.position.x, pose.position.y, pose.position.z); Eigen::Matrix3d m(Eigen::Quaterniond(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z)); for (double x=0-dim[0]/2.0; x<=dim[0]/2.0; x+=grid_->getResolution()) { for (double y=0-dim[1]/2.0; y<=dim[1]/2.0; y+=grid_->getResolution()) { for (double z=0-dim[2]/2.0; z<=dim[2]/2.0; z+=grid_->getResolution()) { vin(0) = (x); vin(1) = (y); vin(2) = (z); vout = m*vin; vout += v; voxels.push_back(vout); } } } }
int loadMarkerFromVCF(const std::string& fileName, const std::string& marker, std::vector<std::string>* rowLabel, Matrix* genotype) { if (!rowLabel || !genotype) { // invalid parameter return -1; } Matrix& m = *genotype; int col = 0; VCFInputFile vin(fileName); vin.setRangeList(marker); while (vin.readRecord()) { VCFRecord& r = vin.getVCFRecord(); VCFPeople& people = r.getPeople(); VCFIndividual* indv; m.Dimension(people.size(), col + 1); int GTidx = r.getFormatIndex("GT"); for (int i = 0; i < (int)people.size(); i++) { indv = people[i]; // get GT index. if you are sure the index will not change, // call this function only once! if (GTidx >= 0) { // printf("%s ", indv->justGet(0).toStr()); // [0] meaning the first // field of each individual m[i][col] = indv->justGet(GTidx).getGenotype(); } else { logger->error("Cannot find GT field!"); return -1; } } if (col == 0) { // set-up names rowLabel->resize(people.size()); for (size_t i = 0; i < people.size(); ++i) { (*rowLabel)[i] = people[i]->getName(); } } std::string colLabel = r.getChrom(); colLabel += ":"; colLabel += r.getPosStr(); m.SetColumnLabel(col, colLabel.c_str()); ++col; } return 0; }
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry) { entry.pushKV("txid", tx.GetHash().GetHex()); entry.pushKV("version", tx.nVersion); entry.pushKV("locktime", (int64_t)tx.nLockTime); UniValue vin(UniValue::VARR); BOOST_FOREACH(const CTxIn& txin, tx.vin) { UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); else { in.pushKV("txid", txin.prevout.hash.GetHex()); in.pushKV("vout", (int64_t)txin.prevout.n); UniValue o(UniValue::VOBJ); o.pushKV("asm", txin.scriptSig.ToString()); o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); in.pushKV("scriptSig", o); } in.pushKV("sequence", (int64_t)txin.nSequence); vin.push_back(in); } entry.pushKV("vin", vin); UniValue vout(UniValue::VARR); for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); UniValue outValue(UniValue::VNUM, FormatMoney(txout.nValue)); out.pushKV("value", outValue); out.pushKV("n", (int64_t)i); UniValue o(UniValue::VOBJ); ScriptPubKeyToUniv(txout.scriptPubKey, o, true); out.pushKV("scriptPubKey", o); vout.push_back(out); } entry.pushKV("vout", vout); if (hashBlock != 0) entry.pushKV("blockhash", hashBlock.GetHex()); }
int main(int argc, char *argv[]) { NODE(gnd); NODE(in); NODE(out); vco vco1("vco1", in, gnd, out, gnd, 1.0, 7.0e6, 30.0e3); r r1 ("r1", out, gnd, 1.0e6); vdc vin("vin", in, gnd, 1.0); op::monitor = 1; kernel::op(); // plot::output = *argv; // plot::add("in", "pll_in", "lf_out", "vco_out"); // // tran::monitor = 1; // tran::tsmin = 1.0e-21; // tran(1.0e-7, 300.0e-6, 0.0, 1.0e-9); }
Vector3 RenderTargetD3D9::project(const Vector3 & v) { //world matrix D3DXMATRIX matWorldD3D ( MappingsD3D9::getMatrix( m_RenderState.m_mtxWorld ) ); //view matrix xs::Matrix4 matView( m_RenderState.m_mtxView ); matView[2][0] = -matView[2][0]; matView[2][1] = -matView[2][1]; matView[2][2] = -matView[2][2]; matView[2][3] = -matView[2][3]; D3DXMATRIX matViewD3D( MappingsD3D9::getMatrix( matView ) ); //projection matrix xs::Matrix4 matProj; convertProjectionMatrix(m_RenderState.m_mtxProjection, matProj, false); D3DXMATRIX matProjD3D( MappingsD3D9::getMatrix( matProj) ); D3DXVECTOR3 vin(v.x, v.y, v.z); D3DXVECTOR3 vout; D3DXVec3Project(&vout, &vin, &m_viewport, &matProjD3D, &matViewD3D, &matWorldD3D); return Vector3(vout.x, vout.y, vout.z); }
// ----------------------------------- void OggVorbisSubStream::procHeaders(Channel *ch) { unsigned int packPtr=0; for(int i=0; i<pack.numPackets; i++) { MemoryStream vin(&pack.body[packPtr],pack.packetSizes[i]); packPtr += pack.packetSizes[i]; char id[8]; vin.read(id,7); id[7]=0; switch (id[0]) { case 1: // ident LOG_CHANNEL("OGG Vorbis Header: Ident (%d bytes)",vin.len); readIdent(vin,ch->info); break; case 3: // comment { LOG_CHANNEL("OGG Vorbis Header: Comment (%d bytes)",vin.len); ChanInfo newInfo = ch->info; readComment(vin,newInfo); ch->updateInfo(newInfo); } break; case 5: // setup LOG_CHANNEL("OGG Vorbis Header: Setup (%d bytes)",vin.len); //readSetup(vin); break; default: throw StreamException("Unknown Vorbis packet header type"); break; } } }
int main(int argc, char** argv){ time_t currentTime = time(0); fprintf(stderr, "Analysis started at: %s", ctime(¤tTime)); //////////////////////////////////////////////// BEGIN_PARAMETER_LIST(pl) ADD_PARAMETER_GROUP(pl, "Input/Output") ADD_STRING_PARAMETER(pl, inVcf, "--inVcf", "input VCF File") ADD_STRING_PARAMETER(pl, outVcf, "--outVcf", "output VCF File") ADD_PARAMETER_GROUP(pl, "Site Filter") ADD_STRING_PARAMETER(pl, site, "--site", "input site file (.rod file: 0-based position)") ADD_BOOL_PARAMETER(pl, inverse, "--inverse", "Inverse site") ADD_STRING_PARAMETER(pl, rangeList, "--rangeList", "Specify some ranges to use, please use chr:begin-end format.") ADD_STRING_PARAMETER(pl, rangeFile, "--rangeFile", "Specify the file containing ranges, please use chr:begin-end format.") ADD_BOOL_PARAMETER(pl, snpOnly, "--snpOnly", "Specify only extract SNP site") END_PARAMETER_LIST(pl) ; pl.Read(argc, argv); pl.Status(); if (FLAG_REMAIN_ARG.size() > 0){ fprintf(stderr, "Unparsed arguments: "); for (unsigned int i = 0; i < FLAG_REMAIN_ARG.size(); i++){ fprintf(stderr, " %s", FLAG_REMAIN_ARG[i].c_str()); } fprintf(stderr, "\n"); abort(); } REQUIRE_STRING_PARAMETER(FLAG_inVcf, "Please provide input file using: --inVcf"); REQUIRE_STRING_PARAMETER(FLAG_outVcf, "Please provide output file using: --outVcf"); const char defaultDbSnp[] = "/net/fantasia/home/zhanxw/amd/data/umake-resources/dbSNP/dbsnp_129_b37.rod.map"; if (FLAG_site == "") { FLAG_site = defaultDbSnp; fprintf(stderr, "Use default dbsnp: [ %s ]\n", defaultDbSnp); } SiteSet snpSet; snpSet.loadRodFile(FLAG_site); fprintf(stderr, "%zu dbSNP sites loaded.\n", snpSet.getTotalSite()); const char* fn = FLAG_inVcf.c_str(); VCFInputFile vin(fn); VCFOutputFile* vout = NULL; // PlinkOutputFile* pout = NULL; if (FLAG_outVcf.size() > 0) { vout = new VCFOutputFile(FLAG_outVcf.c_str()); }; if (vout) vout->writeHeader(vin.getVCFHeader()); // set range filters here // e.g. // vin.setRangeList("1:69500-69600"); vin.setRangeList(FLAG_rangeList.c_str()); vin.setRangeFile(FLAG_rangeFile.c_str()); std::string filt; /// char ref, alt; bool keep; int lineNo = 0; int lineOut = 0; while (vin.readRecord()){ lineNo ++; VCFRecord& r = vin.getVCFRecord(); keep = snpSet.isIncluded(r.getChrom(), r.getPos()); if (FLAG_inverse) { keep = !keep; } if (!keep) continue; if (FLAG_snpOnly) { if ( strlen(r.getRef()) != 1) continue; if ( strlen(r.getAlt()) != 1) continue; if ( r.getAlt()[0] == '.') continue; //deletion e.g. A -> . } if (vout) vout->writeRecord(& r); lineOut ++; }; delete vout; fprintf(stdout, "Total %d VCF records have converted successfully\n", lineNo); fprintf(stdout, "Total %d VCF records have outputted successfully\n", lineOut); currentTime = time(0); fprintf(stderr, "Analysis end at: %s", ctime(¤tTime)); return 0; };
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; bool flag = true; FILE* file; switch (message) { case WM_KEYDOWN: switch (wParam) { case VK_LEFT: for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if (matrix[row][col] == 0 && col < 3 && flag){ matrix[row][col] = matrix[row][col + 1]; matrix[row][col + 1] = 0; flag = false; } } } flag = true; InvalidateRect(hWnd, NULL,true); break; case VK_RIGHT: for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if (matrix[row][col] == 0 && col > 0 && flag){ matrix[row][col] = matrix[row][col - 1]; matrix[row][col - 1] = 0; flag = false; } } } flag = true; InvalidateRect(hWnd, NULL,true); break; case VK_UP: for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if (matrix[row][col] == 0 && row < 3 && flag){ matrix[row][col] = matrix[row + 1][col]; matrix[row + 1][col] = 0; flag = false; } } } flag = true; InvalidateRect(hWnd, NULL,true); break; case VK_DOWN: for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if (matrix[row][col] == 0 && row > 0 && flag){ matrix[row][col] = matrix[row - 1][col]; matrix[row - 1][col] = 0; flag = false; } } } flag = true; InvalidateRect(hWnd, NULL,true); break; default: return DefWindowProc(hWnd, message, wParam, lParam ); break; } vin(hWnd); break; case WM_LBUTTONDOWN: { int xPos = GET_X_LPARAM(lParam); int yPos = GET_Y_LPARAM(lParam); for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if (yPos > row*100+15 && xPos > col*100+15 && yPos < row*100+100 && xPos < col*100+100){ if (matrix[row][col-1] == 0 && col > 0 && flag){ matrix[row][col-1] = matrix[row][col]; matrix[row][col] = 0; flag = false; }else if (matrix[row][col+1] == 0 && col < 3 && flag){ matrix[row][col+1] = matrix[row][col]; matrix[row][col] = 0; flag = false; }else if (matrix[row-1][col] == 0 && row > 0 && flag){ matrix[row-1][col] = matrix[row][col]; matrix[row][col] = 0; flag = false; }else if (matrix[row+1][col] == 0 && row < 3 && flag){ matrix[row+1][col] = matrix[row][col]; matrix[row][col] = 0; flag = false; } } } } flag = true; InvalidateRect(hWnd, NULL,true); } vin(hWnd); break; case WM_SIZE: break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Разобрать выбор в меню: if (wmId == 10000) { for(int i = 0; i < 800; ++i){ v=1; switch(rand()%(4)){ case 0: SendMessage(hWnd, WM_KEYDOWN, VK_RIGHT, 1); UpdateWindow(hWnd); break; case 1: SendMessage(hWnd, WM_KEYDOWN, VK_LEFT, 1); UpdateWindow(hWnd); break; case 2: SendMessage(hWnd, WM_KEYDOWN, VK_UP, 1); UpdateWindow(hWnd); break; case 3: SendMessage(hWnd, WM_KEYDOWN, VK_DOWN, 1); UpdateWindow(hWnd); break; } v=0; //Sleep(100); } MessageBox(hWnd, L"Фсьо, перемішав!", L"", 0); }else if(wmId == 9000 || wmId == IDM_32773){ file = fopen("save", "w"); for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if(matrix[row][col] < 10) fprintf (file, "%d \n", matrix[row][col]); else fprintf (file, "%d\n", matrix[row][col]); } } fclose(file); SetFocus(hWnd); MessageBox(hWnd,L"Гру успішно збережено", L"Файл записано",NULL); }else if(wmId == 8000 || wmId == IDM_32772){ file = fopen("save", "a+"); for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ char s[3]; char ss[3]; s[0]=NULL;s[1]=NULL;s[2]=NULL; fgets(s, 3, file); fgets(ss, 2, file); matrix[row][col] = atoi(s); } } fclose(file); UpdateWindow(hWnd); InvalidateRect(hWnd, NULL,true); SetFocus(hWnd); MessageBox(hWnd,L"Гру відновлено", L"Файл відкрито",NULL); }else if(wmId == IDM_ABOUT){ DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); }else if(wmId == IDM_EXIT){ DestroyWindow(hWnd); }else{ return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); Rectangle(hdc, 5,5,425,425); Rectangle(hdc, 6,6,424,424); Rectangle(hdc, 7,7,423,423); for(int row = 0; row < 4; ++row){ for(int col = 0; col < 4; ++col){ if (matrix[row][col] != 0){ paste_picture(hWnd, hdc, row, col, matrix[row][col]); } } } EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
int main(int argc, char** argv) { time_t currentTime = time(0); fprintf(stderr, "Analysis started at: %s", ctime(¤tTime)); PARSE_PARAMETER(argc, argv); PARAMETER_STATUS(); REQUIRE_STRING_PARAMETER(FLAG_s, "Please provide input file using: -s"); // load referene const char* fn = FLAG_s.c_str(); VCFInputFile vin(fn); StringArray refPeople; vin.getVCFHeader()->getPeopleName(&refPeople); VCFInputFile** compareVcfs = new VCFInputFile*[FLAG_REMAIN_ARG.size()]; StringArray comparePeopleNames; for (unsigned int i = 0; i < FLAG_REMAIN_ARG.size(); i++) { compareVcfs[i] = new VCFInputFile(FLAG_REMAIN_ARG[i]); StringArray names; compareVcfs[i]->getVCFHeader()->getPeopleName(&names); for (unsigned int j = 0; j < names.size(); j++) { comparePeopleNames.push_back(names[j]); }; }; StringArray unionPeopleNames; StringArray commonNames; set_union(comparePeopleNames, &unionPeopleNames); set_intersection(refPeople, unionPeopleNames, &commonNames); vin.excludeAllPeople(); vin.includePeople(commonNames); fprintf(stderr, "Total %d samples are included.\n", (int)commonNames.size()); // set range filters here // e.g. // vin.setRangeList("1:69500-69600"); vin.setRangeList(FLAG_rangeList.c_str()); vin.setRangeFile(FLAG_rangeFile.c_str()); vin.setSiteFile(FLAG_siteFile.c_str()); AllConcordanceType data; loadGenotype(vin, &data, Value::REFERENCE); printf( "File\t" "PeopleId\t" "Overlap\t" "Std_total\t" "Input_total\t" "Std_only\t" "Input_only\t" "nonRefConcord_overlap\t" "Std_variants\t" "Input_variants\t" "Std_variants_in_Input\t" "Ptg_Std_variants_in_Input\t" "HomR/HomR\tHomR/Het\tHomR/HomA\t" "Het/HomR\tHet/Het\tHet/HomA\t" "HomA/HomR\tHomA/Het\tHomA/HomA\n"); for (unsigned int i = 0; i < FLAG_REMAIN_ARG.size(); i++) { fprintf(stderr, "Process %s ... \n", FLAG_REMAIN_ARG[i].c_str()); compareVcfs[i]->setRangeList(FLAG_rangeList.c_str()); compareVcfs[i]->setRangeFile(FLAG_rangeList.c_str()); compareVcfs[i]->setSiteFile(FLAG_siteFile.c_str()); loadGenotype(*compareVcfs[i], &data, Value::COMPARISON); StringArray names; compareVcfs[i]->getVCFHeader()->getPeopleName(&names); printComparision(*compareVcfs[i], data, names); clearGenotype(&data); } for (unsigned int i = 0; i < FLAG_REMAIN_ARG.size(); i++) { delete compareVcfs[i]; } delete[] compareVcfs; currentTime = time(0); fprintf(stderr, "Analysis end at: %s", ctime(¤tTime)); return 0; };
int main(int argc, char** argv) { time_t currentTime = time(0); fprintf(stderr, "Analysis started at: %s", ctime(¤tTime)); PARSE_PARAMETER(argc, argv); PARAMETER_STATUS(); if (FLAG_REMAIN_ARG.size() > 0) { fprintf(stderr, "Unparsed arguments: "); for (unsigned int i = 0; i < FLAG_REMAIN_ARG.size(); i++) { fprintf(stderr, " %s", FLAG_REMAIN_ARG[i].c_str()); } fprintf(stderr, "\n"); abort(); } REQUIRE_STRING_PARAMETER(FLAG_inVcf, "Please provide input file using: --inVcf"); const char* fn = FLAG_inVcf.c_str(); VCFInputFile vin(fn); // set range filters here // e.g. // vin.setRangeList("1:69500-69600"); vin.setRangeList(FLAG_rangeList.c_str()); vin.setRangeFile(FLAG_rangeFile.c_str()); // set people filters here if (FLAG_peopleIncludeID.size() || FLAG_peopleIncludeFile.size()) { vin.excludeAllPeople(); vin.includePeople(FLAG_peopleIncludeID.c_str()); vin.includePeopleFromFile(FLAG_peopleIncludeFile.c_str()); } vin.excludePeople(FLAG_peopleExcludeID.c_str()); vin.excludePeopleFromFile(FLAG_peopleExcludeFile.c_str()); // let's write it out. if (FLAG_updateId != "") { int ret = vin.updateId(FLAG_updateId.c_str()); fprintf(stdout, "%d samples have updated id.\n", ret); } // load gene ranges std::map<std::string, std::string> geneRange; if (FLAG_geneName.size()) { if (FLAG_geneFile.size() == 0) { fprintf(stderr, "Have to provide --geneFile to extract by gene.\n"); abort(); } LineReader lr(FLAG_geneFile); std::vector<std::string> fd; while (lr.readLineBySep(&fd, "\t ")) { if (FLAG_geneName != fd[0]) continue; fd[2] = chopChr(fd[2]); // chop "chr1" to "1" if (geneRange.find(fd[0]) == geneRange.end()) { geneRange[fd[0]] = fd[2] + ":" + fd[4] + "-" + fd[5]; } else { geneRange[fd[0]] += "," + fd[2] + ":" + fd[4] + "-" + fd[5]; } }; } std::string range; for (std::map<std::string, std::string>::iterator it = geneRange.begin(); it != geneRange.end(); it++) { if (range.size() > 0) { range += ","; } range += it->second; }; fprintf(stderr, "range = %s\n", range.c_str()); vin.setRangeList(range.c_str()); Regex regex; if (FLAG_annoType.size()) { regex.readPattern(FLAG_annoType); } // print header std::vector<std::string> names; vin.getVCFHeader()->getPeopleName(&names); printf("CHROM\tPOS"); for (unsigned int i = 0; i < names.size(); i++) { printf("\t%s", names[i].c_str()); } printf("\n"); // real working part int nonVariantSite = 0; while (vin.readRecord()) { VCFRecord& r = vin.getVCFRecord(); VCFPeople& people = r.getPeople(); VCFIndividual* indv; if (FLAG_variantOnly) { bool hasVariant = false; int geno; int GTidx = r.getFormatIndex("GT"); for (size_t i = 0; i < people.size(); i++) { indv = people[i]; geno = indv->justGet(GTidx).getGenotype(); if (geno != 0 && geno != MISSING_GENOTYPE) hasVariant = true; } if (!hasVariant) { nonVariantSite++; continue; } } if (FLAG_annoType.size()) { bool isMissing = false; const char* tag = r.getInfoTag("ANNO", &isMissing).toStr(); if (isMissing) continue; // fprintf(stdout, "ANNO = %s", tag); bool match = regex.match(tag); // fprintf(stdout, " %s \t", match ? "match": "noMatch"); // fprintf(stdout, " %s \n", exists ? "exists": "missing"); if (!match) { continue; } } fprintf(stdout, "%s\t%s", r.getChrom(), r.getPosStr()); for (size_t i = 0; i < people.size(); i++) { indv = people[i]; fprintf(stdout, "\t%d", indv->justGet(0).getGenotype()); } fprintf(stdout, "\n"); }; currentTime = time(0); fprintf(stderr, "Analysis ends at: %s", ctime(¤tTime)); return 0; };
/* Insert one or more shallow copies of a block (created by DXFBlock as * Transform Group) into a layer (created by DXFLayer as MaterialGroup) or * another block. * \todo * Could there be a INSERT inside a block referring to another block which has * not been read yet? We then have to find a solution to enable deferred * instantiation of INSERT entities :-( */ DXFResult DXFInsert::endEntity(void) { NodeUnrecPtr ctrafoNodeP = NULL; // ComponentTransformUnrecPtr ctrafoCoreP = NULL; TransformUnrecPtr ctrafoCoreP = NULL; NodeUnrecPtr blockNodeP = NULL; Node *parentNodeP = getParentNode(); StringToNodePtrMap::iterator itr = _blocksMapP->find(_blockName); if (itr != _blocksMapP->end() && parentNodeP != NULL) { blockNodeP = itr->second; // TODO: check fetched INSERT Data for consistency! // Insert multiple times in a grid... Vec3f offset(0.0, 0.0, 0.0); for(Int16 column = 0; column < _columnCount; ++ column) { offset[0] = column * _columnSpacing; for(Int16 row = 0; row < _rowCount; ++ row) { offset[1] = row * _rowSpacing; // TODO: find out about DXF insert semantics! ctrafoNodeP = Node::create(); ctrafoCoreP = Transform::create(); #if 0 beginEditCP(ctrafoCoreP); #endif { if(_blockName == std::string("Rectangular Mullion - 64 x 128 rectangular-V1-Level 1")) { std::cout << blockNodeP->getNChildren() << std::endl; } OSG::TransformationMatrix<Real32> transMat; transMat.setIdentity(); transMat.setTranslate(_insertionPoint + offset); OSG::TransformationMatrix<Real32> rotMat; rotMat.setIdentity(); OSG::Quaternion rot(OSG::Vec3f(0,0,1),osgDegree2Rad(_rotationAngle)); rotMat.setRotate(rot); OSG::TransformationMatrix<Real32> scaleMat; scaleMat.setIdentity(); scaleMat.setScale(_scaleFactor); OSG::Vec3f vin(-40, 65, 0); OSG::Vec3f vout; transMat.mult(rotMat); transMat.mult(scaleMat); if(_extrusionDirection[2]<0) { transMat[0][0] *= -1.0; transMat[1][0] *= -1.0; transMat[2][0] *= -1.0; transMat[3][0] *= -1.0; } ctrafoCoreP->setMatrix(transMat); } #if 0 endEditCP(ctrafoCoreP); #endif #if 0 beginEditCP(ctrafoNodeP); #endif { ctrafoNodeP->setCore(ctrafoCoreP); #if 0 ctrafoNodeP->addChild(blockNodeP->clone()); #endif NodeUnrecPtr pClone = cloneTree(blockNodeP); ctrafoNodeP->addChild(pClone); } #if 0 endEditCP(ctrafoNodeP); #endif #if 0 beginEditCP(parentNodeP); #endif { parentNodeP->addChild(ctrafoNodeP); } #if 0 endEditCP(parentNodeP); #endif } } // Warn for details not implemented or assured yet! TODO: better // implement missing features! /*if(fabs(_rotationAngle) > Eps) FWARNING(("DXF Loader: before line %d: " "DXFInsert does not yet support ROTATION " "(group code 50). " "Most likely the graphics are incorrect!\n", DXFRecord::getLineNumber() ));*/ /*if(_scaleFactor != Vec3f(1.0,1.0,1.0)) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret SCALING " "(group codes 41, 42, 43) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() ));*/ if(_columnCount != 1 || _rowCount != 1) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret REPEATED INSERTION " "(group codes 70, 71, 44, 45) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() )); } else { if(itr == _blocksMapP->end()) FWARNING(("DXF Loader: before line %d (inside %s section): " "BLOCK '%s' to be inserted not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _blockName.c_str() )); if(parentNodeP == NULL) FWARNING(("DXF Loader: before line %d (inside %s section): " "layer %s to be inserted to not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _layerName.c_str() )); } //set back to default value; _insertionPoint.setNull(), _scaleFactor[0]=_scaleFactor[1]=_scaleFactor[2]=1.0; _rotationAngle=0.0; _columnCount=1; _rowCount=1; _columnSpacing=0.0; _rowSpacing=0.0; _extrusionDirection[0]=0; _extrusionDirection[1]=0; _extrusionDirection[2]=1; return DXFStateContinue; }
int main(int argc, char* argv[]) { { std::string fn = "all.anno.filtered.extract.bcf.gz"; std::string r = "1:196621007-196716634"; VCFExtractor vin(fn); vin.setRangeList(r); printf("Extract two sites\n"); vin.setAnnoType("Nonsynonymous"); while (vin.readRecord()) { VCFRecord& r = vin.getVCFRecord(); VCFPeople& people = r.getPeople(); VCFIndividual* indv; printf("%s:%d\n", r.getChrom(), r.getPos()); } } if (false) { // this code demonstrate how to temporarily close stdout int fd = STDOUT_FILENO; int dupFd = dup(fileno(stdout)); stdout = fdopen(dupFd, "w"); assert(stdout); assert(dupFd > 0); printf("before stdout, fd = %d, dupFd = %d\n", fd, dupFd); fclose(stdout); printf("after stdout\n"); return 0; } const char* fn = "test.bcf.gz"; { BCFReader tr(fn); int n = 0; std::string line; while (tr.readLine(&line)) { // printf("line %d = [ %s ]\n", n, line.c_str()); ++n; } fprintf(stdout, "Read %d lines\n", n); assert(n == 14); // without header lines } { BCFReader tr(fn); tr.addRange("1:196341181-196341254"); int n = 0; std::string line; while (tr.readLine(&line)) { // printf("line %d = [ %s ]\n", n, line.c_str()); ++n; } fprintf(stdout, "Read %d lines\n", n); assert(n == 2); } { BCFReader tr(fn); tr.addRange("1:196341857-196341857"); tr.addRange("1:196341181-196341254"); int n = 0; std::string line; while (tr.readLine(&line)) { // printf("line %d = [ %s ]\n", n, line.c_str()); ++n; } fprintf(stdout, "Read %d lines\n", n); // assert ( n == 3) ; } { BCFReader tr(fn); tr.addRange("2:196341857-196341857"); tr.addRange("2:196341181-196341254"); int n = 0; std::string line; while (tr.readLine(&line)) { printf("line %d = [ %s ]\n", n, line.c_str()); ++n; } fprintf(stdout, "Read %d lines\n", n); // assert ( n == 0) ; } { BCFReader tr(fn); std::string h = tr.getHeader().c_str(); int count = 0; for (size_t i = 0; i < h.size(); ++i) { if (h[i] == '\n') count++; } fprintf(stdout, "header has %d lines.\n", count); assert(count == 60); } return 0; }
inline void addvec_simd(F * out, const F in) { vec<F> vin(in); detail::addvec<F, n>::mp_iteration(out, vin); }
int main(int argc, char** argv){ time_t currentTime = time(0); fprintf(stderr, "Analysis started at: %s", ctime(¤tTime)); //////////////////////////////////////////////// BEGIN_PARAMETER_LIST(pl) ADD_PARAMETER_GROUP(pl, "Input/Output") ADD_STRING_PARAMETER(pl, inVcf, "--inVcf", "input VCF File") ADD_STRING_PARAMETER(pl, outMerlin, "--outMerlin", "output prefix") ADD_PARAMETER_GROUP(pl, "People Filter") ADD_STRING_PARAMETER(pl, peopleIncludeID, "--peopleIncludeID", "give IDs of people that will be included in study") ADD_STRING_PARAMETER(pl, peopleIncludeFile, "--peopleIncludeFile", "from given file, set IDs of people that will be included in study") ADD_STRING_PARAMETER(pl, peopleExcludeID, "--peopleExcludeID", "give IDs of people that will be included in study") ADD_STRING_PARAMETER(pl, peopleExcludeFile, "--peopleExcludeFile", "from given file, set IDs of people that will be included in study") ADD_PARAMETER_GROUP(pl, "Site Filter") ADD_STRING_PARAMETER(pl, rangeList, "--rangeList", "Specify some ranges to use, please use chr:begin-end format.") ADD_STRING_PARAMETER(pl, rangeFile, "--rangeFile", "Specify the file containing ranges, please use chr:begin-end format.") END_PARAMETER_LIST(pl) ; pl.Read(argc, argv); pl.Status(); if (FLAG_REMAIN_ARG.size() > 0){ fprintf(stderr, "Unparsed arguments: "); for (unsigned int i = 0; i < FLAG_REMAIN_ARG.size(); i++){ fprintf(stderr, " %s", FLAG_REMAIN_ARG[i].c_str()); } fprintf(stderr, "\n"); abort(); } REQUIRE_STRING_PARAMETER(FLAG_inVcf, "Please provide input file using: --inVcf"); const char* fn = FLAG_inVcf.c_str(); VCFInputFile vin(fn); // set range filters here // e.g. // vin.setRangeList("1:69500-69600"); vin.setRangeList(FLAG_rangeList.c_str()); vin.setRangeFile(FLAG_rangeFile.c_str()); // set people filters here if (FLAG_peopleIncludeID.size() || FLAG_peopleIncludeFile.size()) { vin.excludeAllPeople(); vin.includePeople(FLAG_peopleIncludeID.c_str()); vin.includePeopleFromFile(FLAG_peopleIncludeFile.c_str()); } vin.excludePeople(FLAG_peopleExcludeID.c_str()); vin.excludePeopleFromFile(FLAG_peopleExcludeFile.c_str()); // let's write it out. FILE* fMap; // CHROMOSOME MARKER POSITION FILE* fDat; // A some_disease\n // T some_trait // M some_marker // M another_marker FILE* fPed; // first 5 column: FID, IID, PID, MID, SEX; then follow Dat file FILE* fPid; // Person ID file, (extra for Merlin), including all people ID as they are in PED file. fMap = fopen( (FLAG_outMerlin + ".map").c_str(), "wt"); fDat = fopen( (FLAG_outMerlin + ".dat").c_str(), "wt"); fPed = fopen( (FLAG_outMerlin + ".ped").c_str(), "wt"); fPid = fopen( (FLAG_outMerlin + ".pid").c_str(), "wt"); assert(fMap && fDat && fPed && fPid); std::string marker; // marker x people std::vector<std::string> allMarker; Matrix geno; fputs("CHROMOSOME\tMARKER\tPOSITION\n", fMap); while (vin.readRecord()){ VCFRecord& r = vin.getVCFRecord(); VCFPeople& people = r.getPeople(); VCFIndividual* indv; // write map file marker = r.getID(); if ( marker == "." ) { fprintf(fMap, "%s\t%s:%d\t%d\n", r.getChrom(), r.getChrom(), r.getPos(), r.getPos()); fprintf(fDat, "M\t%s:%d\n", r.getChrom(), r.getPos()); } else { fprintf(fMap, "%s\t%s\t%d\n", r.getChrom(), marker.c_str(), r.getPos()); fprintf(fDat, "M\t%s\n", marker.c_str()); } allMarker.push_back(marker); geno.Dimension(allMarker.size(), people.size()); // e.g.: get TAG from INFO field // fprintf(stderr, "%s\n", r.getInfoTag("ANNO")); int m = allMarker.size() - 1; // e.g.: Loop each (selected) people in the same order as in the VCF for (int i = 0; i < people.size(); i++) { indv = people[i]; // get GT index. if you are sure the index will not change, call this function only once! int GTidx = r.getFormatIndex("GT"); if (GTidx >= 0) { geno[m][i] = (*indv)[GTidx].getGenotype(); }else { fprintf(stderr, "Cannot find GT field!\n"); abort(); } } }; VCFHeader* h = vin.getVCFHeader(); std::vector< std::string> peopleId; h->getPeopleName(&peopleId); // dump PED and PID file for (int p = 0; p < peopleId.size(); p++){ fprintf(fPed, "%s\t%s\t0\t0\t0", peopleId[p].c_str(), peopleId[p].c_str()); for (int m = 0; m < allMarker.size(); m++){ int g = (int)geno[m][p]; switch (g){ case 0: fputs("\t0/0", fPed); break; case 1: fputs("\t0/1", fPed); break; case 2: fputs("\t1/1", fPed); break; default: fputs("x/x", fPed); break; } } fputs("\n", fPed); fprintf(fPid, "%s\n", peopleId[p].c_str()); } return 0; };
bool VLFeat::CalculateCommon(int f, bool all, int l) { string msg = "VLFeat::CalculateCommon("+ToStr(f)+","+ToStr(all)+","+ ToStr(l)+") : "; // if (!do_fisher && !do_vlad) { // cerr << msg // << "either encoding=fisher or encoding=vlad should be specified" // << endl; // return false; // } if (!gmm && !kmeans) { cerr << msg << "either gmm=xxx or kmeans=xxx option should be given" << endl; return false; } cox::tictac::func tt(tics, "VLFeat::CalculateCommon"); // obs! only some parameters here, should be in ProcessOptionsAndRemove() // too, also scales and geometry should be made specifiable... bool normalizeSift = false, renormalize = true, flat_window = true; size_t step = 3, binsize = 8; EnsureImage(); int width = Width(true), height = Height(true); if (FrameVerbose()) cout << msg+"wxh=" << width << "x" << height << "=" << width*height << endl; vector<float> rgbcoeff { 0.2989, 0.5870, 0.1140 }; imagedata idata = CurrentFrame(); idata.convert(imagedata::pixeldata_float); idata.force_one_channel(rgbcoeff); vector<float> dsift; size_t descr_size_orig = 0, descr_size_final = 0; vector<float> scales { 1.0000, 0.7071, 0.5000, 0.3536, 0.2500 }; // vector<float> scales { 1.0000 }; for (size_t i=0; i<scales.size(); i++) { if (KeyPointVerbose()) cout << "Starting vl_dsift_process() in scale " << scales[i] << endl; imagedata simg = idata; if (scales[i]!=1) { scalinginfo si(simg.width(), simg.height(), (int)floor(scales[i]*simg.width()+0.5), (int)floor(scales[i]*simg.height()+0.5)); simg.rescale(si, 1); } // VlDsiftFilter *sf = vl_dsift_new(simg.width(), simg.height()); VlDsiftFilter *sf = vl_dsift_new_basic(simg.width(), simg.height(), step, binsize); // opts.scales = logspace(log10(1), log10(.25), 5) ; // void vl_dsift_set_bounds ( VlDsiftFilter * self, // int minX, // int minY, // int maxX, // int maxY // ); // VlDsiftDescriptorGeometry geom = { 8, 4, 4, 0, 0 }; // vl_dsift_set_geometry(sf, &geom); //vl_dsift_set_steps(sf, 3, 3); //vl_dsift_set_window_size(sf, 8); vl_dsift_set_flat_window(sf, flat_window); // aka fast in matlab vector<float> imgvec = simg.get_float(); const float *img_fp = &imgvec[0]; // cout << "IMAGE = " << img_fp[0] << " " << img_fp[1] << " " // << img_fp[2] << " ... " << img_fp[41] << endl; vl_dsift_process(sf, img_fp); // if opts.rootSift // false // descrs{si} = sqrt(descrs{si}) ; // end // if opts.normalizeSift //true // descrs{si} = snorm(descrs{si}) ; // end descr_size_orig = sf->descrSize; size_t nf = sf->numFrames; const VlDsiftKeypoint *k = sf->frames; float *d = sf->descrs; if (KeyPointVerbose()) cout << " found " << sf->numFrames << " 'frames' in " << simg.info() << endl << " descriptor dim " << descr_size_orig << endl; if (PixelVerbose()) for (size_t i=0; i<nf; i++) { cout << " i=" << i << " x=" << k[i].x << " y=" << k[i].y << " s=" << k[i].s << " norm=" << k[i].norm; if (FullVerbose()) { cout << " RAW"; for (size_t j=0; j<descr_size_orig; j++) cout << " " << d[i*descr_size_orig+j]; } cout << endl; } if (normalizeSift) { for (size_t i=0; i<nf; i++) { if (PixelVerbose()) cout << " i=" << i << " x=" << k[i].x << " y=" << k[i].y << " s=" << k[i].s << " norm=" << k[i].norm; double mul = 0.0; for (size_t j=0; j<descr_size_orig; j++) mul += d[i*descr_size_orig+j]*d[i*descr_size_orig+j]; if (mul) mul = 1.0/sqrt(mul); if (FullVerbose()) cout << " NORM"; for (size_t j=0; j<descr_size_orig; j++) { d[i*descr_size_orig+j] *= mul; if (FullVerbose()) cout << " " << d[i*descr_size_orig+j]; } if (PixelVerbose()) cout << endl; } } if (!pca.vector_length()) { dsift.insert(dsift.end(), d, d+nf*descr_size_orig); descr_size_final = descr_size_orig; } else { for (size_t i=0; i<nf; i++) { vector<float> vin(d+i*descr_size_orig, d+(i+1)*descr_size_orig); vector<float> vout = pca.projection_coeff(vin); dsift.insert(dsift.end(), vout.begin(), vout.end()); } descr_size_final = pca.base_size(); } vl_dsift_delete(sf); } size_t numdata = dsift.size()/descr_size_final; const float *datain = &dsift[0]; vector<float> enc((do_fisher?2:1)*descriptor_dim()*nclusters()); float *dataout = &enc[0]; if (do_fisher) { if (FrameVerbose()) cout << msg << "fisher encoding " << numdata << " descriptors of size " << descr_size_orig << " => " << descr_size_final << " with gmm dimensionality " << descriptor_dim() << endl; if (descr_size_final!=descriptor_dim()) { cerr << msg << "dimensionality mismatch descr_size_final=" << descr_size_final << " descriptor_dim()=" << descriptor_dim() << endl; return false; } vl_fisher_encode(dataout, VL_TYPE_FLOAT, means(), descriptor_dim(), nclusters(), covariances(), priors(), datain, numdata, VL_FISHER_FLAG_IMPROVED) ; } if (do_vlad) { //obs! correct use of pca? if (FrameVerbose()) cout << msg << "vlad encoding " << numdata << " descriptors of size " << descr_size_final << endl; vector<vl_uint32> indexes(numdata); vector<float> distances(numdata); if (kdtree) vl_kdforest_query_with_array(kdtree, &indexes[0], 1, numdata, &distances[0], datain); else vl_kmeans_quantize(kmeans, &indexes[0], &distances[0], datain, numdata); vector<float> assignments(numdata*nclusters()); for (size_t i=0; i<numdata; i++) assignments[i * nclusters() + indexes[i]] = 1; int vlad_flags = VL_VLAD_FLAG_SQUARE_ROOT|VL_VLAD_FLAG_NORMALIZE_COMPONENTS; vl_vlad_encode(dataout, VL_TYPE_FLOAT, means(), descriptor_dim(), nclusters(), datain, numdata, &assignments[0], vlad_flags); } if (renormalize) { if (PixelVerbose()) cout << " RENORM:"; double mul = 0.0; for (size_t j=0; j<enc.size(); j++) mul += enc[j]*enc[j]; if (mul) mul = 1.0/sqrt(mul); for (size_t j=0; j<enc.size(); j++) { if (PixelVerbose()) cout << " " << enc[j]; enc[j] *= mul; if (PixelVerbose()) cout << "->" << enc[j]; } if (PixelVerbose()) cout << endl; } ((VectorData*)GetData(0))->setVector(enc); return true; }
quint64 Helpers::toQUInt64(const QJsonValue& jv) { std::string hexStr = jv.toString("0x0").remove(0, 2).toStdString(); BigInt::Vin vin(hexStr, 16); return vin.toUlong(); }