-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileLoader.cpp
More file actions
77 lines (62 loc) · 2.01 KB
/
Copy pathFileLoader.cpp
File metadata and controls
77 lines (62 loc) · 2.01 KB
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
#include "FileLoader.h"
#include <QFileInfo>
#include <vtkSmartPointer.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkPLYReader.h>
#include <vtkOBJReader.h>
//------------------------------------------------------------------------------
FileLoader::FileLoader()
{
}
//------------------------------------------------------------------------------
const QString FileLoader::supportedFormats()
{
QStringList formats;
formats << "All formats (*.ply *.obj *.vtp)"
<< "PLY format (*.ply)"
<< "OBJ format (*.obj)"
<< "VTK Polydata XML format (*.vtp)";
return formats.join(";;");
}
//------------------------------------------------------------------------------
bool FileLoader::load(const QString& filename)
{
const QFileInfo fileInfo(filename);
const QString& suffix= fileInfo.completeSuffix();
if( suffix.compare("vtp", Qt::CaseInsensitive) == 0)
{
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(qPrintable(fileInfo.absoluteFilePath()));
m_reader = reader;
return true;
}
else if( suffix.compare("ply", Qt::CaseInsensitive) == 0)
{
auto reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(qPrintable(fileInfo.absoluteFilePath()));
m_reader = reader;
return true;
}
else if( suffix.compare("obj", Qt::CaseInsensitive) == 0)
{
auto reader = vtkSmartPointer<vtkOBJReader>::New();
reader->SetFileName(qPrintable(fileInfo.absoluteFilePath()));
m_reader = reader;
return true;
}
return false;
}
//------------------------------------------------------------------------------
// TODO: this should work in a separated thread and support a progress bar.
vtkSmartPointer<vtkDataSet> FileLoader::getOutput()
{
if( !m_reader )
{
return nullptr;
}
m_reader->Update();
auto data = vtkDataSet::SafeDownCast(m_reader->GetOutputDataObject(0));
// describe what we have loaded
data->PrintSelf(std::cout, vtkIndent(0));
return data;
}