// possible results = STORED/NOT_STORED, OCCLUDED, DOESNT_FIT CoverageMapStorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, bool storeIt) { if (_isRoot) { _checkMapRootCalls++; } // short circuit: we don't handle polygons that aren't all in view, so, if the polygon in question is // not in view, then we just discard it with a DOESNT_FIT, this saves us time checking values later. if (!polygon->getAllInView()) { return DOESNT_FIT; } BoundingBox polygonBox(polygon->getBoundingBox()); if (_isRoot || _myBoundingBox.contains(polygonBox)) { CoverageMapStorageResult result = NOT_STORED; CoverageRegion* storeIn = &_remainder; bool fitsInAHalf = false; // Check each half of the box independently if (_topHalf.contains(polygonBox)) { result = _topHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_topHalf; fitsInAHalf = true; } else if (_bottomHalf.contains(polygonBox)) { result = _bottomHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_bottomHalf; fitsInAHalf = true; } else if (_leftHalf.contains(polygonBox)) { result = _leftHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_leftHalf; fitsInAHalf = true; } else if (_rightHalf.contains(polygonBox)) { result = _rightHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_rightHalf; fitsInAHalf = true; } // if we got this far, there are one of two possibilities, either a polygon doesn't fit // in one of the halves, or it did fit, but it wasn't occluded by anything only in that // half. In either of these cases, we want to check our remainder region to see if its // occluded by anything there if (!(result == STORED || result == OCCLUDED)) { result = _remainder.checkRegion(polygon, polygonBox, storeIt); } // It's possible that this first set of checks might have resulted in an out of order polygon // in which case we just return.. if (result == STORED || result == OCCLUDED) { return result; } // if we made it here, then it means the polygon being stored is not occluded // at this level of the quad tree, so we can continue to insert it into the map. // First we check to see if it fits in any of our sub maps for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { BoundingBox childMapBoundingBox = getChildBoundingBox(i); if (childMapBoundingBox.contains(polygon->getBoundingBox())) { // if no child map exists yet, then create it if (!_childMaps[i]) { _childMaps[i] = new CoverageMap(childMapBoundingBox, NOT_ROOT, _managePolygons); } return _childMaps[i]->checkMap(polygon, storeIt); } } // if we got this far, then the polygon is in our bounding box, but doesn't fit in // any of our child bounding boxes, so we should add it here. if (storeIt) { if (polygon->getBoundingBox().area() > CoverageMap::MINIMUM_POLYGON_AREA_TO_STORE) { //printLog("storing polygon of area: %f\n",polygon->getBoundingBox().area()); storeIn->storeInArray(polygon); return STORED; } else { return NOT_STORED; } } else { return NOT_STORED; } } return DOESNT_FIT; }
// possible results = STORED/NOT_STORED, OCCLUDED, DOESNT_FIT CoverageMapStorageResult CoverageMap::checkMap(OctreeProjectedPolygon* polygon, bool storeIt) { if (_isRoot) { _checkMapRootCalls++; } // short circuit: we don't handle polygons that aren't all in view, so, if the polygon in question is // not in view, then we just discard it with a DOESNT_FIT, this saves us time checking values later. if (!polygon->getAllInView()) { _notAllInView++; return DOESNT_FIT; } BoundingBox polygonBox(polygon->getBoundingBox()); if (_isRoot || _myBoundingBox.contains(polygonBox)) { CoverageMapStorageResult result = NOT_STORED; CoverageRegion* storeIn = &_remainder; // Check each half of the box independently const bool useRegions = true; // for now we will continue to use regions if (useRegions) { if (_topHalf.contains(polygonBox)) { result = _topHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_topHalf; } else if (_bottomHalf.contains(polygonBox)) { result = _bottomHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_bottomHalf; } else if (_leftHalf.contains(polygonBox)) { result = _leftHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_leftHalf; } else if (_rightHalf.contains(polygonBox)) { result = _rightHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_rightHalf; } } // if we got this far, there are one of two possibilities, either a polygon doesn't fit // in one of the halves, or it did fit, but it wasn't occluded by anything only in that // half. In either of these cases, we want to check our remainder region to see if its // occluded by anything there if (!(result == STORED || result == OCCLUDED)) { result = _remainder.checkRegion(polygon, polygonBox, storeIt); } // It's possible that this first set of checks might have resulted in an out of order polygon // in which case we just return.. if (result == STORED || result == OCCLUDED) { /* if (result == STORED) qDebug("CoverageMap2::checkMap()... STORED\n"); else qDebug("CoverageMap2::checkMap()... OCCLUDED\n"); */ return result; } // if we made it here, then it means the polygon being stored is not occluded // at this level of the quad tree, so we can continue to insert it into the map. // First we check to see if it fits in any of our sub maps const bool useChildMaps = true; // for now we will continue to use child maps if (useChildMaps) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { BoundingBox childMapBoundingBox = getChildBoundingBox(i); if (childMapBoundingBox.contains(polygon->getBoundingBox())) { // if no child map exists yet, then create it if (!_childMaps[i]) { _childMaps[i] = new CoverageMap(childMapBoundingBox, NOT_ROOT, _managePolygons); } result = _childMaps[i]->checkMap(polygon, storeIt); /* switch (result) { case STORED: qDebug("checkMap() = STORED\n"); break; case NOT_STORED: qDebug("checkMap() = NOT_STORED\n"); break; case OCCLUDED: qDebug("checkMap() = OCCLUDED\n"); break; default: qDebug("checkMap() = ????? \n"); break; } */ return result; } } } // if we got this far, then the polygon is in our bounding box, but doesn't fit in // any of our child bounding boxes, so we should add it here. if (storeIt) { if (polygon->getBoundingBox().area() > CoverageMap::MINIMUM_POLYGON_AREA_TO_STORE) { if (storeIn->getPolygonCount() < MAX_POLYGONS_PER_REGION) { storeIn->storeInArray(polygon); return STORED; } else { CoverageRegion::_regionFullSkips++; return NOT_STORED; } } else { CoverageRegion::_tooSmallSkips++; return NOT_STORED; } } else { return NOT_STORED; } } return DOESNT_FIT; }