此程式碼示範了一種在一組 2d 點中尋找凸孔的方法。此方法包括建立點雲位圖、計算位圖中每個單元的資料密度、建立未使用區域的清單(map[][] = 0 或map[][]
這是此演算法的 C# 實作提供:
using System; using System.Collections.Generic; using System.Linq; using System.Drawing; namespace HoleFinder { class Program { // Define a cell structure for the bitmap public struct Cell { public double x0, x1, y0, y1; // Bounding box of points inside the cell public int count; // Number of points inside the cell } // Define a line structure for representing hole boundaries public struct Line { public double x0, y0, x1, y1; // Line edge points public int id; // Id of the hole to which the line belongs for segmentation/polygonization public int i0, i1, j0, j1; // Index in map[][] } // Compute the bounding box of the point cloud public static (double x0, double x1, double y0, double y1) ComputeBoundingBox(List<point> points) { double x0 = points[0].X; double x1 = points[0].X; double y0 = points[0].Y; double y1 = points[0].Y; foreach (var point in points) { if (point.X x1) x1 = point.X; if (point.Y y1) y1 = point.Y; } return (x0, x1, y0, y1); } // Create a bitmap of the point cloud public static int[,] CreateBitmap(List<point> points, (double x0, double x1, double y0, double y1) boundingBox, int N) { // Create a 2D array to represent the bitmap int[,] bitmap = new int[N, N]; // Compute the scale factors for converting point coordinates to bitmap indices double mx = N / (boundingBox.x1 - boundingBox.x0); double my = N / (boundingBox.y1 - boundingBox.y0); // Iterate over the points and increment the corresponding cells in the bitmap foreach (var point in points) { int i = (int)Math.Round((point.X - boundingBox.x0) * mx); int j = (int)Math.Round((point.Y - boundingBox.y0) * my); if (i >= 0 && i = 0 && j FindUnusedAreasHorizontalVertical(Cell[] map, int N, int treshold = 0) { List unusedAreas = new List(); // Scan horizontally for (int j = 0; j = 0) { unusedAreas.Add((i0, i1, j, j)); i0 = -1; i1 = -1; } } } if (i0 >= 0) unusedAreas.Add((i0, i1, j, j)); } // Scan vertically for (int i = 0; i = 0) { unusedAreas.Add((i, i, j0, j1)); j0 = -1; j1 = -1; } } } if (j0 >= 0) unusedAreas.Add((i, i, j0, j1)); } return unusedAreas; } // Segment the list of unused areas into groups of connected components public static List<list i0 int i1 j0 j1>> SegmentUnusedAreas(List unusedAreas) { // Initialize each unused area as a separate group List<list i0 int i1 j0 j1>> segments = new List<list i0 int i1 j0 j1>>(); foreach (var unusedArea in unusedAreas) { segments.Add(new List { unusedArea }); } // Iterate until no more segments can be joined bool joined = true; while (joined) { joined = false; // Check if any two segments intersect or are adjacent for (int i = 0; i = unusedArea2.i0 && unusedArea1.j0 = unusedArea2.j0) { intersects = true; break; } } if (intersects) break; } // Check for adjacency bool adjacent = false; if (!intersects) { foreach (var unusedArea1 in segments[i]) { foreach (var unusedArea2 in segments[j]) { if (unusedArea1.i0 == unusedArea2.i0 && unusedArea1.i1 == unusedArea2.i1 && ((unusedArea1.j1 == unusedArea2.j0 && Math.Abs(unusedArea1.j0 - unusedArea2.j1) == 1) || (unusedArea1.j0 == unusedArea2.j1 && Math.Abs(unusedArea1.j1 - unusedArea2.j0) == 1))) { adjacent = true; break; } if (unusedArea1.j0 == unusedArea2.j0 && unusedArea1.j1 == unusedArea2.j1</list></list></list></point></point>
以上是如何使用 C# 識別 2D 點雲中的凸孔並將其多邊形化?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文解釋了C標準模板庫(STL),重點關注其核心組件:容器,迭代器,算法和函子。 它詳細介紹了這些如何交互以啟用通用編程,提高代碼效率和可讀性t

本文詳細介紹了c中有效的STL算法用法。 它強調了數據結構選擇(向量與列表),算法複雜性分析(例如,std :: sort vs. std vs. std :: partial_sort),迭代器用法和並行執行。 常見的陷阱

本文詳細介紹了C中的有效異常處理,涵蓋了嘗試,捕捉和投擲機制。 它強調了諸如RAII之類的最佳實踐,避免了不必要的捕獲塊,並為強大的代碼登錄例外。 該文章還解決了Perf

本文討論了使用C中的移動語義來通過避免不必要的複制來提高性能。它涵蓋了使用std :: Move的實施移動構造函數和任務運算符,並確定了關鍵方案和陷阱以有效

C 20範圍通過表現力,合成性和效率增強數據操作。它們簡化了複雜的轉換並集成到現有代碼庫中,以提高性能和可維護性。

本文討論了C中的動態調度,其性能成本和優化策略。它突出了動態調度會影響性能並將其與靜態調度進行比較的場景,強調性能和之間的權衡

文章討論了在C中有效使用RVALUE參考,以進行移動語義,完美的轉發和資源管理,重點介紹最佳實踐和性能改進。(159個字符)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

記事本++7.3.1
好用且免費的程式碼編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),