artorg-unibe-ch / spline_mesher

Meshing tool for homogenised finite elements based on HR-pQCT images
https://artorg-unibe-ch.github.io/spline_mesher/
MIT License
0 stars 0 forks source link

check if ::-1 is still needed (minus sign) #28

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

https://github.com/simoneponcioni/spline-mesher/blob/3c9d558608e9e291a52501b64106c622945bd7a1/src/spline_mesher/spline-volume-creation.py#L701


        # lines_s, points, curve_loop_tag = self.surfaces_gmsh(x=xnew, y=ynew, z=z_pos)

        # if self.show_plots is not False:
        #     fig = self.plotly_add_traces(
        #         fig, xy_sorted_closed, x_mahalanobis, y_mahalanobis, xnew, ynew
        #     )
        # else:
        #     fig = None

        # return curve_loop_tag, lines_s, points, dstack # commeented just for removing problems with pylint, to be reactivated

    def volume_splines(self):
        contour_ext_fig = []
        contour_int_fig = []
        contour_ext_fig, contour_int_fig = self.binary_threshold(
            contour_ext_fig, contour_int_fig, img_path=self.img_path
        )

        self.slice_index = np.linspace(
            1, len(contour_ext_fig[0, 0, :]) - 1, self.SLICING_COEFFICIENT, dtype=int
        )

        if self.show_plots is True:
            fig = go.Figure(layout=self.layout)
        else:
            print(f"Volume_splines, show_plots:\t{self.show_plots}")
            fig = None

        # fmt: off
        if self.phases >= 1:
            img_contours_ext = sitk.GetImageFromArray(contour_ext_fig, isVector=True)
            image_data_ext = np.transpose(sitk.GetArrayViewFromImage(img_contours_ext), [2, 1, 0])
        if self.phases == 2:
            img_contours_int = sitk.GetImageFromArray(contour_int_fig, isVector=True)
            image_data_int = np.transpose(sitk.GetArrayViewFromImage(img_contours_int), [2, 1, 0])

        contour_ext = []
        contour_int = []
        for i, _slice in enumerate(self.slice_index):
            print(f"Slice:\t{_slice}")
            if self.phases >= 1:
                image_slice_ext = image_data_ext[_slice, :, :][::-1, ::-1]  # TODO: check if ::-1 is still needed (minus sign)
                original, cortical_ext_x, cortical_ext_y = self.sort_surface(image_slice_ext)
                z = np.ones(len(cortical_ext_x)) * (self.spacing[0]* _slice)
                contour_ext = np.append(contour_ext, np.c_[cortical_ext_x, cortical_ext_y, z])

                if self.phases == 1:
                    if self.show_plots is True:
                        fig = self.plotly_add_traces(
                            fig, original, np.c_[contour_ext[:, 0], contour_ext[:, 1]]
                        )
                    else:
                        fig = None
            else:
                print(f"Phases is not >= 1: {self.phases}")

            if self.phases == 2:
                image_slice_int = image_data_int[_slice, :, :][::-1, ::-1]  # TODO: check if ::-1 is still needed (minus sign)
                original, cortical_int_x, cortical_int_y = self.sort_surface(image_slice_int)
                contour_int = np.append(contour_int, np.c_[cortical_int_x, cortical_int_y, z])

                if self.phases == 2:
                    if self.show_plots is True:
                        fig = self.plotly_add_traces(
                            fig, original, np.c_[cortical_int_x, cortical_int_y, z]
                        )
                    else:
                        fig = None
            else:
                print(f"Phases =/= 2: {self.phases}")
        # fmt: on

        if self.show_plots is True:
            self.plotly_makefig(fig)
        elif self.show_plots is False:
            fig = None

        contour_ext = contour_ext.reshape(-1, 3)
        contour_int = contour_int.reshape(-1, 3)

        return contour_ext, contour_int

def main():
    # fmt: off
    img_basefilename = ["C0002234"]
    img_basepath = r"/home/simoneponcioni/Documents/01_PHD/03_Methods/Meshing/Meshing/01_AIM"
simoneponcioni commented 1 year ago

Remember that when you check this you also need to validate the other issue (when phases==2) a few lines below