Example #1
0
        public void L8_FromScaledVector4()
        {
            // Arrange
            L8         gray     = default;
            const byte expected = 128;
            Vector4    scaled   = new L8(expected).ToScaledVector4();

            // Act
            gray.FromScaledVector4(scaled);
            byte actual = gray.PackedValue;

            // Assert
            Assert.Equal(expected, actual);
        }
Example #2
0
            public void L8_FromRgba32_IsInverseOf_ToRgba32(byte luminance)
            {
                var original = new L8(luminance);

                Rgba32 rgba = default;

                original.ToRgba32(ref rgba);

                L8 mirror = default;

                mirror.FromRgba32(rgba);

                Assert.Equal(original, mirror);
            }
Example #3
0
        public void L8_ToScaledVector4(byte input)
        {
            // Arrange
            var gray = new L8(input);

            // Act
            Vector4 actual = gray.ToScaledVector4();

            // Assert
            float scaledInput = input / 255F;

            Assert.Equal(scaledInput, actual.X);
            Assert.Equal(scaledInput, actual.Y);
            Assert.Equal(scaledInput, actual.Z);
            Assert.Equal(1, actual.W);
        }
Example #4
0
            public void FromScaledVector4_IsRgba32Compatible(byte luminance)
            {
                var original = new L8(luminance);

                Rgba32 rgba = default;

                original.ToRgba32(ref rgba);

                Vector4 rgbaVector = original.ToScaledVector4();

                L8 mirror = default;

                mirror.FromScaledVector4(rgbaVector);

                Assert.Equal(original, mirror);
            }
Example #5
0
        public void L8_ToRgba32(byte luminance)
        {
            // Arrange
            var gray = new L8(luminance);

            // Act
            Rgba32 actual = default;

            gray.ToRgba32(ref actual);

            // Assert
            Assert.Equal(luminance, actual.R);
            Assert.Equal(luminance, actual.G);
            Assert.Equal(luminance, actual.B);
            Assert.Equal(byte.MaxValue, actual.A);
        }
        private static Image <L8> CreateTestImage(int width, int height, int noOfFrames, bool paintWhite = false)
        {
            L8  bg    = paintWhite ? new L8(255) : default;
            var image = new Image <L8>(width, height, bg);

            for (int i = 1; i < noOfFrames; i++)
            {
                ImageFrame <L8> f = image.Frames.CreateFrame();
                if (paintWhite)
                {
                    f.PixelBuffer.MemoryGroup.Fill(bg);
                }
            }

            return(image);
        }
Example #7
0
        public void CalculateIntegralImage_Rgba32Works(TestImageProvider <Rgba32> provider)
        {
            using Image <Rgba32> image = provider.GetImage();

            // Act:
            Buffer2D <ulong> integralBuffer = image.CalculateIntegralImage();

            // Assert:
            VerifySumValues(provider, integralBuffer, (Rgba32 pixel) =>
            {
                L8 outputPixel = default;

                outputPixel.FromRgba32(pixel);

                return(outputPixel.PackedValue);
            });
        }
Example #8
0
        static void Main(string[] args)
        {
            const int featureWindowSize     = /*24*/ 16;
            const int halfFeatureWindowSize = featureWindowSize / 2;
            string    imageMainPath         = args[0];

            Image <L8> fullTextImage = Image.Load <L8>(imageMainPath + @"Images\FS18800114.2.11-a2-427w-c32.png");
            Image <L8> completeA     = Image.Load <L8>(imageMainPath + @"\Images\FS18800114.2.11-a2-427w-c32\a\CompleteA.png");

            PakiraDecisionTreeGenerator pakiraGenerator = new PakiraDecisionTreeGenerator();
            TrainData trainData = new TrainData();

            L8   whitePixel         = new L8(255);
            L8   blackPixel         = new L8(0);
            L8   dontCarePixel      = new L8(128);
            byte dontCarePixelValue = dontCarePixel.PackedValue;

            byte[] imageCropPixelsData = new byte[featureWindowSize * featureWindowSize * Unsafe.SizeOf <L8>()];

            completeA.ProcessPixelRows(accessor =>
            {
                Span <byte> imageCropPixels = new Span <byte>(imageCropPixelsData);

                for (int y = 0; y < accessor.Height; y++)
                {
                    Span <L8> pixelRow = accessor.GetRowSpan(y);

                    for (int x = 0; x < pixelRow.Length; x++)
                    {
                        // Get a reference to the pixel at position x
                        ref L8 pixel = ref pixelRow[x];

                        if (pixel != dontCarePixel)
                        {
                            Image <L8> whiteWindow = new Image <L8>(featureWindowSize, featureWindowSize, whitePixel);
                            Image <L8> imageCrop   = whiteWindow.Clone(clone => clone.DrawImage(fullTextImage, new Point(halfFeatureWindowSize - x, halfFeatureWindowSize - y), 1));

                            imageCrop.CopyPixelDataTo(imageCropPixels);

                            trainData = trainData.AddSample(imageCropPixelsData.Select <byte, double>(s => s), pixel.PackedValue);
                        }
                    }
                }
            });
Example #9
0
 public void FromL8(L8 source) => this.FromScaledVector4(source.ToScaledVector4());
Example #10
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        ///
        /// <param name="source">Source image data.</param>
        /// <param name="destination">Destination image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        ///
        protected override void ProcessFilter(Image <Rgb24> source, Image <L8> destination, Rectangle rect)
        {
            // processing start and stop X,Y positions
            int startX = rect.Left + 1;
            int startY = rect.Top + 1;
            int stopX  = startX + rect.Width - 2;
            int stopY  = startY + rect.Height - 2;

            int width  = rect.Width - 2;
            int height = rect.Height - 2;


            int dstOffset = rect.Width + 2;
            int srcOffset = rect.Width + 2;

            // pixel's value and gradients
            int gx, gy;
            //
            double orientation, toAngle = 180.0 / System.Math.PI;
            float  leftPixel = 0, rightPixel = 0;

            // STEP 1 - blur image
            source.Mutate(x => x.ApplyProcessor(this.gaussianFilter));
            var src = source.CloneAs <L8>();

            // orientation array
            byte[] orients = new byte[width * height];
            // gradients array
            float[,] gradients = new float[source.Width, source.Height];
            float maxGradient = float.NegativeInfinity;


            // STEP 2 - calculate magnitude and edge orientation
            int p = 0;

            // for each line
            for (int y = startY; y < stopY; y++)
            {
                // for each pixel
                for (int x = startX; x < stopX; x++, p++)
                {
                    gx = src[y - 1, x + 1].PackedValue + src[y, x + 1].PackedValue
                         - src[y - 1, x - 1].PackedValue - src[y, x - 1].PackedValue
                         + 2 * (src[y + 1, x].PackedValue - src[y - 1, x].PackedValue);

                    gy = src[y - 1, x - 1].PackedValue + src[y - 1, x + 1].PackedValue
                         - src[y, x - 1].PackedValue - src[y, x + 1].PackedValue
                         + 2 * (src[y - 1, x].PackedValue - src[y + 1, x].PackedValue);

                    // get gradient value
                    gradients[x, y] = (float)Math.Sqrt(gx * gx + gy * gy);
                    if (gradients[x, y] > maxGradient)
                    {
                        maxGradient = gradients[x, y];
                    }

                    // --- get orientation
                    if (gx == 0)
                    {
                        // can not divide by zero
                        orientation = (gy == 0) ? 0 : 90;
                    }
                    else
                    {
                        double div = (double)gy / gx;

                        // handle angles of the 2nd and 4th quads
                        if (div < 0)
                        {
                            orientation = 180 - System.Math.Atan(-div) * toAngle;
                        }
                        // handle angles of the 1st and 3rd quads
                        else
                        {
                            orientation = System.Math.Atan(div) * toAngle;
                        }

                        // get closest angle from 0, 45, 90, 135 set
                        if (orientation < 22.5)
                        {
                            orientation = 0;
                        }
                        else if (orientation < 67.5)
                        {
                            orientation = 45;
                        }
                        else if (orientation < 112.5)
                        {
                            orientation = 90;
                        }
                        else if (orientation < 157.5)
                        {
                            orientation = 135;
                        }
                        else
                        {
                            orientation = 0;
                        }
                    }

                    // save orientation
                    orients[p] = (byte)orientation;
                }
            }

            // STEP 3 - suppres non maximums

            p = 0;

            // for each line
            for (int y = startY; y < stopY; y++)
            {
                // for each pixel
                for (int x = startX; x < stopX; x++, p++)
                {
                    // get two adjacent pixels
                    switch (orients[p])
                    {
                    case 0:
                        leftPixel  = gradients[x - 1, y];
                        rightPixel = gradients[x + 1, y];
                        break;

                    case 45:
                        leftPixel  = gradients[x - 1, y + 1];
                        rightPixel = gradients[x + 1, y - 1];
                        break;

                    case 90:
                        leftPixel  = gradients[x, y + 1];
                        rightPixel = gradients[x, y - 1];
                        break;

                    case 135:
                        leftPixel  = gradients[x + 1, y + 1];
                        rightPixel = gradients[x - 1, y - 1];
                        break;
                    }
                    // compare current pixels value with adjacent pixels
                    if ((gradients[x, y] < leftPixel) || (gradients[x, y] < rightPixel))
                    {
                        destination[startY, startX] = new L8(0);
                    }
                    else
                    {
                        var result = (byte)(gradients[x, y] / maxGradient * 255);
                        destination[startY, startX] = new L8(result);
                    }
                }
            }

            // STEP 4 - hysteresis

            // for each line
            for (int y = startY; y < stopY; y++)
            {
                // for each pixel
                for (int x = startX; x < stopX; x++)
                {
                    if (destination[startY, startX].PackedValue < this.HighThreshold)
                    {
                        if (destination[startY, startX].PackedValue < this.LowThreshold)
                        {
                            // non edge
                            destination[startY, startX] = new L8(0);
                        }
                        else
                        {
                            // check 8 neighboring pixels
                            if ((destination[startY - 1, startX].PackedValue < this.HighThreshold) &&
                                (destination[startY + 1, startX].PackedValue < this.HighThreshold) &&
                                (destination[startY - 1, startX - 1].PackedValue < this.HighThreshold) &&
                                (destination[startY - 1, startX].PackedValue < this.HighThreshold) &&
                                (destination[startY - 1, startX + 1].PackedValue < this.HighThreshold) &&
                                (destination[startY + 1, startX - 1].PackedValue < this.HighThreshold) &&
                                (destination[startY + 1, startX].PackedValue < this.HighThreshold) &&
                                (destination[startY + 1, startX + 1].PackedValue < this.HighThreshold))
                            {
                                destination[startY, startX] = new L8(0);
                            }
                        }
                    }
                }
            }

            // STEP 5 - draw black rectangle to remove those pixels, which were not processed
            // (this needs to be done for those cases, when filter is applied "in place" -
            //  source image is modified instead of creating new copy)
            RectangleF r = rect;

            destination.Mutate(x => x.Draw(Pens.Solid(Color.Black, 1), r));
        }
Example #11
0
 public void FromL8(L8 source)
 {
 }
Example #12
0
        private void frm_PSC_CG_Load(object sender, EventArgs e)
        {
            dgv.Rows.Clear();

            dgv.Rows.Add("Distance (m)",
                         L1.ToString("f3"),
                         L2.ToString("f3"),
                         L3.ToString("f3"),
                         L4.ToString("f3"),
                         L5.ToString("f3"),
                         L6.ToString("f3"),
                         L7.ToString("f3"),
                         L8.ToString("f3"),
                         L9.ToString("f3"));

            dgv.Rows.Add("Cable 'e' (mm)",
                         Cable_E.F1.ToString("f3"),
                         Cable_E.F2.ToString("f3"),
                         Cable_E.F3.ToString("f3"),
                         Cable_E.F4.ToString("f3"),
                         Cable_E.F5.ToString("f3"),
                         Cable_E.F6.ToString("f3"),
                         Cable_E.F7.ToString("f3"),
                         Cable_E.F8.ToString("f3"),
                         Cable_E.F9.ToString("f3"));
            dgv.Rows.Add("Cable 'd' (mm)",
                         Cable_D.F1.ToString("f3"),
                         Cable_D.F2.ToString("f3"),
                         Cable_D.F3.ToString("f3"),
                         Cable_D.F4.ToString("f3"),
                         Cable_D.F5.ToString("f3"),
                         Cable_D.F6.ToString("f3"),
                         Cable_D.F7.ToString("f3"),
                         Cable_D.F8.ToString("f3"),
                         Cable_D.F9.ToString("f3"));
            dgv.Rows.Add("Cable 'c' (mm)",
                         Cable_C.F1.ToString("f3"),
                         Cable_C.F2.ToString("f3"),
                         Cable_C.F3.ToString("f3"),
                         Cable_C.F4.ToString("f3"),
                         Cable_C.F5.ToString("f3"),
                         Cable_C.F6.ToString("f3"),
                         Cable_C.F7.ToString("f3"),
                         Cable_C.F8.ToString("f3"),
                         Cable_C.F9.ToString("f3"));


            dgv.Rows.Add("Cable 'b' (mm)",
                         Cable_B.F1.ToString("f3"),
                         Cable_B.F2.ToString("f3"),
                         Cable_B.F3.ToString("f3"),
                         Cable_B.F4.ToString("f3"),
                         Cable_B.F5.ToString("f3"),
                         Cable_B.F6.ToString("f3"),
                         Cable_B.F7.ToString("f3"),
                         Cable_B.F8.ToString("f3"),
                         Cable_B.F9.ToString("f3"));
            dgv.Rows.Add("Cable 'a' (mm)",
                         Cable_A.F1.ToString("f3"),
                         Cable_A.F2.ToString("f3"),
                         Cable_A.F3.ToString("f3"),
                         Cable_A.F4.ToString("f3"),
                         Cable_A.F5.ToString("f3"),
                         Cable_A.F6.ToString("f3"),
                         Cable_A.F7.ToString("f3"),
                         Cable_A.F8.ToString("f3"),
                         Cable_A.F9.ToString("f3"));

            //Average
            Cable_CG = ((Cable_A + Cable_B + Cable_C + Cable_D + Cable_E) / 5.0);


            dgv.Rows.Add("CG",
                         Cable_CG.F1.ToString("f3"),
                         Cable_CG.F2.ToString("f3"),
                         Cable_CG.F3.ToString("f3"),
                         Cable_CG.F4.ToString("f3"),
                         Cable_CG.F5.ToString("f3"),
                         Cable_CG.F6.ToString("f3"),
                         Cable_CG.F7.ToString("f3"),
                         Cable_CG.F8.ToString("f3"),
                         Cable_CG.F9.ToString("f3"));


            dgv.Rows[0].ReadOnly = true;
            dgv.Rows[0].Frozen   = true;
            dgv.Rows[0].DefaultCellStyle.ForeColor = Color.Blue;

            dgv.Rows[6].ReadOnly = true;
            dgv.Rows[6].Frozen   = true;
            dgv.Rows[6].DefaultCellStyle.ForeColor = Color.Blue;
        }
 /// <inheritdoc />
 public void FromL8(L8 source)
 {
     throw new NotImplementedException();
 }
Example #14
0
        public void ExportTextures(StreamWriter mtlWriter, string outputPath, bool forceDirect = false)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (textureDat == null)
            {
                throw new InvalidOperationException("No texture pack supplied.");
            }

            int i = 0;

            numWrittenTextures = 0;
            foreach (var pair in textureCache.OrderBy(p => p.Key))
            {
                string    pngPath    = $"{outputPath}{i}.png";
                string    alphaPath  = $"{outputPath}{i}_alpha.png";
                TxmHeader textureTxm = pair.Value;

                int txmIndex = (int)(pair.Key >> 32);
                using (var txmMs = new MemoryStream(textureDat.GetData(txmIndex)))
                {
                    BinaryReader txmBr  = new BinaryReader(txmMs);
                    TxmHeader    pakTxm = new TxmHeader();
                    pakTxm.Read(txmBr);

                    Image <Rgba32> img = null;
                    try
                    {
                        // Check if TXM is already suitable
                        if (forceDirect ||
                            /*pakTxm.ImageSourcePixelFormat == textureTxm.ImageSourcePixelFormat &&*/
                            pakTxm.ImageBufferBase == textureTxm.ImageBufferBase &&
                            pakTxm.ClutPixelFormat == textureTxm.ClutPixelFormat &&
                            pakTxm.ClutBufferBase == textureTxm.ClutBufferBase)
                        {
                            // Use TXM as-is
                            txmMs.Seek(0, SeekOrigin.Begin);
                            if (new string(txmBr.ReadChars(4)) == "DAT\0")
                            {
                                // Unwrap DAT
                                txmMs.Seek(0, SeekOrigin.Begin);
                                using (DatReader txmDat = new DatReader(txmMs))
                                {
                                    if (txmDat.EntriesCount != 1)
                                    {
                                        throw new InvalidDataException("Nested texture DAT contains more than one file.");
                                    }
                                    using (MemoryStream innerStream = new MemoryStream(txmDat.GetData(0)))
                                    {
                                        img = TxmConversion.ConvertTxmToImage(innerStream);
                                    }
                                }
                            }
                            else
                            {
                                txmMs.Seek(0, SeekOrigin.Begin);
                                img = TxmConversion.ConvertTxmToImage(txmMs);

                                // Dump palette
                                //if (pakTxm.ClutPixelFormat != TxmPixelFormat.None)
                                //{
                                //    txmMs.Seek(0x10, SeekOrigin.Begin);
                                //    using (var palette = TxmConversion.ConvertTxmRgba32(txmBr, pakTxm.ClutWidth, pakTxm.ClutHeight))
                                //    {
                                //        palette.SaveAsPng($"palette_{numWrittenTextures}.png");
                                //    }
                                //}
                            }
                        }
                        else
                        {
                            // Generate new TXM
                            using (MemoryStream ms = new MemoryStream())
                            {
                                BinaryWriter bw = new BinaryWriter(ms);
                                textureTxm.Write(bw);
                                CopyTexelsClut(txmBr, bw, pakTxm, textureTxm);
                                CopyTexels(txmBr, bw, pakTxm, textureTxm);
                                bw.Flush();
                                ms.Seek(0, SeekOrigin.Begin);
                                img = TxmConversion.ConvertTxmToImage(ms);
                            }
                        }

                        // Save out color texture
                        using (var img24bpp = img.CloneAs <Rgb24>())
                        {
                            img24bpp.SaveAsPng(pngPath);
                        }

                        // Extract alpha channel as a separate image
                        using (var alphaImg = new Image <L8>(img.Width, img.Height))
                        {
                            for (int y = 0; y < alphaImg.Height; ++y)
                            {
                                var srcSpan  = img.GetPixelRowSpan(y);
                                var destSpan = alphaImg.GetPixelRowSpan(y);
                                for (int x = 0; x < alphaImg.Width; ++x)
                                {
                                    var srcAlpha = srcSpan[x].A;
                                    destSpan[x] = new L8(srcAlpha);
                                }
                            }
                            alphaImg.SaveAsPng(alphaPath);
                        }
                    }
                    finally
                    {
                        if (img != null)
                        {
                            img.Dispose();
                        }
                    }
                }

                mtlWriter.WriteLine($"newmtl tex_{pair.Key:x12}");
                mtlWriter.WriteLine("Kd 0.80000000 0.80000000 0.80000000");
                mtlWriter.WriteLine("Ka 0 0 0");
                mtlWriter.WriteLine("Ke 0 0 0");
                mtlWriter.WriteLine("Ks 0 0 0");
                mtlWriter.WriteLine("d 1");
                mtlWriter.WriteLine("illum 2");
                mtlWriter.WriteLine($"map_Kd {Path.GetFileName(pngPath)}");
                mtlWriter.WriteLine($"map_d {Path.GetFileName(alphaPath)}");
                mtlWriter.WriteLine();

                ++i;
                ++numWrittenTextures;
            }
        }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        NowCursorState = tmpCursor.GetComponent <AnimatedCursor>().tmpCursorState;

        PlaceBtnState  = PlaceButton.GetComponent <ButtonInteraction>().NowButtonState;
        DeleteBtnState = DeleteButton.GetComponent <ButtonInteraction>().NowButtonState;
        CancelBtnState = CancelButton.GetComponent <ButtonInteraction>().NowButtonState;


        lineRenderer = GetComponent <LineRenderer>();

        //Debug.Log("Cursor Position: " + tmpCursor.transform.position);

        //Vector3 CursorPosition = tmpCursor.GetComponent<Transform>().position;

        if ((ButtonInteraction.PosState == PosButtonType.PLACE) && (NowCursorState == CursorStateEnum.Release) &&
            (PlaceBtnState != ButtonStateEnum.Targeted) && (PlaceBtnState != ButtonStateEnum.Pressed) &&
            (DeleteBtnState != ButtonStateEnum.Observation) && (CancelBtnState != ButtonStateEnum.Observation))
        {
            if (SizeButtonCollection.SizeButtonState == SizeButtonType.MEDIUM)
            {
                offset = 6.0f;
            }
            else if (SizeButtonCollection.SizeButtonState == SizeButtonType.LARGE)
            {
                offset = 8.0f;
            }
            else if (SizeButtonCollection.SizeButtonState == SizeButtonType.SMALL)
            {
                offset = 5.0f;
            }

            Vector3 FinalPos = tmpCursor.transform.position - new Vector3(0f, 0f, 0.1f) * offset;
            Instantiate(PlaneObject, FinalPos, transform.rotation, this.transform);   //Genarate the drone

            ChildCount = this.transform.childCount;

            /*Use to process the three Red Light*/

            if (ChildCount > 1)
            {
                Vector3 pos1, pos2;                                                                          //the position of two way point(drone)
                Vector3 p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18; //Red light initial position
                pos1 = this.gameObject.transform.GetChild(ChildCount - 2).transform.position;
                pos2 = this.gameObject.transform.GetChild(ChildCount - 1).transform.position;

                p0  = (pos1 * 1 + pos2 * 19) / 20;
                p1  = (pos1 * 2 + pos2 * 18) / 20;
                p2  = (pos1 * 3 + pos2 * 17) / 20;
                p3  = (pos1 * 4 + pos2 * 16) / 20;
                p4  = (pos1 * 5 + pos2 * 15) / 20;
                p5  = (pos1 * 6 + pos2 * 14) / 20;
                p6  = (pos1 * 7 + pos2 * 13) / 20;
                p7  = (pos1 * 8 + pos2 * 12) / 20;
                p8  = (pos1 * 9 + pos2 * 11) / 20;
                p9  = (pos1 * 10 + pos2 * 10) / 20;
                p10 = (pos1 * 11 + pos2 * 9) / 20;
                p11 = (pos1 * 12 + pos2 * 8) / 20;
                p12 = (pos1 * 13 + pos2 * 7) / 20;
                p13 = (pos1 * 14 + pos2 * 6) / 20;
                p14 = (pos1 * 15 + pos2 * 5) / 20;

                p15 = (pos1 * 16 + pos2 * 4) / 20;
                p16 = (pos1 * 17 + pos2 * 3) / 20;
                p17 = (pos1 * 18 + pos2 * 2) / 20;
                p18 = (pos1 * 19 + pos2 * 1) / 20;


                L0 = Instantiate(CloneRedLight_0, p0, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L0.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L0.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L0.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L1 = Instantiate(CloneRedLight_1, p1, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L1.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L1.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L1.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L2 = Instantiate(CloneRedLight_2, p2, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L2.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L2.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L2.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L3 = Instantiate(CloneRedLight_3, p3, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L3.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L3.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L3.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L4 = Instantiate(CloneRedLight_4, p4, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L4.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L4.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L4.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L5 = Instantiate(CloneRedLight_5, p5, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L5.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L5.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L5.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L6 = Instantiate(CloneRedLight_6, p6, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L6.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L6.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L6.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L7 = Instantiate(CloneRedLight_7, p7, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L7.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L7.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L7.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L8 = Instantiate(CloneRedLight_8, p8, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L8.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L8.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L8.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L9 = Instantiate(CloneRedLight_9, p9, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L9.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L9.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L9.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L10 = Instantiate(CloneRedLight_10, p10, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L10.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L10.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L10.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L11 = Instantiate(CloneRedLight_11, p11, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L11.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L11.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L11.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L12 = Instantiate(CloneRedLight_12, p12, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L12.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L12.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L12.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L13 = Instantiate(CloneRedLight_13, p13, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L13.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L13.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L13.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L14 = Instantiate(CloneRedLight_14, p14, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L14.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L14.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L14.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;


                /////////////////////////////////////////
                L15 = Instantiate(CloneRedLight_15, p15, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L15.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L15.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L15.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L16 = Instantiate(CloneRedLight_16, p16, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L16.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L16.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L16.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L17 = Instantiate(CloneRedLight_17, p17, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L17.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L17.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L17.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;

                L18 = Instantiate(CloneRedLight_18, p18, this.gameObject.transform.GetChild(ChildCount - 2).transform.rotation, LightManager.transform);
                L18.GetComponent <RedLightPos>().Obj1        = this.gameObject.transform.GetChild(ChildCount - 2).gameObject;
                L18.GetComponent <RedLightPos>().Obj2        = this.gameObject.transform.GetChild(ChildCount - 1).gameObject;
                L18.GetComponent <RedLightPos>().Current_Num = ChildCount - 2;
            }

            //WayPoint.Add(tmp);
            //Debug.Log("InstantiateInstantiateInstantiateInstantiateInstantiateInstantiate");
        }


        /* Line Process*/
        ChildCount = this.transform.childCount;
        lineRenderer.SetVertexCount(ChildCount);


        if (ChildCount > 1)
        {
            for (int i = 0; i < ChildCount; i++)
            {
                tmp = this.gameObject.transform.GetChild(i).gameObject;
                lineRenderer.SetPosition(i, tmp.transform.position);
            }


            /*Obstacle Detect*/
            for (int i = 0; i < ChildCount - 1; i++)
            {
                Obj1 = this.gameObject.transform.GetChild(i).gameObject;
                Obj2 = this.gameObject.transform.GetChild(i + 1).gameObject;
                Ray        ray = new Ray(Obj1.transform.position, Obj2.transform.position - Obj1.transform.position);
                RaycastHit hit;

                //Debug.Log( i + " -> " + (i+1) + " distance : " + Vector3.Distance(Obj1.transform.position, Obj2.transform.position));
                float distance = Vector3.Distance(Obj1.transform.position, Obj2.transform.position) - 0.1f;

                Physics.Raycast(ray, out hit, distance, mask);

                //When collision is NOT NULL, there is obstacles
                if (hit.transform != null)
                {
                    lineRenderer.material = LineMat2; // if collision the line become red
                    //Debug.Log("BBBBBBBBB");

                    //LineCollision = false;   // Let Other Script Know Collision State
                    //LineCollisionNum = i + 1;

                    Debug.Log("Blocked by : " + hit.transform.name);
                }
                //If is NULL -> No Obstacles
                else if (hit.transform == null)
                {
                    lineRenderer.material = LineMat1;
                    //LineCollision = true;
                    //LineCollisionNum = -1;
                    //Debug.Log("NNNNNNNNN");
                }

                //Debug.Log("Line color : " + lineRenderer.material);
            }
        }

        //if(ChildCount == 2) lineRenderer.SetPosition(2, new Vector3(0,0,1));
    }
        //TODO: test display area buffer

        private static byte getByteFromL8(L8 source)
        {
            return(source.PackedValue);
        }