# # import math, time mindist = 0.001 # minimum accepted distance between two vertices # fn = "c:/temp/v3chest.obj" # # read the file - extract vertex lines, clean up whitespace # - store values to list as numbers # print "Processing : " +fn st = time.time() fi = file(fn,"r") c = [] s = '\n' for line in fi: if line.startswith("v "): a = line.replace('\n'," ") b = a.replace(" "," ") a1 = b.strip( ) ba = a1.split(" ") c.append([float(ba[1]),float(ba[2]),float(ba[3])]) fi.close() # now sort x value vertex to + and - values xp = [] xm = [] x0 = [] for b in c: if b[0] > 0: xp.append(b) if b[0] < 0 : xm.append(b) if b[0] == 0: x0.append (b) print "Array Lengths +/-/0 : " ,len(xp),len(xm),len(x0) print "" # now match vertices by distance using minimum distance value ma = [] # matched vertice [ source,target ] nm = [] # vertex not matched rc = 0 # record count for p in xp: rc = rc + 1 if rc > len(xp)/50: rc = 0 print "*", mv = 10000000 # set min value large to start for m in xm : xvar = p[0] + m[0] yvar = p[1] - m[1] zvar = p[2] - m[2] # now check variances tv = math.sqrt((xvar * xvar) + (yvar * yvar)+ (zvar * zvar)) # test value = distance if tv < mv: # if test is smaller than stored values - store new values mv = tv mve = m if mv < mindist: ma.append([p,mve]) #xm.remove(mve) else: nm.append(p) et = time.time() dur = et-st print "" print "Duration : " + str(dur) print "Vertex matched : " + str(len(ma)) print "No Match found : " + str(len(nm)) print "Total Vertices : " + str(len(ma) + len(nm)) print "Done"