static internal IEnumerable <Autodesk.Revit.DB.Point> ToHost(this Rhino.Geometry.PointCloud pointCloud) { foreach (var p in pointCloud) { yield return(Autodesk.Revit.DB.Point.Create(ToHost(p.Location))); } }
public void Populate(List <Point3d> P) { Mesh_Vis = false; Section_Vis = false; PC = new PointCloud(P); this.Enabled = true; }
public override BoundingBox GetBoundingBox(Transform xform) { if (Value == null) { return(BoundingBox.Empty); } var pointCloud = new Rhino.Geometry.PointCloud(Value.ToPoint3dArray()); return(pointCloud.GetBoundingBox(xform)); }
// Pointcloud public Pointcloud PointcloudToSpeckle(RH.PointCloud pointcloud, string units = null) { var u = units ?? ModelUnits; var _pointcloud = new Pointcloud() { points = PointsToFlatArray(pointcloud.GetPoints().ToList()).ToList(), colors = pointcloud.GetColors().Select(o => o.ToArgb()).ToList(), bbox = BoxToSpeckle(new RH.Box(pointcloud.GetBoundingBox(true)), u), units = u }; return(_pointcloud); }
public RH.PointCloud PointcloudToNative(Pointcloud pointcloud) { var points = pointcloud.GetPoints().Select(o => PointToNative(o).Location).ToList(); var _pointcloud = new RH.PointCloud(points); if (pointcloud.colors.Count == points.Count) { for (int i = 0; i < points.Count; i++) { _pointcloud[i].Color = System.Drawing.Color.FromArgb(pointcloud.colors[i]); } } return(_pointcloud); }
/* * public static void ConvertToTree(GH_Structure<GH_Point> structure, ref DataTree<Point3d> tree) * { * for (int i = 0; i < structure.Paths.Count; i++) * { * var path = structure.Paths[i]; * for (int j = 0; j < structure[path].Count; j++) * { * tree.Add(structure[path][j].Value, path); * } * } * } */ public static List <double> DistNearPt(List <Point3d> pts) { var rtnList = new List <double>(); for (int i = 0; i < pts.Count; i++) { var others = new List <Point3d>(pts); others.RemoveAt(i); var pc = new Rhino.Geometry.PointCloud(others); var closestIdx = pc.ClosestPoint(pts[i]); rtnList.Add(pts[i].DistanceTo(others[closestIdx])); } return(rtnList); }
public override IGH_GeometricGoo Transform(Transform xform) { if (Value == null) { return(null); } var copy = Value.Duplicate(); var pointCloud = new Rhino.Geometry.PointCloud(copy.ToPoint3dArray()); pointCloud.Transform(xform); for (int i = 0; i < Value.Nodes.Count; i++) { copy.Nodes[i].X = pointCloud[i].Location.X; copy.Nodes[i].Y = pointCloud[i].Location.Y; copy.Nodes[i].Z = pointCloud[i].Location.Z; } return(new MolecularGoo(copy)); }
/// <summary> /// Constructs a new tree with an element for each pointcloud point. /// </summary> /// <param name="cloud">A pointcloud.</param> /// <returns>A new tree, or null on error.</returns> public static RTree CreatePointCloudTree(PointCloud cloud) { if (cloud == null) { throw new ArgumentNullException(nameof(cloud)); } IntPtr const_ptr_cloud = cloud.ConstPointer(); IntPtr ptr_rtree = UnsafeNativeMethods.ON_RTree_CreatePointCloudTree(const_ptr_cloud); if (IntPtr.Zero == ptr_rtree) { return(null); } RTree rc = new RTree(ptr_rtree); uint size = UnsafeNativeMethods.ON_RTree_SizeOf(ptr_rtree); rc.m_memory_pressure = size; GC.AddMemoryPressure(rc.m_memory_pressure); rc.m_count = cloud.Count; GC.KeepAlive(cloud); return(rc); }
public void Populate(List <List <Point3d> > P, List <List <double> > pressure) { Mesh_Vis = false; Section_Vis = false; if (pressure.Count > 0) { PC = new PointCloud(); for (int j = 0; j < P.Count; j++) { for (int i = 0; i < P[j].Count; i++) { PC.Add(P[j][i], P_Color(20 * System.Math.Log(pressure[j][i] / 2E-5)));//0.0000000004 } } } else { for (int j = 0; j < P.Count; j++) { PC = new PointCloud(P[j]); } } this.Enabled = true; }
public Rhino.Geometry.PointCloud DuplicatePointCloudGeometry() { Rhino.Geometry.PointCloud rc = DuplicateGeometry() as Rhino.Geometry.PointCloud; return(rc); }
public void Compute(int gridSize, int x_Ex, int y_Ex, int offsetValue, int offsetValue2, int reduceNum, int minRoomNum, Point3d center , ref List <Rhino.Geometry.Point3d> shapedGrid, ref PolylineCurve shapeCrv, ref Polyline offsetShapeCrv, ref Rectangle3d originalShape) { var grid = RhinoWrapper.MakeGrid(x_Ex, y_Ex, gridSize); var rectMain = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize); var rectMainCrv = rectMain.ToPolyline().ToPolylineCurve(); originalShape = rectMain; //減らす部分の四角形をつくるための元のcorner var corners = new Rhino.Geometry.Point3d[4]; for (int i = 0; i < 4; i++) { corners[i] = rectMain.Corner(i); } //引くための四角形を作る範囲 var rectSub = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize, offsetValue); var rectSub2 = RhinoWrapper.MakeRect(center, x_Ex, y_Ex, gridSize, offsetValue2); var populate = RhinoWrapper.RandomPt(rectSub, reduceNum); var randPts = populate.Where(pt => RhinoWrapper.IsInside(pt, rectSub2.ToPolyline()) == false).ToList(); //点が近いところにあるとオフセットがうまく機能しない。 for (int i = 0; i < randPts.Count; i++) { for (int j = 0; j < randPts.Count; j++) { if (i == j) { continue; } if (randPts[i].DistanceTo(randPts[j]) < gridSize * (minRoomNum + 1)) { randPts.RemoveAt(j); j--; } } } //Reduce Rectsを作ってる var reduceRects = new List <Rhino.Geometry.PolylineCurve>(); var planeXY = new Rhino.Geometry.Plane(Point3d.Origin, Vector3d.ZAxis); for (int i = 0; i < randPts.Count; i++) { var pc = new Rhino.Geometry.PointCloud(corners); int closestIdx = pc.ClosestPoint(randPts[i]); var reduceRect = new Rectangle3d(planeXY, randPts[i], corners[closestIdx]); var polyCrv = reduceRect.ToPolyline().ToPolylineCurve(); reduceRects.Add(polyCrv); } var shape = Curve.CreateBooleanDifference(rectMainCrv, reduceRects, 0.1); offsetShapeCrv = null; //正四角形でない形がでたとき if (shape.Length > 0) { shape[0].TryGetPolyline(out Polyline polyShape); //ref shapedGrid = grid.Where(pt => RhinoWrapper.IsInside(pt, polyShape)).ToList(); //ref shapeCrv = polyShape.ToPolylineCurve(); //ref var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis); shapeCrv.Offset(plane, (-gridSize * minRoomNum), 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out offsetShapeCrv); if (offsetShapeCrv == null) { offsetShapeCrv = new Rectangle3d(plane, 1, 1).ToPolyline(); } } else//正四角形が残ったとき。(ひくためのRectangleができない) { shapedGrid = grid.Where(pt => RhinoWrapper.IsInside(pt, rectMainCrv.ToPolyline())).ToList(); //ref shapeCrv = rectMainCrv.ToPolyline().ToPolylineCurve(); //ref var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis); shapeCrv.Offset(plane, (-gridSize * minRoomNum), 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out offsetShapeCrv); if (offsetShapeCrv == null) { offsetShapeCrv = new Rectangle3d(plane, 1, 1).ToPolyline(); } } }
public PointCloudPoints(PointCloud ptc) { m_ptc = ptc; }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex) { if (IntPtr.Zero == pGeometry) { return(null); } var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) { return(null); } GeometryBase rc = null; switch (type) { case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1 rc = new Curve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8 rc = new Point(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10 rc = new Surface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11 rc = new Brep(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20 { int faceindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (ptr_brep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Faces[faceindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21 { int edgeindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (ptr_brep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Edges[edgeindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32 rc = new Light(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35 { int loopindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (ptr_brep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Loops[loopindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36 { int trimindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (ptr_brep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Trims[trimindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38 rc = new Leader(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39 rc = new SubD(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40 rc = new LinearDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41 rc = new AngularDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42 rc = new RadialDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43 rc = new OrdinateDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44 rc = new Centermark(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45 rc = new TextEntity(pGeometry, parent); break; default: rc = new UnknownGeometry(pGeometry, parent, subobjectIndex); break; } return(rc); }
/// <summary> /// Adds particle points to this class for display based on the distance traveled from the source. /// </summary> /// <param name="Dist"></param> public void Populate(double Dist, bool Nearest_Neighbor) { Mesh_Vis = false; Section_Vis = false; PC = new PointCloud(); this.Enabled = false; double[] e = new double[PR.Length * PR[0].Count()]; Point3d[] pts = new Point3d[PR.Length * PR[0].Count()]; int[][] voxel = new int[e.Length][]; for (int s = 0; s < PR.Length; s++) { for (int q = 0; q < PR[s].Count(); q++) { double energy; Point3d N, PT; if (!PR[s].RayPt(q, Dist, 4, out energy, out N, out PT)) continue; Vector3d loc = PT - min; int x = (int)System.Math.Floor(loc.X / dx); int y = (int)System.Math.Floor(loc.Y / dy); int z = (int)System.Math.Floor(loc.Z / dz); int id = q + s * PR[s].Count(); ptgrid[x,y,z].Add(id); voxel[id] = new int[3] { x, y, z }; pts[id] = PT; e[id] = energy; } } //foreach(int[] i in voxel) //{ // if (i == null) // { // Rhino.RhinoApp.WriteLine("oops..."); // } //} System.Threading.Semaphore S = new System.Threading.Semaphore(1, 1); if (Nearest_Neighbor) { System.Threading.Tasks.Parallel.For(0, pts.Length, s => //for (int s = 0; s < pts.Length; s++) { if (voxel[s] != null) { double energy = e[s]; foreach (int[] sp in SearchPattern) { int x = voxel[s][0] + sp[0]; int y = voxel[s][1] + sp[1]; int z = voxel[s][2] + sp[2]; if (x < 0 || x > nx - 1 || y < 0 || y > ny - 1 || z < 0 || z > nz - 1) continue; foreach (int t in ptgrid[x, y, z]) { if (s == t) continue; Vector3d pt = pts[s] - pts[t]; double d2 = pt.X * pt.X + pt.Y * pt.Y + pt.Z * pt.Z; if (d2 < 1) { energy += e[t] * (1 - d2); } } } S.WaitOne(); PC.Add(pts[s], P_Color(Utilities.AcousticalMath.SPL_Intensity(energy))); S.Release(); } }); foreach (List<int> p in ptgrid) { p.Clear(); } } else { for (int s = 0; s < pts.Length; s++) { PC.Add(pts[s], P_Color(Utilities.AcousticalMath.SPL_Intensity(e[s]))); } } this.Enabled = true; }
internal PointCloudItem(PointCloud parent, int index) { m_parent = parent; m_index = index; }
/// <summary> /// Draw a coloured point cloud /// </summary> /// <param name="points"></param> /// <param name="colour"></param> /// <param name="size"></param> public void Draw(RC.PointCloud points, Color colour, double size) { Display.DrawPointCloud(points, (int)size, colour); }
void AddPointCloudPreviews(Rhino.Geometry.PointCloud previewCloud) { int verticesCount = previewCloud.Count; if (verticesCount > VertexThreshold) { primitives = new Primitive[(verticesCount / VertexThreshold) + ((verticesCount % VertexThreshold) > 0 ? 1 : 0)]; for (int c = 0; c < verticesCount / VertexThreshold; ++c) { var part = new Primitive.Part(c * VertexThreshold, (c + 1) * VertexThreshold); primitives[c] = new ObjectPrimitive(rhinoObject, previewCloud, part); } if ((verticesCount % VertexThreshold) > 0) { var part = new Primitive.Part((primitives.Length - 1) * VertexThreshold, verticesCount); primitives[primitives.Length - 1] = new ObjectPrimitive(rhinoObject, previewCloud, part); } } else { primitives = new Primitive[] { new ObjectPrimitive(rhinoObject, previewCloud) } }; } void AddMeshPreviews(Rhino.Geometry.Mesh previewMesh) { int verticesCount = previewMesh.Vertices.Count; if (verticesCount > VertexThreshold || previewMesh.Faces.Count > VertexThreshold) { // If it's insane big show as point clouds if (previewMesh.Faces.Count > (VertexThreshold - 1) * 16) { primitives = new Primitive[(verticesCount / VertexThreshold) + ((verticesCount % VertexThreshold) > 0 ? 1 : 0)]; for (int c = 0; c < verticesCount / VertexThreshold; ++c) { var part = new Primitive.Part(c * VertexThreshold, (c + 1) * VertexThreshold); primitives[c] = new ObjectPrimitive(rhinoObject, previewMesh, part); } if ((verticesCount % VertexThreshold) > 0) { var part = new Primitive.Part((primitives.Length - 1) * VertexThreshold, verticesCount); primitives[primitives.Length - 1] = new ObjectPrimitive(rhinoObject, previewMesh, part); } // Mesh.Reduce is slow in this case //previewMesh = previewMesh.DuplicateMesh(); //previewMesh.Reduce((BigMeshThreshold - 1) * 16, true, 5, true); } // Split the mesh into partitions else if (previewMesh.CreatePartitions(VertexThreshold, int.MaxValue)) { int partitionCount = previewMesh.PartitionCount; primitives = new Primitive[partitionCount]; for (int p = 0; p < partitionCount; ++p) { primitives[p] = new ObjectPrimitive(rhinoObject, previewMesh, previewMesh.GetPartition(p)); } } } else { primitives = new Primitive[] { new ObjectPrimitive(rhinoObject, previewMesh) } }; }
public ObjectPrimitive(Rhino.DocObjects.RhinoObject o, Rhino.Geometry.PointCloud pc, Part p) : base(pc, p) { rhinoObject = o; }
public void Populate(List<List<Point3d>> P, List<List<double>> pressure) { Mesh_Vis = false; Section_Vis = false; if (pressure.Count > 0) { PC = new PointCloud(); for (int j = 0; j < P.Count; j++) { for (int i = 0; i < P[j].Count; i++) { PC.Add(P[j][i], P_Color(20 * System.Math.Log(pressure[j][i] / 2E-5)));//0.0000000004 } } } else { for (int j = 0; j < P.Count; j++) { PC = new PointCloud(P[j]); } } this.Enabled = true; }
public void Populate(List<Point3d> P) { Mesh_Vis = false; Section_Vis = false; PC = new PointCloud(P); this.Enabled = true; }
private void RunThread(CancellationToken token) { Intel.RealSense.PointCloud pc = new Intel.RealSense.PointCloud(); DecimationFilter dec_filter = new DecimationFilter(); SpatialFilter spat_filter = new SpatialFilter(); TemporalFilter temp_filter = new TemporalFilter(); dec_filter.Options[Option.FilterMagnitude].Value = DecimationMagnitude; spat_filter.Options[Option.FilterMagnitude].Value = SpatialMagnitude; spat_filter.Options[Option.FilterSmoothAlpha].Value = Math.Min(1.0f, (float)SpatialSmoothAlpha); spat_filter.Options[Option.FilterSmoothDelta].Value = (float)SpatialSmoothDelta; temp_filter.Options[Option.FilterSmoothAlpha].Value = Math.Min(1.0f, (float)TemporalSmoothAlpha); temp_filter.Options[Option.FilterSmoothDelta].Value = (float)TemporalSmoothDelta; List <ProcessingBlock> filters = new List <ProcessingBlock> { dec_filter, spat_filter, temp_filter }; Align align_to_depth = new Align(Stream.Depth); var cfg = new Config(); cfg.EnableStream(Stream.Depth, 640, 480); cfg.EnableStream(Stream.Color, 1280, 720, Format.Rgb8); var pipeline = new Pipeline(); PipelineProfile pp = null; try { pp = pipeline.Start(cfg); } catch (Exception e) { RhinoApp.WriteLine("RsToolkit: " + e.Message); return; } while (!token.IsCancellationRequested) { try { using (var frames = pipeline.WaitForFrames()) { var aligned = align_to_depth.Process <FrameSet>(frames).DisposeWith(frames); var color = aligned.ColorFrame.DisposeWith(frames); pc.MapTexture(color); var filtered = aligned[Stream.Depth].DisposeWith(frames); foreach (var filter in filters) { filtered = filter.Process(filtered).DisposeWith(frames); } Points points = pc.Process <Points>(filtered); var vertices = new Point3f[points.Count]; var tex_coords = new Point2f[points.Count]; points.CopyVertices <Point3f>(vertices); points.CopyTextureCoords <Point2f>(tex_coords); Debug.Assert(vertices.Length == tex_coords.Length); // ======== CULL INVALID POINTS ======== if (true) { var flags = new bool[vertices.Length]; int new_size = 0; for (int i = 0; i < vertices.Length; ++i) { if (vertices[i].Z > 0.1) { flags[i] = true; new_size++; } } var new_vertices = new Point3f[new_size]; var new_tex_coords = new Point2f[new_size]; for (int i = 0, j = 0; i < vertices.Length; ++i) { if (flags[i]) { new_vertices[j] = vertices[i]; new_tex_coords[j] = tex_coords[i]; ++j; } } vertices = new_vertices; tex_coords = new_tex_coords; } // ======== TRANSFORM ======== if (m_xform.IsValid) { Parallel.For(0, vertices.Length - 1, (i) => { vertices[i].Transform(m_xform); }); } // ======== CLIP TO BOX ======== if (m_clipping_box.IsValid && m_clipping_box.X.Length > 0 && m_clipping_box.Y.Length > 0 && m_clipping_box.Z.Length > 0) { Point3d box_centre = m_clipping_box.Plane.Origin; double minx = m_clipping_box.X.Min + box_centre.X, maxx = m_clipping_box.X.Max + box_centre.X; double miny = m_clipping_box.Y.Min + box_centre.Y, maxy = m_clipping_box.Y.Max + box_centre.Y; double minz = m_clipping_box.Z.Min + box_centre.Z, maxz = m_clipping_box.Z.Max + box_centre.Z; var flags = new bool[vertices.Length]; int new_size = 0; for (int i = 0; i < vertices.Length; ++i) { if ( vertices[i].X <maxx && vertices[i].X> minx && vertices[i].Y <maxy && vertices[i].Y> miny && vertices[i].Z <maxz && vertices[i].Z> minz ) { flags[i] = true; new_size++; } } var new_vertices = new Point3f[new_size]; var new_tex_coords = new Point2f[new_size]; for (int i = 0, j = 0; i < vertices.Length; ++i) { if (flags[i]) { new_vertices[j] = vertices[i]; new_tex_coords[j] = tex_coords[i]; ++j; } } vertices = new_vertices; tex_coords = new_tex_coords; } Debug.Assert(vertices.Length == tex_coords.Length); var point_colors = GetPointColors(color, tex_coords); RPointCloud new_pointcloud = new RPointCloud(); new_pointcloud.AddRange(vertices.Select(x => new Point3d(x)), point_colors); lock (m_pointcloud) m_pointcloud = new_pointcloud; } } catch (Exception e) { RhinoApp.WriteLine("RsToolkit: " + e.Message); m_is_on = false; break; } } RhinoApp.WriteLine("RsToolkit: Task cancelled."); if (pipeline != null) { pipeline.Stop(); } }
/// <summary> /// Adds particle points to this class for display based on the distance traveled from the source. /// </summary> /// <param name="Dist"></param> public void Populate(double Dist, bool Nearest_Neighbor) { Mesh_Vis = false; Section_Vis = false; PC = new PointCloud(); this.Enabled = false; double[] e = new double[PR.Length * PR[0].Count()]; Point3d[] pts = new Point3d[PR.Length * PR[0].Count()]; int[][] voxel = new int[e.Length][]; double emin = System.Math.Pow(10, V_Bounds[0] / 10) * 1e-12; for (int s = 0; s < PR.Length; s++) { for (int q = 0; q < PR[s].Count(); q++) { double energy; Point3d N, PT; if (!PR[s].RayPt(q, Dist, 4, out energy, out N, out PT)) { continue; } Vector3d loc = PT - min; int x = (int)System.Math.Floor(loc.X / dx); int y = (int)System.Math.Floor(loc.Y / dy); int z = (int)System.Math.Floor(loc.Z / dz); int id = q + s * PR[s].Count(); ptgrid[x, y, z].Add(id); voxel[id] = new int[3] { x, y, z }; pts[id] = PT; e[id] = energy; } } //foreach(int[] i in voxel) //{ // if (i == null) // { // Rhino.RhinoApp.WriteLine("oops..."); // } //} System.Threading.Semaphore S = new System.Threading.Semaphore(1, 1); if (Nearest_Neighbor) { System.Threading.Tasks.Parallel.For(0, pts.Length, s => //for (int s = 0; s < pts.Length; s++) { if (e[s] > emin) { if (voxel[s] != null) { double energy = e[s]; foreach (int[] sp in SearchPattern) { int x = voxel[s][0] + sp[0]; int y = voxel[s][1] + sp[1]; int z = voxel[s][2] + sp[2]; if (x < 0 || x > nx - 1 || y < 0 || y > ny - 1 || z < 0 || z > nz - 1) { continue; } foreach (int t in ptgrid[x, y, z]) { if (s == t) { continue; } Vector3d pt = pts[s] - pts[t]; double d2 = pt.X * pt.X + pt.Y * pt.Y + pt.Z * pt.Z; if (d2 < 1) { energy += e[t] * (1 - d2); } } } S.WaitOne(); PC.Add(pts[s], P_Color(Utilities.AcousticalMath.SPL_Intensity(energy))); S.Release(); } } }); foreach (List <int> p in ptgrid) { p.Clear(); } } else { for (int s = 0; s < pts.Length; s++) { PC.Add(pts[s], P_Color(Utilities.AcousticalMath.SPL_Intensity(e[s]))); } } this.Enabled = true; }
public PointCloudItemEnumerator(PointCloud cloud_points) { m_owner = cloud_points; }
public BrepConverter(SurfaceConverter surfConv, CurveConverter curveConv, Point3dConverter ptConv) : base( (rb) => { List <pps.Surface> faces = new List <pps.Surface>(); List <List <int> > adjacency = new List <List <int> >(); for (int i = 0; i < rb.Faces.Count; i++) { var surf = (pps.NurbsSurface)surfConv.ToPipe <rh.Surface, pps.Surface>(rb.Faces[i].ToNurbsSurface()); surf.OuterTrims.Clear(); surf.OuterTrims.AddRange(rb.Faces[i].Loops.Where((l) => l.LoopType == rh.BrepLoopType.Outer).Select((l) => curveConv.ToPipe <rh.Curve, ppc.Curve>(l.To3dCurve()))); surf.InnerTrims.Clear(); surf.InnerTrims.AddRange(rb.Faces[i].Loops.Where((l) => l.LoopType == rh.BrepLoopType.Inner).Select((l) => curveConv.ToPipe <rh.Curve, ppc.Curve>(l.To3dCurve()))); faces.Add(surf); adjacency.Add(rb.Faces[i].AdjacentFaces().ToList()); } var polySurf = new pps.PolySurface(faces, adjacency); polySurf.IsSolid = rb.IsSolid; return(polySurf); }, (pb) => { if (pb.Surfaces.Count <= 0) { return(null); } rh.Brep brep = null; //trying to create a trimmed brep with built in methods if (Util.TryCreateBrepWithBuiltInMethods(pb, out brep, surfConv, curveConv)) { return(brep); } //attemping to build it from scratch - 15 attempts int attempts = 0; while (attempts < 15) { brep = new rh.Brep(); var ptCloud = new rh.PointCloud(pb.Vertices().Select((p) => ptConv.FromPipe <rh.Point3d, pp.Vec>(p))); var ptList = ptCloud.GetPoints().ToList(); ptList.ForEach((p) => brep.Vertices.Add(p, Rhino.RhinoMath.ZeroTolerance)); var ppEdges = pb.Edges(); foreach (var ppCur in ppEdges) { var rhCurve = curveConv.FromPipe <rh.Curve, ppc.Curve>(ppCur); int curveIndex = brep.Curves3D.Add(rhCurve); int startIndex = ptCloud.ClosestPoint(rhCurve.PointAtStart); int endIndex = ptCloud.ClosestPoint(rhCurve.PointAtEnd); var edge = brep.Edges.Add(startIndex, endIndex, curveIndex, Rhino.RhinoMath.ZeroTolerance); } foreach (var ppSurf in pb.Surfaces) { var rhSurf = surfConv.FromPipe <rh.Surface, pps.Surface>(ppSurf); var surfIndex = brep.AddSurface(rhSurf); var face = brep.Faces.Add(surfIndex); var loop = brep.Loops.Add(rh.BrepLoopType.Outer, face); var surfEdges = ppSurf.Edges(); int loopCount = 0; foreach (var ppLoop in surfEdges) { var rhCurve = curveConv.FromPipe <rh.Curve, ppc.Curve>(ppLoop); var curve2d = rhSurf.Pullback(rhCurve, Rhino.RhinoMath.ZeroTolerance); if (curve2d == null) { continue; } loopCount += 1; int c2i = brep.Curves2D.Add(curve2d); int c3i = ppEdges.IndexOf(ppLoop); if (c3i == -1) { c3i = brep.Curves3D.Add(rhCurve); } int startIndex = ptCloud.ClosestPoint(rhCurve.PointAtStart); int endIndex = ptCloud.ClosestPoint(rhCurve.PointAtEnd); var trim = brep.Trims.Add(brep.Edges[c3i], false, loop, c2i); trim.IsoStatus = rh.IsoStatus.None; trim.TrimType = rh.BrepTrimType.Boundary; trim.SetTolerances(0.0, 0.0); } if (loopCount == 0) { var curve2d = Util.Get2dEdgeLoop(rhSurf); int c2i = brep.Curves2D.Add(curve2d); var curve3d = rhSurf.Pushup(curve2d, Rhino.RhinoMath.ZeroTolerance); int c3i = brep.Curves3D.Add(curve3d); int startIndex = ptCloud.ClosestPoint(curve3d.PointAtStart); int endIndex = ptCloud.ClosestPoint(curve3d.PointAtEnd); var edge = brep.Edges.Add(startIndex, endIndex, c3i, Rhino.RhinoMath.ZeroTolerance); var trim = brep.Trims.Add(brep.Edges[c3i], false, loop, c2i); trim.IsoStatus = rh.IsoStatus.None; trim.TrimType = rh.BrepTrimType.Boundary; trim.SetTolerances(0.0, 0.0); } //var uSurfDom = rhSurf.Domain(0); //var vSurfDom = rhSurf.Domain(1); //var ufaceDom = face.Domain(0); //var vfaceDom = face.Domain(1); //var surfNorm = rhSurf.NormalAt(uSurfDom.Mid, vSurfDom.Mid); //var faceNorm = face.NormalAt(ufaceDom.Mid, vfaceDom.Mid); //face.OrientationIsReversed = rh.Vector3d.Multiply(surfNorm, faceNorm) < 0; face.OrientationIsReversed = false; } //updating attempts and breaking if succeeded attempts += 1; if (brep.IsValid) { break; } } string msg; if (!brep.IsValidWithLog(out msg)) { System.Diagnostics.Debug.WriteLine(msg); brep.Repair(Rhino.RhinoMath.ZeroTolerance); if (brep.IsValid) { return(brep); } //finally attemping to create an untrimmed brep int attempt = 0; while (!brep.IsValid && attempt < 15) { brep = rh.Brep.MergeBreps(pb.Surfaces.Select((s) => rh.Brep.CreateFromSurface(surfConv.FromPipe <rh.Surface, pps.Surface>(s))), Rhino.RhinoMath.ZeroTolerance); attempt += 1; } if (!brep.IsValid) { throw new InvalidOperationException("Failed to create a valid brep from " + "received data because: \n" + msg); } } return(brep); } ) { }