Open gaoxipeng opened 1 week ago
Thanks. First I would like to correct the roof method. Please give me details on what is not working about it? Thanks
Sorry not next to the computer right now, my earlier attempt was probably because of the Polyskel.skeletonize(eb_polygonxy, ib_polygonsxy) two parameters
No rush. When you can please let me know where and how it fails so I can fix it. Thanks
Dear @wassimj , Here is the code that may cause the issue:
from topologicpy.Cell import Cell
from topologicpy.Topology import Topology
from topologicpy.Face import Face
from topologicpy.Shell import Shell
f1 = Face.Rectangle(width=100, length=100)
cell = Cell.ByThickenedFace(face=f1, thickness=100, bothSides=False)
f2 = Topology.Translate(f1, z=100)
roof = Cell.Roof(f2)
Topology.Show(roof, renderer='offline')
in Shell.Roof line 1370: origin = Topology.Centroid(face) normal = Face.Normal(face, mantissa=mantissa) flat_face = Topology.Flatten(face, origin=origin, direction=normal) but not UnFlatten,so use ‘faces = Topology.Faces(shell) + [face] cell = Cell.ByFaces(faces, tolerance=tolerance) ’in Cell.Roof in line 1850 cannot creat a cell.
Still the above test code, if run multiple times, in Shell.py line 1524: br = wire. BoundingRectangle(roof) #This works even if it is a Cluster not a Wire in Wire.py in line 207:w = Wire.ByVertices(vList) f = Face.ByWire(w, tolerance=tolerance), It is still possible to select three collinear vertices and create a Wire that cannot create a face. Also, I've been confused about why in Wire.py line227 use factor = (round(((11-optimize)/30 + 0.57), 2),What was the reason for choosing these values. In my process, I usually only work on horizontal 2D planes, so I use the following approach:
def BoundingRectangle(topology):
z = Topology.Vertices(topology)[0].Z()
def br(topology):
vertices = []
_ = topology.Vertices(None, vertices)
x = []
y = []
for aVertex in vertices:
x.append(aVertex.X())
y.append(aVertex.Y())
minX = min(x)
minY = min(y)
maxX = max(x)
maxY = max(y)
return [minX, minY, maxX, maxY]
boundingRectangle = br(topology)
minX = boundingRectangle[0]
minY = boundingRectangle[1]
maxX = boundingRectangle[2]
maxY = boundingRectangle[3]
w = abs(maxX - minX)
l = abs(maxY - minY)
orig_area = l * w
origin = Topology.Centroid(topology)
min_area = orig_area
best_angle = 0
# Rotate from 0 to 90 degrees
for angle in range(0, 91, 1):
t = Topology.Rotate(topology, origin=origin, angle=angle)
minX, minY, maxX, maxY = br(t)
w = abs(maxX - minX)
l = abs(maxY - minY)
area = l * w
# Update the minimum area and best angle
if area < min_area:
min_area = area
best_angle = angle
# Now, best_angle is the rotation angle that gives the minimum area
best_br = br(Topology.Rotate(topology, origin=origin, angle=best_angle))
minX, minY, maxX, maxY = best_br
vb1 = Vertex.ByCoordinates(minX, minY, z)
vb2 = Vertex.ByCoordinates(maxX, minY, z)
vb3 = Vertex.ByCoordinates(maxX, maxY, z)
vb4 = Vertex.ByCoordinates(minX, maxY, z)
boundingRectangle = Wire.ByVertices([vb1, vb2, vb3, vb4], close=True)
boundingRectangle = Topology.Rotate(boundingRectangle, origin=origin, angle=-best_angle)
return boundingRectangle
First things first. Shell.Roof was not Unflattening the resulting shell. This has been corrected and now Cell.Roof works correctly. This will be included in the next release.
Second: You wrote:
Still the above test code, if run multiple times, in Shell.py line 1524: br = wire. BoundingRectangle(roof) #This works even if it is a Cluster not a Wire
in Wire.py in line 207:w = Wire.ByVertices(vList)
f = Face.ByWire(w, tolerance=tolerance), It is still possible to select three collinear vertices and create a Wire that cannot create a face.
Not sure I understand fully. Do you mean that I should first check if the vertices are collinear and thus I should reject that and return None because no bounding rectangle can be created from collinear vertices? If so, I have implemented that and it will be part of the next release. If you meant something else, please explain further. Thank you!
Yes, there's a chance that three collinear vertices could be randomly selected to form a wire, but they cannot further form a face.
Third: You wrote:
Also, I've been confused about why in Wire.py line227 use factor = (round(((11-optimize)/30 + 0.57), 2),What was the reason for choosing these values.
That is truly the weirdest line of code in my software. I cannot tell why I wrote it that way! I must've had a reason, but now I cannot read it back. I will take a look at your code and see if I can use it instead.
Yes, there's a chance that three collinear vertices could be randomly selected to form a wire, but they cannot further form a face.
In the latest version, I believe I keep selecting vertices until I find three that are not collinear.
Please test v0.7.21 to see if the issues with skeleton and roof are corrected. I will then start on OBJ import/export with colour. Thanks!
The current version of the roof is correct, thank you for the repair🫡
Dear @gaoxipeng , Topologicpy version 0.7.22 now supports color and opacity export and import. Please test and let me know if you find any bugs. The API for these methods has changed so please consult documentation for the correct input parameters and expected output. Thanks!
Dear @wassimj , Thanks for your modification, it is working normally, You may need to modify the comment section at the beginning of the code.
Dear @gaoxipeng, Thanks for spotting the wrong comments. I have updated them and issued a new version (0.7.23)
Dear @wassimj , Hello, The current ExportToOBJ only supports exporting geometric data without colors. I attempted to modify the existing function to accept multiple topology elements, colors, and transparency. Possibly due to changes in the base functions, the current version of the Roof function is incorrect. Therefore, I am using version 0.6.0 of topologicpy with a test roof function. This method can produce an OBJ file with colors, but it does not support the current ByOBJFile function. I am unsure if this method is worth further discussion. I look forward to your testing and reply.