Skip to content

Instantly share code, notes, and snippets.

@CharStiles
Created March 25, 2018 02:03
Show Gist options
  • Save CharStiles/c172c0e988500c91cda8b82d75970415 to your computer and use it in GitHub Desktop.
Save CharStiles/c172c0e988500c91cda8b82d75970415 to your computer and use it in GitHub Desktop.
from sys import argv
import os
import math
def dist(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
def notLight(li):
ln = li.split()
if (len(ln)<6):return False
try:
if (dist(float(ln[0]),float(ln[2]),0,0)>100):
return False
except:
print "fail"
print ln
return True
def notGreen(li):
ln = li.split()
#print ln
if (len(ln)<6):return False
r = int(ln[3])
g = int(ln[4])
b = int(ln[5])
if (((float(ln[1]) < 0.5 )) & ((r < 130) &\
(g > 150) &\
(b < 130)) | ((g-r>10) & (g-b>10))) :
return False
return True# numFiles = 4
coordStart = 9
#for i in xrange(numFiles):
for filename in os.listdir(os.getcwd()):
#filename = "frame0000"+str(i)+".ply"
if (filename.endswith(".ply") == False):
continue
f = open(filename)
lines = f.readlines()
f.close()
f = open(filename, 'w')
j = 0
size = 0
for line in lines:
if (j == 9 ): #the place where alpha should be
f.write("property uchar alpha\n")
f.write(line) #write end headder
elif (j == 5): #the place where alpha should be
f.write("property float z\n")
elif (j == 4): #the place where alpha should be
f.write("property float y\n")
elif (j == 3): #the place where alpha should be
f.write("property float x\n")
else:
if ( (j > coordStart) &(notGreen(line) == True)&\
(notLight(line) == True) & (line[9:11]!= "-1") &\
(line[10:12]!= "-1")): #
size = size + 1
f.write(line[:-1] + " 255\n")
if((j<=coordStart)):
f.write(line)
j = j+1
f.close()
#now I need to go back and put the correct amount of verts
f = open(filename)
lines = f.readlines()
f.close()
f = open(filename, 'w')
j2=0
for line in lines:
#replace with the correct number of vertices(this might not be on the 2nd line)
if (j2 == 2):f.write("element vertex "+str(size)+"\n")
else: f.write(line)
j2 = j2 +1
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment