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

Method BuildTree

IO/Infovis/vtkNewickTreeReader.cxx:314–493  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

312
313//------------------------------------------------------------------------------
314vtkIdType vtkNewickTreeReader::BuildTree(char* buffer, vtkMutableDirectedGraph* g,
315 vtkDoubleArray* weights, vtkStringArray* names, vtkIdType parent)
316{
317 char* current;
318 char* start;
319 char* colon = nullptr;
320 char temp;
321 int childCount;
322 vtkIdType node;
323
324 start = buffer;
325
326 if (*start != '(')
327 {
328 // Leaf node. Separate name from weight (if it exists).
329 current = buffer;
330 while (*current != '\0')
331 {
332 if (*current == ':')
333 {
334 colon = current;
335 }
336 current++;
337 }
338 node = g->AddChild(parent);
339 if (colon == nullptr)
340 {
341 // Name only
342 std::string name(start, strlen(start));
343 names->SetValue(node, name);
344 }
345 else
346 {
347 // Name
348 *colon = '\0';
349 std::string name(start, strlen(start));
350 names->SetValue(node, name);
351 *colon = ':';
352 // Weight
353 colon++;
354 double weight;
355 VTK_FROM_CHARS_IF_ERROR_BREAK(colon, weight);
356 weights->SetValue(g->GetEdgeId(parent, node), weight);
357 }
358 }
359 else
360 {
361 // Create node
362 if (parent == -1)
363 {
364 node = g->AddVertex();
365 names->SetValue(node, "");
366 }
367 else
368 {
369 node = g->AddChild(parent);
370 }
371

Callers 1

ReadNewickTreeMethod · 0.95

Calls 4

GetEdgeIdMethod · 0.80
AddChildMethod · 0.45
SetValueMethod · 0.45
AddVertexMethod · 0.45

Tested by

no test coverage detected