vtkXdmf3SILBuilder.cxx 4.02 KB
Newer Older
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXdmf3SILBuilder.cxx
  Language:  C++

  Copyright (c) 1993-2002 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.

=========================================================================*/

#include "vtkXdmf3SILBuilder.h"

#include "vtkDataSetAttributes.h"
#include "vtkStringArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkMutableDirectedGraph.h"

// As soon as num-grids (sub-grids and all) grows beyond this number, we assume
// that the grids are too numerous for the user to select individually and
// hence only the top-level grids are made accessible.
#define MAX_COLLECTABLE_NUMBER_OF_GRIDS 1000

//------------------------------------------------------------------------------
vtkXdmf3SILBuilder::vtkXdmf3SILBuilder()
{
  this->SIL = NULL;
  this->NamesArray = NULL;
  this->CrossEdgesArray = NULL;
  this->RootVertex = -1;
  this->BlocksRoot = -1;
  this->HierarchyRoot = -1;
  this->VertexCount = 0;
}

//------------------------------------------------------------------------------
vtkXdmf3SILBuilder::~vtkXdmf3SILBuilder()
{
  if (this->SIL)
45
  {
46
    this->SIL->Delete();
47
  }
48
  if (this->NamesArray)
49
  {
50
    this->NamesArray->Delete();
51
  }
52
  if (this->CrossEdgesArray)
53
  {
54
    this->CrossEdgesArray->Delete();
55
  }
56 57 58 59 60 61
}

//------------------------------------------------------------------------------
void vtkXdmf3SILBuilder::Initialize()
{
  if (this->SIL)
62
  {
63
    this->SIL->Delete();
64
  }
65 66 67 68
  this->SIL = vtkMutableDirectedGraph::New();
  this->SIL->Initialize();

  if (this->NamesArray)
69
  {
70
    this->NamesArray->Delete();
71
  }
72 73 74 75 76
  this->NamesArray = vtkStringArray::New();
  this->NamesArray->SetName("Names");
  this->SIL->GetVertexData()->AddArray(this->NamesArray);

  if (this->CrossEdgesArray)
77
  {
78
    this->CrossEdgesArray->Delete();
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 133 134 135 136 137 138 139 140 141

  this->CrossEdgesArray = vtkUnsignedCharArray::New();
  this->CrossEdgesArray->SetName("CrossEdges");
  this->SIL->GetEdgeData()->AddArray(this->CrossEdgesArray);

  this->RootVertex = this->AddVertex("SIL");
  this->BlocksRoot = this->AddVertex("Blocks");
  this->HierarchyRoot = this->AddVertex("Hierarchy");
  this->AddChildEdge(RootVertex, BlocksRoot);
  this->AddChildEdge(RootVertex, HierarchyRoot);

  this->VertexCount = 0;
}

//------------------------------------------------------------------------------
vtkIdType vtkXdmf3SILBuilder::AddVertex(const char* name)
{
  this->VertexCount++;
  vtkIdType vertex = this->SIL->AddVertex();
  this->NamesArray->InsertValue(vertex, name);
  return vertex;
}

//------------------------------------------------------------------------------
vtkIdType vtkXdmf3SILBuilder::AddChildEdge(vtkIdType parent, vtkIdType child)
{
  vtkIdType id = this->SIL->AddEdge(parent, child).Id;
  this->CrossEdgesArray->InsertValue(id, 0);
  return id;
}

//------------------------------------------------------------------------------
vtkIdType vtkXdmf3SILBuilder::AddCrossEdge(vtkIdType src, vtkIdType dst)
{
  vtkIdType id = this->SIL->AddEdge(src, dst).Id;
  this->CrossEdgesArray->InsertValue(id, 1);
  return id;
}

//------------------------------------------------------------------------------
vtkIdType vtkXdmf3SILBuilder::GetRootVertex()
{
  return this->RootVertex;
}

//------------------------------------------------------------------------------
vtkIdType vtkXdmf3SILBuilder::GetBlocksRoot()
{
  return this->BlocksRoot;
}

//------------------------------------------------------------------------------
vtkIdType vtkXdmf3SILBuilder::GetHierarchyRoot()
{
  return this->HierarchyRoot;
}

//------------------------------------------------------------------------------
bool vtkXdmf3SILBuilder::IsMaxedOut()
{
  return (this->VertexCount >= MAX_COLLECTABLE_NUMBER_OF_GRIDS);
}