def extraction_algorithm(fine_data, resolutions, dimensions): print "### Dual Contouring ###" [verts_out_dc, quads_out_dc, manifolds, datasets] = tworesolution_dual_contour(fine_data, resolutions, dimensions) print "### Dual Contouring DONE ###" N_quads = {'coarse': quads_out_dc['coarse'].__len__(), 'fine': quads_out_dc['fine'].__len__()} N_verts = {'coarse': verts_out_dc['coarse'].__len__(), 'fine': verts_out_dc['fine'].__len__()} quads = {'coarse': [None] * N_quads['coarse'], 'fine': quads_out_dc['fine']} verts = {'coarse': verts_out_dc['coarse'], 'fine': verts_out_dc['fine']} # todo substitute with vertex objects for i in range(N_quads['coarse']): quads['coarse'][i]=Quad(i,quads_out_dc['coarse'],verts_out_dc['coarse']) assert quads['coarse'].__len__() > 0 print "### Projecting Datapoints onto coarse quads ###" # do projection of fine verts on coarse quads param = create_parameters(verts, quads) export_results.export_as_csv(param,'param') print "### Projecting Datapoints onto coarse quads DONE ###" return verts_out_dc, quads_out_dc, quads, param, datasets
def tworesolution_dual_contour(data, resolutions, dims): # fine_dataset = VoxelDataset.from_filename('GE_white_big.vtk') # use for GE bracket fine_dataset = VoxelDataset(dims, resolutions['fine'], data) # use for topy files print "++ Aligning Dataset ++" fine_dataset.align() fine_dataset.surround() pre_coarsening_steps = 0 if pre_coarsening_steps > 0: print "PRESMOOTHING OF DATASET APPLIED!" print "++ Precoarsening of dataset ++" print "coarsening steps: %d" % (pre_coarsening_steps) fine_dataset = coarsen_dataset(pre_coarsening_steps, fine_dataset) print "++ Fine Resolution DC ++" print "resolution: %d" % (fine_dataset._resolution) [dc_verts_fine, dc_quads_fine, dc_manifold_edges_fine, not_resolved_edges_fine] = dual_contour(fine_dataset, resolutions['fine'], is_coarse_level=False, do_manifold_treatment=False) # compute necessary coarsening steps from given coarse resolution. print "fine quads produced: %d" % (dc_quads_fine.__len__()) coarsening_steps = int(np.log(resolutions['coarse']) / np.log(2)) - pre_coarsening_steps if coarsening_steps > 0: print "++ Coarsening Dataset ++" assert type(coarsening_steps) is int # coarsening steps have to be integer! coarse_dataset = coarsen_dataset(coarsening_steps, fine_dataset) else: coarse_dataset = fine_dataset print "++ Coarse Resolution DC ++" print "resolution: %d" % (coarse_dataset._resolution) [dc_verts_coarse, dc_quads_coarse, dc_manifold_edges_coarse, not_resolved_edges_coarse] = dual_contour( coarse_dataset, resolutions['fine'], is_coarse_level=True, do_manifold_treatment=True) print "coarse quads produced: %d" % (dc_quads_coarse.__len__()) dc_verts = {'fine': dc_verts_fine, 'coarse': dc_verts_coarse} dc_quads = {'fine': dc_quads_fine, 'coarse': dc_quads_coarse} dc_manifolds = {'fine': dc_manifold_edges_fine, 'coarse': dc_manifold_edges_coarse} print "checking for remaining non-manifold edges on coarse level:" nonmanifold = [] edge_usage = generate_edge_usage_dict(dc_quads_coarse) for edge_identifier, used_by_quads in edge_usage.items(): if used_by_quads.__len__() != 2: nonmanifold.append(np.array(edge_identifier)) try: assert nonmanifold.__len__() == 0 and not_resolved_edges_coarse.__len__() == 0 except AssertionError as e: import traceback, os.path top = traceback.extract_stack()[-1] print '\n' print ', '.join([os.path.basename(top[0]), str(top[1])]) print "ERROR found. exporting intermediate results." export_results.export_as_csv(dc_verts_fine, './PYTHON/NURBSReconstruction/DualContouring/plotting/dc_verts_fine') export_results.export_as_csv(dc_quads_fine, './PYTHON/NURBSReconstruction/DualContouring/plotting/dc_quads_fine') export_results.export_as_csv(dc_verts_coarse, './PYTHON/NURBSReconstruction/DualContouring/plotting/dc_verts_coarse') export_results.export_as_csv(dc_quads_coarse, './PYTHON/NURBSReconstruction/DualContouring/plotting/dc_quads_coarse') export_results.export_as_csv(np.array(nonmanifold), './PYTHON/NURBSReconstruction/DualContouring/plotting/dc_non_manifold_edges') export_results.export_as_csv([coarse_dataset._dimensions['min'], coarse_dataset._dimensions['max']], './PYTHON/NURBSReconstruction/DualContouring/plotting/dc_dimensions') print "dc_non_manifold_edges references all the vertices connected by a non-manifold edge." print PColors.FAIL + "ERROR: Not all manifold edges have been successfully resolved! Aborting." + PColors.ENDC quit() datasets = {'fine': fine_dataset, 'coarse': coarse_dataset} return dc_verts, dc_quads, dc_manifolds, datasets