///** // * this method write the triangulation as an SMF file (OFF like format) // * // * // * @param smfFile // * - file name // * @throws Exception // */ public void write_smf(String smfFile) { int len = this._vertices.Count; Point_dt[] ans = new Point_dt[len]; Point_dt[] it = this._vertices.ToArray(); IComparer <Point_dt> comp = Point_dt.getComparator(); for (int i = 0; i < len; i++) { ans[i] = it[i]; } Array.Sort(ans, comp); using (StreamWriter fw = new StreamWriter(smfFile)) { // prints the tsin file header: fw.WriteLine("begin"); for (int i = 0; i < len; i++) { fw.WriteLine("v " + ans[i].toFile()); } int t = 0, i1 = -1, i2 = -1, i3 = -1; foreach (Triangle_dt curr in this.trianglesIterator()) { if (!curr.halfplane) { i1 = Array.BinarySearch(ans, curr.a, comp); i2 = Array.BinarySearch(ans, curr.b, comp); i3 = Array.BinarySearch(ans, curr.c, comp); if (i1 < 0 || i2 < 0 || i3 < 0) { throw new Exception("wrong triangulation inner bug - cant write as an SMF file!"); } fw.WriteLine("f " + (i1 + 1) + " " + (i2 + 1) + " " + (i3 + 1)); } } fw.WriteLine("end"); fw.Close(); } }
/** * creates a Delaunay Triangulation from all the points. Note: duplicated * points are ignored. */ public Delaunay_Triangulation(Point_dt[] ps) { _modCount = 0; _modCount2 = 0; _bb_min = null; _bb_max = null; this._vertices = new TreeSet <Point_dt>(Point_dt.getComparator()); _triangles = new List <Triangle_dt>(); allCollinear = true; for (int i = 0; ps != null && i < ps.Length && ps[i] != null; i++) { this.insertPoint(ps[i]); } // build grid points to make find faster gridPoints = new PointsGridDT(5, this); }