Commit f49b6a4c authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

cleanup vtkSMFieldDataDomain

vtkSMFieldDataDomain no longer updates itself based on input type. That
was generally not useful and added unnecessary complication to the
domain and the corresponding UI. Cleaned that up.

vtkSMFieldDataDomain now raises warnings if used in
vtkSMStringVectorProperty as we tended to do in the past.
parent a80fbc54
......@@ -25,21 +25,16 @@
#include "vtkSMInputProperty.h"
#include "vtkSMIntVectorProperty.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMStringVectorProperty.h"
#include "vtkSmartPointer.h"
#include <set>
vtkStandardNewMacro(vtkSMFieldDataDomain);
//---------------------------------------------------------------------------
static const char* const vtkSMFieldDataDomainAttributeTypes[] = { "Point Data", "Cell Data",
"Field Data", "(invalid)", "Vertex Data", "Edge Data", "Row Data", NULL };
//---------------------------------------------------------------------------
vtkSMFieldDataDomain::vtkSMFieldDataDomain()
{
this->EnableFieldDataSelection = false;
this->DisableUpdateDomainEntries = false;
this->ForcePointAndCellDataSelection = false;
this->DefaultValue = -1;
}
//---------------------------------------------------------------------------
......@@ -48,112 +43,70 @@ vtkSMFieldDataDomain::~vtkSMFieldDataDomain()
}
//---------------------------------------------------------------------------
void vtkSMFieldDataDomain::Update(vtkSMProperty*)
const char* vtkSMFieldDataDomain::GetAttributeTypeAsString(int attrType)
{
// We don't return here, since even if updating the domain values may be
// disabled, we still would want to pick a good default for this domain.
// if (this->DisableUpdateDomainEntries)
// {
// return;
// }
vtkPVDataInformation* dataInfo = this->GetInputDataInformation("Input");
vtkSMProperty* pp = this->GetRequiredProperty("Input");
vtkSMInputArrayDomain* iad =
pp ? vtkSMInputArrayDomain::SafeDownCast(pp->FindDomain("vtkSMInputArrayDomain")) : NULL;
this->UpdateDomainEntries(iad ? iad->GetAttributeType() : vtkSMInputArrayDomain::ANY, dataInfo);
static const char* const vtkSMFieldDataDomainAttributeTypes[] = { "Point Data", "Cell Data",
"Field Data", nullptr, "Vertex Data", "Edge Data", "Row Data", nullptr };
if (attrType >= 0 && attrType < vtkDataObject::NUMBER_OF_ATTRIBUTE_TYPES)
{
return vtkSMFieldDataDomainAttributeTypes[attrType];
}
return nullptr;
}
//---------------------------------------------------------------------------
void vtkSMFieldDataDomain::UpdateDomainEntries(
int acceptable_association, vtkPVDataInformation* dataInfo)
int vtkSMFieldDataDomain::ComputeDefaultValue()
{
std::set<int> accepted_associations;
// iterate over all attribute types and add the "acceptable" attribute types
// to this domain.
for (int idx = vtkSMInputArrayDomain::POINT;
idx < vtkSMInputArrayDomain::NUMBER_OF_ATTRIBUTE_TYPES; idx++)
auto dataInfo = this->GetInputDataInformation("Input");
if (!dataInfo)
{
if (idx == vtkSMInputArrayDomain::ANY ||
!vtkSMInputArrayDomain::IsAttributeTypeAcceptable(acceptable_association, idx, NULL))
{
continue;
}
// Add field-data if ...
if (
// ... domain updates are disabled
this->DisableUpdateDomainEntries ||
// ... point/cell if forced.
(this->ForcePointAndCellDataSelection &&
(idx == vtkSMInputArrayDomain::POINT || idx == vtkSMInputArrayDomain::CELL)))
{
accepted_associations.insert(idx);
continue;
}
// add the idx is it has some arrays.
if (dataInfo == NULL || dataInfo->GetAttributeInformation(idx) == NULL ||
dataInfo->GetAttributeInformation(idx)->GetMaximumNumberOfTuples() == 0)
{
continue;
}
accepted_associations.insert(idx);
return -1;
}
// field data is added only if this->EnableFieldDataSelection is true.
if (this->EnableFieldDataSelection)
// first, find an attribute with non-empty arrays and tuples
for (unsigned int cc = 0, max = this->GetNumberOfEntries(); cc < max; ++cc)
{
accepted_associations.insert(vtkSMInputArrayDomain::FIELD);
const int attrType = this->GetEntryValue(cc);
auto attrInfo = dataInfo->GetAttributeInformation(attrType);
if (attrInfo && attrInfo->GetNumberOfArrays() > 0 && attrInfo->GetMaximumNumberOfTuples() > 0)
{
return attrType;
}
}
if (accepted_associations.size() > 0)
// if that fails, find an attribute with non-empty arrays
for (unsigned int cc = 0, max = this->GetNumberOfEntries(); cc < max; ++cc)
{
// to pick a good default, find the first non-empty acceptable attribute.
this->DefaultValue = (*accepted_associations.begin());
for (std::set<int>::const_iterator iter = accepted_associations.begin();
iter != accepted_associations.end(); ++iter)
const int attrType = this->GetEntryValue(cc);
auto attrInfo = dataInfo->GetAttributeInformation(attrType);
if (attrInfo && attrInfo->GetNumberOfArrays() > 0)
{
vtkPVDataSetAttributesInformation* attrInfo =
dataInfo ? dataInfo->GetAttributeInformation(*iter) : NULL;
if (attrInfo && attrInfo->GetNumberOfArrays() > 0)
{
this->DefaultValue = *iter;
break;
}
return attrType;
}
}
else
{
this->DefaultValue = -1;
}
// FIXME: Add ability to not modify the domain unless changed for real.
this->RemoveAllEntries();
for (std::set<int>::const_iterator iter = accepted_associations.begin();
iter != accepted_associations.end(); iter++)
{
this->AddEntry(vtkSMFieldDataDomainAttributeTypes[*iter], *iter);
}
return -1;
}
//---------------------------------------------------------------------------
int vtkSMFieldDataDomain::SetDefaultValues(vtkSMProperty* prop, bool use_unchecked_values)
{
vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(prop);
if (ivp && this->DefaultValue != -1)
if (vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(prop))
{
if (use_unchecked_values)
{
ivp->SetUncheckedElement(0, this->DefaultValue);
}
else
const int defaultValue = this->ComputeDefaultValue();
if (defaultValue != -1)
{
ivp->SetElement(0, this->DefaultValue);
if (use_unchecked_values)
{
ivp->SetUncheckedElement(0, defaultValue);
}
else
{
ivp->SetElement(0, defaultValue);
}
return 1;
}
return 1;
}
return this->Superclass::SetDefaultValues(prop, use_unchecked_values);
}
......@@ -166,24 +119,64 @@ int vtkSMFieldDataDomain::ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLElement
return 0;
}
if (vtkSMStringVectorProperty::SafeDownCast(prop))
{
#if !defined(VTK_LEGACY_SILENT)
vtkErrorMacro(
"`vtkSMFieldDataDomain` is being used on a `vtkSMStringVectorProperty`. "
"This is no longer needed or supported. Simply remove it from your XML configuration "
"for property "
<< prop->GetXMLName());
#endif
#if defined(VTK_LEGACY_REMOVE)
return 0;
#else
return 1;
#endif
}
#if !defined(VTK_LEGACY_SILENT)
if (element->GetAttribute("disable_update_domain_entries"))
{
vtkErrorMacro("`vtkSMFieldDataDomain` no longer supports or needs "
"`disable_update_domain_entries` attribute."
"Simply remove it from the XML for property "
<< prop->GetXMLName());
}
if (element->GetAttribute("force_point_cell_data"))
{
vtkErrorMacro(
"`vtkSMFieldDataDomain` no longer supports or needs `force_point_cell_data` attribute."
"Simply remove it from the XML for property "
<< prop->GetXMLName());
}
#endif
int enable_field_data = 0;
if (element->GetScalarAttribute("enable_field_data", &enable_field_data))
{
this->EnableFieldDataSelection = (enable_field_data != 0) ? true : false;
}
int disable_update_domain_entries = 0;
if (element->GetScalarAttribute("disable_update_domain_entries", &disable_update_domain_entries))
{
this->DisableUpdateDomainEntries = (disable_update_domain_entries != 0) ? true : false;
}
int force_point_cell_data = 0;
if (element->GetScalarAttribute("force_point_cell_data", &force_point_cell_data))
// iterate over all attribute types and add the "acceptable" attribute types
// to this domain.
this->RemoveAllEntries();
for (int idx = 0; idx < vtkSMInputArrayDomain::NUMBER_OF_ATTRIBUTE_TYPES; idx++)
{
this->ForcePointAndCellDataSelection = (force_point_cell_data != 0) ? true : false;
auto label = vtkSMFieldDataDomain::GetAttributeTypeAsString(idx);
if (!label)
{
continue;
}
if (idx == vtkDataObject::FIELD && !this->EnableFieldDataSelection)
{
continue;
}
this->AddEntry(label, idx);
}
this->UpdateDomainEntries(vtkSMInputArrayDomain::ANY, NULL);
return 1;
}
......
......@@ -13,31 +13,38 @@
=========================================================================*/
/**
* @class vtkSMFieldDataDomain
* @brief enumeration with point and cell data entries
* @class vtkSMFieldDataDomain
* @brief enumeration domain to select array association or attribute type.
*
* vtkSMFieldDataDomain is a sub-class vtkSMEnumerationDomain that looks at
* the input in Update() and populates the entry list based on whether
* there are valid arrays in point/cell/vertex/edge/row data.
* At most it consists of two
* entries: ("Point Data", vtkDataObject::FIELD_ASSOCIATION_POINTS) and
* ("Cell Data", vtkDataObject::FIELD_ASSOCIATION_CELLS) in case of vtkDataSet
* subclasses
* OR
* ("Vertex Data", vtkDataObject::FIELD_ASSOCIATION_VERTICES) and
* ("Edge Data", vtkDataObject::FIELD_ASSOCIATION_EDGES) in case of vtkGraph and
* subclasses
* OR
* ("Row Data", vtkDataObject::FIELD_ASSOCIATION_ROWS) in case of vtkTable and
* subclasses.
* It requires Input (vtkSMProxyProperty) property.
* If attribute "disable_update_domain_entries" is set to true (false by
* default),
* then the domain values will not changed based on input field availability.
* Only the default value setting will be affected by that.
* @sa
* vtkSMEnumerationDomain vtkSMProxyProperty
*/
* vtkSMFieldDataDomain can be used on a vtkSMIntVectorProperty that is intended
* to specify the attribute type (`vtkDataObject::AttributeTypes`) or field association
* (`vtkDataObject::FieldAssociations`).
*
* By default, `vtkDataObject::Field` (or vtkDataObject::FIELD_ASSOCIATION_NONE) is
* not added to the domain. If you want to support field data, then use `enable_field_data="1"`
* attribute in the XML configuration.
*
* @section DefaultValue Selecting the default value
*
* vtkSMFieldDataDomain picks the default value to be the first attribute type that has non empty
* arrays
* and non-zero tuples. If all attributes have no tuples, then the first attribute with non empty
* arrays is selected. If all attributes have no arrays, then vtkSMEnumerationDomain
* picks the default. For this to work, the domain must be provided an `Input` property as a
* required property for function "Input".
*
* @section DeprecatedUsage Deprecated Usage
*
* Previously (5.6 and earlier), vtkSMFieldDataDomain was added to vtkSMStringVectorProperty
* instances that allowed user to choose the array to process. This is no longer needed
* or supported. Simply remove the vtkSMFieldDataDomain from the XML for such properties.
*
* The domain provided ability to limit the attribute types to the data type of the input dataset.
* This was clumsy since it did not correctly handle cases where data type changes or
* non empty attribute types changed. Hence we've dropped support for that. Simply remove
* `disable_update_domain_entries` and `force_point_cell_data` attributes from the XML
* for this domain since they are no longer supported.
*/
#ifndef vtkSMFieldDataDomain_h
#define vtkSMFieldDataDomain_h
......@@ -52,20 +59,19 @@ class VTKPVSERVERMANAGERCORE_EXPORT vtkSMFieldDataDomain : public vtkSMEnumerati
public:
static vtkSMFieldDataDomain* New();
vtkTypeMacro(vtkSMFieldDataDomain, vtkSMEnumerationDomain);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Check the input and appropriate fields (point data or cell data)
* to the enumeration. This uses the Input property with a
* vtkSMInputArrayDomain.
* Overridden to ensure that the property's default value is valid for the
* enumeration, if not it will be set to the first enumeration value.
*/
void Update(vtkSMProperty* prop) VTK_OVERRIDE;
int SetDefaultValues(vtkSMProperty*, bool use_unchecked_values) override;
/**
* Overridden to ensure that the property's default value is valid for the
* enumeration, if not it will be set to the first enumeration value.
* Convenience method to return the string for an attribute type. Will return nullptr
* for unsupported or invalid type.
*/
int SetDefaultValues(vtkSMProperty*, bool use_unchecked_values) VTK_OVERRIDE;
static const char* GetAttributeTypeAsString(int attrType);
protected:
vtkSMFieldDataDomain();
......@@ -75,31 +81,16 @@ protected:
* Set the appropriate ivars from the xml element. Should
* be overwritten by subclass if adding ivars.
*/
int ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLElement* elem) VTK_OVERRIDE;
int ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLElement* elem) override;
// When true, "Field Data" option is added to the domain.
bool EnableFieldDataSelection;
// When true, we don't update the available list of attributes based on what's
// actually available in the input (false by default).
bool DisableUpdateDomainEntries;
// When true, "Point Data" and "Cell Data" is included to the domain even
// if they don't have any properties. This is used by the spreadsheet
// view.( false by default )
bool ForcePointAndCellDataSelection;
private:
// Used by SetDefaultValues.
int DefaultValue;
/**
* Utility functions called by Update()
*/
void UpdateDomainEntries(int acceptable_association, vtkPVDataInformation* dataInfo);
vtkSMFieldDataDomain(const vtkSMFieldDataDomain&) = delete;
void operator=(const vtkSMFieldDataDomain&) = delete;
int ComputeDefaultValue();
};
#endif
......@@ -3563,8 +3563,7 @@
number_of_elements="1"
panel_visibility="never">
<Documentation>Select the attribute data to pass.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
</FieldDataDomain>
</IntVectorProperty>
......@@ -6756,8 +6755,7 @@
name="AttributeType"
number_of_elements="1">
<Documentation>Select the attribute data to render.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
<RequiredProperties>
<Property function="Input" name="Input" />
......@@ -7196,8 +7194,7 @@
name="FieldAssociation"
number_of_elements="1">
<Documentation>Select the attribute data to pass.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
<RequiredProperties>
<Property function="Input"
......@@ -7365,8 +7362,7 @@
name="FieldAssociation"
number_of_elements="1">
<Documentation>Select the attribute data to pass.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
<RequiredProperties>
<Property function="Input"
......@@ -7555,8 +7551,7 @@
name="FieldAssociation"
number_of_elements="1">
<Documentation>Select the attribute data to pass.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
<RequiredProperties>
<Property function="Input"
......@@ -8029,8 +8024,7 @@
name="AttributeType"
number_of_elements="1">
<Documentation>Select the attribute data to render.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
<RequiredProperties>
<Property function="Input" name="Input" />
......@@ -8327,8 +8321,7 @@
name="AttributeType"
number_of_elements="1">
<Documentation>Select the attribute data to render.</Documentation>
<FieldDataDomain disable_update_domain_entries="1"
enable_field_data="1"
<FieldDataDomain enable_field_data="1"
name="enum">
<RequiredProperties>
<Property function="Input" name="Input" />
......
......@@ -4,6 +4,26 @@ Major API Changes {#MajorAPIChanges}
This page documents major API/design changes between different versions since we
started tracking these (starting after version 4.2).
Changes in 5.7
--------------
###vtkSMFieldDataDomain in array selection properties###
Previously, `vtkSMFieldDataDomain` was added to `vtkSMStringVectorProperty`
instances that allowed user to choose the array to process. This is no longer needed
or supported. Simply remove the `vtkSMFieldDataDomain` from the XML for such properties.
Typically such properties have `vtkSMArrayListDomain` and that domain alone is
sufficient to enable selection of array name and its association.
###Changes to vtkSMFieldDataDomain###
vtkSMFieldDataDomain no longer updates the domain based on the type of the
input. The domain will always list the attribute types known to VTK/ParaView. As
a result, XML attributes `force_point_cell_data` and
`disable_update_domain_entries` for the XML definition of vtkSMFieldDataDomain
have been deprecated and should simply be removed from the XML as they are no
longer relevant.
Changes in 5.6
--------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment