def rawoaasolve(agent, sparkgoal, sparkparams, sparkpattern=None): oaa = _oaa(agent) iclgoal = value_to_icl(sparkgoal) iclparams = value_to_icl(sparkparams) iclanswers = IclList() debug("calling oaaSolve on %s", iclgoal) functor = iclgoal.functor logInfo("rawoaasolve[%s]"%functor) result = oaa.oaaSolve(iclgoal, iclparams, iclanswers) logInfo("rawoaasolve complete[%s]"%functor) if result: debug("oaaSolve returned success: %s", iclanswers) if not iclanswers.isList(): raise LowError("The call to oaaSolve returned a non-IclList answer: %s"%iclanswers) if sparkpattern is None: ans = icl_to_value(iclanswers) else: bindings = HashMap() iclpattern = value_to_icl(sparkpattern) anslist = [] for iclans in iclanswers.iterator(): bindings.clear() if UNIFIER.matchTerms(iclans, iclgoal, bindings): anslist.append(icl_to_value(UNIFIER.deref(iclpattern, bindings))) else: raise LowError("The call to oaaSolve returned an answer that doesn't unify with the query:\nans=%s\query=%s"%(iclans, iclgoal)) ans = List(anslist) logInfo("rawoaasolve answers deconstructed[%s]"%functor) return ans else: debug("oaaSolve return failure: %s", iclanswers) logError("rawoaasolve return failure with answers [%s]"%iclanswers) raise OAAError("The call to oaaSolve [goal %s] failed and returned %s"\ %(functor, iclanswers))
def rawoaasolve(agent, sparkgoal, sparkparams, sparkpattern=None): oaa = _oaa(agent) iclgoal = value_to_icl(sparkgoal) iclparams = value_to_icl(sparkparams) iclanswers = IclList() debug("calling oaaSolve on %s", iclgoal) functor = iclgoal.functor logInfo("rawoaasolve[%s]" % functor) result = oaa.oaaSolve(iclgoal, iclparams, iclanswers) logInfo("rawoaasolve complete[%s]" % functor) if result: debug("oaaSolve returned success: %s", iclanswers) if not iclanswers.isList(): raise LowError( "The call to oaaSolve returned a non-IclList answer: %s" % iclanswers) if sparkpattern is None: ans = icl_to_value(iclanswers) else: bindings = HashMap() iclpattern = value_to_icl(sparkpattern) anslist = [] for iclans in iclanswers.iterator(): bindings.clear() if UNIFIER.matchTerms(iclans, iclgoal, bindings): anslist.append( icl_to_value(UNIFIER.deref(iclpattern, bindings))) else: raise LowError( "The call to oaaSolve returned an answer that doesn't unify with the query:\nans=%s\query=%s" % (iclans, iclgoal)) ans = List(anslist) logInfo("rawoaasolve answers deconstructed[%s]" % functor) return ans else: debug("oaaSolve return failure: %s", iclanswers) logError("rawoaasolve return failure with answers [%s]" % iclanswers) raise OAAError("The call to oaaSolve [goal %s] failed and returned %s"\ %(functor, iclanswers))
else: if options.preserveGroups: liaison.getMesh().buildGroupBoundaries() #0 writeVTK(liaison) opts = HashMap() opts.put("coplanarity", "0.9") opts.put("size", str(options.size * 0.06)) QEMDecimateHalfEdge(liaison, opts).compute() #1 writeVTK(liaison) opts.clear() opts.put("size", str(options.size)) Remesh(liaison, opts).compute() #2 writeVTK(liaison) opts.clear() opts.put("coplanarity", "0.9") SwapEdge(liaison, opts).compute() #3 writeVTK(liaison) opts.clear() opts.put("size", str(options.size * 0.3))
def __remesh(options): afront_stderr = getattr(options, 'afront_stderr', None) mesh = getattr(options, 'mesh', None) liaison = getattr(options, 'liaison', None) if not liaison: if not mesh: mesh = create_mesh(**options) liaison = MeshLiaison.create(mesh) if options.recordFile: liaison.getMesh().getTrace().setDisabled(False) liaison.getMesh().getTrace().setLogFile(options.recordFile) liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh()) if options.immutable_border: liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE) liaison.getMesh().buildRidges(options.coplanarity) if options.immutable_border_group: liaison.mesh.tagGroupBoundaries(AbstractHalfEdge.IMMUTABLE) else: if options.preserveGroups: liaison.getMesh().buildGroupBoundaries() immutable_groups = [] if options.immutable_groups_file: immutable_groups = read_groups(options.immutable_groups_file) liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE) if options.point_metric_file: point_metric = DistanceMetric(options.size, options.point_metric_file) elif getattr(options, 'point_metric', None): point_metric = options.point_metric else: point_metric = None safe_coplanarity = str(max(options.coplanarity, 0.8)) if options.forced_points: if point_metric: vi = VertexInsertion(liaison, point_metric) else: vi = VertexInsertion(liaison, options.size) vi.insertNodes(options.forced_points, -1) Vertex.setMutable(vi.mutableInserted, False) #0 writeVTK(liaison) if options.boundary_angle == None: options.boundary_angle = 1.66 if point_metric: point_metric.scaling = 1 if options.forced_bounds: BeamInsertion(liaison.mesh, point_metric).insert(options.forced_bounds[0], options.forced_bounds[1]) RemeshSkeleton(liaison, options.boundary_angle, options.size / 100.0, point_metric).compute() else: RemeshSkeleton(liaison, options.boundary_angle, options.size / 100.0, options.size).compute() if options.forced_bounds: BeamInsertion(liaison.mesh, options.size).insert(options.forced_bounds[0], options.forced_bounds[1]) #1 writeVTK(liaison) opts = HashMap() opts.put("coplanarity", safe_coplanarity) # Swapping here will help QEMDecimateHalfEdge to decimate more and will # reduce the risk to have edge not processed by LengthDecimateHalfEdge algo = SwapEdge(liaison, opts) algo.maxSwapVolume = (options.size / 4.0)**3 algo.compute() #2 writeVTK(liaison) if options.recordFile: cmds = [ String("assert self.m.checkNoDegeneratedTriangles()"), String("assert self.m.checkNoInvertedTriangles()"), String("assert self.m.checkVertexLinks()"), String("assert self.m.isValid()") ] liaison.getMesh().getTrace().setHooks(cmds) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("size", str(options.size * 0.3)) opts.put("maxlength", str(options.size * sqrt(2))) #workaround for a QEMDecimateHalfEdge bug opts.put("freezeNonManifold", "true") algo = QEMDecimateHalfEdge(liaison, opts) if point_metric: point_metric.scaling = sqrt(2) algo.analyticMetric = point_metric algo.compute() #3 # afront call writeVTK(liaison) afront_nodes_reader = None afront_frozen = None if options.afront_path: tmp_dir = tempfile.mkdtemp() afront_nodes_reader = afront(options.afront_path, tmp_dir, liaison.mesh, options.size, point_metric, immutable_groups, afront_stderr=afront_stderr) afront_frozen = afront_insert(liaison, afront_nodes_reader, options.size, point_metric) Vertex.setMutable(afront_frozen, False) #4 writeVTK(liaison) if options.afront_path: opts.clear() opts.put("expectInsert", "false") opts.put("coplanarity", safe_coplanarity) SwapEdge(liaison, opts).compute() #5 writeVTK(liaison) opts.clear() opts.put("size", str(options.size)) opts.put("freeEdgesOnly", "true") opts.put("coplanarity", "-2") algo = LengthDecimateHalfEdge(liaison, opts) if point_metric: algo.analyticMetric = point_metric algo.compute() #6 writeVTK(liaison) opts.clear() opts.put("size", str(options.size)) opts.put("coplanarity", str(options.coplanarity)) opts.put("minCosAfterSwap", "0.3") opts.put("nearLengthRatio", "0.6") algo = Remesh(liaison, opts) if point_metric: point_metric.scaling = 1 algo.analyticMetric = point_metric algo.compute() #7 writeVTK(liaison) opts.clear() opts.put("coplanarity", safe_coplanarity) opts.put("expectInsert", "false" if options.afront_path else "true") SwapEdge(liaison, opts).compute() #8 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("iterations", "2") opts.put("size", str(options.size)) algo = SmoothNodes3DBg(liaison, opts) algo.compute() #9 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("expectInsert", "false" if options.afront_path else "true") opts.put("minCosAfterSwap", "0.3") SwapEdge(liaison, opts).compute() #10 writeVTK(liaison) if not options.afront_path: opts.clear() opts.put("size", str(options.size)) algo = Remesh(liaison, opts) algo.analyticMetric = point_metric algo.compute() #11 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("size", str(options.size * 0.3)) opts.put("maxlength", str(options.size * sqrt(2))) #workaround for a QEMDecimateHalfEdge bug opts.put("freezeNonManifold", "true") algo = QEMDecimateHalfEdge(liaison, opts) if point_metric: point_metric.scaling = sqrt(2) algo.analyticMetric = point_metric algo.compute() #12 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("expectInsert", "false" if options.afront_path else "true") opts.put("minCosAfterSwap", "0.3") SwapEdge(liaison, opts).compute() #13 writeVTK(liaison) if afront_frozen: Vertex.setMutable(afront_frozen, True) opts.clear() opts.put("checkNormals", "false") ImproveVertexValence(liaison, opts).compute() #14 writeVTK(liaison) opts.clear() opts.put("coplanarity", safe_coplanarity) opts.put("iterations", str(8)) algo = SmoothNodes3DBg(liaison, opts) algo.compute() #15 writeVTK(liaison) #MeshWriter.writeObject3D(liaison.mesh, outDir, "" polylines = PolylineFactory(liaison.mesh, 135.0, options.size * 0.2) liaison.mesh.resetBeams() for entry in polylines.entrySet(): groupId = entry.key for polyline in entry.value: listM = ArrayList() for v in polyline: listM.add(EuclidianMetric3D(options.size)) #print "Remesh polyline of group "+str(groupId)+"/"+str(polylines.size())+" "+str(polyline.size())+" vertices" if liaison.mesh.getGroupName(groupId) in immutable_groups: result = polyline else: result = RemeshPolyline(liaison.mesh, polyline, listM).compute() for i in xrange(result.size() - 1): liaison.mesh.addBeam(result.get(i), result.get(i + 1), groupId) #print " New polyline: "+str(result.size())+" vertices" if options.recordFile: liaison.getMesh().getTrace().finish() if options.post_script: execfile(options.post_script) MeshWriter.writeObject3D(liaison.mesh, options.out_dir, "")
def __remesh(options): afront_stderr = getattr(options, 'afront_stderr', None) mesh = getattr(options, 'mesh', None) liaison = getattr(options, 'liaison', None) if not liaison: if not mesh: mesh = create_mesh(**options) liaison = MeshLiaison.create(mesh) if options.recordFile: liaison.getMesh().getTrace().setDisabled(False) liaison.getMesh().getTrace().setLogFile(options.recordFile) liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh()) if options.immutable_border: liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE) liaison.getMesh().buildRidges(options.coplanarity) if options.immutable_border_group: liaison.mesh.tagGroupBoundaries(AbstractHalfEdge.IMMUTABLE) else: if options.preserveGroups: liaison.getMesh().buildGroupBoundaries() immutable_groups = [] if options.immutable_groups_file: immutable_groups = read_groups(options.immutable_groups_file) liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE) if options.point_metric_file: point_metric = DistanceMetric(options.size, options.point_metric_file) elif getattr(options, 'point_metric', None): point_metric = options.point_metric else: point_metric = None safe_coplanarity = str(max(options.coplanarity, 0.8)) if options.forced_points: if point_metric: vi = VertexInsertion(liaison, point_metric) else: vi = VertexInsertion(liaison, options.size) vi.insertNodes(options.forced_points, -1) Vertex.setMutable(vi.mutableInserted, False) #0 writeVTK(liaison) if options.boundary_angle == None: options.boundary_angle = 1.66 if point_metric: point_metric.scaling = 1 if options.forced_bounds: BeamInsertion(liaison.mesh, point_metric).insert( options.forced_bounds[0], options.forced_bounds[1]) RemeshSkeleton(liaison, options.boundary_angle, options.size / 100.0, point_metric).compute() else: RemeshSkeleton(liaison, options.boundary_angle, options.size / 100.0, options.size).compute() if options.forced_bounds: BeamInsertion(liaison.mesh, options.size).insert( options.forced_bounds[0], options.forced_bounds[1]) #1 writeVTK(liaison) opts = HashMap() opts.put("coplanarity", safe_coplanarity) # Swapping here will help QEMDecimateHalfEdge to decimate more and will # reduce the risk to have edge not processed by LengthDecimateHalfEdge algo = SwapEdge(liaison, opts) algo.maxSwapVolume = (options.size / 4.0)**3 algo.compute() #2 writeVTK(liaison) if options.recordFile: cmds = [ String("assert self.m.checkNoDegeneratedTriangles()"), String("assert self.m.checkNoInvertedTriangles()"), String("assert self.m.checkVertexLinks()"), String("assert self.m.isValid()") ] liaison.getMesh().getTrace().setHooks(cmds) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("size", str(options.size*0.3)) opts.put("maxlength", str(options.size*sqrt(2))) #workaround for a QEMDecimateHalfEdge bug opts.put("freezeNonManifold", "true") algo = QEMDecimateHalfEdge(liaison, opts) if point_metric: point_metric.scaling = sqrt(2) algo.analyticMetric = point_metric algo.compute() #3 # afront call writeVTK(liaison) afront_nodes_reader = None afront_frozen = None if options.afront_path: tmp_dir = tempfile.mkdtemp() afront_nodes_reader = afront(options.afront_path, tmp_dir, liaison.mesh, options.size, point_metric, immutable_groups, afront_stderr = afront_stderr) afront_frozen = afront_insert(liaison, afront_nodes_reader, options.size, point_metric) Vertex.setMutable(afront_frozen, False) shutil.rmtree(tmp_dir, ignore_errors=True) #4 writeVTK(liaison) if options.afront_path: opts.clear() opts.put("expectInsert", "false") opts.put("coplanarity", safe_coplanarity) SwapEdge(liaison, opts).compute() #5 writeVTK(liaison) opts.clear() opts.put("size", str(options.size)) opts.put("freeEdgesOnly", "true") opts.put("coplanarity", "-2") algo = LengthDecimateHalfEdge(liaison, opts) if point_metric: algo.analyticMetric = point_metric algo.compute() #6 writeVTK(liaison) opts.clear() opts.put("size", str(options.size)) opts.put("coplanarity", str(options.coplanarity)) opts.put("minCosAfterSwap", "0.3") opts.put("nearLengthRatio", "0.6") algo = Remesh(liaison, opts) if point_metric: point_metric.scaling = 1 algo.analyticMetric = point_metric algo.compute() #7 writeVTK(liaison) opts.clear() opts.put("coplanarity", safe_coplanarity) opts.put("expectInsert", "false" if options.afront_path else "true") SwapEdge(liaison, opts).compute() #8 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("iterations", "2") opts.put("size", str(options.size)) algo = SmoothNodes3DBg(liaison, opts) algo.compute() #9 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("expectInsert", "false" if options.afront_path else "true") opts.put("minCosAfterSwap", "0.3") algo = SwapEdge(liaison, opts) algo.angleQualityRatio = 150 algo.compute() #10 writeVTK(liaison) if not options.afront_path: opts.clear() opts.put("size", str(options.size)) algo = Remesh(liaison, opts) algo.analyticMetric = point_metric algo.compute() #11 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("size", str(options.size*0.3)) opts.put("maxlength", str(options.size*sqrt(2))) #workaround for a QEMDecimateHalfEdge bug opts.put("freezeNonManifold", "true") algo = QEMDecimateHalfEdge(liaison, opts) if point_metric: point_metric.scaling = sqrt(2) algo.analyticMetric = point_metric algo.compute() #12 writeVTK(liaison) opts.clear() opts.put("coplanarity", str(options.coplanarity)) opts.put("expectInsert", "false" if options.afront_path else "true") opts.put("minCosAfterSwap", "0.3") algo = SwapEdge(liaison, opts) algo.angleQualityRatio = 150 algo.compute() #13 writeVTK(liaison) if afront_frozen: Vertex.setMutable(afront_frozen, True) opts.clear() opts.put("checkNormals", "false") ImproveVertexValence(liaison, opts).compute() #14 writeVTK(liaison) opts.clear() opts.put("coplanarity", safe_coplanarity) opts.put("iterations", str(8)) algo = SmoothNodes3DBg(liaison, opts) algo.compute() #15 writeVTK(liaison) #MeshWriter.writeObject3D(liaison.mesh, outDir, "" polylines=PolylineFactory(liaison.mesh, 135.0, options.size*0.2) liaison.mesh.resetBeams() for entry in polylines.entrySet(): groupId = entry.key for polyline in entry.value: listM = ArrayList() for v in polyline: listM.add(EuclidianMetric3D(options.size)) #print "Remesh polyline of group "+str(groupId)+"/"+str(polylines.size())+" "+str(polyline.size())+" vertices" if liaison.mesh.getGroupName(groupId) in immutable_groups: result = polyline elif point_metric: result = RemeshPolyline(liaison.mesh, polyline, point_metric).compute() else: result = RemeshPolyline(liaison.mesh, polyline, listM).compute() for i in xrange(result.size() - 1): liaison.mesh.addBeam(result.get(i), result.get(i+1), groupId) #print " New polyline: "+str(result.size())+" vertices" if options.recordFile: liaison.getMesh().getTrace().finish() if options.post_script: execfile(options.post_script) if options.out_dir: MeshWriter.writeObject3D(liaison.mesh, options.out_dir, "")
else: if options.preserveGroups: liaison.getMesh().buildGroupBoundaries() #0 writeVTK(liaison) opts = HashMap() opts.put("coplanarity", "0.9") opts.put("size", str(options.size*0.06)) QEMDecimateHalfEdge(liaison, opts).compute() #1 writeVTK(liaison) opts.clear() opts.put("size", str(options.size)) Remesh(liaison, opts).compute() #2 writeVTK(liaison) opts.clear() opts.put("coplanarity", "0.9") SwapEdge(liaison, opts).compute() #3 writeVTK(liaison) opts.clear() opts.put("size", str(options.size*0.3))
class TtlCache(Map, K, V): """ generated source for class TtlCache """ class Entry(object): """ generated source for class Entry """ ttl = int() value = V() def __init__(self, value, ttl): """ generated source for method __init__ """ self.value = value self.ttl = ttl @SuppressWarnings("unchecked") def equals(self, o): """ generated source for method equals """ if isinstance(o, (self.Entry, )): return (o).value == self.value return False contents = Map() ttl = int() def __init__(self, ttl): """ generated source for method __init__ """ super(TtlCache, self).__init__() self.contents = HashMap() self.ttl = ttl @synchronized def containsKey(self, key): """ generated source for method containsKey """ return self.contents.containsKey(key) @synchronized def get(self, key): """ generated source for method get """ entry = self.contents.get(key) if entry == None: return None # Reset the TTL when a value is accessed directly. entry.ttl = self.ttl return entry.value @synchronized def prune(self): """ generated source for method prune """ toPrune = ArrayList() for key in contents.keySet(): if entry.ttl == 0: toPrune.add(key) entry.ttl -= 1 for key in toPrune: self.contents.remove(key) @synchronized def put(self, key, value): """ generated source for method put """ x = self.contents.put(key, self.Entry(value, self.ttl)) if x == None: return None return x.value @synchronized def size(self): """ generated source for method size """ return len(self.contents) @synchronized def clear(self): """ generated source for method clear """ self.contents.clear() @synchronized def containsValue(self, value): """ generated source for method containsValue """ return self.contents.containsValue(value) @synchronized def isEmpty(self): """ generated source for method isEmpty """ return self.contents.isEmpty() @synchronized def keySet(self): """ generated source for method keySet """ return self.contents.keySet() @synchronized def putAll(self, m): """ generated source for method putAll """ for anEntry in m.entrySet(): self.put(anEntry.getKey(), anEntry.getValue()) @synchronized def remove(self, key): """ generated source for method remove """ return self.contents.remove(key).value @synchronized def values(self): """ generated source for method values """ theValues = HashSet() for e in contents.values(): theValues.add(e.value) return theValues class entrySetMapEntry(Map, Entry, K, V): """ generated source for class entrySetMapEntry """ key = K() value = V() def __init__(self, k, v): """ generated source for method __init__ """ super(entrySetMapEntry, self).__init__() self.key = k self.value = v def getKey(self): """ generated source for method getKey """ return self.key def getValue(self): """ generated source for method getValue """ return self.value def setValue(self, value): """ generated source for method setValue """ return (self.value = value) @synchronized def entrySet(self): """ generated source for method entrySet """ theEntries = HashSet() for e in contents.entrySet(): theEntries.add(self.entrySetMapEntry(e.getKey(), e.getValue().value)) return theEntries