Exemplo n.º 1
0
Arquivo: align.py Projeto: gic888/MIEN
def manualAlign(
    doc,
    elems=[],
    trans_x=0.0,
    trans_y=0.0,
    trans_z=0.0,
    rot_x=0.0,
    rot_y=0.0,
    rot_z=0.0,
    scale_x=1.0,
    scale_y=1.0,
    scale_z=1.0,
    scale_d=1.0,
    order="Trans,Rot,Scale",
):
    """Apply the spatial transformation specified by the various trans, rot, and scale arguments to all the elements specified by upaths in the list "elems". The parameter "order" determines the order in which the translation, rotation, and scaling transforms are applied."""
    spTrans = {
        "Trans_x": trans_x,
        "Trans_y": trans_y,
        "Trans_z": trans_z,
        "Rot_x": rot_x,
        "Rot_y": rot_y,
        "Rot_z": rot_z,
        "Scale_x": scale_x,
        "Scale_y": scale_y,
        "Scale_z": scale_z,
        "Scale_d": scale_d,
        "Order": order,
    }
    for on in elems:
        obj = doc.getInstance(on)
        alignObject(obj, spTrans)
Exemplo n.º 2
0
Arquivo: align.py Projeto: gic888/MIEN
def coRegPointsTrans(doc, elems=[], point1=[0, 0, 0], point2=[0, 0, 0]):
    """Apply a translation to all the elements in "elems" such that point1 is moved to the location of point2 (all points in elems are shifted by point2-point1)"""
    objl = [doc.getInstance(p) for p in elems]
    pt = array(point2) - array(point1)
    conv = {"Trans_x": pt[0], "Trans_y": pt[1], "Trans_z": pt[2]}
    for obj in objl:
        print obj, conv
        alignObject(obj, conv)
Exemplo n.º 3
0
Arquivo: align.py Projeto: gic888/MIEN
def coRegPointsRotScale(doc, elems=[], point1=[0, 0, 0], point2=[0, 0, 0]):
    """Apply a rotation and scaling to the elements in elems such that point1 is moved to the location of point2. this is accomplished by first rotating such that the vectors point1 and point2 are colinear, and then scaling by ||point2||/||point1||. Scaling applied by this function does not scale diameters of 4D points. The scale factor used is printed and returned, so that it can be passed to "scaleDiameter" if needed."""
    # FIXME
    for d in parlist:
        conv[d["Name"]] = d["Value"]
    for obj in objl:
        alignObject(obj, conv, cv.report)
        if cv.xm:
            cv.update_all(object=obj)
    cv.addAll()
Exemplo n.º 4
0
def convert_aff(fname, scale=1.0):
	doc = getAff(fname)
	if not doc:
		return
	if scale!=1.0:
		sd={ 'Scale_x':scale, 'Scale_y':scale, 'Scale_z':scale}
		for e in doc.getElements(depth=1):
			alignObject(e, sd)
	fname = os.path.splitext(fname)[0]+'.nmpml'
	io.write(doc, fname, format='nmpml')
Exemplo n.º 5
0
def scale134(lfn):
    """scale the elements in the listed files by a factor of 1.34 in x y and z (but not d)"""
    from mien.spatial.alignment import alignObject

    for n in lfn:
        doc = io.read(n)
        nn, ext = os.path.splitext(n)
        nn = nn + "_scaledup" + ext
        factor = 1.34
        scale = {"Scale_x": factor, "Scale_y": factor, "Scale_z": factor}
        els = doc.getElements(["Cell", "Fiducial", "SpatialField"])
        for e in els:
            alignObject(e, scale)
        io.write(doc, nn)
Exemplo n.º 6
0
	def apply_align(self, event):
		trans = {}
		for name in self.ctrl_vals:
			trans[name]=self.ctrl_vals[name].GetValue()
		ntrans = self.calc_diff(trans)
		if self.is_noop(ntrans):
			return 
		print ntrans
		for obj in self.get_alignment_set():
			alignObject(obj, ntrans)	
		self.last=trans
		self.cv.graph.clearAll()
		for o in self.cv.getPlotTargets():
			self.cv.graph.plotXML(o)
		self.cv.graph.OnDraw()
Exemplo n.º 7
0
def xhairAlign(doc, elemXhair="guess"):
    """Translate all elements so as to set the anterior-most point in the x-hair object to 0,0,0. elemXhair may be an object ID or "guess". The algorithm to guess the X-hair ID is to choose the contour that contains the point closest to the center of the bounding box of all countours in the data set"""
    # std_xhair = doc.getElements('Fiducial', 'std_xhair')[0]
    if elemXhair != "guess":
        new_xhair = doc.getInstance(elemXhair)
    else:
        els = _getElems(doc)  # some xhairs now are Cells or Spheres, not lines!!!
        new_xhair = _nearCenter(els)
        doc.report("Guessing %s to be the xhair" % (new_xhair.upath(),))
        # topt = _anterior(std_xhair)
    topt = N.array([0.0, 0.0, 0.0])
    frompt = _anterior(new_xhair)
    pt = topt - frompt
    conv = {"Trans_x": pt[0], "Trans_y": pt[1], "Trans_z": pt[2]}
    for obj in _getElems(doc):
        alignObject(obj, conv)
Exemplo n.º 8
0
def make_map(dir):
	doc = io.read(os.path.join(dir, 'standard_outline.123.nmpml'))
	invert = { 'Scale_x':-1.0}
	for fn in os.listdir(dir):
		if not fn[0] in ['L', 'M', 'S']:
			continue
		if not fn.endswith('nmpml'):
			continue
		d2=io.read(os.path.join(dir, fn))
		varic = d2.getElements('Fiducial', {"Style":'spheres'})[0]
		for s in ["color", "Color", "Direction"]:
			if s in varic.attributes:
				del(varic.attributes[s])		
		right_varic = varic.clone()
		right_varic.setAttrib('meta_cercus', 'right')
		right_varic.setName(varic.name()+"_right")
		alignObject(right_varic, invert) 
		doc.newElement(varic)
		doc.newElement(right_varic)
	io.write(doc, 'full_map.nmpml', format='nmpml')
Exemplo n.º 9
0
Arquivo: align.py Projeto: gic888/MIEN
def scaleXYZ(doc, elems=[], factor=1.5):
    """Scale all X Y and Z (but not D) dimensions by factor"""
    spTrans = {"Scale_x": factor, "Scale_y": factor, "Scale_z": factor}
    for on in elems:
        obj = doc.getInstance(on)
        alignObject(obj, spTrans)
Exemplo n.º 10
0
Arquivo: align.py Projeto: gic888/MIEN
def scaleDiameter(doc, elems=[], value=1.0):
    """Scale the diameters of all 4D points in elems by value"""
    objl = [doc.getInstance(p) for p in elems]
    conv = {"Scale_d": value}
    for obj in objl:
        alignObject(obj, conv)
Exemplo n.º 11
0
Arquivo: align.py Projeto: gic888/MIEN
def setZero(doc, elems=[], point1=[0, 0, 0]):
    """Translate the selected objects so that pont1 has coordinates [0,0,0] in the new system. Equivalent to coRegPointsTrans if the argument point2 is [0,0,0]"""
    objl = [doc.getInstance(p) for p in elems]
    conv = {"Trans_x": -1 * point1[0], "Trans_y": -1 * point1[1], "Trans_z": -1 * point1[2]}
    for obj in objl:
        alignObject(obj, conv)
Exemplo n.º 12
0
def scaleAll(doc, factor=-1.38):
    """Scale all X Y and Z (but not D) dimensions by factor. All Cell and fiducial elements in the document are scaled, unless their names begin with "std", or they define the attribute "noAlign"."""
    spTrans = {"Scale_x": factor, "Scale_y": factor, "Scale_z": factor}
    for obj in _getElems(doc):
        alignObject(obj, spTrans)
Exemplo n.º 13
0
def scale(doc, scale_x=1.0, scale_y=1.0, scale_z=1.0):
    """Scale the indicated dimensions by the provided ammounts. All Cell and fiducial elements in the document are scaled, unless their names begin with "std_", or they define the attribute "noAlign"."""
    spTrans = {"Scale_x": scale_x, "Scale_y": scale_y, "Scale_z": scale_z}
    for obj in _getElems(doc):
        alignObject(obj, spTrans)