void VortexTransition::LoadFromFile(const std::string& dataname, int ts, int tl) { _ts = ts; _tl = tl; for (int i=ts; i<ts+tl-1; i++) { std::stringstream ss; ss << dataname << ".match." << i << "." << i+1; VortexTransitionMatrix tm; if (!tm.LoadFromFile(ss.str())) { fprintf(stderr, "cannot open file %s\n", ss.str().c_str()); tm.SetToDummy(); } _matrices.insert(std::make_pair(i, tm)); _nvortices_per_frame[i] = tm.n0(); _nvortices_per_frame[i+1] = tm.n1(); } _max_nvortices_per_frame = 0; for (std::map<int, int>::iterator it = _nvortices_per_frame.begin(); it != _nvortices_per_frame.end(); it ++) { _max_nvortices_per_frame = std::max(_max_nvortices_per_frame, it->second); } // fprintf(stderr, "max_nvortices_per_frame=%d\n", _max_nvortices_per_frame); }
void VortexTransition::ConstructSequence() { for (int i=_ts; i<_ts+_tl-1; i++) { // fprintf(stderr, "=====t=%d\n", i); VortexTransitionMatrix tm = Matrix(i); assert(tm.Valid()); if (i == _ts) { // initial for (int k=0; k<tm.n0(); k++) { int gid = NewVortexSequence(i); _seqs[gid].tl ++; _seqs[gid].lids.push_back(k); _seqmap[std::make_pair(i, k)] = gid; _invseqmap[std::make_pair(i, gid)] = k; } } for (int k=0; k<tm.NModules(); k++) { int event; std::set<int> lhs, rhs; tm.GetModule(k, lhs, rhs, event); if (lhs.size() == 1 && rhs.size() == 1) { // ordinary case int l = *lhs.begin(), r = *rhs.begin(); int gid = _seqmap[std::make_pair(i, l)]; _seqs[gid].tl ++; _seqs[gid].lids.push_back(r); _seqmap[std::make_pair(i+1, r)] = gid; _invseqmap[std::make_pair(i+1, gid)] = r; } else { // some events, need re-ID for (std::set<int>::iterator it=rhs.begin(); it!=rhs.end(); it++) { int r = *it; int gid = NewVortexSequence(i+1); _seqs[gid].tl ++; _seqs[gid].lids.push_back(r); _seqmap[std::make_pair(i+1, r)] = gid; _invseqmap[std::make_pair(i+1, gid)] = r; } } // build events // if (event >= VORTEX_EVENT_MERGE) { if (event > VORTEX_EVENT_DUMMY) { VortexEvent e; e.frame = i; e.type = event; e.lhs = lhs; e.rhs = rhs; _events.push_back(e); } } } // RandomColorSchemes(); SequenceGraphColoring(); }
static void compute_moving_speed( int f0, int f1, std::vector<VortexLine>& vlines0, // moving speed will be written in vlines const std::vector<VortexLine>& vlines1, const VortexTransitionMatrix& mat) { int event; std::set<int> lhs, rhs; for (int i=0; i<mat.NModules(); i++) { mat.GetModule(i, lhs, rhs, event); if (event != VORTEX_EVENT_DUMMY) continue; // cannot compute moving speed for events const int llvid = *lhs.begin(), rlvid = *rhs.begin(); const float A = AreaL(vlines0[llvid], vlines1[rlvid]); vlines0[llvid].moving_speed = A; // fprintf(stderr, "f0=%d, f1=%d, llvid=%d, rlvid=%d, A=%f\n", // f0, f1, llvid, rlvid, A); } }
void operator()(tbb::flow::continue_msg) const { const vfgpu_hdr_t& hdr0 = hdrs_all[f0], hdr1 = hdrs_all[f1]; GLHeader h0 = conv_hdr(cfg, hdr0), h1 = conv_hdr(cfg, hdr1); const std::vector<vfgpu_pf_t>& pfs0 = pfs_all[f0], pfs1 = pfs_all[f1]; const std::vector<vfgpu_pe_t>& pes = pes_all[interval]; const std::vector<VortexObject>& vobjs0 = vobjs_all[f0], vobjs1 = vobjs_all[f1]; std::vector<VortexLine>& vlines0 = vlines_all[f0], vlines1 = vlines_all[f1]; GLGPU3DDataset *ds = new GLGPU3DDataset; ds->SetHeader(h0); ds->SetMeshType(cfg.meshtype); ds->BuildMeshGraph(); VortexExtractor *ex = new VortexExtractor; ex->SetDataset(ds); for (int i=0; i<pfs0.size(); i++) { const vfgpu_pf_t &pf = pfs0[i]; int chirality = pf.fid_and_chirality & 0x80000000 ? 1 : -1; int fid = pf.fid_and_chirality & 0x7fffffff; ex->AddPuncturedFace(fid, 0, chirality, pf.pos); } for (int i=0; i<pfs1.size(); i++) { const vfgpu_pf_t &pf = pfs1[i]; int chirality = pf.fid_and_chirality & 0x80000000 ? 1 : -1; int fid = pf.fid_and_chirality & 0x7fffffff; ex->AddPuncturedFace(fid, 1, chirality, pf.pos); } for (int i=0; i<pes.size(); i++) { const vfgpu_pe_t &pe = pes[i]; int chirality = pe & 0x80000000 ? 1 : -1; int eid = pe & 0x7fffffff; ex->AddPuncturedEdge(eid, chirality, 0); } ex->SetVortexObjects(vobjs0, 0); ex->SetVortexObjects(vobjs1, 1); VortexTransitionMatrix mat = ex->TraceOverTime(); mat.SetInterval(interval); mat.Modularize(); vt.AddMatrix(mat); delete ex; delete ds; // compute_moving_speed(f0, f1, vlines0, vlines1, mat); write_mat(f0, f1, mat); write_vlines(f0, vlines0); fprintf(stderr, "interval={%d, %d}, #pfs0=%d, #pfs1=%d, #pes=%d\n", interval.first, interval.second, (int)pfs0.size(), (int)pfs1.size(), (int)pes.size()); // release resources pes_all[interval].clear(); int &fc0 = frame_counter[f0], &fc1 = frame_counter[f1]; __sync_fetch_and_add(&fc0, 1); __sync_fetch_and_add(&fc1, 1); if (fc0 == 2) { pfs_all[fc0] = std::vector<vfgpu_pf_t>(); vobjs_all[fc0] = std::vector<VortexObject>(); vlines_all[fc0] = std::vector<VortexLine>(); } if (fc1 == 2) { pfs_all[fc1] = std::vector<vfgpu_pf_t>(); vobjs_all[fc1] = std::vector<VortexObject>(); vlines_all[fc1] = std::vector<VortexLine>(); } __sync_fetch_and_sub(&num_buffered_frames, 1); }
void VortexTransition::AddMatrix(const VortexTransitionMatrix& m) { if (!m.Valid()) return; int t = m.t0(); _matrices[t] = m; }