Issue
I'm displaying a geometry using simple lines in a 3D WPF library. An example of it could be seen in the next picture:
In it you can see a set of triangles and quads. The way I'm plotting this is that I provide a List<Point3D>
in which I place pairs of points representing each segment.
The problem is that there are a lot of duplicate edges and I would like to avoid this as this type of representation seems to be very resource demanding.
The points list is generated iterating over each Element
that contains N vertices. It is not aware of if a particular edge is shared or not.
<p0, p1, p1, p2, p2, p333, p333, p89, p89, p2, p2, p1 ...>
The idea would be to remove the repeated pairs (note that the order could be not the same). In the example above the removed pair should be the last one (p2, p1), as it represents the same edge as the second pair of points (p1, p2). There could be one, two, or more duplicate pairs of points.
I need to do this operation as fast as possible, performance is top prio here.
Ideas
While adding points in the list I could store temporarily two of them and check if the list already contains them, but this implies looking into a list each time I add a point and doesn't seems a good idea to me (the list will contain several thousand of points 5000-50000).
The elements of which I generate the points list have several nodes with an unique ID so I think it could be used somehow by creating a Dictionary
of ordered Tuple<Point3D, Point3D>
and then removing the duplicate items.
I haven't tried the last idea as I'm not sure how to implement it yet, and I would like to hear if there is some other thing that can be done.