Shree
10-28-2007, 02:46 PM
I have a templated class (IsosurfaceOctreeVolume) which contains a pointer to another templated class (OctreeVolume), The start of the class definition is shown below:
template <class T>
class IsosurfaceOctreeVolume : public PrimitiveCommon
{
const OctreeVolume<T>* octdata;
For the 4 function calls made using this pointer below I get the following gcc compiler error "error: ISO C++ forbids comp arison between pointer and integer":
octdata->lookup_neighbor<0,0,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<0,1,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<1,0,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<1,1,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
However, these 3 calls also using exactly the same pointer do not generate an error:
octdata->lookup_neighbor<1,1,0>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<1,0,0>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<0,1,0>(child_cell, offset, stop_depth, leaf_depth, index_trace);
Looking at the above 7 calls there seems to be a problem when the 3rd (last) template argument being passed to OctreeVolume::lookup_neighbor has the value 1 instead of 0.
The complete code for function lookup_neighbor (which is a member function of the templated class OctreeVolume) is listed below:
template <typename T>
template<bool CHECK_X, bool CHECK_Y, bool CHECK_Z>
inline T OctreeVolume<T>::lookup_neighbor(Vec3i& cell, Vec3i& offset, int stop_depth, int depth, unsigned int* index_trace) const
{
Vec3i target_neighbor = cell + offset;
int child_bit;
//recurse up the tree until we find a parent that contains both cell and target_neighbor
for(int up = depth; up >= 0; up--)
{
child_bit = child_bit_depth[up];
if (CHECK_X && CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_X && CHECK_Y)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_X && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_X)
{
if ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit))
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_Y)
{
if ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit))
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_Z)
{
if ((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit))
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
}
child_bit = max_depth_bit;
if (CHECK_X && CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_X && CHECK_Y)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_X && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_X)
{
if ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit))
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_Y)
{
if ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit))
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_Z)
{
if ((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit))
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
return 0;
}
If I explicitly specify the type of the OctreeVolume (as shown below) then the error disappears:
namespace Manta
{
template <class T>
class IsosurfaceOctreeVolume : public PrimitiveCommon
{
const OctreeVolume<float>* octdata;
So declaring the pointer to be of type OctreeVolume<T> instead of OctreeVolume<float> or some other explicit type is somehow causing the above error. However, strangely it only affects 4 out of the 7 possible function calls.
Does anyone have any idea why this is happening and what the problem is?:wallbash:
template <class T>
class IsosurfaceOctreeVolume : public PrimitiveCommon
{
const OctreeVolume<T>* octdata;
For the 4 function calls made using this pointer below I get the following gcc compiler error "error: ISO C++ forbids comp arison between pointer and integer":
octdata->lookup_neighbor<0,0,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<0,1,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<1,0,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<1,1,1>(child_cell, offset, stop_depth, leaf_depth, index_trace);
However, these 3 calls also using exactly the same pointer do not generate an error:
octdata->lookup_neighbor<1,1,0>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<1,0,0>(child_cell, offset, stop_depth, leaf_depth, index_trace);
octdata->lookup_neighbor<0,1,0>(child_cell, offset, stop_depth, leaf_depth, index_trace);
Looking at the above 7 calls there seems to be a problem when the 3rd (last) template argument being passed to OctreeVolume::lookup_neighbor has the value 1 instead of 0.
The complete code for function lookup_neighbor (which is a member function of the templated class OctreeVolume) is listed below:
template <typename T>
template<bool CHECK_X, bool CHECK_Y, bool CHECK_Z>
inline T OctreeVolume<T>::lookup_neighbor(Vec3i& cell, Vec3i& offset, int stop_depth, int depth, unsigned int* index_trace) const
{
Vec3i target_neighbor = cell + offset;
int child_bit;
//recurse up the tree until we find a parent that contains both cell and target_neighbor
for(int up = depth; up >= 0; up--)
{
child_bit = child_bit_depth[up];
if (CHECK_X && CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_X && CHECK_Y)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_X && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_X)
{
if ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit))
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_Y)
{
if ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit))
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
else if (CHECK_Z)
{
if ((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit))
return lookup_node(target_neighbor, stop_depth, up, index_trace[up]);
}
}
child_bit = max_depth_bit;
if (CHECK_X && CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_X && CHECK_Y)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_X && CHECK_Z)
{
if ( ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_Y && CHECK_Z)
{
if ( ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit)) &&
((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit)) )
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_X)
{
if ((target_neighbor.data[0] & child_bit) == (cell.data[0] & child_bit))
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_Y)
{
if ((target_neighbor.data[1] & child_bit) == (cell.data[1] & child_bit))
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
else if (CHECK_Z)
{
if ((target_neighbor.data[2] & child_bit) == (cell.data[2] & child_bit))
return lookup_node(target_neighbor, stop_depth, 0, 0);
}
return 0;
}
If I explicitly specify the type of the OctreeVolume (as shown below) then the error disappears:
namespace Manta
{
template <class T>
class IsosurfaceOctreeVolume : public PrimitiveCommon
{
const OctreeVolume<float>* octdata;
So declaring the pointer to be of type OctreeVolume<T> instead of OctreeVolume<float> or some other explicit type is somehow causing the above error. However, strangely it only affects 4 out of the 7 possible function calls.
Does anyone have any idea why this is happening and what the problem is?:wallbash: