Closed petrasvestartas closed 3 years ago
I have trouble seeing the semantic of you loop, but you could do something like this:
std::vector<int> result;
auto callback = [&result](int foundValue) -> bool {
for (int id : result) {
if (id < foundValue) { // check the logic here, I do not know what you want to do!
result.push_back(foundValue);
return true;
}
}
};
int nhits = tree.Search(min, max, callback);
Please do not use issues to ask questions that are not issues for the project. Issues are there to track errors or missing features in projects.
How can I ask question not related to bugs? Thank you for the answer I am trying to understand it.
why do you have this loop inside lamda?
for (int id : result) {
}
To reiterate I just want to collect indices that are higher than the current id
if (id < foundValue)
If I would write this, id would be undefined, I wonder why:
std::vector<int> result;
auto callback = [&result](int foundValue) -> bool {
//for (int id : result) {
if (foundValue>id) { // check the logic here, I do not know what you want to do!
result.push_back(foundValue);
return true;
}
//}
};
The loop in the lambda is there to check before inserting something in the result list. This removes the loop afterwards, like you mentioned in your first message here.
id
is not defined because you commented the definition of it. The for-loop is a for-each loop.
What is "the current id"? Do I get this correct?
int currentId = 42; // this would be set by your outer loop or something else
std::vector<int> result;
auto callback = [&result, currentId](int foundValue) -> bool {
if (currentId < foundValue) {
result.push_back(foundValue);
}
return true;
};
int nhits = tree.Search(min, max, callback);
Thank you this works perfectly.
The currentID is an integer of every book I loop after inserting. 1) I insert all boxes 2) I loop through all the inserted boxes and gather the neighbours
for (int i = 0; i < AABB.size(); i++) {
double min[3] = { AABB[i].xmin(), AABB[i].ymin(), AABB[i].zmin() };
double max[3] = { AABB[i].xmax(), AABB[i].ymax(), AABB[i].zmax() };
tree.Insert(min, max, i);
}
//////////////////////////////////////////////////////////////////////////////
// Search Closest Boxes | Skip duplicates pairs | Perform callback with OBB
//////////////////////////////////////////////////////////////////////////////
std::vector<int> pairs; //x.key, y.key,
for (int i = 0; i < 1; i++) {
double min[3] = { AABB[i].xmin(), AABB[i].ymin(), AABB[i].zmin() };
double max[3] = { AABB[i].xmax(), AABB[i].ymax(), AABB[i].zmax() };
//Perform search you just wrote
}
Dear @AlexVonB
Thank you for a previous help. I have one more question.
How can I modify existing code or include into lambda, the check that the id of a box is bigger than searched one? I want to avoid the second loop below when I collect resultWanted.