def save_triangulated(V, Vint, F, outputdir, outputfile): logger.debug("triangulation") Ftr = triangulate_quads(F) if outputfile is not None: outputfile = os.path.join(outputdir, outputfile) writeFile(outputfile + "_sm_i_tr.obj", Vint, Ftr) writeFile(outputfile + "_sm_tr.obj", V, Ftr) return Ftr
def main(): logger = logging.getLogger() logger.setLevel(logging.WARNING) ch = logging.StreamHandler() logger.addHandler(ch) # logger.debug('input params') # input parser parser = argparse.ArgumentParser(description="Laplacian smoothing") parser.add_argument('-i', '--inputfile', default=None, required=True, help='input file') parser.add_argument('-o', '--outputfile', default='smooth.obj', help='input file') parser.add_argument('-v', '--visualization', action='store_true', help='Use visualization') parser.add_argument('-d', '--debug', action='store_true', help='Debug mode') args = parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) t0 = time.time() V, FV = readFile(args.inputfile) t1 = time.time() logger.info('Data imported %ss. #V: %i, #FV: %i' % (str(t1 - t0), len(V), len(FV))) # V2 = makeSmoothing(V, FV) V2 = iterativeLaplacianSmoothing(V, FV) if args.visualization: # t7 = time.time() # FV = triangulateSquares(FV) # tv1 = time.time() # logger.info('triangulation %ss' % # (str(tv1 - t7))) VIEW(STRUCT(MKPOLS((V2, FV)))) # write outputs writeFile(args.outputfile + '.pkl', V2, FV) writeFile(args.outputfile, V2, FV) logger.info("Data stored to ' %s" % (args.outputfile))
def main(): logger = logging.getLogger() logger.setLevel(logging.WARNING) ch = logging.StreamHandler() logger.addHandler(ch) # logger.debug('input params') # input parser parser = argparse.ArgumentParser( description="Remove faces from file" ) parser.add_argument( '-i', '--inputfile', default=None, required=True, help='input file' ) parser.add_argument( '-o', '--outputfile', default=None, required=True, help='output file' ) parser.add_argument( '-b', '--boxsize', default=None, type=int, metavar='N', nargs='+', help='Size of box' ) parser.add_argument( '-a', '--alberto', action='store_true', help='Albertos algorithm') parser.add_argument( '-d', '--debug', action='store_true', help='Debug mode') args = parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) v, f = readFile(args.inputfile) print "Before" print "Number of vertexes: %i Number of faces %i" % (len(v), len(f)) # findBoxVertexesForAxis(v, 2, 0) # v, f = findBoundaryFaces(v, f, 2) v, f = removeDoubleVertexesAndFaces(v, f, args.boxsize, use_dict_algorithm=args.alberto) writeFile(args.outputfile, v, f) print "After" print "Number of vertexes: %i Number of faces %i" % (len(v), len(f))
def makeCleaningAndSmoothing(V, F, outputfile=None): logger.debug("outputfile " + str(outputfile)) # findBoxVertexesForAxis(v, 2, 0) # v, f = findBoundaryFaces(v, f, 2) # @TODO debug dict algorithm V, F = rmbox.removeDoubleVertexesAndFaces(V, F, use_dict_algorithm=False) if outputfile is not None: writeFile(outputfile + "_cl.obj", V, F) V = ls.makeSmoothing(V, F) # @TODO remove unused vertexes is too general and slow V, F = rmbox.removeDoubleVertexesAndFaces(V, F, use_dict_algorithm=False) V, F = __remove_first_vertex(V, F) if outputfile is not None: writeFile(outputfile + "_sm.obj", V, F, ignore_empty_vertex_warning=True) return V, F
def makeSmooth(inputfile, bordersize=[2, 2, 2], outputdir='output', outputfile='out', visualization=False, borderdir='border', make_triangulation=True, label=2, smoothing=True): """ :param inputfile: path to input data. It can be tiff, pklz, dicom or other 3d file or directory with dicom files or jpegs :param bordersize: Data are processed per partes. bordersize specify size of one part :param outputdir: directory with output stl files and temporary files. Acronyms in file names are: sm - smoothing, i - converted to integer, tr - triangulation, cl - cleaning done, do double faces. :param outputfile: name of outpu file :param visualization: output can be visualized by setting this parametr True :param borderdir: temporary directory with bordermatrix computation :param make_triangulation: :param label: expected value in object pixels of input data :return: """ filepath, ext = os.path.splitext(inputfile) if ext == "obj": obj_input = inputfile else: print 'Processing pklz data' convert(inputfile, bordersize, outputdir, borderdir=borderdir, label=label) obj_input = 'stl/model-2.obj' # V, F = readFile(args.inputfile) V, F = readFile(os.path.join(outputdir, obj_input)) print "Before" print "Number of vertexes: %i Number of faces %i" % (len(V), len(F)) # F = rmbox.shiftFaces(F, -1) V, F = makeCleaningAndSmoothing(V, F, os.path.join(outputdir, outputfile), smoothing) print "After" print "Number of vertexes: %i Number of faces %i" % (len(V), len(F)) # write to ints # fill empty vertexes V = [v if len(v) == 3 else [0, 0, 0] for v in V] # make tenimes bigger Vint = (np.asarray(V) * 10).astype(np.int).tolist() if outputfile is not None: writeFile(os.path.join(outputdir, outputfile + "_sm_i.obj"), Vint, F, ignore_empty_vertex_warning=True) # make triangulation if make_triangulation: Ftr = save_triangulated(V, Vint, F, outputdir, outputfile) if visualization: Ftr = triangulate_quads(F) vis.visualize(V, Ftr) return V, F