MCPcopy Create free account
hub / github.com/Kitware/VTK / UpdateSearchMethod

Method UpdateSearchMethod

Common/DataModel/vtkPiecewiseFunction.cxx:1037–1082  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1035
1036//------------------------------------------------------------------------------
1037void vtkPiecewiseFunction::UpdateSearchMethod(double epsilon, double thresh)
1038{
1039 double averageDiff = 0;
1040 double stdDiff = 0;
1041 double currDiff = 0;
1042 const size_t nodeCount = this->Internal->Nodes.size();
1043
1044 if (nodeCount < 3)
1045 {
1046 this->Internal->AutomaticSearchMethod = BINARY_SEARCH;
1047 return;
1048 }
1049
1050 // compute the mean of the sampling rate
1051 averageDiff = (this->Internal->Nodes[nodeCount - 1]->X - this->Internal->Nodes[0]->X) /
1052 static_cast<double>(nodeCount);
1053
1054 // It should not happens since the piecewise function
1055 // can't have multiple node at the same X
1056 if (std::abs(averageDiff) < epsilon)
1057 {
1058 this->Internal->AutomaticSearchMethod = BINARY_SEARCH;
1059 return;
1060 }
1061
1062 // compute the standard deviation of the sampling rate
1063 for (size_t k = 0; k < this->Internal->Nodes.size() - 1; ++k)
1064 {
1065 currDiff = this->Internal->Nodes[k + 1]->X - this->Internal->Nodes[k]->X;
1066 stdDiff += std::pow(currDiff - averageDiff, 2);
1067 }
1068
1069 stdDiff /= std::max(static_cast<double>(this->Internal->Nodes.size() - 1), 1.0);
1070 stdDiff = std::sqrt(stdDiff);
1071
1072 double C = std::abs(stdDiff / averageDiff);
1073
1074 if (C < thresh)
1075 {
1076 this->Internal->AutomaticSearchMethod = INTERPOLATION_SEARCH;
1077 }
1078 else
1079 {
1080 this->Internal->AutomaticSearchMethod = BINARY_SEARCH;
1081 }
1082}
1083
1084//------------------------------------------------------------------------------
1085int vtkPiecewiseFunction::GetAutomaticSearchMethod()

Callers 2

SortAndUpdateRangeMethod · 0.95

Calls 5

absFunction · 0.50
powFunction · 0.50
maxFunction · 0.50
sqrtFunction · 0.50
sizeMethod · 0.45

Tested by 1