File: TestImageHelper2.cxx

package info (click to toggle)
gdcm 3.0.24-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 27,560 kB
  • sloc: cpp: 203,722; ansic: 76,471; xml: 48,131; python: 3,473; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 97
file content (122 lines) | stat: -rw-r--r-- 3,907 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "gdcmTesting.h"
#include "gdcmImageHelper.h"
#include "gdcmImageReader.h"
#include "gdcmImageWriter.h"
#include "gdcmMediaStorage.h"
#include "gdcmDataSet.h"
#include "gdcmAttribute.h"
#include "gdcmDirectionCosines.h"

/*
 * Let's check this is easy with GDCM to handle the new
 * Real World Value Mapping Sequence mechanism
 */
int TestImageHelper2(int, char *[])
{
  static const char *filenames[] = {
    "D_CLUNIE_MR2_JPLL.dcm",
    "D_CLUNIE_MR2_JPLY.dcm",
    "D_CLUNIE_MR2_RLE.dcm",
    "D_CLUNIE_MR4_JPLL.dcm",
    "D_CLUNIE_MR4_JPLY.dcm",
    "D_CLUNIE_MR4_RLE.dcm",
    "MR-MONO2-12-shoulder.dcm",
    "MR_Philips-Intera_BreaksNOSHADOW.dcm",
    "MR_Philips_Intera_No_PrivateSequenceImplicitVR.dcm",
    "MR_Philips_Intera_PrivateSequenceExplicitVR_in_SQ_2001_e05f_item_wrong_lgt_use_NOSHADOWSEQ.dcm",
    "MR_Philips_Intera_SwitchIndianess_noLgtSQItem_in_trueLgtSeq.dcm",
    "PHILIPS_GDCM12xBug.dcm",
    "PHILIPS_GDCM12xBug2.dcm",
    "PHILIPS_Gyroscan-12-Jpeg_Extended_Process_2_4.dcm",
    "PHILIPS_Gyroscan-12-MONO2-Jpeg_Lossless.dcm",
    "PHILIPS_Gyroscan-8-MONO2-Odd_Sequence.dcm",
    "PHILIPS_Intera-16-MONO2-Uncompress.dcm",
    "PhilipsInteraSeqTermInvLen.dcm",
    "SIEMENS_MOSAIC_12BitsStored-16BitsJPEG.dcm",
    "THERALYS-12-MONO2-Uncompressed-Even_Length_Tag.dcm",
    "gdcm-MR-PHILIPS-16-Multi-Seq.dcm",
    "gdcm-MR-PHILIPS-16-NonSquarePixels.dcm",
    "PHILIPS_Gyroscan-12-Jpeg_Extended_Process_2_4.dcm", // need PVRG option
  };

  const unsigned int nfiles = sizeof(filenames)/sizeof(*filenames);
  const char *root = gdcm::Testing::GetDataRoot();
  if( !root || !*root )
    {
    std::cerr << "root is not defined" << std::endl;
    return 1;
    }
  std::string sroot = root;
  sroot += "/";

  gdcm::Trace::WarningOff();
  for(unsigned int i = 0; i < nfiles; ++i)
  {
    const char * filename = filenames[i];
    std::string fullpath = sroot + filename;

    gdcm::ImageHelper::SetForceRescaleInterceptSlope(true);
    gdcm::ImageReader r;
    r.SetFileName( fullpath.c_str() );
    if( !r.Read() )
    {
      return 1;
    }
    gdcm::ImageHelper::SetForceRescaleInterceptSlope(false);
    gdcm::Image & img = r.GetImage();
    //std::cout << img.GetIntercept() << std::endl;
    //std::cout << img.GetSlope() << std::endl;
    // Create directory first:
    const char subdir[] = "TestImageHelper2";
    std::string tmpdir = gdcm::Testing::GetTempDirectory( subdir );
    if( !gdcm::System::FileIsDirectory( tmpdir.c_str() ) )
    {
      gdcm::System::MakeDirectory( tmpdir.c_str() );
      //return 1;
    }
    std::string outfilename = gdcm::Testing::GetTempFilename( filename, subdir );

    gdcm::ImageWriter writer;
    writer.SetFileName( outfilename.c_str() );
    writer.SetFile( r.GetFile() );
    writer.SetImage( r.GetImage() );
    if( !writer.Write() )
    {
      std::cerr << "Failed to write: " << outfilename << std::endl;
      return 1;
    }

    gdcm::ImageReader r2;
    r2.SetFileName( outfilename.c_str() );
    if( !r2.Read() )
    {
      return 1;
    }
    gdcm::Image & img2 = r2.GetImage();
    if( img.GetIntercept() != img2.GetIntercept() )
    {
      std::cerr << img2.GetIntercept() << std::endl;
      return 1;
    }
    if( img.GetSlope() != img2.GetSlope() )
    {
    std::cout << img2.GetSlope() << std::endl;
    return 1;
    }
  }

  return 0;
}