gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.72k stars 390 forks source link

Point Clouds Correct Import? #73

Open ruribev opened 6 years ago

ruribev commented 6 years ago

Hello,

I apologize if this is a basic question but I am a bit confused on how to import a point cloud using a DMesh3. I follow the last tutorial and this is what I got so far:

`
Dim tri As Integer() = New Integer() {} Dim pts As List(Of g3.Vector3d) = New List(Of g3.Vector3d) Dim nrm As List(Of g3.Vector3d) = New List(Of g3.Vector3d)

    Dim pointSetBuilder As g3.DMesh3Builder = New g3.DMesh3Builder()

    For Each pt In imputPoints
        pts.Add(New g3.Vector3d(pt.x, pt.y, pt.z))
        nrm.Add(New g3.Vector3d(pt.normal.x, pt.normal.y, pt.normal.z))
    Next

    Dim mesht As g3.DMesh3 = g3.DMesh3Builder.Build(pts, tri, nrm)
    Dim pointSet = mesht
    Dim pointBVTree As g3.PointAABBTree3 = New g3.PointAABBTree3(mesht, True)

    Dim areas As Double() = New Double(pointSet.MaxVertexID - 1) {}

    For Each vid As Integer In pointSet.VertexIndices()
        pointBVTree.PointFilterF = Function(i) i <> vid
        Dim near_vid As Integer = pointBVTree.FindNearestPoint(pointSet.GetVertex(vid))
        Dim pt As g3.Vector3d = pointSet.GetVertex(vid)
        Dim ptt As g3.Vector3d = pointSet.GetVertex(near_vid)
        Dim dist As Double = Math.Sqrt((pt.x - ptt.x) * (pt.x - ptt.x) + (pt.y - ptt.y) * (pt.y - ptt.y) + (pt.z - ptt.z) * (pt.z - ptt.z))
        areas(vid) = g3.Circle2d.RadiusArea(dist) * factor
    Next

    pointBVTree.FWNAreaEstimateF = Function(vid) areas(vid)
    pointBVTree.FastWindingNumber(g3.Vector3d.Zero)

    Dim mc As g3.MarchingCubes = New g3.MarchingCubes()
    Dim Implicit = New PWNImplicit()
    Implicit.Spatial = pointBVTree
    Implicit.Bounds()
    mc.Implicit = Implicit

    mc.IsoValue = 0.0
    mc.CubeSize = pointBVTree.Bounds.MaxDim / 12.5
    mc.Bounds = pointBVTree.Bounds.Expanded(mc.CubeSize * 3)
    mc.RootMode = g3.MarchingCubes.RootfindingModes.Bisection
    mc.Generate()
    Dim resultMesh As g3.DMesh3 = mc.Mesh

`

The resultMesh have 0 vertex and 0 meshes. Thanks for the help. I really appreciate it!