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

Method ReadCelFile

IO/Geometry/vtkProStarReader.cxx:244–446  ·  view source on GitHub ↗

read in the cells from the .cel file ---------------------------------------------------------------------------*\ Line 1: PROSTAR_CELL [newline] Line 2: 0 0 0 0 0 0 0 [newline] Body: [newline] .. .. with shapeId: * 1 = point * 2 = line * 3 = shell * 11 = hexa * 12 = prism * 13 = tetra *

Source from the content-addressed store, hash-verified

242
243\*---------------------------------------------------------------------------*/
244bool vtkProStarReader::ReadCelFile(vtkUnstructuredGrid* output, const idMapping& mapPointId)
245{
246 FILE* in = this->OpenFile(".cel");
247 if (in == nullptr)
248 {
249 return false;
250 }
251
252 constexpr int MAX_LINE = 1024;
253 char rawLine[MAX_LINE];
254
255 int errorCount = 0;
256 vtk::scan_result_type<std::string_view, int> resultLabel;
257 if (fgets(rawLine, MAX_LINE, in) != nullptr && strncmp(rawLine, "PROSTAR_CELL", 12) == 0 &&
258 fgets(rawLine, MAX_LINE, in) != nullptr &&
259 ((resultLabel = vtk::scan_int<int>(std::string_view(rawLine)))) && resultLabel->value() >= 4000)
260 {
261 vtkDebugMacro(<< "Got PROSTAR_CELL header");
262 }
263 else
264 {
265 vtkErrorMacro(<< "Error reading header for PROSTAR_CELL file");
266 ++errorCount;
267 }
268 int lineLabel = resultLabel->value();
269
270 // don't know the number of cells a priori -- just pick some number
271 output->Allocate(10000, 20000);
272
273 // add a cellTableId array
274 vtkIntArray* cellTableId = vtkIntArray::New();
275 cellTableId->Allocate(10000, 20000);
276 cellTableId->SetName("cellTableId");
277
278 int shapeId, nLabels, tableId, typeId;
279 std::vector<vtkIdType> starLabels;
280 starLabels.reserve(256);
281
282 // face-stream for a polyhedral cell
283 // [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...]
284 std::vector<vtkIdType> faceStream;
285 faceStream.reserve(256);
286
287 // use string buffer for easier parsing
288 std::istringstream strbuf;
289
290 int lineNr = 2;
291 while (!errorCount && fgets(rawLine, MAX_LINE, in) != nullptr)
292 {
293 ++lineNr;
294 auto result =
295 vtk::scan<int, int, int, int, int>(std::string_view(rawLine), "{:d} {:d} {:d} {:d} {:d}");
296 if (result)
297 {
298 std::tie(lineLabel, shapeId, nLabels, tableId, typeId) = result->values();
299 starLabels.clear();
300 starLabels.reserve(nLabels);
301

Callers 1

RequestDataMethod · 0.95

Calls 15

OpenFileMethod · 0.95
SetScalarsMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
swapFunction · 0.50
valueMethod · 0.45
AllocateMethod · 0.45
SetNameMethod · 0.45
reserveMethod · 0.45
valuesMethod · 0.45
clearMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected