| 160 | //=========================================================================================================================================== |
| 161 | |
| 162 | void |
| 163 | visualize (const ModelLibrary::HashTable& hash_table) |
| 164 | { |
| 165 | PCLVisualizer vis; |
| 166 | vis.setBackgroundColor (0.1, 0.1, 0.1); |
| 167 | |
| 168 | const ModelLibrary::HashTableCell* cells = hash_table.getVoxels (); |
| 169 | std::size_t max_num_entries = 0; |
| 170 | int id3[3], num_cells = hash_table.getNumberOfVoxels (); |
| 171 | float half_side, b[6], cell_center[3], spacing = hash_table.getVoxelSpacing ()[0]; |
| 172 | char cube_id[128]; |
| 173 | |
| 174 | // Just get the maximal number of entries in the cells |
| 175 | for ( int i = 0 ; i < num_cells ; ++i, ++cells ) |
| 176 | { |
| 177 | if (!cells->empty ()) // That's the number of models in the cell (it's maximum one, since we loaded only one model) |
| 178 | { |
| 179 | std::size_t num_entries = (*cells->begin ()).second.size(); // That's the number of entries in the current cell for the model we loaded |
| 180 | // Get the max number of entries |
| 181 | if ( num_entries > max_num_entries ) |
| 182 | max_num_entries = num_entries; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Now, that we have the max. number of entries, we can compute the |
| 187 | // right scale factor for the spheres |
| 188 | float s = (0.5f*spacing)/static_cast<float> (max_num_entries); |
| 189 | |
| 190 | std::cout << "s = " << s << ", max_num_entries = " << max_num_entries << std::endl; |
| 191 | |
| 192 | // Now, render a sphere with the right radius at the right place |
| 193 | cells = hash_table.getVoxels (); |
| 194 | for ( int i = 0; i < num_cells ; ++i, ++cells ) |
| 195 | { |
| 196 | // Does the cell have any entries? |
| 197 | if (!cells->empty ()) |
| 198 | { |
| 199 | hash_table.compute3dId (i, id3); |
| 200 | hash_table.computeVoxelCenter (id3, cell_center); |
| 201 | |
| 202 | // That's half of the cube's side length |
| 203 | half_side = s*static_cast<float> ((*cells->begin ()).second.size ()); |
| 204 | |
| 205 | // Adjust the bounds of the cube |
| 206 | b[0] = cell_center[0] - half_side; b[1] = cell_center[0] + half_side; |
| 207 | b[2] = cell_center[1] - half_side; b[3] = cell_center[1] + half_side; |
| 208 | b[4] = cell_center[2] - half_side; b[5] = cell_center[2] + half_side; |
| 209 | |
| 210 | // Set the id |
| 211 | sprintf (cube_id, "cube %i", i); |
| 212 | |
| 213 | // Add to the visualizer |
| 214 | vis.addCube (b[0], b[1], b[2], b[3], b[4], b[5], 1.0, 1.0, 0.0, cube_id); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | vis.addCoordinateSystem(1.5, "global"); |
| 219 | vis.resetCamera (); |
no test coverage detected