예제 #1
0
파일: master.cpp 프로젝트: reuk/wayverb
    void context_created(generic_renderer<scene::view>&) override {
        //  Set up the scene model so that everything is visible.
        const auto scene_data = model_.project.get_scene_data();
        auto triangles = scene_data.get_triangles();
        auto vertices = util::map_to_vector(begin(scene_data.get_vertices()),
                                            end(scene_data.get_vertices()),
                                            wayverb::core::to_vec3{});

        //  Get scene data in correct format.
        //  This command will be run on the graphics thread, so it
        //  must be thread safe.
        view_.high_priority_command([
            t = std::move(triangles),
            v = std::move(vertices),
            vs = model_.scene.get_view_state(),
            pm = model_.scene.get_projection_matrix()
        ](auto& r) {
            r.set_scene(t.data(), t.size(), v.data(), v.size());
            r.set_view_state(vs);
            r.set_projection_matrix(pm);
            r.set_emphasis_colour(
                    {AngularLookAndFeel::emphasis.getFloatRed(),
                     AngularLookAndFeel::emphasis.getFloatGreen(),
                     AngularLookAndFeel::emphasis.getFloatBlue()});
            //  TODO we might need to set other state here too.
        });
    }
예제 #2
0
void basic_face::add_triangle(const map_vertex& v1, const map_vertex& v2, const map_vertex& v3) {
	if (m_triangle_count == -1) m_triangle_count = 0;

	get_vertices().push_back(v1);
	get_vertices().push_back(v2);
	get_vertices().push_back(v3);

	map_vertex* test = &get_vertices()[0];
	m_triangle_count++;
}
예제 #3
0
// mark an arc forbidden/permanent,
// note that, if adjacent arcs are also forbidden/permanent, this mark may cascade
bool t_dir_graph::mark_arc(const t_arc& a, const uint mark){
	if(successors.find(a.first) == successors.end()) return false; // dont mark edges that are not in VxV
	if(successors.find(a.second) == successors.end()) return false; // dont mark edges that are not in VxV
	dbgcout << "marking " << a << (mark==MRK_NONE?"none":(mark==MRK_FORBIDDEN?"forbidden":"permanent")) << "\n";
	bool result = true;
	switch(mark){
		case MRK_NONE:
			return (forbidden_arcs.erase(a) || permanent_arcs.erase(a));
			break;
		case MRK_FORBIDDEN:
			if((!contains_arc(a)) && (forbidden_arcs.find(a) == forbidden_arcs.end())
					&& forbidden_arcs.insert(a).second) {
				set<t_vertex> belt = set_intersect(get_successors(a.first), get_predecessors(a.second));
				for(set<t_vertex>::iterator u = belt.begin(); u != belt.end(); u++){
					if(permanent_arcs.find(t_arc(a.first, *u)) != permanent_arcs.end())
						result &= mark_arc(t_arc(*u, a.second), MRK_FORBIDDEN);
					if(permanent_arcs.find(t_arc(*u, a.second)) != permanent_arcs.end())
						result &= mark_arc(t_arc(a.first, *u), MRK_FORBIDDEN);
				}
				return result;
			} else return false;
			break;
		case MRK_PERMANENT:
			if(contains_arc(a) && (permanent_arcs.find(a) == permanent_arcs.end())
					&& permanent_arcs.insert(a).second) {
				set<t_vertex> pred = get_predecessors(a.first);
				for(set<t_vertex>::iterator u = pred.begin(); u != pred.end(); u++){
					if(permanent_arcs.find(t_arc(*u, a.first)) != permanent_arcs.end())
						result &= mark_arc(t_arc(*u, a.second), MRK_PERMANENT);
				}
				pred = set_substract(get_vertices(), get_predecessors(a.second));
				for(set<t_vertex>::iterator u = pred.begin(); u != pred.end(); u++){
					if(forbidden_arcs.find(t_arc(*u, a.second)) != forbidden_arcs.end())
						result &= mark_arc(t_arc(*u, a.second), MRK_FORBIDDEN);
				}
				set<t_vertex> succ = get_successors(a.second);
				for(set<t_vertex>::iterator u = succ.begin(); u != succ.end(); u++){
					if(permanent_arcs.find(t_arc(a.second, *u)) != permanent_arcs.end())
						result &= mark_arc(t_arc(a.first, *u), MRK_PERMANENT);
				}
				succ = set_substract(get_vertices(), get_successors(a.first));
				for(set<t_vertex>::iterator u = succ.begin(); u != succ.end(); u++){
					if(forbidden_arcs.find(t_arc(a.first, *u)) != forbidden_arcs.end())
						result &= mark_arc(t_arc(a.second, *u), MRK_FORBIDDEN);
				}
				return result;
			} else return false;
			break;
		default: return false;
	}	
}
예제 #4
0
파일: main_model.cpp 프로젝트: reuk/wayverb
void main_model::reset_view() {
    //  Set up the scene model so that everything is visible.
    const auto scene_data = project.get_scene_data();
    const auto vertices = util::map_to_vector(begin(scene_data.get_vertices()),
                                              end(scene_data.get_vertices()),
                                              wayverb::core::to_vec3{});

    const auto aabb = wayverb::core::geo::compute_aabb(vertices);
    const auto origin = -centre(aabb);
    const auto radius = glm::distance(aabb.get_min(), aabb.get_max()) / 2;

    scene.set_origin(origin);
    scene.set_eye_distance(2 * radius);
    scene.set_rotation(wayverb::core::az_el{M_PI / 4, M_PI / 6});
}
예제 #5
0
파일: base.cpp 프로젝트: toggled/pagmo
/**
 * Will return a formatted string containing:
 * - the output of human_readable_terse(),
 * - the list of vertices and edges in a DOT-like syntax.
 *
 * @return string containing complete human readable representation of the topology.
 */
std::string base::human_readable() const
{
	std::ostringstream s;
	s << human_readable_terse();
	s << "Connections:\n\n";
	std::pair<v_iterator,v_iterator> vertices = get_vertices();
	std::pair<a_iterator,a_iterator> adj_vertices;
	for (; vertices.first != vertices.second; ++vertices.first) {
		adj_vertices = get_adjacent_vertices(*vertices.first);
		s << (*vertices.first);
		if (adj_vertices.first != adj_vertices.second) {
			s << " -> {";
			while (adj_vertices.first != adj_vertices.second) {
				s << (*adj_vertices.first);
				++adj_vertices.first;
				if (adj_vertices.first != adj_vertices.second) {
					s << ' ';
				}
			}
			s << '}';
		}
		s << '\n';
	}
	return s.str();
}
예제 #6
0
파일: erdos_renyi.cpp 프로젝트: YS-L/pagmo
void erdos_renyi::connect(const vertices_size_type &n)
{
	for (std::pair<v_iterator,v_iterator> vertices = get_vertices(); vertices.first != vertices.second; ++vertices.first) {
		// Connect n bidirectionally to the other nodes with probability m_prob. Also, avoid to connect n with itself.
		if (*vertices.first != n && m_drng() < m_prob) {
			add_edge(n,*vertices.first);
			add_edge(*vertices.first,n);
		}
	}
}
예제 #7
0
    rs2::frame pointcloud::process_depth_frame(const rs2::frame_source& source, const rs2::depth_frame& depth)
    {
        auto res = allocate_points(source, depth);
        auto pframe = (librealsense::points*)(res.get());

        auto depth_data = (const uint16_t*)depth.get_data();
        float2* tex_ptr = pframe->get_texture_coordinates();

        const float3* points;

        points = depth_to_points(res, (uint8_t*)pframe->get_vertices(), *_depth_intrinsics, depth_data, *_depth_units);

        auto vid_frame = depth.as<rs2::video_frame>();

        // Pixels calculated in the mapped texture. Used in post-processing filters
        float2* pixels_ptr = _pixels_map.data();
        rs2_intrinsics mapped_intr;
        rs2_extrinsics extr;
        bool map_texture = false;
        {
            if (_extrinsics && _other_intrinsics)
            {
                mapped_intr = *_other_intrinsics;
                extr = *_extrinsics;
                map_texture = true;
            }
        }

        if (map_texture)
        {
            auto height = vid_frame.get_height();
            auto width = vid_frame.get_width();

            get_texture_map(res, points, width, height, mapped_intr, extr, tex_ptr, pixels_ptr);

            if (_occlusion_filter->active())
            {
                _occlusion_filter->process(pframe->get_vertices(), pframe->get_texture_coordinates(), _pixels_map);
            }
        }
        return res;
    }
예제 #8
0
파일: solveflow.hpp 프로젝트: kwabe007/adk
    std::string to_str() const {
        std::string output;

        output += "Edges: " + std::to_string(get_edges()) + " Source: " + std::to_string(source) + " Target: " + std::to_string(target) + "\n";
        for (std::size_t i = 0; i < edge_vec.size(); ++i) {
            output += edge_vec[i].get_str() + "\n";
        }

        output += "Vertices: " + std::to_string(get_vertices());
        return output;
    }
std::list<Vertex> Graph::get_vertices(typename Vertex::Type type) {
  // Define a nested predicate functor.
  struct is_type {
    typename Vertex::Type type;
    is_type(typename Vertex::Type type) : type(type) {}
    bool operator()(const Vertex& vertex) {
      return vertex.type != type;
    }
  };
  // Retrieve the list of verticies.
  std::list<Vertex> vertices = get_vertices();
  // Remove the ones we don't want.
  vertices.remove_if(is_type(type));
  // Return the list.
  return vertices;
}
예제 #10
0
QPointF jpsRoom::get_center()
{
    QVector<QPointF> vertices = get_vertices();
    qreal sum_x=0;
    qreal sum_y=0;

    for (int i=0; i<vertices.size(); i++)
    {
        sum_x+=vertices[i].x();
        sum_y+=vertices[i].y();
    }
    QPointF mean;
    mean.setX(sum_x/vertices.size());
    mean.setY(sum_y/vertices.size());

    return mean;
}
예제 #11
0
auto load_scene(const std::string& name) {
    //  Attempt to load from file path.
    wayverb::core::scene_data_loader loader{name};

    const auto scene_data = loader.get_scene_data();
    if (!scene_data) {
        throw std::runtime_error{"Failed to load scene."};
    }

    return wayverb::core::make_scene_data(
            scene_data->get_triangles(),
            scene_data->get_vertices(),
            util::aligned::vector<
                    wayverb::core::surface<wayverb::core::simulation_bands>>(
                    scene_data->get_surfaces().size(),
                    wayverb::core::surface<wayverb::core::simulation_bands>{}));
}
예제 #12
0
void ClusterZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
                            std::map<std::string, xbt_edge_t>* edges)
{
  xbt_assert(router_,
             "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");

  /* create the router */
  xbt_node_t routerNode = new_xbt_graph_node(graph, router_->get_cname(), nodes);

  xbt_node_t backboneNode = nullptr;
  if (backbone_) {
    backboneNode = new_xbt_graph_node(graph, backbone_->get_cname(), nodes);
    new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
  }

  for (auto const& src : get_vertices()) {
    if (not src->is_router()) {
      xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);

      std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(src->id());

      if (info.first) { // link up
        xbt_node_t current = new_xbt_graph_node(graph, info.first->get_cname(), nodes);
        new_xbt_graph_edge(graph, previous, current, edges);

        if (backbone_) {
          new_xbt_graph_edge(graph, current, backboneNode, edges);
        } else {
          new_xbt_graph_edge(graph, current, routerNode, edges);
        }
      }

      if (info.second) { // link down
        xbt_node_t current = new_xbt_graph_node(graph, info.second->get_cname(), nodes);
        new_xbt_graph_edge(graph, previous, current, edges);

        if (backbone_) {
          new_xbt_graph_edge(graph, current, backboneNode, edges);
        } else {
          new_xbt_graph_edge(graph, current, routerNode, edges);
        }
      }
    }
  }
}
예제 #13
0
void CalculateNeighbourCells(        Complex2D&  G, 
			       const CellSet  &  cell_set,
			             FacetMap &  facet_map)
{

  typedef typename CellSet::CellIterator  SetCellIt;

  typedef typename FacetMap::iterator     MapIt;
  typedef grid_types<Complex2D>           gt;
  typedef typename gt::Cell               Cell;
  typedef typename gt::FacetOnCellIterator FacetOnCellIt;
  //  typedef typename gt::CellOnCellIterator CellNeighbourIt;
  
  friend_for_input gg(G); // gg == G + access to private routines
  
  typedef vtuple_2d<Complex2D> vtuple;
  SetCellIt c = cell_set.FirstCell();
  for(c= cell_set.FirstCell(); !c.IsDone(); ++c){
    Cell C(*c);
    FacetOnCellIt f(C.FirstFacet());
    for(; !f.IsDone();++f) {
      vtuple  facet(get_vertices(f));
      MapIt nb;
      if((nb = facet_map.find(facet)) != facet_map.end()){ 
        // facet found: nb has already been visited
        // do appropriate entries in the neighbourlists
        //  & remove facet from the map.
        FacetOnCellIt NbIt((*nb).second);
        gg.set_neighbour(f,    NbIt.TheCell());
        gg.set_neighbour(NbIt, f.   TheCell());
        //(int&)(*f._nb)      = G.handle(NbIt.TheCell()); // replace with call to
        //(int&)(*(NbIt._nb)) = G.handle(f.TheCell());    // internal fct of Complex2D
        facet_map.erase(nb);
      }
      else // 1st time this facet is encountered: add it to map
        facet_map[facet] = f ;
    } // for(f=C.FirstNeighbour();...
  } // for(c=FirstCell();...

  // all remaining map entries are on the boundary of cell_set
  // because they have been encountered exactly once.

}
예제 #14
0
int main(int argc, char** argv) {
    try {
        constexpr auto surface =
                wayverb::core::surface<wayverb::core::simulation_bands>{
                        {{0.07, 0.09, 0.11, 0.12, 0.13, 0.14, 0.16, 0.17}},
                        {{0.07, 0.09, 0.11, 0.12, 0.13, 0.14, 0.16, 0.17}}};

        if (argc != 2) {
            throw std::runtime_error{"Expected a scene file."};
        }

        auto scene_data = load_scene(argv[1]);
        scene_data.set_surfaces(surface);

        // const auto box = wayverb::core::geo::box{glm::vec3{0},
        //                                         glm::vec3{5.56, 3.97, 2.81}};
        // const auto scene_data =
        //        wayverb::core::geo::get_scene_data(box, surface);

        const auto aabb_centre = centre(
                wayverb::core::geo::compute_aabb(scene_data.get_vertices()));

        const auto source = aabb_centre + glm::vec3{0, 0, 0.2};
        const auto receiver = aabb_centre + glm::vec3{0, 0, -0.2};

        const auto rays = 1 << 16;
        const auto img_src_order = 4;

        const auto cutoff = 1000;
        const auto usable_portion = 0.6;

        const auto output_sample_rate = 44100.0;

        const auto params = wayverb::waveguide::single_band_parameters{cutoff, usable_portion};

        //  Set up simulation.
        wayverb::combined::engine engine{
                wayverb::core::compute_context{},
                scene_data,
                source,
                receiver,
                wayverb::core::environment{},
                wayverb::raytracer::simulation_parameters{rays, img_src_order},
                wayverb::combined::make_waveguide_ptr(params)};

        //  When the engine changes, print a nice progress bar.

        util::progress_bar pb{std::cout};
        engine.connect_engine_state_changed([&](auto state, auto progress) {
            set_progress(pb, progress);
        });

        //  Run simulation.
        const auto intermediate = engine.run(true);

        //  Do directional postprocessing.
        const wayverb::core::orientation receiver_orientation{};
        std::vector<util::named_value<
                std::unique_ptr<wayverb::combined::capsule_base>>>
                capsules;
        capsules.emplace_back(
                "microphone",
                wayverb::combined::make_capsule_ptr(
                        wayverb::core::attenuator::microphone{
                                wayverb::core::orientation{}, 0.5},
                        receiver_orientation));
        capsules.emplace_back(
                "hrtf",
                wayverb::combined::make_capsule_ptr(
                        wayverb::core::attenuator::hrtf{
                                wayverb::core::orientation{},
                                wayverb::core::attenuator::hrtf::channel::left},
                        receiver_orientation));

        auto output_channels = util::map_to_vector(
                begin(capsules), end(capsules), [&](const auto& i) {
                    return map(
                            [&](const auto& i) {
                                return i->postprocess(*intermediate,
                                                      output_sample_rate);
                            },
                            i);
                });

        //  Reduce volume to reasonable level.
        constexpr auto volume_factor = 0.05;
        for (auto& i : output_channels) {
            wayverb::core::mul(i.value, volume_factor);
        }

        //  Write out.
        for (const auto& i : output_channels) {
            write(util::build_string(i.name, ".wav").c_str(),
                  i.value,
                  output_sample_rate,
                  audio_file::format::wav,
                  audio_file::bit_depth::pcm16);
        }

    } catch (const std::exception& e) {
        std::cerr << e.what() << '\n';
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
예제 #15
0
    auto run_simulation(const wayverb::core::geo::box& boundary,
                        const util::aligned::vector<glm::vec3>& receivers,
                        const wayverb::waveguide::coefficients_canonical&
                        coefficients) const {
        const auto scene_data = wayverb::core::geo::get_scene_data(
                                    boundary,
                                    wayverb::core::make_surface<wayverb::core::simulation_bands>(
                                        0, 0));

        auto mesh = wayverb::waveguide::compute_mesh(
                        cc_,
                        make_voxelised_scene_data(
                            scene_data,
                            5,
                            wayverb::waveguide::compute_adjusted_boundary(
                                wayverb::core::geo::compute_aabb(
                                    scene_data.get_vertices()),
                                source_position_,
                                divisions_)),
                        divisions_,
                        speed_of_sound);

        mesh.set_coefficients({coefficients});

        const auto source_index =
            compute_index(mesh.get_descriptor(), source_position_);

        const auto input = [&] {
            const util::aligned::vector<float> raw_input{1.0f};
            auto ret = wayverb::waveguide::make_transparent(
                           raw_input.data(), raw_input.data() + raw_input.size());
            ret.resize(steps, 0);
            return ret;
        }();

        auto prep = wayverb::waveguide::preprocessor::make_soft_source(
                        source_index, input.begin(), input.end());

        auto output_holders = util::map_to_vector(
        begin(receivers), end(receivers), [&](auto i) {
            const auto receiver_index{
                compute_index(mesh.get_descriptor(), i)};
            if (!wayverb::waveguide::is_inside(mesh, receiver_index)) {
                throw std::runtime_error{
                    "receiver is outside of mesh!"};
            }
            return wayverb::core::callback_accumulator<
            wayverb::waveguide::postprocessor::node> {
                receiver_index
            };
        });

        util::progress_bar pb{};
        wayverb::waveguide::run(
            cc_,
            mesh,
            prep,
        [&](auto& queue, const auto& buffer, auto step) {
            for (auto& i : output_holders) {
                i(queue, buffer, step);
            }
            set_progress(pb, step, steps);
        },
        true);

        return util::map_to_vector(
        begin(output_holders), end(output_holders), [](const auto& i) {
            return i.get_output();
        });
    }
예제 #16
0
void material::compute_kdtree()
{
  assert(!tree_ && "only call this function once");
  tree_ = create_kdtree(indices, get_vertices());
}
예제 #17
0
파일: clustered_ba.cpp 프로젝트: YS-L/pagmo
void clustered_ba::connect(const vertices_size_type &idx)
{
	pagmo_assert(get_number_of_vertices() > 0);
	const vertices_size_type prev_size = get_number_of_vertices() - 1;
	if (prev_size < m_m0) {
		// If we had not built the initial m0 nodes, do it.
		// We want to connect the newcomer island with high probability, and make sure that
		// at least one connection exists (otherwise the island stays isolated).
		// NOTE: is it worth to make it a user-tunable parameter?
                const double prob = 0.0;
		// Flag indicating if at least 1 connection was added.
		bool connection_added = false;
		// Main loop.
		for (std::pair<v_iterator,v_iterator> vertices = get_vertices(); vertices.first != vertices.second; ++vertices.first) {
			// Do not consider the new vertex itself.
			if (*vertices.first != idx) {
				if (m_drng() < prob) {
					connection_added = true;
					// Add the connections
					add_edge(*vertices.first,idx);
					add_edge(idx,*vertices.first);
				}
			}
		}
		// If no connections were established and this is not the first island being inserted,
		// establish at least one connection with a random island other than n.
		if ((!connection_added) && (prev_size != 0)) {
			// Get a random vertex index between 0 and n_vertices - 1. Keep on repeating the procedure if by
			// chance we end up on idx again.
			boost::uniform_int<vertices_size_type> uni_int(0,get_number_of_vertices() - 1);
			vertices_size_type rnd;
                        do {
				rnd = uni_int(m_urng);
			} while (rnd == idx);
			// Add connections to the random vertex.
			add_edge(rnd,idx);
			add_edge(idx,rnd);
		}
	} else {
                // Now we need to add j edges, choosing the nodes with a probability
		// proportional to their number of connections. We keep track of the
		// connection established in order to avoid connecting twice to the same
		// node.
                // j is a random integer in the range 1 to m.
                boost::uniform_int<edges_size_type> uni_int2(1,m_m);
		std::size_t i = 0;
                std::size_t j = uni_int2(m_urng);
		std::pair<v_iterator,v_iterator> vertices;
		std::pair<a_iterator,a_iterator> adj_vertices;
                while (i < j) {
                        // Let's find the current total number of edges.
                        const edges_size_type n_edges = get_number_of_edges();
                        pagmo_assert(n_edges > 0);
                        boost::uniform_int<edges_size_type> uni_int(0,n_edges - 1 - i);
                        // Here we choose a random number between 0 and n_edges - 1 - i.
                        const edges_size_type rn = uni_int(m_urng);
                        edges_size_type n = 0;
			// Iterate over all vertices and accumulate the number of edges for each of them. Stop when the accumulated number of edges is greater
			// than rn. This is equivalent to giving a chance of connection to vertex v directly proportional to the number of edges departing from v.
			// You can think of this process as selecting a random edge among all the existing edges and connecting to the vertex from which the
			// selected edge departs.
			vertices = get_vertices();
			for (; vertices.first != vertices.second; ++vertices.first) {
				// Do not consider it_n.
				if (*vertices.first != idx) {
					adj_vertices = get_adjacent_vertices(*vertices.first);
					n += boost::numeric_cast<edges_size_type>(std::distance(adj_vertices.first,adj_vertices.second));
					if (n > rn) {
						break;
					}
				}
			}
			pagmo_assert(vertices.first != vertices.second);
			// If the candidate was not already connected, then add it.
			if (!are_adjacent(idx,*vertices.first)) {
                                // Connect to nodes that are already adjacent to idx with probability p.
                                // This step increases clustering in the network.
                                adj_vertices = get_adjacent_vertices(idx);
                                for(;adj_vertices.first != adj_vertices.second; ++adj_vertices.first) {
                                    if(m_drng() < m_p && *adj_vertices.first != *vertices.first && !are_adjacent(*adj_vertices.first,*vertices.first)) {
                                        add_edge(*adj_vertices.first, *vertices.first);
                                        add_edge(*vertices.first, *adj_vertices.first);
                                    }
                                }
                                // Connect to idx
				add_edge(*vertices.first,idx);
				add_edge(idx,*vertices.first);
				++i;
			}
		}
	}
}
예제 #18
0
Ref<Mesh> NavigationMesh::get_debug_mesh() {

	if (debug_mesh.is_valid())
		return debug_mesh;



	PoolVector<Vector3> vertices = get_vertices();
	PoolVector<Vector3>::Read vr=vertices.read();
	List<Face3> faces;
	for(int i=0;i<get_polygon_count();i++) {
		Vector<int> p = get_polygon(i);

		for(int j=2;j<p.size();j++) {
			Face3 f;
			f.vertex[0]=vr[p[0]];
			f.vertex[1]=vr[p[j-1]];
			f.vertex[2]=vr[p[j]];

			faces.push_back(f);
		}
	}


	Map<_EdgeKey,bool> edge_map;
	PoolVector<Vector3> tmeshfaces;
	tmeshfaces.resize(faces.size()*3);

	{
		PoolVector<Vector3>::Write tw=tmeshfaces.write();
		int tidx=0;


		for(List<Face3>::Element *E=faces.front();E;E=E->next()) {

			const Face3 &f = E->get();

			for(int j=0;j<3;j++) {

				tw[tidx++]=f.vertex[j];
				_EdgeKey ek;
				ek.from=f.vertex[j].snapped(CMP_EPSILON);
				ek.to=f.vertex[(j+1)%3].snapped(CMP_EPSILON);
				if (ek.from<ek.to)
					SWAP(ek.from,ek.to);

				Map<_EdgeKey,bool>::Element *E=edge_map.find(ek);

				if (E) {

					E->get()=false;

				} else {

					edge_map[ek]=true;
				}

			}
		}
	}
	List<Vector3> lines;

	for(Map<_EdgeKey,bool>::Element *E=edge_map.front();E;E=E->next()) {

		if (E->get()) {
			lines.push_back(E->key().from);
			lines.push_back(E->key().to);
		}
	}

	PoolVector<Vector3> varr;
	varr.resize(lines.size());
	{
		PoolVector<Vector3>::Write w = varr.write();
		int idx=0;
		for(List<Vector3>::Element *E=lines.front();E;E=E->next()) {
			w[idx++]=E->get();
		}
	}

	debug_mesh = Ref<Mesh>( memnew( Mesh ) );

	Array arr;
	arr.resize(Mesh::ARRAY_MAX);
	arr[Mesh::ARRAY_VERTEX]=varr;

	debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES,arr);

	return debug_mesh;
}
예제 #19
0
파일: base.cpp 프로젝트: toggled/pagmo
/**
 * Remove all connections between vertices.
 */
void base::remove_all_edges()
{
	for (std::pair<v_iterator,v_iterator> vertices = get_vertices(); vertices.first != vertices.second; ++vertices.first) {
		boost::clear_vertex(*vertices.first,m_graph);
	}
}
예제 #20
0
QPolygonF jpsRoom::RoomAsPolygon() const
{

    return QPolygonF(get_vertices());
}
예제 #21
0
// delete all vertices that are not in the given vertex set from the graph
void t_dir_graph::induced_subgraph(const set<t_vertex>& vertices){
	set<t_vertex> v = set_substract(get_vertices(), vertices);
	for(set<t_vertex>::const_iterator i = v.begin(); i != v.end(); i++)
		delete_vertex(*i);
}
예제 #22
0
int main(void)
{
  char * line = NULL;
  size_t len = 0;
  ssize_t read;
  regex_t * __restrict compiled_edge = (regex_t *) malloc(sizeof (regex_t));
  (void) regcomp(compiled_edge,"^e (.) (.)", REG_EXTENDED);   // Compilacion de RegEx para vertices  
  regex_t * __restrict compiled_num = (regex_t *) malloc(sizeof (regex_t)); 
  (void) regcomp(compiled_num, "^p", REG_EXTENDED);   //  Compilacion de RegEx para numero de vertices
  char * dump = (char *) malloc(sizeof(char)*12);
  int d1;  
  int d2;
  int vertex_num;
  // Comienza lectura de la entrada estandar
  while ((read = getline(&line, &len, stdin)) != -1) {
    if (regexec(compiled_num, line, 0, NULL, 0) == 0) {
      sscanf(line,"%c %s %d %d", dump, dump,&vertex_num,&d2);
      break;
      // ahora vertex_num contiene numero de vertices en grafo
    }
  }
  // Inicializacion de arreglo de adyacencias
  row_vertex main_col[vertex_num];
  int i;
  for (i = 0; i < vertex_num ; i++) {
    main_col[i].pt = NULL;
    main_col[i].vertex = i; 
    main_col[i].color = -1; // Color inicial
    main_col[i].color_around = (int *) malloc(sizeof(int)*vertex_num); 
    int j;
    for(j = 0; j < vertex_num; j++) 
      // Inicialización de arreglo de colores adyacentes
      main_col[i].color_around[j] = 0;
  }
  
  // Lectura del resto del archivo
  while ((read = getline(&line, &len, stdin)) != -1) {
    if (regexec(compiled_edge, line, 0, NULL, 0) == 0) { 
      sscanf(line,"%c %d %d", dump,&d1,&d2);
      d1 -= 1;
      d2 -= 1;
      if (d1 != d2) {
        // Arco d1 --> d2
        linked_list * adjacent1 = (linked_list *) malloc(sizeof(linked_list)); 
        adjacent1->vertex = d2;
        // Insercion de elementos de lista por la izquierda
        adjacent1->next = main_col[d1].pt;
        main_col[d1].pt = (struct linked_list *) adjacent1;
        // Arco d2 --> d1
        linked_list * adjacent2 = malloc(sizeof(linked_list)); 
        adjacent2->vertex = d1;
        // Insercion de elementos de lista por la izquierda
        adjacent2->next = main_col[d2].pt;
        main_col[d2].pt = (struct linked_list *) adjacent2;
      }
    }
  }
  tuple * deg_vert = (tuple *) malloc(sizeof(tuple)*vertex_num);
  degree(main_col, vertex_num, deg_vert);
  pair result;  // Par clique-coloración
  int upper_bound;
  int lower_bound;

  double TIEMPOINICIAL;
  double TIEMPOFINAL;
  struct timeval t_p;
  //COMIENZA ALGORITMO
  if (!gettimeofday(&t_p, NULL))
    TIEMPOINICIAL = (double) t_p.tv_sec + ((double) t_p.tv_usec)/1000000.0;
  else
    printf("\n mal tiempo \n");

  signal(SIGALRM, alarmHandler);
  alarm(300); // 5 minutos medidos en segundos
  // Se obtiene cota superior
  result = dsatur(main_col, deg_vert, vertex_num, -1);
  upper_bound = result.coloring;
  // Se obtiene cota inferior
  lower_bound = -1;
  int k;
  int j;
  // miembros tentativos
  int * members;
  int * cromatic_num = NULL; //Número cromático
  for(i = 0; i < vertex_num; i++) {
    main_col_init(main_col, vertex_num);
    result = dsatur(main_col, deg_vert, vertex_num, i);
    if (result.clique > lower_bound) {
      lower_bound = result.clique;
      members = result.members;
      continue;
    }
    free(result.members);
  }

  printf("Resultados de Brelaz+interchange \n");
  printf("Cota superior = %d \n", upper_bound);
  printf("Cota inferior = %d \n", lower_bound);
  if (lower_bound == upper_bound)
    printf("Número cromático = %d \n", upper_bound);
  else {
    int * vertices;
    vertices = get_vertices(members, vertex_num);
    free(members);
    cromatic_num = (int *) implicit_enum(main_col, lower_bound, upper_bound, vertices, vertex_num);
    printf("Resultado de enumeración implícita \n");
    printf("Número cromático = %d \n", *cromatic_num);
    free(cromatic_num);
    free(vertices);
  }

  // TERMINA ALGORITMO
  
  if (!gettimeofday(&t_p, NULL))
    TIEMPOFINAL =  (double) t_p.tv_sec + ((double) t_p.tv_usec)/1000000.0;
  else
    printf("\n mal tiempo \n");
  
  printf("Tiempo en segundos de ejecución del programa: %1.4f \n", (TIEMPOINICIAL - TIEMPOFINAL)*-1);

  free_row_vertex(main_col, vertex_num);
  free(dump);
  free(compiled_num);
  free(compiled_edge);
  free(line);
  free(deg_vert);
  return EXIT_SUCCESS;
}