textured_triangle.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
33 #ifndef _TEXTURED_TRIANGLE_H_
34 #define _TEXTURED_TRIANGLE_H_
35 
36 //####################################################################
37 // Includes:
38 //####################################################################
39 
40 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
41 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
42 
43 typedef CGAL::Exact_predicates_inexact_constructions_kernel K1;
44 //typedef CGAL::Triangulation_vertex_base_2<K1> Vb1;
45 //typedef CGAL::Constrained_triangulation_face_base_2<K1> Fb1;
46 //typedef CGAL::Triangulation_data_structure_2<Vb1,Fb1> TDS1;
47 //typedef CGAL::Exact_predicates_tag Itag1;
48 //typedef CGAL::Constrained_Delaunay_triangulation_2<K1, TDS1, Itag1> CDT2;
49 
50 
51 
52 
53 //System Includes
54 #include <pcl/segmentation/sac_segmentation.h>
55 #include <pcl/filters/project_inliers.h>
56 #include <pcl/point_cloud.h>
57 #include <pcl/point_types.h>
58 #include <pcl_ros/transforms.h>
59 #include <pcl/ModelCoefficients.h>
60 #include <tf/tf.h>
61 #include <visualization_msgs/Marker.h>
62 #include <queue>
63 
64 #define DONT_INTERSECT 0
65 #define DO_INTERSECT 1
66 #define COLLINEAR 2
67 
68 #define SAME_SIGNS( a, b ) \
69  (((long) ((unsigned long) a ^ (unsigned long) b)) >= 0 )
70 
71 
72 
74 {
75  public:
77  class_textured_vertex(float vx, float vy, float vz, float vrgb);
79 
81  {
83  v_out.x = vin.x;
84  v_out.y = vin.y;
85  v_out.z = vin.z;
86  v_out.rgb = vin.rgb;
87  return v_out;
88 
89  }
90 
91  float x,y,z,rgb;
92 
93 };
94 
96 {
97  public:
100 
102 
104  float weight;
105  float provenience;
106 
108  void print_info(void)
109  {
110  ROS_INFO("v0 x=%f y=%f z=%f rgb=%f\n v1 x=%f y=%f z=%f rgb=%f\n v2 x=%f y=%f z=%f rgb=%f\n", v[0].x, v[0].y, v[0].z, v[0].rgb, v[1].x, v[1].y, v[1].z, v[1].rgb,v[2].x, v[2].y, v[2].z, v[2].rgb);
111  }
112 
113  private:
114  //
115 
116  int test2( double px, double py, double m, double b ) {
117  if (py < m * px + b ) {
118  return -1; // point is under line
119  }else if ( py == m * px + b ){
120  return 0; // point is on line
121  } else {
122  return 1; // point is over line
123  }
124  }
125 
126  int test1(double px, double py, double m,double b, double lx,double ly) {
127  return (test2(px,py, m,b) == test2(lx,ly,m,b));
128  }
129 
130 
131 
132  int point_inside_triangle(double x0,double y0,double x1,double y1,double x2,double y2,double px, double py)
133  {
134  int line1, line2, line3;
135  double m01 = (y1-y0)/(x1-x0);
136  double b01 = m01 * -x1 + y1;
137  double m02, m12, b02, b12;
138  m02 = (y2-y0)/(x2-x0);
139  m12 = (y2-y1)/(x2-x1);
140  b02 = m02 * -x2 + y2;
141  b12 = m12 * -x2 + y2;
142 
143 
144  // vertical line checks
145 
146  if( x1 == x0 ) {
147  line1 = ( (px < x0) == (x2 < x0) );
148  } else {
149  line1 = test1( px, py, m01, b01,x2,y2);
150  }
151 
152  if( x1 == x2 ) {
153  line2 = ( (px < x2) == (x0 < x2) );
154  } else {
155  line2 = test1(px,py, m12, b12,x0,y0);
156  }
157 
158  if( x2 == x0 ) {
159  line3 = ( (px < x0 ) == (x1 < x0) );} else {
160  line3 = test1(px, py, m02,b02,x1,y1);
161  }
162 
163  if(line1==-1 && line2==-1 && line3==-1)
164  return 1;
165  else if(line1==1 && line2==1 && line3==1)
166  return 1;
167  else
168  return 0;
169 
170 
171  //return line1 && line2 && line3;
172  }
173 
174 
180  float Ax, float Ay,
181  float Bx, float By,
182  float Cx, float Cy,
183  float Dx, float Dy,
184  double *X, double *Y) {
185 
186  double distAB, theCos, theSin, newX, ABpos ;
187 
188  // Fail if either line segment is zero-length.
189  if (((Ax==Bx) && (Ay==By)) || ((Cx==Dx) && (Cy==Dy))) return DONT_INTERSECT;
190 
191  // Fail if the segments share an end-point.
192  if (((Ax==Cx) && (Ay==Cy)) || ((Bx==Cx) && (By==Cy))
193  || ((Ax==Dx) && (Ay==Dy)) || ((Bx==Dx) && (By==Dy))) {
194  return DONT_INTERSECT; }
195 
196  // (1) Translate the system so that point A is on the origin.
197  Bx-=Ax; By-=Ay;
198  Cx-=Ax; Cy-=Ay;
199  Dx-=Ax; Dy-=Ay;
200 
201  // Discover the length of segment A-B.
202  distAB=sqrt(Bx*Bx+By*By);
203 
204  // (2) Rotate the system so that point B is on the positive X axis.
205  theCos=Bx/distAB;
206  theSin=By/distAB;
207  newX=Cx*theCos+Cy*theSin;
208  Cy =Cy*theCos-Cx*theSin; Cx=newX;
209  newX=Dx*theCos+Dy*theSin;
210  Dy =Dy*theCos-Dx*theSin; Dx=newX;
211 
212  // Fail if segment C-D doesn't cross line A-B.
213  if ((Cy<0. && Dy<0.) || (Cy>=0. && Dy>=0.)) return DONT_INTERSECT;
214 
215  // (3) Discover the position of the intersection point along line A-B.
216  ABpos=Dx+(Cx-Dx)*Dy/(Dy-Cy);
217 
218  // Fail if segment C-D crosses line A-B outside of segment A-B.
219  if (ABpos<0. || ABpos>distAB) return DONT_INTERSECT;
220 
221  // (4) Apply the discovered position to line A-B in the original coordinate system.
222  *X=Ax+ABpos*theCos;
223  *Y=Ay+ABpos*theSin;
224 
225  // Success.
226  return DO_INTERSECT;
227  }
228 
229 
230 };
231 
232 typedef enum
233 {
234  FORCE=55,
236 }t_add_method;
237 
238 
239 #define ADDED_TRIANGLE 1
240 #define DID_NOT_ADD_TRIANGLE 0
241 
246 {
247  public:
248 
249  //methods
251  {
252  next_key=0;
253  };
254 
256 
257  int add_triangle(class_textured_vertex v0, class_textured_vertex v1, class_textured_vertex v2, int provenience, float weight, t_add_method method);
258  int set_transform(tf::Transform* st);
259  int export_to_pc(void);
260 
261  //Variables
262  std::vector<boost::shared_ptr<class_textured_triangle> > set;
263  pcl::PointCloud<pcl::PointXYZRGB> pc;
264  std::vector<int> pc_proveniences;
265  tf::Transform transform;
266  size_t next_key;
267 };
268 
269 
270 #endif
271 
int point_inside_triangle(double x0, double y0, double x1, double y1, double x2, double y2, double px, double py)
#define DO_INTERSECT
int set_transform(tf::Transform *st)
std::vector< int > pc_proveniences
class_textured_vertex v[3]
bool overlaps(class_textured_triangle *t)
#define DONT_INTERSECT
class_textured_vertex operator=(class_textured_vertex vin)
int test2(double px, double py, double m, double b)
CGAL::Exact_predicates_inexact_constructions_kernel K1
int add_triangle(class_textured_vertex v0, class_textured_vertex v1, class_textured_vertex v2, int provenience, float weight, t_add_method method)
t_add_method
std::vector< boost::shared_ptr< class_textured_triangle > > set
int test1(double px, double py, double m, double b, double lx, double ly)
int lineSegmentIntersection(float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Dx, float Dy, double *X, double *Y)
public domain function by Darel Rex Finley, 2006. Determines the intersection point of the line segme...
pcl::PointCloud< pcl::PointXYZRGB > pc
unsigned char b[16]
tf::Transform transform


polygon_primitives_extraction
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:42