// extract this contour map into DNA, the feature map // used their C++ code for this method, Line 535-581 public List<Phi> extractDNA() { List<Phi> DNA = new List<Phi>(); // DNA for poly List<Phi> DNAseq = new List<Phi>(); // DNA for all List<Phi> verticies = new List<Phi>(); // start of extraction int i = 0; foreach (ColorfulPoint point in _points) { Phi tempPhi = new Phi(); tempPhi.x = point.X; tempPhi.y = point.Y; tempPhi.theta = 0; tempPhi.l = i; tempPhi.color = point.color; DNAseq.Add(tempPhi); i++; } i = 0; foreach (ColorfulPoint point in _polyPoints) { Phi tempPhi = new Phi(); tempPhi.x = point.X; tempPhi.y = point.Y; tempPhi.theta = 0; tempPhi.l = 0; tempPhi.color = point.color; verticies.Add(tempPhi); i++; } // interpolate the arc length for (int j = 0, t = 0; j < verticies.Count; ++j) { while (!(verticies[j].x == DNAseq[t].x && verticies[j].y == DNAseq[t].y)) { t++; } Phi vert = verticies[j]; vert.l = t; verticies[j] = vert; t = 0; } // End of Functional codes // Start of Experimental double angle = 0; for (i = 0; i < verticies.Count; ++i) { int next = i + 1; if (next == verticies.Count) { next = 0; }//Bounds check //Turning angle computation //If this is starting vertex theta = 0 if (i == 0) { angle = 0.0; } else { //Compute turning angle double turn_angle = Geometry.calcAngle(verticies[next].x, verticies[next].y, verticies[i].x, verticies[i].y, verticies[i - 1].x, verticies[i - 1].y); double vector1_x = verticies[i].x - verticies[i - 1].x; double vector1_y = verticies[i].y - verticies[i - 1].y; double vector2_x = verticies[next].x - verticies[i].x; double vector2_y = verticies[next].y - verticies[i].y; int direction = Geometry.sign((vector1_y * vector2_x) - (vector1_x * vector2_y)); // Cumulate the turning angles angle += (180 - turn_angle) * direction; } //Store this turning function value Phi vert = verticies[i]; vert.theta = Math.Round(angle); verticies[i] = vert; //For all points between vertex[i] and vertex[next] theta will be the same // Theta is the total angle turned from start point if (verticies[next].l > verticies[i].l) { for (int j = verticies[i].l; j <= verticies[next].l; ++j) { Phi v = DNAseq[j]; v.theta = Math.Round(angle); DNAseq[j] = v; } } else { for (int j = verticies[i].l; j <= verticies[next].l + Length; ++j) { int index = j; if (index >= Length) { index -= Length; } Phi vv = DNAseq[index]; vv.theta = Math.Round(angle); DNAseq[index] = vv; } } } for (i = 0; i < DNAseq.Count; i++) { int index = i + verticies[0].l + 1; if (index >= DNAseq.Count) { index -= DNAseq.Count; } DNA.Add(DNAseq[index]); Phi tem = DNA[i]; tem.l = i; DNA[i] = tem; } return DNA; }
// extract this contour map into DNA, the feature map // used their C++ code for this method, Line 535-581 public List <Phi> extractDNA() { List <Phi> DNA = new List <Phi>(); // DNA for poly List <Phi> DNAseq = new List <Phi>(); // DNA for all List <Phi> verticies = new List <Phi>(); // start of extraction int i = 0; foreach (ColorfulPoint point in _points) { Phi tempPhi = new Phi(); tempPhi.x = point.X; tempPhi.y = point.Y; tempPhi.theta = 0; tempPhi.l = i; tempPhi.color = point.color; DNAseq.Add(tempPhi); i++; } i = 0; foreach (ColorfulPoint point in _polyPoints) { Phi tempPhi = new Phi(); tempPhi.x = point.X; tempPhi.y = point.Y; tempPhi.theta = 0; tempPhi.l = 0; tempPhi.color = point.color; verticies.Add(tempPhi); i++; } // interpolate the arc length for (int j = 0, t = 0; j < verticies.Count; ++j) { while (!(verticies[j].x == DNAseq[t].x && verticies[j].y == DNAseq[t].y)) { t++; } Phi vert = verticies[j]; vert.l = t; verticies[j] = vert; t = 0; } // End of Functional codes // Start of Experimental double angle = 0; for (i = 0; i < verticies.Count; ++i) { int next = i + 1; if (next == verticies.Count) { next = 0; }//Bounds check //Turning angle computation //If this is starting vertex theta = 0 if (i == 0) { angle = 0.0; } else { //Compute turning angle double turn_angle = Geometry.calcAngle(verticies[next].x, verticies[next].y, verticies[i].x, verticies[i].y, verticies[i - 1].x, verticies[i - 1].y); double vector1_x = verticies[i].x - verticies[i - 1].x; double vector1_y = verticies[i].y - verticies[i - 1].y; double vector2_x = verticies[next].x - verticies[i].x; double vector2_y = verticies[next].y - verticies[i].y; int direction = Geometry.sign((vector1_y * vector2_x) - (vector1_x * vector2_y)); // Cumulate the turning angles angle += (180 - turn_angle) * direction; } //Store this turning function value Phi vert = verticies[i]; vert.theta = Math.Round(angle); verticies[i] = vert; //For all points between vertex[i] and vertex[next] theta will be the same // Theta is the total angle turned from start point if (verticies[next].l > verticies[i].l) { for (int j = verticies[i].l; j <= verticies[next].l; ++j) { Phi v = DNAseq[j]; v.theta = Math.Round(angle); DNAseq[j] = v; } } else { for (int j = verticies[i].l; j <= verticies[next].l + Length; ++j) { int index = j; if (index >= Length) { index -= Length; } Phi vv = DNAseq[index]; vv.theta = Math.Round(angle); DNAseq[index] = vv; } } } for (i = 0; i < DNAseq.Count; i++) { int index = i + verticies[0].l + 1; if (index >= DNAseq.Count) { index -= DNAseq.Count; } DNA.Add(DNAseq[index]); Phi tem = DNA[i]; tem.l = i; DNA[i] = tem; } return(DNA); }