<p>Take a random vertex on your loop, shoot a ray trough all the other loops. For loops you crossed a odd number of times your inside for loops you crossed a even number of times your outside.</p>

<p>The loops that are outside of all others is in the root of your tree. Then find loops that are inside that, but not inside some other. Then find next level and next level and so on. </p>

<p><a href="https://i.sstatic.net/eY5kH.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eY5kH.gif" alt="enter image description here"></a></p>

<p><strong>Image 1</strong>: Animation of arranging in tree by shooting rays</p>

<p>You can optimize this by using bounding boxes/ bsp trees for the test areas. But for a small number of areas that might be overkill. just sorting them left to right top to bottom should suffice. You can use the same algorithms as your scan line operators.</p>

<p><a href="https://i.sstatic.net/FGFVR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FGFVR.png" alt="offset"></a></p>

<p><strong>Image 2</strong>: And now you can offset the shape. But you need to recheck that there is no intersection left after this.</p>

<p>Now the topology is somewhat stable across levels of slices so you can use that to your benefit. Just follow the 3D surface.</p>

<p>Or you could do the offset in 3D on the polygons so you do not need this info. Also if you just need the winding for knowing which way to offset rule you can derive it from the 3d model itself, each vertex has a normal so project the normal for one triangle in each loop with your slicing algorithm per loop. That then gives you the direction of loops outside which is inside for nearly free. You wouldn't get the tree but then again you might not need it.</p>

CC BY-SA 3.0
2016-05-13T11:57:41.403Z
2016-05-13T12:11:09.990Z
2016-05-13T12:11:09.990Z
joojaa
<p>The slicing algorithm is done on the STL model and it is ensured that the result is a series of simple polygons that do not intersect each other. In other words all of those polygons generate closed loops. I need to identify which of those loops are outer and inner loops. There have been some references suggesting tree depth can be used to identify external and internal loops, without any outline of the algorithm. </p>

<p>It would be great if anyone can point to more detailed references where the tree depth can be utilized to filter out inner and outer contour lines.</p>

<p>The following images will provide more information:</p>

<p><a href="https://i.sstatic.net/qOCYz.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qOCYz.jpg" alt="Partition areas"></a>
<a href="https://i.sstatic.net/QTbP4.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QTbP4.jpg" alt="Depth Tree Structure"></a></p>

<p>According to the article that I am following - a, b, e, f, and j are outer loops, while the rest are inner loops. </p>

<p>In the current situation, I am identifying the inner and outer loops while doing the scanline over each layer after the slicing operation. But I want to identify the inner and outer loops ahead of the scanline operation, so that I can create inner/outer offset for the identified loops and then run the scanline to generate the fill pattern.</p>

<p>The article that I am following is titled - "Equidistant path generation for improving scanning efficiency in layered manufacturing". I googled up and I am afraid that it is not public. I downloaded the article through the university database.</p>

CC BY-SA 3.0
2016-05-11T16:43:11.213Z
Hi @sajis997, it's hard to understand what you're talking about from words alone. Could you add a screenshot or diagram to show what you mean by inner and outer loops and tree depth?
Nathan Reed
CC BY-SA 3.0
2016-05-11T19:24:10.857Z
Hi @NathanReed, The initial question is edited with some image snapshot. I hope it wil be clear now.
sajis997
CC BY-SA 3.0
2016-05-13T01:01:46.353Z
Do you have access to the tree shown in the image? If so my answer would be "the outer loops are at even depths, the inner loops are at odd depths". Is your requirement to produce this tree, or to interpret its results?
trichoplax is on Codidact now
CC BY-SA 3.0
2016-05-13T07:38:12.677Z
After the slicing operation, I have closed loops . I want separate into separate layer parts when each layer part contain an outer loop, one/several loops and infill pattern. I want to use Tree data structure for this purpose as mentioned in the paper.
sajis997
<computational-geometry>
Identify different contour cycle after model slicing
sajis997
# Identify different contour cycle after model slicing

(Asked by: username_0 on 2016-05-11)

The slicing algorithm is done on the STL model and it is ensured that the result is a series of simple polygons that do not intersect each other. In other words all of those polygons generate closed loops. I need to identify which of those loops are outer and inner loops. There have been some references suggesting tree depth can be used to identify external and internal loops, without any outline of the algorithm.

It would be great if anyone can point to more detailed references where the tree depth can be utilized to filter out inner and outer contour lines.

The following images will provide more information:

[![Partition areas](https://i.sstatic.net/qOCYz.jpg)](https://i.sstatic.net/qOCYz.jpg)
[![Depth Tree Structure](https://i.sstatic.net/QTbP4.jpg)](https://i.sstatic.net/QTbP4.jpg)

According to the article that I am following - a, b, e, f, and j are outer loops, while the rest are inner loops.

In the current situation, I am identifying the inner and outer loops while doing the scanline over each layer after the slicing operation. But I want to identify the inner and outer loops ahead of the scanline operation, so that I can create inner/outer offset for the identified loops and then run the scanline to generate the fill pattern.

The article that I am following is titled - "Equidistant path generation for improving scanning efficiency in layered manufacturing". I googled up and I am afraid that it is not public. I downloaded the article through the university database.

**Tags:** computational-geometry

> **Comments:**
> **username_1**: Hi @username_0, it's hard to understand what you're talking about from words alone. Could you add a screenshot or diagram to show what you mean by inner and outer loops and tree depth?  
> **username_0**: Hi @username_1, The initial question is edited with some image snapshot. I hope it wil be clear now.  
> **username_2**: Do you have access to the tree shown in the image? If so my answer would be "the outer loops are at even depths, the inner loops are at odd depths". Is your requirement to produce this tree, or to interpret its results?  
> **username_0**: After the slicing operation, I have closed loops . I want separate into separate layer parts when each layer part contain an outer loop, one/several loops and infill pattern. I want to use Tree data structure for this purpose as mentioned in the paper.  

---

## 1 answers

### Answer by username_3 on 2016-05-13. Score: 2 | Accepted answer

Take a random vertex on your loop, shoot a ray trough all the other loops. For loops you crossed a odd number of times your inside for loops you crossed a even number of times your outside.

The loops that are outside of all others is in the root of your tree. Then find loops that are inside that, but not inside some other. Then find next level and next level and so on.

[![enter image description here](https://i.sstatic.net/eY5kH.gif)](https://i.sstatic.net/eY5kH.gif)

**Image 1**: Animation of arranging in tree by shooting rays

You can optimize this by using bounding boxes/ bsp trees for the test areas. But for a small number of areas that might be overkill. just sorting them left to right top to bottom should suffice. You can use the same algorithms as your scan line operators.

[![offset](https://i.sstatic.net/FGFVR.png)](https://i.sstatic.net/FGFVR.png)

**Image 2**: And now you can offset the shape. But you need to recheck that there is no intersection left after this.

Now the topology is somewhat stable across levels of slices so you can use that to your benefit. Just follow the 3D surface.

Or you could do the offset in 3D on the polygons so you do not need this info. Also if you just need the winding for knowing which way to offset rule you can derive it from the 3d model itself, each vertex has a normal so project the normal for one triangle in each loop with your slicing algorithm per loop. That then gives you the direction of loops outside which is inside for nearly free. You wouldn't get the tree but then again you might not need it.


---

