0001"""
0002**geometric objects** representing a defined transformation of a given set of objects
0003"""
0004
0005__Def__ =       ['Transform']
0006
0007__Classes__ =   ['CentralProjection', 'ReflectTransform']
0008
0009__all__= __Classes__+  __Def__
0010
0011__doc_hints__={'m_type':'factory'}
0012
0013import pygeo.base.abstracts._real as Real
0014
0015from pygeo.base.analytics.pygeomath import multiply, matrixmultiply, transpose, array
0016
0017
0018
0019class CentralProjection(Real._Transformation):
0020    """
0021*projection* of the objects in the given list from the given **point** 
0022to the given **plane**
0023    
0024    inherits
0025    
0026        `_Transformation`__
0027
0028__ class-base.abstracts._real._Transformation.html        
0029    
0030    """
0031
0032    __doc_hints__=  {'factory':'Transform',
0033                    'args':['plane,point,[list of objects]']}
0034
0035    def __init__(self,plane,point,elements,**kws):
0036        self.plane=plane
0037        self.point=point
0038        self.elements=[]
0039        for e in elements:
0040            for t in e:
0041                self.elements.append(t)
0042        args=[plane]+[point]+self.elements
0043        for element in elements:
0044            if not element in args:
0045                args.append(element)
0046        Real._Transformation.__init__(self,*args,**kws)
0047        self.init()
0048
0049    def _getMat(self):
0050        pt=self.point.homogenous()
0051        equat=self.plane.equat()
0052        self.mat= multiply.outer(equat,pt)
0053        k=matrixmultiply(pt,equat)
0054        for i in range(4):
0055            self.mat[i,i]-=k
0056        return True
0057
0058class ReflectTransform(Real._Transformation):
0059    """
0060*reflection* of the given **list of objects**  
0061in the given **plane**
0062    
0063    inherits
0064    
0065        `_Transformation`__
0066
0067__ class-base.abstracts._real._Transformation.html        
0068    
0069    """
0070    __doc_hints__=  {'factory':'Transform',
0071                    'args':['plane,[list of objects]']}
0072
0073    def __init__(self,plane,elements,**kws):
0074        self.plane=plane
0075        self.elements=[]
0076        for e in elements:
0077            for t in e:
0078                self.elements.append(t)
0079        args=[plane]+self.elements
0080        for element in elements:
0081            if not element in args:
0082                args.append(element)
0083        Real._Transformation.__init__(self,*args,**kws)
0084        self.init()
0085
0086    def _getMat(self):
0087        plane=self.plane
0088        x,y,z=plane._u.x,plane._u.y,plane._u.z
0089        self.mat=transpose(array([[1-2*x**2,-2*x*y,-2*x*z,2*x*self.plane._d],
0090                                  [-2*x*y,1-2*y**2,-2*y*z,2*y*self.plane._d],
0091                                  [-2*x*z,-2*y*z,1-2*z**2,2*z*self.plane._d],
0092                                  [0.,0.,0.,1]]))
0093        return True
0094
0095def  Transform(*args,**kws):
0096    """
0097'class factory' function returns instance of object derived form the 
0098_Transformation abstract class representing a defined transformation of 
0099a given set of objects
0100    """
0101
0102    from pygeo.base.abstracts._element import method_get
0103    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0104    from pygeo.base.analytics.pygeomath import vector
0105
0106    __sigs__=[[Real._Plane,vector,list],[Real._Plane,vector,tuple],
0107             [Real._Circle,vector,list],[Real._Circle,vector,tuple],
0108             [Real._Plane,list],[Real._Plane,tuple],
0109             [Real._Circle,list],[Real._Circle,tuple]]
0110    t,i = method_get(__sigs__,args)
0111
0112    if t is None:
0113        raise Argument_Type_Error(__sigs__,args)
0114    else:
0115        if i==0 or i==1 or i==3:
0116            return CentralProjection(t[0],t[1],t[2],**kws)
0117        elif i==4 or i==5 or i==6 or i==7:
0118            return ReflectTransform(t[0],t[1],**kws)
0119        else:
0120            raise Argument_Type_Error(__sigs__,args)