Exemplo n.º 1
0
	def load (self) :
		SVGLayer.load(self)
		if self.nb_images()>0 :
			w,h,d=self.size()
			self.set_size(w,h,self.nb_images()-1)
		dx=float(self.get_default("dx",1.))
		dy=float(self.get_default("dy",1.))
		dz=float(self.get_default("dz",1.))
		self.set_resolution(dx,dy,dz)
		#variants
		for i in xrange(self.nb_children()) :
			if self.child(i).nodename()=="variant" :
				variant=SVGStackVariant()
				variant.from_node(self.child(i))
				self.set_child(i,variant)
				self._variants.append(variant)
				variant.load()
		#masked images
		self._masked=[]
		for im in self.images() :
			name=im.filename()
			if name[-1]=="X" :
				self._masked.append(True)
				im.set_filename(name[:-1])
			else :
				self._masked.append(False)
Exemplo n.º 2
0
	def save (self) :
		var_mem=self._variant_used
		self.use_variant(None)
		#variants
		for var in self.variants() :
			var.save()
		#node
		inv=lambda x : 1./x if abs(x)>1e-6 else 0.
		dx,dy,dz=self.resolution()
		self._transform3D*=Matrix4(scaling(tuple(inv(r) for r in (dx,dy,dz))))
		#masked
		for i in xrange(len(self)) :
			im=self.image(i)
			if self._masked[i] :
				im.set_filename("%sX" % im.filename())
		SVGLayer.save(self)
		self.set_attribute("descr","stack")
		self.set_attribute("dx","%f" % dx)
		self.set_attribute("dy","%f" % dy)
		self.set_attribute("dz","%f" % dz)
		self._transform3D*=Matrix4(scaling((dx,dy,dz)))
		#masked
		for i in xrange(len(self)) :
			im=self.image(i)
			if self._masked[i] :
				im.set_filename(im.filename()[:-1])
		#variant
		self.use_variant(var_mem)
 def save(self):
     var_mem = self._variant_used
     self.use_variant(None)
     #variants
     for var in self.variants():
         var.save()
     #node
     inv = lambda x: 1. / x if abs(x) > 1e-6 else 0.
     dx, dy, dz = self.resolution()
     self._transform3D *= Matrix4(
         scaling(tuple(inv(r) for r in (dx, dy, dz))))
     #masked
     for i in xrange(len(self)):
         im = self.image(i)
         if self._masked[i]:
             im.set_filename("%sX" % im.filename())
     SVGLayer.save(self)
     self.set_attribute("descr", "stack")
     self.set_attribute("dx", "%f" % dx)
     self.set_attribute("dy", "%f" % dy)
     self.set_attribute("dz", "%f" % dz)
     self._transform3D *= Matrix4(scaling((dx, dy, dz)))
     #masked
     for i in xrange(len(self)):
         im = self.image(i)
         if self._masked[i]:
             im.set_filename(im.filename()[:-1])
     #variant
     self.use_variant(var_mem)
 def load(self):
     SVGLayer.load(self)
     if self.nb_images() > 0:
         w, h, d = self.size()
         self.set_size(w, h, self.nb_images() - 1)
     dx = float(self.get_default("dx", 1.))
     dy = float(self.get_default("dy", 1.))
     dz = float(self.get_default("dz", 1.))
     self.set_resolution(dx, dy, dz)
     #variants
     for i in xrange(self.nb_children()):
         if self.child(i).nodename() == "variant":
             variant = SVGStackVariant()
             variant.from_node(self.child(i))
             self.set_child(i, variant)
             self._variants.append(variant)
             variant.load()
     #masked images
     self._masked = []
     for im in self.images():
         name = im.filename()
         if name[-1] == "X":
             self._masked.append(True)
             im.set_filename(name[:-1])
         else:
             self._masked.append(False)
Exemplo n.º 5
0
	def add_image (self, image_name, width, height, masked=False, zreverse=False) :
		ind=len(self)
		gr=SVGLayer("gslice%.4d" % ind)
		self.append(gr)
		gr.set_size(width,height)
		if zreverse :
			gr.translate( (0,0,-ind) )
		else :
			gr.translate( (0,0,ind) )
		gr.display=False
		im=SVGImage("slice%.4d" % ind)
		gr.append(im)
		im.set_filename(image_name)
		im.scale2D( (width,height,1.) )
		self._masked.append(masked)
Exemplo n.º 6
0
def svg_element(xmlelm):
    """Factory
    
    Construct the appropriate SVGElement
    according to informations stored
    in an XMLElement
    
    :Returns Type: :class:`SVGElement`
    """
    name = xmlelm.nodename()
    if name[:4] == "svg:":
        name = name[4:]

    if name == "rect":
        return SVGBox(0, 0, 1, 1)
    elif name == "image":
        return SVGImage(0, 0, 1, 1, None)
    elif name == "text":
        return SVGText(0, 0, "txt")
    elif name == "circle":
        return SVGSphere(0, 0, 1, 1)
    elif name == "ellipse":
        return SVGSphere(0, 0, 1, 1)
    elif name == "path":  #either a path, a circle or a connector
        if xmlelm.has_attribute("sodipodi:type") \
           and xmlelm.attribute("sodipodi:type") == "arc" :#its a circle
            return SVGSphere(0, 0, 1, 1)
            #TODO extend to other sodipodi types if needed
        else:  #either a path or a connector
            if xmlelm.has_attribute(
                    "inkscape:connector-type"):  #it's a connector
                return SVGConnector(None, None)
            else:  #it's a simple path
                return SVGPath()
    elif name == "g":  #either a group or a layer
        if xmlelm.has_attribute(
                "inkscape:groupmode"):  #either a layer or a stack
            if (xmlelm.has_attribute("descr")
                    and xmlelm.attribute("descr") == "stack"):
                return SVGStack()
            else:
                return SVGLayer("layer", 1, 1)
        else:
            return SVGGroup(1, 1)
    else:
        raise KeyError("Node not recognized: '%s'" % name)
Exemplo n.º 7
0
	def __init__ (self, id=None, parent=None) :
		SVGLayer.__init__(self,id,parent)
		self.display=False
		self._variants=[]
		self._variant_used=None
		self._masked=[]
 def add_image(self,
               image_name,
               width,
               height,
               masked=False,
               zreverse=False):
     ind = len(self)
     gr = SVGLayer("gslice%.4d" % ind)
     self.append(gr)
     gr.set_size(width, height)
     if zreverse:
         gr.translate((0, 0, -ind))
     else:
         gr.translate((0, 0, ind))
     gr.display = False
     im = SVGImage("slice%.4d" % ind)
     gr.append(im)
     im.set_filename(image_name)
     im.scale2D((width, height, 1.))
     self._masked.append(masked)
 def __init__(self, id=None, parent=None):
     SVGLayer.__init__(self, id, parent)
     self.display = False
     self._variants = []
     self._variant_used = None
     self._masked = []