private void CalculateAllFeatures(List <Point> sketch, String BuildingType)
        {
            SketchProcessor sketchProcessor     = new SketchProcessor();
            List <Point>    SingleGesturePoints = sketchProcessor.getResampledPoints(sketch);

            //F1, F2 cos  and sin start angle
            // if (!(SingleGesturePoints.Count < 3))
            //{
            Double xdiff = SingleGesturePoints[2].X - SingleGesturePoints[0].X;
            Double ydiff = SingleGesturePoints[2].Y - SingleGesturePoints[0].Y;
            Double hypot = Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2));
            Double F1    = xdiff / hypot;
            Double F2    = ydiff / hypot;

            //}
            //F1, F2 cos  and sin start angle
            System.Diagnostics.Debug.WriteLine("xdiff " + xdiff + " " + "hypot " + hypot);

            //F3 dist first and last
            var    lastIndex = SingleGesturePoints.Count - 1;
            Double F3        = Math.Sqrt(Math.Pow((SingleGesturePoints[lastIndex].X - SingleGesturePoints[0].X), 2) + Math.Pow((SingleGesturePoints[lastIndex].Y - SingleGesturePoints[0].Y), 2));
            //F3 dist first and last

            //F4 cos angle first last
            Double F4 = (SingleGesturePoints[SingleGesturePoints.Count - 1].X - SingleGesturePoints[0].X) / F3;
            //F4 cos angle first last

            // F5 sin angle first last
            Double F5 = (SingleGesturePoints[SingleGesturePoints.Count - 1].Y - SingleGesturePoints[0].Y) / F3;
            // F5 sin angle first last

            //F6 stroke length
            Double sum = 0;

            for (var i = 1; i < SingleGesturePoints.Count; i++)
            {
                sum = sum + Math.Sqrt(Math.Pow((SingleGesturePoints[i].X - SingleGesturePoints[i - 1].X), 2) + Math.Pow((SingleGesturePoints[i].Y - SingleGesturePoints[i - 1].Y), 2));
            }
            Double F6 = sum;
            //F6 stroke Length

            //F7, F8, F9 All angles
            Double totalAngle   = 0;
            Double squaredAngle = 0;
            Double modAngle     = 0;
            Double theta        = 0;

            for (var i = 1; i < SingleGesturePoints.Count - 1; i++)
            {
                var numerator   = (SingleGesturePoints[i].X * SingleGesturePoints[i - 1].Y) - (SingleGesturePoints[i - 1].X * SingleGesturePoints[i].Y);
                var denominator = (SingleGesturePoints[i].X * SingleGesturePoints[i - 1].Y) + (SingleGesturePoints[i - 1].Y * SingleGesturePoints[i].Y);
                if (denominator != 0)
                {
                    theta = Math.Atan(numerator / denominator);
                }
                else
                {
                    if (numerator < 0)
                    {
                        theta = Math.PI * 3 / 2;
                    }
                    else
                    {
                        theta = Math.PI / 2;
                    }
                }
                //not handling the case where numerator = 0
                totalAngle   = totalAngle + theta;
                squaredAngle = squaredAngle + Math.Pow(theta, 2);
                modAngle     = modAngle + Math.Abs(theta);
            }
            Double F7 = totalAngle;
            Double F8 = squaredAngle;
            Double F9 = modAngle;
            //F7, F8, F9 All angles

            //F10 Length of bounding box
            Double xmax = 0;
            Double ymax = 0;
            Double xmin = 0;
            Double ymin = 0;

            for (var i = 0; i < SingleGesturePoints.Count; i++)
            {
                if (xmax == 0 || xmax < SingleGesturePoints[i].X)
                {
                    xmax = SingleGesturePoints[i].X;
                }
                if (xmin == 0 || xmin > SingleGesturePoints[i].X)
                {
                    xmin = SingleGesturePoints[i].X;
                }
                if (ymax == 0 || ymax < SingleGesturePoints[i].Y)
                {
                    ymax = SingleGesturePoints[i].Y;
                }
                if (ymin == 0 || ymin > SingleGesturePoints[i].Y)
                {
                    ymin = SingleGesturePoints[i].Y;
                }
            }
            Double F10 = Math.Sqrt(Math.Pow(xmax - xmin, 2) + Math.Pow(ymax - ymin, 2));
            //F10 Length of bounding box

            //F11 angle of bounding box
            Double F11 = Math.Atan((ymax - ymin) / (xmax - xmin));
            //F11 angle of bounding box

            //Create/append features and building type to a txt file
            // Double[] arr = {F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11};
            //List<Double> featurearray = new List<Double>();
            //featurearray.Add(F1); featurearray.Add(F2); featurearray.Add(F3); featurearray.Add(F4);
            //featurearray.Add(F5); featurearray.Add(F6); featurearray.Add(F7); featurearray.Add(F8);
            //featurearray.Add(F9); featurearray.Add(F10); featurearray.Add(F11);//featurearray.Add(BuildingType);
            string path1 = @"D:\final_version\Gesture-Gis-master\GestureGis2\Featurefile.txt";
            string path  = @"D:\final_version\Gesture-Gis-master\GestureGis2\ComparisonFeaturefile.txt";

            string buildm = "Resdential";

            try
            {
                var myFile = File.Create(path);
                myFile.Close();
                TextWriter tw_new_one = new StreamWriter(path);
                using (StreamReader reader = new StreamReader(path1))
                {
                    while (!reader.EndOfStream)
                    {
                        tw_new_one.WriteLine(reader.ReadLine());
                    }
                    //tw_new_one.WriteLine("   ");
                    //tw_new_one.WriteLine(" ");
                    tw_new_one.Write(F1); tw_new_one.Write(","); tw_new_one.Write(F2); tw_new_one.Write(","); tw_new_one.Write(F3); tw_new_one.Write(","); tw_new_one.Write(F4); tw_new_one.Write(",");
                    tw_new_one.Write(F5); tw_new_one.Write(","); tw_new_one.Write(F6); tw_new_one.Write(","); tw_new_one.Write(F7); tw_new_one.Write(","); tw_new_one.Write(F8); tw_new_one.Write(",");
                    tw_new_one.Write(F9); tw_new_one.Write(","); tw_new_one.Write(F10); tw_new_one.Write(","); tw_new_one.Write(F11); tw_new_one.Write(","); tw_new_one.Write(buildm + Environment.NewLine);
                    //tw_new_one.WriteLine(" ");
                    reader.Close();
                    tw_new_one.Close();
                }

                classifyTest();
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                string pathar = @"D:\final_version\Gesture-Gis-master\GestureGis2\ComparisonFeaturefile.arff";
                if (File.Exists(pathar))
                {
                    File.Delete(pathar);
                }

                System.Diagnostics.Debug.WriteLine(F1 + " " + F2 + " " + F3 + " " + F4 + " " + F5 + " " + F6 + " " + F7 + " " + F8 + " " + F9 + " " + F10 + " " + F11);
            }
            catch (java.lang.Exception ex)
            {
                ex.printStackTrace();
            }
        }
Beispiel #2
0
        private void CalculateAllFeatures(List <Point> sketch, String BuildingType)
        {
            SketchProcessor sketchProcessor     = new SketchProcessor();
            List <Point>    SingleGesturePoints = sketchProcessor.getResampledPoints(sketch);

            //F1, F2 cos  and sin start angle
            // if (!(SingleGesturePoints.Count < 3))
            //{
            Double xdiff = SingleGesturePoints[2].X - SingleGesturePoints[0].X;
            Double ydiff = SingleGesturePoints[2].Y - SingleGesturePoints[0].Y;
            Double hypot = Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2));
            Double F1    = xdiff / hypot;
            Double F2    = ydiff / hypot;

            //}
            //F1, F2 cos  and sin start angle
            System.Diagnostics.Debug.WriteLine("xdiff " + xdiff + " " + "hypot " + hypot);

            //F3 dist first and last
            var    lastIndex = SingleGesturePoints.Count - 1;
            Double F3        = Math.Sqrt(Math.Pow((SingleGesturePoints[lastIndex].X - SingleGesturePoints[0].X), 2) + Math.Pow((SingleGesturePoints[lastIndex].Y - SingleGesturePoints[0].Y), 2));
            //F3 dist first and last

            //F4 cos angle first last
            Double F4 = (SingleGesturePoints[SingleGesturePoints.Count - 1].X - SingleGesturePoints[0].X) / F3;
            //F4 cos angle first last

            // F5 sin angle first last
            Double F5 = (SingleGesturePoints[SingleGesturePoints.Count - 1].Y - SingleGesturePoints[0].Y) / F3;
            // F5 sin angle first last

            //F6 stroke length
            Double sum = 0;

            for (var i = 1; i < SingleGesturePoints.Count; i++)
            {
                sum = sum + Math.Sqrt(Math.Pow((SingleGesturePoints[i].X - SingleGesturePoints[i - 1].X), 2) + Math.Pow((SingleGesturePoints[i].Y - SingleGesturePoints[i - 1].Y), 2));
            }
            Double F6 = sum;
            //F6 stroke Length

            //F7, F8, F9 All angles
            Double totalAngle   = 0;
            Double squaredAngle = 0;
            Double modAngle     = 0;
            Double theta        = 0;

            for (var i = 1; i < SingleGesturePoints.Count - 1; i++)
            {
                var numerator   = (SingleGesturePoints[i].X * SingleGesturePoints[i - 1].Y) - (SingleGesturePoints[i - 1].X * SingleGesturePoints[i].Y);
                var denominator = (SingleGesturePoints[i].X * SingleGesturePoints[i - 1].Y) + (SingleGesturePoints[i - 1].Y * SingleGesturePoints[i].Y);
                if (denominator != 0)
                {
                    theta = Math.Atan(numerator / denominator);
                }
                else
                {
                    if (numerator < 0)
                    {
                        theta = Math.PI * 3 / 2;
                    }
                    else
                    {
                        theta = Math.PI / 2;
                    }
                }
                //not handling the case where numerator = 0
                totalAngle   = totalAngle + theta;
                squaredAngle = squaredAngle + Math.Pow(theta, 2);
                modAngle     = modAngle + Math.Abs(theta);
            }
            Double F7 = totalAngle;
            Double F8 = squaredAngle;
            Double F9 = modAngle;
            //F7, F8, F9 All angles

            //F10 Length of bounding box
            Double xmax = 0;
            Double ymax = 0;
            Double xmin = 0;
            Double ymin = 0;

            for (var i = 0; i < SingleGesturePoints.Count; i++)
            {
                if (xmax == 0 || xmax < SingleGesturePoints[i].X)
                {
                    xmax = SingleGesturePoints[i].X;
                }
                if (xmin == 0 || xmin > SingleGesturePoints[i].X)
                {
                    xmin = SingleGesturePoints[i].X;
                }
                if (ymax == 0 || ymax < SingleGesturePoints[i].Y)
                {
                    ymax = SingleGesturePoints[i].Y;
                }
                if (ymin == 0 || ymin > SingleGesturePoints[i].Y)
                {
                    ymin = SingleGesturePoints[i].Y;
                }
            }
            Double F10 = Math.Sqrt(Math.Pow(xmax - xmin, 2) + Math.Pow(ymax - ymin, 2));
            //F10 Length of bounding box

            //F11 angle of bounding box
            Double F11 = Math.Atan((ymax - ymin) / (xmax - xmin));
            //F11 angle of bounding box

            //Create/append features and building type to a txt file
            // Double[] arr = {F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11};
            //List<Double> featurearray = new List<Double>();
            //featurearray.Add(F1); featurearray.Add(F2); featurearray.Add(F3); featurearray.Add(F4);
            //featurearray.Add(F5); featurearray.Add(F6); featurearray.Add(F7); featurearray.Add(F8);
            //featurearray.Add(F9); featurearray.Add(F10); featurearray.Add(F11);//featurearray.Add(BuildingType);

            /*if(!(classArray.Contains(BuildingType)))
             * {
             *  classArray.Add(BuildingType);
             *  string path_class = @"D:\final_version\Gesture-Gis-master\GestureGis2\Classfile.txt";
             *  if (!File.Exists(path_class))
             *  {
             *      var myFile = File.Create(path_class);
             *      myFile.Close();
             *      TextWriter tw = new StreamWriter(path_class);
             *      tw.Write(BuildingType+Environment.NewLine);
             *      tw.Close();
             *  }
             *  else if (File.Exists(path_class))
             *  {
             *      using (var tw = new StreamWriter(path_class, true))
             *      {
             *          tw.Write(BuildingType+Environment.NewLine);
             *          tw.Close();
             *      }
             *  }
             * }*/
            string mypath = @"D:\final_version\Gesture-Gis-master\GestureGis2\Featurefile.txt";
            string inp    = "interpretation";

            //FileStream fs = null;
            if (!File.Exists(mypath))
            {
                var myFile = File.Create(mypath);
                myFile.Close();
                TextWriter tw = new StreamWriter(mypath);
                //tw.WriteLine("  ");
                tw.Write(1.0); tw.Write(","); tw.Write(2.0); tw.Write(","); tw.Write(3.0); tw.Write(","); tw.Write(4.0); tw.Write(","); tw.Write(5.0); tw.Write(","); tw.Write(6.0); tw.Write(","); tw.Write(7.0); tw.Write(","); tw.Write(8.0);
                tw.Write(","); tw.Write(9.0); tw.Write(","); tw.Write(10.0); tw.Write(","); tw.Write(11.0); tw.Write(","); tw.Write(inp + Environment.NewLine);
                //tw.WriteLine(" ");
                tw.Write(F1); tw.Write(","); tw.Write(F2); tw.Write(","); tw.Write(F3); tw.Write(","); tw.Write(F4); tw.Write(",");
                tw.Write(F5); tw.Write(","); tw.Write(F6); tw.Write(","); tw.Write(F7); tw.Write(","); tw.Write(F8); tw.Write(",");
                tw.Write(F9); tw.Write(","); tw.Write(F10); tw.Write(","); tw.Write(F11); tw.Write(","); tw.Write(BuildingType + Environment.NewLine);
                tw.Close();
                // tw.WriteLine(BuildingType);
                //tw.Close();
            }
            else if (File.Exists(mypath))
            {
                using (var tw = new StreamWriter(mypath, true))
                {
                    //tw.WriteLine(" ");
                    tw.Write(F1); tw.Write(","); tw.Write(F2); tw.Write(","); tw.Write(F3); tw.Write(","); tw.Write(F4); tw.Write(",");
                    tw.Write(F5); tw.Write(","); tw.Write(F6); tw.Write(","); tw.Write(F7); tw.Write(","); tw.Write(F8); tw.Write(",");
                    tw.Write(F9); tw.Write(","); tw.Write(F10); tw.Write(","); tw.Write(F11); tw.Write(","); tw.Write(BuildingType + Environment.NewLine);
                    tw.Close();
                }
            }
        }