Vasundhara-root / sensorFusion

0 stars 0 forks source link

cluster.cpp missing euclidean function #1

Open FrancoisMasson1990 opened 4 years ago

FrancoisMasson1990 commented 4 years ago

Your kdtree.h seems correct but you are missing to complete the euclideanCluster function and the clusterHelper

std::vector<std::vector<int>> euclideanCluster(const std::vector<std::vector<float>>& points, KdTree* tree, float distanceTol) {

    std::vector<std::vector<int>> clusters;

    std::vector<bool> processed(points.size(), false);

    int i = 0;
    while (i < points.size()) {
        if (processed[i]) {
            i++;
            continue;
        }

        std::vector<int> cluster;
        clusterHelper(i, points, cluster, processed, tree, distanceTol);
        clusters.push_back(cluster);
        i++;
    }

    // Return list of indices for each cluster
    return clusters;

}

and

void clusterHelper(int index, const std::vector<std::vector<float>> points, std::vector<int>& cluster, std::vector<bool>& processed, KdTree* tree, float distanceTol) {
    processed[index] = true;
    cluster.push_back(index);

    std::vector<int> nearest = tree->search(points[index], distanceTol);

    for (int id : nearest) {
        if (!processed[id]) {
            clusterHelper(id, points, cluster, processed, tree, distanceTol);
        }
    }
}
Vasundhara-root commented 4 years ago

Euclidean clustering is in the next part of the tutorial but also checked by adding the above code, still facing the same error.

FrancoisMasson1990 commented 4 years ago

Can you print out the error ?

Vasundhara-root commented 4 years ago

There is no error as such yet because it is not going inside the main logic of the searchHealper function as the tree that is calling it is having Node as null. Can you check if the root is being passed properly to the function? Error: If condition check for empty tree is True (Line no. 58 in kdtree.h ) and hence it is printing out the "Empty Tree" which I have added as a debug code.

Vasundhara-root commented 4 years ago

@FrancoisMasson1990 Can you please have a look again?

FrancoisMasson1990 commented 4 years ago

I thought I answered it in Udacity Knowledge. Basically you have to change to two lines in your code

line30 in kdtree.h

if(node == NULL) replace by if (nullptr == node) and

line58 in kdtree.h

if(node!= NULL) replace by if (nullptr != node)