Esempio n. 1
0
    def parse(self, resolution=0.001):
        interped = np.linspace(0, 1, int(1/resolution))
        self._mainCenterline = Curve(self.parse_filepath(
            self.main_centerline_id).data)(interped)
        self._bifurCenterline = Curve(self.parse_filepath(
            self.bifur_centerline_id).data)(interped)

        self._sorMainDistalToProximal()
        self._sortBifurCenterlinebyMainCenterline()

        return self.data()
Esempio n. 2
0
 def plot3d(self, *args, **kwargs):
     color = kwargs.pop('color', 'blue')
     long = self.shape[-1]
     for i in range(long):
         f, ax, obj = Curve.plot3d(
             self[:, :, i], *args, color=color, **kwargs)
     return f, ax, obj
Esempio n. 3
0
 def __init__(self, contour, refinement=None):
     assert isinstance(contour, Contour)
     self._contour = contour
     if refinement is None:
         refinement = contour.shape[-1] // 4
     # c_1 = Curve(contour(np.linspace(0, 0.25, refinement)))
     # c_4 = Curve(contour(np.linspace(0.25, 0.5, refinement)))
     # c_3 = Curve(np.fliplr(np.array(contour(np.linspace(0.5, 0.75, refinement)))))
     # c_2 = Curve(np.fliplr(np.array(contour(np.linspace(0.75, 1.0, refinement)))))
     # super().__init__(c_1, c_2, c_3, c_4)
     c_1 = Curve(contour(np.linspace(0, 0.25, refinement)))
     c_2 = Curve(contour(np.linspace(0.25, 0.5, refinement)))
     c_3 = Curve(
         np.fliplr(np.array(contour(np.linspace(0.5, 0.75, refinement)))))
     c_4 = Curve(
         np.fliplr(np.array(contour(np.linspace(0.75, 1.0, refinement)))))
     super().__init__(c_1, c_2, c_3, c_4)
Esempio n. 4
0
    def interpolate_long(self, npts, *args, centerline_reparam=False, **kwargs):
        newsurface = np.zeros(
            (self.shape[0], self.shape[1], npts)
        )
        if centerline_reparam:
            centroids = np.concatenate([Contour(self[:,:, i]).centroid for i in range(self.shape[-1])], axis=-1)
            centerline = Curve(centroids)
            centerline_s = centerline.s_frac

        for i in range(self.shape[1]):
            line = Curve(self[:, i, :], **kwargs)

            if not centerline_reparam:
                newsurface[:, i, :] = line(
                        np.linspace(0, 1, npts)
                    )
            else:
                newsurface[:, i, :] = line(
                        np.linspace(0, 1, npts), reparam_curve=centerline_s
                )
        return self.__class__(newsurface)
Esempio n. 5
0
    def __call__(self, U, V, close=True, reparam=True):
        centroids = np.concatenate([Contour(self[:,:, i]).centroid for i in range(self.shape[-1])], axis=-1)
        centerline = Curve(centroids)
        if reparam:
            centerline_s = centerline.s_frac
        else:
            centerline_s = None

        surface = np.stack(
            [Curve(self[:, i, :], reparam_curve=centerline_s)(V) for i in  range(self.shape[1])],
            axis=1
        )
        if any([U[-1] != 1, U[0] != 0]):
            surface = np.stack(
                    [Curve(surface[:, :, i])(U) for i in  range(surface.shape[-1])],
                axis=-1
            )
        else:
            surface = np.stack(
                    [FlatContour(surface[:, :, i])(U) for i in  range(surface.shape[-1])],
                axis=-1
            )

        return self.__class__(surface)
Esempio n. 6
0
    def _sorMainDistalToProximal(self):
        am, bm = self._mainCenterline[:, 0], self._mainCenterline[:, -1]
        ab, bb = self._bifurCenterline[:, 0], self._bifurCenterline[:, -1]

        shortestDistanceStart = min(
            math.l2_norm(am-ab),
            math.l2_norm(am-bb)
        )
        shortestDistanceEnd = min(
            math.l2_norm(bm-ab),
            math.l2_norm(bm-bb)
        )

        if shortestDistanceStart < shortestDistanceEnd:
            self._mainCenterline = Curve(np.flipud(self._mainCenterline.T).T)
Esempio n. 7
0
 def get_centerline(self):
     centroids = np.concatenate([Contour(self[:,:, i]).centroid for i in range(self.shape[-1])], axis=-1)
     centerline = Curve(centroids)
     return centerline
Esempio n. 8
0
    def _sortBifurCenterlinebyMainCenterline(self):
        am = self._mainCenterline[:, 0]
        ab, bb = self._bifurCenterline[:, 0], self._bifurCenterline[:, -1]

        if math.l2_norm(am - ab) > math.l2_norm(am - bb):
            self._bifurCenterline = Curve(np.flipud(self._bifurCenterline.T).T)
Esempio n. 9
0
 def data(self):
     return dict(
         main=Curve(self._mainCenterline),
         bifur=Curve(self._bifurCenterline),
     )