Class: Nanodicom_Core

Source Location: /nanodicom/core.php

Class Overview [line 23]


Nanodicom_Core class.

Author(s):

Version:

  • 1.2

Copyright:

  • (c) 2010-2011

Variables

Constants

Methods


Child classes:

Nanodicom
abstract Nanodicom class.

Inherited Variables

Inherited Constants

Inherited Methods



Class Details

Nanodicom_Core class.

Tags:

[ Top ]


Class Variables

static $default_dictionary = array('UN', '1', 'Unknown')

[line 63]

Tags:

  • var - default dictionary
  • access - public

Type: array

Overrides:

[ Top ]

static $is_cli =  FALSE

[line 73]

Tags:

  • var - command line environment?
  • access - public

Type: boolean

Overrides:

[ Top ]

static $is_windows =  FALSE

[line 78]

Tags:

  • var - Windows environment?
  • access - public

Type: boolean

Overrides:

[ Top ]

static $items_elements = array(self::ITEM, self::ITEM_DELIMITER, self::SEQUENCE_DELIMITER)

[line 58]

The elements for group 0xFFFE should be Encoded as Implicit VR.

DICOM Standard 09. PS 3.6 - Section 7.5: "Nesting of Data Sets"

Tags:

  • var - item elements
  • access - public

Type: array

Overrides:

[ Top ]

static $vr_array = array(
      'AE' => array('Application Entity', 16, 0),'AS'=>array('Age String',4,1),'AT'=>array('Attribute Tag',4,1),'CS'=>array('Code String',16,0),'DA'=>array('Date',8,1),'DS'=>array('Decimal String',16,0),'DT'=>array('Date Time',26,0),'FL'=>array('Floating Point Single',4,1),'FD'=>array('Floating Point Double',8,1),'IS'=>array('Integer String',12,0),'LO'=>array('Long String',64,0),'LT'=>array('Long Text',10240,0),'OB'=>array('Other Byte String',0,0),'OF'=>array('Other Float String',4294967292,0),'OX'=>array('Mixed. Other {Byte|Word} String',0,0),'OW'=>array('Other Word String',0,0),'PN'=>array('Person Name',64,0),'SH'=>array('Short String',16,0),'SL'=>array('Signed Long',4,1),'SQ'=>array('Sequence of Items',0,0),'SS'=>array('Signed Short',2,1),'ST'=>array('Short Text',1024,0),'TM'=>array('Time',16,0),'UI'=>array('Unique Identifier UID',64,0),'UL'=>array('Unsigned Long',4,1),'UN'=>array('Unknown',0,0),'US'=>array('Unsigned Short',2,1),'UT'=>array('Unlimited Text',4294967294,0))

[line 87]

Value Representations (DICOM Standard PS 3.5 Section 6.2) Bytes = 0 => Undefined length.

Fixed = 1 => Exact field length, otherwise max length. each array contains: Name, Bytes, Fixed

Tags:

  • access - public

Type: array

Overrides:

[ Top ]

static $vr_explicit_4bytes = array('OB', 'OW', 'OF', 'SQ', 'UT', 'UN')

[line 68]

Tags:

  • var - list of vr that have the explicit 4 bytes
  • access - public

Type: array

Overrides:

[ Top ]

static $_read_int =  '_read_int_32'

[line 187]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

static $_write_int =  '_write_int_32'

[line 190]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$errors = array()

[line 208]

Tags:

  • access - public

Type: mixed

Overrides:

[ Top ]

$has_dicom_preamble =  FALSE

[line 199]

Tags:

  • access - public

Type: mixed

Overrides:

[ Top ]

$profiler = array()

[line 202]

Tags:

  • access - public

Type: mixed

Overrides:

[ Top ]

$status =  self::INITIAL

[line 217]

Tags:

  • var - Denotes status of given file.
    1. => Initial (Not parsed yet),
    2. => Partial (Some tags were read),
    3. => Success (Is it a DICOM file),
    4. => Failure (Not a DICOM file)
  • access - public

Type: integer

Overrides:

[ Top ]

$warnings = array()

[line 205]

Tags:

  • access - public

Type: mixed

Overrides:

[ Top ]

$_blob =  ''

[line 247]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_check_deflate_function =  '_check_deflate'

[line 265]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_check_list_function =  '_dummy'

[line 262]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_check_proper_endian_function =  '_check_proper_endian'

[line 268]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_children

[line 250]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_counted_elements =  0

[line 256]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_current_pointer =  0

[line 235]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_dataset = array()

[line 196]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_file_length

[line 232]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_force_load_dictionary =  FALSE

[line 193]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_found_group_8 =  FALSE

[line 259]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_is_parsed =  FALSE

[line 220]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_location

[line 226]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_meta_group_last_byte =  -1

[line 229]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_meta_information_group_length =  NULL

[line 238]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_parent_vr

[line 253]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_preamble

[line 223]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_transfer_syntax =  self::IMPLICIT_VR_LITTLE_ENDIAN

[line 244]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]

$_vr_reading_list = array()

[line 241]

Tags:

  • access - protected

Type: mixed

Overrides:

[ Top ]


Class Methods

static array_get

static mixed array_get( array $array, string $index, [mixed $default = ''])

[line 571]

Public static method to get the value from an array. If index does not exist, it returns the default.

Tags:

  • return - Either the found or the default value
  • access - public

Parameters:

  • array $array - the array to search
  • string $index - the index to look
  • mixed $default - the default value in case index not found

[ Top ]

static decode_transfer_syntax

static array decode_transfer_syntax( string $transfer_syntax)

[line 166]

Get the VR mode and endian from a transfer syntax.

Tags:

  • return - returning the vr mode and endian
  • access - public

Parameters:

  • string $transfer_syntax - transfer syntax to check

[ Top ]

static factory

static Dicom_tool factory( mixed $location, [string $name = 'simple'], [string $type = 'file'])

[line 137]

Create a new Nanodicom instance. It is usually called from a class extended from Nanodicom, ie Dumper

$dicom_object = Nanodicom::factory($location, 'dumper');

or from Nanodicom itself

$dicom_object = Nanodicom::factory($location);

for passing 'blobs', use the second parameter as 'blob'

$dicom_object = Nanodicom::factory($blob, 'blob');

Tags:

  • return - A Tool
  • access - public

Parameters:

  • mixed $location - blob or location of the file
  • string $name - name of the tool to load
  • string $type - type of data passed

[ Top ]

dataset_value

mixed|false|void dataset_value( array &$dataset, [mixed $group = NULL], [mixed $element = NULL], [mixed $new_value = NULL], [boolean $create = FALSE])

[line 702]

Public method to get and set values when passing a dataset.

It supports retrieving a single element or a dataset for reading values

Tags:

  • return - found value or false when tag was not found or not enough arguments or void when setting a value successfully
  • access - public

Parameters:

  • array &$dataset - a dataset
  • mixed $group - either the group or name of the tag
  • mixed $element - either the element or value to set of the tag
  • mixed $new_value - either the value to set or the create
  • boolean $create - flag to allow creation of tag or not

[ Top ]

extend

this extend( string $name)

[line 413]

Public method to extend the tool to include other tools.

It is preferable to load the required tool directly. This mechanism is still under evaluation.

Unknown results when the object is extended and then manipulated and then extended.

Tags:

  • access - public

Parameters:

  • string $name - name of the tool to extend

[ Top ]

flush

this flush( )

[line 526]

Public method to flush the object

Tags:

  • access - public

Parameters:

[ Top ]

get

mixed|false|void get( [mixed $group = NULL], [mixed $element = NULL], [mixed $default = NULL], [mixed $dataset = NULL])

[line 679]

Public method to get the value of an element.

Tags:

  • return - found value or default value
  • access - public

Parameters:

  • mixed $group - either the group or name of the tag
  • mixed $element - either the element or value to set of the tag
  • mixed $default - the default value to return if no value found
  • mixed $dataset - the dataset to use, if not set, used full dataset from parsing

[ Top ]

get_transfer_syntax

string get_transfer_syntax( )

[line 512]

Public method to get the transfer syntax used

Tags:

  • return - trimmed transfer syntax used
  • access - public

Parameters:

[ Top ]

is_dicom

boolean is_dicom( [boolean $allow_partial = FALSE])

[line 494]

Public method to quickly check if file is DICOM. Does a brute force parse of the object and checks the returned status.

Tags:

  • return - true if file was parsed (depends on parameter to check partial reads), false otherwise
  • access - public

Parameters:

  • boolean $allow_partial - set to TRUE to allow partially read files

[ Top ]

last_error

mixed last_error( )

[line 482]

Returns the last error found

Tags:

  • return - last error found or FALSE otherwise
  • access - public

Parameters:

[ Top ]

__construct

Nanodicom __construct( mixed $location, string $name, string $type)

[line 281]

Create a new Nanodicom instance. It is usually called from a class extended from core, ie Dumper

$dicom_object = DICOM_Dumper::factory($location);

Tags:

  • access - public

Parameters:

  • mixed $location - file blob or location of the file
  • string $name - the name of the tool created
  • string $type - type of first parameter

[ Top ]

parse

this parse( [array $vr_reading_list = array()], [boolean $check_dicom_preamble = FALSE])

[line 793]

Parses the object.

If the list of elements has a tag name, dictionaries will be loaded. For performance is better to pass only arrays of the form: array(group, element) where group and element are numbers (hex or decimal equivalents or any other base).

Tags:

  • access - public

Parameters:

  • array $vr_reading_list - a list of elements tags to read. parsing stops when all found.
  • boolean $check_dicom_preamble - a flag to test if dicom file has DCM header only.

[ Top ]

profiler_diff

float profiler_diff( string $name)

[line 454]

Public method to show the profiling time for methods. Profiling names MUST be equal to method names.

Tags:

  • return - the number of seconds used
  • access - public

Parameters:

  • string $name - name of the method

[ Top ]

set_vr_reading_list

this set_vr_reading_list( array $vr_reading_list)

[line 900]

Public method to set the vrs to read

Tags:

  • access - public

Parameters:

  • array $vr_reading_list - a list of elements tags to read. Either names or array of (group,element)

[ Top ]

summary

mixed|false summary( [string $output = 'string'])

[line 585]

Public method to get the summary of the given file.

Tags:

  • return - Either a string, array or FALSE (when file is not DICOM)
  • access - public

Parameters:

  • string $output - how the output is returned. Either as string (ready to be echoed) or array

[ Top ]

value

mixed|false|void value( [mixed $group = NULL], [mixed $element = NULL], [mixed $new_value = NULL], [boolean $create = FALSE])

[line 558]

Public method to get and set values, but only values at top level.

Tags:

  • return - found value or false when tag was not found or not enough arguments or void when setting a value successfully
  • access - public

Parameters:

  • mixed $group - either the group or name of the tag
  • mixed $element - either the element or value to set of the tag
  • mixed $new_value - either the value to set or the create
  • boolean $create - flag to allow creation of tag or not

[ Top ]

write

string write( )

[line 831]

Returns a blob of the current dataset

This function will do some corrections:

  1. Make the File Meta Information EXPLICIT VR LITTLE ENDIAN
  2. Convert Known tags to their real Tag values
  3. Prepends preamble if not present (forces it)
  4. [probably] Prepend File Meta Information if not present (future versions)

Tags:

  • return - binary string of contents
  • access - public

Parameters:

[ Top ]

write_file

this write_file( string $filename)

[line 815]

Writes the file to the specified location

TODO: Throw exceptions in errors

Tags:

  • access - public

Parameters:

  • string $filename - location of the file where the contents will be written

[ Top ]

_check_deflate

void _check_deflate( )

[line 2135]

Tags:

  • access - protected

Parameters:

[ Top ]

_check_list

boolean _check_list( integer $group, integer $element)

[line 983]

Checks if the given group and element are part of the list of elements to look for.

Stops after all elements are found.

Tags:

  • return - true if all elements have been found (finish parsing), false otherwise
  • access - protected

Parameters:

  • integer $group - the group
  • integer $element - the element

[ Top ]

_check_proper_endian

array _check_proper_endian( integer $group, integer $endian)

[line 1010]

Check that proper endian is used

Tags:

  • return - the proper group and endian
  • access - protected

Parameters:

  • integer $group - the group
  • integer $endian - the endian mode

[ Top ]

_check_proper_endian_same

array _check_proper_endian_same( integer $group, integer $endian)

[line 1051]

Returns the same values passed

Tags:

  • return - the group and endian passed
  • access - protected

Parameters:

  • integer $group - the group
  • integer $endian - the endian mode

[ Top ]

_decode_vr

boolean _decode_vr( integer $group, integer $element, $vr, $length)

[line 1068]

Decodes the proper vr from the group, element, current vr and length.

The priority order is: 1) From dictionary 2) If current vr is a valid vr and not UN or empty, then set as current vr (Explicit mode) 3) If length is undefined, most likely it is a sequence, 4) Otherwise is it the default VR ('UN')

Tags:

  • return - true if all elements have been found (finish parsing), false otherwise
  • access - protected

Parameters:

  • integer $group - the group
  • integer $element - the element
  • $vr -
  • $length -

[ Top ]

_dummy

void _dummy( [mixed $arg1 = NULL], [mixed $arg2 = NULL], [mixed $arg3 = NULL], [mixed $arg4 = NULL], [mixed $arg5 = NULL])

[line 933]

Dummy function to be used instead of other time consuming functions.

Tags:

  • access - protected

Parameters:

  • mixed $arg1 -
  • mixed $arg2 -
  • mixed $arg3 -
  • mixed $arg4 -
  • mixed $arg5 -

[ Top ]

_forward

void _forward( integer $offset)

[line 2004]

Moves the current_pointer forward

Tags:

  • access - protected

Parameters:

  • integer $offset - number of bytes to move forward

[ Top ]

_parse

this _parse( [boolean $check_preamble_only = FALSE])

[line 1099]

Parsing code

Tags:

  • return - for chaining
  • access - protected

Parameters:

  • boolean $check_preamble_only - true to check file is dicom, default to false

[ Top ]

_proper_name

string _proper_name( string $name)

[line 969]

Get the proper name of the tag name. Removes spaces and _, and converts it to lowercase.

Tags:

  • return - the proper name
  • access - protected

Parameters:

  • string $name - tag name

[ Top ]

_read

boolean|string _read( [integer $length = NULL])

[line 2104]

Reads specified number of bytes from blob, or checks if there is still data left to be read

Tags:

  • return - boolean when checking if there is still data or a binary string otherwise
  • throws - Nanodicom_Exception
  • access - protected

Parameters:

  • integer $length - number of bytes to read or NULL

[ Top ]

_read_element

void _read_element( )

[line 1244]

Read an element

PS 3.10 Page 22 (2009) Except for the 128 byte preamble and the 4 byte prefix, the File Meta Information shall be encoded using the Explicit VR Little Endian Transfer Syntax (UID=1.2.840.10008.1.2.1) as defined in DICOM PS 3.5. Values of each File Meta Element shall be padded when necessary to achieve an even length, as specified in PS 3.5 by their corresponding Value Representation. The Unknown (UN) Value Representation shall not be used in the File Meta Information. For compatibility with future versions of this Standard, any Tag (0002,xxxx) not defined in Table 7.1-1 shall be ignored.

However, this parser CAN read File Meta Information encoded (wrongly) with Implicit VR Little Endian TODO: Thow a warning

This parser handles (incorrectly set) odd lengths as well.

Tags:

  • throws - Nanodicom_Exception
  • access - protected

Parameters:

[ Top ]

_read_file

void _read_file( [integer $starting_byte = 0], [mixed $length = NULL])

[line 2039]

Read file or blob accordingly

Tags:

  • throws - Nanodicom_Exception
  • access - protected

Parameters:

  • integer $starting_byte - starting byte for reading
  • mixed $length - how many bytes to read

[ Top ]

_read_float

mixed _read_float( integer $bytes, integer $length, integer 2)

[line 1931]

Reads a float

Tags:

  • return - a float or an array of floats
  • access - protected

Parameters:

  • integer 2 - the sign
  • integer $bytes - number of bytes to read per float
  • integer $length - total length to read

[ Top ]

_read_int_32

mixed _read_int_32( integer $bytes, integer $endian, integer $length, [integer $sign = self::UNSIGNED], [string $data = NULL])

[line 1848]

Reads integers

Tags:

  • return - a single value or an array
  • access - protected

Parameters:

  • integer $bytes - the bytes needed per integer
  • integer $endian - the endian mode: Little or Big Endian
  • integer $length - the number of bytes to read
  • integer $sign - the sign
  • string $data - if present, a binary string, otherwise, read from file

[ Top ]

_read_int_64

mixed _read_int_64( integer $bytes, integer $endian, integer $length, [integer $sign = self::UNSIGNED], [string $data = NULL])

[line 1818]

Reads an integer for 64-bit machines

Tags:

  • return - a single value or an array
  • access - protected

Parameters:

  • integer $bytes - the bytes needed per integer
  • integer $endian - the endian mode: Little or Big Endian
  • integer $length - the number of bytes to read
  • integer $sign - the sign
  • string $data - if present, a binary string, otherwise, read from file

[ Top ]

_read_value

array _read_value( string $vr, string $value_representation, integer $length, mixed $vr_mode, [mixed $endian = NULL])

[line 1414]

Read the value of an Tag element accordingly. No numeric values are interpreted. No reading of PN

Tags:

  • return - a list of $value, $value_representation, $is_binary, $items
  • access - protected

Parameters:

  • string $vr - the read VR
  • string $value_representation - the obtained VR
  • integer $length - the number of bytes to read
  • mixed $vr_mode - either the vr_mode already or the transfer syntax
  • mixed $endian - either NULL (not set so decode from transfer syntax), or the endian

[ Top ]

_read_value_from_blob

void _read_value_from_blob( object the &$elem, integer $group, integer $element)

[line 1378]

Read the value from the blob

Tags:

  • access - protected

Parameters:

  • object the &$elem - element array
  • integer $group - the group
  • integer $element - the element

[ Top ]

_rewind

void _rewind( [integer $position = 0])

[line 1984]

Set the current_pointer to a given value

Tags:

  • access - protected

Parameters:

  • integer $position - the new position, defaults to beginning of file

[ Top ]

_tell

integer _tell( )

[line 2026]

Finds current position of pointer

Tags:

  • return - current position of pointer
  • access - protected

Parameters:

[ Top ]

_update_group_length

void _update_group_length( integer &$dataset, $group)

[line 943]

Updates the group length value if exists

Tags:

  • access - protected

Parameters:

  • integer &$dataset - the group
  • $group -

[ Top ]

_write

string _write( integer $group, integer $element, string $data)

[line 1608]

Creates a binary string from the current dataset

Tags:

  • return - the binary string
  • access - protected

Parameters:

  • integer $group - the group
  • integer $element - the element
  • string $data - the data

[ Top ]

_write_float

string _write_float( integer $value, integer $bytes, integer $length)

[line 1955]

Writes a float

Tags:

  • return - the binary value
  • access - protected

Parameters:

  • integer $value - the new value
  • integer $bytes - the bytes needed per integer
  • integer $length - the number of bytes to read

[ Top ]

_write_int_32

string _write_int_32( integer $value, integer $bytes, integer $endian, integer $length, [integer $sign = self::UNSIGNED])

[line 1900]

Writes an integer for 32-bit machines.

Tags:

  • return - the binary value
  • access - protected

Parameters:

  • integer $value - the new value
  • integer $bytes - the bytes needed per integer
  • integer $endian - the endian mode: Little or Big Endian
  • integer $length - the number of bytes to read
  • integer $sign - the sign

[ Top ]

_write_int_64

string _write_int_64( integer $value, integer $bytes, integer $endian, integer $length, [integer $sign = self::UNSIGNED])

[line 1880]

Writes an integer for 64-bit machines. Uses 32-bit function

Tags:

  • return - the binary value
  • access - protected

Parameters:

  • integer $value - the new value
  • integer $bytes - the bytes needed per integer
  • integer $endian - the endian mode: Little or Big Endian
  • integer $length - the number of bytes to read
  • integer $sign - the sign

[ Top ]

__call

mixed|false __call( string $name, $args)

[line 387]

Magic method to call an undefined method. It will look for methods on children Performance is better when called directly

Tags:

  • return - when the method if found in any children or false in case the method does not exist
  • access - public

Parameters:

  • string $name - tag element name
  • $args -

[ Top ]

__get

mixed __get( string $name)

[line 326]

Magic method, calls [Nanodicom::value] with the same parameters. Used to get values by name.

$transfer_syntax = $dicom_object->transfer_syntax;

Tags:

  • access - public

Parameters:

  • string $name - tag element name

[ Top ]

__set

this __set( string $name, mixed $value)

[line 340]

Magic method, calls [Nanodicom::value] with the corresponding group and element based on the tag name.

$dicom_object->patient_name = 'Anonymous';

Tags:

  • access - public

Parameters:

  • string $name - tag element name
  • mixed $value - new value

[ Top ]

__toString

string __toString( )

[line 313]

Returns the name of the loaded file or 'blob'

Tags:

  • return - name of loaded file or 'blob'
  • access - public

Parameters:

[ Top ]

__unset

this __unset( string $name)

[line 361]

Magic method to unset a tag element. To be used wisely.

unset($dicom_object->patient_name);

Tags:

  • access - public

Parameters:

  • string $name - tag element name

[ Top ]


Class Constants

BIG_ENDIAN =  100

[line 29]

[ Top ]

CODENAME =  'Imperial Cuzco'

[line 27]

[ Top ]

DEFLATE_TRANSFER_SYNTAX =  '1.2.840.10008.1.2.1.99'

[line 36]

[ Top ]

EXPLICIT_VR_BIG_ENDIAN =  '1.2.840.10008.1.2.2'

[line 35]

[ Top ]

EXPLICIT_VR_LITTLE_ENDIAN =  '1.2.840.10008.1.2.1'

[line 34]

[ Top ]

FAILURE =  3

[line 51]

[ Top ]

GROUP_8 =  0x0008

[line 39]

[ Top ]

GROUP_LENGTH =  0x0000

[line 37]

[ Top ]

IMPLICIT_VR_LITTLE_ENDIAN =  '1.2.840.10008.1.2'

[line 33]

[ Top ]

INITIAL =  0

[line 48]

[ Top ]

ITEM =  0xE000

[line 45]

[ Top ]

ITEMS_GROUP =  0xFFFE

[line 44]

[ Top ]

ITEM_DELIMITER =  0xE00D

[line 46]

[ Top ]

LITTLE_ENDIAN =  101

[line 30]

[ Top ]

METADATA_GROUP =  0x0002

[line 38]

[ Top ]

PARTIAL =  1

[line 49]

[ Top ]

SEQUENCE_DELIMITER =  0xE0DD

[line 47]

[ Top ]

SEQUENCE_VR =  'SQ'

[line 43]

[ Top ]

SIGNED =  101

[line 42]

[ Top ]

SUCCESS =  2

[line 50]

[ Top ]

UNDEFINED_LENGTH =  -1

[line 40]

[ Top ]

UNSIGNED =  100

[line 41]

[ Top ]

VERSION =  '1.2'

[line 26]

[ Top ]

VR_MODE_EXPLICIT =  101

[line 32]

[ Top ]

VR_MODE_IMPLICIT =  100

[line 31]

[ Top ]


Documentation generated on Thu, 08 Sep 2011 17:22:14 -0700 by phpDocumentor 1.4.3