Exemplo n.º 1
0
    def createRay(self, x, y):
        near = self.params['near'].value
        far = self.params['far'].value
        o = self.params['center'].value
        d = self.params['lookAt'].value
        m = self.params['matrix'].value
        xres = PtWorld.options.xres.value
        yres = PtWorld.options.yres.value

        ## create a transform
        #xf = PtTransform.PtTransform(m)
        ## flip the values  (why? IHNFI)
        o.y *= -1
        o.z *= -1
        xpoint = PtTransform.PiTranslate(o)
        #xpoint = PtTransform.PtMatrix()

        ## multipliy the xform by the position
        m *= xpoint

        px = x - xres / 2. + 0.5
        py = y - yres / 2. + 0.5

        tmp = PtGeom.PtRay(origin=PtGeom.PtPoint(px, py, o.z),
                           direction=PtGeom.PtVector(d.x, d.y, d.z))
        tmp.mint = near
        tmp.maxt = far
        tmp.transform(m)
        return tmp
Exemplo n.º 2
0
 def test_PiRotateZ(self):
     m = [0.70710678118654757, -0.70710678118654746, 0.0, 0.0, 
          0.70710678118654746, 0.70710678118654757, 0.0, 0.0,
          0.0, 0.0, 1.0, 0.0,
          0.0, 0.0, 0.0, 1.0]
     
     r = PtTransform.PiRotateZ(45)
     self.assertEqual(r.m,m)
Exemplo n.º 3
0
 def test_PiTranslate(self):
     m = [1.,0.,0.,0.,
          0.,1.,0.,0.,
          0.,0.,1.,0.,
          0.,0.,0.,1.]
     trans = [1.,0.,0.,2.,
               0.,1.,0.,3.,
               0.,0.,1.,4.,
               0.,0.,0.,1.]
     #test empty
     t = PtTransform.PiTranslate()
     self.assertEqual(t.m,m)
     #test list init
     t = PtTransform.PiTranslate([2.,3.,4.])
     self.assertEqual(t.m,trans)
     #test Vector init
     t = PtTransform.PiTranslate(PtGeom.PtVector(2.,3.,4.))
     self.assertEqual(t.m,trans)
Exemplo n.º 4
0
    def test_PtMatrix(self):
        # test for no param init
        m = [1.,0.,0.,0.,
             0.,1.,0.,0.,
             0.,0.,1.,0.,
             0.,0.,0.,1.]
        mat = PtTransform.PtMatrix()
        self.assertEqual(m,mat.m)

        # test for list init
        m2 = [1.1,0.,0.,0.,
             0.,1.2,0.,0.,
             0.,0.,1.3,0.,
             0.,0.,0.,1.]
        # test for no param init
        mat = PtTransform.PtMatrix(m2)
        self.assertEqual(m2,mat.m)
        # test determinant
        self.assertEqual(mat.determinant,1.7160000000000002)
        # test identity
        mat.identity
        self.assertEqual(m,mat.m)

        #test Transpose
        m3 = [1.,0.,0.,2.,
              0.,1.,0.,3.,
              0.,0.,1.,4.,
              0.,0.,0.,1.]
        m3i = [1.,0.,0.,-2.,
              0.,1.,0.,-3.,
              0.,0.,1.,-4.,
              0.,0.,0.,1.]
        m3t = [1.,0.,0.,0.,
               0.,1.,0.,0.,
               0.,0.,1.,0.,
               2.,3.,4.,1.]
        mat = PtTransform.PtMatrix(m3)
        mat.transpose
        self.assertEqual(mat.m,m3t)
        mat.transpose
        # test invert
        mat.invert
        self.assertEqual(mat.m,m3i)
Exemplo n.º 5
0
    def intersectP(self,ray):
        radius = self.params['radius'].value
        zmin = self.params['zmin'].value * radius
        zmax = self.params['zmax'].value * radius
        phiMax=self.params['phiMax'].value
        pos = self.params['center'].value
        m = self.params['matrix'].value

        # transform for sphere center
        xpoint = PtTransform.PiTranslate(pos)
        # multiply transforms
        m *= xpoint
        # get a local ray
        ray.transform(m)
        # variables for quadratic function
        A = ray.d.x*ray.d.x + ray.d.y*ray.d.y + ray.d.z * ray.d.z
        B = 2 * (ray.d.x*ray.o.x + ray.d.y*ray.o.y + ray.d.z*ray.o.z)
        C = ray.o.x*ray.o.x + ray.o.y*ray.o.y + ray.o.z*ray.o.z - radius*radius
        
        hit, t0, t1 = PtMath.quadratic(A,B,C)
        
        if not hit:
            return False
        #  Compute intersection distance along ray
        if t0 > ray.maxt or t1 < ray.mint:
            return False

        thit = t0
        if t0 < ray.mint:
            thit = t1
            if thit > ray.maxt:
                return False

        # Compute sphere hit position and $\phi
        #phit = PtGeom.PtRay(origin=ray.o,direction=ray.d,
        #                    mint=ray.mint,maxt=ray.maxt)
        phit = ray
        phit.offset(thit)

        #phit = ray.offset(thit,True)
        
        #print phit
        phi = math.atan2(phit.o.y,phit.o.x)
        if phi < 0.:
            phi += 2. * math.pi 
        #  Test sphere intersection against clipping parameters 
        if (zmin > -radius and phit.o.z < zmin) or \
           (zmax < radius and phit.o.z > zmax) or \
           phi > math.radians(phiMax):
            if thit == 1:
                return False
            if t1 > ray.maxt:
                return False
            thit = t1
        # Compute sphere hit position and $\phi$
            #phit = ray.offset(thit,True)
            #phit = PtGeom.PtRay(origin=ray.o,direction=ray.d,
            #                mint=ray.mint,maxt=ray.maxt)
            phit.offset(thit)
            phi = math.atan2(phit.o.y,phit.o.x)
            if phi < 0.:
                phi += 2. * math.pi
            if phit.o.z < zmin or phit.o.z > zmax or phi > phiMax:
                return False
        
        return True