void operator()(dynamic_array<size_type>& path) { printf("default_path_visitor; path size: %lu\n", path.size()); vertex_id_map<Graph> vid_map = get(_vertex_id_map, g); edge_id_map<Graph> eid_map = get(_edge_id_map, g); edge_iterator ei = edges(g); vertex_iterator vi = vertices(g); for (size_type i = 0; i < path.size(); ++i) { if (i % 2 == 0) { size_type vid = path[i]; printf("vertex [ %lu ]\n", vid); } else { size_type eid = path[i]; edge_descriptor e = ei[eid]; size_type uid = get(vid_map, source(e, g)); size_type vid = get(vid_map, target(e, g)); printf("edge ( %lu , %lu )\n", uid, vid); } } }
Slot allocate_slot(Id id) { if (id > id_to_slot_map_.length()) id_to_slot_map_.resize(id); const Slot slot = (Slot) slot_to_id_map_.length(); slot_to_id_map_.emplace_back(id); id_to_slot_map_[id - 1] = slot; return slot; }
double add_delta(delta const& d) { deltas.push_back(d); x+=d.d; if (tmax<d.t) tmax=d.t; }
int DistanceTransform::inOrOut(const dynamic_array<int> &triList, const Point3f& vert, const Point3f& nearPnt) { int i, j, len = triList.length(); assert(len > 1); Point3f center, cpnt; Point3f v0, v1, v2; p_Surf->getTriVerts(triList[0], v0, v1, v2); double tnear = 1; int nearTri = 0; for(i = 0; i < 3; i++) { center[i] = (v0[i] + v1[i] + v2[i])/ 3; cpnt[i] = 0.9 * nearPnt[i] + 0.1 * center[i]; } for(i = 1; i < len; i++) { double t = rayTriangleIntersection(triList[i], vert, cpnt); if(t < tnear) { tnear = t; nearTri = i; } } Vector3f trinorm; p_Surf->getTriNormal(triList[nearTri], trinorm); p_Surf->getTriVerts(triList[nearTri], v0, v1, v2); Vector3f diff = vert - v0; if (DotProduct(diff, trinorm) < 0) { return -1; } return 1; }
void operator()(dynamic_array<size_type>& path) { typedef typename dynamic_array<size_type>::size_type d_size_type; printf("Path:"); for (d_size_type i = 1; i < path.size(); i += 2) printf("%6lu", path[i]); printf("\n"); }
void osd_interface::update_option(osd_options &options, const char * key, dynamic_array<const char *> &values) { astring current_value(options.description(key)); astring new_option_value(""); for (int index = 0; index < values.count(); index++) { astring t(values[index]); if (new_option_value.len() > 0) { if( index != (values.count()-1)) new_option_value.cat(", "); else new_option_value.cat(" or "); } new_option_value.cat(t); } // TODO: core_strdup() is leaked options.set_description(key, core_strdup(current_value.cat(new_option_value).cstr())); }
void operator()(dynamic_array<size_type_sg>& path) { typedef typename dynamic_array<size_type_sg>::size_type d_size_type; edge_id_map<Graph> eid_map = get(_edge_id_map, g); edge_iterator_sg edgs_sg = edges(sg); printf("Path:"); for (d_size_type i = 1; i < path.size(); i += 2) { size_type eid = get(eid_map, sg.local_to_global(edgs_sg[path[i]])); printf("%6lu", eid); } printf("\n"); }
// 0-indexed, of course std::string getline(unsigned i, bool chop_newline = true) { if (!file) { return boost::lexical_cast<std::string>(i); } Assert(i>=0 && i+1 < line_begins.size()); pos start = line_begins[i]; pos end = line_begins[i+1]; unsigned len = end-start; if (chop_newline && len > 0) --len; // don't want to include newline char auto_array<char> buf(len); // FIXME: could just return a shared_ptr or use string = getline(blah,sep) ... or return expression object that can convert to string or be printed file->seekg(start); file->read(buf.begin(), len); return std::string(buf.begin(), len); }
void operator()(dynamic_array<size_type>& path) { #ifdef DEBUG assert(path.size() == 7); #endif vertex_iterator vi = vertices(g); edge_iterator ei = edges(g); size_type v0 = path[0]; size_type v1 = path[2]; size_type v2 = path[4]; size_type v3 = path[6]; if (v0 != v1 && v1 != v2 && v0 != v2 && v3 == v0) { user_vis(path, "subiso"); } }
void index() { file->seekg(0); line_begins.clear(); line_begins.push_back(file->tellg()); while (!file->eof()) { file->ignore(std::numeric_limits<std::streamsize>::max(), linesep); //FIXME: does setting max unsigned really work here? not if you have very very long lines ;) but those don't fit into memory. pos end = file->tellg(); if (end > line_begins.back()) line_begins.push_back(end); } // should never be needed! Assert(file->tellg() == line_begins.back()); /* pos eof=file->tellg(); if (eof > line_begins.back()) { // only necessary to handle lack of trailing newline in a friendly way line_begins.push_back(eof); }*/ file->clear(); // don't want EOF flag stopping reads. line_begins.compact(); }
void component_leaders( Graph& g, const ComponentMap& C, dynamic_array<typename graph_traits<Graph>::vertex_descriptor>& leaders) { #pragma mta noalias g #pragma mta noalias C #pragma mta noalias leaders typedef typename graph_traits<Graph>::size_type size_type; typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor; typedef typename graph_traits<Graph>::thread_vertex_iterator thread_vertex_iterator; size_type order = num_vertices(g); size_type* rcount = (size_type*) malloc(order * sizeof(size_type)); for (size_type i = 0; i < order; ++i) rcount[i] = 0; size_type stream_id = 0; size_type num_streams = 1; // Count the number of vertices in each component. #pragma mta for all streams stream_id of num_streams { size_type start_pos = begin_block_range(order, stream_id, num_streams); size_type end_pos = end_block_range(order, stream_id, num_streams); thread_vertex_iterator verts = thread_vertices(start_pos, g); for ( ; start_pos != end_pos; ++start_pos, ++verts) { mt_incr(rcount[C[*verts]], 1); } } size_type num_components = 0; // Count the number of components. #pragma mta assert nodep for (size_type i = 0; i < order; ++i) { if (rcount[i] > 0) mt_incr(num_components, 1); } // Resize the leaders array. leaders.resize(num_components); num_components = 0; // Put the leaders for each component in the leaders array. #pragma mta for all streams stream_id of num_streams { size_type start_pos = begin_block_range(order, stream_id, num_streams); size_type end_pos = end_block_range(order, stream_id, num_streams); thread_vertex_iterator verts = thread_vertices(start_pos, g); for ( ; start_pos != end_pos; ++start_pos, ++verts) { if (rcount[start_pos] > 0) { size_type pos = mt_incr(num_components, 1); leaders[pos] = *verts; } } } free(rcount); }
Slot allocated_slot_count() const { return (Slot) slot_to_id_map_.length(); }
const Id* slot_to_id_map() const { return slot_to_id_map_.data(); }
void deallocate_slot(Slot slot) { slot_to_id_map_.unordered_remove(slot); const Id replacement_id = slot_to_id_map_[slot]; id_to_slot_map_[replacement_id - 1] = slot; }
unsigned size() const { Assert(exists() && line_begins.size()>0); return line_begins.size()-1; }
//!! this function doesn't work properly int DistanceTransform::nearestPlane(const dynamic_array<int>& triList, const Point3f& vert) { int i, j, len = triList.length(); assert(len > 1); for (i = 0; i < len; i++) { Vector3f tnorm; Point3f v0, v1, v2; p_Surf->getTriNormal(triList[i], tnorm); p_Surf->getTriVerts(triList[i], v0, v1, v2); Vector3f diff = vert - v0; float dot = DotProduct(tnorm, diff); // it may be unstable if the vert is very close to the nearest corner const double TOLERANCE = 1.0e-6; if(fabs(dot) < TOLERANCE) { //printf("WARNING: "); continue; } bool nearest = true; for(j = 0; j < len; j++) { if (j == i) { continue; } Point3f anv0, anv1, anv2; p_Surf->getTriVerts(triList[j], anv0, anv1, anv2); float d0 = DotProduct(tnorm, anv0 - v0); float d1 = DotProduct(tnorm, anv1 - v0); float d2 = DotProduct(tnorm, anv2 - v0); float d; if(fabs(d0) > fabs(d1)) { if(fabs(d0) > fabs(d2)) { d = d0; } else { d = d2; } } else { if (fabs(d1) > fabs(d2)) { d = d1; } else { d = d2; } } if( d * dot > 0) { // triangle i is not the nearest plane nearest = false; break; } } if (nearest) { return i; } } // should not come here printf("WARNING: trouble in finding the nearest plane\n"); /* for(i = 0; i < len; i++) { TriId3i tid3 = p_Surf->getTriId(triList[i]); printf("vert (%f %f %f) 's %dth triangle has vertices %d %d %d\n", vert[0], vert[1], vert[2], i, tid3[0], tid3[1], tid3[2]); } */ return 0; }