Source: raytracer/lightcache.h


Annotated List
Files
Globals
Hierarchy
Index
/* *************************************************************************
                          lightcache.h  -  description
                             -------------------
    begin                : Wed Oct 16 2002        
    copyright            : (C) 2002 by Micha Riser
    email                : mriser@gmx.net
 ************************************************************************* */

/* *************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ************************************************************************* */

#ifndef LIGHTCACHE_H
#define LIGHTCACHE_H

#include "vector.h"
#include "colour.h"
#include "lightlist.h"
#include "statistics.h"

class Scene;

/**Light Cache for Media calculation
  *@author Micha Riser
  */
class LightCache {

public: // Public type definitions

    /**Type of interpolation:
      *    EXACT: no interpolation
      *    NEAREST: nearest point aligned on grid
      *    TRILINEAR_BEST: trilinear interpolation but do not take
      *        additional samples
      *    TRILINEAR: full trilinear interpolation with sampling of all
      *        necessary samples
      */
    enum interpolationtype {EXACT, NEAREST, TRILINEAR_BEST, TRILINEAR};

public: // Public attributes
    interpolationtype itype;
    
public: // Constructors and destructor
    LightCache(const Scene* s): itype(EXACT), scene(s), map() {}

private:
    LightCache(const LightCache&);
    LightCache& operator=(const LightCache&);

public: // Public methods

    /**Set cache interpolation type and cache size.
      */
    void setType(interpolationtype type, int size);

    /**Looks up a point given by location and returns the list of lights
      *there. Lookup is done according to the cache's interpolation type.
      *@param location lookup point
      *@param err returns approx. maximum error in lookup
      *@param precision space tolerance for lookup
      */
    LightList* lookup(const Vector3& location, CLR& err, DBL precision);

private: // Inner classes

    /**MapEntry holds one element of the cache.
      */
    class MapEntry {

    public: // Public attributes
        Vector3 location;
        CLR blockingerror;
        LightList* list;
        unsigned int hitcount;

    public: // Constructor and destructor
        MapEntry(const Vector3& l, CLR err, LightList* data):
        location(l), blockingerror(err), list(data), hitcount(1) {}
  
        MapEntry(): list(0), hitcount(0) {}

        ~MapEntry();
        
    };


    /**Holds the data in a hash data structure.
      */
    class Hash {

    public: // Static members

        /**Counts number of cache evaluations and successes.
          */
        static HitStatistics hitstat;
        /**Counts number of data insertions and collisions thereby.
          */
        static HitStatistics insertstat;
            
    public: // Constructor and destructor
        Hash();
        ~Hash();
    private:
        Hash(const Hash&);
        Hash& operator=(const Hash&);

    public: // Public methods
        void setSize(int size);
        bool get(const Vector3& location, CLR& err, LightList*&);
        void put(const Vector3& location, CLR err, LightList* l);

    private: // Private attributes
        int size, sondmod;
        MapEntry* data;

    private: // Private methods
        unsigned int calcHashValue(unsigned int);
        unsigned int calcHashValueSond(unsigned int);
        unsigned int vectorToInt(const Vector3&v);

    };

private: // Constants
    static const int sondsize = 3;

private: // Private methods
    LightList* sample(const Vector3& p, CLR& err);

private: // Private attributes
    const Scene* scene;
    Hash map;

};

#endif

Generated by: micha@laptop on Thu Oct 24 20:25:24 2002, using kdoc 2.0a53.