Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <training.h>
00009 #include <sac_3dof.h>
00010 #include <pcl17/io/io.h>
00011 #include <gtest/gtest.h>
00012
00013
00014
00015 TEST(ClusteringTest, SameNumberOfPointsAndClusters)
00016 {
00017
00018 std::vector<featureType> features;
00019 std::vector<featureType> cluster_centers;
00020 std::vector<int> cluster_labels;
00021 int num_clusters = 10;
00022
00023 for (int i = 0; i < num_clusters; i++)
00024 {
00025 featureType feature;
00026
00027 for (int j = 0; j < featureLength; j++)
00028 {
00029 feature.histogram[j] = (float)rand() / (float)RAND_MAX;
00030 }
00031 features.push_back(feature);
00032 }
00033
00034 cluster_features(features, num_clusters, cluster_centers, cluster_labels);
00035
00036 for (int i = 0; i < num_clusters; i++)
00037 {
00038 featureType feature = features[i];
00039 featureType cluster_center = cluster_centers[cluster_labels[i]];
00040 for (int j = 0; j < featureLength; j++)
00041 {
00042 EXPECT_FLOAT_EQ(feature.histogram[j], cluster_center.histogram[j])
00043 << "Feature and Cluster Center differ at index " << j;
00044 }
00045 }
00046 }
00047
00048
00049
00050 TEST(ClusteringTest, SymetricDelta)
00051 {
00052
00053 std::vector<featureType> features;
00054 std::vector<featureType> cluster_centers;
00055 std::vector<int> cluster_labels;
00056 int num_clusters = 2;
00057 float delta = 0.01;
00058
00059 featureType feature;
00060
00061 for (int j = 0; j < featureLength; j++)
00062 {
00063 feature.histogram[j] = 0;
00064 }
00065 features.push_back(feature);
00066
00067 for (int j = 0; j < featureLength; j++)
00068 {
00069 feature.histogram[j] = 0 - delta;
00070 }
00071 features.push_back(feature);
00072
00073 for (int j = 0; j < featureLength; j++)
00074 {
00075 feature.histogram[j] = 0 + delta;
00076 }
00077 features.push_back(feature);
00078
00079 for (int j = 0; j < featureLength; j++)
00080 {
00081 feature.histogram[j] = 1;
00082 }
00083 features.push_back(feature);
00084
00085 for (int j = 0; j < featureLength; j++)
00086 {
00087 feature.histogram[j] = 1 - delta;
00088 }
00089 features.push_back(feature);
00090
00091 for (int j = 0; j < featureLength; j++)
00092 {
00093 feature.histogram[j] = 1 + delta;
00094 }
00095 features.push_back(feature);
00096
00097 cluster_features(features, num_clusters, cluster_centers, cluster_labels);
00098
00099 for (int i = 0; i < 3; i++)
00100 {
00101 featureType cluster_center = cluster_centers[cluster_labels[i]];
00102 for (int j = 0; j < featureLength; j++)
00103 {
00104 EXPECT_FLOAT_EQ(0.0f, cluster_center.histogram[j])
00105 << "Cluster Center is not equal to 0 at index " << j;
00106 }
00107 }
00108
00109 for (int i = 3; i < 6; i++)
00110 {
00111 featureType cluster_center = cluster_centers[cluster_labels[i]];
00112 for (int j = 0; j < featureLength; j++)
00113 {
00114 EXPECT_FLOAT_EQ(1.0f, cluster_center.histogram[j])
00115 << "Cluster Center is not equal to 1 at index " << j;
00116 }
00117 }
00118 }
00119
00120
00121
00122 int main(int argc, char **argv)
00123 {
00124 testing::InitGoogleTest(&argc, argv);
00125 return RUN_ALL_TESTS();
00126 }