public static void Triangulate(TriangulationAlgorithm algorithm, Triangulable t) { //long time = System.nanoTime(); TriangulationContext tcx = GetFreeTcxContext(algorithm); tcx.Clear(); //step 1: (3.1) initialization tcx.PrepareTriangulation(t); //step 2: (3.4) sweeping Triangulate(tcx); ReleaseCtxContext(tcx); //logger.info( "Triangulation of {} points [{}ms]", tcx.getPoints().size(), ( System.nanoTime() - time ) / 1e6 ); }
public virtual void PrepareTriangulation(Triangulable t) { Triangulatable = t; TriangulationMode = t.TriangulationMode; t.Prepare(this); }
public override void PrepareTriangulation(Triangulable t) { //-------------------- //initialization phase: //all points are sorted regarding y coordinate, //regardless of whether they define an edge or not. //those points havingthe same y coordinates are also sorted //in the x direction. //Each point is associated with the information wheter nor not //it is the upper ending point of one or more edge e^i //-------------------- //the following creates 'initial triangle', //max bounds, //p1 and p2=> artificial points //------------------- //during the fininalization phase, //all triangles, having at least one vertex among the //artificial points, are erased. base.PrepareTriangulation(t); double xmax, xmin; double ymax, ymin; xmax = xmin = Points[0].X; ymax = ymin = Points[0].Y; // Calculate bounds. Should be combined with the sorting var tmp_points = this.Points; for (int i = tmp_points.Count - 1; i >= 0; --i) { var p = tmp_points[i]; if (p.X > xmax) { xmax = p.X; } if (p.X < xmin) { xmin = p.X; } if (p.Y > ymax) { ymax = p.Y; } if (p.Y < ymin) { ymin = p.Y; } } double deltaX = ALPHA * (xmax - xmin); double deltaY = ALPHA * (ymax - ymin); TriangulationPoint p1 = new TriangulationPoint(xmax + deltaX, ymin - deltaY); TriangulationPoint p2 = new TriangulationPoint(xmin - deltaX, ymin - deltaY); Head = p1; Tail = p2; //long time = System.nanoTime(); //Sort the points along y-axis Points.Sort(Compare); //logger.info( "Triangulation setup [{}ms]", ( System.nanoTime() - time ) / 1e6 ); }