Пример #1
0
	def _select_coords(self, coords, prm):
		"""
		Choose between two intersection points on a quadric surface.
		This implementation extends QuadricGM's behaviour by not choosing
		intersections outside the rectangular aperture.
		
		Arguments:
		coords - a 2 by 3 by n array whose each column is the global coordinates
			of one intersection point of a ray with the sphere.
		prm - the corresponding parametric location on the ray where the
			intersection occurs.

		Returns:
		The index of the selected intersection, or None if neither will do.
		"""
		select = QuadricGM._select_coords(self, coords, prm)

		coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis = 1)
		# assumed no additional parameters to coords, axis = 1
		local = N.sum(N.linalg.inv(self._working_frame)[None,:2,:,None] * \
			coords[:,None,:,:], axis=2)

		abs_x = abs(local[:,0,:])
		abs_y = abs(local[:,1,:])
		outside = abs_x > self._w
		outside |= abs_y > self._h
		inside = (~outside) & (prm > 1e-6)

		select[~N.logical_or(*inside)] = N.nan
		one_hit = N.logical_xor(*inside)
		select[one_hit] = N.nonzero(inside.T[one_hit,:])[1]

		return select
Пример #2
0
	def _select_coords(self, coords, prm):
		"""
		Choose between two intersection points on a quadric surface.
		This implementation extends QuadricGM's behaviour by not choosing
		intersections outside the rectangular aperture.
		
		Arguments:
		coords - a 2 by 3 by n array whose each column is the global coordinates
			of one intersection point of a ray with the sphere.
		prm - the corresponding parametric location on the ray where the
			intersection occurs.

		Returns:
		The index of the selected intersection, or None if neither will do.
		"""
		select = QuadricGM._select_coords(self, coords, prm)

		coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis = 1)
		# assumed no additional parameters to coords, axis = 1
		local = N.sum(N.linalg.inv(self._working_frame)[None,:2,:,None] * \
			coords[:,None,:,:], axis=2)

		abs_x = abs(local[:,0,:])
		abs_y = abs(local[:,1,:])
		outside = abs_x > self._w
		outside |= abs_y > self._h
		inside = (~outside) & (prm > 1e-6)

		select[~N.logical_or(*inside)] = N.nan
		one_hit = N.logical_xor(*inside)
		select[one_hit] = N.nonzero(inside.T[one_hit,:])[1]

		return select
Пример #3
0
    def _select_coords(self, coords, prm):
        """
        Choose between two intersection points on a quadric surface.
        This implementation extends QuadricGM's behaviour by not choosing
        intersections outside the circular aperture.
        
        Arguments:
        coords - a 2 by 3 by n array whose each column is the global coordinates
            of one intersection point of a ray with the sphere.
        prm - the corresponding parametric location on the ray where the
            intersection occurs.

        Returns:
        The index of the selected intersection, or None if neither will do.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate((coords, N.ones((2, 1, coords.shape[2]))), axis=1)
        local_z = N.sum(N.linalg.inv(self._working_frame)[None, 2, :, None] * coords, axis=1)
        under_cut = (local_z <= self._h) & (prm > 0)

        select[~N.logical_or(*under_cut)] = N.nan
        one_hit = N.logical_xor(*under_cut)
        select[one_hit] = N.nonzero(under_cut.T[one_hit, :])[1]

        return select
Пример #4
0
    def _select_coords(self, coords, prm):
        """
        Choose between two intersection points on a quadric surface.
        This implementation extends QuadricGM's behaviour by not choosing
        intersections outside the circular aperture.
        
        Arguments:
        coords - a 2 by 3 by n array whose each column is the global coordinates
            of one intersection point of a ray with the sphere.
        prm - the corresponding parametric location on the ray where the
            intersection occurs.

        Returns:
        The index of the selected intersection, or None if neither will do.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate((coords, N.ones((2, 1, coords.shape[2]))),
                               axis=1)
        local_z = N.sum(N.linalg.inv(self._working_frame)[None,2,:,None] * \
            coords, axis=1)
        under_cut = (local_z <= self._h) & (prm > 0)

        select[~N.logical_or(*under_cut)] = N.nan
        one_hit = N.logical_xor(*under_cut)
        select[one_hit] = N.nonzero(under_cut.T[one_hit, :])[1]

        return select
Пример #5
0
    def _select_coords(self, coords, prm):
        """
        Choose between two intersection points on a quadric surface.
        This implementation extends QuadricGM's behaviour by not choosing
        intersections outside the hexagon aperture.
        
        Arguments:
        coords - a 2 by 3 by n array whose each column is the global coordinates
            of one intersection point of a ray with the sphere. Why 2 by three here, doesn't concatenate with 
        prm - the corresponding parametric location on the ray where the
            intersection occurs.

        Returns:
        The index of the selected intersection, or None if neither will do.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate(
            (coords, N.ones((2, 1, coords.shape[2]))), axis=1
        )  # n rays two clusters of row matrices with n elements of one concatenated horizontally 2*4*n ats.
        local = N.sum(N.linalg.inv(self._working_frame)[None, :2, :, None] * coords[:, None, :, :], axis=2)
        # working frame, a 4*4 homogeneous transform array representing the surface frame in the global coordinates. This is an elementwise multiplication, interesting.
        # 2*4 and three extra layers. Imitation of a dot product. Now the coordinates transferred back to the local ones.
        abs_x = abs(local[:, 0, :])
        abs_y = abs(local[:, 1, :])
        outside = abs_x > N.sqrt(3) * self._R / 2.0
        outside |= abs_y > self._R - N.tan(N.pi / 6.0) * abs_x
        inside = (~outside) & (prm > 1e-9)

        select[~N.logical_or(*inside)] = N.nan
        one_hit = N.logical_xor(*inside)
        select[one_hit] = N.nonzero(inside.T[one_hit, :])[1]

        return select
Пример #6
0
	def _select_coords(self, coords, prm):
		select = QuadricGM._select_coords(self, coords, prm) # defaults
        
		coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis=1)
		local = N.sum(N.linalg.inv(self._working_frame)[None,:,:,None] * coords[:,None,:,:], axis=2)

		bottom_hem = (local[:,2,:] <= 0) & (prm > 0)
		in_facet = (N.abs(local[:,0,:])<=self.lx/2.) & (N.abs(local[:,1,:])<=self.ly/2.)
		good = N.logical_and(bottom_hem,in_facet)
		select[~N.logical_or(*good)] = N.nan
		one_hit = N.logical_xor(*good)
		select[one_hit] = N.nonzero(good[:,one_hit])[0]
		return select
Пример #7
0
    def _select_coords(self, coords, prm):
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate((coords, N.ones((2, 1, coords.shape[2]))),
                               axis=1)
        local = N.sum(N.linalg.inv(self._working_frame)[None, :, :, None] *
                      coords[:, None, :, :],
                      axis=2)

        bottom_hem = (local[:, 2, :] <= 0) & (prm > 0)
        in_facet = (N.abs(local[:, 0, :]) <= self.lx / 2.) & (N.abs(
            local[:, 1, :]) <= self.ly / 2.)
        good = N.logical_and(bottom_hem, in_facet)
        select[~N.logical_or(*good)] = N.nan
        one_hit = N.logical_xor(*good)
        select[one_hit] = N.nonzero(good[:, one_hit])[0]
        return select
Пример #8
0
 def _select_coords(self, coords, prm):
     """
     Select from dual intersections by vetting out rays in the upper
     hemisphere, or if both are below use the default behaviour of choosing
     the first hit.
     """
     select = QuadricGM._select_coords(self, coords, prm) # defaults
     
     coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis=1)
     local = N.sum(N.linalg.inv(self._working_frame)[None,:,:,None] * \
         coords[:,None,:,:], axis=2)
     bottom_hem = (local[:,2,:] <= 0) & (prm > 0)
     
     select[~N.logical_or(*bottom_hem)] = N.nan
     one_hit = N.logical_xor(*bottom_hem)
     select[one_hit] = N.nonzero(bottom_hem[:,one_hit])[0]
     
     return select
Пример #9
0
    def _select_coords(self, coords, prm):
        """
        Select from dual intersections by vetting out rays in the upper
        hemisphere, or if both are below use the default behaviour of choosing
        the first hit.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate((coords, N.ones((2, 1, coords.shape[2]))),
                               axis=1)
        local = N.sum(N.linalg.inv(self._working_frame)[None,:,:,None] * \
            coords[:,None,:,:], axis=2)
        bottom_hem = (local[:, 2, :] <= 0) & (prm > 0)

        select[~N.logical_or(*bottom_hem)] = N.nan
        one_hit = N.logical_xor(*bottom_hem)
        select[one_hit] = N.nonzero(bottom_hem[:, one_hit])[0]

        return select