File: vtkRemoveHiddenData.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 (169 lines) | stat: -rw-r--r-- 5,251 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkRemoveHiddenData.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 "vtkRemoveHiddenData.h"

#include "vtkAnnotation.h"
#include "vtkAnnotationLayers.h"
#include "vtkCellData.h"
#include "vtkConvertSelection.h"
#include "vtkDoubleArray.h"
#include "vtkExtractSelectedGraph.h"
#include "vtkExtractSelectedRows.h"
#include "vtkGraph.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkDataSet.h"
#include "vtkScalarsToColors.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include "vtkUnsignedCharArray.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"


vtkStandardNewMacro(vtkRemoveHiddenData);

vtkRemoveHiddenData::vtkRemoveHiddenData()
{
  this->ExtractGraph = vtkSmartPointer<vtkExtractSelectedGraph>::New();
  this->ExtractGraph->SetRemoveIsolatedVertices(false);

  this->ExtractTable = vtkSmartPointer<vtkExtractSelectedRows>::New();

  this->SetNumberOfInputPorts(2);
}

vtkRemoveHiddenData::~vtkRemoveHiddenData()
{
}

int vtkRemoveHiddenData::FillInputPortInformation(int port, vtkInformation* info)
{
  if (port == 0)
    {
    info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkGraph");
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable");
    }
  else if (port == 1)
    {
    info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkAnnotationLayers");
    info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
    }
  return 1;
}

int vtkRemoveHiddenData::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
{
  // get the info objects
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation* annotationsInfo = inputVector[1]->GetInformationObject(0);
  vtkInformation* outInfo = outputVector->GetInformationObject(0);

  // get the input and output
  vtkDataObject* input = inInfo->Get(vtkDataObject::DATA_OBJECT());
  vtkDataObject* output = outInfo->Get(vtkDataObject::DATA_OBJECT());

  vtkAnnotationLayers* annotations = 0;
  if (annotationsInfo)
    {
    annotations = vtkAnnotationLayers::SafeDownCast(
      annotationsInfo->Get(vtkDataObject::DATA_OBJECT()));
    }

  // Nothing to do if no input annotations
  if (!annotations)
    {
    output->ShallowCopy(input);
    return 1;
    }

  vtkGraph* graph = vtkGraph::SafeDownCast(output);
  vtkTable* table = vtkTable::SafeDownCast(output);

  vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
  unsigned int numAnnotations = annotations->GetNumberOfAnnotations();
  int numHiddenAnnotations = 0;
  for (unsigned int a = 0; a < numAnnotations; ++a)
    {
    vtkAnnotation* ann = annotations->GetAnnotation(a);

    // Only if the annotation is both enabled AND hidden will
    // its selection get added
    if (ann->GetInformation()->Has(vtkAnnotation::ENABLE()) &&
        ann->GetInformation()->Get(vtkAnnotation::ENABLE())==1 &&
        ann->GetInformation()->Has(vtkAnnotation::HIDE()) &&
        ann->GetInformation()->Get(vtkAnnotation::HIDE())==1 )
      {
      selection->Union(ann->GetSelection());
      numHiddenAnnotations++;
      }
    }

  // Nothing to do if no hidden annotations
  if(numHiddenAnnotations == 0)
    {
    output->ShallowCopy(input);
    return 1;
    }

  // We want to output the visible data, so the hidden annotation
  // selections need to be inverted before sent to the extraction filter:
  for (unsigned int i = 0; i < selection->GetNumberOfNodes(); ++i)
    {
    vtkSelectionNode* node = selection->GetNode(i);
    node->GetProperties()->Set(vtkSelectionNode::INVERSE(),1);
    }

  if (graph)
    {
    this->ExtractGraph->SetInputData(input);
    this->ExtractGraph->SetInputData(1, selection);
    this->ExtractGraph->Update();
    output->ShallowCopy(this->ExtractGraph->GetOutput());
    }
  else if (table)
    {
    this->ExtractTable->SetInputData(input);
    this->ExtractTable->SetInputData(1, selection);
    this->ExtractTable->Update();
    output->ShallowCopy(this->ExtractTable->GetOutput());
    }
  else
    {
    vtkErrorMacro("Unsupported input data type.");
    return 0;
    }

  return 1;
}



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