Commit e438006c authored by Michael Migliore's avatar Michael Migliore Committed by Kitware Robot
Browse files

Merge topic 'sel-optim'

98dd5879

 Optimize selection creation
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Acked-by: Utkarsh Ayachit's avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !4476
parents 51382dad 98dd5879
Pipeline #197574 failed with stages
in 180 minutes and 33 seconds
......@@ -191,6 +191,18 @@ int vtkSMDoubleVectorProperty::SetUncheckedElements(const double* values, unsign
return this->Internals->SetUncheckedElements(values, numValues);
}
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::AppendElements(const double* values, unsigned int num)
{
return this->Internals->AppendElements(values, num);
}
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::AppendUncheckedElements(const double* values, unsigned int num)
{
return this->Internals->AppendUncheckedElements(values, num);
}
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::ReadXMLAttributes(vtkSMProxy* proxy, vtkPVXMLElement* element)
{
......
......@@ -108,6 +108,16 @@ public:
*/
int SetElements4(double value0, double value1, double value2, double value3);
/**
* Append the values. The vector is resized as necessary.
*/
int AppendElements(const double* values, unsigned int numValues);
/**
* Append the values to the unchecked elements. The vector is resized as necessary.
*/
int AppendUncheckedElements(const double* values, unsigned int numValues);
/**
* Returns the value of 1 element.
*/
......
......@@ -162,6 +162,18 @@ int vtkSMIdTypeVectorProperty::SetElements(const vtkIdType* values, unsigned int
return this->Internals->SetElements(values, num);
}
//---------------------------------------------------------------------------
int vtkSMIdTypeVectorProperty::AppendElements(const vtkIdType* values, unsigned int num)
{
return this->Internals->AppendElements(values, num);
}
//---------------------------------------------------------------------------
int vtkSMIdTypeVectorProperty::AppendUncheckedElements(const vtkIdType* values, unsigned int num)
{
return this->Internals->AppendUncheckedElements(values, num);
}
//---------------------------------------------------------------------------
int vtkSMIdTypeVectorProperty::SetUncheckedElements(const vtkIdType* values)
{
......
......@@ -99,6 +99,16 @@ public:
*/
int SetElements3(vtkIdType value0, vtkIdType value1, vtkIdType value2);
/**
* Append the values. The vector is resized as necessary.
*/
int AppendElements(const vtkIdType* values, unsigned int numValues);
/**
* Append the values to the unchecked elements. The vector is resized as necessary.
*/
int AppendUncheckedElements(const vtkIdType* values, unsigned int numValues);
/**
* Returns the value of 1 element.
*/
......
......@@ -184,6 +184,18 @@ int vtkSMIntVectorProperty::SetElements(const int* values, unsigned int numElems
return this->Internals->SetElements(values, numElems);
}
//---------------------------------------------------------------------------
int vtkSMIntVectorProperty::AppendElements(const int* values, unsigned int num)
{
return this->Internals->AppendElements(values, num);
}
//---------------------------------------------------------------------------
int vtkSMIntVectorProperty::AppendUncheckedElements(const int* values, unsigned int num)
{
return this->Internals->AppendUncheckedElements(values, num);
}
//---------------------------------------------------------------------------
int* vtkSMIntVectorProperty::GetUnCheckedElements()
{
......
......@@ -101,6 +101,16 @@ public:
*/
int SetElements3(int value0, int value1, int value2);
/**
* Append the values. The vector is resized as necessary.
*/
int AppendElements(const int* values, unsigned int numValues);
/**
* Append the values to the unchecked elements. The vector is resized as necessary.
*/
int AppendUncheckedElements(const int* values, unsigned int numValues);
/**
* Returns the value of 1 element.
*/
......
......@@ -493,6 +493,77 @@ inline void vtkSMPropertyHelper::SetPropertyArray(const vtkIdType* values, unsig
}
#endif
//----------------------------------------------------------------------------
template <typename T>
inline void vtkSMPropertyHelper::AppendPropertyArray(const T* values, unsigned int count)
{
(void)values;
(void)count;
}
//----------------------------------------------------------------------------
template <>
inline void vtkSMPropertyHelper::AppendPropertyArray(const int* values, unsigned int count)
{
if (this->Type == INT)
{
if (this->UseUnchecked)
{
this->IntVectorProperty->AppendUncheckedElements(values, count);
}
else
{
this->IntVectorProperty->AppendElements(values, count);
}
}
else
{
vtkSMPropertyHelperWarningMacro("Call not supported for the current property type.");
}
}
//----------------------------------------------------------------------------
template <>
inline void vtkSMPropertyHelper::AppendPropertyArray(const double* values, unsigned int count)
{
if (this->Type == DOUBLE)
{
if (this->UseUnchecked)
{
this->DoubleVectorProperty->AppendUncheckedElements(values, count);
}
else
{
this->DoubleVectorProperty->AppendElements(values, count);
}
}
else
{
vtkSMPropertyHelperWarningMacro("Call not supported for the current property type.");
}
}
//----------------------------------------------------------------------------
template <>
inline void vtkSMPropertyHelper::AppendPropertyArray(const vtkIdType* values, unsigned int count)
{
if (this->Type == IDTYPE)
{
if (this->UseUnchecked)
{
this->IdTypeVectorProperty->AppendUncheckedElements(values, count);
}
else
{
this->IdTypeVectorProperty->AppendElements(values, count);
}
}
else
{
vtkSMPropertyHelperWarningMacro("Call not supported for the current property type.");
}
}
//----------------------------------------------------------------------------
vtkSMPropertyHelper::vtkSMPropertyHelper(vtkSMProxy* proxy, const char* pname, bool quiet)
{
......@@ -677,12 +748,24 @@ void vtkSMPropertyHelper::Set(const int* values, unsigned int count)
this->SetPropertyArray<int>(values, count);
}
//----------------------------------------------------------------------------
void vtkSMPropertyHelper::Append(const int* values, unsigned int count)
{
this->AppendPropertyArray(values, count);
}
//----------------------------------------------------------------------------
void vtkSMPropertyHelper::Set(unsigned int index, double value)
{
this->SetProperty<double>(index, value);
}
//----------------------------------------------------------------------------
void vtkSMPropertyHelper::Append(const double* values, unsigned int count)
{
this->AppendPropertyArray(values, count);
}
//----------------------------------------------------------------------------
double vtkSMPropertyHelper::GetAsDouble(unsigned int index /*=0*/) const
{
......@@ -720,6 +803,12 @@ void vtkSMPropertyHelper::Set(const vtkIdType* values, unsigned int count)
this->SetPropertyArray<vtkIdType>(values, count);
}
//----------------------------------------------------------------------------
void vtkSMPropertyHelper::Append(const vtkIdType* values, unsigned int count)
{
this->AppendPropertyArray(values, count);
}
//----------------------------------------------------------------------------
unsigned int vtkSMPropertyHelper::Get(vtkIdType* values, unsigned int count /*=1*/) const
{
......
......@@ -150,6 +150,7 @@ public:
void Set(int value) { this->Set(0, value); }
void Set(unsigned int index, int value);
void Set(const int* values, unsigned int count);
void Append(const int* values, unsigned int count);
int GetAsInt(unsigned int index = 0) const;
unsigned int Get(int* values, unsigned int count = 1) const;
std::vector<int> GetIntArray() const;
......@@ -163,6 +164,7 @@ public:
void Set(double value) { this->Set(0, value); }
void Set(unsigned int index, double value);
void Set(const double* values, unsigned int count);
void Append(const double* values, unsigned int count);
double GetAsDouble(unsigned int index = 0) const;
unsigned int Get(double* values, unsigned int count = 1) const;
std::vector<double> GetDoubleArray() const;
......@@ -177,6 +179,7 @@ public:
void Set(vtkIdType value) { this->Set(0, value); }
void Set(unsigned int index, vtkIdType value);
void Set(const vtkIdType* values, unsigned int count);
void Append(const vtkIdType* values, unsigned int count);
unsigned int Get(vtkIdType* values, unsigned int count = 1) const;
#endif
vtkIdType GetAsIdType(unsigned int index = 0) const;
......@@ -311,6 +314,8 @@ private:
void SetPropertyArray(const T* values, unsigned int count);
void SetPropertyArrayIdType(const vtkIdType* values, unsigned int count);
template <typename T>
void AppendPropertyArray(const T* values, unsigned int count);
template <typename T>
bool CopyInternal(const vtkSMPropertyHelper& source);
enum PType
......
......@@ -259,6 +259,20 @@ int vtkSMStringVectorProperty::SetElement(unsigned int idx, const char* value)
return this->Internals->SetElement(idx, value);
}
//---------------------------------------------------------------------------
int vtkSMStringVectorProperty::AppendElements(const std::vector<std::string>& newvalue)
{
return this->Internals->AppendElements(
newvalue.data(), static_cast<unsigned int>(newvalue.size()));
}
//---------------------------------------------------------------------------
int vtkSMStringVectorProperty::AppendUncheckedElements(const std::vector<std::string>& newvalue)
{
return this->Internals->AppendUncheckedElements(
newvalue.data(), static_cast<unsigned int>(newvalue.size()));
}
//---------------------------------------------------------------------------
unsigned int vtkSMStringVectorProperty::GetElementIndex(const char* value, int& exists)
{
......
......@@ -84,6 +84,16 @@ public:
int SetUncheckedElements(const std::vector<std::string>& newvalue);
//@}
/**
* Append the values. The vector is resized as necessary.
*/
int AppendElements(const std::vector<std::string>& newvalue);
/**
* Append the values to the unchecked elements. The vector is resized as necessary.
*/
int AppendUncheckedElements(const std::vector<std::string>& newvalue);
/**
* Fills up the vtkStringList instance with the current value.
*/
......
......@@ -296,6 +296,26 @@ public:
return 1;
}
//---------------------------------------------------------------------------
int AppendUncheckedElements(const T* values, unsigned int numValues)
{
this->UncheckedValues.insert(std::end(this->UncheckedValues), values, values + numValues);
this->Property->InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
return 1;
}
//---------------------------------------------------------------------------
int AppendElements(const T* values, unsigned int numValues)
{
this->Values.insert(std::end(this->Values), values, values + numValues);
this->Initialized = true;
this->Property->Modified();
this->ClearUncheckedElements();
return 1;
}
//---------------------------------------------------------------------------
void Copy(vtkSMVectorPropertyTemplate<T>* dsrc)
{
......
......@@ -245,19 +245,19 @@ vtkSMProxy* vtkSMSelectionHelper::NewSelectionSourceFromSelectionInternal(vtkSMS
// remove default values set by the XML if we created a brand new proxy.
ids->SetNumberOfElements(0);
}
unsigned int curValues = ids->GetNumberOfElements();
vtkIdTypeArray* idList = vtkIdTypeArray::SafeDownCast(selection->GetSelectionList());
if (idList)
{
vtkIdType numIDs = idList->GetNumberOfTuples();
if (!use_composite && !use_hierarchical)
{
ids->SetNumberOfElements(curValues + numIDs * 2);
std::vector<vtkIdType> newVals(2 * numIDs);
for (vtkIdType cc = 0; cc < numIDs; cc++)
{
ids->SetElement(curValues + 2 * cc, procID);
ids->SetElement(curValues + 2 * cc + 1, idList->GetValue(cc));
newVals[2 * cc] = procID;
newVals[2 * cc + 1] = idList->GetValue(cc);
}
ids->AppendElements(newVals.data(), static_cast<unsigned int>(newVals.size()));
}
else if (use_composite)
{
......@@ -267,25 +267,28 @@ vtkSMProxy* vtkSMSelectionHelper::NewSelectionSourceFromSelectionInternal(vtkSMS
composite_index = selProperties->Get(vtkSelectionNode::COMPOSITE_INDEX());
}
ids->SetNumberOfElements(curValues + numIDs * 3);
std::vector<vtkIdType> newVals(3 * numIDs);
for (vtkIdType cc = 0; cc < numIDs; cc++)
{
ids->SetElement(curValues + 3 * cc, composite_index);
ids->SetElement(curValues + 3 * cc + 1, procID);
ids->SetElement(curValues + 3 * cc + 2, idList->GetValue(cc));
newVals[3 * cc] = composite_index;
newVals[3 * cc + 1] = procID;
newVals[3 * cc + 2] = idList->GetValue(cc);
}
ids->AppendElements(newVals.data(), static_cast<unsigned int>(newVals.size()));
}
else if (use_hierarchical)
{
vtkIdType level = selProperties->Get(vtkSelectionNode::HIERARCHICAL_LEVEL());
vtkIdType dsIndex = selProperties->Get(vtkSelectionNode::HIERARCHICAL_INDEX());
ids->SetNumberOfElements(curValues + numIDs * 3);
std::vector<vtkIdType> newVals(3 * numIDs);
for (vtkIdType cc = 0; cc < numIDs; cc++)
{
ids->SetElement(curValues + 3 * cc, level);
ids->SetElement(curValues + 3 * cc + 1, dsIndex);
ids->SetElement(curValues + 3 * cc + 2, idList->GetValue(cc));
newVals[3 * cc] = level;
newVals[3 * cc + 1] = dsIndex;
newVals[3 * cc + 2] = idList->GetValue(cc);
}
ids->AppendElements(newVals.data(), static_cast<unsigned int>(newVals.size()));
}
}
}
......
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