Skip to content
Commits on Source (3)
#!/usr/bin/python
#!/usr/bin/env python3
#--------------------------------------------------------------------------
# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
......@@ -65,21 +65,9 @@ import invesalius.i18n as i18n
import invesalius.session as ses
import invesalius.utils as utils
FS_ENCODE = sys.getfilesystemencoding()
from invesalius import inv_paths
if sys.platform == 'win32':
from invesalius.expanduser import expand_user
try:
USER_DIR = expand_user()
except:
USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE)
else:
USER_DIR = utils.decode(os.path.expanduser('~'),FS_ENCODE)
USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius')
USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets')
USER_RAYCASTING_PRESETS_DIRECTORY = os.path.join(USER_PRESET_DIR, u'raycasting')
USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs')
FS_ENCODE = sys.getfilesystemencoding()
# ------------------------------------------------------------------
......@@ -147,9 +135,8 @@ class Inv3SplashScreen(SplashScreen):
create_session = True
install_lang = 0
# Check if there is a language set (if session file exists
if session.ReadLanguage():
lang = session.GetLanguage()
lang = session.GetLanguage()
if lang:
if (lang != "False"):
_ = i18n.InstallLanguage(lang)
install_lang = 1
......@@ -179,7 +166,9 @@ class Inv3SplashScreen(SplashScreen):
invdir = os.path.join(homedir, ".invesalius")
shutil.rmtree(invdir)
sys.exit()
dialog.Destroy()
# Session file should be created... So we set the recent
# choosen language
if (create_session):
......@@ -187,18 +176,20 @@ class Inv3SplashScreen(SplashScreen):
session.SetLanguage(lang)
session.WriteSessionFile()
session.SaveConfigFileBackup()
# session.SaveConfigFileBackup()
# Only after language was defined, splash screen will be
# shown
if lang:
# print "LANG", lang, _, wx.Locale(), wx.GetLocale()
import locale
try:
locale.setlocale(locale.LC_ALL, '')
except locale.Error:
pass
#import locale
#try:
# locale.setlocale(locale.LC_ALL, '')
#except locale.Error:
# pass
# For pt_BR, splash_pt.png should be used
if (lang.startswith('pt')):
icon_file = "splash_pt.png"
......@@ -244,9 +235,9 @@ class Inv3SplashScreen(SplashScreen):
self.main = Frame(None)
self.control = Controller(self.main)
self.fc = wx.FutureCall(1, self.ShowMain)
self.fc = wx.CallLater(200, self.ShowMain)
options, args = parse_comand_line()
wx.FutureCall(1, use_cmd_optargs, options, args)
wx.CallLater(1, use_cmd_optargs, options, args)
# Check for updates
from threading import Thread
......@@ -333,6 +324,13 @@ def parse_comand_line():
parser.add_option("-a", "--export-to-all",
help="Export to STL for all mask presets.")
parser.add_option("--export-project",
help="Export slices and mask to HDF5 or Nifti file.")
parser.add_option("--no-masks", action="store_false",
dest="save_masks", default=True,
help="Make InVesalius not export mask when exporting project.")
options, args = parser.parse_args()
return options, args
......@@ -426,6 +424,17 @@ def check_for_export(options, suffix='', remove_surfaces=False):
finally:
exit(0)
if options.export_project:
from invesalius.project import Project
prj = Project()
export_filename = options.export_project
if suffix:
export_filename, ext = os.path.splitext(export_filename)
export_filename = u'{}-{}{}'.format(export_filename, suffix, ext)
prj.export_project(export_filename, save_masks=options.save_masks)
print("Saved {}".format(export_filename))
def export(path_, threshold_range, remove_surface=False):
import invesalius.constants as const
......@@ -489,17 +498,14 @@ if __name__ == '__main__':
os.chdir(path)
# Create raycasting presets' folder, if it doens't exist
if not os.path.isdir(USER_RAYCASTING_PRESETS_DIRECTORY):
os.makedirs(USER_RAYCASTING_PRESETS_DIRECTORY)
# Create logs' folder, if it doesn't exist
if not os.path.isdir(USER_LOG_DIR):
os.makedirs(USER_LOG_DIR)
if not inv_paths.USER_INV_DIR.exists():
inv_paths.create_conf_folders()
if inv_paths.OLD_USER_INV_DIR.exists():
inv_paths.copy_old_files()
if hasattr(sys,"frozen") and sys.frozen == "windows_exe":
# Set system standard error output to file
path = os.path.join(USER_LOG_DIR, u"stderr.log")
path = inv_paths.USER_LOG_DIR.join("stderr.log")
sys.stderr = open(path, "w")
# Add current directory to PYTHONPATH, so other classes can
......
invesalius (3.1.99993-1) unstable; urgency=medium
* New upstream version
-- Thiago Franco de Moraes <tfmoraes@cti.gov.br> Tue, 21 May 2019 11:30:01 -0300
invesalius (3.1.99992-3) unstable; urgency=medium
* Force Python3 >= 3.7 (its also python3-dev rather than python3-all-dev)
......
......@@ -30,6 +30,7 @@ Depends: ${python3:Depends},
python3-nibabel,
python3-serial,
python3-psutil,
python3-h5py,
invesalius-bin
Description: 3D medical imaging reconstruction software
InVesalius generates 3D medical imaging reconstructions based on a sequence of
......
Author: Thiago Franco Moraes
Last-Update: 2016-10-06 14:28:25 +0000
Last-Update: 2019-05-21 11:28:25 -0300
Description: Import cython modules
diff --git a/invesalius/data/mask.py b/invesalius/data/mask.py
index 2bae7b49..40df971d 100644
--- a/invesalius/data/mask.py
+++ b/invesalius/data/mask.py
@@ -30,7 +30,7 @@
@@ -30,7 +30,7 @@ import invesalius.constants as const
import invesalius.data.imagedata_utils as iu
import invesalius.session as ses
......@@ -13,45 +15,54 @@ Description: Import cython modules
from wx.lib.pubsub import pub as Publisher
from scipy import ndimage
diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py
index 44976042..f6ce9e41 100644
--- a/invesalius/data/slice_.py
+++ b/invesalius/data/slice_.py
@@ -31,9 +31,9 @@
@@ -35,10 +35,10 @@ import invesalius.session as ses
import invesalius.utils as utils
from invesalius.data.mask import Mask
from invesalius.project import Project
-from invesalius.data import mips
+from invesalius_cy import mips
-from invesalius.data import transforms
+from invesalius_cy import transforms
import invesalius.data.transformations as transformations
from invesalius.data import transforms
-import invesalius.data.transformations as transformations
+import invesalius_cy as transformations
OTHER=0
PLIST=1
WIDGET=2
diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py
index 5f302d4d..3bd712a4 100644
--- a/invesalius/data/styles.py
+++ b/invesalius/data/styles.py
@@ -45,7 +45,7 @@
@@ -47,7 +47,7 @@ from skimage.morphology import watershed
import invesalius.gui.dialogs as dialogs
from invesalius.data.measures import MeasureData
from invesalius.data.measures import MeasureData, CircleDensityMeasure, PolygonDensityMeasure
-from . import floodfill
+from invesalius_cy import floodfill
import invesalius.data.watershed_process as watershed_process
import invesalius.utils as utils
diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py
index 4a7179b6..fb13078c 100644
--- a/invesalius/data/surface.py
+++ b/invesalius/data/surface.py
@@ -48,7 +48,7 @@
import invesalius.utils as utl
import invesalius.data.vtk_utils as vu
@@ -60,7 +60,7 @@ import invesalius.data.vtk_utils as vu
from invesalius.gui import dialogs
-from invesalius.data import cy_mesh
+from invesalius_cy import cy_mesh
# TODO: Verificar ReleaseDataFlagOn and SetSource
class Surface():
diff --git a/setup.py b/setup.py
index b4962e1d..c8c61ad8 100644
--- a/setup.py
+++ b/setup.py
@@ -11,26 +11,26 @@
@@ -11,26 +11,26 @@ import numpy
if sys.platform.startswith('linux'):
setup(
cmdclass = {'build_ext': build_ext},
......
10_sample_path.patch
10_import_cython_modules.patch
10_remove_python2_shebang.patch
10_remove_py2_prints.patch
......@@ -39,6 +39,7 @@ override_dh_clean:
create-launcher:
echo '#!/bin/sh' > invesalius3
echo 'export INV_SAMPLE_DIR="/usr/share/doc/invesalius-examples/examples/"' >> invesalius3
echo 'export PYTHONPATH=$$PYTHONPATH:"/usr/lib/invesalius"' >> invesalius3
echo 'export INVESALIUS_LIBRARY_PATH="/usr/share/invesalius/"' >> invesalius3
echo 'cd $$INVESALIUS_LIBRARY_PATH' >> invesalius3
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -24,6 +24,7 @@ import wx
import itertools
from invesalius import utils
from invesalius import inv_paths
#from invesalius.project import Project
INVESALIUS_VERSION = "3.1.1"
......@@ -98,9 +99,15 @@ SAGITAL = 3
VOLUME = 4
SURFACE = 5
AXIAL_STR="AXIAL"
CORONAL_STR="CORONAL"
SAGITAL_STR="SAGITAL"
# Measure type
LINEAR = 6
ANGULAR = 7
DENSITY_ELLIPSE = 8
DENSITY_POLYGON = 9
# Colour representing each orientation
ORIENTATION_COLOUR = {'AXIAL': (1,0,0), # Red
......@@ -329,59 +336,13 @@ REDUCE_IMAGEDATA_QUALITY = 0
# PATHS
FS_ENCODE = sys.getfilesystemencoding()
if sys.platform == 'win32':
from invesalius.expanduser import expand_user
try:
USER_DIR = expand_user()
except:
USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE)
else:
USER_DIR = utils.decode(os.path.expanduser('~'), FS_ENCODE)
USER_INV_DIR = os.path.join(USER_DIR, u'.invesalius')
USER_PRESET_DIR = os.path.join(USER_INV_DIR, u'presets')
USER_LOG_DIR = os.path.join(USER_INV_DIR, u'logs')
FILE_PATH = utils.decode(os.path.split(__file__)[0], FS_ENCODE)
if hasattr(sys,"frozen") and (sys.frozen == "windows_exe"\
or sys.frozen == "console_exe"):
abs_path = os.path.abspath(FILE_PATH, u'..', u'..', u'..')
ICON_DIR = os.path.join(abs_path, u"icons")
SAMPLE_DIR = os.path.join(FILE_PATH, u'samples')
DOC_DIR = os.path.join(FILE_PATH, u'docs')
folder=RAYCASTING_PRESETS_DIRECTORY= os.path.join(abs_path, u"presets", u"raycasting")
RAYCASTING_PRESETS_COLOR_DIRECTORY = os.path.join(abs_path, u"presets", u"raycasting", u"color_list")
else:
ICON_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'icons'))
SAMPLE_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'samples'))
DOC_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'docs'))
folder=RAYCASTING_PRESETS_DIRECTORY= os.path.abspath(os.path.join(u".",
u"presets",
u"raycasting"))
RAYCASTING_PRESETS_COLOR_DIRECTORY = os.path.abspath(os.path.join(u".",
u"presets",
u"raycasting",
u"color_list"))
# MAC App
if not os.path.exists(ICON_DIR):
ICON_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'..', u'..', u'..', u'icons'))
SAMPLE_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'..', u'..', u'..', u'samples'))
DOC_DIR = os.path.abspath(os.path.join(FILE_PATH, u'..', u'..', u'..', u'..', u'docs'))
ID_TO_BMP = {VOL_FRONT: [_("Front"), os.path.join(ICON_DIR, u"view_front.png")],
VOL_BACK: [_("Back"), os.path.join(ICON_DIR, u"view_back.png")],
VOL_TOP: [_("Top"), os.path.join(ICON_DIR, u"view_top.png")],
VOL_BOTTOM: [_("Bottom"), os.path.join(ICON_DIR, u"view_bottom.png")],
VOL_RIGHT: [_("Right"), os.path.join(ICON_DIR, u"view_right.png")],
VOL_LEFT: [_("Left"), os.path.join(ICON_DIR, u"view_left.png")],
VOL_ISO:[_("Isometric"), os.path.join(ICON_DIR, u"view_isometric.png")]
ID_TO_BMP = {VOL_FRONT: [_("Front"), str(inv_paths.ICON_DIR.joinpath("view_front.png"))],
VOL_BACK: [_("Back"), str(inv_paths.ICON_DIR.joinpath("view_back.png"))],
VOL_TOP: [_("Top"), str(inv_paths.ICON_DIR.joinpath("view_top.png"))],
VOL_BOTTOM: [_("Bottom"), str(inv_paths.ICON_DIR.joinpath("view_bottom.png"))],
VOL_RIGHT: [_("Right"), str(inv_paths.ICON_DIR.joinpath("view_right.png"))],
VOL_LEFT: [_("Left"), str(inv_paths.ICON_DIR.joinpath("view_left.png"))],
VOL_ISO:[_("Isometric"), str(inv_paths.ICON_DIR.joinpath("view_isometric.png"))]
}
# if 1, use vtkVolumeRaycastMapper, if 0, use vtkFixedPointVolumeRayCastMapper
......@@ -427,10 +388,9 @@ RAYCASTING_FILES = {_("Airways"): "Airways.plist",
# os.path.isfile(os.path.join(folder,filename))]
USER_RAYCASTING_PRESETS_DIRECTORY = os.path.join(USER_PRESET_DIR, u'raycasting')
RAYCASTING_TYPES = [_(filename.split(".")[0]) for filename in
os.listdir(USER_RAYCASTING_PRESETS_DIRECTORY) if
os.path.isfile(os.path.join(USER_RAYCASTING_PRESETS_DIRECTORY, filename))]
RAYCASTING_TYPES = [_(filename.name.split(".")[0]) for filename in
inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY.glob('*') if
filename.is_file()]
RAYCASTING_TYPES += RAYCASTING_FILES.keys()
RAYCASTING_TYPES.append(_(' Off'))
RAYCASTING_TYPES.sort()
......@@ -440,8 +400,8 @@ RAYCASTING_TOOLS = [_("Cut plane")]
# If 0 dont't blur, 1 blur
RAYCASTING_WWWL_BLUR = 0
RAYCASTING_PRESETS_FOLDERS = (RAYCASTING_PRESETS_DIRECTORY,
USER_RAYCASTING_PRESETS_DIRECTORY)
RAYCASTING_PRESETS_FOLDERS = (inv_paths.RAYCASTING_PRESETS_DIRECTORY,
inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY)
####
......@@ -506,10 +466,11 @@ VTK_WARNING = 0
#----------------------------------------------------------
[ID_DICOM_IMPORT, ID_PROJECT_OPEN, ID_PROJECT_SAVE_AS, ID_PROJECT_SAVE,
ID_PROJECT_CLOSE, ID_PROJECT_INFO, ID_SAVE_SCREENSHOT, ID_DICOM_LOAD_NET,
ID_PRINT_SCREENSHOT, ID_IMPORT_OTHERS_FILES, ID_PREFERENCES, ID_DICOM_NETWORK,
ID_TIFF_JPG_PNG, ID_VIEW_INTERPOLATED, ID_MODE_NAVIGATION, ID_ANALYZE_IMPORT,
ID_NIFTI_IMPORT, ID_PARREC_IMPORT] = [wx.NewId() for number in range(18)]
ID_PROJECT_CLOSE, ID_EXPORT_SLICE, ID_EXPORT_MASK, ID_PROJECT_INFO,
ID_SAVE_SCREENSHOT, ID_DICOM_LOAD_NET, ID_PRINT_SCREENSHOT,
ID_IMPORT_OTHERS_FILES, ID_PREFERENCES, ID_DICOM_NETWORK, ID_TIFF_JPG_PNG,
ID_VIEW_INTERPOLATED, ID_MODE_NAVIGATION, ID_ANALYZE_IMPORT, ID_NIFTI_IMPORT,
ID_PARREC_IMPORT, ID_MODE_DBS] = [wx.NewId() for number in range(21)]
ID_EXIT = wx.ID_EXIT
ID_ABOUT = wx.ID_ABOUT
......@@ -546,9 +507,14 @@ ID_WATERSHED_SEGMENTATION = wx.NewId()
ID_THRESHOLD_SEGMENTATION = wx.NewId()
ID_FLOODFILL_SEGMENTATION = wx.NewId()
ID_CROP_MASK = wx.NewId()
ID_DENSITY_MEASURE = wx.NewId()
ID_MASK_DENSITY_MEASURE = wx.NewId()
ID_CREATE_SURFACE = wx.NewId()
ID_CREATE_MASK = wx.NewId()
ID_GOTO_SLICE = wx.NewId()
ID_GOTO_COORD = wx.NewId()
#---------------------------------------------------------
STATE_DEFAULT = 1000
STATE_WL = 1001
......@@ -559,6 +525,9 @@ STATE_PAN = 1005
STATE_ANNOTATE = 1006
STATE_MEASURE_DISTANCE = 1007
STATE_MEASURE_ANGLE = 1008
STATE_MEASURE_DENSITY = 1009
STATE_MEASURE_DENSITY_ELLIPSE = 1010
STATE_MEASURE_DENSITY_POLYGON = 1011
SLICE_STATE_CROSS = 3006
SLICE_STATE_SCROLL = 3007
......@@ -577,7 +546,11 @@ VOLUME_STATE_SEED = 2001
TOOL_STATES = [STATE_WL, STATE_SPIN, STATE_ZOOM,
STATE_ZOOM_SL, STATE_PAN, STATE_MEASURE_DISTANCE,
STATE_MEASURE_ANGLE] #, STATE_ANNOTATE]
STATE_MEASURE_ANGLE, STATE_MEASURE_DENSITY_ELLIPSE,
STATE_MEASURE_DENSITY_POLYGON,
] #, STATE_ANNOTATE]
TOOL_SLICE_STATES = [SLICE_STATE_CROSS, SLICE_STATE_SCROLL,
SLICE_STATE_REORIENT]
......@@ -592,6 +565,9 @@ SLICE_STYLES.append(SLICE_STATE_REMOVE_MASK_PARTS)
SLICE_STYLES.append(SLICE_STATE_SELECT_MASK_PARTS)
SLICE_STYLES.append(SLICE_STATE_FFILL_SEGMENTATION)
SLICE_STYLES.append(SLICE_STATE_CROP_MASK)
SLICE_STYLES.append(STATE_MEASURE_DENSITY)
SLICE_STYLES.append(STATE_MEASURE_DENSITY_ELLIPSE)
SLICE_STYLES.append(STATE_MEASURE_DENSITY_POLYGON)
VOLUME_STYLES = TOOL_STATES + [VOLUME_STATE_SEED, STATE_MEASURE_DISTANCE,
STATE_MEASURE_ANGLE]
......@@ -612,6 +588,9 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1,
STATE_DEFAULT: 0,
STATE_MEASURE_ANGLE: 2,
STATE_MEASURE_DISTANCE: 2,
STATE_MEASURE_DENSITY_ELLIPSE: 2,
STATE_MEASURE_DENSITY_POLYGON: 2,
STATE_MEASURE_DENSITY: 2,
STATE_WL: 2,
STATE_SPIN: 2,
STATE_ZOOM: 2,
......@@ -684,6 +663,7 @@ STATIC_REF = 0
DYNAMIC_REF = 1
DEFAULT_REF_MODE = DYNAMIC_REF
REF_MODE = [_("Static ref."), _("Dynamic ref.")]
FT_SENSOR_MODE = [_("Sensor 3"), _("Sensor 4")]
DEFAULT_COIL = SELECT
COIL = [_("Select coil:"), _("Neurosoft Figure-8"),
......@@ -711,13 +691,11 @@ TIPS_IMG = [_("Select left ear in image"),
BTNS_TRK = {TR1: {3: _('LET')},
TR2: {4: _('RET')},
TR3: {5: _('NAT')},
SET: {6: _('SET')}}
TR3: {5: _('NAT')}}
TIPS_TRK = [_("Select left ear with spatial tracker"),
_("Select right ear with spatial tracker"),
_("Select nasion with spatial tracker"),
_("Show set coordinates in image")]
_("Select nasion with spatial tracker")]
OBJL = wx.NewId()
OBJR = wx.NewId()
......@@ -737,11 +715,11 @@ TIPS_OBJ = [_("Select left object fiducial"),
_("Select object center"),
_("Attach sensor to object")]
CAL_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'CalibrationFiles'))
MAR_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'mtc_files', 'Markers'))
PROBE_NAME = "1Probe"
REF_NAME = "2Ref"
OBJ_NAME = "3Coil"
#OBJECT TRACKING
OBJ_DIR = os.path.abspath(os.path.join(FILE_PATH, '..', 'navigation', 'objects'))
ARROW_SCALE = 3
ARROW_UPPER_LIMIT = 30
#COIL_ANGLES_THRESHOLD = 3 * ARROW_SCALE
......
......@@ -42,6 +42,8 @@ import invesalius.gui.dialogs as dialogs
import subprocess
import sys
from invesalius import inv_paths
DEFAULT_THRESH_MODE = 0
class Controller():
......@@ -58,7 +60,8 @@ class Controller():
#None, others and opened Project = 0
#DICOM = 1
#TIFF uCT = 2
self.img_type = 0
self.img_type = 0
self.affine = None
#Init session
session = ses.Session()
......@@ -108,6 +111,8 @@ class Controller():
Publisher.subscribe(self.OnSaveProject, 'Save project')
Publisher.subscribe(self.Send_affine, 'Get affine matrix')
def SetBitmapSpacing(self, spacing):
proj = prj.Project()
proj.spacing = spacing
......@@ -249,6 +254,7 @@ class Controller():
def ShowDialogCloseProject(self):
session = ses.Session()
st = session.project_status
print('Status', st, type(st))
if st == const.PROJ_CLOSE:
return -1
try:
......@@ -367,6 +373,7 @@ class Controller():
session = ses.Session()
session.CloseProject()
Publisher.sendMessage('Update status text in GUI', label=_("Ready"))
###########################
def StartImportBitmapPanel(self, path):
......@@ -656,6 +663,7 @@ class Controller():
proj.level = self.Slice.window_level
proj.threshold_range = int(matrix.min()), int(matrix.max())
proj.spacing = self.Slice.spacing
proj.affine = self.affine.tolist()
######
session = ses.Session()
......@@ -712,7 +720,7 @@ class Controller():
else:
return
xyspacing = xyspacing[0] / resolution_percentage, xyspacing[1] / resolution_percentage
xyspacing = xyspacing[0] / resolution_percentage, xyspacing[1] / resolution_percentage
......@@ -811,7 +819,7 @@ class Controller():
else:
return
xyspacing = xyspacing[0] / resolution_percentage, xyspacing[1] / resolution_percentage
xyspacing = xyspacing[0] / resolution_percentage, xyspacing[1] / resolution_percentage
self.matrix, scalar_range, self.filename = image_utils.dcm2memmap(filelist, size,
orientation, resolution_percentage)
......@@ -859,6 +867,10 @@ class Controller():
self.matrix, scalar_range, self.filename = image_utils.img2memmap(group)
hdr = group.header
if group.affine.any():
self.affine = group.affine
Publisher.sendMessage('Update affine matrix',
affine=self.affine, status=True)
hdr.set_data_dtype('int16')
dims = hdr.get_zooms()
dimsf = tuple([float(s) for s in dims])
......@@ -879,6 +891,11 @@ class Controller():
threshold_range=scalar_range)
return self.matrix, self.filename
def Send_affine(self):
if self.affine is not None:
Publisher.sendMessage('Update affine matrix',
affine=self.affine, status=True)
def LoadImagedataInfo(self):
proj = prj.Project()
......@@ -905,13 +922,13 @@ class Controller():
def LoadRaycastingPreset(self, preset_name):
if preset_name != const.RAYCASTING_OFF_LABEL:
if preset_name in const.RAYCASTING_FILES.keys():
path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY,
path = os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY,
const.RAYCASTING_FILES[preset_name])
else:
path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY,
path = os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY,
preset_name+".plist")
if not os.path.isfile(path):
path = os.path.join(const.USER_RAYCASTING_PRESETS_DIRECTORY,
path = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY,
preset_name+".plist")
preset = plistlib.readPlist(path)
prj.Project().raycasting_preset = preset
......@@ -925,7 +942,7 @@ class Controller():
def SaveRaycastingPreset(self, preset_name):
preset = prj.Project().raycasting_preset
preset['name'] = preset_name
preset_dir = os.path.join(const.USER_RAYCASTING_PRESETS_DIRECTORY,
preset_dir = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY,
preset_name + '.plist')
plistlib.writePlist(preset, preset_dir)
......
......@@ -21,7 +21,7 @@ import numpy
import vtk
from vtk.util import numpy_support
def to_vtk(n_array, spacing, slice_number, orientation):
def to_vtk(n_array, spacing, slice_number, orientation, origin=(0, 0, 0), padding=(0, 0, 0)):
if orientation == "SAGITTAL":
orientation = "SAGITAL"
......@@ -32,20 +32,22 @@ def to_vtk(n_array, spacing, slice_number, orientation):
dy, dx = n_array.shape
dz = 1
px, py, pz = padding
v_image = numpy_support.numpy_to_vtk(n_array.flat)
if orientation == 'AXIAL':
extent = (0, dx -1, 0, dy -1, slice_number, slice_number + dz - 1)
extent = (0 - px , dx -1 - px, 0 - py, dy - 1 - py, slice_number - pz, slice_number + dz - 1 - pz)
elif orientation == 'SAGITAL':
dx, dy, dz = dz, dx, dy
extent = (slice_number, slice_number + dx - 1, 0, dy - 1, 0, dz - 1)
extent = (slice_number - px, slice_number + dx - 1 - px, 0 - py, dy - 1 - py, 0 - pz, dz - 1 - pz)
elif orientation == 'CORONAL':
dx, dy, dz = dx, dz, dy
extent = (0, dx - 1, slice_number, slice_number + dy - 1, 0, dz - 1)
extent = (0 - px, dx - 1 - px, slice_number - py, slice_number + dy - 1 - py, 0 - pz, dz - 1 - pz)
# Generating the vtkImageData
image = vtk.vtkImageData()
image.SetOrigin(0, 0, 0)
image.SetOrigin(origin)
image.SetSpacing(spacing)
image.SetDimensions(dx, dy, dz)
# SetNumberOfScalarComponents and SetScalrType were replaced by
......
......@@ -54,37 +54,22 @@ def GetCoordinates(trck_init, trck_id, ref_mode):
def ClaronCoord(trck_init, trck_id, ref_mode):
trck = trck_init[0]
scale = np.array([1.0, 1.0, -1.0])
coord = None
k = 0
# TODO: try to replace 'while' and use some Claron internal computation
trck.Run()
scale = np.array([1.0, 1.0, 1.0])
if ref_mode:
while k < 20:
try:
trck.Run()
probe = np.array([trck.PositionTooltipX1, trck.PositionTooltipY1,
trck.PositionTooltipZ1, trck.AngleX1, trck.AngleY1, trck.AngleZ1])
reference = np.array([trck.PositionTooltipX2, trck.PositionTooltipY2,
trck.PositionTooltipZ2, trck.AngleZ2, trck.AngleY2, trck.AngleX2])
k = 30
except AttributeError:
k += 1
print("wait, collecting coordinates ...")
if k == 30:
coord = dynamic_reference(probe, reference)
coord = (coord[0] * scale[0], coord[1] * scale[1], coord[2] * scale[2], coord[3], coord[4], coord[5])
else:
while k < 20:
try:
trck.Run()
coord = np.array([trck.PositionTooltipX1 * scale[0], trck.PositionTooltipY1 * scale[1],
trck.PositionTooltipZ1 * scale[2], trck.AngleX1, trck.AngleY1, trck.AngleZ1])
coord1 = np.array([float(trck.PositionTooltipX1)*scale[0], float(trck.PositionTooltipY1)*scale[1],
float(trck.PositionTooltipZ1)*scale[2],
float(trck.AngleZ1), float(trck.AngleY1), float(trck.AngleX1)])
k = 30
except AttributeError:
k += 1
print("wait, collecting coordinates ...")
coord2 = np.array([float(trck.PositionTooltipX2)*scale[0], float(trck.PositionTooltipY2)*scale[1],
float(trck.PositionTooltipZ2)*scale[2],
float(trck.AngleZ2), float(trck.AngleY2), float(trck.AngleX2)])
coord3 = np.array([float(trck.PositionTooltipX3) * scale[0], float(trck.PositionTooltipY3) * scale[1],
float(trck.PositionTooltipZ3) * scale[2],
float(trck.AngleZ3), float(trck.AngleY3), float(trck.AngleX3)])
coord = np.vstack([coord1, coord2, coord3])
Publisher.sendMessage('Sensors ID', probe_id=trck.probeID, ref_id=trck.refID)
......@@ -124,7 +109,10 @@ def PolhemusWrapperCoord(trck, trck_id, ref_mode):
coord3 = np.array([float(trck.PositionTooltipX3) * scale[0], float(trck.PositionTooltipY3) * scale[1],
float(trck.PositionTooltipZ3) * scale[2],
float(trck.AngleX3), float(trck.AngleY3), float(trck.AngleZ3)])
coord = np.vstack([coord, coord3])
coord4 = np.array([float(trck.PositionTooltipX4) * scale[0], float(trck.PositionTooltipY4) * scale[1],
float(trck.PositionTooltipZ4) * scale[2],
float(trck.AngleX4), float(trck.AngleY4), float(trck.AngleZ4)])
coord = np.vstack([coord, coord3, coord4])
if trck.StylusButton:
Publisher.sendMessage('PLH Stylus Button On')
......@@ -174,33 +162,31 @@ def PolhemusSerialCoord(trck_init, trck_id, ref_mode):
# aoflt -> 0:letter 1:x 2:y 3:z
# this method is not optimized to work with all trackers, only with ISOTRAK
# serial connection is obsolete, remove in future
trck_init.write("P")
trck_init.write(str.encode("P"))
scale = 10. * np.array([1., 1.0, 1.0])
lines = trck_init.readlines()
coord = None
if lines[0][0] != '0':
if lines is None:
print("The Polhemus is not connected!")
else:
for s in lines:
if s[1] == '1':
data = s
elif s[1] == '2':
data = s
# single ref mode
if not ref_mode:
data = data.replace('-', ' -')
data = [s for s in data.split()]
j = 0
while j == 0:
try:
plh1 = [float(s) for s in data[1:len(data)]]
j = 1
except:
print("error!!")
coord = data[0:6]
data = lines[0]
data = data.replace(str.encode('-'), str.encode(' -'))
data = [s for s in data.split()]
data = [float(s) for s in data[1:len(data)]]
probe = np.array([data[0] * scale[0], data[1] * scale[1], data[2] * scale[2], data[3], data[4], data[5]])
if ref_mode:
data2 = lines[1]
data2 = data2.replace(str.encode('-'), str.encode(' -'))
data2 = [s for s in data2.split()]
data2 = [float(s) for s in data2[1:len(data2)]]
reference = np.array(
[data2[0] * scale[0], data2[1] * scale[1], data2[2] * scale[2], data2[3], data2[4], data2[5]])
else:
reference = np.zeros(6)
coord = np.vstack([probe, reference])
return coord
......@@ -225,9 +211,12 @@ def DebugCoord(trk_init, trck_id, ref_mode):
coord3 = np.array([uniform(1, 200), uniform(1, 200), uniform(1, 200),
uniform(-180.0, 180.0), uniform(-180.0, 180.0), uniform(-180.0, 180.0)])
coord4 = np.array([uniform(1, 200), uniform(1, 200), uniform(1, 200),
uniform(-180.0, 180.0), uniform(-180.0, 180.0), uniform(-180.0, 180.0)])
Publisher.sendMessage('Sensors ID', probe_id=int(uniform(0, 5)), ref_id=int(uniform(0, 5)))
return np.vstack([coord1, coord2, coord3])
return np.vstack([coord1, coord2, coord3, coord4])
def dynamic_reference(probe, reference):
......
......@@ -117,9 +117,7 @@ class Editor:
# a = (int(self.txtThresI.GetValue()), int(self.txtThresF.GetValue()))
# self.editor.SetOperationType(op, a)
wx, wy, wz = self.From3dToImagePixel(pos, (x, y, z))
print "Comecei"
self.DoOperation(wx, wy, wz)
print "Terminei"
Publisher.sendMessage('Update images', self.image)
Publisher.sendMessage('Update viewer', None)
......@@ -135,7 +133,6 @@ class Editor:
"""
x, y, z = pPos
bounds = self.actor.GetBounds()
print bounds
#c = vtk.vtkCoordinate()
#c.SetCoordinateSystemToWorld()
......@@ -228,15 +225,11 @@ class Editor:
cursor = self.cursor
b = [0,0,0,0,0,0]
self.actor.GetDisplayBounds(b)
print "To Paint", xc, yc, zc
print "Bounds", b
print "dimensions", self.image.GetDimensions()
xs, ys, zs = self.image.GetSpacing()
try:
zs = (b[-1]-b[-2]) / self.image.GetDimensions()[2]
except ZeroDivisionError:
pass
print xs, ys, zs
if self.orientation == AXIAL:
o = lambda x, y: (xc + x, y + yc, zc)
elif self.orientation == CORONAL:
......
This diff is collapsed.
......@@ -37,6 +37,8 @@ import invesalius.reader.bitmap_reader as bitmap_reader
import invesalius.utils as utils
import invesalius.data.converters as converters
from invesalius import inv_paths
if sys.platform == 'win32':
try:
import win32api
......@@ -335,7 +337,7 @@ def CreateImageData(filelist, zspacing, xyspacing,size,
message = _("Generating multiplanar visualization...")
if not const.VTK_WARNING:
log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt')
log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt')
fow = vtk.vtkFileOutputWindow()
fow.SetFileName(log_path)
ow = vtk.vtkOutputWindow()
......@@ -440,7 +442,7 @@ class ImageCreator:
message = _("Generating multiplanar visualization...")
if not const.VTK_WARNING:
log_path = os.path.join(const.USER_LOG_DIR, 'vtkoutput.txt')
log_path = os.path.join(inv_paths.USER_LOG_DIR, 'vtkoutput.txt')
fow = vtk.vtkFileOutputWindow()
fow.SetFileName(log_path)
ow = vtk.vtkOutputWindow()
......
......@@ -4,7 +4,7 @@ import numpy as np
cimport numpy as np
cimport cython
from libc.math cimport floor, ceil, sqrt, fabs, round, sin, M_PI
from libc.math cimport floor, ceil, sqrt, fabs, sin, M_PI
from cython.parallel import prange
DEF LANCZOS_A = 4
......@@ -81,7 +81,7 @@ cdef double[64][64] temp = [
@cython.cdivision(True)
@cython.wraparound(False)
cdef double nearest_neighbour_interp(image_t[:, :, :] V, double x, double y, double z) nogil:
return V[<int>round(z), <int>round(y), <int>round(x)]
return V[<int>(z), <int>(y), <int>(x)]
@cython.boundscheck(False) # turn of bounds-checking for entire function
@cython.cdivision(True)
......
This diff is collapsed.