def setDepth(self, depth): """ Set the box depth """ debugMsg("Called Box.setDepth()") # get the current depth oldDepth = self.getDepth() # get the current bounds (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() # add half the difference between the new depth and the old depth # to the zmin and zmax variables halfDiff = (depth - oldDepth)/2.0 zminNew = zmin - halfDiff zmaxNew = zmax + halfDiff # reset the bounds self.setBounds(xmin, xmax, ymin, ymax, zminNew, zmaxNew) # set the depth self.depth = zmaxNew - zminNew # do a check to make sure the calculated depth is what was asked # for if __debug__: newDepth = self.getDepth() assert abs(newDepth - depth) < self.tolerance, \ "Depth not set to within tolerance" return
def setBLF(self, bottom, left, front): """ Set the position of the bottom, left, front corner """ debugMsg("Called Box.setBLF()") # get the current bounds (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() # make sure that the bounds aren't silly if bottom > xmax: warnString = "bottom set too large for maximum x dimension." warnString += " Resetting to xMin." warnings.warn(warnString) bottom = xmin if left > ymax: warnString = "left set too large for maximum y dimension." warnString += " Resetting to yMin." warnings.warn(warnString) left = ymin if front > zmax: warnString = "front set too large for maximum z dimension." warnString += " Resetting to zMin." warnings.warn(warnString) front = zmin # set the new bounds self.setBounds(bottom, xmax, left, ymax, front, zmax) # set the blf variable self.blf = (bottom, left, front) return
def setWidth(self, width): """ Set the width of the box """ debugMsg("Called Box.setWidth()") # get the current width oldWidth = self.getWidth() # get the current bounds (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() # add half the difference between the new width and the old width # to the xmin and xmax variables halfDiff = (width - oldWidth)/2.0 xminNew = xmin - halfDiff xmaxNew = xmax + halfDiff # reset the bounds self.setBounds(xminNew, xmaxNew, ymin, ymax, zmin, zmax) # set the width self.width = xmaxNew - xminNew # do a check to make sure the calculated width is what was asked for if __debug__: newWidth = self.getWidth() assert abs(newWidth - width) < self.tolerance, \ "Width not set to within tolerance" return
def setHeight(self, height): """ Set the box height """ debugMsg("Called Box.setHeight()") # get the current height oldHeight = self.getHeight() # get the current bounds (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() # add half the difference between the new height and the old height # to the ymin and ymax variables halfDiff = (height - oldHeight)/2.0 yminNew = ymin - halfDiff ymaxNew = ymax + halfDiff # reset the bounds self.setBounds(xmin, xmax, yminNew, ymaxNew, zmin, zmax) # set the height self.height = ymaxNew - yminNew # do a check to make sure the calculated height is what was asked # for if __debug__: newHeight = self.getHeight() assert abs(newHeight - height) < self.tolerance, \ "Height not set to within tolerance" return
def __init__(self, scene): """ Initialisation of the OffsetPlot class @param scene: The Scene to render the plot in @type scene: Scene object """ debugMsg("Called OffsetPlot.__init__()") Plot.__init__(self, scene) self.renderer = scene.renderer self.renderer.addToInitStack("# OffsetPlot.__init__()") self.renderer.addToInitStack("_plot = vtk.vtkXYPlotActor()") self.title = None self.xlabel = None self.ylabel = None # the extra separation between curves (user set) self.sep = None # the default values for shared info self.fname = None self.format = None self.scalars = None # add the plot to the scene scene.add(self)
def render(self): """ Does OffsetPlot object specific (pre)rendering stuff """ debugMsg("Called OffsetPlot.render()") self.renderer.runString("# OffsetPlot.render()") self.renderer.runString("_renderer.AddActor2D(_plot)") # set the title if set if self.title is not None: evalString = "_plot.SetTitle(\'%s\')" % self.title self.renderer.runString(evalString) # if an xlabel is set, add it if self.xlabel is not None: evalString = "_plot.SetXTitle(\'%s\')" % self.xlabel self.renderer.runString(evalString) # if an ylabel is set, add it if self.ylabel is not None: evalString = "_plot.SetYTitle(\'%s\')" % self.ylabel self.renderer.runString(evalString) return
def __init__(self, scene): """ Initialisation of the IsosurfacePlot class @param scene: The Scene to render the plot in @type scene: Scene object """ debugMsg("Called IsosurfacePlot.__init__()") Plot.__init__(self, scene) self.renderer = scene.renderer self.renderer.addToInitStack("# IsosurfacePlot.__init__()") # labels and stuff self.title = None self.xlabel = None self.ylabel = None self.zlabel = None # how many contours? self.numContours = 5 # contour range self.contMin = None self.contMax = None # default values for fname, format and scalars self.fname = None self.format = None self.scalars = None # add the plot to the scene scene.add(self)
def setTRB(self, top, right, back): """ Set the position of the top, right, back corner """ debugMsg("Called Box.setTRB()") # get the current bounds (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() # make sure that the bounds aren't silly if top < xmin: warnString = "top set too small for minimum x dimension." warnString += " Resetting to xMax." warnings.warn(warnString) top = xmax if right < ymin: warnString = "right set too small for minimum y dimension." warnString += " Resetting to yMax." warnings.warn(warnString) right = ymax if back < zmin: warnString = "back set too small for minimum z dimension." warnString += " Resetting to zMax." warnings.warn(warnString) back = zmax # set the new bounds self.setBounds(xmin, top, ymin, right, zmin, back) # set the trb variable self.trb = (top, right, back) return
def getInsideOut(self): """ Get the current value of the inside out flag """ debugMsg("Called ClipBox.getInsideOut()") self.plot.renderer.runString("# ClipBox.getInsideOut()") return self.insideOut
def getAzimuth(self): """ Get the azimuthal angle (in degrees) of the Camera """ debugMsg("Called Camera.getAzimuth()") return self.azimuth
def _setDataFromFile(self): """ Set data to plot using an input file """ debugMsg("Called _setDataFromFile() in Plot()") return
def _setPlainData(self): """ Set data to plot using numpy objects """ debugMsg("Called _setPlainData() in Plot()") return
def render(self): """ Does PdfImage object specific (pre)rendering stuff """ debugMsg("Called PdfImage.render()") return
def render(self): """ Render the Plot object """ debugMsg("Called Plot.render()") return
def __init__(self, scene): """ Initialisation of the EllipsoidPlot class @param scene: The Scene to render the plot in @type scene: Scene object """ debugMsg("Called EllipsoidPlot.__init__()") Plot.__init__(self, scene) self.renderer = scene.renderer self.renderer.addToInitStack("# EllipsoidPlot.__init__()") # labels and stuff self.title = None self.xlabel = None self.ylabel = None self.zlabel = None # default values for fname, format and tensors self.fname = None self.format = None self.tensors = None # add the plot to the scene scene.add(self)
def __init__(self): """ Initialisation of Renderer() class """ debugMsg("Called Renderer.__init__()") BaseRenderer.__init__(self) # initialise some attributes self.renderWindowWidth = 640 self.renderWindowHeight = 480 # what is the name of my renderer? self.name = _rendererName # the namespace to run the exec code self.renderDict = {} # initialise the evalstack self._evalStack = "" # keep the initial setup of the module for later reuse self._initStack = "" # initialise the renderer module self.runString("# Renderer._initRendererModule") self.addToInitStack("import vtk") self.addToInitStack("from numpy import *")
def setOrigin(self, xo, yo, zo): """ Set the origin of the box """ debugMsg("Called Box.setOrigin()") # get the current origin (xi, yi, zi) = self.getOrigin() # get the current bounds (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() # get the difference between the two origins (xd, yd, zd) = (xo-xi, yo-yi, zo-zi) # move the bounds accordingly self.setBounds(xmin+xd, xmax+xd, ymin+yd, ymax+yd, zmin+zd, zmax+zd) # the calculated origin should be the same as the one desired to be # set by the user (xmin, xmax, ymin, ymax, zmin, zmax) = self.getBounds() self.origin = ((xmin + xmax)/2.0, (ymin + ymax)/2.0, (zmin + zmax)/2.0) # do a check to see if calculated origin is close enough to that # desired by the user (to within the tolerance) if __debug__: (xi, yi, zi) = self.getOrigin() originDiff = (xo-xi, yo-yi, zo-zi) for i in range(3): assert abs(originDiff[i]) < self.tolerance, \ "Origin not set to within tolerance" return
def __init__(self): """ Initialisation of the Box object """ debugMsg("Called Box.__init__()") Item.__init__(self) # define a box in many ways, either by its centre and width, height # and depth, or by its bounds, xmin, xmax, ymin, ymax, zmin, zmax, # or by its bottom left front and top right back points. # set the default bounds self.xmin = -0.5 self.xmax = 0.5 self.ymin = -0.5 self.ymax = 0.5 self.zmin = -0.5 self.zmax = 0.5 # set the default origin (the centre of the box) self.origin = ((self.xmin + self.xmax)/2.0, (self.ymin + self.ymax)/2.0, (self.zmin + self.zmax)/2.0) # set the default dimensions self.width = self.xmax - self.xmin self.height = self.ymax - self.ymin self.depth = self.zmax - self.zmin # set the default blf and trb points self.blf = (self.xmin, self.ymin, self.zmin) self.trb = (self.xmax, self.ymax, self.zmax) # tolerance for calculated variables checking purposes self.tolerance = 1e-8
def getElevation(self): """ Gets the elevation angle (in degrees) of the Camera """ debugMsg("Called Camera.getElevation()") return self.elevation
def __init__(self, scene): """ Initialisation of the Plane object """ debugMsg("Called Plane.__init__()") Item.__init__(self) self.renderer = scene.renderer
def getBounds(self): """ Get the current bounds of the box """ debugMsg("Called Box.getBounds()") return (self.xmin, self.xmax, \ self.ymin, self.ymax, \ self.zmin, self.zmax)
def setInsideOut(self, insideOut): """ Set the inside out flag """ debugMsg("Called ClipBox.setInsideOut()") self.plot.renderer.runString("# ClipBox.setInsideOut()") self.insideOut = insideOut return
def getSize(self): """ Gets the current size of the scene This size is effectively the renderer window size. Returns a tuple of the x and y dimensions respectively, in pixel units(??). """ debugMsg("Called Scene.getSize()") return (self.xSize, self.ySize)
def __init__(self): """ Intialisation of the ClipPlane object """ debugMsg("Called ClipPlane.__init__()") Plane.__init__(self) # set the default inside out flag value self.insideOut = False
def getPosition(self): """ Get the position of Camera within Scene Returns the position in a tuple of form (xPos, yPos, zPos) """ debugMsg("Called Camera.getPosition()") return (self.xPos, self.yPos, self.zPos)
def __init__(self, scene): debugMsg("Called BallPlot.__init__()") Plot.__init__(self, scene) self.renderer = scene.renderer self.renderer.runString("# BallPlot.__init__()") # add the plot to the scene scene.add(self)
def getFocalPoint(self): """ Get the position of the focal point of the Camera Returns the position of the focal point in a tuple of form (xPos, yPos, zPos) """ debugMsg("Called Camera.getFocalPoint()") return (self.xFocalPoint, self.yFocalPoint, self.zFocalPoint)
def _register(self, obj): """ Register the given object with the plot object This is useful for keeping track of the objects being used to clip the current plot object, and for inserting the appropriate code. """ debugMsg("Called Plot._register()") self.objectList.append(obj) return
def load(self, fname): """ Loads image data from file. @param fname: The filename from which to load image data @type fname: string """ debugMsg("Called Image.load()") fileCheck(fname) return
def __init__(self, scene=None): """ Initialises the Image class object @param scene: The Scene object to add to @type scene: Scene object """ debugMsg("Called Image.__init__()") Item.__init__(self) if scene is not None: self.renderer = scene.renderer