Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <pcl/surface/simplification_remove_unused_vertices.h>
00039
00040 #include <cstring>
00041 #include <vector>
00042 #include <iostream>
00043 #include <stdio.h>
00044
00045 void
00046 pcl::surface::SimplificationRemoveUnusedVertices::simplify(const pcl::PolygonMesh& input, pcl::PolygonMesh& output, std::vector<int>& indices)
00047 {
00048 if (input.polygons.size () == 0)
00049 return;
00050
00051 unsigned int nr_points = input.cloud.width * input.cloud.height;
00052
00053 std::vector<int> new_indices (nr_points, -1);
00054 indices.clear ();
00055 indices.reserve (nr_points);
00056
00057
00058 for (size_t polygon = 0; polygon < input.polygons.size (); ++polygon)
00059 for (size_t point = 0; point < input.polygons[polygon].vertices.size (); ++point)
00060 if (new_indices[ input.polygons[polygon].vertices[point] ] == -1 )
00061 {
00062 new_indices[input.polygons[polygon].vertices[point]] = static_cast<int> (indices.size ());
00063 indices.push_back (input.polygons[polygon].vertices[point]);
00064 }
00065
00066
00067 if (indices.size () == nr_points)
00068 {
00069 output = input;
00070 return;
00071 }
00072
00073
00074 output.header = input.header;
00075 output.cloud.data.clear ();
00076 output.cloud.header = input.cloud.header;
00077 output.cloud.fields = input.cloud.fields;
00078 output.cloud.row_step = input.cloud.row_step;
00079 output.cloud.point_step = input.cloud.point_step;
00080 output.cloud.is_bigendian = input.cloud.is_bigendian;
00081 output.cloud.height = 1;
00082 output.cloud.width = static_cast<int> (indices.size ());
00083 output.cloud.row_step = output.cloud.point_step * output.cloud.width;
00084 output.cloud.data.resize (output.cloud.width * output.cloud.height * output.cloud.point_step);
00085 output.cloud.is_dense = false;
00086 output.polygons.clear ();
00087
00088
00089 for (size_t i = 0; i < indices.size (); ++i)
00090 memcpy (&output.cloud.data[i * output.cloud.point_step], &input.cloud.data[indices[i] * output.cloud.point_step], output.cloud.point_step);
00091
00092
00093 output.polygons.reserve (input.polygons.size ());
00094 for (size_t polygon = 0; polygon < input.polygons.size (); ++polygon)
00095 {
00096 pcl::Vertices corrected_polygon;
00097 corrected_polygon.vertices.resize (input.polygons[polygon].vertices.size ());
00098 for (size_t point = 0; point < input.polygons[polygon].vertices.size(); ++point)
00099 corrected_polygon.vertices[point] = new_indices[input.polygons[polygon].vertices[point]];
00100 output.polygons.push_back (corrected_polygon);
00101 }
00102 }
00103