public WindingGridImplicit(MeshWindingNumberGrid mwnGrid) { Initialize(mwnGrid); }
public void Initialize(MeshWindingNumberGrid mwnGrid) { WindingGrid = new DenseGridTrilinearImplicit(mwnGrid.Grid, mwnGrid.GridOrigin, mwnGrid.CellSize); WindingIsoValue = mwnGrid.WindingIsoValue; }
public static void test_winding_grid() { //Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { EdgeVertices = 15, Radius = 5 }; //CappedCylinderGenerator gen = new CappedCylinderGenerator() { }; //TrivialBox3Generator gen = new TrivialBox3Generator() { Box = new Box3d(Vector3d.Zero, 5 * Vector3d.One) }; //DMesh3 mesh = gen.Generate().MakeDMesh(); //MeshTransforms.Translate(mesh, 5 * Vector3d.One); //DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj"); //DMesh3 mesh = TestUtil.LoadTestInputMesh("holey_bunny.obj"); DMesh3 mesh = TestUtil.LoadTestInputMesh("holey_bunny_2.obj"); //DMesh3 mesh = TestUtil.LoadTestMesh("C:\\git\\gsOrthoVRApp\\sample_files\\scan_1_raw.obj"); // use iso 0.25 //DMesh3 mesh = TestUtil.LoadTestMesh("C:\\scratch\\irongiant.stl"); //DMesh3 mesh = TestUtil.LoadTestMesh("C:\\Users\\rms\\Dropbox\\meshes\\cars\\beetle.obj"); //DMesh3 mesh = TestUtil.LoadTestMesh("c:\\scratch\\PigHead_rot90.obj"); //DMesh3 mesh = TestUtil.LoadTestMesh("C:\\Projects\\nia_files\\testscan2.obj"); //TestUtil.WriteTestOutputMesh(mesh, "xxx.obj"); AxisAlignedBox3d meshBounds = mesh.CachedBounds; int num_cells = 128; double cell_size = meshBounds.MaxDim / num_cells; float winding_iso = 0.35f; DMeshAABBTree3 spatial = new DMeshAABBTree3(mesh, true); MeshWindingNumberGrid mwnGrid = new MeshWindingNumberGrid(mesh, spatial, cell_size) { WindingIsoValue = winding_iso }; mwnGrid.DebugPrint = true; LocalProfiler p = new LocalProfiler(); p.Start("grid"); mwnGrid.Compute(); p.Stop("grid"); System.Console.WriteLine(p.AllTimes()); MarchingCubes c = new MarchingCubes(); c.Implicit = new WindingGridImplicit(mwnGrid); c.Bounds = mesh.CachedBounds; c.CubeSize = c.Bounds.MaxDim / 128; //c.Bounds = mesh.CachedBounds; //c.Bounds.Expand(c.Bounds.MaxDim * 0.1); //c.CubeSize = cell_size * 0.5; //c.IsoValue = mwnGrid.WindingIsoValue; c.Generate(); // reproject foreach (int vid in c.Mesh.VertexIndices()) { Vector3d v = c.Mesh.GetVertex(vid); int tid = spatial.FindNearestTriangle(v, cell_size * MathUtil.SqrtTwo); if (tid != DMesh3.InvalidID) { var query = MeshQueries.TriangleDistance(mesh, tid, v); if (v.Distance(query.TriangleClosest) < cell_size) { c.Mesh.SetVertex(vid, query.TriangleClosest); } } } //MeshNormals.QuickCompute(c.Mesh); TestUtil.WriteTestOutputMesh(c.Mesh, "mwn_implicit.obj"); }