main(int argc, char *argv[]) { if (argc != 2) fatal("usage: cgraph type"); string s; if (strcmp(argv[1],"graph") == 0) { Graph g; g.read(cin); Graph g1(1,1); g1.copyFrom(g); cout << g1.toString(s); } else if (strcmp(argv[1],"wgraph") == 0) { Wgraph wg; wg.read(cin); Wgraph wg1(1,1); wg1.copyFrom(wg); cout << wg1.toString(s); } else if (strcmp(argv[1],"digraph") == 0) { Digraph dig; dig.read(cin); Digraph dig1(1,1); dig1.copyFrom(dig); cout << dig1.toString(s); } else if (strcmp(argv[1],"wdigraph") == 0) { Wdigraph wdig; wdig.read(cin); Wdigraph wdig1(1,1); wdig1.copyFrom(wdig); cout << wdig1.toString(s); } else if (strcmp(argv[1],"flograph") == 0) { Flograph fg; fg.read(cin); Flograph fg1(2,1); fg1.copyFrom(fg); cout << fg1.toString(s); } else if (strcmp(argv[1],"wflograph") == 0) { Wflograph wfg; wfg.read(cin); Wflograph wfg1(2,1); wfg1.copyFrom(wfg); cout << wfg1.toString(s); } else { fatal("usage: cgraph type"); } }
void dynamics_mul::compute_intensity_force(){ HMesh::HalfEdgeAttributeVector<int> touched(s_dsc->get_no_halfedges(), 0); for (auto eit = s_dsc->halfedges_begin(); eit != s_dsc->halfedges_end(); eit++) { if(s_dsc->is_interface(*eit) and !touched[*eit]){ auto hew = s_dsc->walker(*eit); double c0 = mean_inten_[s_dsc->get_label(hew.face())]; double c1 = mean_inten_[s_dsc->get_label(hew.opp().face())]; // Loop on the edge auto p0 = s_dsc->get_pos(hew.opp().vertex()); auto p1 = s_dsc->get_pos(hew.vertex()); Vec2 L01 = p1 - p0; L01.normalize(); Vec2 N01(L01[1], -L01[0]); // Outward pointing normal int length = (int)(p1 - p0).length(); double f0 = 0.0, f1 = 0.0; Vec2 fg0(0.0), fg1(0.0); for (int i = 0; i <= length; i++) { auto p = p0 + (p1 - p0)*(double(i)/(double)length); double I = s_img->get_intensity(p[0], p[1]); // Normalize force int normalizedF = 1; double f ; switch (normalizedF) { case 1: f = ( (c0-c1)*(2*I - c0 - c1)) / ((c0-c1)*(c0-c1)); break; case 2: f = ( (c0-c1)*(2*I - c0 - c1)) / std::abs((c0 - c1)); break; case 3: f = (c0-c1)*(2*I - c0 - c1); break; default: f = 0.0; break; } Vec2 fu = N01*(c0-c1)*(2*I - c0 - c1); // Image gradient force int lengthM = 10; Vec2 gm(0.0); double max_grad = 0; for (int l = 0; l < lengthM; l++) { Vec2 curPt = p + fu*(l/(double)(lengthM)); Vec2 gg = s_img->grad((int)curPt[0], (int)curPt[1]); if (max_grad < gg.length()) { max_grad = gg.length(); gm = gg*(lengthM - l)/(double)lengthM; } } Vec2 fg = gm*(2*I - c0 - c1); Vec2 fv = (fu + fg)/((c0-c1)*(c0-c1)); fg0 += fv*(p-p1).length() / (double)length; fg1 += fv*(p-p0).length() / (double)length; // Barry Centric coordinate f0 += f*(p-p1).length() / (double)length; f1 += f*(p-p0).length() / (double)length; // Image gradient force // Vec2 fg = s_img->grad((int)p[0], (int)p[1]) * (2*I - c0 - c1) / ((c0-c1)*(c0-c1)); // fg0 += fg*(p-p1).length() / (double)length; // fg1 += fg*(p-p0).length() / (double)length; } // Set force Vec2 f_x0 = fg0; // N01*f0; Vec2 f_x1 = fg1; // N01*f1; s_dsc->add_node_external_force(hew.opp().vertex(), f_x0*g_param.beta); s_dsc->add_node_external_force(hew.vertex(), f_x1*g_param.beta); // Avoid retouch the edge touched[*eit] = 1; touched[hew.opp().halfedge()] = 1; } } }