Triangle.Rendering documentation and minor updates.

This commit is contained in:
wo80
2022-03-01 00:52:52 +01:00
parent e8ca95960f
commit e35b465330
14 changed files with 321 additions and 238 deletions
@@ -44,12 +44,10 @@ namespace MeshExplorer.Topology
{
renderer = new TopologyRenderer(mesh);
zoom = new Projection(this.ClientRectangle);
zoom = new Projection(ClientRectangle);
//zoom.ClipMargin = 10.0f;
var b = mesh.Bounds;
zoom.Initialize(new BoundingBox((float)b.Left, (float)b.Right,
(float)b.Bottom, (float)b.Top));
zoom.Initialize(mesh.Bounds);
InitializeBuffer();
+16 -16
View File
@@ -12,12 +12,12 @@ namespace TriangleNet.Rendering
public float Width
{
get { return this.Right - this.Left; }
get { return Right - Left; }
}
public float Height
{
get { return this.Top - this.Bottom; }
get { return Top - Bottom; }
}
public BoundingBox()
@@ -27,20 +27,20 @@ namespace TriangleNet.Rendering
public BoundingBox(float left, float right, float bottom, float top)
{
this.Left = left;
this.Right = right;
this.Bottom = bottom;
this.Top = top;
Left = left;
Right = right;
Bottom = bottom;
Top = top;
}
public void Update(Point pt)
{
this.Update(pt.X, pt.Y);
Update(pt.X, pt.Y);
}
public void Update(PointF pt)
{
this.Update(pt.X, pt.Y);
Update(pt.X, pt.Y);
}
public void Update(double x, double y)
@@ -51,18 +51,18 @@ namespace TriangleNet.Rendering
public void Update(float x, float y)
{
// Update bounding box
if (this.Left > x) this.Left = x;
if (this.Right < x) this.Right = x;
if (this.Bottom > y) this.Bottom = y;
if (this.Top < y) this.Top = y;
if (Left > x) Left = x;
if (Right < x) Right = x;
if (Bottom > y) Bottom = y;
if (Top < y) Top = y;
}
public void Reset()
{
this.Left = float.MaxValue;
this.Right = -float.MaxValue;
this.Bottom = float.MaxValue;
this.Top = -float.MaxValue;
Left = float.MaxValue;
Right = -float.MaxValue;
Bottom = float.MaxValue;
Top = -float.MaxValue;
}
}
}
+10 -19
View File
@@ -5,11 +5,10 @@ namespace TriangleNet.Rendering.Buffer
{
protected T[] data;
protected int size;
public BufferBase(int capacity, int size)
: this(new T[capacity], size)
{
this.data = new T[capacity];
this.size = size;
}
public BufferBase(T[] data, int size)
@@ -18,24 +17,16 @@ namespace TriangleNet.Rendering.Buffer
this.size = size;
}
public T[] Data
{
get { return data; }
}
/// <inheritdoc/>
public T[] Data => data;
public int Count
{
get { return data == null ? 0 : data.Length; }
}
/// <inheritdoc/>
public int Count => data == null ? 0 : data.Length;
public abstract int Size
{
get;
}
/// <inheritdoc/>
public abstract int Size { get; }
public abstract BufferTarget Target
{
get;
}
/// <inheritdoc/>
public abstract BufferTarget Target { get; }
}
}
+14 -9
View File
@@ -1,29 +1,34 @@
namespace TriangleNet.Rendering.Buffer
{
using System;
using System.Drawing;
public class ColorBuffer : BufferBase<Color>
{
/// <summary>
/// Initializes a new instance of the <see cref="ColorBuffer"/> class.
/// </summary>
/// <param name="capacity">The buffer capacity.</param>
/// <param name="size">The size of one element in the buffer (i.e. 2 for 2D points)</param>
public ColorBuffer(int capacity, int size)
: base(capacity, size)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ColorBuffer"/> class.
/// </summary>
/// <param name="data">The buffer data.</param>
/// <param name="size">The size of one element in the buffer (i.e. 2 for 2D points)</param>
public ColorBuffer(Color[] data, int size)
: base(data, size)
{
}
public override int Size
{
get { return 1; }
}
/// <inheritdoc/>
public override int Size => 1;
public override BufferTarget Target
{
get { return BufferTarget.ColorBuffer; }
}
/// <inheritdoc/>
public override BufferTarget Target => BufferTarget.ColorBuffer;
}
}
+14 -12
View File
@@ -3,28 +3,30 @@ namespace TriangleNet.Rendering.Buffer
{
public class IndexBuffer : BufferBase<int>
{
/// <summary>
/// Initializes a new instance of the <see cref="IndexBuffer"/> class.
/// </summary>
/// <param name="capacity">The buffer capacity.</param>
/// <param name="size">The size of one element in the buffer (i.e. 2 for 2D points)</param>
public IndexBuffer(int capacity, int size)
: base(capacity, size)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="IndexBuffer"/> class.
/// </summary>
/// <param name="data">The buffer data.</param>
/// <param name="size">The size of one element in the buffer (i.e. 2 for 2D points)</param>
public IndexBuffer(int[] data, int size)
: base(data, size)
{
}
/// <summary>
/// Gets the number of indices for one element (i.e. 2 for segments
/// or 3 for triangles).
/// </summary>
public override int Size
{
get { return size; }
}
/// <inheritdoc/>
public override int Size => size;
public override BufferTarget Target
{
get { return BufferTarget.IndexBuffer; }
}
/// <inheritdoc/>
public override BufferTarget Target => BufferTarget.IndexBuffer;
}
}
+14 -12
View File
@@ -3,28 +3,30 @@ namespace TriangleNet.Rendering.Buffer
{
public class VertexBuffer : BufferBase<float>
{
/// <summary>
/// Initializes a new instance of the <see cref="VertexBuffer"/> class.
/// </summary>
/// <param name="capacity">The buffer capacity.</param>
/// <param name="size">The size of one element in the buffer (i.e. 2 for 2D points)</param>
public VertexBuffer(int capacity, int size = 2)
: base(capacity, size)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="VertexBuffer"/> class.
/// </summary>
/// <param name="data">The buffer data.</param>
/// <param name="size">The size of one element in the buffer (i.e. 2 for 2D points)</param>
public VertexBuffer(float[] data, int size = 2)
: base(data, size)
{
}
/// <summary>
/// Gets the number of coordinates of one vertex in the buffer (i.e. 2 for
/// 2D points or 3D points).
/// </summary>
public override int Size
{
get { return size; }
}
/// <inheritdoc/>
public override int Size => size;
public override BufferTarget Target
{
get { return BufferTarget.VertexBuffer; }
}
/// <inheritdoc/>
public override BufferTarget Target => BufferTarget.VertexBuffer;
}
}
+3 -3
View File
@@ -98,7 +98,7 @@ namespace TriangleNet.Rendering
public Dictionary<int, Color> ColorDictionary { get; set; }
/// <summary>
/// Gets or sets a colormap which is used for function plotting.
/// Gets or sets a colormap used for function plotting.
/// </summary>
public ColorMap ColorMap { get; set; }
@@ -128,10 +128,10 @@ namespace TriangleNet.Rendering
keys[i] = i;
}
CreateColorDictionary(keys, length);
CreateColorDictionary(keys);
}
public void CreateColorDictionary(IEnumerable<int> keys, int length)
public void CreateColorDictionary(IEnumerable<int> keys)
{
this.ColorDictionary = new Dictionary<int, Color>();
+1 -1
View File
@@ -264,7 +264,7 @@ namespace TriangleNet.Rendering.GDI
if (colors.ColorDictionary == null)
{
colors.CreateColorDictionary(regions, regions.Count);
colors.CreateColorDictionary(regions);
}
return labels;
+58 -3
View File
@@ -4,31 +4,86 @@ namespace TriangleNet.Rendering
using System.Collections.Generic;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Voronoi.Legacy;
public interface IRenderContext
{
/// <summary>
/// Gets the color manager.
/// </summary>
ColorManager ColorManager { get; }
BoundingBox Bounds { get; }
/// <summary>
/// Gets the list of <see cref="IRenderLayer"/>s.
/// </summary>
IList<IRenderLayer> RenderLayers { get; }
/// <summary>
/// Gets the <see cref="Projection"/>.
/// </summary>
Projection Zoom { get; }
/// <summary>
/// Gets the <see cref="IMesh"/>.
/// </summary>
IMesh Mesh { get; }
/// <summary>
/// Gets a value indicating whether the context has data to render.
/// </summary>
bool HasData { get; }
/// <summary>
/// Add polygon data.
/// </summary>
/// <param name="data"></param>
void Add(IPolygon data);
/// <summary>
/// Add mesh data.
/// </summary>
/// <param name="data"></param>
/// <param name="reset"></param>
void Add(IMesh data, bool reset);
/// <summary>
/// Add edge data (used for Voronoi).
/// </summary>
/// <param name="points"></param>
/// <param name="edges"></param>
/// <param name="reset"></param>
void Add(ICollection<Point> points, IEnumerable<IEdge> edges, bool reset);
/// <summary>
/// Add mesh function values <c>z=f(x,y)</c>.
/// </summary>
/// <param name="values"></param>
void Add(float[] values);
/// <summary>
/// Add mesh partitioning data.
/// </summary>
/// <param name="partition"></param>
void Add(int[] partition);
/// <summary>
/// Enable or disable a layer for rendering.
/// </summary>
/// <param name="layer">The layer index.</param>
/// <param name="enabled">If true, enable layer, otherwise disable.</param>
/// <remarks>
/// 0 = mesh (filled)
/// 1 = mesh (wireframe)
/// 2 = polygon
/// 3 = points
/// 4 = voronoi overlay
/// 5 = vector field
/// 6 = contour lines
/// </remarks>
void Enable(int layer, bool enabled);
/// <summary>
/// Clear data from all layers.
/// </summary>
void Clear();
}
}
+100 -5
View File
@@ -9,35 +9,130 @@ namespace TriangleNet.Rendering
using Color = System.Drawing.Color;
/// <summary>
/// Interface for managing the data of a render layer.
/// </summary>
public interface IRenderLayer
{
/// <summary>
/// Gets the number of points in the point buffer.
/// </summary>
int Count { get; }
/// <summary>
/// Gets the points buffer.
/// </summary>
IBuffer<float> Points { get; }
/// <summary>
/// Gets the indices buffer.
/// </summary>
IBuffer<int> Indices { get; }
/// <summary>
/// Gets or sets a value indicating whether the layer is enabled.
/// </summary>
bool IsEnabled { get; set; }
/// <summary>
/// Indicates whether this layer contains data to render.
/// </summary>
/// <returns>Returns true, if the points buffer contains data.</returns>
bool IsEmpty();
/// <summary>
/// Resets this layer to an empty state.
/// </summary>
/// <param name="clear">If true, all buffers will be set to <c>null</c>.</param>
void Reset(bool clear);
// TODO: add boolean: reset
BoundingBox SetPoints(IBuffer<float> buffer);
BoundingBox SetPoints(IPolygon poly);
BoundingBox SetPoints(IMesh mesh);
BoundingBox SetPoints(ICollection<Point> points);
/// <summary>
/// Replaces the current points with the given buffer.
/// </summary>
/// <param name="buffer">The new points buffer.</param>
void SetPoints(IBuffer<float> buffer);
/// <summary>
/// Copy the points of the given <see cref="IPolygon"/> to the layers point buffer.
/// </summary>
/// <param name="poly">The polygon to render.</param>
void SetPoints(IPolygon poly);
/// <summary>
/// Copy the points of the given <see cref="IMesh"/> to the layers point buffer.
/// </summary>
/// <param name="mesh">The mesh to render.</param>
void SetPoints(IMesh mesh);
/// <summary>
/// Copy the points of the given collection to the layers point buffer.
/// </summary>
/// <param name="points">The point set to render.</param>
void SetPoints(ICollection<Point> points);
/// <summary>
/// Copy the segment indices of the given polygon to the layers index buffer.
/// </summary>
/// <param name="poly">The polygon to render.</param>
void SetPolygon(IPolygon poly);
/// <summary>
/// Copy the segment indices of the given mesh to the layers index buffer.
/// </summary>
/// <param name="mesh">The mesh to render.</param>
void SetPolygon(IMesh mesh);
/// <summary>
/// Copy the indices of the given mesh triangles to the layers index buffer.
/// </summary>
/// <param name="mesh">The mesh to render.</param>
/// <param name="elements">If true, all triangle indices are copied. Otherwise,
/// only edge indices are copied.</param>
/// <remarks>
/// Use <c>elements = true</c> for layers rendering filled triangles (3 indices per buffer item).
/// Use <c>elements = false</c> if only edges are rendered (wireframe, 2 indices per buffer item).
/// </remarks>
void SetMesh(IMesh mesh, bool elements);
/// <summary>
/// Copy the indices of the given edges to the layers index buffer.
/// </summary>
/// <param name="edges">The edges to render.</param>
void SetMesh(IEnumerable<IEdge> edges);
#region Attached data (mesh partitioning and heat map rendering)
// TODO: better put these into a subclass.
// TODO: better put attached data into a subclass?
/// <summary>
/// Gets the mesh partition.
/// </summary>
/// <remarks>
/// Triangle <c>i</c> given by indices <c>[3 * i, 3 * i + 1, 3 * i + 2]</c>
/// belongs to <c>Partition[i]</c>.
/// </remarks>
IBuffer<int> Partition { get; }
/// <summary>
/// Gets the color attached to a point in the points buffer.
/// </summary>
IBuffer<Color> Colors { get; }
/// <summary>
/// Attach function values <c>z=f(x,y)</c> for all points <c>(x,y)</c> in the point buffer.
/// </summary>
/// <param name="values">The function values.</param>
/// <param name="colormap">The color map.</param>
void AttachLayerData(float[] values, ColorMap colormap);
/// <summary>
/// Attach partitioning data to each triangle in the index buffer.
/// </summary>
/// <param name="partition">The mesh partition.</param>
void AttachLayerData(int[] partition);
#endregion
}
}
+13 -10
View File
@@ -44,10 +44,10 @@ namespace TriangleNet.Rendering
public float ClipMargin { get; set; }
// The y-direction of windows screen coordinates is upside down,
// so inverY must be set to true.
bool invertY = false;
// so invertY should be set to true.
bool invertY;
int maxZoomLevel = 100;
const int maxZoomLevel = 100;
public Projection(Rectangle screen, bool invertY = true)
{
@@ -66,26 +66,29 @@ namespace TriangleNet.Rendering
/// Inititialize the projection.
/// </summary>
/// <param name="world">The world that should be transformed to screen coordinates.</param>
public void Initialize(BoundingBox world)
public void Initialize(Geometry.Rectangle world)
{
this.Level = 1;
float width = (float)world.Width;
float height = (float)world.Height;
// Add a margin so there's some space around the border
float worldMargin = (world.Width < world.Height) ? world.Height * 0.05f : world.Width * 0.05f;
float worldMargin = (width < height) ? height * 0.05f : width * 0.05f;
// Get the initial viewport (complete mesh centered on the screen)
float screenRatio = screen.Width / (float)screen.Height;
float worldRatio = world.Width / world.Height;
float worldRatio = width / height;
float scale = (world.Width + worldMargin) / screen.Width;
float scale = (width + worldMargin) / screen.Width;
if (screenRatio > worldRatio)
{
scale = (world.Height + worldMargin) / screen.Height;
scale = (height + worldMargin) / screen.Height;
}
float centerX = world.Left + world.Width / 2;
float centerY = world.Bottom + world.Height / 2;
float centerX = (float)world.Left + width / 2;
float centerY = (float)world.Bottom + height / 2;
// TODO: Add initial margin
this.Viewport = new RectangleF(centerX - screen.Width * scale / 2,
+30 -37
View File
@@ -5,7 +5,6 @@ namespace TriangleNet.Rendering
using System.Linq;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Voronoi.Legacy;
/// <summary>
/// The RenderContext class brings all the rendering parts together.
@@ -13,16 +12,14 @@ namespace TriangleNet.Rendering
public class RenderContext : IRenderContext
{
private ColorManager colorManager;
private BoundingBox bounds;
private Projection zoom;
private Rectangle bounds;
private IMesh mesh;
private List<IRenderLayer> renderLayers;
public RenderContext(Projection zoom, ColorManager colorManager)
{
bounds = new BoundingBox();
renderLayers = new List<IRenderLayer>(6);
renderLayers.Add(new RenderLayer()); // 0 = mesh (filled)
@@ -41,39 +38,22 @@ namespace TriangleNet.Rendering
this.colorManager = colorManager;
}
public ColorManager ColorManager
{
get { return colorManager; }
}
/// <inheritdoc />
public ColorManager ColorManager => colorManager;
public BoundingBox Bounds
{
get { return bounds; }
}
/// <inheritdoc />
public IList<IRenderLayer> RenderLayers => renderLayers;
public IList<IRenderLayer> RenderLayers
{
get { return renderLayers; }
}
/// <inheritdoc />
public Projection Zoom => zoom;
public Projection Zoom
{
get { return zoom; }
}
/// <inheritdoc />
public IMesh Mesh => mesh;
public IMesh Mesh
{
get { return mesh; }
}
public bool HasData
{
get
{
return renderLayers.Any(layer => !layer.IsEmpty());
}
}
/// <inheritdoc />
public bool HasData => renderLayers.Any(layer => !layer.IsEmpty());
/// <inheritdoc />
public void Add(IPolygon data)
{
foreach (var layer in RenderLayers)
@@ -92,13 +72,16 @@ namespace TriangleNet.Rendering
p.ID = i++;
}
this.bounds = RenderLayers[2].SetPoints(data);
this.zoom.Initialize(bounds);
bounds = data.Bounds();
zoom.Initialize(bounds);
RenderLayers[2].SetPoints(data);
RenderLayers[2].SetPolygon(data);
RenderLayers[3].SetPoints(RenderLayers[2].Points);
}
/// <inheritdoc />
public void Add(IMesh data, bool reset)
{
foreach (var layer in RenderLayers)
@@ -110,11 +93,12 @@ namespace TriangleNet.Rendering
RenderLayers[4].Reset(true);
// Save reference to mesh.
this.mesh = data;
mesh = data;
bounds = data.Bounds;
this.bounds = RenderLayers[1].SetPoints(data);
this.zoom.Initialize(bounds);
zoom.Initialize(bounds);
RenderLayers[1].SetPoints(data);
RenderLayers[1].SetMesh(data, false);
RenderLayers[2].SetPoints(RenderLayers[1].Points);
@@ -123,6 +107,7 @@ namespace TriangleNet.Rendering
RenderLayers[3].SetPoints(RenderLayers[1].Points);
}
/// <inheritdoc />
public void Add(ICollection<Point> points, IEnumerable<IEdge> edges, bool reset)
{
RenderLayers[4].SetPoints(points);
@@ -130,6 +115,7 @@ namespace TriangleNet.Rendering
RenderLayers[4].IsEnabled = true;
}
/// <inheritdoc />
public void Add(float[] data)
{
// Add function values for filled mesh.
@@ -140,6 +126,7 @@ namespace TriangleNet.Rendering
RenderLayers[0].IsEnabled = true;
}
/// <inheritdoc />
public void Add(int[] data)
{
// Add partition data for filled mesh.
@@ -150,13 +137,19 @@ namespace TriangleNet.Rendering
RenderLayers[0].IsEnabled = true;
}
/// <inheritdoc />
public void Enable(int layer, bool enabled)
{
renderLayers[layer].IsEnabled = enabled;
}
/// <inheritdoc />
public void Clear()
{
foreach (var layer in RenderLayers)
{
layer.Reset(true);
}
}
}
}
+36 -49
View File
@@ -24,38 +24,31 @@ namespace TriangleNet.Rendering
this.IsEnabled = false;
}
public int Count
{
get { return count; }
}
/// <inheritdoc />
public int Count => count;
public IBuffer<float> Points
{
get { return points; }
}
/// <inheritdoc />
public IBuffer<float> Points => points;
public IBuffer<int> Indices
{
get { return indices; }
}
/// <inheritdoc />
public IBuffer<int> Indices => indices;
public IBuffer<int> Partition
{
get { return partition; }
}
/// <inheritdoc />
public IBuffer<int> Partition => partition;
public IBuffer<Color> Colors
{
get { return colors; }
}
/// <inheritdoc />
public IBuffer<Color> Colors => colors;
/// <inheritdoc />
public bool IsEnabled { get; set; }
/// <inheritdoc />
public bool IsEmpty()
{
return (points == null || points.Count == 0);
}
/// <inheritdoc />
public void Reset(bool clear)
{
if (clear)
@@ -69,12 +62,13 @@ namespace TriangleNet.Rendering
colors = null;
}
public BoundingBox SetPoints(IBuffer<float> buffer)
/// <inheritdoc />
public void SetPoints(IBuffer<float> buffer)
{
BoundingBox bounds = new BoundingBox();
if (points != null && points.Count < buffer.Count)
{
// NOTE: we keep the old size to be able to render new Steiner
// points in a different color than existing points.
count = points.Count / points.Size;
}
else
@@ -82,41 +76,31 @@ namespace TriangleNet.Rendering
count = buffer.Count / buffer.Size;
}
this.points = buffer;
return bounds;
points = buffer;
}
public BoundingBox SetPoints(IPolygon poly)
/// <inheritdoc />
public void SetPoints(IPolygon poly)
{
BoundingBox bounds = new BoundingBox();
points = BufferHelper.CreateVertexBuffer(poly.Points, ref bounds);
points = BufferHelper.CreateVertexBuffer(poly.Points);
count = points.Count / points.Size;
return bounds;
}
public BoundingBox SetPoints(IMesh mesh)
/// <inheritdoc />
public void SetPoints(IMesh mesh)
{
BoundingBox bounds = new BoundingBox();
points = BufferHelper.CreateVertexBuffer(mesh.Vertices, ref bounds);
points = BufferHelper.CreateVertexBuffer(mesh.Vertices);
count = points.Count / points.Size;
return bounds;
}
public BoundingBox SetPoints(ICollection<Point> vertices)
/// <inheritdoc />
public void SetPoints(ICollection<Point> vertices)
{
BoundingBox bounds = new BoundingBox();
points = BufferHelper.CreateVertexBuffer(vertices, ref bounds);
points = BufferHelper.CreateVertexBuffer(vertices);
count = points.Count / points.Size;
return bounds;
}
/// <inheritdoc />
public void SetPolygon(IPolygon poly)
{
indices = BufferHelper.CreateIndexBuffer(poly.Segments, 2);
@@ -127,11 +111,13 @@ namespace TriangleNet.Rendering
indices = BufferHelper.CreateIndexBuffer(mesh.Segments, 2);
}
/// <inheritdoc />
public void SetMesh(IEnumerable<IEdge> edges)
{
indices = BufferHelper.CreateIndexBuffer(edges, 2);
}
/// <inheritdoc />
public void SetMesh(IMesh mesh, bool elements)
{
mesh.Renumber();
@@ -147,13 +133,11 @@ namespace TriangleNet.Rendering
}
}
// TODO: remove colormap argument
/// <inheritdoc />
public void AttachLayerData(float[] values, ColorMap colormap)
{
int length = values.Length;
Color[] data = new Color[length];
double min = double.MaxValue;
double max = double.MinValue;
@@ -171,14 +155,17 @@ namespace TriangleNet.Rendering
}
}
var colorData = new Color[length];
for (int i = 0; i < length; i++)
{
data[i] = colormap.GetColor(values[i], min, max);
colorData[i] = colormap.GetColor(values[i], min, max);
}
colors = new ColorBuffer(data, 1);
colors = new ColorBuffer(colorData, 1);
}
/// <inheritdoc />
public void AttachLayerData(int[] partition)
{
this.partition = new IndexBuffer(partition, 1);
+10 -58
View File
@@ -5,43 +5,14 @@ namespace TriangleNet.Rendering.Util
using TriangleNet.Topology;
using TriangleNet.Geometry;
using TriangleNet.Rendering.Buffer;
using System.Linq;
internal static class BufferHelper
{
public static IBuffer<float> CreateVertexBuffer(double[] points, ref BoundingBox bounds)
{
int length = points.Length;
var buffer = new VertexBuffer(length);
bounds.Reset();
var data = buffer.Data;
float x, y;
length = length >> 1;
for (int i = 0; i < length; i++)
{
x = (float)points[2 * i];
y = (float)points[2 * i + 1];
data[2 * i] = x;
data[2 * i + 1] = y;
bounds.Update(x, y);
}
return buffer as IBuffer<float>;
}
public static IBuffer<float> CreateVertexBuffer(ICollection<Point> points, ref BoundingBox bounds)
public static IBuffer<float> CreateVertexBuffer(ICollection<Point> points)
{
var buffer = new VertexBuffer(2 * points.Count);
bounds.Reset();
var data = buffer.Data;
float x, y;
@@ -56,20 +27,16 @@ namespace TriangleNet.Rendering.Util
data[2 * i] = x;
data[2 * i + 1] = y;
bounds.Update(x, y);
i++;
}
return buffer as IBuffer<float>;
return buffer;
}
public static IBuffer<float> CreateVertexBuffer(ICollection<Vertex> points, ref BoundingBox bounds)
public static IBuffer<float> CreateVertexBuffer(ICollection<Vertex> points)
{
var buffer = new VertexBuffer(2 * points.Count);
bounds.Reset();
var data = buffer.Data;
int i = 0;
@@ -79,23 +46,21 @@ namespace TriangleNet.Rendering.Util
data[2 * i] = (float)p.X;
data[2 * i + 1] = (float)p.Y;
bounds.Update(p.X, p.Y);
i++;
}
return buffer as IBuffer<float>;
return buffer;
}
public static IBuffer<int> CreateIndexBuffer(IList<IEdge> segments, int size)
public static IBuffer<int> CreateIndexBuffer(IEnumerable<IEdge> edges, int size)
{
var buffer = new IndexBuffer(size * segments.Count, size);
var buffer = new IndexBuffer(size * edges.Count(), size);
var data = buffer.Data;
int i = 0;
foreach (var e in segments)
foreach (var e in edges)
{
data[size * i + 0] = e.P0;
data[size * i + 1] = e.P1;
@@ -103,20 +68,7 @@ namespace TriangleNet.Rendering.Util
i++;
}
return buffer as IBuffer<int>;
}
public static IBuffer<int> CreateIndexBuffer(IEnumerable<IEdge> edges, int size)
{
var data = new List<int>();
foreach (var e in edges)
{
data.Add(e.P0);
data.Add(e.P1);
}
return new IndexBuffer(data.ToArray(), size) as IBuffer<int>;
return buffer;
}
public static IBuffer<int> CreateIndexBuffer(ICollection<Triangle> elements, int size)
@@ -136,7 +88,7 @@ namespace TriangleNet.Rendering.Util
i++;
}
return buffer as IBuffer<int>;
return buffer;
}
}
}