CustusX  20.03-rc1
An IGT application
cxPNGImageReader.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxPNGImageReader.h"
13 
14 #include <QFileInfo>
15 #include <vtkPNGReader.h>
16 #include <vtkImageData.h>
17 #include <ctkPluginContext.h>
18 #include "cxImage.h"
19 #include "cxPatientModelService.h"
20 
21 typedef vtkSmartPointer<class vtkPNGReader> vtkPNGReaderPtr;
22 namespace cx
23 {
24 
26  FileReaderWriterImplService("PNGImageReader" ,Image::getTypeName(), "", "png", patientModelService)
27 {
28 
29 }
30 
31 bool PNGImageReader::canRead(const QString &type, const QString &filename)
32 {
33  QString fileType = QFileInfo(filename).suffix();
34  return (fileType.compare("png", Qt::CaseInsensitive) == 0);
35 }
36 
37 bool PNGImageReader::readInto(DataPtr data, QString filename)
38 {
39  return this->readInto(boost::dynamic_pointer_cast<Image>(data), filename);
40 }
41 
42 bool PNGImageReader::readInto(ImagePtr image, QString filename)
43 {
44  if (!image)
45  return false;
46  vtkImageDataPtr raw = this->loadVtkImageData(filename);
47  if(!raw)
48  return false;
49  image->setVtkImageData(raw);
50  return true;
51 }
52 
54 {
55  return Image::getTypeName();
56 }
57 
58 DataPtr PNGImageReader::read(const QString& uid, const QString& filename)
59 {
60  ImagePtr image(new Image(uid, vtkImageDataPtr()));
61  this->readInto(image, filename);
62  return image;
63 }
64 
65 std::vector<DataPtr> PNGImageReader::read(const QString &filename)
66 {
67  std::vector<DataPtr> retval;
68  ImagePtr image = boost::dynamic_pointer_cast<Image>(this->createData(Image::getTypeName() , filename));
69 
70  vtkImageDataPtr raw = this->loadVtkImageData(filename);
71  if(!raw)
72  return retval;
73  image->setVtkImageData(raw);
74 
75  retval.push_back(image);
76  return retval;
77 
78 }
79 
81 {
82  vtkPNGReaderPtr pngReader = vtkPNGReaderPtr::New();
83  pngReader->SetFileName(filename.toStdString().c_str());
84  pngReader->Update();
85  return pngReader->GetOutput();
86 }
87 
88 }
89 
90 
92 {
93  return "";
94 }
95 
96 bool cx::PNGImageReader::canWrite(const QString &type, const QString &filename) const
97 {
98  return false;
99 }
bool canWrite(const QString &type, const QString &filename) const
virtual QString canReadDataType() const
DataPtr createData(QString type, QString filename, QString name="") const
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
PNGImageReader(PatientModelServicePtr patientModelService)
virtual DataPtr read(const QString &uid, const QString &filename)
boost::shared_ptr< class Data > DataPtr
vtkSmartPointer< class vtkPNGReader > vtkPNGReaderPtr
A volumetric data set.
Definition: cxImage.h:45
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static QString getTypeName()
Definition: cxImage.h:126
virtual bool canRead(const QString &type, const QString &filename)
virtual vtkImageDataPtr loadVtkImageData(QString filename)
virtual bool readInto(DataPtr data, QString path)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
QString canWriteDataType() const
Namespace for all CustusX production code.