00001 /*
00002 File: AnaRad.cc
00003
00004 Function: See header file
00005
00006 Author(s): Andrew Willmott
00007
00008 Copyright: (c) 1997-2000, Andrew Willmott
00009
00010 Notes:
00011
00012 */
00013
00014 #include "AnaRad.h"
00015 #include "AnaMesh.h"
00016 #ifdef RAD_VIS
00017 #include "gcl/Forms.h"
00018 #endif
00019
00020 Bool AnaRad::Render()
00021 // Returns true if no interruptions.
00022 {
00023 Int i, j;
00024 Colour patchIrr;
00025 GCLReal save;
00026 GCLReal sumArea, sumAF, sumAFLog, patchFactor;
00027 Point p;
00028 Vector n;
00029
00030 RadMethod::Render();
00031
00032 lights.Clear();
00033 if (!gRadControl->patchView)
00034 for (j = 0; j < baseElems.NumItems(); j++)
00035 if (len(baseElems[j]->Emittance()) > 0) // A light!
00036 lights.Append(baseElems[j]);
00037
00038 gRadControl->jitterRot = false;
00039 sumArea = 0.0;
00040 sumAF = 0.0;
00041 sumAFLog = 0.0;
00042 theMI = 0.0;
00043
00044 Stage(1);
00045
00046 for (i = 0; i < patches.NumItems(); i++)
00047 {
00048 p = patches[i]->Centre();
00049 n = patches[i]->Normal();
00050
00051 patchIrr = cBlack;
00052 sumArea += patches[i]->area;
00053
00054 if (lights.NumItems() > 0)
00055 {
00056 for (j = 0; j < lights.NumItems(); j++)
00057 {
00058 patchFactor = lights[j]->PatchFactor(p, n);
00059 if (patchFactor > 0)
00060 patchFactor *= lights[j]->Visibility(patches[i]);
00061
00062 sumAF += patches[i]->area * patchFactor;
00063 sumAFLog += patches[i]->area * patchFactor *
00064 log(patchFactor / lights[j]->area);
00065
00066 patchIrr += patchFactor * lights[j]->Emittance();
00067 }
00068 }
00069 else
00070 {
00071 for (j = 0; j < patches.NumItems(); j++)
00072 {
00073 patchFactor = patches[j]->PatchFactor(p, n);
00074 if (patchFactor > 0)
00075 patchFactor *= patches[j]->Visibility(patches[i]);
00076
00077 sumAF += patches[i]->area * patchFactor;
00078 sumAFLog += patches[i]->area * patchFactor *
00079 log(patchFactor / patches[j]->area);
00080
00081 patchIrr += patchFactor * patches[j]->Emittance();
00082 }
00083 }
00084
00085 patches[i]->SetColour(patches[i]->Emittance() +
00086 patches[i]->Reflectance() * patchIrr);
00087 }
00088
00089 cout << sumAFLog << ", " << sumAF << ", " << sumArea << endl;
00090 theMI = (sumAFLog + sumAF * log(sumArea)) / sumArea;
00091
00092 Stage(2);
00093
00094 return(0);
00095 }
00096
00097 RadElem *AnaRad::NewMesh()
00098 {
00099 return(new AnaGrid);
00100 }
00101
00102 #ifdef RAD_VIS
00103
00104 Void AnaRad::DumpStats(){}
00105
00106 Int AnaRad::Stage(Int stage)
00107 {
00108 switch (stage)
00109 {
00110 case 1:
00111 break;
00112 case 2:
00113 ColourVertices();
00114 display->Redraw();
00115 Field(out1) << "Mutual Information: " << theMI << show;
00116 Field(out2) << "illum patches: " << lights.NumItems()
00117 << " patches:" << patches.NumItems() << show;
00118 Field(out3) << "Rays: " << gRadControl->rays << show;
00119 break;
00120 }
00121
00122 if (Pause()) return(1);
00123
00124 return(0);
00125 }
00126
00127 #else
00128
00129 Void AnaRad::DumpStats()
00130 {
00131 cout << dumpID
00132 << ' ' << totTime
00133 << ' ' << gRadControl->stage
00134 << ' ' << lights.NumItems()
00135 << ' ' << patches.NumItems()
00136 << ' ' << gRadControl->rays
00137 << ' ' << theMI
00138 << endl;
00139
00140 DumpScene();
00141 }
00142
00143 Int AnaRad::Stage(Int stage)
00144 {
00145 if (CheckTime()) return(1);
00146
00147 gRadControl->stage = stage;
00148
00149 switch (stage)
00150 {
00151 case 1: // pre setup
00152 cout << "method ana " << endl;
00153 cout << "sub " << gRadControl->patchSubdivs << endl;
00154 cout << "scene " << sceneName << endl;
00155 cout << "format ID time stage illumPatches patches rays MI" << endl;
00156 cout << "-------------------------------------------------" << endl;
00157
00158 DumpStats();
00159 break;
00160
00161 case 2:
00162 DumpStats();
00163 break;
00164
00165 default:
00166 break;
00167 }
00168
00169 if (Idle()) return(0);
00170 timer.ContTimer();
00171 return(0);
00172 }
00173
00174 #endif
00175