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 170 171 172 173 174 175 176 177 178
|
/*=========================================================================
Program: ParaView
Module: vtkSMArrayRangeDomain.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 "vtkSMArrayRangeDomain.h"
#include "vtkDataObject.h"
#include "vtkObjectFactory.h"
#include "vtkPVArrayInformation.h"
#include "vtkPVDataInformation.h"
#include "vtkSMArrayListDomain.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMUncheckedPropertyHelper.h"
vtkStandardNewMacro(vtkSMArrayRangeDomain);
//---------------------------------------------------------------------------
vtkSMArrayRangeDomain::vtkSMArrayRangeDomain()
{
}
//---------------------------------------------------------------------------
vtkSMArrayRangeDomain::~vtkSMArrayRangeDomain()
{
}
//---------------------------------------------------------------------------
void vtkSMArrayRangeDomain::Update(vtkSMProperty*)
{
// Find the array whose range we are interested in and then find the producer
// who is producing the data with the array of interest.
vtkSMProperty* propForInput = this->GetRequiredProperty("Input");
vtkSMProperty* propForArraySelection =
this->GetRequiredProperty("ArraySelection");
if (!propForInput || !propForArraySelection)
{
return;
}
vtkSMUncheckedPropertyHelper inputHelper(propForInput);
vtkSMUncheckedPropertyHelper arraySelectionHelper(propForArraySelection);
if (arraySelectionHelper.GetNumberOfElements() < 5)
{
return;
}
const char* arrayName = arraySelectionHelper.GetAsString(4);
if (!arrayName || arrayName[0] == '\0')
{
return;
}
if (vtkSMSourceProxy::SafeDownCast(inputHelper.GetAsProxy()) != NULL)
{
this->Update(arrayName, arraySelectionHelper.GetAsInt(3),
vtkSMSourceProxy::SafeDownCast(inputHelper.GetAsProxy()),
inputHelper.GetOutputPort());
}
}
//---------------------------------------------------------------------------
void vtkSMArrayRangeDomain::Update(
const char* arrayName, int fieldAssociation,
vtkSMSourceProxy* producer, int producerPort)
{
assert(producer != NULL && arrayName != NULL);
// Make sure the outputs are created.
producer->CreateOutputPorts();
vtkPVDataInformation* info = producer->GetDataInformation(producerPort);
if (!info)
{
return;
}
vtkPVArrayInformation* arrayInfo = info->GetArrayInformation(
arrayName, fieldAssociation);
int component_number = VTK_INT_MAX;
if (arrayInfo == NULL &&
(fieldAssociation == vtkDataObject::POINT ||
fieldAssociation == vtkDataObject::CELL))
{
// it's possible that the array name was mangled due to "auto-conversion" of
// field arrays.
// first try to see if there's a component suffix added and hence we failed
// to locate the array information.
std::string name = vtkSMArrayListDomain::ArrayNameFromMangledName(arrayName);
arrayInfo = name.length() > 0?
info->GetArrayInformation(name.c_str(), fieldAssociation) :
NULL;
if (!arrayInfo)
{
// try the other field association.
int otherField = fieldAssociation == vtkDataObject::POINT?
vtkDataObject::CELL : vtkDataObject::POINT;
arrayInfo = info->GetArrayInformation(arrayName, otherField);
arrayInfo = arrayInfo? arrayInfo :
info->GetArrayInformation(name.c_str(), otherField);
}
// Now, extract component information. If name == arrayName, it means we
// don't have any component information in the array name itself.
if (arrayInfo && (name != arrayName))
{
int mangledCompNo = vtkSMArrayListDomain::ComponentIndexFromMangledName(
arrayInfo, arrayName);
// ComponentIndexFromMangledName returns -1 on error and num_of_component
// for magnitude. Which is not what vtkPVArrayInformation expects, to
// convert that.
if (mangledCompNo == -1)
{
return;
}
if (mangledCompNo >= arrayInfo->GetNumberOfComponents())
{
component_number = -1;
}
else
{
component_number = mangledCompNo;
}
}
}
if (!arrayInfo)
{
std::vector<vtkEntry> values;
this->SetEntries(values);
}
else if (component_number < arrayInfo->GetNumberOfComponents())
{
// a particular component was chosen, add ranges for that.
std::vector<vtkEntry> values(1);
values[0].Valid[0] = values[0].Valid[1] = true;
values[0].Value = vtkTuple<double, 2>(
arrayInfo->GetComponentRange(component_number));
this->SetEntries(values);
}
else
{
std::vector<vtkEntry> values(arrayInfo->GetNumberOfComponents());
for (int cc=0; cc <arrayInfo->GetNumberOfComponents(); cc++)
{
values[cc].Valid[0] = values[cc].Valid[1] = true;
values[cc].Value = vtkTuple<double, 2>(
arrayInfo->GetComponentRange(cc));
}
if (arrayInfo->GetNumberOfComponents() > 1)
{
// add vector magnitude.
vtkEntry entry;
entry.Valid[0] = entry.Valid[1] = true;
entry.Value = vtkTuple<double, 2>(arrayInfo->GetComponentRange(-1));
values.push_back(entry);
}
this->SetEntries(values);
}
}
//---------------------------------------------------------------------------
void vtkSMArrayRangeDomain::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|