diff --git a/src/MeshExplorer/Topology/TopologyRenderControl.cs b/src/MeshExplorer/Topology/TopologyRenderControl.cs
index 0ce864b..5818118 100644
--- a/src/MeshExplorer/Topology/TopologyRenderControl.cs
+++ b/src/MeshExplorer/Topology/TopologyRenderControl.cs
@@ -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();
diff --git a/src/Triangle.Rendering/BoundingBox.cs b/src/Triangle.Rendering/BoundingBox.cs
index 0fe8d0e..41a5d0b 100644
--- a/src/Triangle.Rendering/BoundingBox.cs
+++ b/src/Triangle.Rendering/BoundingBox.cs
@@ -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;
}
}
}
diff --git a/src/Triangle.Rendering/Buffer/BufferBase.cs b/src/Triangle.Rendering/Buffer/BufferBase.cs
index 65fb23c..fe14212 100644
--- a/src/Triangle.Rendering/Buffer/BufferBase.cs
+++ b/src/Triangle.Rendering/Buffer/BufferBase.cs
@@ -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; }
- }
+ ///
+ public T[] Data => data;
- public int Count
- {
- get { return data == null ? 0 : data.Length; }
- }
+ ///
+ public int Count => data == null ? 0 : data.Length;
- public abstract int Size
- {
- get;
- }
+ ///
+ public abstract int Size { get; }
- public abstract BufferTarget Target
- {
- get;
- }
+ ///
+ public abstract BufferTarget Target { get; }
}
}
diff --git a/src/Triangle.Rendering/Buffer/ColorBuffer.cs b/src/Triangle.Rendering/Buffer/ColorBuffer.cs
index 8919033..e074f1e 100644
--- a/src/Triangle.Rendering/Buffer/ColorBuffer.cs
+++ b/src/Triangle.Rendering/Buffer/ColorBuffer.cs
@@ -1,29 +1,34 @@
namespace TriangleNet.Rendering.Buffer
{
- using System;
using System.Drawing;
public class ColorBuffer : BufferBase
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The buffer capacity.
+ /// The size of one element in the buffer (i.e. 2 for 2D points)
public ColorBuffer(int capacity, int size)
: base(capacity, size)
{
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The buffer data.
+ /// The size of one element in the buffer (i.e. 2 for 2D points)
public ColorBuffer(Color[] data, int size)
: base(data, size)
{
}
- public override int Size
- {
- get { return 1; }
- }
+ ///
+ public override int Size => 1;
- public override BufferTarget Target
- {
- get { return BufferTarget.ColorBuffer; }
- }
+ ///
+ public override BufferTarget Target => BufferTarget.ColorBuffer;
}
}
diff --git a/src/Triangle.Rendering/Buffer/IndexBuffer.cs b/src/Triangle.Rendering/Buffer/IndexBuffer.cs
index 4a963d9..13a9975 100644
--- a/src/Triangle.Rendering/Buffer/IndexBuffer.cs
+++ b/src/Triangle.Rendering/Buffer/IndexBuffer.cs
@@ -3,28 +3,30 @@ namespace TriangleNet.Rendering.Buffer
{
public class IndexBuffer : BufferBase
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The buffer capacity.
+ /// The size of one element in the buffer (i.e. 2 for 2D points)
public IndexBuffer(int capacity, int size)
: base(capacity, size)
{
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The buffer data.
+ /// The size of one element in the buffer (i.e. 2 for 2D points)
public IndexBuffer(int[] data, int size)
: base(data, size)
{
}
- ///
- /// Gets the number of indices for one element (i.e. 2 for segments
- /// or 3 for triangles).
- ///
- public override int Size
- {
- get { return size; }
- }
+ ///
+ public override int Size => size;
- public override BufferTarget Target
- {
- get { return BufferTarget.IndexBuffer; }
- }
+ ///
+ public override BufferTarget Target => BufferTarget.IndexBuffer;
}
}
diff --git a/src/Triangle.Rendering/Buffer/VertexBuffer.cs b/src/Triangle.Rendering/Buffer/VertexBuffer.cs
index 86c111e..568a50a 100644
--- a/src/Triangle.Rendering/Buffer/VertexBuffer.cs
+++ b/src/Triangle.Rendering/Buffer/VertexBuffer.cs
@@ -3,28 +3,30 @@ namespace TriangleNet.Rendering.Buffer
{
public class VertexBuffer : BufferBase
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The buffer capacity.
+ /// The size of one element in the buffer (i.e. 2 for 2D points)
public VertexBuffer(int capacity, int size = 2)
: base(capacity, size)
{
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The buffer data.
+ /// The size of one element in the buffer (i.e. 2 for 2D points)
public VertexBuffer(float[] data, int size = 2)
: base(data, size)
{
}
- ///
- /// Gets the number of coordinates of one vertex in the buffer (i.e. 2 for
- /// 2D points or 3D points).
- ///
- public override int Size
- {
- get { return size; }
- }
+ ///
+ public override int Size => size;
- public override BufferTarget Target
- {
- get { return BufferTarget.VertexBuffer; }
- }
+ ///
+ public override BufferTarget Target => BufferTarget.VertexBuffer;
}
}
diff --git a/src/Triangle.Rendering/ColorManager.cs b/src/Triangle.Rendering/ColorManager.cs
index 302a14f..fd89305 100644
--- a/src/Triangle.Rendering/ColorManager.cs
+++ b/src/Triangle.Rendering/ColorManager.cs
@@ -98,7 +98,7 @@ namespace TriangleNet.Rendering
public Dictionary ColorDictionary { get; set; }
///
- /// Gets or sets a colormap which is used for function plotting.
+ /// Gets or sets a colormap used for function plotting.
///
public ColorMap ColorMap { get; set; }
@@ -128,10 +128,10 @@ namespace TriangleNet.Rendering
keys[i] = i;
}
- CreateColorDictionary(keys, length);
+ CreateColorDictionary(keys);
}
- public void CreateColorDictionary(IEnumerable keys, int length)
+ public void CreateColorDictionary(IEnumerable keys)
{
this.ColorDictionary = new Dictionary();
diff --git a/src/Triangle.Rendering/GDI/ImageRenderer.cs b/src/Triangle.Rendering/GDI/ImageRenderer.cs
index 9045fbd..78ffa7e 100644
--- a/src/Triangle.Rendering/GDI/ImageRenderer.cs
+++ b/src/Triangle.Rendering/GDI/ImageRenderer.cs
@@ -264,7 +264,7 @@ namespace TriangleNet.Rendering.GDI
if (colors.ColorDictionary == null)
{
- colors.CreateColorDictionary(regions, regions.Count);
+ colors.CreateColorDictionary(regions);
}
return labels;
diff --git a/src/Triangle.Rendering/IRenderContext.cs b/src/Triangle.Rendering/IRenderContext.cs
index 46f1036..c8c8b82 100644
--- a/src/Triangle.Rendering/IRenderContext.cs
+++ b/src/Triangle.Rendering/IRenderContext.cs
@@ -4,31 +4,86 @@ namespace TriangleNet.Rendering
using System.Collections.Generic;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
- using TriangleNet.Voronoi.Legacy;
public interface IRenderContext
{
+ ///
+ /// Gets the color manager.
+ ///
ColorManager ColorManager { get; }
- BoundingBox Bounds { get; }
-
+ ///
+ /// Gets the list of s.
+ ///
IList RenderLayers { get; }
+ ///
+ /// Gets the .
+ ///
Projection Zoom { get; }
+ ///
+ /// Gets the .
+ ///
IMesh Mesh { get; }
+ ///
+ /// Gets a value indicating whether the context has data to render.
+ ///
bool HasData { get; }
+ ///
+ /// Add polygon data.
+ ///
+ ///
void Add(IPolygon data);
+
+ ///
+ /// Add mesh data.
+ ///
+ ///
+ ///
void Add(IMesh data, bool reset);
+
+ ///
+ /// Add edge data (used for Voronoi).
+ ///
+ ///
+ ///
+ ///
void Add(ICollection points, IEnumerable edges, bool reset);
+ ///
+ /// Add mesh function values z=f(x,y).
+ ///
+ ///
void Add(float[] values);
+
+ ///
+ /// Add mesh partitioning data.
+ ///
+ ///
void Add(int[] partition);
+ ///
+ /// Enable or disable a layer for rendering.
+ ///
+ /// The layer index.
+ /// If true, enable layer, otherwise disable.
+ ///
+ /// 0 = mesh (filled)
+ /// 1 = mesh (wireframe)
+ /// 2 = polygon
+ /// 3 = points
+ /// 4 = voronoi overlay
+ /// 5 = vector field
+ /// 6 = contour lines
+ ///
void Enable(int layer, bool enabled);
+ ///
+ /// Clear data from all layers.
+ ///
void Clear();
}
}
diff --git a/src/Triangle.Rendering/IRenderLayer.cs b/src/Triangle.Rendering/IRenderLayer.cs
index a1785ad..b672356 100644
--- a/src/Triangle.Rendering/IRenderLayer.cs
+++ b/src/Triangle.Rendering/IRenderLayer.cs
@@ -9,35 +9,130 @@ namespace TriangleNet.Rendering
using Color = System.Drawing.Color;
+ ///
+ /// Interface for managing the data of a render layer.
+ ///
public interface IRenderLayer
{
+ ///
+ /// Gets the number of points in the point buffer.
+ ///
int Count { get; }
+ ///
+ /// Gets the points buffer.
+ ///
IBuffer Points { get; }
+
+ ///
+ /// Gets the indices buffer.
+ ///
IBuffer Indices { get; }
+ ///
+ /// Gets or sets a value indicating whether the layer is enabled.
+ ///
bool IsEnabled { get; set; }
+ ///
+ /// Indicates whether this layer contains data to render.
+ ///
+ /// Returns true, if the points buffer contains data.
bool IsEmpty();
+ ///
+ /// Resets this layer to an empty state.
+ ///
+ /// If true, all buffers will be set to null.
void Reset(bool clear);
// TODO: add boolean: reset
- BoundingBox SetPoints(IBuffer buffer);
- BoundingBox SetPoints(IPolygon poly);
- BoundingBox SetPoints(IMesh mesh);
- BoundingBox SetPoints(ICollection points);
+
+ ///
+ /// Replaces the current points with the given buffer.
+ ///
+ /// The new points buffer.
+ void SetPoints(IBuffer buffer);
+
+ ///
+ /// Copy the points of the given to the layers point buffer.
+ ///
+ /// The polygon to render.
+ void SetPoints(IPolygon poly);
+
+ ///
+ /// Copy the points of the given to the layers point buffer.
+ ///
+ /// The mesh to render.
+ void SetPoints(IMesh mesh);
+
+ ///
+ /// Copy the points of the given collection to the layers point buffer.
+ ///
+ /// The point set to render.
+ void SetPoints(ICollection points);
+
+ ///
+ /// Copy the segment indices of the given polygon to the layers index buffer.
+ ///
+ /// The polygon to render.
void SetPolygon(IPolygon poly);
+
+ ///
+ /// Copy the segment indices of the given mesh to the layers index buffer.
+ ///
+ /// The mesh to render.
void SetPolygon(IMesh mesh);
+
+ ///
+ /// Copy the indices of the given mesh triangles to the layers index buffer.
+ ///
+ /// The mesh to render.
+ /// If true, all triangle indices are copied. Otherwise,
+ /// only edge indices are copied.
+ ///
+ /// Use elements = true for layers rendering filled triangles (3 indices per buffer item).
+ /// Use elements = false if only edges are rendered (wireframe, 2 indices per buffer item).
+ ///
void SetMesh(IMesh mesh, bool elements);
+
+ ///
+ /// Copy the indices of the given edges to the layers index buffer.
+ ///
+ /// The edges to render.
void SetMesh(IEnumerable 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?
+
+ ///
+ /// Gets the mesh partition.
+ ///
+ ///
+ /// Triangle i given by indices [3 * i, 3 * i + 1, 3 * i + 2]
+ /// belongs to Partition[i].
+ ///
IBuffer Partition { get; }
+
+ ///
+ /// Gets the color attached to a point in the points buffer.
+ ///
IBuffer Colors { get; }
+ ///
+ /// Attach function values z=f(x,y) for all points (x,y) in the point buffer.
+ ///
+ /// The function values.
+ /// The color map.
void AttachLayerData(float[] values, ColorMap colormap);
+
+ ///
+ /// Attach partitioning data to each triangle in the index buffer.
+ ///
+ /// The mesh partition.
void AttachLayerData(int[] partition);
+
+ #endregion
}
}
diff --git a/src/Triangle.Rendering/Projection.cs b/src/Triangle.Rendering/Projection.cs
index 1cd1105..985f655 100644
--- a/src/Triangle.Rendering/Projection.cs
+++ b/src/Triangle.Rendering/Projection.cs
@@ -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.
///
/// The world that should be transformed to screen coordinates.
- 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,
diff --git a/src/Triangle.Rendering/RenderContext.cs b/src/Triangle.Rendering/RenderContext.cs
index 63d7ec3..1433f7e 100644
--- a/src/Triangle.Rendering/RenderContext.cs
+++ b/src/Triangle.Rendering/RenderContext.cs
@@ -5,7 +5,6 @@ namespace TriangleNet.Rendering
using System.Linq;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
- using TriangleNet.Voronoi.Legacy;
///
/// 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 renderLayers;
public RenderContext(Projection zoom, ColorManager colorManager)
{
- bounds = new BoundingBox();
-
renderLayers = new List(6);
renderLayers.Add(new RenderLayer()); // 0 = mesh (filled)
@@ -41,39 +38,22 @@ namespace TriangleNet.Rendering
this.colorManager = colorManager;
}
- public ColorManager ColorManager
- {
- get { return colorManager; }
- }
+ ///
+ public ColorManager ColorManager => colorManager;
- public BoundingBox Bounds
- {
- get { return bounds; }
- }
+ ///
+ public IList RenderLayers => renderLayers;
- public IList RenderLayers
- {
- get { return renderLayers; }
- }
+ ///
+ public Projection Zoom => zoom;
- public Projection Zoom
- {
- get { return zoom; }
- }
+ ///
+ public IMesh Mesh => mesh;
- public IMesh Mesh
- {
- get { return mesh; }
- }
-
- public bool HasData
- {
- get
- {
- return renderLayers.Any(layer => !layer.IsEmpty());
- }
- }
+ ///
+ public bool HasData => renderLayers.Any(layer => !layer.IsEmpty());
+ ///
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);
}
+ ///
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);
}
+ ///
public void Add(ICollection points, IEnumerable edges, bool reset)
{
RenderLayers[4].SetPoints(points);
@@ -130,6 +115,7 @@ namespace TriangleNet.Rendering
RenderLayers[4].IsEnabled = true;
}
+ ///
public void Add(float[] data)
{
// Add function values for filled mesh.
@@ -140,6 +126,7 @@ namespace TriangleNet.Rendering
RenderLayers[0].IsEnabled = true;
}
+ ///
public void Add(int[] data)
{
// Add partition data for filled mesh.
@@ -150,13 +137,19 @@ namespace TriangleNet.Rendering
RenderLayers[0].IsEnabled = true;
}
+ ///
public void Enable(int layer, bool enabled)
{
renderLayers[layer].IsEnabled = enabled;
}
+ ///
public void Clear()
{
+ foreach (var layer in RenderLayers)
+ {
+ layer.Reset(true);
+ }
}
}
}
diff --git a/src/Triangle.Rendering/RenderLayer.cs b/src/Triangle.Rendering/RenderLayer.cs
index 1042c9a..fa4e4aa 100644
--- a/src/Triangle.Rendering/RenderLayer.cs
+++ b/src/Triangle.Rendering/RenderLayer.cs
@@ -24,38 +24,31 @@ namespace TriangleNet.Rendering
this.IsEnabled = false;
}
- public int Count
- {
- get { return count; }
- }
+ ///
+ public int Count => count;
- public IBuffer Points
- {
- get { return points; }
- }
+ ///
+ public IBuffer Points => points;
- public IBuffer Indices
- {
- get { return indices; }
- }
+ ///
+ public IBuffer Indices => indices;
- public IBuffer Partition
- {
- get { return partition; }
- }
+ ///
+ public IBuffer Partition => partition;
- public IBuffer Colors
- {
- get { return colors; }
- }
+ ///
+ public IBuffer Colors => colors;
+ ///
public bool IsEnabled { get; set; }
+ ///
public bool IsEmpty()
{
return (points == null || points.Count == 0);
}
+ ///
public void Reset(bool clear)
{
if (clear)
@@ -69,12 +62,13 @@ namespace TriangleNet.Rendering
colors = null;
}
- public BoundingBox SetPoints(IBuffer buffer)
+ ///
+ public void SetPoints(IBuffer 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)
+ ///
+ 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)
+ ///
+ 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 vertices)
+ ///
+ public void SetPoints(ICollection vertices)
{
- BoundingBox bounds = new BoundingBox();
-
- points = BufferHelper.CreateVertexBuffer(vertices, ref bounds);
+ points = BufferHelper.CreateVertexBuffer(vertices);
count = points.Count / points.Size;
-
- return bounds;
}
+ ///
public void SetPolygon(IPolygon poly)
{
indices = BufferHelper.CreateIndexBuffer(poly.Segments, 2);
@@ -127,11 +111,13 @@ namespace TriangleNet.Rendering
indices = BufferHelper.CreateIndexBuffer(mesh.Segments, 2);
}
+ ///
public void SetMesh(IEnumerable edges)
{
indices = BufferHelper.CreateIndexBuffer(edges, 2);
}
+ ///
public void SetMesh(IMesh mesh, bool elements)
{
mesh.Renumber();
@@ -147,13 +133,11 @@ namespace TriangleNet.Rendering
}
}
- // TODO: remove colormap argument
+ ///
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);
}
+ ///
public void AttachLayerData(int[] partition)
{
this.partition = new IndexBuffer(partition, 1);
diff --git a/src/Triangle.Rendering/Util/BufferHelper.cs b/src/Triangle.Rendering/Util/BufferHelper.cs
index ef891ab..486ee3a 100644
--- a/src/Triangle.Rendering/Util/BufferHelper.cs
+++ b/src/Triangle.Rendering/Util/BufferHelper.cs
@@ -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 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;
- }
-
- public static IBuffer CreateVertexBuffer(ICollection points, ref BoundingBox bounds)
+ public static IBuffer CreateVertexBuffer(ICollection 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;
+ return buffer;
}
- public static IBuffer CreateVertexBuffer(ICollection points, ref BoundingBox bounds)
+ public static IBuffer CreateVertexBuffer(ICollection 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;
+ return buffer;
}
- public static IBuffer CreateIndexBuffer(IList segments, int size)
+ public static IBuffer CreateIndexBuffer(IEnumerable 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;
- }
-
- public static IBuffer CreateIndexBuffer(IEnumerable edges, int size)
- {
- var data = new List();
-
- foreach (var e in edges)
- {
- data.Add(e.P0);
- data.Add(e.P1);
- }
-
- return new IndexBuffer(data.ToArray(), size) as IBuffer;
+ return buffer;
}
public static IBuffer CreateIndexBuffer(ICollection elements, int size)
@@ -136,7 +88,7 @@ namespace TriangleNet.Rendering.Util
i++;
}
- return buffer as IBuffer;
+ return buffer;
}
}
}