vtkPVMergeTables.cxx 4.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*=========================================================================

  Program:   ParaView
  Module:    vtkPVMergeTables.cxx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkPVMergeTables.h"

17
18
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
19
#include "vtkDataSetAttributes.h"
20
21
#include "vtkInformation.h"
#include "vtkInformationVector.h"
22
23
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
24
#include "vtkSmartPointer.h"
25
#include "vtkTable.h"
26
27
28
29
30
31
32
33
34
35
36
37
38

vtkStandardNewMacro(vtkPVMergeTables);
//----------------------------------------------------------------------------
vtkPVMergeTables::vtkPVMergeTables()
{
}

//----------------------------------------------------------------------------
vtkPVMergeTables::~vtkPVMergeTables()
{
}

//----------------------------------------------------------------------------
Kitware Robot's avatar
Kitware Robot committed
39
int vtkPVMergeTables::FillInputPortInformation(int vtkNotUsed(port), vtkInformation* info)
40
41
{
  info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
42
43
44
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable");
  info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
  return 1;
45
46
47
}

//----------------------------------------------------------------------------
48
vtkExecutive* vtkPVMergeTables::CreateDefaultExecutive()
49
{
50
51
  return vtkCompositeDataPipeline::New();
}
52

53
54
55
//----------------------------------------------------------------------------
static void vtkPVMergeTablesMerge(vtkTable* output, vtkTable* inputs[], int num_inputs)
{
56
  vtkDataSetAttributes::FieldList fields;
57
  for (int idx = 0; idx < num_inputs; ++idx)
Kitware Robot's avatar
Kitware Robot committed
58
  {
59
    vtkTable* curTable = inputs[idx];
60
    if (curTable && curTable->GetNumberOfRows() > 0 && curTable->GetNumberOfColumns() > 0)
Kitware Robot's avatar
Kitware Robot committed
61
    {
62
      fields.IntersectFieldList(curTable->GetRowData());
Kitware Robot's avatar
Kitware Robot committed
63
    }
64
  }
65

66
67
68
69
70
71
72
73
74
75
  auto outRD = output->GetRowData();
  // passing sz=0 ensures that fields simply uses the accumulated counts for
  // number of rows.
  fields.CopyAllocate(outRD, vtkDataSetAttributes::PASSDATA, /*sz=*/0, /*ext=*/0);

  vtkIdType outStartRow = 0;
  for (int idx = 0, fieldsInputIdx = 0; idx < num_inputs; ++idx)
  {
    vtkTable* curTable = inputs[idx];
    if (!curTable || curTable->GetNumberOfRows() == 0 || curTable->GetNumberOfColumns() == 0)
Kitware Robot's avatar
Kitware Robot committed
76
    {
77
      continue;
Kitware Robot's avatar
Kitware Robot committed
78
    }
79

80
81
82
83
84
    auto inRD = curTable->GetRowData();
    const auto inNumRows = inRD->GetNumberOfTuples();
    fields.CopyData(fieldsInputIdx, inRD, 0, inNumRows, outRD, outStartRow);
    outStartRow += inNumRows;
    ++fieldsInputIdx;
Kitware Robot's avatar
Kitware Robot committed
85
  }
86
87
88
89
}

//----------------------------------------------------------------------------
int vtkPVMergeTables::RequestData(
Kitware Robot's avatar
Kitware Robot committed
90
  vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
91
92
93
94
95
96
97
{
  int num_connections = this->GetNumberOfInputConnections(0);

  // Get output table
  vtkTable* outputTable = vtkTable::GetData(outputVector, 0);

  if (vtkTable::GetData(inputVector[0], 0))
Kitware Robot's avatar
Kitware Robot committed
98
  {
99
100
    vtkTable** inputs = new vtkTable*[num_connections];
    for (int idx = 0; idx < num_connections; ++idx)
Kitware Robot's avatar
Kitware Robot committed
101
    {
102
      inputs[idx] = vtkTable::GetData(inputVector[0], idx);
Kitware Robot's avatar
Kitware Robot committed
103
    }
104
    ::vtkPVMergeTablesMerge(outputTable, inputs, num_connections);
Kitware Robot's avatar
Kitware Robot committed
105
    delete[] inputs;
106
    return 1;
Kitware Robot's avatar
Kitware Robot committed
107
  }
108

109
110
111
112
  vtkCompositeDataSet* input0 = vtkCompositeDataSet::GetData(inputVector[0], 0);
  vtkCompositeDataIterator* iter = input0->NewIterator();
  iter->SkipEmptyNodesOff();
  for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
Kitware Robot's avatar
Kitware Robot committed
113
  {
114
115
    vtkTable** inputs = new vtkTable*[num_connections];
    for (int idx = 0; idx < num_connections; ++idx)
Kitware Robot's avatar
Kitware Robot committed
116
    {
117
118
      vtkCompositeDataSet* inputCD = vtkCompositeDataSet::GetData(inputVector[0], idx);
      if (!inputCD)
Kitware Robot's avatar
Kitware Robot committed
119
      {
120
        continue;
Kitware Robot's avatar
Kitware Robot committed
121
      }
122
123
124
      vtkSmartPointer<vtkCompositeDataIterator> iter2;
      iter2.TakeReference(inputCD->NewIterator());
      if (iter2->IsDoneWithTraversal())
Kitware Robot's avatar
Kitware Robot committed
125
      {
126
127
128
        // trivial case, the composite dataset being merged is empty, simply
        // ignore it.
        inputs[idx] = NULL;
Kitware Robot's avatar
Kitware Robot committed
129
      }
130
      else
Kitware Robot's avatar
Kitware Robot committed
131
      {
132
        inputs[idx] = vtkTable::SafeDownCast(inputCD->GetDataSet(iter));
133
134
      }
    }
Kitware Robot's avatar
Kitware Robot committed
135
136
137
    ::vtkPVMergeTablesMerge(outputTable, inputs, num_connections);
    delete[] inputs;
  }
138
  iter->Delete();
139
140
141
142
143
144
145
146
  return 1;
}

//----------------------------------------------------------------------------
void vtkPVMergeTables::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}