tags:

views:

21

answers:

1

I want a tool to remove duplicate nodes ("nodes" in the finite element sense, simply a point in space with certain coordinates). Basically, I want to be able to take a collection of nodes, and reduce it by eliminating extra nodes that are within a certain tolerance in distance of other nodes. I figure that an STL set of nodes sorted by coordinate will fit the bill nicely performance wise. My question is how to incorporate a tolerance that is settable at run time.

Consider the simple key comparison function for the 1D case (a single coordinate per node). I know my logic could be shortened; that isn't what my question is about.

struct NodeSorter_x{
    //Stores Node objects sorted by x coordinate within tolerance TOL
    bool operator()(const Node N1, const Node N2) const
    {
        //returns true if N1 < N2 and not within TOL distance
        return ( N1.x < N2.x) && !( fabs( N1.x - N2.x ) < TOL );
    }
};

And the set containing unique node objects (no duplicates)...

std::set <Node,NodeSorter_x> UniqueNodeSet;

So, I want to be able to set TOL used in the comparison at run time. How do I go about doing so?

A: 
struct NodeSorter_x{
    NodeSorter_x(double tol) : TOL(tol) {}
    bool operator()(const Node N1, const Node N2) const
    {
        //returns true if N1 < N2 and not within TOL distance
        return ( N1.x < N2.x) && !( fabs( N1.x - N2.x ) < TOL );
    }
};

std::set <Node,NodeSorter_x> UniqueNodeSet( NodeSorter_x(0.1) );
sbi
Ahh, constructor for the comparison object. Makes sense. I assume that there is a way to access this after creation of UniqueNodeSet to change the tolerance. Looking at stl documentation, it appears that it would be something like UniqueNodeSet.key_compare.setTolerance(val), assuming the proper memebers existed in NodeSorter_x.
Ross_Mc