r3381: Add sandbox for ImageMagick support

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-02-17 Fabien Freling <fabien.freling@lrde.epita.fr> Add sandbox for ImageMagick support. * fabien/dicom/load.hh: Minor update of dcmtk support. * fabien/dicom/save.hh: Minor update of dcmtk support. * fabien/magick/Makefile: New file to help testing. * fabien/magick/load.hh: ImageMagick load support. * fabien/magick/magick.cc: Test file. --- dicom/load.hh | 591 ++++++++++++++++++++----------------------------------- dicom/save.hh | 220 -------------------- magick/Makefile | 2 magick/load.hh | 142 +++++++++++++ magick/magick.cc | 14 + 5 files changed, 374 insertions(+), 595 deletions(-) Index: trunk/milena/sandbox/fabien/dicom/save.hh =================================================================== --- trunk/milena/sandbox/fabien/dicom/save.hh (revision 3380) +++ trunk/milena/sandbox/fabien/dicom/save.hh (revision 3381) @@ -949,223 +949,3 @@ return 0; } - -//******************************* - -/* -** CVS/RCS Log: -** $Log: dump2dcm.cc,v $ -** Revision 1.51 2005/12/16 09:07:03 onken -** - Added variable initialization to avoid compiler warning -** -** Revision 1.50 2005/12/08 15:40:50 meichel -** Changed include path schema for all DCMTK header files -** -** Revision 1.49 2004/07/13 09:43:10 meichel -** Fixed memory leak occuring when raw data is read from file. -** -** Revision 1.48 2004/03/05 09:59:00 joergr -** Avoid wrong warning for LUTData (0028,3006) having a VR of US or SS. -** Added initial "hooks" for (compressed) pixel items. -** Added "ignore errors" option (similar to dcmdump). -** -** Revision 1.47 2004/01/16 10:53:16 joergr -** Adapted type casts to new-style typecast operators defined in ofcast.h. -** Removed acknowledgements with e-mail addresses from CVS log. -** -** Revision 1.46 2003/11/05 16:15:27 meichel -** Removed useless "--write-xfer-same" command line option -** -** Revision 1.45 2002/12/05 13:59:29 joergr -** Fixed typo. -** -** Revision 1.44 2002/11/27 12:07:18 meichel -** Adapted module dcmdata to use of new header file ofstdinc.h -** -** Revision 1.43 2002/11/26 08:43:02 meichel -** Replaced all includes for "zlib.h" with <zlib.h> -** to avoid inclusion of zlib.h in the makefile dependencies. -** -** Revision 1.42 2002/09/23 17:52:04 joergr -** Prepared code for future support of 'config.guess' host identifiers. -** -** Revision 1.41 2002/09/23 13:50:42 joergr -** Added new command line option "--version" which prints the name and version -** number of external libraries used. -** -** Revision 1.40 2002/08/21 10:14:16 meichel -** Adapted code to new loadFile and saveFile methods, thus removing direct -** use of the DICOM stream classes. -** -** Revision 1.39 2002/04/16 13:38:55 joergr -** Added configurable support for C++ ANSI standard includes (e.g. streams). -** -** Revision 1.38 2001/12/11 14:00:39 joergr -** Fixed bug in 'dump2dcm' parser causing AT attribute values to be ignored. -** -** Revision 1.37 2001/11/09 15:50:53 joergr -** Renamed some of the getValue/getParam methods to avoid ambiguities reported -** by certain compilers. -** -** Revision 1.36 2001/09/25 17:21:01 meichel -** Adapted dcmdata to class OFCondition -** -** Revision 1.35 2001/06/01 15:48:30 meichel -** Updated copyright header -** -** Revision 1.34 2000/04/14 15:42:54 meichel -** Global VR generation flags are now derived from OFGlobal and, thus, -** safe for use in multi-thread applications. -** -** Revision 1.33 2000/03/08 16:26:06 meichel -** Updated copyright header. -** -** Revision 1.32 2000/03/06 18:09:38 joergr -** Avoid empty statement in the body of if-statements (MSVC6 reports warnings). -** -** Revision 1.31 2000/03/03 14:05:16 meichel -** Implemented library support for redirecting error messages into memory -** instead of printing them to stdout/stderr for GUI applications. -** -** Revision 1.30 2000/02/29 11:48:51 meichel -** Removed support for VS value representation. This was proposed in CP 101 -** but never became part of the standard. -** -** Revision 1.29 2000/02/23 15:11:36 meichel -** Corrected macro for Borland C++ Builder 4 workaround. -** -** Revision 1.28 2000/02/10 16:02:51 joergr -** Enhanced handling of PixelData/Item element. Externally stored raw data is -** now always imported as little endian and swapped if necessary. This change -** reflects the new 'export' feature of dcmdump. -** -** Revision 1.27 2000/02/01 10:11:58 meichel -** Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4, -** workaround for bug in compiler header files. -** -** Revision 1.26 1999/05/03 14:13:40 joergr -** Minor code purifications to keep Sun CC 2.0.1 quiet. -** -** Revision 1.25 1999/04/27 17:50:53 joergr -** Adapted console applications to new OFCommandLine and OFConsoleApplication -** functionality. -** -** Revision 1.24 1999/04/27 12:23:27 meichel -** Prevented dcmdata applications from opening a file with empty filename, -** leads to application crash on Win32. -** -** Revision 1.23 1999/03/31 09:24:23 meichel -** Updated copyright header in module dcmdata -** -** Revision 1.22 1999/03/29 10:14:15 meichel -** Adapted command line options of dcmdata applications to new scheme. -** -** Revision 1.21 1999/03/22 16:16:01 meichel -** dump2dcm now allows to include the contents of binary files -** as OB/OW values while converting a dump to a DICOM file. -** -** Revision 1.20 1999/01/07 14:13:12 meichel -** Corrected bug in dump2dcm that prevented the correct processing of -** dumps created with dcmdump if they contained the "internal" VR markers -** "xs" (US or SS) or "ox" (OB or OW). -** -** Revision 1.19 1998/01/27 10:51:27 meichel -** Removed some unused variables, meaningless const modifiers -** and unreached statements. -** -** Revision 1.18 1998/01/14 14:41:15 hewett -** Modified existing -u command line option to also disable generation -** of UT and VS (previously just disabled generation of UN). -** -** Revision 1.17 1997/08/05 07:34:54 andreas -** Corrected Error handling of SQ in dump2dcm -** -** Revision 1.16 1997/07/21 07:59:02 andreas -** - Deleted support for DcmPixelItems and DcmPixelSequences in dump2dcm -** ToDo: New support should be added in the future compatible to -** the new DcmPixel class. -** - Replace all boolean types (BOOLEAN, CTNBOOLEAN, DICOM_BOOL, BOOL) -** with one unique boolean type OFBool. -** -** Revision 1.15 1997/07/03 15:09:40 andreas -** - removed debugging functions Bdebug() and Edebug() since -** they write a static array and are not very useful at all. -** Cdebug and Vdebug are merged since they have the same semantics. -** The debugging functions in dcmdata changed their interfaces -** (see dcmdata/include/dcdebug.h) -** -** Revision 1.14 1997/05/30 06:44:57 andreas -** - fixed scanf format problem leading to warnings on 64 bit machines. -** -** Revision 1.13 1997/05/29 15:52:52 meichel -** Added constant for dcmtk release date in dcuid.h. -** All dcmtk applications now contain a version string -** which is displayed with the command line options ("usage" message) -** and which can be queried in the binary with the "ident" command. -** -** Revision 1.12 1997/05/22 13:26:25 hewett -** Modified the test for presence of a data dictionary to use the -** method DcmDataDictionary::isDictionaryLoaded(). -** -** Revision 1.11 1997/05/20 07:57:12 andreas -** - Removed obsolete applications file2ds and ds2file. The functionality of these -** applications is now peformed by dcmconv. Unified calling parameters -** are implemented in dump2dcm, dcmdump and dcmconv. -** -** Revision 1.10 1997/05/16 08:31:06 andreas -** - Revised handling of GroupLength elements and support of -** DataSetTrailingPadding elements. The enumeratio E_GrpLenEncoding -** got additional enumeration values (for a description see dctypes.h). -** addGroupLength and removeGroupLength methods are replaced by -** computeGroupLengthAndPadding. To support Padding, the parameters of -** element and sequence write functions changed. -** -** Revision 1.9 1997/04/18 08:06:56 andreas -** - Minor corrections: correct some warnings of the SUN-C++ Compiler -** concerning the assignments of wrong types and inline compiler -** errors -** - The put/get-methods for all VRs did not conform to the C++-Standard -** draft. Some Compilers (e.g. SUN-C++ Compiler, Metroworks -** CodeWarrier, etc.) create many warnings concerning the hiding of -** overloaded get methods in all derived classes of DcmElement. -** So the interface of all value representation classes in the -** library are changed rapidly, e.g. -** OFCondition get(Uint16 & value, const unsigned long pos); -** becomes -** OFCondition getUint16(Uint16 & value, const unsigned long pos); -** All (retired) "returntype get(...)" methods are deleted. -** For more information see dcmdata/include/dcelem.h -** -** Revision 1.8 1997/03/27 15:47:25 hewett -** Added command line switche to allow generation of UN to be -** disabled (it is enabled by default). -** -** Revision 1.7 1996/09/24 16:13:51 hewett -** Added preliminary support for the Macintosh environment (GUSI library). -** -** Revision 1.6 1996/05/02 17:00:23 hewett -** Corrected program name in usage description. -** -** Revision 1.5 1996/05/02 15:55:11 hewett -** Stopped whitespace being stripped from inside value strings when -** no [] delimiter present. Now only leading and trailing whitespace -** is stripped. -** -** Revision 1.4 1996/04/27 12:13:01 hewett -** Corrected bug in last bug-fix. A tag value [some text] was being -** parsed as an empty string. Now both [] and [some text] appear to -** work as intended. -** -** Revision 1.3 1996/03/22 12:38:44 andreas -** Correct some mistakes: handling [] as empty string (no value field) -** handling =Name correct if Name is not correct -** -** Revision 1.2 1996/03/12 15:11:39 hewett -** Added call to prepareCmdLineArgs to enable command line arguments -** in environments which do not provide them. -** -** Revision 1.1 1996/01/29 13:36:38 andreas -** dump2dcm added convert ASCII descriptions into DICOM files -** -** -*/ Index: trunk/milena/sandbox/fabien/dicom/load.hh =================================================================== --- trunk/milena/sandbox/fabien/dicom/load.hh (revision 3380) +++ trunk/milena/sandbox/fabien/dicom/load.hh (revision 3381) @@ -1,3 +1,30 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + /* * * Copyright (C) 1994-2005, OFFIS @@ -30,45 +57,109 @@ * */ -#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ -#include "dcmtk/ofstd/ofstream.h" -#include "dcmtk/dcmdata/dctk.h" -#include "dcmtk/dcmdata/dcdebug.h" -#include "dcmtk/dcmdata/cmdlnarg.h" -#include "dcmtk/ofstd/ofconapp.h" -#include "dcmtk/dcmdata/dcuid.h" /* for dcmtk version name */ -#include "dcmtk/dcmdata/dcistrmz.h" /* for dcmZlibExpectRFC1950Encoding */ +#ifndef MLN_IO_DICOM_LOAD_HH +# define MLN_IO_DICOM_LOAD_HH + +/*! + * \file mln/io/dicom/load.hh + * + * \brief Define a function which loads an image of kind dicom with + * given path. + * + */ + +# include <mln/io/pnm/load.hh> + +# include <dcmtk/config/osconfig.h> /* make sure OS specific configuration is included first */ +# include <dcmtk/ofstd/ofstream.h> +# include <dcmtk/dcmdata/dctk.h> +# include <dcmtk/dcmdata/dcdebug.h> +# include <dcmtk/dcmdata/cmdlnarg.h> +# include <dcmtk/ofstd/ofconapp.h> +# include <dcmtk/dcmdata/dcuid.h> /* for dcmtk version name */ +# include <dcmtk/dcmdata/dcistrmz.h> /* for dcmZlibExpectRFC1950Encoding */ #define INCLUDE_CSTDLIB #define INCLUDE_CSTRING -#include "dcmtk/ofstd/ofstdinc.h" +# include <dcmtk/ofstd/ofstdinc.h> #ifdef WITH_ZLIB #include <zlib.h> /* for zlibVersion() */ #endif -#define OFFIS_CONSOLE_APPLICATION "dcmdump" +# define SHORTCOL 3 +# define LONGCOL 20 +# define PATH_SEPARATOR '/' + + + +namespace mln +{ + + namespace io + { + + namespace dicom + { + + /*! Load a dicom image in a Milena image. + * + * \param[out] ima A reference to the image which will receive + * data. + * \param[in] filename The source. + */ + template <typename I> + void load(Image<I>& ima, + const std::string& filename); + + /*! Load a dicom image in a Milena image. To use this routine, you + * should specialize the template whith the value type of the + * image loaded. (ex : load<value::int_u8>("...") ) + * + * \param[in] filename The image source. + * + * \return An image2d which contains loaded data. + */ + template <typename V> + image2d<V> load(const std::string& filename); + + /*! Load a dicom image in a Milena image. To use this routine, you + * should specialize the template whith the value type of the + * image loaded. (ex : load<value::int_u8>("...") ) + * + * \param[in] filename The image source. + * + * \return An image2d which contains loaded data. + */ + template <typename V> + image3d<V> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + + template <typename V> + inline + image2d<V> load(const std::string& filename) + { + trace::entering("mln::io::dicom::load"); + image2d<V> ima;// = io::pnm::load<V>(DICOM, filename); + trace::exiting("mln::io::dicom::load"); + return ima; + } + + template <typename V> + inline + image3d<V> load(const std::string& filename) + { + trace::entering("mln::io::dicom::load"); + image2d<V> ima;// = io::pnm::load<V>(DICOM, filename); + trace::exiting("mln::io::dicom::load"); + return ima; + } + -static char rcsid[] = "$dcmtk: " OFFIS_CONSOLE_APPLICATION " v" - OFFIS_DCMTK_VERSION " " OFFIS_DCMTK_RELEASEDATE " $"; -#ifdef HAVE_GUSI_H - /* needed for Macintosh */ -#include <GUSI.h> -#include <SIOUX.h> -#endif -static int dumpFile(ostream & out, - const char *ifname, - const E_FileReadMode readMode, - const E_TransferSyntax xfer, - const size_t printFlags, - const OFBool loadIntoMemory, - const OFBool stopOnErrors, - const OFBool writePixelData, - const char *pixelDirectory); -// ******************************************** static OFBool printAllInstances = OFTrue; static OFBool prependSequenceHierarchy = OFFalse; @@ -81,7 +172,7 @@ static OFBool addPrintTagName(const char* tagName) { if (printTagCount >= MAX_PRINT_TAG_NAMES) { - CERR << "error: too many print Tag options (max: " << MAX_PRINT_TAG_NAMES << ")" << endl; + std::cerr << "error: too many print Tag options (max: " << MAX_PRINT_TAG_NAMES << ")" << endl; return OFFalse; } @@ -92,16 +183,21 @@ /* it is a name */ const DcmDataDictionary& globalDataDict = dcmDataDict.rdlock(); const DcmDictEntry *dicent = globalDataDict.findEntry(tagName); - if( dicent == NULL ) { - CERR << "error: unrecognised tag name: '" << tagName << "'" << endl; + if (dicent == NULL) + { + std::cerr << "error: unrecognised tag name: '" << tagName << "'" << endl; dcmDataDict.unlock(); return OFFalse; - } else { + } + else + { /* note for later */ printTagKeys[printTagCount] = new DcmTagKey(dicent->getKey()); } dcmDataDict.unlock(); - } else { + } + else + { /* tag name has format xxxx,xxxx */ /* do not lookup in dictionary, tag could be private */ printTagKeys[printTagCount] = NULL; @@ -112,327 +208,13 @@ return OFTrue; } -#define SHORTCOL 3 -#define LONGCOL 20 - -int main(int argc, char *argv[]) -{ - int opt_debugMode = 0; - OFBool loadIntoMemory = OFTrue; - size_t printFlags = DCMTypes::PF_shortenLongTagValues /*| DCMTypes::PF_showTreeStructure*/; - OFBool printFilename = OFFalse; - OFBool writePixelData = OFFalse; - E_FileReadMode readMode = ERM_autoDetect; - E_TransferSyntax xfer = EXS_Unknown; - OFBool stopOnErrors = OFTrue; - const char *current = NULL; - const char *pixelDirectory = NULL; - - -#ifdef HAVE_GUSI_H - /* needed for Macintosh */ - /* set options for the Metrowerks CodeWarrior SIOUX console */ - SIOUXSettings.autocloseonquit = OFFalse; - SIOUXSettings.asktosaveonclose = OFFalse; - SIOUXSettings.showstatusline = OFTrue; - SIOUXSettings.setupmenus = OFTrue; - /* set options for the GUSI sockets library */ - GUSISetup(GUSIwithSIOUXSockets); - GUSISetup(GUSIwithInternetSockets); -#endif - - SetDebugLevel(( 0 )); - - OFConsoleApplication app(OFFIS_CONSOLE_APPLICATION, "Dump DICOM file and data set", rcsid); - OFCommandLine cmd; - cmd.setOptionColumns(LONGCOL, SHORTCOL); - cmd.setParamColumn(LONGCOL + SHORTCOL + 4); - - cmd.addParam("dcmfile-in", "DICOM input filename to be dumped", OFCmdParam::PM_MultiMandatory); - - cmd.addGroup("general options:", LONGCOL, SHORTCOL + 2); - cmd.addOption("--help", "-h", "print this help text and exit"); - cmd.addOption("--version", "print version information and exit", OFTrue /* exclusive */); -#ifdef USE_EXPERIMENTAL_QUIET_MODE - cmd.addOption("--quiet", "-q", "quiet mode, print no warnings and errors"); -#endif - cmd.addOption("--debug", "-d", "debug mode, print debug information"); - - cmd.addGroup("input options:"); - cmd.addSubGroup("input file format:"); - cmd.addOption("--read-file", "+f", "read file format or data set (default)"); - cmd.addOption("--read-file-only", "+fo", "read file format only"); - cmd.addOption("--read-dataset", "-f", "read data set without file meta information"); - cmd.addSubGroup("input transfer syntax:"); - cmd.addOption("--read-xfer-auto", "-t=", "use TS recognition (default)"); - cmd.addOption("--read-xfer-detect", "-td", "ignore TS specified in the file meta header"); - cmd.addOption("--read-xfer-little", "-te", "read with explicit VR little endian TS"); - cmd.addOption("--read-xfer-big", "-tb", "read with explicit VR big endian TS"); - cmd.addOption("--read-xfer-implicit", "-ti", "read with implicit VR little endian TS"); - cmd.addSubGroup("parsing of odd-length attributes:"); - cmd.addOption("--accept-odd-length", "+ao", "accept odd length attributes (default)"); - cmd.addOption("--assume-even-length", "+ae", "assume real length is one byte larger"); - cmd.addSubGroup("handling of undefined length UN elements:"); - cmd.addOption("--enable-cp246", "+ui", "read undefined len UN as implicit VR (default)"); - cmd.addOption("--disable-cp246", "-ui", "read undefined len UN as explicit VR"); - cmd.addSubGroup("handling of defined length UN elements:"); - cmd.addOption("--retain-un", "-uc", "retain elements as UN (default)"); - cmd.addOption("--convert-un", "+uc", "convert to real VR if known"); - cmd.addSubGroup("automatic data correction:"); - cmd.addOption("--enable-correction", "+dc", "enable automatic data correction (default)"); - cmd.addOption("--disable-correction", "-dc", "disable automatic data correction"); -#ifdef WITH_ZLIB - cmd.addSubGroup("bitstream format of deflated input:"); - cmd.addOption("--bitstream-deflated", "+bd", "expect deflated bitstream (default)"); - cmd.addOption("--bitstream-zlib", "+bz", "expect deflated zlib bitstream"); -#endif - - cmd.addGroup("output options:"); - cmd.addSubGroup("printing:"); - cmd.addOption("--load-all", "+M", "load very long tag values (default)"); - cmd.addOption("--load-short", "-M", "do not load very long values (e.g. pixel data)"); - cmd.addOption("--max-read-length", "+R", 1, "[k]bytes: integer [4..4194302] (default: 4)", - "set threshold for long values to k kbytes"); - cmd.addOption("--print-all", "+L", "print long tag values completely"); - cmd.addOption("--print-short", "-L", "print long tag values shortened (default)"); - cmd.addOption("--print-filename", "+F", "print header with filename for each input file"); - - cmd.addSubGroup("error handling:"); - cmd.addOption("--stop-on-error", "-E", "do not print if file is damaged (default)"); - cmd.addOption("--ignore-errors", "+E", "attempt to print even if file is damaged"); - - cmd.addSubGroup("searching:"); - cmd.addOption("--search", "+P", 1, "[t]ag: \"xxxx,xxxx\" or a data dictionary name", - "print the value of tag t\nthis option can be specified multiple times\n(default: the complete file is printed)"); - - cmd.addOption("--search-all", "+s", "print all instances of searched tags (default)"); - cmd.addOption("--search-first", "-s", "only print first instance of searched tags"); - - cmd.addOption("--prepend", "+p", "prepend sequence hierarchy to printed tag,\ndenoted by: (xxxx,xxxx).(xxxx,xxxx).*\n(only with --search-all or --search-first)"); - cmd.addOption("--no-prepend", "-p", "do not prepend hierarchy to tag (default)"); - - cmd.addSubGroup("writing:"); - cmd.addOption("--write-pixel", "+W", 1, "[d]irectory : string", - "write pixel data to a .raw file stored in d\n(little endian, filename created automatically)"); - - /* evaluate command line */ - prepareCmdLineArgs(argc, argv, OFFIS_CONSOLE_APPLICATION); - if (app.parseCommandLine(cmd, argc, argv, OFCommandLine::ExpandWildcards)) - { - /* check exclusive options first */ - - if (cmd.getParamCount() == 0) - { - if (cmd.findOption("--version")) - { - app.printHeader(OFTrue /*print host identifier*/); // uses ofConsole.lockCerr() - CERR << endl << "External libraries used:"; -#ifdef WITH_ZLIB - CERR << endl << "- ZLIB, Version " << zlibVersion() << endl; -#else - CERR << " none" << endl; -#endif - return 0; - } - } - - /* options */ - -#ifdef USE_EXPERIMENTAL_QUIET_MODE - if (cmd.findOption("--quiet")) - { - // tbd: disable ofConsole output! - app.setQuietMode(); - } -#endif - if (cmd.findOption("--debug")) opt_debugMode = 5; - - cmd.beginOptionBlock(); - if (cmd.findOption("--read-file")) readMode = ERM_autoDetect; - if (cmd.findOption("--read-file-only")) readMode = ERM_fileOnly; - if (cmd.findOption("--read-dataset")) readMode = ERM_dataset; - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--read-xfer-auto")) - xfer = EXS_Unknown; - if (cmd.findOption("--read-xfer-detect")) - dcmAutoDetectDatasetXfer.set(OFTrue); - if (cmd.findOption("--read-xfer-little")) - { - app.checkDependence("--read-xfer-little", "--read-dataset", readMode == ERM_dataset); - xfer = EXS_LittleEndianExplicit; - } - if (cmd.findOption("--read-xfer-big")) - { - app.checkDependence("--read-xfer-big", "--read-dataset", readMode == ERM_dataset); - xfer = EXS_BigEndianExplicit; - } - if (cmd.findOption("--read-xfer-implicit")) - { - app.checkDependence("--read-xfer-implicit", "--read-dataset", readMode == ERM_dataset); - xfer = EXS_LittleEndianImplicit; - } - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--accept-odd-length")) - { - dcmAcceptOddAttributeLength.set(OFTrue); - } - if (cmd.findOption("--assume-even-length")) - { - dcmAcceptOddAttributeLength.set(OFFalse); - } - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--enable-cp246")) - { - dcmEnableCP246Support.set(OFTrue); - } - if (cmd.findOption("--disable-cp246")) - { - dcmEnableCP246Support.set(OFFalse); - } - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--retain-un")) - { - dcmEnableUnknownVRConversion.set(OFFalse); - } - if (cmd.findOption("--convert-un")) - { - dcmEnableUnknownVRConversion.set(OFTrue); - } - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--enable-correction")) - { - dcmEnableAutomaticInputDataCorrection.set(OFTrue); - } - if (cmd.findOption("--disable-correction")) - { - dcmEnableAutomaticInputDataCorrection.set(OFFalse); - } - cmd.endOptionBlock(); - -#ifdef WITH_ZLIB - cmd.beginOptionBlock(); - if (cmd.findOption("--bitstream-deflated")) - { - dcmZlibExpectRFC1950Encoding.set(OFFalse); - } - if (cmd.findOption("--bitstream-zlib")) - { - dcmZlibExpectRFC1950Encoding.set(OFTrue); - } - cmd.endOptionBlock(); -#endif - - if (cmd.findOption("--max-read-length")) - { - app.checkValue(cmd.getValueAndCheckMinMax(maxReadLength, 4, 4194302)); - maxReadLength *= 1024; // convert kbytes to bytes - } - cmd.beginOptionBlock(); - if (cmd.findOption("--load-all")) loadIntoMemory = OFTrue; - if (cmd.findOption("--load-short")) loadIntoMemory = OFFalse; - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--print-all")) printFlags &= ~DCMTypes::PF_shortenLongTagValues; - if (cmd.findOption("--print-short")) printFlags |= DCMTypes::PF_shortenLongTagValues; - cmd.endOptionBlock(); - - if (cmd.findOption("--print-filename")) - printFilename = OFTrue; - - cmd.beginOptionBlock(); - if (cmd.findOption("--stop-on-error")) stopOnErrors = OFTrue; - if (cmd.findOption("--ignore-errors")) stopOnErrors = OFFalse; - cmd.endOptionBlock(); - - if (cmd.findOption("--search", 0, OFCommandLine::FOM_First)) - { - do - { - app.checkValue(cmd.getValue(current)); - if (!addPrintTagName(current)) return 1; - } while (cmd.findOption("--search", 0, OFCommandLine::FOM_Next)); - } - - cmd.beginOptionBlock(); - if (cmd.findOption("--search-all")) - { - app.checkDependence("--search-all", "--search", printTagCount>0); - printAllInstances = OFTrue; - } - if (cmd.findOption("--search-first")) - { - app.checkDependence("--search-first", "--search", printTagCount>0); - printAllInstances = OFFalse; - } - cmd.endOptionBlock(); - - cmd.beginOptionBlock(); - if (cmd.findOption("--prepend")) - { - app.checkDependence("--prepend", "--search", printTagCount>0); - prependSequenceHierarchy = OFTrue; - } - if (cmd.findOption("--no-prepend")) - { - app.checkDependence("--no-prepend", "--search", printTagCount>0); - prependSequenceHierarchy = OFFalse; - } - cmd.endOptionBlock(); - - if (cmd.findOption("--write-pixel")) - { - app.checkValue(cmd.getValue(pixelDirectory)); - writePixelData = OFTrue; - } - } - - SetDebugLevel((opt_debugMode)); - - /* make sure data dictionary is loaded */ - if (!dcmDataDict.isDictionaryLoaded()) - { - CERR << "Warning: no data dictionary loaded, " - << "check environment variable: " - << DCM_DICT_ENVIRONMENT_VARIABLE; - } - - int errorCount = 0; - int count = cmd.getParamCount(); - for (int i=1; i<=count; i++) - { - cmd.getParam(i, current); - if (printFilename) - { - /* a newline separates two consecutive "dumps" */ - if (i > 1) - COUT << endl; - /* print header with filename */ - COUT << "# " << OFFIS_CONSOLE_APPLICATION << " (" << i << "/" << count << "): " << current << endl; - } - errorCount += dumpFile(COUT, current, readMode, xfer, printFlags, loadIntoMemory, stopOnErrors, - writePixelData, pixelDirectory); - } - - return errorCount; -} -static void printResult(ostream& out, DcmStack& stack, size_t printFlags) + template <typename I> + static void printResult(Image<I>& ima, DcmStack& stack, size_t printFlags) { unsigned long n = stack.card(); - if (n == 0) { + if (n == 0) return; - } if (prependSequenceHierarchy) { /* print the path leading up to the top stack elem */ @@ -446,17 +228,18 @@ sprintf(buf, "(%x,%x).", OFstatic_cast(unsigned, dobj->getGTag()), OFstatic_cast(unsigned, dobj->getETag())); - out << buf; + std::cout << buf; } } } /* print the tag and its value */ DcmObject *dobj = stack.top(); - dobj->print(out, printFlags); + dobj->print(std::cout, printFlags); } -static int dumpFile(ostream & out, + template <typename I> + static int dumpFile(Image<I>& ima, const char *ifname, const E_FileReadMode readMode, const E_TransferSyntax xfer, @@ -468,16 +251,11 @@ { int result = 0; - if ((ifname == NULL) || (strlen(ifname) == 0)) - { - CERR << OFFIS_CONSOLE_APPLICATION << ": invalid filename: <empty string>" << endl; - return 1; - } - DcmFileFormat dfile; DcmObject *dset = &dfile; - if (readMode == ERM_dataset) dset = dfile.getDataset(); + if (readMode == ERM_dataset) + dset = dfile.getDataset(); // Load file @@ -487,14 +265,15 @@ if (! cond.good()) { - CERR << OFFIS_CONSOLE_APPLICATION << ": error: " << dfile.error().text() + std::cerr << "error: " << dfile.error().text() << ": reading file: "<< ifname << endl; - result = 1; - if (stopOnErrors) return result; + if (stopOnErrors) + return result; } - if (loadIntoMemory) dfile.loadAllDataIntoMemory(); + if (loadIntoMemory) + dfile.loadAllDataIntoMemory(); if (printTagCount == 0) { @@ -510,10 +289,13 @@ else rname += str.substr(pos + 1); size_t counter = 0; - dset->print(out, printFlags, 0 /*level*/, rname.c_str(), &counter); - } else - dset->print(out, printFlags); - } else { + dset->print(std::cout, printFlags, 0 /*level*/, rname.c_str(), &counter); + } + else + dset->print(std::cout, printFlags); + } + else + { /* only print specified tags */ for (int i=0; i<printTagCount; i++) { @@ -521,23 +303,29 @@ unsigned int elem = 0xffff; DcmTagKey searchKey; const char* tagName = printTagNames[i]; - if (printTagKeys[i]) searchKey = *printTagKeys[i]; - else if (sscanf( tagName, "%x,%x", &group, &elem ) == 2 ) searchKey.set(group, elem); - else { - CERR << "Internal ERROR in File " << __FILE__ << ", Line " - << __LINE__ << endl - << "-- Named tag inconsistency" << endl; + if (printTagKeys[i]) + searchKey = *printTagKeys[i]; + else + { + if (sscanf(tagName, "%x,%x", &group, &elem) == 2) + searchKey.set(group, elem); + else + { + std::cerr << "Internal ERROR in File " << __FILE__ << ", Line " + << __LINE__ << std::endl + << "-- Named tag inconsistency" << std::endl; abort(); } + } DcmStack stack; if (dset->search(searchKey, stack, ESM_fromHere, OFTrue) == EC_Normal) { - printResult(out, stack, printFlags); + printResult(ima, stack, printFlags); if (printAllInstances) { while (dset->search(searchKey, stack, ESM_afterStackTop, OFTrue) == EC_Normal) - printResult(out, stack, printFlags); + printResult(ima, stack, printFlags); } } } @@ -545,3 +333,56 @@ return result; } + + + template <typename I> + inline + void load(Image<I>& ima, + const std::string& filename) + { + trace::entering("mln::io::dicom::load"); + + std::ifstream file(filename.c_str()); + if (! file) + { + std::cerr << "error: cannot open file '" << filename << "'!"; + abort(); + } + + int opt_debugMode = 0; + OFBool loadIntoMemory = OFTrue; + size_t printFlags = DCMTypes::PF_shortenLongTagValues /*| DCMTypes::PF_showTreeStructure*/; + OFBool printFilename = OFFalse; + OFBool writePixelData = OFFalse; + E_FileReadMode readMode = ERM_autoDetect; + E_TransferSyntax xfer = EXS_Unknown; + OFBool stopOnErrors = OFTrue; + const char *current = NULL; + const char *pixelDirectory = NULL; + + + /* make sure data dictionary is loaded */ + if (!dcmDataDict.isDictionaryLoaded()) + { + std::cerr << "Warning: no data dictionary loaded, " + << "check environment variable: " + << DCM_DICT_ENVIRONMENT_VARIABLE; + } + + int errorCount = 0; + dumpFile(ima, current, readMode, xfer, printFlags, loadIntoMemory, stopOnErrors, + writePixelData, pixelDirectory); + + trace::exiting("mln::io::dicom::load"); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::io::dicom + + } // end of namespace mln::io + +} // end of namespace mln + + +#endif // ! MLN_IO_DICOM_LOAD_HH Index: trunk/milena/sandbox/fabien/magick/magick.cc =================================================================== --- trunk/milena/sandbox/fabien/magick/magick.cc (revision 0) +++ trunk/milena/sandbox/fabien/magick/magick.cc (revision 3381) @@ -0,0 +1,14 @@ +#include <mln/core/image/image2d.hh> +#include <mln/value/int_u8.hh> + +#include "load.hh" + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d<int_u8> lena; + + io::magick::load(lena, "/Users/HiSoKa/Work/LRDE/Olena/resources/CardiacCT/178562160.dcm"); +} Index: trunk/milena/sandbox/fabien/magick/Makefile =================================================================== --- trunk/milena/sandbox/fabien/magick/Makefile (revision 0) +++ trunk/milena/sandbox/fabien/magick/Makefile (revision 3381) @@ -0,0 +1,2 @@ +all: magick.cc + g++ -I../../../ `Magick++-config --cppflags --cxxflags --ldflags --libs` magick.cc -o mln_magick Index: trunk/milena/sandbox/fabien/magick/load.hh =================================================================== --- trunk/milena/sandbox/fabien/magick/load.hh (revision 0) +++ trunk/milena/sandbox/fabien/magick/load.hh (revision 3381) @@ -0,0 +1,142 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_IO_MAGICK_LOAD_HH +# define MLN_IO_MAGICK_LOAD_HH + +/*! + * \file mln/io/magick/load.hh + * + * \brief Define a function which loads an image of kind magick with + * given path. + * + */ + +# include <mln/core/image/image2d.hh> +# include <Magick++.h> + + +namespace mln +{ + + namespace io + { + + namespace magick + { + + /*! Load a magick image in a Milena image. + * + * \param[out] ima A reference to the image which will receive + * data. + * \param[in] filename The source. + */ + template <typename I> + void load(Image<I>& ima, + const std::string& filename); + + /*! Load a magick image in a Milena image. To use this routine, you + * should specialize the template whith the value type of the + * image loaded. (ex : load<value::int_u8>("...") ) + * + * \param[in] filename The image source. + * + * \return An image2d which contains loaded data. + */ + template <typename V> + image2d<V> load(const std::string& filename); + + /*! Load a magick image in a Milena image. To use this routine, you + * should specialize the template whith the value type of the + * image loaded. (ex : load<value::int_u8>("...") ) + * + * \param[in] filename The image source. + * + * \return An image2d which contains loaded data. + */ + template <typename V> + image3d<V> load(const std::string& filename); + +# ifndef MLN_INCLUDE_ONLY + + template <typename V> + inline + image2d<V> load(const std::string& filename) + { + trace::entering("mln::io::magick::load"); + image2d<V> ima;// = io::pnm::load<V>(MAGICK, filename); + trace::exiting("mln::io::magick::load"); + return ima; + } + + template <typename V> + inline + image3d<V> load(const std::string& filename) + { + trace::entering("mln::io::magick::load"); + image2d<V> ima;// = io::pnm::load<V>(MAGICK, filename); + trace::exiting("mln::io::magick::load"); + return ima; + } + + + template <typename I> + inline + void load(Image<I>& ima, + const std::string& filename) + { + trace::entering("mln::io::magick::load"); + + //std::ifstream file(filename.c_str()); + //if (! file) + //{ + // std::cerr << "error: cannot open file '" << filename << "'!"; + // abort(); + //} + + Magick::Image file(filename); + //std::cout << "file attribute: " << file.attribute() << std::endl; + std::cout << "width: " << file.columns() << std::endl; + std::cout << "height: " << file.rows() << std::endl; + std::cout << "x resolution: " << file.xResolution() << std::endl; + std::cout << "y resolution: " << file.yResolution() << std::endl; + std::cout << "comment: " << file.comment() << std::endl; + std::cout << "format: " << file.format() << std::endl; + + trace::exiting("mln::io::magick::load"); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::io::magick + + } // end of namespace mln::io + +} // end of namespace mln + + +#endif // ! MLN_IO_MAGICK_LOAD_HH
participants (1)
-
Fabien Freling