<commit_before>#include "BoundingOctree.h"
#include <algorithm>
using namespace nspace;
using namespace std;



const TypeId Octree::getCollisionType()const{
    return type;
}


void Octree::classify(){
    if(_depth==0)_classfication = classifyGeometrically();
    else _classfication = classifyByChildNodes();
    if(_classfication == Classification::UNCLASSIFIED){
        cout << "Node not classifiable" << endl;
    }
}

BoundingVolume &  Octree::getBoundingVolume(){
    return *_boundingVolume;
}
BoundingVolume & Octree::getBoundingVolume()const{
    return *_boundingVolume;
}

const Octree * Octree::child(OctreeNodeId i)const{
    if(isLeaf())return 0;
    return _children[i];
}


Octree::~Octree(){
    delete _boundingVolume;
    _boundingVolume =0;

}
void Octree::createBoundingVolume(){
    _boundingVolume = _boundingVolumeFactory.create(getBoundingBox().minValue(), getBoundingBox().maxValue(),getGeometry().coordinates());
}

Octree *  Octree::createChild( OctreeNodeId id){
    Octree * child = new Octree(id, *this);
    child->_level = getLevel()+1;
    child->_depth =  _depth -1;

    // calculate the node's bounding box
    child->_aabb.minValue() = _aabb.minValue();
    child->_aabb.maxValue() = _aabb.maxValue();
    Vector3D delta = 0.5*(_aabb.maxValue() - _aabb.minValue());
    if((id/4)%2==1){ //left half volume
        child->_aabb.minValue()(0) += delta(0);
    }else{
        child->_aabb.maxValue()(0) -= delta(0);
    }
    if((id/2)%2==1){//bottom half volume
        child->_aabb.minValue()(1) += delta(1);
    }else{
        child->_aabb.maxValue()(1) -= delta(1);
    }
    if((id/1)%2==1){//back half volume
        child->_aabb.minValue()(2) += delta(2);
    }else{
        child->_aabb.maxValue()(2) -= delta(2);
    }
    
    child->createBoundingVolume();

    return child;
}


Octree::Octree(OctreeNodeId id, Octree & parent):
    _geometry(parent.getGeometry()),
    _boundingVolumeFactory(parent._boundingVolumeFactory),
    _id(id),
    _depth(0),
    _level(0),
    _classfication(Classification::UNCLASSIFIED),
    _boundingVolume(0),
    _children(0)
{}

OctreeNodeId Octree::getId()const{
    return _id;
}

Octree * Octree::getNode(OctreeNodeId id){
    if(!_children)return 0;
    return _children[id];
}
void Octree::setNode(Octree * node){
    if(!_children){
        _children = new Octree*[8];
        for(int i=0; i < 8; i++){
            _children[i]=0;
        }
    }
    Octree * old = _children[node->getId()];
    if(old){
        old->deleteChildren();
        delete old;
    }
    _children[node->getId()]=node;
}

void Octree::deleteChildren(){
    if(_children){
        for(int i = 0; i < 8; i++){
            Octree * child = _children[i];
            if(!child) continue;
            child->deleteChildren();
            delete child;
            _children[i] =0;
        }
        delete _children;
        _children =0;
    }
}
Geometry & _geometry;
///< The bounding volume factory is same for all nodes of an octree
BoundingVolumeFactory & _boundingVolumeFactory;
///< The id of the node
const OctreeNodeId _id;
///< The depth of the tree from this node ( 0 => leaf leaf !=> 0)
unsigned int _depth;
///< The level at which this node is (0 is root)
unsigned int _level;
///< The classfication (inside, outside or both)
Classification _classfication;
///< The aabb representing the dimension of this octree node
BoundingBox _aabb;
///< The bounding volume used for collision and classification
BoundingVolume * _boundingVolume;
///< The children
Octree ** _children;

Octree::Octree( Geometry & geometry,int depth, BoundingVolumeFactory & boundingVolumeFactory)
    :
      _geometry(geometry),
      _boundingVolumeFactory(boundingVolumeFactory),
      _id(OctreeNodeId::NODE_ROOT),
      _depth(depth),
      _level(0),
      _boundingVolume(0),
      _children(0)
{}


bool Octree::initializeObject(){
    cout<< "initializing octree "<<endl;
    if( NODE_ROOT != _id)return true;
    deleteChildren(); //safety first<commit_msg>fixed more warnings<commit_after>#include "BoundingOctree.h"
#include <algorithm>
using namespace nspace;
using namespace std;



const TypeId Octree::getCollisionType()const{
    return type;
}


void Octree::classify(){
    if(_depth==0)_classfication = classifyGeometrically();
    else _classfication = classifyByChildNodes();
    if(_classfication == Classification::UNCLASSIFIED){
        cout << "Node not classifiable" << endl;
    }
}

BoundingVolume &  Octree::getBoundingVolume(){
    return *_boundingVolume;
}
BoundingVolume & Octree::getBoundingVolume()const{
    return *_boundingVolume;
}

const Octree * Octree::child(OctreeNodeId i)const{
    if(isLeaf())return 0;
    return _children[i];
}


Octree::~Octree(){
    delete _boundingVolume;
    _boundingVolume =0;

}
void Octree::createBoundingVolume(){
    _boundingVolume = _boundingVolumeFactory.create(getBoundingBox().minValue(), getBoundingBox().maxValue(),getGeometry().coordinates());
}

Octree *  Octree::createChild( OctreeNodeId id){
    Octree * child = new Octree(id, *this);
    child->_level = getLevel()+1;
    child->_depth =  _depth -1;

    // calculate the node's bounding box
    child->_aabb.minValue() = _aabb.minValue();
    child->_aabb.maxValue() = _aabb.maxValue();
    Vector3D delta = 0.5*(_aabb.maxValue() - _aabb.minValue());
    if((id/4)%2==1){ //left half volume
        child->_aabb.minValue()(0) += delta(0);
    }else{
        child->_aabb.maxValue()(0) -= delta(0);
    }
    if((id/2)%2==1){//bottom half volume
        child->_aabb.minValue()(1) += delta(1);
    }else{
        child->_aabb.maxValue()(1) -= delta(1);
    }
    if((id/1)%2==1){//back half volume
        child->_aabb.minValue()(2) += delta(2);
    }else{
        child->_aabb.maxValue()(2) -= delta(2);
    }
    
    child->createBoundingVolume();

    return child;
}


Octree::Octree(OctreeNodeId id, Octree & parent):
    _geometry(parent.getGeometry()),
    _boundingVolumeFactory(parent._boundingVolumeFactory),
    _id(id),
    _depth(0),
    _level(0),
    _classfication(Classification::UNCLASSIFIED),
    _boundingVolume(0),
    _children(0)
{}

OctreeNodeId Octree::getId()const{
    return _id;
}

Octree * Octree::getNode(OctreeNodeId id){
    if(!_children)return 0;
    return _children[id];
}
void Octree::setNode(Octree * node){
    if(!_children){
        _children = new Octree*[8];
        for(int i=0; i < 8; i++){
            _children[i]=0;
        }
    }
    Octree * old = _children[node->getId()];
    if(old){
        old->deleteChildren();
        delete old;
    }
    _children[node->getId()]=node;
}

void Octree::deleteChildren(){
    if(_children){
        for(int i = 0; i < 8; i++){
            Octree * child = _children[i];
            if(!child) continue;
            child->deleteChildren();
            delete child;
            _children[i] =0;
        }
        delete _children;
        _children =0;
    }
}


Octree::Octree( Geometry & geometry,int depth, BoundingVolumeFactory & boundingVolumeFactory)
    :
      _geometry(geometry),
      _boundingVolumeFactory(boundingVolumeFactory),
      _id(OctreeNodeId::NODE_ROOT),
      _depth(depth),
      _level(0),
      _boundingVolume(0),
      _children(0)
{}


bool Octree::initializeObject(){
    cout<< "initializing octree "<<endl;
    if( NODE_ROOT != _id)return true;
    deleteChildren(); //safety first
{'fraction_non_alphanumeric': 0.14814814814814814, 'fraction_numerical': 0.012570965125709651, 'mean_word_length': 3.276878612716763, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889574', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2437, 'n_words': 492}