Closed polysurface?

1CLOSED.3dm (348.6 KB)

I have an imported Brep that is clearly 2 parts, but it showing as a valid closed polysurface.

How can I detect these types of Breps?

Thanks,

Dan

Hi @lignindes,

Where or what did you import the file from?

It is possible to create disjoint Breps programmatically. I can’t think of a good way to detect this, off the top of my head.

– Dale

@dale

Revit, of course! The place where geometry goes to die.

Darn, this type of problem is something I’m coming up against regularly. Can I detect using a Python script and RhinoCommon? Is there an .IsDisjoint() method anywhere?

Dan

Hi @lignindes,

I’ll see what I can come up with.

– Dale

@dale

This is exciting!

Dan

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def count_regions(brep_id):
	brep_obj = sc.doc.Objects.Find(brep_id)
	brep_geo = brep_obj.Geometry
	regions = 0
	to_check = [True for i in range(brep_geo.Vertices.Count)]
	def are_adjacent(v1, v2):
		for edge in brep_geo.Edges:
			if all([v in (edge.StartVertex.VertexIndex, edge.EndVertex.VertexIndex) for v in (v1, v2)]): return True
		return False
	while True:
		if sum(to_check) == 0:
			break
		regions += 1
		next_vertex = to_check.index(True)
		to_check[next_vertex] = False
		boundary = [next_vertex]
		while True:
			expand = [v for v in (v.VertexIndex for v in brep_geo.Vertices) if to_check[v] and any([are_adjacent(v, bv) for bv in boundary])]
			if len(expand) == 0:
				break
			else:
				for v in expand: to_check[v] = False
				boundary = expand
	return regions

def is_disjoint(brep_id):
	return count_regions(brep_id) > 1

def check_disjoint():
	brep = rs.GetObject("select brep", filter=8+16, preselect=True)
	if not brep:
		print("Cancel")
		return
	region_count = count_regions(brep)
	if region_count > 1:
		print("Brep is disjoint with {} regions.".format(region_count))
	else:
		print("Brep is contiguous.")

if __name__ == "__main__":
	check_disjoint()

Hi @lignindes,

https://mcneel.myjetbrains.com/youtrack/issue/RH-85074

I’ve added some “stuff” that should make this easier. It will appear in the first Rhino 5 SR15 release candidate.

– Dlae

Can’t you use this?

Yep, that works - thanks for reminding me.

The new stuff I added is a little fancier, as it returns an index map identifying what faces went into making the pieces. If you don’t care about that, use what you’ve mentioned.

– Dale

1 Like

Thanks @Measure !

1 Like

RH-85074 is fixed in Rhino 8 Service Release 15