[英]How to draw tensor visualization on a 2D grid
I want to implement (ac# program) the system in this paper IPSM It uses tensor field to design street network. 我想在本文中实现(ac#程序)系统IPSM它使用张量场设计街道网络。 For my implementation, my priority is to generate my own street network from my own tensor field.
对于我的实现,我的首要任务是根据自己的张量场生成自己的街道网络。 I don't want something too advanced at first.
首先,我不要太高级。 The paper said that tensor lines (major and minor eigenvector) will represent the streets.
该论文说,张量线(主要和次要特征向量)将代表街道。 Does anyone have any ideas where should I start to look at (how can I draw those lines inside a 2D grid).
有谁有任何想法我应该从哪里着手(如何在2D网格内绘制这些线)。 There are some references inside the paper such tensor field visualization paper but I can't stop turning inside a loop looking one reference to another one.
诸如张量场可视化论文之类的论文中有一些参考文献,但我不能停止在一个循环中寻找一个参考文献。
Regards. 问候。
I'm going to assume that it's the drawing part you need help with. 我将假定它是您需要帮助的绘图部分。 C# has a number of drawing capabilities that make it pretty easy to draw stuff like this.
C#具有许多绘图功能,使绘制这样的东西变得非常容易。 GDI+ (the graphics/drawing package contained in System.Drawing) has built-in support for 2D transformations, so we can create a bitmap and then draw on it using arbitrary coordinate systems.
GDI +(System.Drawing中包含的图形/绘图包)具有对2D转换的内置支持,因此我们可以创建位图,然后使用任意坐标系在其上进行绘制。 You can also leverage the existing Vector class in the System.Windows namespace to make vector math simpler.
您还可以利用System.Windows命名空间中现有的Vector类来简化矢量数学。
First, the namespaces and assemblies you'll need: 首先,您需要的名称空间和程序集:
using System;
// Needs reference to System.Drawing to use GDI+ for drawing
using System.Drawing;
using System.Drawing.Imaging;
// Needs reference to WindowBase to use Vector class
using Vector = System.Windows.Vector;
The following example just draws a 10x10 grid of vectors. 以下示例仅绘制了一个10x10的矢量网格。 The output looks like this.
输出看起来像这样。 The code will run just fine inside of a console application (ie no user interface).
该代码将在控制台应用程序内正常运行(即没有用户界面)。 You could also modify the code to generate the bitmap and display in a Windows Forms application via a picture box or some other UI element.
您还可以修改代码以生成位图,并通过图片框或其他UI元素在Windows窗体应用程序中显示。 The console version, though, is dead simple and easy to play around with:
但是,控制台版本非常简单,易于使用:
// Define the size of our viewport using arbitary world coordinates
var viewportSize = new SizeF(10, 10);
// Create a new bitmap image that is 500 by 500 pixels
using (var bmp = new Bitmap(500, 500, PixelFormat.Format32bppPArgb))
{
// Create graphics object to draw on the bitmap
using (var g = Graphics.FromImage(bmp))
{
// Set up transformation so that drawing calls automatically convert world coordinates into bitmap coordinates
g.TranslateTransform(0, bmp.Height * 0.5f - 1);
g.ScaleTransform(bmp.Width / viewportSize.Width, -bmp.Height / viewportSize.Height);
g.TranslateTransform(0, -viewportSize.Height * 0.5f);
// Create pen object for drawing with
using (var redPen = new Pen(Color.Red, 0.01f)) // Note that line thickness is in world coordinates!
{
// Randomization
var rand = new Random();
// Draw a 10x10 grid of vectors
var a = new Vector();
for (a.X = 0.5; a.X < 10.0; a.X += 1.0)
{
for (a.Y = 0.5; a.Y < 10.0; a.Y += 1.0)
{
// Connect the center of this cell to a random point inside the cell
var offset = new Vector(rand.NextDouble() - 0.5, rand.NextDouble() - 0.5);
var b = a + offset;
g.DrawLine(redPen, a.ToPointF(), b.ToPointF());
}
}
}
}
// Save the bitmap and display it
string filename = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"c#test.png");
bmp.Save(filename, ImageFormat.Png);
System.Diagnostics.Process.Start(filename);
}
You are going to need to do quite a lot of work to develop a system like they have. 您将需要做很多工作才能开发出像他们一样的系统。 You first step will be to draw the flow lines of a vector field.
您的第一步将是绘制矢量场的流线。 There is a lot of literature on the topic because it is a big area.
关于该主题的文献很多,因为它涉及的领域很大。 I would recommend getting a book on the subject rather than trying to work with papers which are always missing on the nitty gritty details.
我建议您买一本关于该主题的书,而不是尝试处理那些始终在细节上不完整的论文。
Once you have a framework which can do streamlines, you can move onto the other parts of the algorithm. 一旦有了可以简化的框架,就可以继续进行算法的其他部分。 To simplify the algorithm I would look at the section on height-maps.
为了简化算法,我将查看高度图部分。 If you could generate a height-map over the whole domain then you define one of the vectors as the gradient and draw some stream lines from that vector field.
如果可以在整个域上生成高度图,则可以将向量之一定义为渐变,并从该向量字段中绘制一些流线。
This might be a good way to get a fairly simple working system. 这可能是获得相当简单的工作系统的好方法。 Their full algorithm is really quite involved.
他们的完整算法确实很复杂。 I would say you would need about a month of work to implement their whole algorithm.
我要说,您将需要大约一个月的时间来实现他们的整个算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.