How to get the unique vertices for a shape


I want to get all unique vertices from a shape. For example, if we consider a box, it has 8 vertices. I want to get the 8 vertices values. I used the following codes. However, it returns 48 vertices (6 faces * 4 wires in each face * 2 vertices in each wire).

TopExp_Explorer ex;
Standard_Integer count=0;
for (ex.Init(topoDSShape, TopAbs_VERTEX); ex.More(); ex.Next()) 
	TopoDS_Vertex vertex = TopoDS::Vertex(ex.Current());
	gp_Pnt pt = BRep_Tool::Pnt(vertex);
	Standard_Real x= pt.X();
	Standard_Real y= pt.Y();
	Standard_Real z= pt.Z();
	TCollection_ExtendedString msg = "Vertex ";
	msg += ++count;
	msg += " is: X=";
	msg += x;
	msg += ", Y=";
	msg += y;
	msg += ", Z=";
	msg += z;, msg);

TCollection_ExtendedString msg = "Total Vertices are: ";
msg += count;, msg);


How can I get the unique 8 vertices for a box or unique vertices for any shape (cylinder, sphere ….)?

I am looking forward your help.

magesecond_148729's picture

1. create a function to compare 2 gp_pnt

2. create a List<gp_pnt> 

3. look if your new gp_pnt is already included in your list, if not add it

4. enjoy your unique vertices