Source: raytracer/csg.h


Annotated List
Files
Globals
Hierarchy
Index
/* *************************************************************************
                            csg.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 CSG_H
#define CSG_H

#include<list>
#include<vector>
using std::list;
using std::vector;

#include "types.h"
#include "object3d.h"
#include "intersection.h"

/**Provides a container for multiple objects and different set operations
  *between them.
  *@author Micha Riser
  */

class CSG: public Object3D {

public: // Public types
    enum csgtype {UNION, INTERSECT, MERGE};

public: // Constructors and destructor

    /**Constructs new empty CSG object.
      *@param t type of set operation between members of the new CSG
      */
    CSG(csgtype t): listrefcount(new int(1)), /*inverserefcount(0),*/
      objectlist(new vector<Object3D*>),
      /*inverselist(0),*/ type(t), isclosed(false) {}
    
    ~CSG();

private:
    /**Copy constructor.
      */
    CSG(const CSG& c);

public: // Public methods

    /**Add object to CSG member list.
      */
    void addObject(Object3D* o);

    /**Finish CSG object list creation. After calling this method no more
      *object can be added to this CSG.
      */
    void close();

    // Inherited from Object3D
    void inverse();
    void prepareToRender();
    Object3D* duplicate() const;
    
    void listInside(const Vector3& location, InsideList& l) const;
    Intersection* intersectUnBounded(const Ray &r);
    Intersection* intersectUnBounded(const Ray &r, DBL maxtime);
    bool isInsideAt(const Vector3 &locallocation) const;

private: // Static members

    /**Intersection statistics.
      */
    static HitStatistics stat;

private: // Private methods
    /**Calculates and creates a bounding box for the CSG if it is finit.
      */
    void calculateBoundingBox();

private: // Private inner classes

    /**One element of intersection queue.
      */
    class Node{
    public: // Public attributes
        Intersection* intersection;
        DBL time;
        Object3D* object;

    public: // Constructors
        Node() {}
        Node(Intersection* i, DBL t, Object3D* o): intersection(i), time(t), object(o) {}
    };

    /**Describes Ray-CSG intersection.
      */
    class CSGIntersection: public Intersection {
    public: // Public attributes
        vector<Node> nodelist;
        int listsize;
    private: // Private attributes
        const CSG* parent;
        DBL tmax;

    public: // Constructors and destructor
        CSGIntersection(const CSG* p, const Ray& r, DBL maxtime):
          Intersection(0, r), listsize(0), parent(p)/*, shoot(r)*/, tmax(maxtime) {
              
            // init empty heap (the index 0 is not used but we need to create it)
            nodelist.push_back(Node());
            
        }

        ~CSGIntersection();

    public: // Public methods
        // Inherited from Intersection
        DBL currentTime() {return nodelist[1].time;}
        void next();
        Vector3 normal();
        Texture* texture();

        /**Check if head node is OK.
          */
        bool checkHead();

        /**Initialize heap structure.
          */
        void initListStructure();
    
    };

private: // Private attributes
public: // should be private but gcc 2.95 does not allow outer classes to access private inner members
    int* listrefcount;
//    int* inverserefcount;    
    vector<Object3D*> *objectlist;
//    vector<Object3D*> *inverselist;
    csgtype type;
    bool isclosed;
  
};

#endif



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