Exemple #1
0
        public override void Interpolate(Point3d position, Voxel voxel)
        {
            voxel.Position.X = position.X;
            voxel.Position.Y = position.Y;
            voxel.Position.Z = position.Z;

            if (!XRange.Contains(position.X) || !YRange.Contains(position.Y) || !ZRange.Contains(position.Z))
            {
                voxel.Value = DefaultPhysicalValue;
            }
            else
            {
                try
                {
                    //float x0 = 0, x1 = 0, y0 = 0, y1 = 0, z0 = 0, z1 = 0;
                    //int ix0 = 0, ix1 = 0, iy0 = 0, iy1 = 0, iz0 = 0, iz1 = 0;

                    if (ConstantGridSpacing)
                    {
                        ix0 = (int)((position.X - XCoords[0]) / GridSpacing.X);
                        if (ix0 >= XCoords.Length - 1)
                        {
                            ix1 = ix0 = XCoords.Length - 1;
                        }
                        else
                        {
                            ix1 = ix0 + 1;
                        }
                        x0 = XCoords[ix0];
                        x1 = XCoords[ix1];

                        iy0 = (int)((position.Y - YCoords[0]) / GridSpacing.Y);
                        if (iy0 >= YCoords.Length - 1)
                        {
                            iy1 = iy0 = YCoords.Length - 1;
                        }
                        else
                        {
                            iy1 = iy0 + 1;
                        }

                        y0 = YCoords[iy0];
                        y1 = YCoords[iy1];
                        if (GridSpacing.Z != 0)
                        {
                            iz0 = (int)((position.Z - ZCoords[0]) / GridSpacing.Z);
                            iz1 = iz0 + 1;

                            if (iz0 >= ZCoords.Length - 1)
                            {
                                iz1 = iz0 = ZCoords.Length - 1;
                            }
                            else
                            {
                                iz1 = iz0 + 1;
                            }

                            z0 = ZCoords[iz0];
                            z1 = ZCoords[iz1];
                        }
                        else
                        {
                            iz0 = 0; iz1 = 0;
                            z0  = ZCoords[iz0];
                            z1  = ZCoords[iz1];
                        }
                    }
                    else
                    {
                        var xt = binarySearchForSurroundingCoords(position.X, XCoords);
                        x0  = (float)xt.Item1;
                        x1  = (float)xt.Item2;
                        ix0 = xt.Item3;
                        ix1 = xt.Item4;
                        var yt = binarySearchForSurroundingCoords(position.Y, YCoords);
                        y0  = (float)yt.Item1;
                        y1  = (float)yt.Item2;
                        iy0 = yt.Item3;
                        iy1 = yt.Item4;
                        var zt = binarySearchForSurroundingCoords(position.Z, ZCoords);
                        z0  = (float)zt.Item1;
                        z1  = (float)zt.Item2;
                        iz0 = zt.Item3;
                        iz1 = zt.Item4;
                    }

                    voxel.Value = Interpolation.TrilinearInterpolate(
                        (float)position.X, (float)position.Y, (float)position.Z,
                        x0, y0, z0,
                        x1, y1, z1,
                        Data[getIndex(ix0, iy0, iz0)],
                        Data[getIndex(ix1, iy0, iz0)],
                        Data[getIndex(ix0, iy0, iz1)],
                        Data[getIndex(ix1, iy0, iz1)],
                        Data[getIndex(ix0, iy1, iz0)],
                        Data[getIndex(ix1, iy1, iz0)],
                        Data[getIndex(ix0, iy1, iz1)],
                        Data[getIndex(ix1, iy1, iz1)]);
                }
#pragma warning disable CS0168 // The variable 'e' is declared but never used
                catch (Exception e)
#pragma warning restore CS0168 // The variable 'e' is declared but never used
                {
                    voxel.Value = DefaultPhysicalValue;
                }
            }
        }
 public bool ContainsPoint(double x, double y, double z)
 {
     return(XRange.Contains(x) && YRange.Contains(y) && ZRange.Contains(z));
 }
Exemple #3
0
        public override void Interpolate(Point3d position, Voxel voxel)
        {
            voxel.Position.X = position.X;
            voxel.Position.Y = position.Y;
            voxel.Position.Z = position.Z;

            if (!XRange.Contains(position.X) || !YRange.Contains(position.Y) || !ZRange.Contains(position.Z))
            {
                voxel.Value = 0;
            }
            else
            {
                float x0 = 0, x1 = 0, y0 = 0, y1 = 0, z0 = 0, z1 = 0;
                int   ix0 = 0, ix1 = 0, iy0 = 0, iy1 = 0, iz0 = 0, iz1 = 0;

                if (ConstantGridSpacing)
                {
                    ix0 = (int)((position.X - XCoords[0]) / GridSpacing.X);
                    ix1 = ix0 == XCoords.Length - 1 ? ix0 : ix0 + 1;
                    x0  = (float)XCoords[ix0];
                    x1  = (float)XCoords[ix1];
                    iy0 = (int)((position.Y - YCoords[0]) / GridSpacing.Y);
                    iy1 = iy0 == YCoords.Length - 1 ? iy0 : iy0 + 1;
                    y0  = (float)YCoords[iy0];
                    y1  = (float)YCoords[iy1];
                    if (GridSpacing.Z != 0)
                    {
                        iz0 = (int)((position.Z - ZCoords[0]) / GridSpacing.Z);
                        iz1 = iz0 == ZCoords.Length - 1 ? iz0 : iz0 + 1;
                        z0  = (float)ZCoords[iz0];
                        z1  = (float)ZCoords[iz1];
                    }
                    else
                    {
                        iz0 = 0; iz1 = 0;
                        z0  = (float)ZCoords[iz0];
                        z1  = (float)ZCoords[iz1];
                    }
                }
                else
                {
                    var xt = binarySearchForSurroundingCoords(position.X, XCoords);
                    x0  = (float)xt.Item1;
                    x1  = (float)xt.Item2;
                    ix0 = xt.Item3;
                    ix1 = xt.Item4;
                    var yt = binarySearchForSurroundingCoords(position.Y, YCoords);
                    y0  = (float)yt.Item1;
                    y1  = (float)yt.Item2;
                    iy0 = yt.Item3;
                    iy1 = yt.Item4;
                    var zt = binarySearchForSurroundingCoords(position.Z, ZCoords);
                    z0  = (float)zt.Item1;
                    z1  = (float)zt.Item2;
                    iz0 = zt.Item3;
                    iz1 = zt.Item4;
                }
                float xd;
                if (x1 == x0)
                {
                    xd = 0;
                }
                else
                {
                    xd = (float)(position.X - x0) / (x1 - x0);
                }
                double yd;
                if (y1 == y0)
                {
                    yd = 0;
                }
                else
                {
                    yd = (position.Y - y0) / (y1 - y0);
                }
                double zd;
                if (z1 == z0)
                {
                    zd = 0;
                }
                else
                {
                    zd = (position.Z - z0) / (z1 - z0);
                }
                float c00 = Data[ix0, iy0, iz0] * (1 - xd) + Data[ix1, iy0, iz0] * xd;
                float c01 = Data[ix0, iy0, iz1] * (1 - xd) + Data[ix1, iy0, iz1] * xd;
                float c10 = Data[ix0, iy1, iz0] * (1 - xd) + Data[ix1, iy1, iz0] * xd;
                float c11 = Data[ix0, iy1, iz1] * (1 - xd) + Data[ix1, iy1, iz1] * xd;
                float c0  = (float)(c00 * (1 - yd) + c10 * yd);
                float c1  = (float)(c01 * (1 - yd) + c11 * yd);
                float c   = (float)(c0 * (1 - zd) + c1 * zd);

                voxel.Value = c;
            }
        }