File: bunny.py

package info (click to toggle)
mayavi2 4.8.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,892 kB
  • sloc: python: 49,447; javascript: 32,885; makefile: 129; fortran: 60
file content (42 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Viewing Stanford 3D Scanning Repository bunny model
"""
# Copyright (c) 2014-2020, Enthought, Inc.
# Standard library imports
import os
from os.path import join

# Enthought library imports
from mayavi import mlab

### Download the bunny data, if not already on disk ############################
if not os.path.exists('bunny.tar.gz'):
    # Download the data
    try:
        from urllib import urlopen
    except ImportError:
        from urllib.request import urlopen
    print("Downloading bunny model, Please Wait (3MB)")
    opener = urlopen(
                'http://graphics.stanford.edu/pub/3Dscanrep/bunny.tar.gz')
    open('bunny.tar.gz', 'wb').write(opener.read())

# Extract the data
import tarfile
bunny_tar_file = tarfile.open('bunny.tar.gz')
try:
    os.mkdir('bunny_data')
except:
    pass
bunny_tar_file.extractall('bunny_data')
bunny_tar_file.close()

# Path to the bunny ply file
bunny_ply_file = join('bunny_data', 'bunny', 'reconstruction', 'bun_zipper.ply')

# Render the bunny ply file
mlab.pipeline.surface(mlab.pipeline.open(bunny_ply_file))
mlab.show()

import shutil
shutil.rmtree('bunny_data')