CustusX  22.04-rc5
An IGT application
cxXMLPolyDataMeshReader.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 
13 
14 #include "cxMesh.h"
15 #include <ctkPluginContext.h>
16 #include "cxErrorObserver.h"
17 #include <vtkXMLPolyDataReader.h>
18 #include "cxTypeConversions.h"
19 #include <vtkPolyData.h>
20 
21 namespace cx {
22 
23 bool XMLPolyDataMeshReader::readInto(DataPtr data, QString filename)
24 {
25  return this->readInto(boost::dynamic_pointer_cast<Mesh>(data), filename);
26 }
27 
28 bool XMLPolyDataMeshReader::readInto(MeshPtr mesh, QString filename)
29 {
30  if (!mesh)
31  return false;
32  vtkPolyDataPtr raw = this->loadVtkPolyData(filename);
33  if(!raw)
34  return false;
35  mesh->setVtkPolyData(raw);
36  return true;
37 }
38 
39 std::vector<DataPtr> XMLPolyDataMeshReader::read(const QString &filename)
40 {
41  std::vector<DataPtr> retval;
42  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(this->createData(Mesh::getTypeName(), filename));
43 
44  vtkPolyDataPtr raw = this->loadVtkPolyData(filename);
45  if(!raw)
46  return retval;
47  mesh->setVtkPolyData(raw);
48 
49  retval.push_back(mesh);
50  return retval;
51 }
52 
54 {
55  vtkXMLPolyDataReaderPtr reader = vtkXMLPolyDataReaderPtr::New();
56  reader->SetFileName(cstring_cast(fileName));
57 
58  if (!ErrorObserver::checkedRead(reader, fileName))
59  return vtkPolyDataPtr();
60 
61  vtkPolyDataPtr polyData = reader->GetOutput();
62  return polyData;
63 }
64 
65 DataPtr XMLPolyDataMeshReader::read(const QString& uid, const QString& filename)
66 {
67  MeshPtr mesh(new Mesh(uid));
68  this->readInto(mesh, filename);
69  return mesh;
70 }
71 
73 {
74  return Mesh::getTypeName();
75 }
76 
78  FileReaderWriterImplService("XMLPolyDataMeshReader", Mesh::getTypeName(), "", "vtp", patientModelService)
79 {
80 }
81 
82 bool XMLPolyDataMeshReader::canRead(const QString &type, const QString &filename)
83 {
84  QString fileType = QFileInfo(filename).suffix();
85  return ( fileType.compare("vtp", Qt::CaseInsensitive) == 0);
86 }
87 
88 }
89 
91 {
92  return "";
93 }
94 
95 bool cx::XMLPolyDataMeshReader::canWrite(const QString &type, const QString &filename) const
96 {
97  return false;
98 }
bool canWrite(const QString &type, const QString &filename) const
A mesh data set.
Definition: cxMesh.h:45
DataPtr createData(QString type, QString filename, QString name="") const
virtual bool readInto(DataPtr data, QString path)
vtkSmartPointer< class vtkXMLPolyDataReader > vtkXMLPolyDataReaderPtr
cstring_cast_Placeholder cstring_cast(const T &val)
boost::shared_ptr< class Data > DataPtr
virtual QString canReadDataType() const
virtual DataPtr read(const QString &uid, const QString &filename)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual bool canRead(const QString &type, const QString &filename)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
static bool checkedRead(vtkSmartPointer< vtkAlgorithm > reader, QString filename)
static QString getTypeName()
Definition: cxMesh.h:67
boost::shared_ptr< class Mesh > MeshPtr
XMLPolyDataMeshReader(PatientModelServicePtr patientModelService)
virtual vtkPolyDataPtr loadVtkPolyData(QString filename)
Namespace for all CustusX production code.