コード例 #1
0
ファイル: box.py プロジェクト: rc/gensei
    def get_points(self):
        """
        All points in the block.
        """
        for axis, num in ordered_iteritems(self.n_slice):
            am = self._axis_map[axis]

            shape = np.array((self.resolution[0], self.resolution[1], num))
            pb = np.zeros((3,), dtype=np.object)
            for ii in range(3):
                pb[am[ii]] = np.linspace(0, self.dims[ii], shape[ii])

            if num > 1:
                delta = pb[am[2]][1] - pb[am[2]][0]
            else:
                delta = 0.0
            x1, x2 = np.meshgrid(pb[am[0]], pb[am[1]])
            x1 = x1.ravel()
            x2 = x2.ravel()

            points = np.empty((x1.shape[0], 3), dtype=np.float64)
            points[:,am[0]] = x1
            points[:,am[1]] = x2

            yield pb, points, delta, num, axis, am
コード例 #2
0
ファイル: single_object.py プロジェクト: rc/gensei
    def set_centre(self, centre):
        """
        Set the objects's centre and update its description matrix in
        homogenous coordinates. Also update the intersector. 
        """
        self.centre = np.array(centre, dtype=np.float64)
        self.mtx_hc = self._get_matrix_hc()

        self.intersector.set_data(mtx_hc=self.mtx_hc, centre=self.centre)
コード例 #3
0
ファイル: cylinder.py プロジェクト: rc/gensei
    def get_circumscribed_ellipsoid(self):
        """
        Return a circumscribed ellipsoid of the cylinder.
        """
        semiaxes = np.array(3 * [np.sqrt(2.0) * self.radius], dtype=np.float64)
        semiaxes[2] *= self.length_to_width
        mtx = np.diag(1.0 / (semiaxes**2))

        return mtx
コード例 #4
0
    def set_centre(self, centre):
        """
        Set the objects's centre and update its description matrix in
        homogenous coordinates. Also update the intersector. 
        """
        self.centre = np.array(centre, dtype=np.float64)
        self.mtx_hc = self._get_matrix_hc()

        self.intersector.set_data(mtx_hc=self.mtx_hc, centre=self.centre)
コード例 #5
0
    def __init__(self, dims=None, units=None, resolution=None,
                 n_object=None, n_slice=None):
        Object.__init__(self, name='box',
                        dims=np.array(dims, dtype=np.float64),
                        units=units, resolution=resolution,
                        n_object=n_object, n_slice=n_slice)

        if not isinstance(self.n_slice, dict):
            self.n_slice = {'z' : int(self.n_slice)}

        self.init_trait('volume', np.prod(self.dims))

        self._axis_map = {'x' : [1, 2, 0], 'y' : [2, 0, 1], 'z' : [0, 1, 2]}
コード例 #6
0
ファイル: cylinder.py プロジェクト: ramosapf/gensei
    def contains(self, points):
        """
        Point x in cylinder. Works for array of points.

        Parameters
        ----------
        points : (n_point, 3) array
            The points to be tested for inclusion.
        """
        points = np.array(points, ndmin=2, dtype=np.float64)
        x = points.T - self.centre[:,np.newaxis]
        aux = np.dot(self.rot_mtx, x)
        r = np.sqrt(aux[0,:]**2 + aux[1,:]**2)
        mask = (np.abs(aux[2,:]) <= (0.5 * self.height)) & (r <= self.radius)

        return mask
コード例 #7
0
    def contains(self, points):
        """
        Point x in ellipsoid A <=> x^T A x <= 1.
        Works for array of points.

        Parameters:
            points : (n_point, 3) array
        """
        points = np.array(points, ndmin=2, dtype=np.float64)
        x = points.T - self.centre[:, np.newaxis]
        aux = np.sum(x * np.dot(self.mtx, x), axis=0)
        mask = np.where(aux <= 1.0, True, False)
        ##         x2 = np.r_[points.T, np.ones((1,points.shape[0]))]
        ##         aux2 = np.sum(x2 * np.dot(self.mtx_hc, x2), axis = 0)
        ##         mask2 = np.where(aux2 <= 0.0, True, False)
        ##         print np.alltrue(mask == mask2)

        return mask
コード例 #8
0
ファイル: ellipsoid.py プロジェクト: rc/gensei
    def contains(self, points):
        """
        Point x in ellipsoid A <=> x^T A x <= 1.
        Works for array of points.

        Parameters:
            points : (n_point, 3) array
        """
        points = np.array(points, ndmin=2, dtype=np.float64)
        x = points.T - self.centre[:,np.newaxis]
        aux = np.sum(x * np.dot(self.mtx, x), axis = 0)
        mask = np.where(aux <= 1.0, True, False)
##         x2 = np.r_[points.T, np.ones((1,points.shape[0]))]
##         aux2 = np.sum(x2 * np.dot(self.mtx_hc, x2), axis = 0)
##         mask2 = np.where(aux2 <= 0.0, True, False)
##         print np.alltrue(mask == mask2)
        
        return mask
コード例 #9
0
    def __init__(self, semiaxes):
        """
        Parameters:

            semiaxes : (float, float, float)
                The semiaxes a, b, c of the ellipsoid.
        """
        self.semiaxes = np.array(semiaxes, dtype=np.float64)
        self.mtx0 = np.diag(1.0 / (self.semiaxes**2))

        im = self.semiaxes.argmax()
        self.direction0 = np.eye(3, dtype=np.float64)[im]

        self.volume = 4.0 / 3.0 * np.pi * np.prod(self.semiaxes)
        self.surface = self.compute_approximate_surface()
        self.length = self.semiaxes[im]

        self.is_placed = False
        self.intersection_counters = {}
        self.intersector = EllipsoidIntersector()
コード例 #10
0
ファイル: ellipsoid.py プロジェクト: rc/gensei
    def __init__(self, semiaxes):
        """
        Parameters:

            semiaxes : (float, float, float)
                The semiaxes a, b, c of the ellipsoid.
        """
        self.semiaxes = np.array(semiaxes, dtype=np.float64)
        self.mtx0 = np.diag(1.0 / (self.semiaxes**2))

        im = self.semiaxes.argmax()
        self.direction0 = np.eye(3, dtype=np.float64)[im]

        self.volume = 4.0 / 3.0 * np.pi * np.prod(self.semiaxes)
        self.surface = self.compute_approximate_surface()
        self.length = self.semiaxes[im]

        self.is_placed = False
        self.intersection_counters = {}
        self.intersector = EllipsoidIntersector()
コード例 #11
0
ファイル: cylinder.py プロジェクト: ramosapf/gensei
    def __init__(self, radius, height):
        """
        Parameters
        ----------
        radius : float
            The radius of the cylinder.
        height : float
            The height of the cylinder.
        """
        self.radius = radius
        self.height = height
        self.length_to_width = 0.5 * height / radius

        self.mtx0 = self.get_circumscribed_ellipsoid()

        self.direction0 = np.array([0.0, 0.0, 1.0], dtype=np.float64)

        self.volume = height * np.pi * (radius**2)
        self.surface = 2.0 * np.pi * radius * height
        self.length = self.height

        self.is_placed = False
        self.intersection_counters = {}
        self.intersector = EllipsoidIntersector()
コード例 #12
0
ファイル: intersectors.py プロジェクト: ramosapf/gensei
 def set_centre(self, centre):
     """
     Set the intersector's centre.
     """
     self.centre = np.array(centre, dtype=np.float64)
コード例 #13
0
ファイル: intersectors.py プロジェクト: rc/gensei
 def set_centre(self, centre):
     """
     Set the intersector's centre.
     """
     self.centre = np.array(centre, dtype=np.float64)