StelGeodesicGrid.cpp   StelGeodesicGrid.cpp 
skipping to change at line 274 skipping to change at line 274
if (lev <= maxVisitLevel) if (lev <= maxVisitLevel)
{ {
index *= 4; index *= 4;
visitTriangles(lev,index+0,c0,t.e2,t.e1,maxVisitLevel,func,c ontext); visitTriangles(lev,index+0,c0,t.e2,t.e1,maxVisitLevel,func,c ontext);
visitTriangles(lev,index+1,t.e2,c1,t.e0,maxVisitLevel,func,c ontext); visitTriangles(lev,index+1,t.e2,c1,t.e0,maxVisitLevel,func,c ontext);
visitTriangles(lev,index+2,t.e1,t.e0,c2,maxVisitLevel,func,c ontext); visitTriangles(lev,index+2,t.e1,t.e0,c2,maxVisitLevel,func,c ontext);
visitTriangles(lev,index+3,t.e0,t.e1,t.e2,maxVisitLevel,func ,context); visitTriangles(lev,index+3,t.e0,t.e1,t.e2,maxVisitLevel,func ,context);
} }
} }
int StelGeodesicGrid::searchZone(const Vec3d &v,int searchLevel) const int StelGeodesicGrid::getZoneNumberForPoint(const Vec3d &v,int searchLevel) const
{ {
for (int i=0;i<20;i++) for (int i=0;i<20;i++)
{ {
const int *const corners = icosahedron_triangles[i].corners; const int *const corners = icosahedron_triangles[i].corners;
const Vec3d &c0(icosahedron_corners[corners[0]]); const Vec3d &c0(icosahedron_corners[corners[0]]);
const Vec3d &c1(icosahedron_corners[corners[1]]); const Vec3d &c1(icosahedron_corners[corners[1]]);
const Vec3d &c2(icosahedron_corners[corners[2]]); const Vec3d &c2(icosahedron_corners[corners[2]]);
if (((c0^c1)*v >= 0.0) && ((c1^c2)*v >= 0.0) && ((c2^c0)*v > = 0.0)) if (((c0^c1)*v >= 0.0) && ((c1^c2)*v >= 0.0) && ((c2^c0)*v > = 0.0))
{ {
// v lies inside this icosahedron triangle // v lies inside this icosahedron triangle
skipping to change at line 315 skipping to change at line 315
} }
return i; return i;
} }
} }
qWarning() << "ERROR StelGeodesicGrid::searchZone - not found"; qWarning() << "ERROR StelGeodesicGrid::searchZone - not found";
exit(-1); exit(-1);
// shut up the compiler // shut up the compiler
return -1; return -1;
} }
void StelGeodesicGrid::searchZones(const StelGeom::ConvexS& convex, // First iteration on the icosahedron base triangles
void StelGeodesicGrid::searchZones(const QVector<SphericalCap>& convex,
int **inside_list,int **border_list, int **inside_list,int **border_list,
int maxSearchLevel) const int maxSearchLevel) const
{ {
if (maxSearchLevel < 0) maxSearchLevel = 0; if (maxSearchLevel < 0) maxSearchLevel = 0;
else if (maxSearchLevel > maxLevel) maxSearchLevel = maxLevel; else if (maxSearchLevel > maxLevel) maxSearchLevel = maxLevel;
#if defined __STRICT_ANSI__ || !defined __GNUC__ #if defined __STRICT_ANSI__ || !defined __GNUC__
int *halfs_used = new int[convex.size()]; int *halfs_used = new int[convex.size()];
#else #else
int halfs_used[convex.size()]; int halfs_used[convex.size()];
#endif #endif
for (int h=0;h<(int)convex.size();h++) {halfs_used[h] = h;} for (int h=0;h<(int)convex.size();h++) {halfs_used[h] = h;}
#if defined __STRICT_ANSI__ || !defined __GNUC__ #if defined __STRICT_ANSI__ || !defined __GNUC__
bool *corner_inside[12]; bool *corner_inside[12];
for(int ci=0; ci < 12; ci++) corner_inside[ci]= new bool[convex.size ()]; for(int ci=0; ci < 12; ci++) corner_inside[ci]= new bool[convex.size ()];
#else #else
bool corner_inside[12][convex.size()]; bool corner_inside[12][convex.size()];
#endif #endif
for (size_t h=0;h<convex.size();h++) for (int h=0;h<convex.size();h++)
{ {
const StelGeom::HalfSpace &half_space(convex[h]); const SphericalCap& half_space(convex.at(h));
for (int i=0;i<12;i++) for (int i=0;i<12;i++)
{ {
corner_inside[i][h] = half_space.contains(icosahedro n_corners[i]); corner_inside[i][h] = half_space.contains(icosahedro n_corners[i]);
} }
} }
for (int i=0;i<20;i++) for (int i=0;i<20;i++)
{ {
searchZones(0,i, searchZones(0,i,
convex,halfs_used,convex.size(), convex,halfs_used,convex.size(),
corner_inside[icosahedron_triangles[i].corners[0 ]], corner_inside[icosahedron_triangles[i].corners[0 ]],
skipping to change at line 357 skipping to change at line 358
corner_inside[icosahedron_triangles[i].corners[2 ]], corner_inside[icosahedron_triangles[i].corners[2 ]],
inside_list,border_list,maxSearchLevel); inside_list,border_list,maxSearchLevel);
} }
#if defined __STRICT_ANSI__ || !defined __GNUC__ #if defined __STRICT_ANSI__ || !defined __GNUC__
delete[] halfs_used; delete[] halfs_used;
for(int ci=0; ci < 12; ci++) delete[] corner_inside[ci]; for(int ci=0; ci < 12; ci++) delete[] corner_inside[ci];
#endif #endif
} }
void StelGeodesicGrid::searchZones(int lev,int index, void StelGeodesicGrid::searchZones(int lev,int index,
const StelGeom::ConvexS& convex, const QVe
const int *indexOfUsedHalfSpaces, ctor<SphericalCap>&convex,
const int *indexOfUsedSphericalCaps,
const int halfSpacesUsed, const int halfSpacesUsed,
const bool *corner0_inside, const bool *corner0_inside,
const bool *corner1_inside, const bool *corner1_inside,
const bool *corner2_inside, const bool *corner2_inside,
int **inside_list,int **border_list, int **inside_list,int **border_list,
const int maxSearchLevel) const const int maxSearchLevel) const
{ {
#if defined __STRICT_ANSI__ || !defined __GNUC__ #if defined __STRICT_ANSI__ || !defined __GNUC__
int *halfs_used = new int[halfSpacesUsed]; int *halfs_used = new int[halfSpacesUsed];
#else #else
int halfs_used[halfSpacesUsed]; int halfs_used[halfSpacesUsed];
#endif #endif
int halfs_used_count = 0; int halfs_used_count = 0;
for (int h=0;h<halfSpacesUsed;h++) for (int h=0;h<halfSpacesUsed;h++)
{ {
const int i = indexOfUsedHalfSpaces[h]; const int i = indexOfUsedSphericalCaps[h];
if (!corner0_inside[i] && !corner1_inside[i] && !corner2_ins ide[i]) if (!corner0_inside[i] && !corner1_inside[i] && !corner2_ins ide[i])
{ {
// totally outside this HalfSpace // totally outside this SphericalCap
return; return;
} }
else if (corner0_inside[i] && corner1_inside[i] && corner2_i nside[i]) else if (corner0_inside[i] && corner1_inside[i] && corner2_i nside[i])
{ {
// totally inside this HalfSpace // totally inside this SphericalCap
} }
else else
{ {
// on the border of this HalfSpace // on the border of this SphericalCap
halfs_used[halfs_used_count++] = i; halfs_used[halfs_used_count++] = i;
} }
} }
if (halfs_used_count == 0) if (halfs_used_count == 0)
{ {
// this triangle(lev,index) lies inside all halfspaces // this triangle(lev,index) lies inside all halfspaces
**inside_list = index; **inside_list = index;
(*inside_list)++; (*inside_list)++;
} }
else else
{ {
(*border_list)--; (*border_list)--;
**border_list = index; **border_list = index;
if (lev < maxSearchLevel) if (lev < maxSearchLevel)
{ {
Triangle &t(triangles[lev][index]); const Triangle &t(triangles[lev][index]);
lev++; lev++;
index <<= 2; index <<= 2;
inside_list++; inside_list++;
border_list++; border_list++;
#if defined __STRICT_ANSI__ || !defined __GNUC__ #if defined __STRICT_ANSI__ || !defined __GNUC__
bool *edge0_inside = new bool[convex.size()]; bool *edge0_inside = new bool[convex.size()];
bool *edge1_inside = new bool[convex.size()]; bool *edge1_inside = new bool[convex.size()];
bool *edge2_inside = new bool[convex.size()]; bool *edge2_inside = new bool[convex.size()];
#else #else
bool edge0_inside[convex.size()]; bool edge0_inside[convex.size()];
bool edge1_inside[convex.size()]; bool edge1_inside[convex.size()];
bool edge2_inside[convex.size()]; bool edge2_inside[convex.size()];
#endif #endif
for (int h=0;h<halfs_used_count;h++) for (int h=0;h<halfs_used_count;h++)
{ {
const int i = halfs_used[h]; const int i = halfs_used[h];
const StelGeom::HalfSpace &half_space(convex [i]); const SphericalCap& half_space(convex.at(i)) ;
edge0_inside[i] = half_space.contains(t.e0); edge0_inside[i] = half_space.contains(t.e0);
edge1_inside[i] = half_space.contains(t.e1); edge1_inside[i] = half_space.contains(t.e1);
edge2_inside[i] = half_space.contains(t.e2); edge2_inside[i] = half_space.contains(t.e2);
} }
searchZones(lev,index+0, searchZones(lev,index+0,
convex,halfs_used,halfs_used_count, convex,halfs_used,halfs_used_count,
corner0_inside,edge2_inside,edge1_inside , corner0_inside,edge2_inside,edge1_inside ,
inside_list,border_list,maxSearchLevel); inside_list,border_list,maxSearchLevel);
searchZones(lev,index+1, searchZones(lev,index+1,
convex,halfs_used,halfs_used_count, convex,halfs_used,halfs_used_count,
skipping to change at line 455 skipping to change at line 456
} }
} }
#if defined __STRICT_ANSI__ || !defined __GNUC__ #if defined __STRICT_ANSI__ || !defined __GNUC__
delete[] halfs_used; delete[] halfs_used;
#endif #endif
} }
/************************************************************************* /*************************************************************************
Return a search result matching the given spatial region Return a search result matching the given spatial region
*************************************************************************/ *************************************************************************/
const GeodesicSearchResult* StelGeodesicGrid::search(const StelGeom::Convex S& convex, int maxSearchLevel) const const GeodesicSearchResult* StelGeodesicGrid::search(const QVector<Spherica lCap>& convex, int maxSearchLevel) const
{ {
// Try to use the cached version // Try to use the cached version
if (maxSearchLevel==lastMaxSearchlevel && convex==lastSearchRegion) if (maxSearchLevel==lastMaxSearchlevel && convex==lastSearchRegion)
{ {
return cacheSearchResult; return cacheSearchResult;
} }
// Else recompute it and update cache parameters // Else recompute it and update cache parameters
lastMaxSearchlevel = maxSearchLevel; lastMaxSearchlevel = maxSearchLevel;
lastSearchRegion = convex; lastSearchRegion = convex;
cacheSearchResult->search(convex, maxSearchLevel); cacheSearchResult->search(convex, maxSearchLevel);
return cacheSearchResult; return cacheSearchResult;
} }
/*************************************************************************
Return a search result matching the given spatial region
*************************************************************************/
const GeodesicSearchResult* StelGeodesicGrid::search(const Vec3d &e0,const
Vec3d &e1,const Vec3d &e2,const Vec3d &e3,int maxSearchLevel) const
{
StelGeom::ConvexS c(e0, e1, e2, e3);
return search(c,maxSearchLevel);
}
GeodesicSearchResult::GeodesicSearchResult(const StelGeodesicGrid &grid) GeodesicSearchResult::GeodesicSearchResult(const StelGeodesicGrid &grid)
:grid(grid), :grid(grid),
zones(new int*[grid.getMaxLevel()+1]), zones(new int*[grid.getMaxLevel()+1]),
inside(new int*[grid.getMaxLevel()+1]), inside(new int*[grid.getMaxLevel()+1]),
border(new int*[grid.getMaxLevel()+1]) border(new int*[grid.getMaxLevel()+1])
{ {
for (int i=0;i<=grid.getMaxLevel();i++) for (int i=0;i<=grid.getMaxLevel();i++)
{ {
zones[i] = new int[StelGeodesicGrid::nrOfZones(i)]; zones[i] = new int[StelGeodesicGrid::nrOfZones(i)];
} }
skipping to change at line 501 skipping to change at line 493
{ {
for (int i=grid.getMaxLevel();i>=0;i--) for (int i=grid.getMaxLevel();i>=0;i--)
{ {
delete[] zones[i]; delete[] zones[i];
} }
delete[] border; delete[] border;
delete[] inside; delete[] inside;
delete[] zones; delete[] zones;
} }
void GeodesicSearchResult::search(const StelGeom::ConvexS& convex, void GeodesicSearchResult::search(const QVector<SphericalCap>& convex, int
int maxSearchLevel) maxSearchLevel)
{ {
for (int i=grid.getMaxLevel();i>=0;i--) for (int i=grid.getMaxLevel();i>=0;i--)
{ {
inside[i] = zones[i]; inside[i] = zones[i];
border[i] = zones[i]+StelGeodesicGrid::nrOfZones(i); border[i] = zones[i]+StelGeodesicGrid::nrOfZones(i);
} }
grid.searchZones(convex,inside,border,maxSearchLevel); grid.searchZones(convex,inside,border,maxSearchLevel);
} }
void GeodesicSearchInsideIterator::reset(void) void GeodesicSearchInsideIterator::reset(void)
 End of changes. 14 change blocks. 
25 lines changed or deleted 17 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/