Weird product of RhinoBrepSplit function in C++

Hi All,
I am developing a plugin where I use the function RhinoBrepSplit, the version that takes
const ON_SimpleArray<const ON_Curve*> as splitter curves.

The sample code that uses this function is below. It asks user for two breps, one as splitter and the second as object to be splitted. Then intersection curves are created, which in later stage are used as splitter curves to split the splitted brep. I know that in this particular case it is better to just split one brep by another, but the point in my plug-in is to use curves as splitters.

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
	CRhinoGetObject go;
	context.m_doc.UnselectAll();
	go.SetCommandPrompt(L"choose splitter brep");
	go.SetGeometryFilter(ON::brep_object);
	CRhinoGet::result res = go.GetObjects(1, 1);
	if (res != CRhinoGet::object)  return CRhinoCommand::cancel;
	const ON_Brep* splitter = go.Object(0).Brep();
	context.m_doc.UnselectAll();

	go.SetCommandPrompt(L"choose brep to be splitted");
	res = go.GetObjects(1, 1);
	if (res != CRhinoGet::object)  return CRhinoCommand::cancel;
	const ON_Brep* brep = go.Object(0).Brep();
	if (!splitter || !brep)return CRhinoCommand::failure;

	ON_SimpleArray<ON_Curve*> curves;
	if (!RhinoIntersectBreps(*splitter, *brep, context.m_doc.AbsoluteTolerance(), curves)) return CRhinoCommand::failure;

	ON_SimpleArray<const ON_Curve*> constcurves;
	constcurves.Append(curves.Count(), curves.Array());
	ON_SimpleArray<ON_Brep*> pieces;
	RhinoBrepSplit(*brep, constcurves, context.m_doc.AbsoluteTolerance(), pieces);

	if (pieces.Count() > 0)context.m_doc.DeleteObject(go.Object(0)); //original brep is deleted here
	for (int i = 0; i < pieces.Count(); ++i)
	{
		context.m_doc.AddBrepObject(*pieces[i]);
		delete pieces[i];
	}
	for (int i = 0; i < curves.Count(); ++i)
	{
		delete curves[i];
	}
	return CRhinoCommand::success;
}

here:
surfaces2.3dm (361.8 KB)
you can find the model where by splitting the red surface by the grey one, you get the following result:


I mean result of the splitting are three surfaces instead of two.

When I modified the code above, to use RhinoBrepSplit that takes const ON_Brep& as splitter, the result was OK.
From the other side, when I do everything that the above code does, but with Rhino built-in functions (I mean first intersect two surfaces and then split the red one by the result curve), results are also OK.

I just have an impression that there is something wrong with the RhinoBrepSplit taking splitter curves, it is important for me to use just this version in my plug-in.

Dale, maybe you have got some idea?

Regards,
Andrzej

Hi @and.888.r,

Have you tried using this override?

https://developer.rhino3d.com/api/cpp/group___rhino.html#gacef769fe4b6ae20c453da9a5780041ba

– Dale

I will try it, thanks Dale.

Andrzej

Hi again,
I tried to use this override, but it is still a puzzle for me. I wanted that it works like in the description below it (in your link) as follows:

ON_3dVector extrudedir = RhinoApp().ActiveView()->ActiveViewport().ConstructionPlane().m_plane.Normal();

bool ifplanview = RhinoApp().ActiveView()->ActiveViewport().VP().IsParallelProjection();

RhinoBrepSplit(brep, geomarray, extrudedir, ifplanview, context.m_doc.AbsoluteTolerance(),pieces);

but it doesn’t work like it should, probably I use the variables extrudedir and ifplanview in the wrong way?

Regards,
Andrzej

Does anybody know how to use this function?

Hi @and.888.r,

Something is awry here. I’ve logged this so we can have a better look.

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

– Dale

@and.888.r you are using this function correctly. It should have worked. It is a bug in V6 and has been fixed in V7 WIP. Please let me know if you try this case with V7 and let me know how it goes.

Hi Greg,
V7 WIP crashes when I try the code above, with the model above. I have sent a crash report after that.

Edit: As I see the V7 crashes every time when I try the above code, even in very simple trim cases.

Regards,
Andrzej

@GregArden - can you have a look at this?

The array of ON_Brep pointers filled in by RhinoBrepSplit(…) can return nullptr values.
So you need to check before calling AddBrepObject( ).

Yeah, that was the reason. When I added a code that is filtering out the null pointers before AddBrepObject( ), the whole command works well in V7.
Thank you Greg! :smile: