/// <summary> /// Initializes a new instance of the <see cref="SimpleSmoother" /> class. /// </summary> /// <param name="factory">Voronoi object factory.</param> /// <param name="predicates">Geometric predicates implementation.</param> public SimpleSmoother(IVoronoiFactory factory, IPredicates predicates) { this.factory = factory; this.predicates = predicates; this.options = new ConstraintOptions() { ConformingDelaunay = true }; }
private double Step(Mesh mesh, IVoronoiFactory factory, IPredicates predicates) { var voronoi = new BoundedVoronoi(mesh, factory, predicates); double x, y, maxDistanceMoved = 0; foreach (var face in voronoi.Faces) { if (face.generator.label == 0) { Centroid(face, out x, out y); double xShift = face.generator.x - x, yShift = face.generator.y - y, distanceMoved = Math.Sqrt(xShift * xShift + yShift * yShift); if (distanceMoved > maxDistanceMoved) { maxDistanceMoved = distanceMoved; } face.generator.x = x; face.generator.y = y; } } // The maximum distance moved from any site. return(maxDistanceMoved); }
/// <summary> /// Initializes a new instance of the <see cref="SimpleSmoother" /> class. /// </summary> /// <param name="factory">Voronoi object factory.</param> /// <param name="config">Configuration.</param> public SimpleSmoother(IVoronoiFactory factory, Configuration config) { this.factory = factory; this.config = config; this.options = new ConstraintOptions() { ConformingDelaunay = true }; }
/// <summary> /// Generate the Voronoi diagram from given triangle mesh.. /// </summary> /// <param name="mesh"></param> /// <param name="bounded"></param> protected void Generate(Mesh mesh) { mesh.Renumber(); base.edges = new List <HalfEdge>(); this.rays = new List <HalfEdge>(); // Allocate space for Voronoi diagram. var vertices = new Vertex[mesh.triangles.Count + mesh.hullsize]; var faces = new Face[mesh.vertices.Count]; if (factory == null) { factory = new DefaultVoronoiFactory(); } factory.Initialize(vertices.Length, 2 * mesh.NumberOfEdges, faces.Length); // Compute triangles circumcenters. var map = ComputeVertices(mesh, vertices); // Create all Voronoi faces. foreach (var vertex in mesh.vertices.Values) { faces[vertex.id] = factory.CreateFace(vertex); } ComputeEdges(mesh, vertices, faces, map); // At this point all edges are computed, but the (edge.next) pointers aren't set. ConnectEdges(map); base.vertices = new List <Vertex>(vertices); base.faces = new List <Face>(faces); }
/// <summary> /// Generate the Voronoi diagram from given triangle mesh.. /// </summary> /// <param name="mesh"></param> /// <param name="bounded"></param> protected void Generate(Mesh mesh) { mesh.Renumber(); base.edges = new List<HalfEdge>(); this.rays = new List<HalfEdge>(); // Allocate space for Voronoi diagram. var vertices = new Vertex[mesh.triangles.Count + mesh.hullsize]; var faces = new Face[mesh.vertices.Count]; if (factory == null) { factory = new DefaultVoronoiFactory(); } factory.Initialize(vertices.Length, 2 * mesh.NumberOfEdges, faces.Length); // Compute triangles circumcenters. var map = ComputeVertices(mesh, vertices); // Create all Voronoi faces. foreach (var vertex in mesh.vertices.Values) { faces[vertex.id] = factory.CreateFace(vertex); } ComputeEdges(mesh, vertices, faces, map); // At this point all edges are computed, but the (edge.next) pointers aren't set. ConnectEdges(map); base.vertices = new List<Vertex>(vertices); base.faces = new List<Face>(faces); }
public StandardVoronoi(TriangleNetMesh triangleNetMesh, Rectangle box, IVoronoiFactory factory, IPredicates predicates) : base(triangleNetMesh, factory, predicates, true) { // We assume the box to be at least as large as the mesh. box.Expand(triangleNetMesh.bounds); // We explicitly told the base constructor to call the Generate method, so // at this point the basic Voronoi diagram is already created. PostProcess(box); }
public StandardVoronoi(Mesh mesh, Rectangle box, IVoronoiFactory factory, IPredicates predicates) : base(mesh, factory, predicates, true) { // We assume the box to be at least as large as the mesh. box.Expand(mesh.bounds); // We explicitly told the base constructor to call the Generate method, so // at this point the basic Voronoi diagram is already created. PostProcess(box); }
/// <summary> /// Initializes a new instance of the <see cref="VoronoiBase" /> class. /// </summary> /// <param name="mesh">Triangle mesh.</param> /// <param name="factory">Voronoi object factory.</param> /// <param name="predicates">Geometric predicates implementation.</param> /// <param name="generate">If set to true, the constuctor will call the Generate /// method, which builds the Voronoi diagram.</param> protected VoronoiBase(Mesh mesh, IVoronoiFactory factory, IPredicates predicates, bool generate) : base(false) { this.factory = factory; this.predicates = predicates; if (generate) { Generate(mesh); } }
/// <summary> /// Initializes a new instance of the <see cref="VoronoiBase" /> class. /// </summary> /// <param name="mesh">Triangle mesh.</param> /// <param name="factory">Voronoi object factory.</param> /// <param name="predicates">Geometric predicates implementation.</param> /// <param name="generate">If set to true, the constructor will call the Generate /// method, which builds the Voronoi diagram.</param> protected VoronoiBase(Mesh mesh, IVoronoiFactory factory, IPredicates predicates, bool generate) : base(false) { this.factory = factory; this.predicates = predicates; if (generate) { Generate(mesh); } }
/// <summary> /// Initializes a new instance of the <see cref="SimpleSmoother" /> class. /// </summary> public SimpleSmoother(IVoronoiFactory factory) { this.factory = factory; this.pool = new TrianglePool(); this.config = new Configuration( () => RobustPredicates.Default, () => pool.Restart()); this.options = new ConstraintOptions() { ConformingDelaunay = true }; }
public BoundedVoronoi(Mesh mesh, IVoronoiFactory factory, IPredicates predicates) : base(mesh, factory, predicates, true) { // We explicitly told the base constructor to call the Generate method, so // at this point the basic Voronoi diagram is already created. offset = base.vertices.Count; // Each vertex of the hull will be part of a Voronoi cell. base.vertices.Capacity = offset + mesh.hullsize; // Create bounded Voronoi diagram. PostProcess(); ResolveBoundaryEdges(); }
/// <summary> /// Initializes a new instance of the <see cref="StandardVoronoi" /> class. /// </summary> /// <param name="mesh">The mesh.</param> /// <param name="factory"></param> /// <param name="predicates"></param> public BoundedVoronoi(Mesh mesh, IVoronoiFactory factory, IPredicates predicates) : base(mesh, factory, predicates, true) { // We explicitly told the base constructor to call the Generate method, so // at this point the basic Voronoi diagram is already created. offset = base.vertices.Count; // Each vertex of the hull will be part of a Voronoi cell. base.vertices.Capacity = offset + mesh.hullsize; // Create bounded Voronoi diagram. PostProcess(); ResolveBoundaryEdges(); }
/// <summary> /// Generate the Voronoi diagram from given triangle mesh.. /// </summary> /// <param name="mesh"></param> protected void Generate(Mesh mesh) { base.edges = new List <HalfEdge>(); this.rays = new List <HalfEdge>(); // Undead vertices cannot be Voronoi cell generators. int count = mesh.vertices.Count - mesh.undeads; // Allocate space for Voronoi diagram. var vertices = new Vertex[mesh.triangles.Count + mesh.hullsize]; var faces = new Face[count]; if (factory == null) { factory = new DefaultVoronoiFactory(); } factory.Initialize(vertices.Length, 2 * mesh.NumberOfEdges, faces.Length); // Compute triangles circumcenters. var map = ComputeVertices(mesh, vertices); // Ensure linear numbering of vertices (excluding undeads). int vid = 0; // Create all Voronoi faces, skipping undead vertices. foreach (var vertex in mesh.vertices.Values) { if (vertex.type == VertexType.UndeadVertex) { vertex.id = count++; } else { vertex.id = vid++; faces[vertex.id] = factory.CreateFace(vertex); } } ComputeEdges(mesh, vertices, faces, map); // At this point all edges are computed, but the (edge.next) pointers aren't set. ConnectEdges(map); base.vertices = new List <Vertex>(vertices); base.faces = new List <Face>(faces); }
private void Step(Mesh mesh, IVoronoiFactory factory, IPredicates predicates) { var voronoi = new BoundedVoronoi(mesh, factory, predicates); double x, y; foreach (var face in voronoi.Faces) { if (face.generator.label == 0) { Centroid(face, out x, out y); face.generator.x = x; face.generator.y = y; } } }
private void Step(Mesh mesh, IVoronoiFactory factory) { var voronoi = new BoundedVoronoi(mesh, factory, predicates); double x, y; foreach (var face in voronoi.Faces) { if (face.generator.label == 0) { Centroid(face, out x, out y); face.generator.x = x; face.generator.y = y; } } }