def drawPixel(self, device, pixel, microstructure): n0, n1, n2, n3 = self.getNodes(pixel, microstructure) device.set_lineColor(self.color) device.set_lineWidth(self.line_width) device.draw_segment(primitives.Segment(n0, n1)) device.draw_segment(primitives.Segment(n1, n2)) device.draw_segment(primitives.Segment(n2, n3)) device.draw_segment(primitives.Segment(n3, n0))
def drawPixel(self, device, pixel, microstructure): # 2D only dx = microstructure.sizeOfPixels()[0] dy = microstructure.sizeOfPixels()[1] i = pixel.x j = pixel.y n0 = primitives.Point(i*dx, j*dy) n1 = primitives.Point((i+1)*dx, j*dy) n2 = primitives.Point((i+1)*dx, (j+1)*dy) n3 = primitives.Point(i*dx, (j+1)*dy) device.set_lineColor(self.color) device.set_lineWidth(self.line_width) device.draw_segment(primitives.Segment(n0, n1)) device.draw_segment(primitives.Segment(n1, n2)) device.draw_segment(primitives.Segment(n2, n3)) device.draw_segment(primitives.Segment(n3, n0))
def draw(self, gfxwindow, canvas): # 2D only skel = self.who().resolve(gfxwindow) skelobj = skel.getObject() canvas.set_lineColor(self.color) for k in self.boundaries: try: b = skelobj.edgeboundaries[k] except KeyError: pass else: for e in b.edges: nodes = e.get_nodes() canvas.set_lineWidth(self.linewidth) canvas.draw_segment(primitives.Segment( nodes[0].position(), nodes[1].position())) # Boundaries are directed from 0 to 1. center = (nodes[0].position() + nodes[1].position())/2 diff = (nodes[1].position() - nodes[0].position()) # Zero of angles is the y-axis, not the x-axis... angle = math.atan2(-diff.x, diff.y) canvas.set_lineWidth(self.arrowsize) # ? canvas.draw_triangle(center, angle) canvas.set_lineWidth(self.dotsize) canvas.set_fillColor(self.color) for k in self.boundaries: try: b = skelobj.pointboundaries[k] except KeyError: pass else: for n in b.nodes: canvas.draw_dot(n.position())
def get_elemental_segments(self): cs_obj = self.meshctxt.getCrossSection(self.cross_section) (real_start, real_end) = self.get_endpoints() local_segment = primitives.Segment(real_start, real_end) skeleton = self.skeleton start_el = skeleton.enclosingElement(real_start) result = [] # "last" means "most recent", and is distinct from "final". last_pt = cs_obj.start last_el = start_el try: # HACK: Because of round-off, the first call to this # function can see two intersections, but the first one is # spurious. If this happens, re-run it, but tell it about # the spurious intersection. (isec, new_el) = \ skeleton.get_intersection_and_next_element( local_segment, last_el, None) except ooferror.ErrPyProgrammingError, e: if e.summary()=="Segment exits element multiple times.": (isec, new_el) = \ skeleton.get_intersection_and_next_element( local_segment, last_el, real_start) else: raise
def draw(self, gfxwindow, canvas): meshctxt = self.who().resolve(gfxwindow) femesh = meshctxt.getObject() #canvas.comment("InterfaceElementDisplay") canvas.set_lineColor(self.color) canvas.set_lineWidth(self.width) ANYstring = materialparameter.InterfaceAnyMaterialParameter.extranames[ 0] NONEstring = materialparameter.InterfaceAnyMaterialParameter.extranames[ 1] try: meshctxt.restoreCachedData(self.getTime(meshctxt)) if self.boundary == placeholder.every.IDstring: for edgement in femesh.edgement_iterator(): if self.material != ANYstring: if edgement.material(): matname = edgement.material().name() else: matname = NONEstring if self.material != matname: continue el_edges = edgement.perimeter() for edge in el_edges: ## TODO 3.1: Update to use MeshNodePosition ## instead of PositionOutput. pts = self.where.evaluate(femesh, [edge], [[0.0, 1.0]]) canvas.draw_segment(primitives.Segment(pts[0], pts[1])) else: # boundary != every for edgement in femesh.edgement_iterator(): if self.material != ANYstring: if edgement.material(): matname = edgement.material().name() else: matname = NONEstring if self.material != matname: continue if self.boundary not in edgement.namelist(): continue el_edges = edgement.perimeter() for edge in el_edges: ## TODO 3.1: Update to use MeshNodePosition ## instead of PositionOutput. pts = self.where.evaluate(femesh, [edge], [[0.0, 1.0]]) canvas.draw_segment(primitives.Segment(pts[0], pts[1])) finally: meshctxt.releaseCachedData()
def draw(self, gfxwindow, device): mesh = self.who().resolve(gfxwindow) device.set_lineColor(self.color) device.set_lineWidth(self.linewidth) if self.cross_sections == placeholder.selection: cstoolbox = gfxwindow.getToolboxByName('Mesh_Cross_Section') cs = mesh.selectedCS() if cs: device.draw_segment(primitives.Segment(cs.start, cs.end)) else: # List of cs names. for k in self.cross_sections: try: b = mesh.cross_sections[k] except KeyError: pass else: device.draw_segment(primitives.Segment(b.start, b.end))
def draw(self, gfxwindow, device): meshctxt = self.who().resolve(gfxwindow) femesh = meshctxt.getObject() device.comment("InterfaceElementDisplay") device.set_lineColor(self.color) device.set_lineWidth(self.width) ANYstring = materialparameter.InterfaceAnyMaterialParameter.extranames[ 0] NONEstring = materialparameter.InterfaceAnyMaterialParameter.extranames[ 1] try: meshctxt.restoreCachedData(self.getTime(meshctxt, gfxwindow)) if self.boundary == placeholder.every.IDstring: for edgement in femesh.edgement_iterator(): if self.material != ANYstring: if edgement.material(): matname = edgement.material().name() else: matname = NONEstring if self.material != matname: continue el_edges = edgement.perimeter() for edge in el_edges: pts = self.where.evaluate(femesh, [edge], [[0.0, 1.0]]) device.draw_segment(primitives.Segment(pts[0], pts[1])) else: for edgement in femesh.edgement_iterator(): if self.material != ANYstring: if edgement.material(): matname = edgement.material().name() else: matname = NONEstring if self.material != matname: continue if self.boundary not in edgement.namelist(): continue el_edges = edgement.perimeter() for edge in el_edges: pts = self.where.evaluate(femesh, [edge], [[0.0, 1.0]]) device.draw_segment(primitives.Segment(pts[0], pts[1])) finally: meshctxt.releaseCachedData()
def drawElement(self, device, element, which="query"): device.set_lineColor(self.colors[which]) device.set_lineWidth(self.element_width) if config.dimension() == 2: for i in range(element.nnodes()): n0 = element.nodes[i] n1 = element.nodes[(i + 1) % element.nnodes()] device.draw_segment( primitives.Segment(n0.position(), n1.position())) elif config.dimension() == 3: device.draw_cell(element)
def drawSegment(self, device, segment, which="query"): device.set_lineColor(self.colors[which]) device.set_lineWidth(self.segment_width) if config.dimension() == 2: device.draw_segment( primitives.Segment(segment.nodes()[0].position(), segment.nodes()[1].position())) elif config.dimension() == 3: # this is a hack, later on when vtk and oof are more # streamlined, we shouldn't have to create a vtkLine # twice. device.draw_cell(segment.getVtkLine())
def draw(self, gfxwindow, canvas): # 2D only skel = self.who().resolve(gfxwindow).getObject() elements = skel.getIllegalElements() if elements: canvas.set_lineColor(self.color) canvas.set_lineWidth(self.linewidth) # if config.dimension() == 2: for el in elements: for i in range(el.nnodes()): n0 = el.nodes[i] n1 = el.nodes[(i + 1) % el.nnodes()] canvas.draw_segment( primitives.Segment(n0.position(), n1.position()))
def get_elemental_segments(self): result = [] skel = self.meshctxt.getParent().getObject() bdy = skel.edgeboundaries[self.boundary] for edge in bdy.edges: nodes = edge.get_nodes() if self.side == 'LEFT': el = edge.getLeftElement() else: el = edge.getRightElement() result.append((primitives.Segment(nodes[0].position(), nodes[1].position()), self.femesh.getElement(el.meshindex))) return result
def draw(self, gfxwindow, device): skel = self.who().resolve(gfxwindow) skelobj = skel.getObject() device.set_lineColor(self.color) for k in self.boundaries: try: b = skelobj.edgeboundaries[k] except KeyError: pass else: if config.dimension() == 2: for e in b.edges: nodes = e.get_nodes() device.set_lineWidth(self.linewidth) device.draw_segment( primitives.Segment(nodes[0].position(), nodes[1].position())) # Boundaries are directed from 0 to 1. center = (nodes[0].position() + nodes[1].position()) / 2 diff = (nodes[1].position() - nodes[0].position()) # Zero of angles is the y-axis, not the x-axis... angle = math.atan2(-diff.x, diff.y) device.set_lineWidth(self.arrowsize) device.draw_triangle(center, angle) elif config.dimension() == 3: numedges = len(b.edges) if numedges: gridPoints = skelobj.getPoints() grid = vtk.vtkPolyData() grid.Allocate(numedges, numedges) grid.SetPoints(gridPoints) for e in b.edges: line = e.getVtkLine() grid.InsertNextCell(line.GetCellType(), line.GetPointIds()) device.draw_unstructuredgrid(grid) # TODO 3D: add glyphs device.set_lineWidth(self.dotsize) device.set_fillColor(self.color) for k in self.boundaries: try: b = skelobj.pointboundaries[k] except KeyError: pass else: for n in b.nodes: device.draw_dot(n.position())
def drawElement(self, device, toolbox, element, which="query"): device.set_lineColor(self.colors[which]) device.set_lineWidth(self.element_width) if config.dimension() == 2: node_iter = element.cornernode_iterator().exteriornode_iterator() p_list = [node.position() for node in node_iter] displaced_p_list = [ toolbox.meshlayer.displaced_from_undisplaced( toolbox.gfxwindow, x) for x in p_list] for i in range(len(displaced_p_list)): p0 = displaced_p_list[i] p1 = displaced_p_list[(i+1)%len(displaced_p_list)] device.draw_segment(primitives.Segment(p0, p1)) elif config.dimension() == 3: device.draw_cell(element)
def draw(self, displaymethod, device, pixel, microstructure): # Called by PixelInfoDisplay.draw() if self.referenceOrientation is not None: n0, n1, n2, n3 = displaymethod.getNodes(self.referencePoint, microstructure) device.draw_segment(primitives.Segment(n0, n1)) device.draw_segment(primitives.Segment(n1, n2)) device.draw_segment(primitives.Segment(n2, n3)) device.draw_segment(primitives.Segment(n3, n0)) device.draw_segment( primitives.Segment(0.25 * (3 * n0 + n2), 0.25 * (5 * n0 - n2))) device.draw_segment( primitives.Segment(0.25 * (3 * n2 + n0), 0.25 * (5 * n2 - n0))) device.draw_segment( primitives.Segment(0.25 * (3 * n1 + n3), 0.25 * (5 * n1 - n3))) device.draw_segment( primitives.Segment(0.25 * (3 * n3 + n1), 0.25 * (5 * n3 - n1)))
def draw(self, gfxwindow, device): themesh = self.who().resolve(gfxwindow) femesh = themesh.getObject() themesh.restoreCachedData(self.getTime(themesh, gfxwindow)) try: device.comment("PerimeterDisplay") device.set_lineColor(self.color) device.set_lineWidth(self.width) for element in femesh.element_iterator(): el_edges = element.perimeter() for edge in el_edges: if element.exterior(edge.startpt(), edge.endpt()): pts = self.where.evaluate(femesh, [edge], [[0.0, 1.0]]) device.draw_segment(primitives.Segment(pts[0], pts[1])) finally: themesh.releaseCachedData()
def drawEdgeBoundary(self, bdy, skelobj, device): b = bdy.boundary(skelobj) device.set_lineColor(self.color) if config.dimension() == 2: for e in b.edges: nodes = e.get_nodes() n0 = nodes[0].position() n1 = nodes[1].position() device.set_lineWidth(self.linewidth) device.draw_segment(primitives.Segment(n0, n1)) # Boundaries are directed from 0 to 1. center = (n0 + n1) / 2 diff = (n1 - n0) # Zero of angles is the y-axis, not the x-axis... angle = math.atan2(-diff.x, diff.y) device.set_lineWidth(self.arrowsize) device.draw_triangle(center, angle) elif config.dimension() == 3: numedges = len(b.edges) device.set_lineWidth(self.linewidth) device.set_glyphSize(self.arrowsize) if numedges: gridPoints = skelobj.getPoints() grid = vtk.vtkPolyData() grid.Allocate(numedges, numedges) grid.SetPoints(gridPoints) normalarray = vtk.vtkDoubleArray() normalarray.SetNumberOfComponents(3) for e in b.edges: line = e.getVtkLine() grid.InsertNextCell(line.GetCellType(), line.GetPointIds()) nodes = e.get_nodes() n0 = nodes[0].position() n1 = nodes[1].position() d = (n1 - n0) normalarray.InsertNextTuple3(d[0], d[1], d[2]) findcenters = vtk.vtkCellCenters() findcenters.SetInput(grid) centers = findcenters.GetOutput() centers.Update() # we must do this *after* we call Update, otherwise # the data will be overwritten centers.GetPointData().SetNormals(normalarray) device.draw_unstructuredgrid(grid) device.draw_cone_glyphs(centers)
def draw(self, gfxwindow, canvas): themesh = self.who().resolve(gfxwindow) femesh = themesh.getObject() themesh.restoreCachedData(self.getTime(themesh)) try: #canvas.comment("PerimeterDisplay") canvas.set_lineColor(self.color) canvas.set_lineWidth(self.width) for element in femesh.elements(): el_edges = element.perimeter() for edge in el_edges: ## TODO 3.1: Update to use MeshNodePosition instead of ## PositionOutput. if element.exterior(edge.startpt(), edge.endpt()): pts = self.where.evaluate(femesh, [edge], [[0.0, 1.0]]) canvas.draw_segment(primitives.Segment(pts[0], pts[1])) finally: themesh.releaseCachedData()
def draw(self, gfxwindow, device): skel = self.who().resolve(gfxwindow) if skel is not None: device.set_lineColor(self.color) device.set_lineWidth(self.line_width) if config.dimension() == 2: for s in skel.segmentselection.retrieve(): device.draw_segment(primitives.Segment(s.nodes()[0].position(), s.nodes()[1].position())) elif config.dimension() == 3: numsegs = len(skel.segmentselection.retrieve()) if numsegs: gridPoints = skel.getObject().getPoints() grid = vtk.vtkUnstructuredGrid() grid.Allocate(numsegs,numsegs) grid.SetPoints(gridPoints) for s in skel.segmentselection.retrieve(): line = s.getVtkLine() grid.InsertNextCell(line.GetCellType(), line.GetPointIds()) device.draw_unstructuredgrid(grid)
def draw(self, gfxwindow, device): skel = self.who().resolve(gfxwindow).getObject() elements = skel.getIllegalElements() if elements: device.set_lineColor(self.color) device.set_lineWidth(self.linewidth) if config.dimension() == 2: for el in elements: for i in range(el.nnodes()): n0 = el.nodes[i] n1 = el.nodes[(i + 1) % el.nnodes()] device.draw_segment( primitives.Segment(n0.position(), n1.position())) elif config.dimension() == 3: if len(elements): gridPoints = skel.getPoints() grid = vtk.vtkUnstructuredGrid() numCells = len(elements) grid.Allocate(numCells, numCells) grid.SetPoints(gridPoints) for el in elements: grid.InsertNextCell(el.getCellType(), el.getPointIds()) device.draw_unstructuredgrid(grid)
class CrossSectionDomain(Domain): def __init__(self, cross_section): self.cross_section=cross_section def get_endpoints(self): # Dimension-independent version copied from OOF3D for testing # here. DIM = 2 cs_obj = self.meshctxt.getCrossSection(self.cross_section) bounds = self.meshctxt.size() errmsg = ("Segment %s, %s is entirely outside the mesh." %(cs_obj.start, cs_obj.end)) # Check that both endpoints aren't out of bounds on the same # side of the bounding box in any dimension. for i in range(DIM): if ((cs_obj.start[i] < 0 and cs_obj.end[i] < 0) or (cs_obj.start[i] > bounds[i] and cs_obj.end[i] > bounds[i])): raise ooferror.ErrUserError(errmsg) # If an endpoint is out of bounds in any dimension, project it # back onto the bounding planes. First, clone the endpoints # so that we aren't modifying the data in the cross section # object. real_start = primitives.Point(*tuple(cs_obj.start)) real_end = primitives.Point(*tuple(cs_obj.end)) for i in range(DIM): direction = real_end - real_start otherdims = [(i+j)%DIM for j in range(1, DIM)] if real_start[i] < 0: # direction[i] can't be zero if real_start[i] < 0 or # else the bounding box check above would have failed. alpha = -real_start[i]/direction[i] for j in otherdims: real_start[j] += alpha*direction[j] real_start[i] = 0 # don't allow roundoff elif real_start[i] > bounds[i]: alpha = (real_start[i] - bounds[i])/direction[i] for j in otherdims: real_start[j] -= alpha*direction[j] real_start[i] = bounds[i] if real_end[i] < 0: alpha = -real_end[i]/direction[i] for j in otherdims: real_end[j] += alpha*direction[j] real_end[i] = 0 elif real_end[i] > bounds[i]: alpha = (real_end[i] - bounds[i])/direction[i] for j in otherdims: real_end[j] -= alpha*direction[j] real_end[i] = bounds[i] # Check that the clipped segment isn't infinitesimal. This # can happen if it grazes a corner of the Microstructure. seg = real_end - real_start if seg*seg == 0: raise ooferror.ErrUserError(errmsg) # Check that the modified points are within bounds. It's # possible that they're not if the original points were placed # sufficiently perversely. for i in range(DIM): if not (0 <= real_start[i] <= bounds[i] and 0 <= real_end[i] <= bounds[i]): raise ooferror.ErrUserError(errmsg) return (real_start, real_end) # Builds (and returns) a list of tuples, each consisting of a # primitives.Segment object and a mesh element. These occur in # order from start to end, which map exactly once on to the cross # section, and whose boundaries correspond to intersections of the # cross-section with element boundaries. def get_elemental_segments(self): cs_obj = self.meshctxt.getCrossSection(self.cross_section) (real_start, real_end) = self.get_endpoints() local_segment = primitives.Segment(real_start, real_end) skeleton = self.skeleton start_el = skeleton.enclosingElement(real_start) result = [] # "last" means "most recent", and is distinct from "final". last_pt = cs_obj.start last_el = start_el try: # HACK: Because of round-off, the first call to this # function can see two intersections, but the first one is # spurious. If this happens, re-run it, but tell it about # the spurious intersection. (isec, new_el) = \ skeleton.get_intersection_and_next_element( local_segment, last_el, None) except ooferror.ErrPyProgrammingError, e: if e.summary()=="Segment exits element multiple times.": (isec, new_el) = \ skeleton.get_intersection_and_next_element( local_segment, last_el, real_start) else: raise # If the *first* call yields no intersections, then the # whole cross-section lies within one element. Return # a single segment made up of the whole cross-section. if not isec: result.append( (primitives.Segment(last_pt, real_end), self.femesh.getElement(last_el.meshindex)) ) return result # Otherwise, keep iterating until you get to the end. while new_el: result.append( (primitives.Segment(last_pt, isec), self.femesh.getElement(last_el.meshindex)) ) last_pt = isec last_el = new_el (isec, new_el) = \ skeleton.get_intersection_and_next_element( local_segment, last_el, last_pt) # Bolt on the final one. result.append( (primitives.Segment(last_pt, real_end), self.femesh.getElement(last_el.meshindex)) ) return result