$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dicom/get_header.hh
1 // Copyright (C) 2010, 2012 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_IO_DICOM_GET_HEADER_HH
28 # define MLN_IO_DICOM_GET_HEADER_HH
29 
33 
34 # include <iostream>
35 # include <fstream>
36 
37 # include <gdcm-2.0/gdcmReader.h>
38 # include <gdcm-2.0/gdcmImageReader.h>
39 # include <gdcm-2.0/gdcmWriter.h>
40 # include <gdcm-2.0/gdcmDataSet.h>
41 # include <gdcm-2.0/gdcmAttribute.h>
42 
43 # include <mln/core/concept/image.hh>
44 # include <mln/core/routine/initialize.hh>
45 # include <mln/core/box_runstart_piter.hh>
46 # include <mln/core/pixel.hh>
47 # include <mln/data/memcpy_.hh>
48 # include <mln/util/array.hh>
49 
50 namespace mln
51 {
52 
53  namespace io
54  {
55 
56  namespace dicom
57  {
58 
63  struct dicom_header
64  {
65  // The number of dimensions.
66  unsigned dim;
67 
68  // The size in each dimension.
70  };
71 
72 
77  dicom_header get_header(const std::string& filename);
78 
79 
80 # ifndef MLN_INCLUDE_ONLY
81 
82 
83  dicom_header get_header(const std::string& filename)
84  {
85  mln_trace("mln::io::dicom::get_header");
86 
87  dicom_header header;
88 
89  gdcm::ImageReader r;
90  r.SetFileName(filename.c_str());
91  if (!r.Read())
92  {
93  std::cerr << "error: cannot open file '" << filename << "'!";
94  abort();
95  }
96 
97  gdcm::Image& image = r.GetImage();
98 
99  header.dim = image.GetNumberOfDimensions();
100  const unsigned int* dims = image.GetDimensions();
101 
102  for (unsigned i = 2; i < header.dim; ++i)
103  header.size.append(dims[i]); // sli, ...
104  for (unsigned i = 0; i < 2; ++i)
105  header.size.append(dims[i]); // row, col
106 
107  return header;
108  }
109 
110 
111 # endif // ! MLN_INCLUDE_ONLY
112 
113  } // end of namespace mln::io::dicom
114 
115  } // end of namespace mln::io
116 
117 } // end of namespace mln
118 
119 #endif // ! MLN_IO_DICOM_GET_HEADER_HH
120