37 #include <vtkImageData.h>
38 #include <vtkMetaImageReader.h>
39 #include <vtkSmartPointer.h>
40 #include <vtkMetaImageWriter.h>
42 #include <vtkPolyData.h>
43 #include <vtkPolyDataReader.h>
44 #include <vtkPolyDataWriter.h>
45 #include <vtkSTLReader.h>
46 #include <vtkImageChangeInformation.h>
47 #include "vtkMINCImageReader.h"
48 #include "vtkTransform.h"
49 #include "vtkCommand.h"
50 #include <vtkPNGReader.h>
53 #include <QDomDocument>
56 #include <QTextStream>
98 boost::shared_ptr<QMutex> StaticMutexVtkLocker::mMutex;
120 virtual void Execute(vtkObject* caller,
unsigned long,
void* text)
122 mMessage = QString(reinterpret_cast<char*> (text));
126 static bool checkedRead(vtkSmartPointer<vtkAlgorithm> reader, QString filename)
128 vtkSmartPointer<ErrorObserver> errorObserver = vtkSmartPointer<ErrorObserver>::New();
129 reader->AddObserver(
"ErrorEvent", errorObserver);
137 if (!errorObserver->mMessage.isEmpty())
139 reportError(
"Load of data [" + filename +
"] failed with message:\n"
140 + errorObserver->mMessage);
153 reader->ReleaseDataFlagOn();
159 zeroer->SetInputConnection(reader->GetOutputPort());
160 zeroer->SetOutputOrigin(0, 0, 0);
162 return zeroer->GetOutput();
167 return this->
readInto(boost::dynamic_pointer_cast<Image>(data), filename);
181 image->setVtkImageData(raw);
186 image->get_rMd_History()->setRegistration(rMd);
187 image->setModality(customReader->readModality());
188 image->setImageType(customReader->readImageType());
192 double level = customReader->readKey(
"WindowLevel").toDouble(&ok1);
193 double window = customReader->readKey(
"WindowWidth").toDouble(&ok2);
197 image->setInitialWindowLevel(window, level);
198 image->resetTransferFunctions();
215 writer->SetInputData(image->getBaseVtkImageData());
216 writer->SetFileDimensionality(3);
218 QDir().mkpath(QFileInfo(filename).path());
222 writer->SetCompression(
false);
229 customReader->setTransform(image->get_rMd());
230 customReader->setModality(image->getModality());
231 customReader->setImageType(image->getImageType());
232 customReader->setKey(
"WindowLevel",
qstring_cast(image->getInitialWindowLevel()));
233 customReader->setKey(
"WindowWidth",
qstring_cast(image->getInitialWindowWidth()));
234 customReader->setKey(
"Creator", QString(
"CustusX_%1").arg(CustusX_VERSION_STRING));
244 return this->
readInto(boost::dynamic_pointer_cast<Image>(data), filename);
254 image->setVtkImageData(raw);
268 pngReader->SetFileName(filename.toStdString().c_str());
270 return pngReader->GetOutput();
279 return this->
readInto(boost::dynamic_pointer_cast<Mesh>(data), filename);
289 mesh->setVtkPolyData(raw);
314 return this->
readInto(boost::dynamic_pointer_cast<Mesh>(data), filename);
324 mesh->setVtkPolyData(raw);
356 DataReaderPtr DataReaderWriter::findReader(
const QString& path,
const QString& type)
358 for (DataReadersType::iterator iter = mDataReaders.begin(); iter != mDataReaders.end(); ++iter)
360 if ((*iter)->canLoad(type, path))
370 return reader->loadVtkImageData(filename);
378 return reader->loadVtkPolyData(filename);
386 return reader->canLoadDataType();
392 DataReaderPtr reader = this->findReader(path, data->getType());
394 reader->readInto(data, path);
400 data->setFilename(path);
QString qstring_cast(const T &val)
void reportError(QString msg)
virtual vtkPolyDataPtr loadVtkPolyData(QString filename)
QString findDataTypeFromFile(QString filename)
virtual bool readInto(DataPtr data, QString path)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
static ErrorObserver * New()
virtual vtkPolyDataPtr loadVtkPolyData(QString filename)
boost::shared_ptr< class Image > ImagePtr
vtkSmartPointer< vtkImageChangeInformation > vtkImageChangeInformationPtr
cstring_cast_Placeholder cstring_cast(const T &val)
virtual DataPtr load(const QString &uid, const QString &filename)
boost::shared_ptr< DataReader > DataReaderPtr
vtkPolyDataPtr loadVtkPolyData(QString filename)
boost::shared_ptr< class Data > DataPtr
virtual void Execute(vtkObject *caller, unsigned long, void *text)
vtkSmartPointer< class vtkMetaImageReader > vtkMetaImageReaderPtr
boost::shared_ptr< class CustomMetaImage > CustomMetaImagePtr
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
virtual bool readInto(DataPtr data, QString path)
vtkSmartPointer< class vtkSTLReader > vtkSTLReaderPtr
vtkSmartPointer< class vtkPNGReader > vtkPNGReaderPtr
vtkSmartPointer< class vtkMetaImageWriter > vtkMetaImageWriterPtr
virtual DataPtr load(const QString &uid, const QString &filename)
QString changeExtension(QString name, QString ext)
void readInto(DataPtr data, QString path)
virtual vtkImageDataPtr loadVtkImageData(QString filename)
static bool checkedRead(vtkSmartPointer< vtkAlgorithm > reader, QString filename)
Reader for portable network graphics .png files.
vtkSmartPointer< class vtkPolyDataReader > vtkPolyDataReaderPtr
virtual bool readInto(DataPtr data, QString path)
boost::shared_ptr< class Mesh > MeshPtr
vtkImageDataPtr loadVtkImageData(QString filename)
virtual DataPtr load(const QString &uid, const QString &filename)