MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / vtk_to_pointcloud

Function vtk_to_pointcloud

tools/obj_rec_ransac_hash_table.cpp:109–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107//===========================================================================================================================================
108
109bool vtk_to_pointcloud (const char* file_name, PointCloud<PointXYZ>& points_in, PointCloud<Normal>& normals_in, double b[6])
110{
111 std::size_t len = strlen (file_name);
112 if ( file_name[len-3] != 'v' || file_name[len-2] != 't' || file_name[len-1] != 'k' )
113 {
114 fprintf (stderr, "ERROR: we need a .vtk object!\n");
115 return false;
116 }
117
118 // Load the model
119 vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New ();
120 reader->SetFileName (file_name);
121 reader->Update ();
122
123 // Get the points
124 vtkPolyData *vtk_poly = reader->GetOutput ();
125 vtkPoints *vtk_points = vtk_poly->GetPoints ();
126 vtkIdType num_points = vtk_points->GetNumberOfPoints ();
127 double p[3];
128
129 vtk_poly->ComputeBounds ();
130 vtk_poly->GetBounds (b);
131 points_in.resize (num_points);
132
133 // Copy the points
134 for ( vtkIdType i = 0 ; i < num_points ; ++i )
135 {
136 vtk_points->GetPoint (i, p);
137 points_in[i].x = static_cast<float> (p[0]);
138 points_in[i].y = static_cast<float> (p[1]);
139 points_in[i].z = static_cast<float> (p[2]);
140 }
141
142 // Check if we have normals
143 vtkDataArray *vtk_normals = vtk_poly->GetPointData ()->GetNormals ();
144 if ( vtk_normals )
145 {
146 normals_in.resize (num_points);
147 // Copy the normals
148 for ( vtkIdType i = 0 ; i < num_points ; ++i )
149 {
150 vtk_normals->GetTuple (i, p);
151 normals_in[i].normal_x = static_cast<float> (p[0]);
152 normals_in[i].normal_y = static_cast<float> (p[1]);
153 normals_in[i].normal_z = static_cast<float> (p[2]);
154 }
155 }
156
157 return true;
158}
159
160//===========================================================================================================================================
161

Callers 1

mainFunction · 0.70

Calls 3

NewFunction · 0.85
resizeMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected