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

Method Evaluate

Common/Misc/vtkExprTkFunctionParser.cxx:775–873  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

773
774//------------------------------------------------------------------------------
775bool vtkExprTkFunctionParser::Evaluate()
776{
777 if (this->FunctionMTime.GetMTime() > this->ParseMTime.GetMTime())
778 {
779 this->SizeMode = DetermineSizeMode(this->FunctionWithUsedVariableNames);
780 // compile with mode 0 to identify return type
781 if (this->Parse(ParseMode::DetectReturnType) == 0)
782 {
783 return false;
784 }
785 // perform evaluation to identify the return type
786 this->ExprTkTools->Expression.value();
787 const auto& results = this->ExprTkTools->Expression.results();
788 if (this->SizeMode == SizeModes::AutoDetected)
789 {
790 auto result = results[0];
791 this->ResultType = result.type;
792 if (result.size != 0)
793 {
794 this->ResultSize = static_cast<int>(result.size);
795 }
796 else
797 {
798 // if the parser could not identify the size, set it to 3 for vector and 1 for scalar
799 this->ResultSize = this->ResultType == ExprTkResultType::e_vector ? 3 : 1;
800 }
801 }
802 else // (this->SizeMode == SizeModes::VectorDefined)
803 {
804 this->ResultSize = static_cast<int>(results.count());
805 this->ResultType =
806 this->ResultSize > 1 ? ExprTkResultType::e_vector : ExprTkResultType::e_scalar;
807 // assert that all results have type e_scalar and size 1
808 for (size_t i = 0; i < results.count(); ++i)
809 {
810 if (results[i].type != ExprTkResultType::e_scalar || results[i].size != 1)
811 {
812 vtkErrorMacro("In VectorDefined size mode, all components must be scalars of size 1.");
813 this->ResultType = ExprTkResultType::e_unknown;
814 }
815 }
816 }
817 this->Result.resize(this->ResultSize);
818 this->ParserErrorResult.resize(this->ResultSize, std::numeric_limits<double>::quiet_NaN());
819
820 // compile with mode 1 to save results in the result array
821 if (this->Parse(ParseMode::SaveResultInVariable) == 0)
822 {
823 return false;
824 }
825 }
826 // perform evaluation
827 this->ExprTkTools->Expression.value();
828 // check for invalid results
829 if (this->ResultType == ExprTkResultType::e_unknown)
830 {
831 return false;
832 }

Callers 2

IsScalarResultMethod · 0.95
IsVectorResultMethod · 0.95

Calls 7

ParseMethod · 0.95
isinfFunction · 0.85
isnanFunction · 0.50
GetMTimeMethod · 0.45
valueMethod · 0.45
countMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected