Created
March 8, 2012 22:49
-
-
Save sbaer/2003958 to your computer and use it in GitHub Desktop.
CellulateGrid3D sample for Rajaa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool CellulateGrid3D(List<Rhino.Geometry.Point3d[]> points1, | |
List<Rhino.Geometry.Point3d[]> points2, | |
out Rhino.Geometry.Line[] wires, | |
out List<Rhino.Geometry.Point3d[]> cells, | |
out Rhino.Geometry.Brep[] boxes) | |
{ | |
bool rc = false; | |
if (points1.Count > 0 && points2.Count > 0) | |
{ | |
using (var divide_points1 = new ClassArrayPointArray(points1)) | |
using (var divide_points2 = new ClassArrayPointArray(points2)) | |
using (var lines = new SimpleArrayLine()) | |
using (var breps = new SimpleArrayGeometryPointer()) | |
using (var cell_points = new ClassArrayPointArray()) | |
{ | |
IntPtr ptPoints1 = divide_points1.NonConstPointer(); | |
IntPtr ptPoints2 = divide_points2.NonConstPointer(); | |
IntPtr ptWires = lines.NonConstPointer(); | |
IntPtr ptCells = cell_points.NonConstPointer(); | |
IntPtr ptBreps = breps.NonConstPointer(); | |
rc = UnsafeNativeMethods.PTC_Box3DPaneling(ptPoints1, ptPoints2, ptWires, ptCells, ptBreps); | |
if( rc ) | |
{ | |
wires = lines.ToArray(); | |
cells = cell_points.ToList(); | |
var geom_array = breps.ToNonConstArray(); | |
var brep_list = new List<Rhino.Geometry.Brep>(); | |
foreach (Rhino.Geometry.GeometryBase geom in geom_array) | |
{ | |
Rhino.Geometry.Brep brep = geom as Rhino.Geometry.Brep; | |
if( brep!=null ) | |
brep_list.Add(brep); | |
} | |
boxes = brep_list.ToArray(); | |
} | |
} | |
} | |
if( !rc ) | |
{ | |
// set the output items to empty lists and arrays since | |
// untrained devs won't pay attention to null | |
wires = new Rhino.Geometry.Line[0]; | |
cells = new List<Rhino.Geometry.Point3d[]>(); | |
boxes = new Rhino.Geometry.Brep[0]; | |
} | |
return rc; | |
} |
Yep, I was just typing this up off the top of my head. I updated the gist sample.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Steve,
Looks like because we have some out parameters, we need to write the function as in the following:
public static bool CellulateGrid3D(List<Rhino.Geometry.Point3d[]> points1,
List<Rhino.Geometry.Point3d[]> points2,
out Rhino.Geometry.Line[] wires,
out List<Rhino.Geometry.Point3d[]> cells,
out Rhino.Geometry.Brep[] boxes)
{
bool rc = false;
if (points1.Count > 0 && points2.Count > 0)
{
using (var divide_points1 = new ClassArrayPointArray(points1))
using (var divide_points2 = new ClassArrayPointArray(points2))
using (var lines = new SimpleArrayLine())
using (var breps = new SimpleArrayGeometryPointer())
using (var cell_points = new ClassArrayPointArray())
{
IntPtr ptPoints1 = divide_points1.NonConstPointer();
IntPtr ptPoints2 = divide_points2.NonConstPointer();
IntPtr ptWires = lines.NonConstPointer();
IntPtr ptCells = cell_points.NonConstPointer();
IntPtr ptBreps = breps.NonConstPointer();
rc = UnsafeNativeMethods.PTC_Box3DPaneling(ptPoints1, ptPoints2, ptWires, ptCells, ptBreps);
if( rc )
{
wires = lines.ToArray();
cells = cell_points.ToList();
var geom_array = breps.ToNonConstArray();
var brep_list = new List<Rhino.Geometry.Brep>();
foreach (Rhino.Geometry.GeometryBase geom in geom_array)
{
Rhino.Geometry.Brep brep = geom as Rhino.Geometry.Brep;
if( brep!=null )
brep_list.Add(brep);
}
boxes = brep_list.ToArray();
return rc;
}
}
}
// Failed
// set the output items to empty lists and arrays since
// untrained devs won't pay attention to null
wires = new Rhino.Geometry.Line[0];
cells = new List<Rhino.Geometry.Point3d[]>();
boxes = new Rhino.Geometry.Brep[0];
return rc;
}