I collect a series of curves (from clinical images, they are parallel in z direction) and want to loft them. However, because of the image processing, some curves are twisted according to a rotation point in x-y plan (fig1). Thus the lofted surface has the “gaps” (fig2). What I can do now is to manually twist the curves back to minimize the gaps by my eyes (fig3). It’s a time consuming work.
My question is, is it possible to realize the “twisting back” automatically? In my mind it is a quite difficult work, and any suggestion or idea are welcome and appreciated.
The rhino file including the curves and the rotation point is attached. rotate.3dm (297.3 KB)
How do you know how far to rotate each block of curves? Or is it just based on intuition? It does sound difficult, I would start by figuring out the longest diagonal of each slice curve and maybe align those.
Wow, it’s really you, David? I can’t believe my eyes! Thank you so much and I am so happy to have your help!
You are right I just rotate each block based on my intuition.
Your suggestion means I should get out longest diagonal of each slice (I would do it for neighboring slices at the “gap”), then align according to the angle?
Are you sure they are only rotated around that point in your file?
In that case, attached a possible direction to look in using galapagos to compare the overlap between two subsequent curve areas and minimize that. Then rotate the curve and the curves above it and replace the list items with the ones that have been rotated
Maybe @DavidRutten has an idea how to make this into a loop…
You should of course only rotate if the area difference is above a certain treshold… that you define rotate-curves-to-orient.gh (111.5 KB)
ok, because I wonder if there are any risks involved if the reconstruction is not 100% ok. And it isn’t, because although this script removes most of the rotation, there is no guarantee that the least overlap is the right solution. How many of these scans do you need to process?
Ok, yes in that case it’s going to be a tedious exercise!
I can probably make the script faster and more reliable. Right now the twist in the layers seemed to be always in the same direction is this right? Is this always the case?
Hi Gijs, it’s a good question and I never though of it.
Actually we just began our work, and until now we tried about 3-4 cases. For them twist is always in the same direction. But I can’t guarantee there is no “black swan” inside :). Anyway, let’s assume that they are in the same direction.
Thank you again for your kindness!
It’s been a week since your help and I am still struggling in the first step: every time I run your python code, it shows the error:
"Runtime error (NotImplementedException): The method or operation is not implemented.
line 231, in GetObject, “C:\Users\w.wu\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\selection.py”
line 19, in alignInput, “”
line 91, in script"
I tried to search online, and asked other guys in the forum, but no answers. Would you please have a check what the problem is? rotation.gh (5.7 KB)
seems to me like you are trying to put the non-gh version into grasshopper? The .py I posted should be run from the pythonscript editor.
line 19: rs.GetObjects is a method that asks you to select curves. In gh you don’t need this, since you wire things up. In that case rs.GetObjects isn’t needed, because you feed the script with curves right away