MCPcopy Create free account
hub / github.com/PDAL/PDAL / initialize

Method initialize

io/PtsReader.cpp:55–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53std::string PtsReader::getName() const { return s_info.name; }
54
55void PtsReader::initialize(PointTableRef table)
56{
57 m_istream = Utils::openFile(m_filename);
58 if (!m_istream)
59 throwError("Unable to open file '" + m_filename + "'.");
60
61 std::string buf;
62 std::getline(*m_istream, buf);
63
64 // Very first line is point count
65 Utils::trim(buf);
66 auto res = Utils::fromString(buf, m_PointCount);
67 if (!res)
68 throwError("Unable to read expected point count at top of the file '" +
69 m_filename + "': " + res.what());
70 // Peek second line to determine dimensions to add.
71 // Expect points in the formats:
72 // X Y Z,
73 // X Y Z Intensity,
74 // X Y Z Intensity R G B
75 std::getline(*m_istream, buf);
76 StringList fields = Utils::split2(buf, m_separator);
77 switch(fields.size())
78 {
79 case 3:
80 m_dims.push_back(Dimension::Id::X);
81 m_dims.push_back(Dimension::Id::Y);
82 m_dims.push_back(Dimension::Id::Z);
83 break;
84 case 4:
85 m_dims.push_back(Dimension::Id::X);
86 m_dims.push_back(Dimension::Id::Y);
87 m_dims.push_back(Dimension::Id::Z);
88 m_dims.push_back(Dimension::Id::Intensity);
89 break;
90 case 7:
91 m_dims.push_back(Dimension::Id::X);
92 m_dims.push_back(Dimension::Id::Y);
93 m_dims.push_back(Dimension::Id::Z);
94 m_dims.push_back(Dimension::Id::Intensity);
95 m_dims.push_back(Dimension::Id::Red);
96 m_dims.push_back(Dimension::Id::Green);
97 m_dims.push_back(Dimension::Id::Blue);
98 break;
99 default:
100 throwError("Invalid number of fields for the first point in file '" + m_filename + "'.");
101 }
102
103 Utils::closeFile(m_istream);
104}
105
106
107void PtsReader::addDimensions(PointLayoutPtr layout)

Callers

nothing calls this directly

Calls 6

trimFunction · 0.85
fromStringFunction · 0.70
openFileFunction · 0.50
closeFileFunction · 0.50
whatMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected