From b5db0dbda261915c2105364e18c2c9eda34e1fbd Mon Sep 17 00:00:00 2001
From: andreucm <andreu@beta-robots.com>
Date: Thu, 10 Mar 2016 19:18:28 +0100
Subject: [PATCH] GridCluster class added but not yet tested

---
 src/grid_cluster.cpp | 37 +++++++++++++++++++++++++++++++++++++
 src/grid_cluster.h   | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 src/grid_cluster.cpp
 create mode 100644 src/grid_cluster.h

diff --git a/src/grid_cluster.cpp b/src/grid_cluster.cpp
new file mode 100644
index 0000000..6b6336b
--- /dev/null
+++ b/src/grid_cluster.cpp
@@ -0,0 +1,37 @@
+#include "grid_cluster.h"
+
+namespace laserscanutils
+{
+
+//init static cluster counter
+unsigned int GridCluster::cluster_id_count_ = 0;
+
+GridCluster::GridCluster() : PointSet()
+{
+    //
+}
+
+GridCluster::~GridCluster()
+{
+    //
+}
+
+void GridCluster::print() const
+{
+    //print cluster params
+    std::cout 
+            << "\tcluster_id_: " << cluster_id_ << std::endl 
+            << "\tcentroid_x_: " << centroid_(0) << std::endl 
+            << "\tcentroid_y_: " << centroid_(1)<< std::endl;
+
+    //print cluster cell index pairs
+    std::cout << "\tcells_: ";
+    for (unsigned int jj = 0; jj < cells_.size(); jj++)
+    {
+        std::cout << cells_.at(jj).first << "," << cells_.at(jj).second << " - "; 
+    }
+    std::cout << std::endl; 
+}
+
+}//close namespace
+
diff --git a/src/grid_cluster.h b/src/grid_cluster.h
new file mode 100644
index 0000000..2f6eac4
--- /dev/null
+++ b/src/grid_cluster.h
@@ -0,0 +1,39 @@
+#ifndef GRID_CLUSTER_H_
+#define GRID_CLUSTER_H_
+
+//laserscanutils
+#include "laser_scan_utils.h"
+#include "point_set.h"
+
+//std
+#include <iostream>
+
+//open namespace
+namespace laserscanutils
+{
+/** \brief Cluster class
+ * 
+ * Cluster of connected occupied cells in a grid
+ * 
+ **/
+class GridCluster : public PointSet
+{
+    protected:
+        unsigned int cluster_id_; //Cluster id. 
+        static unsigned int cluster_id_count_; //cluster counter (acts as simple ID factory)
+        
+    public:
+        std::vector<std::pair<unsigned int, unsigned int> > cells_; //i,j index of the grid cells of this cluster
+    
+    public:
+        //constructor
+        GridCluster();
+        
+        //Destructor
+        ~GridCluster();
+                           
+        //print
+        virtual void print() const;    
+};
+}//namespace
+#endif
-- 
GitLab