Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert .off files to .ply #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ shapenetcore_partanno_segmentation_benchmark_v0/
cls/
seg/
*.egg-info/
ModelNet40/
30 changes: 28 additions & 2 deletions pointnet/dataset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import print_function
# from __future__ import print_function
import torch.utils.data as data
import os
import os.path
import torch
import meshio
from pathlib import Path
import numpy as np
import sys
from tqdm import tqdm
Expand Down Expand Up @@ -145,7 +147,8 @@ def __init__(self,
root,
npoints=2500,
split='train',
data_augmentation=True):
data_augmentation=True,
convert_off_to_ply=True):
self.npoints = npoints
self.root = root
self.split = split
Expand All @@ -164,6 +167,29 @@ def __init__(self,
print(self.cat)
self.classes = list(self.cat.keys())

if convert_off_to_ply:
p = Path(self.root)
print('searching path', p, 'to convert .off files to .ply')
l = list(p.glob('**/*.off'))
for in_file in l:
# print(in_file)
with in_file.open() as f:
# some OFF files in original dataset had OFF345 345 344 where
# OFF collided with the number. Needs \n
lines = f.readlines()
if lines[0] != 'OFF\n':
# print(lines[0:3])
lines[0] = lines[0][0:3] + '\n' + lines[0][3:]
# print(lines[0:3])
with in_file.open('w') as f:
lines = "".join(lines)
f.write(lines)

mesh = meshio.read(in_file, file_format="off")
out_file = in_file.replace(in_file.with_suffix('.ply'))
# print(out_file)
mesh.write(out_file, file_format='ply')

def __getitem__(self, index):
fn = self.fns[index]
cls = self.cat[fn.split('/')[0]]
Expand Down
9 changes: 5 additions & 4 deletions scripts/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`

cd $SCRIPTPATH/..
wget https://shapenet.cs.stanford.edu/ericyi/shapenetcore_partanno_segmentation_benchmark_v0.zip --no-check-certificate
unzip shapenetcore_partanno_segmentation_benchmark_v0.zip
rm shapenetcore_partanno_segmentation_benchmark_v0.zip
cd -
wget http://modelnet.cs.princeton.edu/ModelNet40.zip --no-check-certificate
unzip ModelNet40.zip
# rm ModelNet40.zip # in case you need to reuse
cd ..
cp test.txt trainval.txt ModelNet40/
Loading