~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/streaming/streamingloader.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <api/icommand.h>
23
23
#include <api/dicom/idicommanager.h>
24
 
#include <api/controllers/icommandscontroller.h>
 
24
#include <main/controllers/commandcontroller.h>
25
25
#include <api/imodelointegracion.h>
26
26
#include <api/internationalization/internationalization.h>
27
27
#include <api/utils/iginkgomatrix4x4.h>
45
45
#include <vtkImageDataStreamer.h>
46
46
 
47
47
#include <itkImage.h>
48
 
#include <itkOrientedImage.h>
 
48
 
49
49
#include <itkCommand.h>
50
50
#include <itkMetaDataObject.h>
51
51
 
52
52
#include <itkImageFileReader.h>
53
53
#include <itkGDCMSeriesFileNames.h>
54
 
#include <itkVectorResampleImageFilter.h>
55
54
#include <itk/itkImageToVTKImageFilter.h>
56
55
#include <itkMetaDataDictionary.h>
 
56
#include <itkMetaDataObject.h>
57
57
#include <vtkAlgorithmOutput.h>
58
58
#include <vtkImageChangeInformation.h>
59
59
 
60
 
//#include <gdcmFilename.h>
61
 
//#include <gdcmSystem.h>
62
 
//#include <gdcmDirectory.h>
63
 
//#include <gdcmTrace.h>
64
 
//#include <gdcmVersion.h>
 
60
 
65
61
//#define DEBUG_PRINT_DIR_COSINES
66
62
 
67
63
class CargaItkProgressCallback : public itk::Command
158
154
        //gdcm::ImageHelper::SetForceRescaleInterceptSlope(true);
159
155
        //gdcm::ImageHelper::SetForcePixelSpacing(true);
160
156
 
161
 
        m_GantryTilt = 0.0;
162
157
        m_SignalFile = false;
163
158
        m_IO = ImageIO::New();
164
159
        m_IO->SetLoadPrivateTags(false);
202
197
        try {
203
198
                m_CurrentFile = fichero;
204
199
                m_IO->SetFileName(fichero);
 
200
                m_IO->SetUseStreamedReading(true);
 
201
 
205
202
 
206
203
                //correct a bug because this dictionary doesn't clear between consecutive loads
207
204
                itk::MetaDataDictionary newDict;
208
205
                m_IO->SetMetaDataDictionary(newDict);
209
206
                //
210
207
                m_IO->ReadImageInformation();
 
208
                
211
209
 
212
210
                //std::string tagkey;
213
211
                //std::string GantryTilt;
255
253
                                #endif
256
254
 
257
255
                        }
 
256
//                      char age[20];
258
257
                        for (int i=0; i < 3; i++) {
259
258
                                m_Spacing[i] = m_IO->GetSpacing(i);
260
259
                                m_Origin[i]  = m_IO->GetOrigin(i);
261
260
                        }
 
261
                        //check if image data is coherent...
 
262
                        itk::MetaDataDictionary& dict = m_IO->GetMetaDataDictionary();
 
263
                        if (dict.HasKey("0028|0107") && dict.HasKey( "0028|0103") && dict.HasKey("0028|0102")) {
 
264
                                //get highBit
 
265
                                if(itk::MetaDataObject <std::string> * highBit =dynamic_cast<itk::MetaDataObject <std::string> *>(dict["0028|0102"].GetPointer())) 
 
266
                                {
 
267
                                        //get largest value
 
268
                                        if(itk::MetaDataObject <std::string> * largestValue =dynamic_cast<itk::MetaDataObject <std::string> *>(dict["0028|0107"].GetPointer())) 
 
269
                                        {
 
270
                                                //get pixel representation
 
271
                                                if(itk::MetaDataObject <std::string> * pixelRepresentation =dynamic_cast<itk::MetaDataObject <std::string> *>(dict["0028|0103"].GetPointer())) 
 
272
                                                {
 
273
                                                        if (pixelRepresentation->GetMetaDataObjectValue() == "1") {//if its signed and largest value > (2^highbit)-1
 
274
                                                                if (atoi(largestValue->GetMetaDataObjectValue().c_str()) > (pow((double)2, atoi(highBit->GetMetaDataObjectValue().c_str())) -1)) {
 
275
                                                                        throw GNC::GCS::ControladorCargaException( _Std("Error reading the study: Largest image pixel value data is not coherent with combination of Pixel Representation and High bit") , "ControladorCarga/CargaMultidimensional");
 
276
                                                                }                                        
 
277
                                                        } else {
 
278
                                                                if (atoi(largestValue->GetMetaDataObjectValue().c_str()) > (pow((double)2, atoi(highBit->GetMetaDataObjectValue().c_str())+1) -1)) {
 
279
                                                                        throw GNC::GCS::ControladorCargaException( _Std("Error reading the study: Largest image pixel value data is not coherent with combination of Pixel Representation and High bit") , "ControladorCarga/CargaMultidimensional");
 
280
                                                                }
 
281
                                                        }
 
282
                                                }
 
283
                                        }
 
284
                                }
 
285
                        }//check if image data is coherent
262
286
                }
263
287
 
264
288
                if (m_CurrentNumberOfComponents != m_IO->GetNumberOfComponents() || m_CurrentComponentType != m_IO->GetComponentType() || m_CurrentPixelType != m_IO->GetPixelType() || m_CurrentDimensions[0] != m_IO->GetDimensions(0) || m_CurrentDimensions[1] != m_IO->GetDimensions(1) || m_CurrentDimensions[2] != m_IO->GetDimensions(2) )
273
297
                                                        case ImageIO::UCHAR:
274
298
                                                                {
275
299
                                                                        typedef unsigned char TypedPixelType;
276
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
300
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
277
301
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
278
302
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
279
303
                                                                        pTypedReader->SetFileName(fichero);
283
307
                                                        case ImageIO::CHAR:
284
308
                                                                {
285
309
                                                                        typedef char TypedPixelType;
286
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
310
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
287
311
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
288
312
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
289
313
                                                                        pTypedReader->SetFileName(fichero);
293
317
                                                        case ImageIO::USHORT:
294
318
                                                                {
295
319
                                                                        typedef unsigned short TypedPixelType;
296
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
320
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
297
321
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
298
322
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
299
323
                                                                        pTypedReader->SetFileName(fichero);
302
326
                                                                break;
303
327
                                                        case ImageIO::SHORT:
304
328
                                                                {
305
 
                                                                        typedef short TypedPixelType;
306
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
329
                                                                        typedef unsigned short TypedPixelType;
 
330
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
307
331
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
308
332
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
309
333
                                                                        pTypedReader->SetFileName(fichero);
313
337
                                                        case ImageIO::UINT:
314
338
                                                                {
315
339
                                                                        typedef unsigned int TypedPixelType;
316
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
340
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
317
341
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
318
342
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
319
343
                                                                        pTypedReader->SetFileName(fichero);
323
347
                                                        case ImageIO::INT:
324
348
                                                                {
325
349
                                                                        typedef int TypedPixelType;
326
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
350
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
327
351
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
328
352
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
329
353
                                                                        pTypedReader->SetFileName(fichero);
333
357
                                                        case ImageIO::ULONG:
334
358
                                                                {
335
359
                                                                        typedef unsigned long TypedPixelType;
336
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
360
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
337
361
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
338
362
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
339
363
                                                                        pTypedReader->SetFileName(fichero);
343
367
                                                        case ImageIO::LONG:
344
368
                                                                {
345
369
                                                                        typedef long TypedPixelType;
346
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
370
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
347
371
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
348
372
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
349
373
                                                                        pTypedReader->SetFileName(fichero);
353
377
                                                        case ImageIO::FLOAT:
354
378
                                                                {
355
379
                                                                        typedef float TypedPixelType;
356
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
380
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
357
381
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
358
382
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
359
383
                                                                        pTypedReader->SetFileName(fichero);
362
386
                                                        case ImageIO::DOUBLE:
363
387
                                                                {
364
388
                                                                        typedef double TypedPixelType;
365
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
389
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
366
390
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
367
391
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
368
392
                                                                        pTypedReader->SetFileName(fichero);
384
408
                                                                {
385
409
                                                                        typedef unsigned char TypedComponentType;
386
410
                                                                        typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
387
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
411
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
388
412
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
389
413
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
390
414
                                                                        pTypedReader->SetFileName(fichero);
395
419
                                                                {
396
420
                                                                        typedef char TypedComponentType;
397
421
                                                                        typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
398
 
                                                                        typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
422
                                                                        typedef itk::Image<TypedPixelType, 3 > TypedImageType;
399
423
                                                                        typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
400
424
                                                                        TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
401
425
                                                                        pTypedReader->SetFileName(fichero);
406
430
                                                        {
407
431
                                                                typedef unsigned short TypedComponentType;
408
432
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
409
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
433
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
410
434
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
411
435
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
412
436
                                                                pTypedReader->SetFileName(fichero);
417
441
                                                        {
418
442
                                                                typedef short TypedComponentType;
419
443
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
420
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
444
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
421
445
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
422
446
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
423
447
                                                                pTypedReader->SetFileName(fichero);
428
452
                                                        {
429
453
                                                                typedef unsigned int TypedComponentType;
430
454
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
431
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
455
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
432
456
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
433
457
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
434
458
                                                                pTypedReader->SetFileName(fichero);
439
463
                                                        {
440
464
                                                                typedef int TypedComponentType;
441
465
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
442
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
466
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
443
467
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
444
468
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
445
469
                                                                pTypedReader->SetFileName(fichero);
450
474
                                                        {
451
475
                                                                typedef long TypedComponentType;
452
476
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
453
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
477
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
454
478
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
455
479
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
456
480
                                                                pTypedReader->SetFileName(fichero);
461
485
                                                        {
462
486
                                                                typedef unsigned long TypedComponentType;
463
487
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
464
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
488
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
465
489
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
466
490
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
467
491
                                                                pTypedReader->SetFileName(fichero);
472
496
                                                        {
473
497
                                                                typedef float TypedComponentType;
474
498
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
475
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
499
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
476
500
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
477
501
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
478
502
                                                                pTypedReader->SetFileName(fichero);
483
507
                                                        {
484
508
                                                                typedef double TypedComponentType;
485
509
                                                                typedef itk::RGBPixel<TypedComponentType> TypedPixelType;
486
 
                                                                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
510
                                                                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
487
511
                                                                typedef itk::ImageFileReader<TypedImageType> TypedReaderType;
488
512
                                                                TypedReaderType* pTypedReader = static_cast<TypedReaderType*>(m_pReader.GetPointer());
489
513
                                                                pTypedReader->SetFileName(fichero);
633
657
 
634
658
void GNC::StreamingLoader::SetOutputSpacing(double spacing[3])
635
659
{
 
660
        if (spacing[0] <= 0 || spacing[1] <= 0) {
 
661
                spacing[0] = spacing[1] = 1.0;
 
662
        }
636
663
        m_pOutput->SetOutputSpacing(spacing);
637
664
}
638
665
 
651
678
        m_pOutput->GetOutputSpacing(spacing);
652
679
}
653
680
 
654
 
int GNC::StreamingLoader::GetCurrentSliceIndex()
 
681
int GNC::StreamingLoader::GetCurrentSliceIndex()  const
655
682
{
656
683
        return 0;
657
684
}
658
685
 
 
686
std::string GNC::StreamingLoader::GetPatientPosition()
 
687
{
 
688
        std::string patientPositionTag;
 
689
        bool ok = m_IO->GetValueFromTag("0018|5100", patientPositionTag);
 
690
        if (ok) {
 
691
                return patientPositionTag;
 
692
        }
 
693
        return "";      
 
694
}
 
695
 
659
696
void GNC::StreamingLoader::RecomponerPipeline()
660
697
{
661
698
        if (m_SignalFile) {
670
707
                m_pOutput->RemoveAllInputs();
671
708
 
672
709
                typedef unsigned short TypedPixelType;
673
 
                typedef itk::OrientedImage<TypedPixelType, 3 > TypedImageType;
 
710
                typedef itk::Image<TypedPixelType, 3 > TypedImageType;
674
711
                typedef itk::ImageToVTKImageFilter<TypedImageType> TypedJoinerType;
675
712
                
676
713
                TypedImageType::Pointer img = TypedImageType::New();
808
845
                                                                reader->SetImageIO(pIO);
809
846
                                                                reader->SetFileName(m_CurrentFile);
810
847
                                                                reader->SetUseStreaming(true);
 
848
                                                                
811
849
                                                                m_pOutput->SetInputConnection(joiner->GetImporter()->GetOutputPort());
812
850
                                                                //reader->GetOutput()->ReleaseDataFlagOn();
813
851
 
1160
1198
        }
1161
1199
        if (m_pReader.IsNotNull() && m_pPipelineJoiner.IsNotNull()) {
1162
1200
                m_pReader->Modified();
 
1201
                
1163
1202
                m_pPipelineJoiner->Modified();
1164
1203
        }
1165
1204
        m_pOutput->Modified();