Implementation of QuadTree
- Constructor who create recursively the image - Destructor who free the structure - image method who create a black picture (temp)
This commit is contained in:
parent
a512ca52b1
commit
4b0521bdfa
1 changed files with 49 additions and 0 deletions
49
src/quadtree.cpp
Normal file
49
src/quadtree.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "../includes/quadtree.hpp"
|
||||
|
||||
QuadTree::QuadTree(SDL_Surface * image, short niveau_p): niveau(niveau_p), couleur(calculeCouleur(image)), dimensions(image->w, image->h),
|
||||
nord_ouest(nullptr), nord_est(nullptr), sud_ouest(nullptr), sud_est(nullptr) {
|
||||
if(!verificationEgalitee(image)) {
|
||||
std::array<SDL_Surface *, 4> image_coupe = coupeEnQuatre(image);
|
||||
|
||||
final = false;
|
||||
nord_ouest = new QuadTree(image_coupe.at(0), niveau + 1);
|
||||
nord_est = new QuadTree(image_coupe.at(1), niveau + 1);
|
||||
sud_ouest = new QuadTree(image_coupe.at(2), niveau + 1);
|
||||
sud_est = new QuadTree(image_coupe.at(3), niveau + 1);
|
||||
}
|
||||
}
|
||||
|
||||
QuadTree::~QuadTree(void) {
|
||||
if(nord_ouest != nullptr) {
|
||||
delete nord_ouest;
|
||||
}
|
||||
if(nord_est != nullptr) {
|
||||
delete nord_est;
|
||||
}
|
||||
if(sud_ouest != nullptr) {
|
||||
delete sud_ouest;
|
||||
}
|
||||
if(sud_est != nullptr) {
|
||||
delete sud_est;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface * QuadTree::image(short niveau_p) {
|
||||
// Temporaire, créer une image noire
|
||||
(void)niveau_p;
|
||||
SDL_Surface * nouvelle_image = SDL_CreateRGBSurface(0, dimensions.first, dimensions.second, 32, 0, 0, 0, 0);
|
||||
if(SDL_LockSurface(nouvelle_image) == 0) {
|
||||
SDL_memset(nouvelle_image->pixels, static_cast<int>(SDL_MapRGB(nouvelle_image->format, 0, 0, 0)), static_cast<size_t>(nouvelle_image->h * nouvelle_image->pitch));
|
||||
SDL_UnlockSurface(nouvelle_image);
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return nouvelle_image;
|
||||
}
|
||||
|
||||
SDL_Color QuadTree::calculeCouleur(SDL_Surface *) { /* return SDL_Color(); */ }
|
||||
|
||||
bool QuadTree::verificationEgalitee(SDL_Surface *) { /* return true; */ }
|
||||
|
||||
std::array<SDL_Surface *, 4> QuadTree::coupeEnQuatre(SDL_Surface *) { /* return std::array<SDL_Surface *, 4>(); */ }
|
Reference in a new issue