Commit 76ad1094 authored by Emeric Verschuur's avatar Emeric Verschuur
Browse files

Modification des méthodes getMinMax.

parent d95eabc9
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -62,5 +62,3 @@ LrMatrix LrEntity::getMat() const
{
     return m_mat;
}

+8 −14
Original line number Diff line number Diff line
@@ -26,15 +26,14 @@ class LrGeometry;
 *
 * Cette classe gère un objet  générique.
 */
class LrEntity;

class LrEntity
{
public:
    ///@brief Liste d'entités.
    typedef std::list<LrEntity *> LrEntityList;
    
    ///@brief Liste de géométries.
    typedef std::list<LrGeometry *> LrGeometryList;
    
    /**
     * @brief Constructeur.
     */
@@ -116,7 +115,7 @@ public:
                                 Real minBound=0, Real maxBound=INFINITY) const=0;
    
    /**
     * @brief Donne le nombre de fragments de la géométrie.
     * @brief Donne le nombre de fragments de l'entitée.
     * @return Un entier.
     */
    virtual int getNbFragments() const = 0;
@@ -130,9 +129,10 @@ public:
     * @param fragmentLocal fragment de l'entitée locale.
     *
     * Calcule le point "en bas, devant, à gauche" et le point "en haut,
     * derrière, à droite" de la géométrie.
     * derrière, à droite" de l'entitée.
     */
    virtual void getMinMax(LrPoint &min, LrPoint &max, int fragment, LrEntity &*entityLocal, int &fragmentLocal) const = 0;
    virtual void getMinMax(LrPoint &min, LrPoint &max, int fragment, 
                           LrEntity *&entityLocal, int &fragmentLocal) const = 0;
    
    /**
     * @brief Calcul des points min et max de la boîte englobante.
@@ -140,15 +140,9 @@ public:
     * @param max LrPoint maximum de la boîte"
     *
     * Calcule le point "en bas, devant, à gauche" et le point "en haut,
     * derrière, à droite" de la géométrie.
     */
    virtual void getMinMax(LrPoint &min, LrPoint &max) const;
    
    /**
     * @brief Donne la liste de géométries qui composent cette entitée.
     * @param geometryList Liste dans laquelle seront ajoutées les géométries.
     * derrière, à droite" de l'entitée.
     */
    virtual void mkGeometryList(LrGeometryList & geometryList) const=0;
    virtual void getMinMax(LrPoint &min, LrPoint &max) const = 0;
private:
    /// @brief Matrice de position.
    LrMatrix m_mat;
+46 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "LrEntityComposed.h"
#include <algorithm>
#include <cmath>

LrEntityComposed::LrEntityComposed(const LrMatrix &mat, const LrEntityList &entities)
        :
@@ -113,10 +114,52 @@ bool LrEntityComposed::remove(LrEntity& entity)
    return true;
}

void LrEntityComposed::mkGeometryList(LrGeometryList & geometryList) const
void LrEntityComposed::getMinMax(LrPoint &min, LrPoint &max) const
{
    max = LrPoint(-INFINITY,-INFINITY,-INFINITY);
    min = LrPoint(INFINITY,INFINITY,INFINITY);
    
    for (LrEntityList::const_iterator it=m_entities.begin(); it != m_entities.end(); it++)
    {
        LrPoint lmin, lmax;
        (*it)->getMinMax(lmin, lmax);
        
        if (lmin.x < min.x)
            min.x = lmin.x;
        if (lmin.y < min.y)
            min.y = lmin.y;
        if (lmin.z < min.z)
            min.z = lmin.z;
        
        if (lmax.x > max.x)
            max.x = lmax.x;
        if (lmax.y > max.y)
            max.y = lmax.y;
        if (lmax.z > max.z)
            max.z = lmax.z;
    }
}

void LrEntityComposed::getMinMax(LrPoint &min, LrPoint &max, int fragment, 
                                 LrEntity *&entityLocal, int &fragmentLocal) const
{
    int nbFrags;
    for (LrEntityList::const_iterator it=m_entities.begin(); it != m_entities.end(); it++)
    {
        nbFrags = (*it)->getNbFragments();
        if(fragment < nbFrags){
            (*it)->getMinMax(min, max, fragment, entityLocal, fragmentLocal);
            break;
        }
        fragment -= nbFrags;
    }
}

int LrEntityComposed::getNbFragments() const{
    int somFrags=0;
    for (LrEntityList::const_iterator it=m_entities.begin(); it != m_entities.end(); it++)
    {
        (*it)->mkGeometryList(geometryList);
        somFrags += (*it)->getNbFragments();
    }
    return somFrags;
}
+29 −6
Original line number Diff line number Diff line
@@ -86,6 +86,35 @@ public:
    virtual bool getIntersection(const LrRay &ray, LrHit *hit,
                                 Real minBound=0, Real maxBound=INFINITY) const;
    
    /**
     * @brief Donne le nombre de fragments de l'entitée.
     * @return Un entier.
     */
    virtual int getNbFragments() const;
    
    /**
     * @brief Calcul des points min et max de la boîte englobante.
     * @param min LrPoint minimum de la boîte.
     * @param max LrPoint maximum de la boîte.
     * @param entityLocal Entitée dans lequel se trouve le fragment.
     * @param fragmentLocal fragment d'entitée.
     *
     * Calcule le point "en bas, devant, à gauche" et le point "en haut,
     * derrière, à droite" de l'entitée.
     */
    virtual void getMinMax(LrPoint &min, LrPoint &max, int fragment, 
                           LrEntity *&entityLocal, int &fragmentLocal) const;
    
    /**
     * @brief Calcul des points min et max de la boîte englobante.
     * @param min LrPoint minimum de la boîte.
     * @param max LrPoint maximum de la boîte"
     *
     * Calcule le point "en bas, devant, à gauche" et le point "en haut,
     * derrière, à droite" de l'entitée.
     */
    virtual void getMinMax(LrPoint &min, LrPoint &max) const;
    
    /**
     * @brief Ajout d'une sous-entité.
     * @param entity Référence de l'entité à ajouter.
@@ -100,12 +129,6 @@ public:
     */
    bool remove(LrEntity& entity);
    
    /**
     * @brief Donne la liste de géométries qui composent cette entitée.
     * @param geometryList Liste dans laquelle seront ajoutées les géométries.
     */
    virtual void mkGeometryList(LrGeometryList & geometryList) const;
    
protected:
    ///@brief Liste des entités
    LrEntityList m_entities;
+14 −2
Original line number Diff line number Diff line
@@ -91,7 +91,19 @@ bool LrEntityElementary::getIntersection(const LrRay &ray, LrHit *hit,
    }
}

void LrEntityElementary::mkGeometryList(LrGeometryList & geometryList) const
void LrEntityElementary::getMinMax(LrPoint &min, LrPoint &max) const
{
    geometryList.push_back(m_geometry);
    m_geometry->getMinMax(min,max,m_transf);
}

void LrEntityElementary::getMinMax(LrPoint &min, LrPoint &max, int fragment, 
               LrEntity *&entityLocal, int &fragmentLocal) const
{
    fragmentLocal = fragment;
    entityLocal = (LrEntity*)this;
    m_geometry->getMinMax(min,max,fragment);
}

int LrEntityElementary::getNbFragments() const{
    return m_geometry->getNbFragments();
}
Loading