GridDiscretization(const Workspace &workspace, const Agent &agent, const std::vector<double> &discretizationSizes) :
		discretizationSizes(discretizationSizes.begin(), discretizationSizes.end()) {
		bounds = workspace.getBounds();
		assert(bounds.size() == discretizationSizes.size());

		unsigned int cellCount = 1;
		for(unsigned int i = 0; i < discretizationSizes.size(); i++) {
			double range = fabs(bounds[i].first - bounds[i].second);
			if(range == 0) {
				dimensions.push_back(1);
			} else {
				dimensions.push_back(ceil(range / discretizationSizes[i]));
			}
			cellCount *= dimensions.back();
		}

		grid.resize(cellCount);

		for(unsigned int i = 0; i < cellCount; i++) {
			auto pt = getGridCenter(i);
			if(workspace.safePoses(agent, agent.getRepresentivePosesForLocation(pt))) {
				grid[i] = true;
			} else {
				grid[i] = false;
			}
		}

		populateGridNeighborOffsets();
	}
Exemple #2
0
    void Scene::update (float duration, bool paused)
    {
        if (mNeedMapUpdate)
        {
            // Note: exterior cell maps must be updated, even if they were visited before, because the set of surrounding cells might be different
            // (and objects in a different cell can "bleed" into another cells map if they cross the border)
            std::set<MWWorld::CellStore*> cellsToUpdate;
            for (CellStoreCollection::iterator active = mActiveCells.begin(); active!=mActiveCells.end(); ++active)
            {
                cellsToUpdate.insert(*active);
            }
            MWBase::Environment::get().getWindowManager()->requestMap(cellsToUpdate);

            mNeedMapUpdate = false;

            if (mCurrentCell->isExterior())
            {
                int cellX, cellY;
                getGridCenter(cellX, cellY);
                MWBase::Environment::get().getWindowManager()->setActiveMap(cellX,cellY,false);
            }
        }

        mRendering.update (duration, paused);
    }
	std::vector< std::vector<double> > getCellBoundingHyperRect(unsigned int n) const {
		std::vector< std::vector<double> > bounds(dimensions.size());

		auto center = getGridCenter(n);

		for(unsigned int i = 0; i < center.size(); ++i) {
			double halfDisc = discretizationSizes[i];
			bounds[i].push_back(center[i] - halfDisc);
			bounds[i].push_back(center[i] + halfDisc);
		}

		return bounds;
	}
Exemple #4
0
    void Scene::playerMoved(const Ogre::Vector3 &pos)
    {
        if (!mCurrentCell || !mCurrentCell->isExterior())
            return;

        // figure out the center of the current cell grid (*not* necessarily mCurrentCell, which is the cell the player is in)
        int cellX, cellY;
        getGridCenter(cellX, cellY);
        float centerX, centerY;
        MWBase::Environment::get().getWorld()->indexToPosition(cellX, cellY, centerX, centerY, true);
        const float maxDistance = 8192/2 + 1024; // 1/2 cell size + threshold
        float distance = std::max(std::abs(centerX-pos.x), std::abs(centerY-pos.y));
        if (distance > maxDistance)
        {
            int newX, newY;
            MWBase::Environment::get().getWorld()->positionToIndex(pos.x, pos.y, newX, newY);
            changeCellGrid(newX, newY);
            mRendering.updateTerrain();
        }
    }