void PCZSceneNode::_update(bool updateChildren, bool parentHasChanged) { Node::_update(updateChildren, parentHasChanged); if (mParent) _updateBounds(); // skip bound update if it's root scene node. Saves a lot of CPU. mPrevPosition = mNewPosition; mNewPosition = mDerivedPosition; }
void CAnimation::onTransformChanged(TransformChangedFlags flags) { if (!SO()->getActive()) return; if ((flags & (TCF_Transform)) != 0) _updateBounds(false); }
void CAnimation::restoreInternal(bool previewMode) { if (mInternal != nullptr) destroyInternal(); mInternal = Animation::create(); mAnimatedRenderable = SO()->getComponent<CRenderable>(); if (!previewMode) { mInternal->onEventTriggered.connect(std::bind(&CAnimation::eventTriggered, this, _1, _2)); mInternal->setWrapMode(mWrapMode); mInternal->setSpeed(mSpeed); mInternal->setCulling(mEnableCull); } _updateBounds(); if (!previewMode) { if (mDefaultClip.isLoaded()) mInternal->play(mDefaultClip); mPrimaryPlayingClip = mInternal->getClip(0); if (mPrimaryPlayingClip.isLoaded()) { if (_scriptRebuildFloatProperties) _scriptRebuildFloatProperties(mPrimaryPlayingClip); } } setBoneMappings(); if(!previewMode) updateSceneObjectMapping(); if (mAnimatedRenderable != nullptr) mAnimatedRenderable->_registerAnimation(static_object_cast<CAnimation>(mThisHandle)); }
void GraphComparator::drawCostDistance(shared_ptr<OsmMap> map, vector<Coordinate>& c, QString output) { _updateBounds(); // make a copy of the map so we can manipulate it. map.reset(new OsmMap(map)); for (size_t i = 0; i < c.size(); i++) { cout << c[i].x << " " << c[i].y << endl; c[i] = _findNearestPointOnFeature(map, c[i]); cout << c[i].x << " " << c[i].y << endl; // find the nearest feature long wId = map->getIndex().findNearestWay(c[i]); shared_ptr<Way> w = map->getWay(wId); // split way at c WayLocation wl = LocationOfPoint::locate(map, w, c[i]); vector< shared_ptr<Way> > v = WaySplitter::split(map, w, wl); wl = LocationOfPoint::locate(map, v[0], c[i]); assert(wl.isNode() == true); } // populate graph shared_ptr<DirectedGraph> graph(new DirectedGraph()); graph->deriveEdges(map); LOG_WARN("Running cost"); ShortestPath sp(graph); for (size_t i = 0; i < c.size(); i++) { long wId = map->getIndex().findNearestWay(c[i]); shared_ptr<Way> w = map->getWay(wId); WayLocation wl = LocationOfPoint::locate(map, w, c[i]); // set cost at c to zero. long sourceId = w->getNodeId(wl.getSegmentIndex()); sp.setNodeCost(sourceId, 0.0); } // calculate cost sp.calculateCost(); LOG_WARN("Cost done"); cv::Mat mat = _paintGraph(map, *graph, sp); _saveImage(mat, output, -1.0, false); _saveImage(mat, output.replace(".png", "2.png"), -1.0, true); shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference()); srs->importFromEPSG(900913); Coordinate c1 = MapProjector::project(Coordinate(_projectedBounds.MinX, _projectedBounds.MinY), map->getProjection(), srs); cout << "coord " << c1.x << ", " << c1.y << endl; Coordinate c2 = MapProjector::project(Coordinate(_projectedBounds.MaxX, _projectedBounds.MaxY), map->getProjection(), srs); cout << "coord2 " << c2.x << ", " << c2.y << endl; printf("POSITION_Y=%f\n", (c1.y + c2.y) / 2.0); //cout << "POSITION_Y=" << (c1.y + c2.y) / 2.0 << endl; printf("POSITION_X=%f\n", (c1.x + c2.x) / 2.0); //cout << "POSITION_X=" << (c1.x + c2.x) / 2.0 << endl; cout << "M12=0.0" << endl; cout << "M11=1.0" << endl; cout << "M10=0.0" << endl; cout << "M02=0.0" << endl; cout << "INITIAL_SCALE=" << (c2.x - c1.x) / (double)_width * 100.0 << endl; cout << "M01=0.0" << endl; cout << "M00=1.0" << endl; // paint graph onto raster //_exportGraphImage(map, *graph, sp, output); }
double GraphComparator::compareMaps() { _updateBounds(); double diffScoreSum = 0.0; vector<double> scores; int same = 0; // sampled standard deviation _s = -1; // 1.645 for 90% confidence, 1.96 for 95% confidence, and 2.58 for 99% confidence. // please update the header file comments if you change this value. double zalpha = 1.645; _ci = -1; // do this a bunch of times for (int i = 0; i < _iterations && same < 4; i++) { // generate a random source point _r.x = Random::generateUniform() * (_projectedBounds.MaxX - _projectedBounds.MinX) + _projectedBounds.MinX; _r.y = Random::generateUniform() * (_projectedBounds.MaxY - _projectedBounds.MinY) + _projectedBounds.MinY; shared_ptr<OsmMap> referenceMap; // pick one map as the reference map if (Random::coinToss()) { referenceMap = _mapP1; } else { referenceMap = _mapP2; } _maxGraphCost = 0.0; // find the random source point's nearest point on a feature in one of the maps _r = _findNearestPointOnFeature(referenceMap, _r); // generate a cost distance raster for each map cv::Mat image1 = _calculateCostDistance(_mapP1, _r); cv::Mat image2 = _calculateCostDistance(_mapP2, _r); // take the difference of the two rasters and normalize double error = _calculateError(image1, image2); if (_debugImages) { cv::Mat diff(cvSize(_width, _height), CV_32FC1); const float* image1Data = image1.ptr<float>(0); const float* image2Data = image2.ptr<float>(0); float* diffData = diff.ptr<float>(0); size_t size = (image1.dataend - image1.datastart) / sizeof(float); for (size_t j = 0; j < size; j++) { diffData[j] = fabs(image1Data[j] - image2Data[j]); } QDir().mkpath("test-output/route-image"); QString s1 = QString("test-output/route-image/route-%1-a.png").arg(i, 3, 10, QChar('0')); QString s2 = QString("test-output/route-image/route-%1-b.png").arg(i, 3, 10, QChar('0')); QString sdiff = QString("test-output/route-image/route-%1-diff.png").arg(i, 3, 10, QChar('0')); _saveImage(image1, s1, _maxGraphCost * 3); _saveImage(image2, s2, _maxGraphCost * 3); _saveImage(diff, sdiff, _maxGraphCost * 3); } image1.release(); image2.release(); // keep a running tally of the differences. diffScoreSum += error; scores.push_back(1 - error); sort(scores.begin(), scores.end()); _median = scores[scores.size() / 2]; _mean = 1 - (diffScoreSum / (i + 1)); if (scores.size() > 1) { double v = 0; for (size_t i = 0; i < scores.size(); i++) { v += (scores[i] - _mean) * (scores[i] - _mean); } _s = sqrt(v / (scores.size() - 1)); _ci = zalpha * _s / sqrt(scores.size()); } if (Log::getInstance().isInfoEnabled()) { cout << i << " / " << _iterations << " mean: " << _mean << " \r"; cout.flush(); } //qDebug() << _median << 1 - error << _mean << "+/-" << _ci << "sd: " << _s; } if (Log::getInstance().isInfoEnabled()) { cout << " \r"; } return _mean; }
//----------------------------------------------------------------------- void SceneNode::_update(bool updateChildren, bool parentHasChanged) { Node::_update(updateChildren, parentHasChanged); _updateBounds(); }
void Frustum::set( const MatrixF &projMat, bool normalize ) { // From "Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix" // by Gil Gribb and Klaus Hartmann. // // http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf // Right clipping plane. mPlanes[ PlaneRight ].set( projMat[3] - projMat[0], projMat[7] - projMat[4], projMat[11] - projMat[8], projMat[15] - projMat[12] ); // Left clipping plane. mPlanes[ PlaneLeft ].set( projMat[3] + projMat[0], projMat[7] + projMat[4], projMat[11] + projMat[8], projMat[15] + projMat[12] ); // Bottom clipping plane. mPlanes[ PlaneBottom ].set( projMat[3] + projMat[1], projMat[7] + projMat[5], projMat[11] + projMat[9], projMat[15] + projMat[13] ); // Top clipping plane. mPlanes[ PlaneTop ].set( projMat[3] - projMat[1], projMat[7] - projMat[5], projMat[11] - projMat[9], projMat[15] - projMat[13] ); // Near clipping plane mPlanes[ PlaneNear ].set( projMat[3] + projMat[2], projMat[7] + projMat[6], projMat[11] + projMat[10], projMat[15] + projMat[14] ); // Far clipping plane. mPlanes[ PlaneFar ].set( projMat[3] - projMat[2], projMat[7] - projMat[6], projMat[11] - projMat[10], projMat[15] - projMat[14] ); if( normalize ) { for( S32 i = 0; i < PlaneCount; ++ i ) mPlanes[ i ].normalize(); } /* // Create the corner points via plane intersections. mPlanes[ PlaneNear ].intersect( mPlanes[ PlaneTop ], mPlanes[ PlaneLeft ], &mPoints[ NearTopLeft ] ); mPlanes[ PlaneNear ].intersect( mPlanes[ PlaneTop ], mPlanes[ PlaneRight ], &mPoints[ NearTopRight ] ); mPlanes[ PlaneNear ].intersect( mPlanes[ PlaneBottom ], mPlanes[ PlaneLeft ], &mPoints[ NearBottomLeft ] ); mPlanes[ PlaneNear ].intersect( mPlanes[ PlaneBottom ], mPlanes[ PlaneRight ], &mPoints[ NearBottomRight ] ); mPlanes[ PlaneFar ].intersect( mPlanes[ PlaneTop ], mPlanes[ PlaneLeft ], &mPoints[ FarTopLeft ] ); mPlanes[ PlaneFar ].intersect( mPlanes[ PlaneTop ], mPlanes[ PlaneRight ], &mPoints[ FarTopRight ] ); mPlanes[ PlaneFar ].intersect( mPlanes[ PlaneBottom ], mPlanes[ PlaneLeft ], &mPoints[ FarBottomLeft ] ); mPlanes[ PlaneFar ].intersect( mPlanes[ PlaneBottom ], mPlanes[ PlaneRight ], &mPoints[ FarBottomRight ] ); */ // Update the axis aligned bounding box. _updateBounds(); }
double AttributeComparator::compareMaps() { _updateBounds(); double scoreSum = 0.0; double buffer = 10.0; double oldIsACost = OsmSchema::getInstance().getIsACost(); OsmSchema::getInstance().setIsACost(0.5); vector<double> scores; // sampled standard deviation _s = -1; // 1.645 for 90% confidence, 1.96 for 95% confidence, and 2.58 for 99% confidence. double zalpha = 1.645; _ci = -1; boost::shared_ptr<OsmMap> referenceMap, otherMap; // do this a bunch of times for (int i = 0; i < _iterations * 4 && (int)scores.size() < _iterations; i++) { // generate a random source point _r.x = Random::instance()->generateUniform() * (_projectedBounds.MaxX - _projectedBounds.MinX) + _projectedBounds.MinX; _r.y = Random::instance()->generateUniform() * (_projectedBounds.MaxY - _projectedBounds.MinY) + _projectedBounds.MinY; // pick one map as the reference map if (Random::instance()->coinToss()) { referenceMap = _mapP1; otherMap = _mapP2; } else { referenceMap = _mapP2; otherMap = _mapP1; } // find the nearest way on the reference map vector<long> wids1 = referenceMap->getIndex().findWayNeighbors(_r, buffer); vector<long> wids2 = otherMap->getIndex().findWayNeighbors(_r, buffer); Tags t1, t2; double bestScore = -1.0; for (size_t j = 0; j < wids1.size(); j++) { WayPtr w1 = referenceMap->getWay(wids1[j]); for (size_t k = 0; k < wids2.size(); k++) { WayPtr w2 = otherMap->getWay(wids2[k]); double score = TagComparator::getInstance().compareTags(w1->getTags(), w2->getTags()); if (score > bestScore) { bestScore = score; t1 = w1->getTags(); t2 = w2->getTags(); } } } if (bestScore >= 0.0) { // LOG_INFO("===="); // LOG_INFO("score: " << bestScore); // LOG_INFO("t1: \n" << t1); // LOG_INFO("t2: \n" << t2); scoreSum += bestScore; scores.push_back(bestScore); sort(scores.begin(), scores.end()); _median = scores[scores.size() / 2]; _mean = scoreSum / (double)scores.size(); } if (scores.size() > 1) { double v = 0; for (size_t i = 0; i < scores.size(); i++) { v += (scores[i] - _mean) * (scores[i] - _mean); } _s = sqrt(v / (scores.size() - 1)); _ci = zalpha * _s / sqrt(scores.size()); } PROGRESS_INFO(i << " / " << _iterations << " mean: " << _mean << " "); } LOG_INFO(_iterations << " / " << _iterations << " mean: " << _mean << " "); OsmSchema::getInstance().setIsACost(oldIsACost); return _mean; }
void CAnimation::_registerRenderable(const HRenderable& renderable) { mAnimatedRenderable = renderable; _updateBounds(); }
void CAnimation::setUseBounds(bool enable) { mUseBounds = enable; _updateBounds(); }
void TerrCell::updateGrid( const RectI &gridRect, bool opacityOnly ) { PROFILE_SCOPE( TerrCell_UpdateGrid ); // If we have a VB... then update it. if ( mVertexBuffer.isValid() && !opacityOnly ) _updateVertexBuffer(); // Update our PB, if any _updatePrimitiveBuffer(); // If we don't have children... then we're // a leaf at the bottom of the cell quadtree // and we should just update our bounds. if ( !mChildren[0] ) { if ( !opacityOnly ) _updateBounds(); _updateMaterials(); return; } // Otherwise, we must call updateGrid on our children // and then update our bounds/materials AFTER to contain them. mMaterials = 0; for ( U32 i = 0; i < 4; i++ ) { TerrCell *cell = mChildren[i]; // The overlap test doesn't hit shared edges // so grow it a bit when we create it. const RectI cellRect( cell->mPoint.x - 1, cell->mPoint.y - 1, cell->mSize + 2, cell->mSize + 2 ); // We do an overlap and containment test as it // properly handles zero sized rects. if ( cellRect.contains( gridRect ) || cellRect.overlaps( gridRect ) ) cell->updateGrid( gridRect, opacityOnly ); // Update the bounds from our children. if ( !opacityOnly ) { if ( i == 0 ) mBounds = mChildren[i]->getBounds(); else mBounds.intersect( mChildren[i]->getBounds() ); mRadius = mBounds.len() * 0.5f; } // Update the material flags. mMaterials |= mChildren[i]->getMaterials(); } if ( mMaterial ) mMaterial->init( mTerrain, mMaterials ); }
void TerrCell::_init( TerrainBlock *terrain, const Point2I &point, U32 size, U32 level ) { PROFILE_SCOPE( TerrCell_Init ); mTerrain = terrain; mPoint = point; mSize = size; mLevel = level; // Generate a VB (and maybe a PB) for this cell, unless we are the Root cell. if ( level > 0 ) { _updateVertexBuffer(); _updatePrimitiveBuffer(); } if ( mSize <= smMinCellSize ) { // Update our bounds and materials... the // parent will use it to update itself. _updateBounds(); _updateMaterials(); return; } // Create our children and update our // bounds and materials from them. const U32 childSize = mSize / 2; const U32 childLevel = mLevel + 1; mChildren[0] = new TerrCell; mChildren[0]->_init( mTerrain, Point2I( mPoint.x, mPoint.y ), childSize, childLevel ); mBounds = mChildren[0]->getBounds(); mMaterials = mChildren[0]->getMaterials(); mChildren[1] = new TerrCell; mChildren[1]->_init( mTerrain, Point2I( mPoint.x + childSize, mPoint.y ), childSize, childLevel ); mBounds.intersect( mChildren[1]->getBounds() ); mMaterials |= mChildren[1]->getMaterials(); mChildren[2] = new TerrCell; mChildren[2]->_init( mTerrain, Point2I( mPoint.x, mPoint.y + childSize ), childSize, childLevel ); mBounds.intersect( mChildren[2]->getBounds() ); mMaterials |= mChildren[2]->getMaterials(); mChildren[3] = new TerrCell; mChildren[3]->_init( mTerrain, Point2I( mPoint.x + childSize, mPoint.y + childSize ), childSize, childLevel ); mBounds.intersect( mChildren[3]->getBounds() ); mMaterials |= mChildren[3]->getMaterials(); mRadius = mBounds.len() * 0.5f; _updateOBB(); }