Skip to content

Commit

Permalink
Fix name of Python module
Browse files Browse the repository at this point in the history
  • Loading branch information
lamyj committed Apr 8, 2016
1 parent 0f66c12 commit 43df08f
Show file tree
Hide file tree
Showing 29 changed files with 320 additions and 317 deletions.
12 changes: 6 additions & 6 deletions applications/echo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import _odil
import odil

def add_subparser(subparsers):
parser = subparsers.add_parser(
Expand All @@ -15,22 +15,22 @@ def add_subparser(subparsers):
return parser

def echo(host, port, calling_ae_title, called_ae_title):
association = _odil.Association()
association = odil.Association()
association.set_peer_host(host)
association.set_peer_port(port)
association.update_parameters()\
.set_calling_ae_title(calling_ae_title)\
.set_called_ae_title(called_ae_title) \
.set_presentation_contexts([
_odil.AssociationParameters.PresentationContext(
3, _odil.registry.VerificationSOPClass,
[ _odil.registry.ImplicitVRLittleEndian ], True, False
odil.AssociationParameters.PresentationContext(
3, odil.registry.VerificationSOPClass,
[ odil.registry.ImplicitVRLittleEndian ], True, False
)
])
association.associate()
logging.info("Association established")

echo = _odil.EchoSCU(association)
echo = odil.EchoSCU(association)
echo.echo()
logging.info("C-ECHO successful")

Expand Down
26 changes: 13 additions & 13 deletions applications/find.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import _odil
import odil

from print_ import find_max_name_length, print_data_set

Expand All @@ -23,42 +23,42 @@ def add_subparser(subparsers):
return parser

def find(host, port, calling_ae_title, called_ae_title, level, keys, decode_uids):
query = _odil.DataSet()
query = odil.DataSet()
for key in keys:
if "=" in key:
key, value = key.split("=", 1)
value = value.split("\\")
else:
value = None

tag = getattr(_odil.registry, key)
tag = getattr(odil.registry, key)

if value is not None:
vr = _odil.registry.public_dictionary[tag].vr
vr = odil.registry.public_dictionary[tag].vr
if vr in ["DS", "FL", "FD"]:
value = _odil.Value.Reals([float(x) for x in value])
value = odil.Value.Reals([float(x) for x in value])
elif vr in ["IS", "SL", "SS", "UL", "US"]:
value = _odil.Value.Integers([int(x) for x in value])
value = odil.Value.Integers([int(x) for x in value])
else:
value = _odil.Value.Strings(value)
value = odil.Value.Strings(value)

query.add(tag, value)
else:
query.add(tag)

sop_class = getattr(
_odil.registry,
odil.registry,
"{}RootQueryRetrieveInformationModelFIND".format(level.capitalize()))

find_pc = _odil.AssociationParameters.PresentationContext(
find_pc = odil.AssociationParameters.PresentationContext(
1, sop_class,
[
_odil.registry.ImplicitVRLittleEndian,
_odil.registry.ExplicitVRLittleEndian
odil.registry.ImplicitVRLittleEndian,
odil.registry.ExplicitVRLittleEndian
], True, False
)

association = _odil.Association()
association = odil.Association()
association.set_peer_host(host)
association.set_peer_port(port)
association.update_parameters()\
Expand All @@ -68,7 +68,7 @@ def find(host, port, calling_ae_title, called_ae_title, level, keys, decode_uids
association.associate()
logging.info("Association established")

find = _odil.FindSCU(association)
find = odil.FindSCU(association)
find.set_affected_sop_class(sop_class)
data_sets = find.find(query)
print "{} answer{}".format(len(data_sets), "s" if len(data_sets)>1 else "")
Expand Down
18 changes: 9 additions & 9 deletions applications/print_.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import _odil
import odil

def add_subparser(subparsers):
parser = subparsers.add_parser(
Expand All @@ -18,7 +18,7 @@ def add_subparser(subparsers):
def print_(inputs, print_header, decode_uids):
for input in inputs:
logging.info("Printing {}".format(input))
header, data_set = _odil.read(input)
header, data_set = odil.read(input)

max_length = find_max_name_length(data_set)
if print_header:
Expand All @@ -32,8 +32,8 @@ def print_(inputs, print_header, decode_uids):
def print_data_set(data_set, decode_uids, padding, max_length):
for tag, element in data_set.items():
name = "{:04x},{:04x}".format(tag.group, tag.element)
if tag in _odil.registry.public_dictionary:
entry = _odil.registry.public_dictionary[tag]
if tag in odil.registry.public_dictionary:
entry = odil.registry.public_dictionary[tag]
name = entry.name

if element.is_data_set():
Expand All @@ -54,10 +54,10 @@ def print_data_set(data_set, decode_uids, padding, max_length):
getter = element.as_string
value = [x for x in getter()]

if decode_uids and element.vr == _odil.VR.UI:
if decode_uids and element.vr == odil.VR.UI:
value = [
_odil.registry.uids_dictionary[uid].name
if uid in _odil.registry.uids_dictionary else uid
odil.registry.uids_dictionary[uid].name
if uid in odil.registry.uids_dictionary else uid
for uid in value
]

Expand All @@ -77,8 +77,8 @@ def print_data_set(data_set, decode_uids, padding, max_length):

def find_max_name_length(data_set, max_length=0, padding_length=0):
for tag, element in data_set.items():
if tag in _odil.registry.public_dictionary:
entry = _odil.registry.public_dictionary[tag]
if tag in odil.registry.public_dictionary:
entry = odil.registry.public_dictionary[tag]
length = len(entry.name)
else:
length = 9 # xxxx,yyyy
Expand Down
18 changes: 9 additions & 9 deletions applications/transcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import _odil
import odil

def add_subparser(subparsers):
parser = subparsers.add_parser(
Expand All @@ -27,8 +27,8 @@ def transcode(input, output, format, transfer_syntax, pretty_print):

if format == "binary":
if transfer_syntax:
transfer_syntax = getattr(_odil.registry, transfer_syntax)
ts_info = _odil.registry.uids_dictionary[transfer_syntax]
transfer_syntax = getattr(odil.registry, transfer_syntax)
ts_info = odil.registry.uids_dictionary[transfer_syntax]
if ts_info.type != "Transfer Syntax":
raise Exception(
"{} is not a transfer syntax".format(ts_info.name))
Expand All @@ -43,17 +43,17 @@ def transcode(input, output, format, transfer_syntax, pretty_print):
globals()["as_{}".format(format)](input, output, **kwargs)

def as_binary(input, output, transfer_syntax):
_, data_set = _odil.read(input)
_odil.write(data_set, output, transfer_syntax=transfer_syntax)
_, data_set = odil.read(input)
odil.write(data_set, output, transfer_syntax=transfer_syntax)

def as_json(input, output, pretty_print):
_, data_set = _odil.read(input)
_, data_set = odil.read(input)
with open(output, "w") as fd:
json = _odil.as_json(data_set, pretty_print)
json = odil.as_json(data_set, pretty_print)
fd.write(json)

def as_xml(input, output, pretty_print):
_, data_set = _odil.read(input)
_, data_set = odil.read(input)
with open(output, "w") as fd:
xml = _odil.as_xml(data_set, pretty_print)
xml = odil.as_xml(data_set, pretty_print)
fd.write(xml)
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ file(GLOB_RECURSE examples *.cpp)
foreach(example_file ${examples})
get_filename_component(example ${example_file} NAME_WE)
add_executable(${example} ${example_file})
target_link_libraries(${example} odil)
target_link_libraries(${example} libodil)
endforeach()

file(GLOB_RECURSE python_examples *.py)
Expand Down
18 changes: 9 additions & 9 deletions examples/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import sys

import _odil
import odil

def main():
parser = argparse.ArgumentParser(description="Convert a DICOM file")
Expand All @@ -16,22 +16,22 @@ def main():
help="Include group length tags")
arguments = parser.parse_args()

if arguments.transfer_syntax not in dir(_odil.registry):
if arguments.transfer_syntax not in dir(odil.registry):
parser.error("Unknown transfer syntax")
uid = getattr(_odil.registry, arguments.transfer_syntax)
if uid not in _odil.registry.uids_dictionary:
uid = getattr(odil.registry, arguments.transfer_syntax)
if uid not in odil.registry.uids_dictionary:
parser.error("Unknown transfer syntax")
if _odil.registry.uids_dictionary[uid].type != "Transfer Syntax":
if odil.registry.uids_dictionary[uid].type != "Transfer Syntax":
parser.error("Not a transfer syntax")
arguments.transfer_syntax = uid

arguments.item_length = getattr(
_odil.Writer.ItemEncoding, "{}Length".format(arguments.item_length))
odil.Writer.ItemEncoding, "{}Length".format(arguments.item_length))

convert(**arguments.__dict__)

def convert(input, output, transfer_syntax, item_length, use_group_length):
header, data_set = _odil.read(input)
header, data_set = odil.read(input)

to_remove = [
"FileMetaInformationVersion",
Expand All @@ -40,9 +40,9 @@ def convert(input, output, transfer_syntax, item_length, use_group_length):
"ImplementationClassUID", "ImplementationVersionName"
]
for name in to_remove:
header.remove(getattr(_odil.registry, name))
header.remove(getattr(odil.registry, name))

_odil.write(data_set, output, header, transfer_syntax, item_length, use_group_length)
odil.write(data_set, output, header, transfer_syntax, item_length, use_group_length)

if __name__ == "__main__":
sys.exit(main())
18 changes: 9 additions & 9 deletions examples/dump.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import sys

import _odil
import odil

def main():
parser = argparse.ArgumentParser(description="Print content of DICOM file")
Expand All @@ -12,7 +12,7 @@ def main():
"--decode-uids", "-D", action="store_true", help="Display UID names")
arguments = parser.parse_args()

header, data_set = _odil.read(arguments.file)
header, data_set = odil.read(arguments.file)
if arguments.header:
print_data_set(header, arguments.decode_uids)
print
Expand All @@ -21,14 +21,14 @@ def main():
def print_data_set(data_set, decode_uids=False, padding=""):
max_length = 0
for tag in data_set.keys():
if tag in _odil.registry.public_dictionary:
entry = _odil.registry.public_dictionary[tag]
if tag in odil.registry.public_dictionary:
entry = odil.registry.public_dictionary[tag]
max_length = max(max_length, len(entry.name))

for tag, element in data_set.items():
name = "{:04x},{:04x}".format(tag.group, tag.element)
if tag in _odil.registry.public_dictionary:
entry = _odil.registry.public_dictionary[tag]
if tag in odil.registry.public_dictionary:
entry = odil.registry.public_dictionary[tag]
name = entry.name

if element.is_data_set():
Expand All @@ -46,10 +46,10 @@ def print_data_set(data_set, decode_uids=False, padding=""):
getter = element.as_string
value = [x for x in getter()]

if decode_uids and element.vr == _odil.VR.UI:
if decode_uids and element.vr == odil.VR.UI:
value = [
_odil.registry.uids_dictionary[uid].name
if uid in _odil.registry.uids_dictionary else uid
odil.registry.uids_dictionary[uid].name
if uid in odil.registry.uids_dictionary else uid
for uid in value
]

Expand Down
34 changes: 17 additions & 17 deletions examples/find.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import _odil
import odil

association = _odil.Association()
association = odil.Association()
association.set_peer_host("184.73.255.26")
association.set_peer_port(11112)

presentation_contexts = [
_odil.AssociationParameters.PresentationContext(
1, _odil.registry.StudyRootQueryRetrieveInformationModelFIND,
[ _odil.registry.ExplicitVRLittleEndian ], True, False
odil.AssociationParameters.PresentationContext(
1, odil.registry.StudyRootQueryRetrieveInformationModelFIND,
[ odil.registry.ExplicitVRLittleEndian ], True, False
),
_odil.AssociationParameters.PresentationContext(
3, _odil.registry.VerificationSOPClass,
[ _odil.registry.ExplicitVRLittleEndian ], True, False
odil.AssociationParameters.PresentationContext(
3, odil.registry.VerificationSOPClass,
[ odil.registry.ExplicitVRLittleEndian ], True, False
)
]

Expand All @@ -21,20 +21,20 @@
.set_presentation_contexts(presentation_contexts)
association.associate()

query = _odil.DataSet()
query.add(_odil.registry.PatientName, _odil.Value.Strings(["*"]))
query.add(_odil.registry.QueryRetrieveLevel, _odil.Value.Strings(["STUDY"]))
query.add(_odil.registry.StudyDescription)
query.add(_odil.registry.StudyDate)
query = odil.DataSet()
query.add(odil.registry.PatientName, odil.Value.Strings(["*"]))
query.add(odil.registry.QueryRetrieveLevel, odil.Value.Strings(["STUDY"]))
query.add(odil.registry.StudyDescription)
query.add(odil.registry.StudyDate)

find = _odil.FindSCU(association)
find.set_affected_sop_class(_odil.registry.StudyRootQueryRetrieveInformationModelFIND)
find = odil.FindSCU(association)
find.set_affected_sop_class(odil.registry.StudyRootQueryRetrieveInformationModelFIND)

def callback(data_set):
print data_set.as_string(_odil.registry.PatientName)[0]
print data_set.as_string(odil.registry.PatientName)[0]
find.find(query, callback)

data_sets = find.find(query)
print len(data_sets), "found"
for data_set in data_sets:
print data_set.as_string(_odil.registry.PatientName)[0]
print data_set.as_string(odil.registry.PatientName)[0]
9 changes: 5 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ add_definitions(
)
link_directories(${Boost_LIBRARY_DIRS} ${DCMTK_LIBRARY_DIRS})

add_library(odil SHARED ${files} ${headers} ${templates})
add_library(libodil SHARED ${files} ${headers} ${templates})
set_target_properties(libodil PROPERTIES OUTPUT_NAME odil)

target_link_libraries(odil
target_link_libraries(libodil
${Boost_LIBRARIES} ${DCMTK_LIBRARIES} ${ICU_LIBRARIES} ${JsonCpp_LIBRARIES})
set_target_properties(odil PROPERTIES
set_target_properties(libodil PROPERTIES
VERSION ${odil_VERSION}
SOVERSION ${odil_MAJOR_VERSION})

install(
DIRECTORY odil/ DESTINATION include/odil
FILES_MATCHING PATTERN "*.h" PATTERN "*.txx")
install(
TARGETS odil
TARGETS libodil
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
Loading

0 comments on commit 43df08f

Please sign in to comment.