
#ifndef _JL_RayCastNode_H_
#define _JL_RayCastNode_H_

#include <stdlib.h>
#include <iostream.h>

#include "bounds3d.h"

#include "raycastable.h"

class Vec4;
class Prim;
class Ray;

class RayCastNode;
typedef RayCastNode *RayCastNodePtr;

//class LinetreeRoot;

class RayCastNode : public RayCastable {

	protected:
		RayCastNode		*_parent;
		Bounds3d		_bounds3d;

	public: 
		RayCastNode();
		RayCastNode(RayCastNode *p, float, float, float, float, float, float);
		RayCastNode(RayCastNode *p, const Bounds3d &B);
		RayCastNode(const RayCastNode &R) { CopyFrom(R); }
		virtual ~RayCastNode();

		RayCastNode& CopyFrom(const RayCastNode&);
		RayCastNode& operator=(const RayCastNode &R) { return CopyFrom(R); }

//		virtual Prim* Copy() const = 0;
//		virtual const char* PrimName() const = 0;

//		virtual LinetreeRoot* GetLinetreeRoot() { return NULL; }

		RayCastNode* Parent() { return _parent; }
		Bounds3d& GetBounds3d() { return _bounds3d; }

		friend ostream& operator<<(ostream&, const RayCastNode&);
//		friend istream& operator>>(istream&, RayCastNode&);

		int BoundTest(const Vec4 &P, const Vec4 &D);

		virtual void PlaceRayCastable(RayCastable*) = 0;

		virtual int IntersectLinespace(const Ray &R1, const Ray &R2,
									   const Ray &R3, const Ray &R4,
									   const Vec4 &N1, const Vec4 &N2,
									   const Vec4 &N3, const Vec4 &N4) = 0;

		virtual void NormalAtPoint(const Vec4&, Vec4&) const {
				cerr << "Error: RayCastNode::NormalAtPoint() called!" << endl;
				exit(-1);
			}

  virtual const Bounds3d & bbox() const {return _bounds3d;}
};

#endif
