Grasshopper

algorithmic modeling for Rhino

Hi to all,

I doing a C# component to trim automatically pipes that self-intersect. I want to trim pipes like this:

I use for this Brep.Trim Method (Brep, Double). On developer.rhino3d.com is explained that "If the Cutter is closed, then a connected component of the Brep that does not intersect the cutter is kept if and only if it is contained in the inside of cutter.", so I obtain as a result of the trimming only the inner part of the pipe (yellow one in the above image).  Instead I want the outer part (the black arrow).

How can I obtain only the outer part? Can you give some tips, some ideas?

Thanks

here my simple test code:

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBrepParameter("Brep", "Brep", "Brep to trim", GH_ParamAccess.item);
pManager.AddBrepParameter("Cutter", "Cutter", "Brep Cutter", GH_ParamAccess.item);
//AddIntegerParameter
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddSurfaceParameter("Cut Surface", "CS", "Cut Brep", GH_ParamAccess.list);
pManager.AddBrepParameter("Cut Brep", "CB", "Cut Brep", GH_ParamAccess.list);
}

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
Brep myBrep = new Brep();
Brep myCutter = new Brep();
DA.GetData(0, ref myBrep);
DA.GetData(1, ref myCutter);

Brep[] brepArray = myBrep.Trim(myCutter, 0.1);

List<Surface> surfList = new List<Surface>();
List<Brep> brepList = new List<Brep>();

for (int i = 0; i < brepArray.Length; i++)
{
brepList.Add(brepArray[i]);
int num = brepArray[i].Surfaces.Count;
if (brepArray[i].Surfaces.Count > 0)
{
for (int r = 0; r < brepArray[i].Surfaces.Count; r++)
{
surfList.Add(brepArray[i].Surfaces[r]);
}
}
}

DA.SetDataList(0, surfList);
DA.SetDataList(1, brepList);
}

Views: 2011

Replies to This Discussion

1. Don't do this: 

Brep myBrep = new Brep();
Brep myCutter = new Brep();

There's no point making a new Brep if you're about to overwrite it. Just say Brep myBrep = null;

You're going to have to use Split() instead of Trim(), and then figure out which of the remaining pieces is unwanted.

Hi David, thank for answering.
You're right about instantiate a new brep, thanks.
Ok for use split, I tried it, but the problem is that I don't know how to find automatically (without searching it manually in a list) the part inside the pipe to delete (I only need the outer part)! Any suggestions?
Thanks

Hi Robert,

well you cannot find it "automatically" since the index of the newly generated trimmed surfaced depends on many factors.

I usually a check that has to do with are or inclusion within the bounding box of the second pipe.

the latter works better but your bounding box needs to be aligned to the main axis of the pipe.

Hope this makes sense.

Ta,

M

Hi Mario's,
Thank you for answering. I think is a good idea, I will try it.
I will let you know.
Bye.
Robert

no problem,

Btw, what I wanted to type above was area and not "are".

The inclusion should work fine, but might not be bulletproof depending on the size of your pipes.

Best,

M

You can also use the BoundingBox of each split segment, find the centre and test that for inclusion inside the splitter pipe object.

Hi David, this is also a very good idea. Later I will try both and I will give feedback. Thank you all.
Bye

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service