Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit 1213c4f

Browse files
author
Daniel
authored
Add files via upload
1 parent 69714ee commit 1213c4f

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

main.cpp

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
#include "src/dbScan.h"
55
#include "src/HTRBasicDataStructures.h"
66

7-
void calculateCentroid(vector<htr::Point3D>& points){
8-
pcl::PointXYZ centroid;
9-
for(htr::Point3D point:points){
10-
centroid.x += point.x;
11-
centroid.y += point.y;
12-
centroid.z += point.z;
13-
}
14-
centroid.x /= points.size();
15-
centroid.y /= points.size();
16-
centroid.z /= points.size();
17-
}
7+
8+
// Colors to display the generated clusters
9+
float colors[] = { 255,0,0,
10+
0,255,0,
11+
0,0,255,
12+
255,255,0,
13+
0,255,255,
14+
255,0,255,
15+
0,0,255,
16+
0,255,255,
17+
255,255,255
18+
};
1819

1920
void readCloudFromFile(int argc, char** argv, std::vector<htr::Point3D>& points,
2021
pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cloud){
@@ -329,42 +330,32 @@ void init(int argc, char** argv,bool show){
329330
std::random_device seeder;
330331
std::ranlux48 gen(seeder());
331332
std::uniform_int_distribution<int> uniform_0_255(0, 255);
333+
334+
int j = 0;
332335

333336
for(auto& cluster : dbscan.getClusters()){
334337

335338
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cluster_rgb (new pcl::PointCloud<pcl::PointXYZRGB>());
336-
//uint8_t r(255), g(15), b(15);
337-
uint8_t r = (uint8_t) uniform_0_255(gen);
338-
uint8_t g = (uint8_t) uniform_0_255(gen);
339-
uint8_t b = (uint8_t) uniform_0_255(gen);
340-
/*
341-
342-
// Colors to display the generated clusters
343-
float colors[] = { 1,0,0,
344-
0,1,0,
345-
0,0,1,
346-
0.5,0,0,
347-
0,0.5,0,
348-
0,0,0.5,
349-
1,1,0,
350-
0,1,1,
351-
1,0,1,
352-
0,0,1,
353-
0,1,1,
354-
1,1,1
355-
};
356-
357-
358-
int j = 0;
359-
for(dbScanSpace::cluster cluster:dbscan2.getClusters()){
360-
for(auto& point:cluster.clusterPoints){
361-
glColor3f(colors[j], colors[j+1], colors[j+2]);
362-
}
363-
364-
j+=3;
365-
if(j > 36) j = 0;
366-
}
367-
*/
339+
//uint8_t r(255), g(15), b(15);
340+
341+
uint8_t r;
342+
uint8_t g;
343+
uint8_t b;
344+
345+
if(j < 27){
346+
347+
r = (uint8_t) colors[j];
348+
g = (uint8_t) colors[j+1];
349+
b = (uint8_t) colors[j+2];
350+
351+
}else{
352+
353+
r = (uint8_t) uniform_0_255(gen);
354+
g = (uint8_t) uniform_0_255(gen);
355+
b = (uint8_t) uniform_0_255(gen);
356+
357+
}
358+
368359

369360
for(auto& pointCluster:cluster.clusterPoints){
370361

@@ -373,11 +364,20 @@ float colors[] = { 1,0,0,
373364
point.y = pointCluster.y;
374365
point.z = pointCluster.z;
375366

367+
//uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
368+
// static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
369+
//point.rgb = *reinterpret_cast<float*>(&rgb);
370+
376371
uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
377372
static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
378373
point.rgb = *reinterpret_cast<float*>(&rgb);
374+
//point.r = 255;
375+
//point.g = 255;
376+
//point.b = (uint8_t)colors[j+2];
379377
cluster_rgb->points.push_back(point);
380378
}
379+
380+
j+=3;
381381

382382
std::string nameId = "cluster_";
383383
nameId += std::to_string(numClust);
@@ -409,6 +409,11 @@ float colors[] = { 1,0,0,
409409

410410
viewer->initCameraParameters();
411411
viewer->resetCamera();
412+
413+
//std::cout << "\nGenerated: " << numClust << " clusters" << std::endl;
414+
pcl::console::print_info("\nGenerated: ");
415+
pcl::console::print_value ("%d", numClust);
416+
pcl::console::print_info (" clusters\n");
412417

413418
pcl::console::print_info ("\npress [q] to exit!\n");
414419

0 commit comments

Comments
 (0)