KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_find_shapes.h
Go to the documentation of this file.
1 /* $Id$ */
35 /* =========================================================================== *
36 |
37 | Copyright (c) 1994-2008 by Kobus Barnard (author).
38 |
39 | Personal and educational use of this code is granted, provided that this
40 | header is kept intact, and that the authorship is not misrepresented, that
41 | its use is acknowledged in publications, and relevant papers are cited.
42 |
43 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
44 |
45 | Please note that the code in this file has not necessarily been adequately
46 | tested. Naturally, there is no guarantee of performance, support, or fitness
47 | for any particular task. Nonetheless, I am interested in hearing about
48 | problems that you encounter.
49 |
50 | Authors:
51 | Emily Hartley
52 |
53 * =========================================================================== */
54 
55 #ifndef KJB_FIND_SHAPES_H
56 #define KJB_FIND_SHAPES_H
57 
59 #include <gr_cpp/gr_polygon.h>
61 #include <m_cpp/m_int_vector.h>
62 #include <g_cpp/g_cylinder.h>
64 #include <g_cpp/g_circle.h>
65 #include <vector>
66 
67 namespace kjb {
68 
74 (
75  const Vector& normal,
76  const Vector& point_on_plane,
77  Vector& plane_params
78 );
79 
85 (
86  const Vector& pt1,
87  const Vector& pt2,
88  const Vector& pt3,
89  Vector& plane_params
90 );
91 
96 (
97  const Vector& plane1_params,
98  const Vector& plane2_params,
99  double tolerance,
100  double distTolerance=1.0
101 );
102 
107 (
108  const Vector& p1,
109  const Vector& p2,
110  const Vector& p3,
111  const Vector& p4,
112  double tolerance
113 );
114 
120 (
121  const Vector& plane1_params,
122  const Vector& plane2_params
123 ) throw (Illegal_argument, KJB_error);
124 
126 
131 void find_planes(const Polymesh& p, std::vector<Polymesh_Plane>& plane);
132 
136 void render_planes
137 (
138  const Polymesh& p,
139  const std::vector<Polymesh_Plane>& planes
140 );
141 
147 (
148  Polymesh& p,
149  std::vector<Circle_in_3d>& circles,
150  std::vector<std::vector<Vector> >& points
151 );
152 
154 
160 (
161  const std::vector<kjb::Polygon>& faces,
162  Int_vector& mask
163 );
164 
170 void find_rectangles
171 (
172  const std::vector<kjb::Polygon>& faces,
173  const Int_vector& mask,
174  const Polymesh& p,
175  std::vector<Right_Triangle_Pair>& rectangles
176 );
177 
183 (
184  const Polymesh& p,
185  const std::vector<Right_Triangle_Pair>& rectangles,
186  Int_vector& rectMask
187 );
188 
194 (
195  const Polymesh& p,
196  const Int_vector& cylMask,
197  const Int_vector& rectMask,
198  const std::vector<Right_Triangle_Pair>& rectangles,
199  int startIndex,
200  int rectIndex,
201  int prevAdjFace,
202  double width,
203  double lengthTolerance,
204  double& smallestAngle,
205  double& largestAngle,
206  double& sumAngles,
207  std::vector<int>& cyl_indices,
208  Vector& edge_pt1,
209  Vector& edge_pt2,
210  Vector& edge_pt1_adj,
211  Vector& edge_pt_adj
212 );
213 
217 void find_cylinders
218 (
219  const Polymesh& p,
220  const std::vector<Right_Triangle_Pair>& rectangles,
221  std::vector<std::vector<int> >& cyl_indices,
222  std::vector<double>& cylSumAngles,
223  std::vector<std::vector<Vector> >& cylEdgePoints
224 );
225 
227 
233 (
234  const Polymesh& p,
235  const Int_vector& rectMask,
236  const std::vector<Right_Triangle_Pair>& rectangles,
237  const std::vector<int>& cyl_indices,
238  std::vector<Vector>& top_points,
239  std::vector<Vector>& bottom_points
240 );
241 
246 (
247  const std::vector<Vector>& points,
248  Vector& centroid
249 );
250 
256 (
257  const std::vector<Vector>& points,
258  const Vector& centroid,
259  Vector& plane_params
260 );
261 
266 (
267  std::vector<Vector>& points,
268  const Vector& plane_params,
269  const Vector& centroid,
270  std::vector<Vector>& projected_points
271 );
272 
273 /*
274  * @brief Maps a 3D plane to the X-Y plane.
275  */
277 (
278  const std::vector<Vector>& points,
279  const Vector& plane_params,
280  std::vector<Vector>& translated_points,
281  std::vector<Matrix>& transformMatrices
282 );
283 
284 /*
285  * @brief Using the transformMatrices from translate_3d_plane_to_xy_plane(),
286  * maps a point on the X-Y plane back onto the original 3D plane.
287  */
289 (
290  const Vector& point,
291  const std::vector<Matrix>& transformMatrices,
292  Vector& translated_point
293 );
294 
299 void fit_cylinder
300 (
301  const Polymesh& p,
302  const Int_vector& rectMask,
303  const std::vector<Right_Triangle_Pair>& rectangles,
304  const std::vector<int>& cyl_indices,
305  double cylAngle,
306  const std::vector<Vector>& cylEdgePoints,
307  Cylinder_section& cyl
308 );
309 
310 
312 
314 (
315  char* faceFile,
316  char* cylFile,
317  const Polymesh& p,
318  std::vector<Polymesh_Plane>& plane,
319  std::vector<Cylinder_section>& cyl
320 );
321 
326 (
327  const Polymesh& p,
328  std::vector<Polymesh_Plane>& plane
329 );
330 
335 (
336  const Polymesh& p,
337  std::vector<Polymesh_Plane>& plane
338 );
339 
344 (
345  const Polymesh& p,
346  std::vector<Polymesh_Plane>& plane
347 );
348 
354 (
355  const Polymesh& p,
356  std::vector<Polymesh_Plane>& plane
357 );
358 
359 }
360 
361 #endif
void find_planes(const Polymesh &p, std::vector< Polymesh_Plane > &plane)
Finds all of the planes in a polymesh and stores each set of coefficients along with the correspondin...
Definition: gr_find_shapes.cpp:385
void render_planes(const Polymesh &p, const std::vector< Polymesh_Plane > &planes)
Renders each plane in a polymesh with a different color.
Definition: gr_find_shapes.cpp:472
void create_rectangle_mask(const Polymesh &p, const std::vector< Right_Triangle_Pair > &rectangles, Int_vector &rectMask)
Creates an Int_vector mask representing the faces in a polymesh that are part of a rectangle...
Definition: gr_find_shapes.cpp:1044
double get_angle_between_two_vectors(const Vector &plane1_params, const Vector &plane2_params)
Calculates the smaller angle between the normal vectors of two planes. The angle returned is in radia...
Definition: gr_find_shapes.cpp:337
void translate_xy_point_to_3d_plane(const Vector &point, const std::vector< Matrix > &transformMatrices, Vector &translated_point)
Definition: gr_find_shapes.cpp:3027
REAL * point
Definition: triangle.c:537
void find_adjacent_rectangles(const Polymesh &p, const Int_vector &cylMask, const Int_vector &rectMask, const std::vector< Right_Triangle_Pair > &rectangles, int startIndex, int rectIndex, int prevAdjFace, double width, double lengthTolerance, double &smallestAngle, double &largestAngle, double &sumAngles, std::vector< int > &cyl_indices, Vector &edge_pt1, Vector &edge_pt2, Vector &edge_pt1_adj, Vector &edge_pt_adj)
Determines which rectangles are adjacent to eachother and if a group of adjacent rectangles form part...
Definition: gr_find_shapes.cpp:1109
void fit_plane_to_3d_points(const std::vector< Vector > &points, const Vector &centroid, Vector &plane_params)
Uses singular value decomposition (SVD) to fit a plane to a set of 3D points.
Definition: gr_find_shapes.cpp:2726
void find_rectangles(const std::vector< kjb::Polygon > &faces, const Int_vector &mask, const Polymesh &p, std::vector< Right_Triangle_Pair > &rectangles)
Finds all pairs of right triangles in a polymesh that are coplanar, adjacent along their hypotenuses...
Definition: gr_find_shapes.cpp:856
void fit_cylinder(const Polymesh &p, const Int_vector &rectMask, const std::vector< Right_Triangle_Pair > &rectangles, const std::vector< int > &cyl_indices, double cylAngle, const std::vector< Vector > &cylEdgePoints, Cylinder_section &cyl)
Determines the parameters of the cylinder formed by a set of faces in the polymesh.
Definition: gr_find_shapes.cpp:3089
void find_rectangles_to_render(const Polymesh &p, std::vector< Polymesh_Plane > &plane)
Renders each pair of faces that forms a rectangle a different color.
Definition: gr_find_shapes.cpp:3584
void find_top_and_bottom_points_of_cylinder(const Polymesh &p, const Int_vector &rectMask, const std::vector< Right_Triangle_Pair > &rectangles, const std::vector< int > &cyl_indices, std::vector< Vector > &top_points, std::vector< Vector > &bottom_points)
Determines which points make up the 'top' and which points make up the 'bottom' of the cylinder speci...
Definition: gr_find_shapes.cpp:2250
Cylinder_section: a section of a geometric cylinder.
void translate_3d_plane_to_xy_plane(const std::vector< Vector > &points, const Vector &plane_params, std::vector< Vector > &translated_points, std::vector< Matrix > &transformMatrices)
Definition: gr_find_shapes.cpp:2862
void find_cylinders_to_render_and_fit(char *faceFile, char *cylFile, const Polymesh &p, std::vector< Polymesh_Plane > &plane, std::vector< Cylinder_section > &cyl)
Definition: gr_find_shapes.cpp:3417
void find_cylinders(const Polymesh &p, const std::vector< Right_Triangle_Pair > &rectangles, std::vector< std::vector< int > > &cyl_indices, std::vector< double > &cylSumAngles, std::vector< std::vector< Vector > > &cylEdgePoints)
Determines which groups of faces in the polymesh form cylinders.
Definition: gr_find_shapes.cpp:1400
void find_right_triangles_to_render(const Polymesh &p, std::vector< Polymesh_Plane > &plane)
Renders each face that is a right triangle in a different color.
Definition: gr_find_shapes.cpp:3647
void find_adjacent_right_triangles_to_render(const Polymesh &p, std::vector< Polymesh_Plane > &plane)
Renders each face that is a right triangle and adjacent to another face that is also a right triangle...
Definition: gr_find_shapes.cpp:3697
void get_plane_parameters(const Vector &normal, const Vector &point_on_plane, Vector &plane_params)
Finds the coefficients of the plane of the form ax + by + cz + d = 0 given the normal vector and a po...
Definition: gr_find_shapes.cpp:88
void find_right_triangles(const std::vector< kjb::Polygon > &faces, Int_vector &mask)
Creates an Int_vector mask representing the faces in a polymesh that are right triangles.
Definition: gr_find_shapes.cpp:828
void find_centroid_of_3d_points(const std::vector< Vector > &points, Vector &centroid)
Finds the center of a set of 3D points.
Definition: gr_find_shapes.cpp:2673
bool check_if_4_points_are_coplanar(const Vector &p1, const Vector &p2, const Vector &p3, const Vector &p4, double tolerance)
Checks if 4 points are coplanar.
Definition: gr_find_shapes.cpp:277
void find_cylinders_to_render(const Polymesh &p, std::vector< Polymesh_Plane > &plane)
Renders each set of faces that forms a cylinder a different color.
Definition: gr_find_shapes.cpp:3520
This class contains a Vector of plane parameters, a list of the face indices that lie in the plane...
struct memorypool points
Definition: triangle.c:637
bool check_if_faces_are_coplanar(const Vector &plane1_params, const Vector &plane2_params, double tolerance, double distTolerance=1.0)
Checks if two faces in a polymesh are coplanar.
Definition: gr_find_shapes.cpp:195
void find_all_circles_in_polymesh(Polymesh &p, std::vector< Circle_in_3d > &circles, std::vector< std::vector< Vector > > &points)
Finds all of the circles and the points that lie on them in the polymesh.
Definition: gr_find_shapes.cpp:563
void project_points_onto_plane(std::vector< Vector > &points, const Vector &plane_params, const Vector &centroid, std::vector< Vector > &projected_points)
Projects 3D points onto the best-fit 3D plane.
Definition: gr_find_shapes.cpp:2781