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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkThresholdTable.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 "vtkThresholdTable.h"
#include "vtkArrayIteratorIncludes.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkVariant.h"
#include "vtkVariantArray.h"
vtkStandardNewMacro(vtkThresholdTable);
vtkThresholdTable::vtkThresholdTable() : MinValue(0), MaxValue(VTK_INT_MAX), Mode(0)
{
}
vtkThresholdTable::~vtkThresholdTable()
{
}
void vtkThresholdTable::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "MinValue: " << this->MinValue.ToString() << endl;
os << indent << "MaxValue: " << this->MaxValue.ToString() << endl;
os << indent << "Mode: ";
switch (this->Mode)
{
case ACCEPT_LESS_THAN:
os << "Accept less than";
break;
case ACCEPT_GREATER_THAN:
os << "Accept greater than";
break;
case ACCEPT_BETWEEN:
os << "Accept between";
break;
case ACCEPT_OUTSIDE:
os << "Accept outside";
break;
default:
os << "Undefined";
break;
}
os << endl;
}
static bool vtkThresholdTableCompare(vtkVariant a, vtkVariant b)
{
return a.ToDouble() <= b.ToDouble();
}
template <typename iterT>
void vtkThresholdTableThresholdRows(iterT* it, vtkTable* input, vtkTable* output, vtkVariant min, vtkVariant max, int mode)
{
vtkIdType maxInd = it->GetNumberOfValues();
for (vtkIdType i = 0; i < maxInd; i++)
{
bool accept = false;
vtkVariant v(it->GetValue(i));
if (mode == vtkThresholdTable::ACCEPT_LESS_THAN)
{
accept = vtkThresholdTableCompare(v, max);
}
else if (mode == vtkThresholdTable::ACCEPT_GREATER_THAN)
{
accept = vtkThresholdTableCompare(min, v);
}
else if (mode == vtkThresholdTable::ACCEPT_BETWEEN)
{
accept = (vtkThresholdTableCompare(min, v) && vtkThresholdTableCompare(v, max));
}
else if (mode == vtkThresholdTable::ACCEPT_OUTSIDE)
{
accept = (vtkThresholdTableCompare(v, min) || vtkThresholdTableCompare(max, v));
}
if (accept)
{
vtkVariantArray* row = input->GetRow(i);
output->InsertNextRow(row);
}
}
}
void vtkThresholdTable::ThresholdBetween(vtkVariant lower, vtkVariant upper)
{
if ( this->MinValue != lower || this->MaxValue != upper ||
this->Mode != vtkThresholdTable::ACCEPT_BETWEEN)
{
this->MinValue = lower;
this->MaxValue = upper;
this->Mode = vtkThresholdTable::ACCEPT_BETWEEN;
this->Modified();
}
}
int vtkThresholdTable::RequestData(
vtkInformation*,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkAbstractArray* arr = this->GetInputAbstractArrayToProcess(0, inputVector);
if (arr == NULL)
{
vtkErrorMacro("An input array must be specified.");
return 0;
}
vtkTable* input = vtkTable::GetData(inputVector[0]);
vtkTable* output = vtkTable::GetData(outputVector);
for (int n = 0; n < input->GetNumberOfColumns(); n++)
{
vtkAbstractArray* col = input->GetColumn(n);
vtkAbstractArray* ncol = vtkAbstractArray::CreateArray(col->GetDataType());
ncol->SetName(col->GetName());
ncol->SetNumberOfComponents(col->GetNumberOfComponents());
output->AddColumn(ncol);
ncol->Delete();
}
vtkArrayIterator* iter = arr->NewIterator();
switch (arr->GetDataType())
{
vtkArrayIteratorTemplateMacro(
vtkThresholdTableThresholdRows(static_cast<VTK_TT*>(iter), input, output,
this->MinValue, this->MaxValue, this->Mode));
}
iter->Delete();
return 1;
}
|