Remove duplicated vertices in the input array of points
| 756 | |
| 757 | // Remove duplicated vertices in the input array of points |
| 758 | void QuickHull::removeDuplicatedVertices(Array<Vector3>& points, MemoryAllocator& allocator) { |
| 759 | |
| 760 | const decimal distanceEpsilon = 0.00001f; |
| 761 | Array<Vector3> pointsToKeep(allocator, points.size()); |
| 762 | |
| 763 | // Compute the points cloud center |
| 764 | Vector3 center(0, 0, 0); |
| 765 | for (uint32 i=0; i < points.size(); i++) { |
| 766 | center += points[i]; |
| 767 | } |
| 768 | center /= points.size(); |
| 769 | |
| 770 | // For each input point |
| 771 | for (uint32 i=0; i < points.size(); i++) { |
| 772 | |
| 773 | // For each point to keep |
| 774 | uint32 j; |
| 775 | for (j=0; j < pointsToKeep.size(); j++) { |
| 776 | |
| 777 | decimal dx = std::abs(pointsToKeep[j].x - points[i].x); |
| 778 | decimal dy = std::abs(pointsToKeep[j].y - points[i].y); |
| 779 | decimal dz = std::abs(pointsToKeep[j].z - points[i].z); |
| 780 | |
| 781 | // If the points are nearly the same |
| 782 | if (dx < distanceEpsilon && dy < distanceEpsilon && dz < distanceEpsilon) { |
| 783 | |
| 784 | // Between the two points, we keep the one that is the furthest away from the cloud points center |
| 785 | if ((points[i] - center).lengthSquare() > (pointsToKeep[j] - center).lengthSquare()) { |
| 786 | |
| 787 | pointsToKeep[j] = points[i]; |
| 788 | } |
| 789 | |
| 790 | break; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | // If the point is not already in the array of points to keep |
| 795 | if (j == pointsToKeep.size()) { |
| 796 | |
| 797 | // We add it |
| 798 | pointsToKeep.add(points[i]); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | points.clear(); |
| 803 | points.addRange(pointsToKeep); |
| 804 | } |
| 805 | |
| 806 | // Return the index of the next vertex candidate to be added to the hull |
| 807 | // This method returns INVALID_VERTEX_INDEX if there is no more vertex candidate |
nothing calls this directly
no test coverage detected