簡體   English   中英

如何在2D網格上繪制張量可視化

[英]How to draw tensor visualization on a 2D grid

我想在本文中實現(ac#程序)系統IPSM它使用張量場設計街道網絡。 對於我的實現,我的首要任務是根據自己的張量場生成自己的街道網絡。 首先,我不要太高級。 該論文說,張量線(主要和次要特征向量)將代表街道。 有誰有任何想法我應該從哪里着手(如何在2D網格內繪制這些線)。 諸如張量場可視化論文之類的論文中有一些參考文獻,但我不能停止在一個循環中尋找一個參考文獻。

問候。

我將假定它是您需要幫助的繪圖部分。 C#具有許多繪圖功能,使繪制這樣的東西變得非常容易。 GDI +(System.Drawing中包含的圖形/繪圖包)具有對2D轉換的內置支持,因此我們可以創建位圖,然后使用任意坐標系在其上進行繪制。 您還可以利用System.Windows命名空間中現有的Vector類來簡化矢量數學。

首先,您需要的名稱空間和程序集:

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;

以下示例僅繪制了一個10x10的矢量網格。 輸出看起來像這樣。 該代碼將在控制台應用程序內正常運行(即沒有用戶界面)。 您還可以修改代碼以生成位圖,並通過圖片框或其他UI元素在Windows窗體應用程序中顯示。 但是,控制台版本非常簡單,易於使用:

// 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);
}

您將需要做很多工作才能開發出像他們一樣的系統。 您的第一步將是繪制矢量場的流線。 關於該主題的文獻很多,因為它涉及的領域很大。 我建議您買一本關於該主題的書,而不是嘗試處理那些始終在細節上不完整的論文。

一旦有了可以簡化的框架,就可以繼續進行算法的其他部分。 為了簡化算法,我將查看高度圖部分。 如果可以在整個域上生成高度圖,則可以將向量之一定義為漸變,並從該向量字段中繪制一些流線。

這可能是獲得相當簡單的工作系統的好方法。 他們的完整算法確實很復雜。 我要說,您將需要大約一個月的時間來實現他們的整個算法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM