예제 #1
0
        public bool PickFrustumTest(Rhino.Geometry.PointCloud cloud, out int pointIndex, out double depth, out double distance)
        {
            pointIndex = -1;
            depth      = -1;
            distance   = -1;
            IntPtr pConstThis  = ConstPointer();
            IntPtr pConstCloud = cloud.ConstPointer();

            return(UnsafeNativeMethods.CRhinoPickContext_PickPointCloud2(pConstThis, pConstCloud, ref pointIndex, ref depth, ref distance));
        }
예제 #2
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            List <GH_hill> listHill = new List <GH_hill>();
            int            uMax = 0, vMax = 0;
            double         size = 0.0;

            if (!DA.GetDataList(0, listHill))
            {
                return;
            }
            if (!DA.GetData(1, ref size))
            {
                return;
            }
            if (!DA.GetData(2, ref uMax))
            {
                return;
            }
            if (!DA.GetData(3, ref vMax))
            {
                return;
            }
            double ContourInterval = 0.01 * listHill[0].Value.h;
            double seaLevel        = 30.0 * ContourInterval;

            double c      = size / uMax;
            double otherc = size / vMax;

            if (c > otherc)
            {
                c = otherc;
            }
            double maxX = c * uMax / 2d;
            double maxY = c * vMax / 2d;

            GH_function newFunction = new GH_function();

            newFunction.Value      = new function();
            newFunction.Value.Func = new _function((xValue, yValue) => {
                res f          = new res();
                double z       = -seaLevel;
                double zDiff_X = 0;
                double zDiff_Y = 0;
                double dx      = 0;
                double dy      = 0;
                for (int hill = 0; hill < listHill.Count; hill++)
                {
                    dx = xValue - listHill[hill].Value.x;
                    dy = yValue - listHill[hill].Value.y;
                    double expThingy = listHill[hill].Value.h * Math.Exp(-(dx * dx + dy * dy) / (listHill[hill].Value.size * listHill[hill].Value.size));
                    z       += expThingy;
                    zDiff_X -= dx * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                    zDiff_Y -= dy * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                }
                f.z      = z;
                f.zDiffX = zDiff_X;
                f.zDiffY = zDiff_Y;

                return(f);
            });
            Rhino.Geometry.PointCloud pc = new Rhino.Geometry.PointCloud();

            for (int i = 0; i <= uMax * 4; i++)
            {
                for (int j = 0; j <= vMax * 4; j++)
                {
                    double x = -maxX + (c / 4d) * i;
                    double y = -maxY + (c / 4d) * j;
                    pc.Add(new Rhino.Geometry.Point3d(x, y, newFunction.Value.Func(x, y).z));
                }
            }
            Rhino.Geometry.Plane        plane     = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Vector3d(1.0, 0, 0), new Rhino.Geometry.Vector3d(0.0, 1.0, 0));
            Rhino.Geometry.PlaneSurface planeSurf = new Rhino.Geometry.PlaneSurface(plane, new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d), new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d));
            DA.SetDataList(0, pc.GetPoints().ToList());
            DA.SetData(1, planeSurf);
            newFunction.size            = size;
            newFunction.uMax            = uMax;
            newFunction.vMax            = vMax;
            newFunction.maxX            = maxX;
            newFunction.maxY            = maxY;
            newFunction.c               = c;
            newFunction.seaLevel        = seaLevel;
            newFunction.ContourInterval = ContourInterval;
            newFunction.a               = c * (Math.Sqrt(7.0) - 1.0) / 6.0;
            newFunction.bsin            = c / 4.0;
            newFunction.bcos            = c * (4.0 - Math.Sqrt(7.0)) / 12.0;
            DA.SetData(2, newFunction);
        }
 public Primitive(Rhino.Geometry.PointCloud pc, Part p)
 {
     geometry = pc; ClippingBox = geometry.GetBoundingBox(false); part = p;
 }
        protected static int ToPointsBuffer
        (
            Rhino.Geometry.PointCloud pointCloud,
            Primitive.Part part,
            out VertexFormatBits vertexFormatBits,
            out VertexBuffer vb, out int vertexCount,
            out IndexBuffer ib
        )
        {
            int pointsCount = part.VertexCount;
            int normalCount = pointCloud.ContainsNormals ? pointsCount : 0;
            int colorsCount = pointCloud.ContainsColors  ? pointsCount : 0;

            bool hasPoints  = pointsCount > 0;
            bool hasNormals = normalCount == pointsCount;
            bool hasColors  = colorsCount == pointsCount;

            if (hasPoints)
            {
                if (hasNormals)
                {
                    if (hasColors)
                    {
                        vertexFormatBits = VertexFormatBits.PositionNormalColored;
                        vb = new VertexBuffer(pointsCount * VertexPositionNormalColored.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPositionNormalColored.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionNormalColored())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                var c     = new ColorWithTransparency(point.Color.R, point.Color.G, point.Color.B, 255u - point.Color.A);
                                vstream.AddVertex(new VertexPositionNormalColored(RawEncoder.ToHost(point.Location), RawEncoder.ToHost(point.Normal), c));
                            }
                        }

                        vb.Unmap();
                    }
                    else
                    {
                        vertexFormatBits = VertexFormatBits.PositionNormal;
                        vb = new VertexBuffer(pointsCount * VertexPositionNormal.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPositionNormal.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionNormal())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                vstream.AddVertex(new VertexPositionNormal(RawEncoder.ToHost(point.Location), RawEncoder.ToHost(point.Normal)));
                            }
                        }

                        vb.Unmap();
                    }
                }
                else
                {
                    if (hasColors)
                    {
                        vertexFormatBits = VertexFormatBits.PositionColored;
                        vb = new VertexBuffer(pointsCount * VertexPositionColored.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPositionColored.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionColored())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                var c     = new ColorWithTransparency(point.Color.R, point.Color.G, point.Color.B, 255u - point.Color.A);
                                vstream.AddVertex(new VertexPositionColored(RawEncoder.ToHost(point.Location), c));
                            }
                        }

                        vb.Unmap();
                    }
                    else
                    {
                        vertexFormatBits = VertexFormatBits.Position;
                        vb = new VertexBuffer(pointsCount * VertexPosition.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPosition.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPosition())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                vstream.AddVertex(new VertexPosition(RawEncoder.ToHost(point.Location)));
                            }
                        }

                        vb.Unmap();
                    }
                }

                ib = IndexPointsBuffer(pointsCount);
            }
            else
            {
                vertexFormatBits = 0;
                vb = null;
                ib = null;
            }

            vertexCount = pointsCount;
            return(pointsCount);
        }
예제 #5
0
 public Primitive(Rhino.Geometry.PointCloud pc, Part p)
 {
     geometry = pc; part = p;
 }
 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;
 }
            /// <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;
            }