File: vtkStreamGraph.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (132 lines) | stat: -rw-r--r-- 4,302 bytes parent folder | download | duplicates (9)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkStreamGraph.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkStreamGraph.h"

#include "vtkCommand.h"
#include "vtkDataSetAttributes.h"
#include "vtkEdgeListIterator.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMergeGraphs.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkMutableUndirectedGraph.h"
#include "vtkMutableGraphHelper.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"

#include <map>

vtkStandardNewMacro(vtkStreamGraph);
//---------------------------------------------------------------------------
vtkStreamGraph::vtkStreamGraph()
{
  this->CurrentGraph = vtkMutableGraphHelper::New();
  this->MergeGraphs = vtkMergeGraphs::New();
  this->UseEdgeWindow = false;
  this->EdgeWindowArrayName = 0;
  this->SetEdgeWindowArrayName("time");
  this->EdgeWindow = 10000.0;
}

//---------------------------------------------------------------------------
vtkStreamGraph::~vtkStreamGraph()
{
  if (this->CurrentGraph)
    {
    this->CurrentGraph->Delete();
    }
  if (this->MergeGraphs)
    {
    this->MergeGraphs->Delete();
    }
  this->SetEdgeWindowArrayName(0);
}

//---------------------------------------------------------------------------
int vtkStreamGraph::RequestData(
  vtkInformation*,
  vtkInformationVector** inputVector,
  vtkInformationVector* outputVector)
{
  vtkInformation* input_info = inputVector[0]->GetInformationObject(0);
  vtkGraph* input = vtkGraph::SafeDownCast(
    input_info->Get(vtkDataObject::DATA_OBJECT()));

  // Copy structure into output graph.
  vtkInformation* outputInfo = outputVector->GetInformationObject(0);
  vtkGraph* output = vtkGraph::SafeDownCast(
    outputInfo->Get(vtkDataObject::DATA_OBJECT()));

  double progress = 0.1;
  this->InvokeEvent(vtkCommand::ProgressEvent, &progress);

  // First pass: make a copy of the graph and we're done
  if (!this->CurrentGraph->GetGraph())
    {
    if (vtkDirectedGraph::SafeDownCast(input))
      {
      vtkSmartPointer<vtkMutableDirectedGraph> g = vtkSmartPointer<vtkMutableDirectedGraph>::New();
      this->CurrentGraph->SetGraph(g);
      }
    else
      {
      vtkSmartPointer<vtkMutableUndirectedGraph> g = vtkSmartPointer<vtkMutableUndirectedGraph>::New();
      this->CurrentGraph->SetGraph(g);
      }
    this->CurrentGraph->GetGraph()->DeepCopy(input);
    if (!output->CheckedShallowCopy(input))
      {
      vtkErrorMacro("Output graph format invalid.");
      return 0;
      }
    return 1;
    }

  progress = 0.2;
  this->InvokeEvent(vtkCommand::ProgressEvent, &progress);

  this->MergeGraphs->SetUseEdgeWindow(this->UseEdgeWindow);
  this->MergeGraphs->SetEdgeWindowArrayName(this->EdgeWindowArrayName);
  this->MergeGraphs->SetEdgeWindow(this->EdgeWindow);

  if (!this->MergeGraphs->ExtendGraph(this->CurrentGraph, input))
    {
    return 0;
    }

  progress = 0.9;
  this->InvokeEvent(vtkCommand::ProgressEvent, &progress);

  output->DeepCopy(this->CurrentGraph->GetGraph());

  return 1;
}

//---------------------------------------------------------------------------
void vtkStreamGraph::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "UseEdgeWindow: " << this->UseEdgeWindow << endl;
  os << indent << "EdgeWindowArrayName: "
     << (this->EdgeWindowArrayName ? this->EdgeWindowArrayName : "(none)") << endl;
  os << indent << "EdgeWindow: " << this->EdgeWindow << endl;
}