For all issues regarding the Forums use, please, refer to the Forum Rules.

### Our Solutions

Need professional assistance?
Consider our:

Need to speed up your development?
Have a look at our:

Need some functionality extending standard OCCT capabilities?
Check out our:

# Change color of edge, get all edges of a vertex

Forums:

Hello,

i've two questions. I've searched the forum and the samples, but couldn't find a clear answer:

1) Is there a way to change the color of an edge? I have a TopoDS_Shape and i know that i can access
individual faces, edges, vertices, etc. by using the TopExp_Explorer. But is there a way to change the color
of individual edges, e.g. of all sharp edges? I'm working on some algorithms and to validate if they're working
correctly i want to change the color of certain edges.

2) How can i get all edges that belong to a vertex? Of course i can search every edge of a shape and check
if it belongs to a certain vertex, but this is very time consuming. So is there a better way?

Thanks a lot

Hello
2. You can see to
TopExp::MapShapesAndAncestors()

and pay attention to the Roman Lygin blog
http://opencascade.blogspot.ru/2009/03/topology-and-geometry-in-open-cascade.html

Good Luck

Thank you very much Alexey, but i'm not sure if i'm getting the right results.
I have the following code:

TopTools_IndexedDataMapOfShapeListOfShape anEFsMap;
TopExp::MapShapesAndAncestors (object, TopAbs_VERTEX, TopAbs_EDGE, anEFsMap);

for (int i = 1; i {

cout

}

For i (= the amount of edges that belong to a vertex) i always get the value 2. But this
is wrong, because i don't have a single vertex in my model that is just connected to two
edges.

Is my code wrong or is the error somewhere else?

I am not clearly understand your situation.

for (int i = 1; i

anEFsMap.FindFromIndex(i).Extent() - count of parent edges

One moment, I think you should iterate with for (int i = 1; i

You're right, But this is not the problem.

Am I right that "TopExp::MapShapesAndAncestors (object, TopAbs_VERTEX, TopAbs_EDGE, anEFsMap);"
maps every egde that belongs to a certain vertex to that vertex?

anEFsMap.FindFromIndex(i) returns a list of TopoDS_Shapes, so anEFsMap.FindFromIndex(i).Extent() should deliver the amount of edges to the vertex i.

But in the above code "anEFsMap.FindFromIndex(i).Extent()" delivers for every vertex 2.
And this result is clearly wrong, because i don't have a single vertex in my model that
belongs to just two edges.

Edit:
I think i know the reason for my problem.
My object is stored in a Stl file, so after importing it i convert it to a TopoDS_Shape
by using this code: http://www.opencascade.org/org/forum/thread_3145/?forum=3

But this code makes from every triangle of the mesh its own face, with one wire
and three edges each. So obviously each vertex belongs to two edges and each edge to one
face. So The OCCT-Algortihms of "TopExp::MapShapesAndAncestors" don't find the correct solution.

Now i don't know how to solve this problem. I need to get every edge that belongs to a
vertex and every triangle that belongs to an edge from my stl mesh. OCCT doesn't seem to
provide a solution for that...
Maybe i have to find a more suitable library

I think OCC should solve your problem. Can you attach sample geometry file and write results you want to achieve?

Thank you very much for still helping me.

I hope there is a solution, if not i have to search a new library.
Yeah, i can open the samples that there provided with open cascade and i'm getting
correct results. Also with TopoDS_Shapes i've created in the code.

The results are just wrong if i convert an object from a stl file to a TopoDS_Shape.
Open Cascade doesn't provide solutions for a mesh from a stl file (as far as i have seen)
to get all triangles of a edge or to get all edges of a vertex.
So i have to convert the stl mesh to a TopoDS_Shape first.
And this shows wrong results (see link and explanation above). The input has to be a 3D mesh.

Maybe a different convertig algorithm could help, but this is not a trivial task and
i'm not sure if there is a solution for different objects.

Are you want to process stl mesh (triangulated geometry)?
In this case we can tell about working with mesh. and you can try VTK lib or SMDS lib (part of salome project, has good API for work with unstructured meshes).

Overall i want to detect sharp edges and cylindrical holes in a mesh. One way to do this is
by computing the angle between the two triangles/polygons that belong to a common edge.
If the angle is bigger than a certain specified value, the edge is a sharp edge.
For this i need methods like getting the triangles that belong to an edge or all the edges
that belong to a vertex.

Can Salome respectively VTK lib, SMDS lib do that?
Currentyl i see no way to do that in Open Cascade when the conversion of a stl mesh to
TopoDS_Shape doesn't work.

Thanks a lot for your help!

Salome (SMESH module) has rich functions for work with meshes - you can load stl file, than get all elements and iterate. You can look for salome mesh module help page, especially on python API.

Hi Sven,

how about using OpenMesh (http://www.openmesh.org)?

What makes your life easier is a kind of "HalfEdge"-Structure...

Greets,

Patrik

Thanks a lot, OpenMesh and SALOME both look promising. I'm going to try them out tomorrow.
Or i'm going to implement a halfedge data structure for Open Cascade. Thanks.

Hi Sven,

if youu know STL structure you could also try to build a list of unique vertices and unique edges to build your faces.. Perhaps this is enough for your needs.

Greeta,

Patrik

This is what i've done now. It seems to work, but it needs some further testing.

I have another problem with displaying an object. When i open a simple cube from a stl file,
with DRAW (meshfromstl), DRAW doesn't display the object fully (see attached file).
The object is alright, when i rotate it, the edges fade in and out fluently.
It looks like the edges and vertices are only displayed until a certain disance to the camera.
"fit all" doesn't help.

Not a huge problem, but a bit annoying.

Attachments:

Edit:

Ok i know the reason/solution for the above problem. If a model/mesh is to big (a couple of meters) Cascade blends the edges and vertices smoothly in and out, depending on the view distance.
Is the model smaller, the entire model is displayed and every edge and vertex is displayed.

### FOLLOW OPEN CASCADE

Youtube

A Capgemini Group Company