How to use Marching Cubes in python?











up vote
0
down vote

favorite












I'm reading some data about mesh objects and 3D-model.
and then I saw this way:Marching Cubes



This is its sample code:



import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

from skimage import measure
from skimage.draw import ellipsoid


# Generate a level set about zero of two identical ellipsoids in 3D
ellip_base = ellipsoid(6, 10, 16, levelset=True)
ellip_double = np.concatenate((ellip_base[:-1, ...],
ellip_base[2:, ...]), axis=0)

# Use marching cubes to obtain the surface mesh of these ellipsoids
verts, faces, normals, values = measure.marching_cubes_lewiner(ellip_double, 0)

# Display resulting triangular mesh using Matplotlib. This can also be done
# with mayavi (see skimage.measure.marching_cubes_lewiner docstring).
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')

# Fancy indexing: `verts[faces]` to generate a collection of triangles
mesh = Poly3DCollection(verts[faces])
mesh.set_edgecolor('k')
ax.add_collection3d(mesh)

ax.set_xlabel("x-axis: a = 6 per ellipsoid")
ax.set_ylabel("y-axis: b = 10")
ax.set_zlabel("z-axis: c = 16")

ax.set_xlim(0, 24) # a = 6 (times two for 2nd ellipsoid)
ax.set_ylim(0, 20) # b = 10
ax.set_zlim(0, 32) # c = 16

plt.tight_layout()
plt.show()


I am interested in this,but I don't know how to use it.



Take my data as an example (dropbox) , it is composed of three dimensions: x, y, and z.
I want to usde them to build a 3D model in this way,but I have no idea to write code.



Please help me.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm reading some data about mesh objects and 3D-model.
    and then I saw this way:Marching Cubes



    This is its sample code:



    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d.art3d import Poly3DCollection

    from skimage import measure
    from skimage.draw import ellipsoid


    # Generate a level set about zero of two identical ellipsoids in 3D
    ellip_base = ellipsoid(6, 10, 16, levelset=True)
    ellip_double = np.concatenate((ellip_base[:-1, ...],
    ellip_base[2:, ...]), axis=0)

    # Use marching cubes to obtain the surface mesh of these ellipsoids
    verts, faces, normals, values = measure.marching_cubes_lewiner(ellip_double, 0)

    # Display resulting triangular mesh using Matplotlib. This can also be done
    # with mayavi (see skimage.measure.marching_cubes_lewiner docstring).
    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(111, projection='3d')

    # Fancy indexing: `verts[faces]` to generate a collection of triangles
    mesh = Poly3DCollection(verts[faces])
    mesh.set_edgecolor('k')
    ax.add_collection3d(mesh)

    ax.set_xlabel("x-axis: a = 6 per ellipsoid")
    ax.set_ylabel("y-axis: b = 10")
    ax.set_zlabel("z-axis: c = 16")

    ax.set_xlim(0, 24) # a = 6 (times two for 2nd ellipsoid)
    ax.set_ylim(0, 20) # b = 10
    ax.set_zlim(0, 32) # c = 16

    plt.tight_layout()
    plt.show()


    I am interested in this,but I don't know how to use it.



    Take my data as an example (dropbox) , it is composed of three dimensions: x, y, and z.
    I want to usde them to build a 3D model in this way,but I have no idea to write code.



    Please help me.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm reading some data about mesh objects and 3D-model.
      and then I saw this way:Marching Cubes



      This is its sample code:



      import numpy as np
      import matplotlib.pyplot as plt
      from mpl_toolkits.mplot3d.art3d import Poly3DCollection

      from skimage import measure
      from skimage.draw import ellipsoid


      # Generate a level set about zero of two identical ellipsoids in 3D
      ellip_base = ellipsoid(6, 10, 16, levelset=True)
      ellip_double = np.concatenate((ellip_base[:-1, ...],
      ellip_base[2:, ...]), axis=0)

      # Use marching cubes to obtain the surface mesh of these ellipsoids
      verts, faces, normals, values = measure.marching_cubes_lewiner(ellip_double, 0)

      # Display resulting triangular mesh using Matplotlib. This can also be done
      # with mayavi (see skimage.measure.marching_cubes_lewiner docstring).
      fig = plt.figure(figsize=(10, 10))
      ax = fig.add_subplot(111, projection='3d')

      # Fancy indexing: `verts[faces]` to generate a collection of triangles
      mesh = Poly3DCollection(verts[faces])
      mesh.set_edgecolor('k')
      ax.add_collection3d(mesh)

      ax.set_xlabel("x-axis: a = 6 per ellipsoid")
      ax.set_ylabel("y-axis: b = 10")
      ax.set_zlabel("z-axis: c = 16")

      ax.set_xlim(0, 24) # a = 6 (times two for 2nd ellipsoid)
      ax.set_ylim(0, 20) # b = 10
      ax.set_zlim(0, 32) # c = 16

      plt.tight_layout()
      plt.show()


      I am interested in this,but I don't know how to use it.



      Take my data as an example (dropbox) , it is composed of three dimensions: x, y, and z.
      I want to usde them to build a 3D model in this way,but I have no idea to write code.



      Please help me.










      share|improve this question















      I'm reading some data about mesh objects and 3D-model.
      and then I saw this way:Marching Cubes



      This is its sample code:



      import numpy as np
      import matplotlib.pyplot as plt
      from mpl_toolkits.mplot3d.art3d import Poly3DCollection

      from skimage import measure
      from skimage.draw import ellipsoid


      # Generate a level set about zero of two identical ellipsoids in 3D
      ellip_base = ellipsoid(6, 10, 16, levelset=True)
      ellip_double = np.concatenate((ellip_base[:-1, ...],
      ellip_base[2:, ...]), axis=0)

      # Use marching cubes to obtain the surface mesh of these ellipsoids
      verts, faces, normals, values = measure.marching_cubes_lewiner(ellip_double, 0)

      # Display resulting triangular mesh using Matplotlib. This can also be done
      # with mayavi (see skimage.measure.marching_cubes_lewiner docstring).
      fig = plt.figure(figsize=(10, 10))
      ax = fig.add_subplot(111, projection='3d')

      # Fancy indexing: `verts[faces]` to generate a collection of triangles
      mesh = Poly3DCollection(verts[faces])
      mesh.set_edgecolor('k')
      ax.add_collection3d(mesh)

      ax.set_xlabel("x-axis: a = 6 per ellipsoid")
      ax.set_ylabel("y-axis: b = 10")
      ax.set_zlabel("z-axis: c = 16")

      ax.set_xlim(0, 24) # a = 6 (times two for 2nd ellipsoid)
      ax.set_ylim(0, 20) # b = 10
      ax.set_zlim(0, 32) # c = 16

      plt.tight_layout()
      plt.show()


      I am interested in this,but I don't know how to use it.



      Take my data as an example (dropbox) , it is composed of three dimensions: x, y, and z.
      I want to usde them to build a 3D model in this way,but I have no idea to write code.



      Please help me.







      python-3.x 3d-reconstruction 3d-modelling marching-cubes






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 14:49

























      asked Nov 19 at 6:23









      LiangJinWei

      62




      62





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369312%2fhow-to-use-marching-cubes-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369312%2fhow-to-use-marching-cubes-in-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin