3 #ifndef GEODESIC_ALGORITHM_BASE_122806 4 #define GEODESIC_ALGORITHM_BASE_122806 6 #include "geodesic_mesh.h" 7 #include "geodesic_constants_and_simple_functions.h" 13 class GeodesicAlgorithmBase
24 GeodesicAlgorithmBase(geodesic::Mesh* mesh):
25 m_type(UNDEFINED_ALGORITHM),
26 m_max_propagation_distance(1e100),
30 virtual ~GeodesicAlgorithmBase(){};
32 virtual void propagate(std::vector<SurfacePoint>& sources,
33 double max_propagation_distance = GEODESIC_INF,
34 std::vector<SurfacePoint>* stop_points = NULL) = 0;
36 virtual void trace_back(SurfacePoint& destination,
37 std::vector<SurfacePoint>& path) = 0;
40 SurfacePoint& destination,
41 std::vector<SurfacePoint>& path);
43 void geodesic(std::vector<SurfacePoint>& sources,
44 std::vector<SurfacePoint>& destinations,
45 std::vector<std::vector<SurfacePoint> >& paths);
47 virtual unsigned best_source(SurfacePoint& point,
48 double& best_source_distance) = 0;
50 virtual void print_statistics()
52 std::cout <<
"propagation step took " << m_time_consumed <<
" seconds " << std::endl;
55 AlgorithmType type(){
return m_type;};
57 virtual std::string name();
59 geodesic::Mesh* mesh(){
return m_mesh;};
62 void set_stop_conditions(std::vector<SurfacePoint>* stop_points,
63 double stop_distance);
64 double stop_distance()
66 return m_max_propagation_distance;
71 typedef std::pair<vertex_pointer, double> stop_vertex_with_distace_type;
72 std::vector<stop_vertex_with_distace_type> m_stop_vertices;
73 double m_max_propagation_distance;
75 geodesic::Mesh* m_mesh;
77 double m_time_consumed;
78 double m_propagation_distance_stopped;
81 inline double length(std::vector<SurfacePoint>& path)
86 for(
unsigned i=0; i<path.size()-1; ++i)
88 length += path[i].distance(&path[i+1]);
94 inline void print_info_about_path(std::vector<SurfacePoint>& path)
96 std::cout <<
"number of the points in the path = " << path.size()
97 <<
", length of the path = " << length(path)
101 inline std::string GeodesicAlgorithmBase::name()
110 return "subdivision";
112 case UNDEFINED_ALGORITHM:
117 inline void GeodesicAlgorithmBase::geodesic(SurfacePoint& source,
118 SurfacePoint& destination,
119 std::vector<SurfacePoint>& path)
121 std::vector<SurfacePoint> sources(1, source);
122 std::vector<SurfacePoint> stop_points(1, destination);
123 double const max_propagation_distance = GEODESIC_INF;
126 max_propagation_distance,
129 trace_back(destination, path);
132 inline void GeodesicAlgorithmBase::geodesic(std::vector<SurfacePoint>& sources,
133 std::vector<SurfacePoint>& destinations,
134 std::vector<std::vector<SurfacePoint> >& paths)
136 double const max_propagation_distance = GEODESIC_INF;
139 max_propagation_distance,
142 paths.resize(destinations.size());
144 for(
unsigned i=0; i<paths.size(); ++i)
146 trace_back(destinations[i], paths[i]);
150 inline void GeodesicAlgorithmBase::set_stop_conditions(std::vector<SurfacePoint>* stop_points,
151 double stop_distance)
153 m_max_propagation_distance = stop_distance;
157 m_stop_vertices.clear();
161 m_stop_vertices.resize(stop_points->size());
163 std::vector<vertex_pointer> possible_vertices;
164 for(
unsigned i = 0; i < stop_points->size(); ++i)
166 SurfacePoint* point = &(*stop_points)[i];
168 possible_vertices.clear();
169 m_mesh->closest_vertices(point, &possible_vertices);
171 vertex_pointer closest_vertex = NULL;
172 double min_distance = 1e100;
173 for(
unsigned j = 0; j < possible_vertices.size(); ++j)
175 double distance = point->distance(possible_vertices[j]);
176 if(distance < min_distance)
178 min_distance = distance;
179 closest_vertex = possible_vertices[j];
182 FEASSERT(closest_vertex);
184 m_stop_vertices[i].first = closest_vertex;
185 m_stop_vertices[i].second = min_distance;
191 #endif //GEODESIC_ALGORITHM_BASE_122806 Definition: geodesic_cpp_03_02_2008/geodesic_algorithm_base.h:11