Reputation: 32091
After debugging literally since Sunday the same code, I've officially given up and think its time someone else takes a look. I have spent hours and hours and cant image whats wrong with my code. Its a bit long, but its easy to follow, and I would really appreciate any help-you're the only choice I got now.
What I'm trying to do is implement a few functions that collectively do this: Given a quad tree where each leaf represents 1 pixel of an image, prune the tree to remove or combine similar colors. Each tree has a root
node with 4 children, and so on. Each node has x,y,width,height, and element
where width and height represent the block of pixels that represents that area and x,y represent the lower left corner pixel of the node and element is a type pixel. Each non-leaf node stores the average color of all of its children. If the difference in color of a certain non-leaf node myNode
with one of its children leaf nodes is greater than the parameter tol(or tolerance)
, then you cant prune. If there are no such cases, then you prune, meaning you'd remove all of the children of myNode
, and myNode
would then just store the average value of all the nodes it just deleted (which should be just automatic when the average is calculated in the code initially).
So, here's my codeflow:
The problem is that I am not getting the correct output when I run it. It's off bigtime. I'm hoping the error will be easy to spot for the experienced among you.
(Also, the quadtree class is implemented perfectly. Everything else has been tested and works fine, so its something with my average calculator or pruneSize.)
Upvotes: 1
Views: 241
Reputation: 2857
In calculateAvg
, I think you should you call calculateAvg
on the children before calculating your "own" average. Otherwise, it looks to me like the values your reading are either stale or undefined..
Upvotes: 0
Reputation: 11516
I could be wrong here (just skimmed over it and can't verify right now), but as far as I'm aware, to square in C++, you need to explicitly multiply a number with itself. Doing A^2
will calculate A XOR 2
.
Upvotes: 4