Code runs without error but doesn't produce expected result

   1954   5   1
User Avatar
Member
39 posts
Joined: 10月 2011
オフライン
You may be interested to know that I passed this code by chatGPT to see if it could detect a problem with it. It pretty accurately summed up the code's purpose this way:

"In summary, the code iterates over a list of barb IDs, finds the points associated with each barb, identifies the smallest point number for each barb, and adds that point to a specific point group."

However, the "stemPoints" group that is generated has zero members and I can't see why, nor does chatGPT (btw, I'm finding that chatGPT seems to reliably produce code that doesn't quite work ). I'm hoping someone here can help me spot the problem.

BTW - the following code is running in a wrangle node set to detail mode. Also, my checks seem to verify that the barbIDsList attribute contains correct values, as does the numberOfPoints variable. And, the "id" attribute" on each point identifies the "barb" - a curve - that it is a member of and yes - that attribute exists and contains correct values.

Oh - and I've attached a houdini scene that demo's the problem.

int numberOfPoints = npoints(0);

//run through one barb at a time
foreach (int barb; barbIdsList){
int barbPointIds = {};
int j = 0;

//get pointNum of all points belonging to current barb
for (int pnt = 0; pnt < numberOfPoints; pnt++) {
if (point(0, "id", pnt) == barb) {
barbPointIds = pnt;
j++;

}
}

//identify smallest point number among the point numbers for the current barb
int smallestPointId = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
foreach (int pnt; barbPointIds) {
if (pnt < smallestPointId) {
smallestPointId = pnt;

}

}

setpointgroup(0,"stemPoints", smallestPointId, 1, "set");

}

Edited by fbb - 2023年5月19日 19:59:12

Attachments:
seekingHelpDemo_gettingBarbRootPoints.hip (154.0 KB)

User Avatar
Member
39 posts
Joined: 10月 2011
オフライン
I found the problem. The very large number I initialized the "smallestPointId" variable with was larger than houdini allows. I had to put it down to 99999999999999999 for it to work.
User Avatar
Member
9452 posts
Joined: 7月 2007
オンライン
fbb
I had to put it down to 99999999999999999
that's still pretty arbitrary and you will find out that the value stored is avtually 1569325055, which is better than your previous number which resulted in -1, but still not the largest possible

so either replace it with maximum 32bit signed integer value (unless you work in 64bit, which would be higher)
int smallestPointId = 2147483647;

or change that part of your code to this so that you dont have to care about initializing it to high number:
    int smallestPointId = 0; // the value here doesnt matter
    foreach (int i; int pnt; barbPointIds) {
        if (i == 0) smallestPointId = pnt;
        smallestPointId = min(smallestPointId, pnt);        
    }
Edited by tamte - 2023年5月19日 20:58:42
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
9452 posts
Joined: 7月 2007
オンライン
that being said, since you are dealing with curves and they most likely have first vertex near the stem you can possibly replace both of your wrangles with a single Point Wrangle
i@group_stemPoints = vertexprimindex(0, @vtxnum) == 0;
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
39 posts
Joined: 10月 2011
オフライン
@tamte - thank you so much for those insights. I can see how the first one would work. I'll try out the second option when I'm back at work.
User Avatar
Member
2173 posts
Joined: 9月 2015
オフライン
Also instead of looping, for less code writting, one could do the following to either get the smallest or largest value of an array:

int List[] = {5,3,8,7,7,2,9,4};
i@Smallest = sort(List)[0];
i@Largest  = reverse(sort(List))[0];

or even simpler:


int List[] = {5,3,8,7,7,2,9,4};
i@Smallest_Simpler = min(List);
i@Largest_Simpler  = max(List);
Edited by BabaJ - 2023年5月21日 12:29:30
  • Quick Links