[Paraview] Possible bug in vtkFunctionParser?

OSHIMA Takuya oshima at eng.niigata-u.ac.jp
Thu Mar 27 09:41:44 EDT 2008


Hi,

Sorry to bother you again, but does anyone have a comment?
This time I had a look through the bug tracker but could not find the issue.

Takuya

From: OSHIMA Takuya <oshima at eng.niigata-u.ac.jp>
Date: Sat, 22 Mar 2008 14:41:17 +0900

Hi,

I have a dataset which contains an array with the name say "A/B,"
which in turn contains a character that may be interpreted as a
mathematical operator '/'. If I try to run Filter->Calculator and to
evaluate an expression "A/B + A/B" over the dataset, I can't get the
expected result (an array with all components doubled).

I'm not sure this should be called as a bug since the array name is
itself confusing, but anyway what I found out was that finding the
first occurrence of the array name within the given expression is not
enough in vtkFunctionParser::OperatorWithinVariable(). I think at
least the array name should be searched until the location of idx even
if there was an occurrence prior to the location.

Here I attach a patch that worked for me. I know this is far from
perfect as a fix (there are still many possible cases that can't be
properly detected). Please take it just as a clarification of a
solution that worked for me.

Regards,
Takuya

--- vtkFunctionParser.cxx.orig	2007-12-22 03:55:56.000000000 +0900
+++ vtkFunctionParser.cxx	2008-03-22 12:26:51.320000000 +0900
@@ -1342,14 +1342,21 @@
     {
     if (strchr(this->ScalarVariableNames[i], this->Function[idx]) != 0)
       {
-      tmpString = strstr(this->Function, this->ScalarVariableNames[i]);
-      if (tmpString)
+      for(end = 0; end <= idx;)
         {
-        start = static_cast<int>(tmpString - this->Function);
-        end = start + strlen(this->ScalarVariableNames[i]);
-        if (start <= idx && end >= idx)
+        tmpString = strstr(this->Function + end, this->ScalarVariableNames[i]);
+        if (tmpString)
           {
-          return 1;
+          start = static_cast<int>(tmpString - this->Function);
+          end = start + strlen(this->ScalarVariableNames[i]);
+          if (start <= idx && end > idx)
+            {
+            return 1;
+            }
+          }
+        else
+          {
+          break;
           }
         }
       }
@@ -1358,14 +1365,21 @@
     {
     if (strchr(this->VectorVariableNames[i], this->Function[idx]) != 0)
       {
-      tmpString = strstr(this->Function, this->VectorVariableNames[i]);
-      if (tmpString)
+      for(end = 0; end <= idx;)
         {
-        start = static_cast<int>(tmpString - this->Function);
-        end = start + strlen(this->VectorVariableNames[i]);
-        if (start <= idx && end >= idx)
+        tmpString = strstr(this->Function + end, this->VectorVariableNames[i]);
+        if (tmpString)
+          {
+          start = static_cast<int>(tmpString - this->Function);
+          end = start + strlen(this->VectorVariableNames[i]);
+          if (start <= idx && end > idx)
+            {
+            return 1;
+            }
+          }
+        else
           {
-          return 1;
+          break;
           }
         }
       }


More information about the ParaView mailing list