MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadVrtFile

Method ReadVrtFile

IO/Geometry/vtkProStarReader.cxx:137–204  ·  view source on GitHub ↗

read in the points from the .vrt file ---------------------------------------------------------------------------*\ Line 1: PROSTAR_VERTEX [newline] Line 2: 0 0 0 0 0 0 0 [newline] Body: [newline] \*---------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

135
136\*---------------------------------------------------------------------------*/
137bool vtkProStarReader::ReadVrtFile(vtkUnstructuredGrid* output, idMapping& mapPointId)
138{
139 mapPointId.clear();
140 FILE* in = this->OpenFile(".vrt");
141 if (in == nullptr)
142 {
143 return false;
144 }
145
146 constexpr int MAX_LINE = 1024;
147 char rawLine[MAX_LINE];
148
149 int errorCount = 0;
150 vtk::scan_result_type<std::string_view, int> resultLabel;
151 if (fgets(rawLine, MAX_LINE, in) != nullptr && strncmp(rawLine, "PROSTAR_VERTEX", 14) == 0 &&
152 fgets(rawLine, MAX_LINE, in) != nullptr &&
153 ((resultLabel = vtk::scan_int<int>(std::string_view(rawLine)))) && resultLabel->value() >= 4000)
154 {
155 vtkDebugMacro(<< "Got PROSTAR_VERTEX header");
156 }
157 else
158 {
159 vtkErrorMacro(<< "Error reading header for PROSTAR_VERTEX file");
160 ++errorCount;
161 }
162 int lineLabel = resultLabel->value();
163
164 vtkPoints* points = vtkPoints::New();
165 // don't know the number of points a priori -- just pick some number
166 points->Allocate(10000, 20000);
167
168 int lineNr = 2;
169 float xyz[3];
170 vtkIdType nodeCount = 0;
171
172 while (!errorCount && fgets(rawLine, MAX_LINE, in) != nullptr)
173 {
174 ++lineNr;
175 auto result =
176 vtk::scan<int, float, float, float>(std::string_view(rawLine), "{:d} {:f} {:f} {:f}");
177 if (result)
178 {
179 std::tie(lineLabel, xyz[0], xyz[1], xyz[2]) = result->values();
180 xyz[0] *= this->ScaleFactor;
181 xyz[1] *= this->ScaleFactor;
182 xyz[2] *= this->ScaleFactor;
183
184 points->InsertNextPoint(xyz);
185 vtkIdType nodeId = lineLabel;
186 mapPointId.insert(std::make_pair(nodeId, nodeCount));
187 ++nodeCount;
188 }
189 else
190 {
191 vtkErrorMacro(<< "Error reading point at line " << lineNr);
192 ++errorCount;
193 }
194 }

Callers 1

RequestDataMethod · 0.95

Calls 11

OpenFileMethod · 0.95
DeleteMethod · 0.65
NewFunction · 0.50
clearMethod · 0.45
valueMethod · 0.45
AllocateMethod · 0.45
valuesMethod · 0.45
InsertNextPointMethod · 0.45
insertMethod · 0.45
SqueezeMethod · 0.45
SetPointsMethod · 0.45

Tested by

no test coverage detected