本文整理汇总了C++中QuadTree类的典型用法代码示例。如果您正苦于以下问题:C++ QuadTree类的具体用法?C++ QuadTree怎么用?C++ QuadTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QuadTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QuadTree
// Evaluate t-SNE cost function (approximately)
double TSNE::evaluateError(int* row_P, int* col_P, double* val_P, double* Y, int N, double theta)
{
// Get estimate of normalization term
const int QT_NO_DIMS = 2;
QuadTree* tree = new QuadTree(Y, N);
double buff[QT_NO_DIMS] = {.0, .0};
double sum_Q = .0;
for(int n = 0; n < N; n++) tree->computeNonEdgeForces(n, theta, buff, &sum_Q);
// Loop over all edges to compute t-SNE error
int ind1, ind2;
double C = .0, Q;
for(int n = 0; n < N; n++) {
ind1 = n * QT_NO_DIMS;
for(int i = row_P[n]; i < row_P[n + 1]; i++) {
Q = .0;
ind2 = col_P[i] * QT_NO_DIMS;
for(int d = 0; d < QT_NO_DIMS; d++) buff[d] = Y[ind1 + d];
for(int d = 0; d < QT_NO_DIMS; d++) buff[d] -= Y[ind2 + d];
for(int d = 0; d < QT_NO_DIMS; d++) Q += buff[d] * buff[d];
Q = (1.0 / (1.0 + Q)) / sum_Q;
C += val_P[i] * log((val_P[i] + FLT_MIN) / (Q + FLT_MIN));
}
}
return C;
}
示例2: main
int main()
{
testDivision();
length_type MAP_SIZE = length_type(64.f * 533.333f);
Point center = {MAP_SIZE/2, MAP_SIZE/2};
QuadTree * tree = QuadTree::create(8, center, MAP_SIZE);
if (!tree)
return 0;
tree->debugSelf();
Circle c = {MAP_SIZE/2, MAP_SIZE/2, 1};
TreeVisitor visitor = {tree};
AABox2d box(AABox2d::create(c));
tree->intersectRecursive(box, visitor);
tree->intersect(box, visitor);
QuadIterator it = tree->deepestContaining(AABox2d::create(c));
_getch();
return 0;
}
示例3: AddEntity
QuadTree* QuadTree::AddEntity(Entity* _Ent){ //Most basic quadtree adding, alot more complicated/better ones exist, thou i don't know them
Drawn=false;
//Check if its a leaf or stem
if (Type == STEM){
//TOP LEFT
QuadTree* QT = children[0];
if (QT->max.x > _Ent->min.x && QT->max.y > _Ent->min.y){
QT->AddEntity(_Ent);
}
//TOP RIGHT
QT = children[1];
if (QT->min.x < _Ent->max.x && QT->max.y > _Ent->min.y){
QT->AddEntity(_Ent);
}
//BOTTOM LEFT
QT = children[2];
if (QT->max.x > _Ent->min.x && QT->min.y < _Ent->max.y){
QT->AddEntity(_Ent);
}
//BOTTOM RIGHT
QT = children[3];
if (QT->min.x < _Ent->max.x && QT->min.y < _Ent->max.y){
QT->AddEntity(_Ent);
}
}else{
Entlist.push_back(_Ent);
return NULL;
}
return NULL;
}
示例4: GetEntinCell
void QuadTree::GetEntinCell(Entity* _Ent, set<Entity*> *list){
Global->count++;
if (Type == STEM){
//TOP LEFT
QuadTree* QT = children[0];
if (QT->max.x > _Ent->min.x && QT->max.y > _Ent->min.y){
QT->GetEntinCell(_Ent, list);
}
//TOP RIGHT
QT = children[1];
if (QT->min.x < _Ent->max.x && QT->max.y > _Ent->min.y){
QT->GetEntinCell(_Ent, list);
}
//BOTTOM LEFT
QT = children[2];
if (QT->max.x > _Ent->min.x && QT->min.y < _Ent->max.y){
QT->GetEntinCell(_Ent, list);
}
//BOTTOM RIGHT
QT = children[3];
if (QT->min.x < _Ent->max.x && QT->min.y < _Ent->max.y){
QT->GetEntinCell(_Ent, list);
}
}else{
FOREACH(Entity*,Entlist,a)
list->insert((*a));
}
}
示例5:
void QuadTree::collide(QuadTree const &quadTree, QuadTree::callInfo call) const
{
Node *node;
Node *node2;
if (call == QuadTree::ALL)
{
for (Elements::const_iterator it = this->_mainNode->getElements().begin();
it != this->_mainNode->getElements().end(); ++it)
quadTree.collideBranches(**it, QuadTree::ALL);
}
else
{
for (Elements::const_iterator it = this->_mainNode->getElements().begin();
it != this->_mainNode->getElements().end(); ++it)
quadTree.collide(**it, static_cast<QuadTree::callInfo>(QuadTree::ALL & (~call)));
}
for (Elements::const_iterator it = quadTree._mainNode->getElements().begin();
it != quadTree._mainNode->getElements().end(); ++it)
this->collide(**it, call);
for (int i = 0; i < 4; ++i)
{
node = this->_mainNode->getChilds()[i];
node2 = quadTree._mainNode->getChilds()[i];
if (node && node2 && this->collideRect(node->getX(), node->getY(), node->getSize(), node->getSize(),
node2->getX(), node2->getY(), node2->getSize(), node2->getSize()))
this->collideNodes(node, node2, call);
}
}
示例6: Update
bool SpaceShipBeam::Update(float dt, QuadTree& tree)
{
glm::vec3 dir(-sin(m_dir * 3.14f / 180.0f),cos(m_dir * 3.14f / 180.0f),0.0f);
m_pos += dir * m_speed * dt;
m_age += dt;
tree.Erase(*this);
m_collisionPoly.GetCircle().center = glm::vec2(m_pos.x,m_pos.y);
tree.Insert(*this);
std::vector<ISpatialObject*> nearObj;
tree.QueryNearObjects(this,nearObj);
for(unsigned int i = 0; i < nearObj.size(); ++i)
{
void* pInterface = nearObj[i]->QueryInterface(IDestroyable::INTERFACE_DESTROY);
void* pBeam = nearObj[i]->QueryInterface(SpaceShipBeam::INTERFACE_BEAM);
if(pInterface != nullptr && pBeam == nullptr)
{
IDestroyable* pDestroyable = static_cast<IDestroyable*>(pInterface);
pDestroyable->Destroy();
m_bDestroyed = true;
}
}
m_animation.Update(dt);
return m_bDestroyed || m_age > 1.5f;
}
示例7: return
bool QuadTree::Delete(Sprite* obj){
if(0 == this->Count())
return( false ); // No objects to delete.
if(!Contains(obj->GetWorldPosition()))
return( false ); // Out of bounds, nothing to delete.
if(!isLeaf){ // Node
QuadTree* dest = subtrees[SubTreeThatContains( obj->GetWorldPosition() )];
if(dest==NULL)
return( false ); // That branch is empty, nothing to delete.
if( dest->Delete(obj) ){
isDirty=true;
objectcount--;
return( true ); // Found that object.
} else {
return( false ); // Didn't find that object.
}
} else { // Leaf
list<Sprite *>::iterator i = std::find( objects->begin(), objects->end(), obj);
if(i != objects->end())
{
i = objects->erase( i );
// Note that leaves don't ReBallance on delete.
objectcount--;
return( true );
} else {
return( false );
}
}
}
示例8: Draw
void gameMap::Draw(QuadTree<bool> &bw, int x, int y, int w, int h, const fsRendererGL& renderer)
{
if (bw.object() == false)
{
if (bw.layers() == 0)
return;
Draw(bw[1](0, 0), x, y, w / 2, h / 2, renderer);
Draw(bw[1](1, 0), x + w / 2, y, w / 2, h / 2, renderer);
Draw(bw[1](0, 1), x, y + h / 2, w / 2, h / 2, renderer);
Draw(bw[1](1, 1), x + w / 2, y + h / 2, w / 2, h / 2 , renderer);
}
else
{
SDL_Rect r;
r.x = x + 1;
r.y = y + 1;
r.w = w - 1;
r.h = h - 1;
SDL_FillRect(SDL_GetVideoSurface(), &r, 0x00CCAA77);
renderer.setColor( c_black );
renderer.setAlpha( .6 );
renderer.renderRect(x,y,x+w,y+h);
renderer.setAlpha( .2 );
renderer.renderRectFill(x,y,x+w,y+h);
}
}
示例9: LoadVertices
vec2 Terrain::LoadVertices(
const QuadTree<TerrainNode>::Iterator& node,
const Image& hmap
)
{
//Setup vertex data
vec2 res = vec2(1.0f, 0.0f);
int verticesCount = (lodResolution + 1) * (lodResolution + 1);
vector<vec3> vertices(verticesCount), colors(verticesCount);
float deltaX = 1.0f / node.LayerSize() / lodResolution;
float deltaY = 1.0f / node.LayerSize() / lodResolution;
float x = node.OffsetFloat().x;
for (int i = 0; i <= lodResolution; i++, x += deltaX)
{
float y = node.OffsetFloat().y;
for (int j = 0; j <= lodResolution; j++, y += deltaY)
{
float h = hmap[vec2(x, y)].x;
res = UniteSegments(res, vec2(h));
vertices[i*lodResolution + i + j] = vec3(x, h, y);
colors[i*lodResolution + i + j] = vec3(0.2f, 0.2f + h, 0.4f - h);
}
}
// VAO allocation
glGenVertexArrays(1, &node->vaoID);
// VAO setup
glBindVertexArray(node->vaoID);
// VBOs allocation
glGenBuffers(2, node->vboID);
// VBOs setup
// vertices buffer
glBindBuffer(GL_ARRAY_BUFFER, node->vboID[0]);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * 3 * sizeof(GLfloat), vertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
glEnableVertexAttribArray(0);
// colors buffer
glBindBuffer(GL_ARRAY_BUFFER, node->vboID[1]);
glBufferData(GL_ARRAY_BUFFER, colors.size() * 3 * sizeof(GLfloat), colors.data(), GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
glEnableVertexAttribArray(1);
// indices buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, GetIndicesBufferID());
OPENGL_CHECK_FOR_ERRORS();
// release vertex data
vertices.clear();
colors.clear();
if (node.Level() < maxLOD)
{
for (int i : {0, 1, 2, 3})
res = UniteSegments(res, LoadVertices(node.Add(i), hmap));
}
node->heights = res;
return res;
}
示例10:
void
GameBoard::MarkAlive(const CellSet& cells,
QuadTree& tree) {
tree.Clear();
for (CellSet::iterator it = cells.begin();
it != cells.end(); ++it) {
tree.Insert(*it);
}
}
示例11: main
int main()
{
string fichier;
ImagePNG originale,compressee;
QuadTree arbre;
// fichier = "i.png";
// originale.charger(fichier);
/* cout << endl << "-------------------------------------------------" << endl;
cout << "Original :" << endl;
arbre.importer(originale);
arbre.afficher();
cout << endl << "-------------------------------------------------" << endl;
cout << "Sans perte :" << endl;
arbre.importer(originale);
arbre.compressionDelta(0);
arbre.afficher();
compressee = arbre.exporter();
compressee.sauver("zip-d000-"+fichier);
cout << endl << "-------------------------------------------------" << endl;
cout << "Delta=128 :" << endl;
arbre.importer(originale);
arbre.compressionDelta(128);
arbre.afficher();
compressee = arbre.exporter();
compressee.sauver("zip-d128-"+fichier);
cout << endl << "-------------------------------------------------" << endl;
cout << "Phi=4 :" << endl;
arbre.importer(originale);
arbre.compressionPhi(4);
arbre.afficher();
compressee = arbre.exporter();
compressee.sauver("zip-p004-"+fichier);
cout << endl << "-------------------------------------------------" << endl;
cout << "Phi=1 :" << endl;
arbre.importer(originale);
arbre.compressionPhi(1);
arbre.afficher();
compressee = arbre.exporter();
compressee.sauver("zip-p001-"+fichier);
*/
cout << endl << "-------------------------------------------------" << endl;
fichier = "pngs/16.png";
originale.charger(fichier);
cout << "Phi=7 :" << endl;
arbre.importer(originale);
arbre.compressionPhi(7);
arbre.afficher();
compressee = arbre.exporter();
compressee.sauver("zip-p001-16.png");
}
示例12: EnableNodes
void Terrain::EnableNodes(const QuadTree<TerrainNode>::Iterator& node)
{
node->enabled = true;
for (int i = 0; i < QTREE_CHILDREN_COUNT; i++)
{
if (node.Child(i))
EnableNodes(node.Child(i));
}
}
示例13: assert_not_null
void QuadTreeRenderProcessor::DetachRenderable(Renderable* renderable)
{
assert_not_null(renderable);
mRenderables.Remove(renderable);
QuadTree* tree = static_cast<QuadTree*>(renderable->GetTree());
if(tree != NULL)
tree->Remove(renderable);
}
示例14: zoneLocker
bool ZoneContainerComponent::insertActiveArea(Zone* newZone, ActiveArea* activeArea) {
if (newZone == NULL)
return false;
if (!activeArea->isDeplyoed())
activeArea->deploy();
Zone* zone = activeArea->getZone();
ManagedReference<SceneObject*> thisLocker = activeArea;
Locker zoneLocker(newZone);
if (activeArea->isInQuadTree() && newZone != zone) {
activeArea->error("trying to insert to zone an object that is already in a different quadtree");
activeArea->destroyObjectFromWorld(true);
//StackTrace::printStackTrace();
}
activeArea->setZone(newZone);
QuadTree* regionTree = newZone->getRegionTree();
regionTree->insert(activeArea);
//regionTree->inRange(activeArea, 512);
// lets update area to the in range players
SortedVector<QuadTreeEntry*> objects;
float range = activeArea->getRadius() + 64;
newZone->getInRangeObjects(activeArea->getPositionX(), activeArea->getPositionY(), range, &objects, false);
for (int i = 0; i < objects.size(); ++i) {
SceneObject* object = cast<SceneObject*>(objects.get(i));
if (!object->isTangibleObject()) {
continue;
}
TangibleObject* tano = cast<TangibleObject*>(object);
Vector3 worldPos = object->getWorldPosition();
if (!tano->hasActiveArea(activeArea) && activeArea->containsPoint(worldPos.getX(), worldPos.getY())) {
tano->addActiveArea(activeArea);
activeArea->enqueueEnterEvent(object);
}
}
newZone->addSceneObject(activeArea);
return true;
}
示例15:
void QuadTree<Element,Comparator>::makeSubQuadTrees() {
QuadTree<Element,Comparator>* qt = new QuadTree<Element,Comparator>
(this->element,QuadTreePosition::LEFT_TOP,this->parent());
qt->setParent(this);
qt = new QuadTree<Element,Comparator>
(this->element,QuadTreePosition::RIGHT_TOP,this->parent());
qt->setParent(this);
qt = new QuadTree<Element,Comparator>
(this->element,QuadTreePosition::LEFT_BOTTOM,this->parent());
qt->setParent(this);
qt = new QuadTree<Element,Comparator>
(this->element,QuadTreePosition::RIGHT_BOTTOM,this->parent());
}