projection_mesh.cpp
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 _projection_mesh_CPP_
34 #define _projection_mesh_CPP_
35 
36 #include "projection_mesh.h"
37 
38 
39 
41 {
42  for (PT::Vertex_iterator it=mesh.vertices_begin(); it!=mesh.vertices_end(); ++it)
43  {
44  mesh.remove_incident_constraints(it);
45  }
46  return 1;
47 }
48 
50 {
51  mesh.clear();
52  return 1;
53 }
54 
55 int class_projection_mesh::set_constraint_polygon(std::vector<pcl::PointXY>* p)
56 {
57  PT::Locate_type lt;
58  int li;
59  std::vector<PT::Vertex_handle> vv;
60 
61  for (size_t i=0; i<p->size();i++)
62  {
63  pcl::PointXY pt = p->at(i);
64  PT::Face_handle fh = mesh.locate(PT::Point(pt.x,pt.y), lt, li);
65 
66  if (lt==PT::VERTEX)
67  {
68  vv.push_back(fh->vertex(li));
69  }
70  else
71  {
73  vh = mesh.insert(PT::Point(pt.x,pt.y));
74  vh->info().z = 0;
75  vh->info().rgb = -1;
76  vh->info().weight = 0;
77  vv.push_back(vh);
78  }
79  }
80 
81 
82  for (size_t i=1; i<vv.size();i++)
83  {
84  mesh.insert_constraint(vv[i-1], vv[i]);
85  }
86  mesh.insert_constraint(vv[vv.size()-1], vv[0]);
87 
88  return 1;
89 }
90 
91 int class_projection_mesh::add_vertex_to_mesh(double x, double y, double z, float rgb, float weight)
92 {
94  vh = mesh.insert(PT::Point(x,y));
95  vh->info().z = z;
96  vh->info().rgb = rgb;
97  vh->info().weight = weight;
98  return 1;
99 }
100 
102 {
103  for(PT::All_faces_iterator it = mesh.all_faces_begin(); it != mesh.all_faces_end(); ++it)
104  {
105  it->counter=-1;
106  it->status=-1;
107  }
108  return 1;
109 }
110 
111 
113  PT::Face_handle start,
114  int index,
115  std::list<PT::Edge>& border )
116 {
117  if(start->counter != -1)
118  {
119  return;
120  }
121  std::list<PT::Face_handle> queue;
122  queue.push_back(start);
123 
124  while(! queue.empty())
125  {
126  PT::Face_handle fh = queue.front();
127  queue.pop_front();
128  if(fh->counter == -1)
129  {
130  fh->counter = index;
131  fh->set_in_domain(index%2 == 1);
132  for(int i = 0; i < 3; i++)
133  {
134  PT::Edge e(fh,i);
135  PT::Face_handle n = fh->neighbor(i);
136  if(n->counter == -1)
137  {
138  if(ct.is_constrained(e))
139  {
140  border.push_back(e);
141  }
142  else
143  {
144  queue.push_back(n);
145  }
146  }
147 
148  }
149  }
150  }
151 }
152 
154 {
155  int index = 0;
156  std::list<PT::Edge> border;
157  discoverComponent(ct, ct.infinite_face(), index++, border);
158  while(! border.empty())
159  {
160  PT::Edge e = border.front();
161  border.pop_front();
162  PT::Face_handle n = e.first->neighbor(e.second);
163  if(n->counter == -1)
164  {
165  discoverComponent(ct, n, e.first->counter+1, border);
166  }
167  }
168 }
169 
170 
171 int class_projection_mesh::draw_mesh_triangles(cv::Mat* image, cv::Scalar color, int thickness)
172 {
173  for(PT::Finite_faces_iterator fc1 = mesh.finite_faces_begin(); fc1 != mesh.finite_faces_end(); ++fc1)
174  {
175  if (!fc1->is_in_domain())
176  {
177  //continue;
178  }
179 
180  cv::line(*image, cv::Point2d( CGAL::to_double(fc1->vertex(0)->point().x()), CGAL::to_double(fc1->vertex(0)->point().y())), cv::Point2d( CGAL::to_double(fc1->vertex(1)->point().x()), CGAL::to_double(fc1->vertex(1)->point().y())), color, thickness);
181  cv::line(*image, cv::Point2d( CGAL::to_double(fc1->vertex(1)->point().x()), CGAL::to_double(fc1->vertex(1)->point().y())), cv::Point2d( CGAL::to_double(fc1->vertex(2)->point().x()), CGAL::to_double(fc1->vertex(2)->point().y())), color, thickness);
182  cv::line(*image, cv::Point2d( CGAL::to_double(fc1->vertex(0)->point().x()), CGAL::to_double(fc1->vertex(0)->point().y())), cv::Point2d( CGAL::to_double(fc1->vertex(2)->point().x()), CGAL::to_double(fc1->vertex(2)->point().y())), color, thickness);
183  }
184 
185  return 1;
186 }
187 
188 
190 {
191  for(PT::Finite_faces_iterator fi = mesh.finite_faces_begin(); fi != mesh.finite_faces_end(); ++fi)
192  {
193  if (!fi->is_in_domain())
194  {
195  //continue;
196  }
197 
198  fi->weight = (fi->vertex(0)->info().weight + fi->vertex(1)->info().weight + fi->vertex(2)->info().weight)/3.0;
199  }
200 
201 
202  return 1;
203 }
204 
205 int class_projection_mesh::export_triangles_in_order(pcl::PointCloud<pcl::PointXYZRGB>* vertex_list, std::vector<float>* face_weights)
206 {
207  //erase both lists
208  vertex_list->points.erase(vertex_list->points.begin(), vertex_list->points.end());
209  vertex_list->erase(vertex_list->begin(), vertex_list->end());
210 
211  pcl::PointXYZRGB pt;
212 
214 
215  std::vector<PT::Face_handle> queue;
216  PT::Finite_faces_iterator fi= mesh.finite_faces_begin();
217  queue.push_back(fi);
218 
219 
220  for (size_t i=0; i<queue.size(); i++)
221  {
222  if (queue[i]->visited==false)
223  {
224  //propagate
225  PT::Face_handle nfh;
226 
227  nfh = queue[i]->neighbor(0);
228  if (nfh->visited==false && !mesh.is_infinite(nfh))
229  {
230  queue.push_back(nfh);
231  }
232 
233  nfh = queue[i]->neighbor(1);
234  if (nfh->visited==false && !mesh.is_infinite(nfh))
235  {
236  queue.push_back(nfh);
237  }
238 
239  nfh = queue[i]->neighbor(2);
240  if (nfh->visited==false && !mesh.is_infinite(nfh))
241  {
242  queue.push_back(nfh);
243  }
244 
245  queue[i]->visited=true;
246 
247  if (queue[i]->is_in_domain())
248  {
249  for (int u=0; u<3;u++)
250  {
251  pt.x = CGAL::to_double(queue[i]->vertex(u)->point().x());
252  pt.y = CGAL::to_double(queue[i]->vertex(u)->point().y());
253  pt.z = CGAL::to_double(queue[i]->vertex(u)->info().z);
254  pt.rgb = queue[i]->vertex(u)->info().rgb;
255  vertex_list->points.push_back(pt);
256  }
257  face_weights->push_back(queue[i]->weight);
258  }
259  queue.erase(queue.begin()+i);
260  i=-1;
261  }
262  }
263 
264  return 1;
265 }
266 
267 
268 int class_projection_mesh::export_triangles(pcl::PointCloud<pcl::PointXYZRGB>* vertex_list, std::vector<float>* face_weights)
269 {
270  //erase both lists
271  vertex_list->points.erase(vertex_list->points.begin(), vertex_list->points.end());
272  vertex_list->erase(vertex_list->begin(), vertex_list->end());
273 
274  pcl::PointXYZRGB pt;
275 
276  for(PT::Finite_faces_iterator fi = mesh.finite_faces_begin(); fi != mesh.finite_faces_end(); ++fi)
277  {
278  if (!fi->is_in_domain())
279  {
280  continue;
281  }
282 
283  for (int u=0; u<3;u++)
284  {
285  pt.x = CGAL::to_double(fi->vertex(u)->point().x());
286  pt.y = CGAL::to_double(fi->vertex(u)->point().y());
287  pt.z = CGAL::to_double(fi->vertex(u)->info().z);
288  pt.rgb = fi->vertex(u)->info().rgb;
289  vertex_list->points.push_back(pt);
290  }
291 
292  face_weights->push_back(fi->weight);
293  }
294 
295  return 1;
296 }
297 #endif
298 
int initialize_all_faces_status(void)
void discoverComponents(const PT &ct)
CDT::All_faces_iterator All_faces_iterator
CDT::Vertex_iterator Vertex_iterator
int draw_mesh_triangles(cv::Mat *image, cv::Scalar color, int thickness)
Delaunay::Edge Edge
Definition: preh.h:77
Ss::Vertex_handle Vertex_handle
void discoverComponent(const PT &ct, PT::Face_handle start, int index, std::list< PT::Edge > &border)
Header for projection mesh.
int set_constraint_polygon(std::vector< pcl::PointXY > *p)
K::Point_2 Point
Definition: preh.h:66
CGAL::Constrained_triangulation_plus_2< CGAL::Constrained_Delaunay_triangulation_2< K, TDS_projection_mesh, CGAL::No_intersection_tag > > PT
Delaunay::Locate_type Locate_type
Definition: preh.h:82
int add_vertex_to_mesh(double x, double y, double z, float rgb, float weight)
int export_triangles_in_order(pcl::PointCloud< pcl::PointXYZRGB > *vertex_list, std::vector< float > *face_weights)
CDT::Finite_faces_iterator Finite_faces_iterator
CDT::Face_handle Face_handle
int export_triangles(pcl::PointCloud< pcl::PointXYZRGB > *vertex_list, std::vector< float > *face_weights)


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