public static BoundingBox GetBB(CylGridData data)
        {
            try
            {
                double maxX = double.MinValue;
                double minX = double.MaxValue;
                double maxY = double.MinValue;
                double minY = double.MaxValue;
                double maxZ = double.MinValue;
                double minZ = double.MaxValue;
                foreach (var strip in data)
                {
                    foreach (var pt in strip)
                    {
                        double x = pt.R;
                        if (x > maxX)
                        {
                            maxX = x;
                        }
                        if (x < minX)
                        {
                            minX = x;
                        }
                        double y = pt.ThetaRad;
                        if (y > maxY)
                        {
                            maxY = y;
                        }
                        if (y < minY)
                        {
                            minY = y;
                        }
                        double z = pt.Z;
                        if (z > maxZ)
                        {
                            maxZ = z;
                        }
                        if (z < minZ)
                        {
                            minZ = z;
                        }
                    }
                }


                var bb = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
                return(bb);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public void BuildModel(ref Model3DGroup modelgroup, CylGridData spiralScan, double radialDirection, double nominalRadius, double maxToleranceValue, double scalingFactor, COLORCODE colorCode)
 {
     try
     {
         model_group        = modelgroup;
         _maxToleranceValue = maxToleranceValue;
         DefineLights();
         var values = BuildHeightArray(spiralScan, radialDirection, nominalRadius, scalingFactor);
         CreateAltitudeMap(values, maxToleranceValue * scalingFactor, colorCode);
         DefineModel(values);
     }
     catch (Exception)
     {
         throw;
     }
 }
 /// <summary>
 /// unroll cylinder into grid
 /// </summary>
 /// <param name="correctedRingList"></param>
 /// <param name="scaling"></param>
 /// <param name="unrollRadius"></param>
 /// <returns></returns>
 static public CartGridData UnrollCylinder(CylGridData correctedRingList, double scaling, double unrollRadius)
 {
     try
     {
         var stripList = new CartGridData();
         foreach (var cylstrip in correctedRingList)
         {
             stripList.Add(UnrollCylinderRing(cylstrip, scaling, unrollRadius));
         }
         return(stripList);
     }
     catch (Exception)
     {
         throw;
     }
 }
        private double[,] BuildHeightArray(CylGridData scan, double radialDirection, double nominalRadius, double scalingFactor)
        {
            try
            {
                int zCount = scan.Count;
                int xCount = scan[0].Count;
                //find smallest strip to dim array
                foreach (CylData strip in scan)
                {
                    if (strip.Count < xCount)
                    {
                        xCount = strip.Count;
                    }
                }
                double[,] inputValues = new double[xCount, zCount];
                int zi = 0;
                //move strip values into array of heights
                foreach (CylData strip in scan)
                {
                    for (int xi = 0; xi < xCount; xi++)
                    {
                        inputValues[xi, zi] = Math.Sign(radialDirection) * strip[xi].R;
                    }
                    zi++;
                }
                //calc x and z spacing
                dxInput  = Math.Abs(nominalRadius * (scan[0][0].ThetaRad - scan[0][1].ThetaRad));
                dzInput  = Math.Abs(scan[0][0].Z - scan[1][0].Z);
                dxTarget = .004;
                dzTarget = .004;
                int    xSpacing = 1;
                double xScaling = dxTarget / dxInput;
                if (xScaling > 1)
                {
                    xSpacing = (int)Math.Ceiling(xScaling);
                }
                else
                {
                    xSpacing = 1;
                }
                int zOutCount = (int)(zCount * dzInput / dzTarget);
                int xOutCount = xCount / xSpacing;

                double[,] valuesXAve = new double[xOutCount, zCount];

                double clippingValue = 20 * _maxToleranceValue;
                //average x values
                for (int zIndex = 0; zIndex < inputValues.GetUpperBound(1); zIndex++)
                {
                    int xi     = 0;
                    int xstart = 0;
                    while (xi < xOutCount)
                    {
                        int    xend = Math.Min(xstart + xSpacing, inputValues.GetUpperBound(0));
                        double sum  = 0;
                        for (int xsub = xstart; xsub < xend; xsub++)
                        {
                            sum += inputValues[xsub, zIndex];
                        }
                        int sumCount = xend - xstart;
                        sum /= sumCount;
                        valuesXAve[xi, zIndex] = sum * scalingFactor;
                        xi++;
                        xstart += xSpacing;
                    }
                }


                double[,] valuesOut = new double[xOutCount, zOutCount];


                //poly fit z values
                for (int xio = 0; xio < xOutCount; xio++)
                {
                    int zOutIndex = 0;
                    for (int zio = 0; zio < zCount - 2; zio++)
                    {
                        double y0 = valuesXAve[xio, zio];
                        double z0 = zio * dzInput;
                        double z1 = (zio + 1) * dzInput;

                        double   z = z0;
                        double[] x = new double[3];
                        double[] y = new double[3];
                        y[0] = valuesXAve[xio, zio];
                        y[1] = valuesXAve[xio, zio + 1];
                        y[2] = valuesXAve[xio, zio + 2];
                        x[0] = zio * dzInput;
                        x[1] = (zio + 1) * dzInput;
                        x[2] = (zio + 2) * dzInput;
                        var func = MathNet.Numerics.Fit.PolynomialFunc(x, y, 2);
                        while (z < z1 && zOutIndex < zOutCount)
                        {
                            valuesOut[xio, zOutIndex] = func(z);
                            z += dzTarget;
                            zOutIndex++;
                        }
                    }
                }
                xIndexMin = 0;
                xIndexMax = valuesOut.GetUpperBound(0);
                dxIndex   = 1;
                zIndexMin = 0;
                zIndexMax = valuesOut.GetUpperBound(1);
                dzIndex   = 1;

                texture_xscale = (xIndexMax - xIndexMin);
                texture_zscale = (zIndexMax - zIndexMin);

                return(valuesOut);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public CylGridDataEnumerator(CylGridData collection)
 {
     _collection = collection;
     curIndex    = -1;
     currentItem = default;
 }