00001 /*
00002 File: RadMethod.h
00003
00004 Function: Defines a base class for all radiosity scene-illumination
00005 implementations.
00006
00007 Author(s): Andrew Willmott
00008
00009 Copyright: (c) 1997-2000, Andrew Willmott
00010 */
00011
00012
00013 #ifndef __Rad__
00014 #define __Rad__
00015
00016 #include "RadControl.h"
00017 #include "RadMesh.h"
00018 #include "RT_Grid.h"
00019
00020 #include "gcl/Scene.h"
00021 #include "cl/Timer.h"
00022 #include "cl/String.h"
00023
00024 #ifdef RAD_VIS
00025 #include "gcl/Forms.h"
00026 #include "gcl/ScenePane.h"
00027 #endif
00028
00029 class XGraphicsSystem;
00030
00031 class RadAttributes
00032 {
00033 public:
00034 RadAttributes();
00035
00036 ColourList *colours;
00037 PointList *points;
00038 VectorList *normals;
00039 CoordList *texCoords;
00040 };
00041
00042 class RadMethod : public RadAttributes
00044 {
00045 public:
00046 RadMethod();
00047 virtual ~RadMethod();
00048
00049 static RadMethod *NewRadMethod();
00050
00051 virtual Void SetScene(scScenePtr scene);
00053 virtual Void ResetOptions();
00055 virtual Bool Render();
00057 virtual Void RemoveDirect();
00059
00060 Void Print(ostream &s) const;
00061 Void Parse(istream &s);
00062 virtual Void PrintCmds(ostream &s) const;
00063 virtual Bool ParseCmd(StrConst str, istream &s);
00064
00065 virtual Void Draw(Renderer &r);
00066
00067 virtual Void DrawMatrix(Renderer &r);
00068
00069 virtual RadElem *NewMesh() = 0;
00071 virtual PatchList *GetElements();
00075 virtual Int Stage(Int stage);
00077 virtual Bool Idle();
00079 virtual Bool Pause();
00081
00082 Void DumpScene();
00083 virtual Void DumpStats() = 0;
00084 Bool CheckTime();
00085
00086 #ifdef RAD_VIS
00087 Void RenderMatrix();
00088
00089 Void StartUpdate();
00090 Bool Update();
00091 Void UpdateCont();
00092 #endif
00093
00094 Void WriteSLFile(StrConst filename);
00096 Void WriteObjFile(StrConst filename);
00098 Void WriteMRBFile(StrConst filename);
00099
00100 Int TotalMemoryUse();
00102
00103 // --- Raytracing -------------------------------------------------------------
00104
00105 Void CreateRTGrid(scScenePtr scene);
00106 virtual Void CreateRTObjects(scScenePtr scene);
00107 Bool IntersectsWithRay(const Point &start, const Point &end);
00108 virtual RadElem *ClosestIntersection(
00109 const Point &start,
00110 const Vector &direction,
00111 Point &hitPoint
00112 );
00113
00114 RT_Grid *grid;
00115 RT_Object *object;
00116 Int rtID;
00117
00118 // ----------------------------------------------------------------------------
00119
00120 Void SetupMesh();
00121 Void FixMesh();
00122 Void ConnectMesh();
00123 Void FindBounds(Point &min, Point &max);
00124 Void ColourMeshInitial();
00126 virtual Void ColourVertices();
00128
00129 Void AssignNormals();
00130 Void CreatePatches();
00131 Void Reanimate();
00132
00133 Void AddQuadTri(
00134 Int numVertices,
00135 Int vertices[],
00136 Int changed,
00137 Decimator *state
00138 );
00139
00140 Void SetupProps(RadProps *props, Decimator *state);
00141
00142 scScenePtr GetScene();
00143
00144 // ----------------------------------------------------------------------------
00145
00146 // fields
00147 PatchList baseElems;
00148 RadProps *props;
00149 Int numProps;
00150 Point min, max;
00151 FindDecInfo qtInfo;
00152
00153 PatchList patches;
00154 PatchStats stats;
00155 ProgramTimer timer;
00156 Int dumpID;
00157 GCLReal totTime;
00158 GCLReal lastTime;
00159
00160 #ifdef RAD_VIS
00161 // visual stuff
00162 Void SetDisplay(ScenePane *displayIn, XGraphicsSystem *gspIn)
00163 { display = displayIn; gsP = gspIn; };
00164
00165 XGraphicsSystem *gsP;
00166 ScenePane *display;
00167 ScenePane *matDisplay;
00168 Bool doUpdate;
00169 GCLReal nextUpdate;
00170 FL_OBJECT *out1, *out2, *out3;
00171 WallClockTimer utimer;
00172 PatchList rtElemPtrs;
00173 #endif
00174
00175 protected:
00176 scScenePtr scene;
00177 String sceneName;
00178 };
00179
00180
00181 #ifdef RAD_VIS
00182
00183 // For the visualisation build.
00184 #define RM_IDLE gRadControl->radObject->Idle()
00185 #define RM_PAUSE gRadControl->radObject->Pause()
00186 #define RM_OUT1(X) Field((gRadControl->radObject)->out1) << X << show
00187 #define RM_OUT2(X) Field((gRadControl->radObject)->out2) << X << show
00188 #define RM_OUT3(X) Field((gRadControl->radObject)->out3) << X << show
00189 #define RM_DISPLAY_SCENE (gRadControl->radObject->display->Redraw())
00190 #define RM_DISPLAY_START (gRadControl->radObject->display->Clear() \
00191 .Draw(gRadControl->radObject->display->ItsScene())) \
00192 .SetCamera(*gRadControl->radObject->display->ItsCamera())
00193
00194 #define RM_DISPLAY_END (gRadControl->radObject->display->Show())
00195
00196 #else
00197
00198 // For the stand-alone build
00199 #define RM_IDLE ((RadMethod *) gRadControl->radObject)->Idle()
00200 #define RM_PAUSE ((RadMethod *) gRadControl->radObject)->Pause()
00201 #ifdef RAD_DEBUG
00202 #define RM_OUT1(X) cout << "1- " << X << endl;
00203 #define RM_OUT2(X) cout << "2- " << X << endl;
00204 #define RM_OUT3(X) cout << "3- " << X << endl;
00205 #else
00206 #define RM_OUT1(X)
00207 #define RM_OUT2(X)
00208 #define RM_OUT3(X)
00209 #endif
00210 #define RM_DISPLAY_SCENE
00211 #define RM_DISPLAY_START
00212 #define RM_DISPLAY_END
00213
00214 #endif
00215
00216 #endif