📄 svmarine.c
字号:
#include <vg.h>
#include <vgperf.h>
#include <vgfx.h>
#include <vgmarine.h>
#include <vgsv.h>
#include <pf.h>
#include <prmath.h>
static void getInput(void);
static void postDrawCB(vgSVSensor *svsensor, vgChannel *channel);
void main(int argc, char *argv[])
{
/* initialize vega, marine, and sv */
vgInitSys();
vgInitFx();
vgInitMarine();
vgInitSV();
/* define and configure vega */
vgDefineSys(argv[1]);
vgConfigSys();
/* disable the ephemeris time update so we can update the tod manually */
vgProp(vgGetEnvfx(0), VGEPHEM_TIMEMULT, VG_OFF);
/* execute the main simulation loop */
while (1) {
vgSyncFrame();
vgFrame();
getInput();
}
}
static void getInput(void)
{
int ival, key;
float fval;
/* process keyboard input */
while ((key = vgGetWinKey(vgGetWin(0))) != 0) {
switch (key) {
case '1': /* enable / disable ambient skyshine reflection */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT);
if (ival & VGSVSENSOR_AMBIENT)
ival &= ~VGSVSENSOR_AMBIENT;
else ival |= VGSVSENSOR_AMBIENT;
vgProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT, ival);
break;
case '2': /* enable / disable diffuse solar / lunar reflection */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT);
if (ival & VGSVSENSOR_DIFFUSE)
ival &= ~VGSVSENSOR_DIFFUSE;
else ival |= VGSVSENSOR_DIFFUSE;
vgProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT, ival);
break;
case '3': /* enable / disable specular solar / lunar reflection */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT);
if (ival & VGSVSENSOR_SPECULAR)
ival &= ~VGSVSENSOR_SPECULAR;
else ival |= VGSVSENSOR_SPECULAR;
vgProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT, ival);
break;
case '4': /* enable / disable thermal emission */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT);
if (ival & VGSVSENSOR_THERMAL)
ival &= ~VGSVSENSOR_THERMAL;
else ival |= VGSVSENSOR_THERMAL;
vgProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT, ival);
break;
case '5': /* enable / disable path emission and scattering */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT);
if (ival & VGSVSENSOR_PATH)
ival &= ~VGSVSENSOR_PATH;
else ival |= VGSVSENSOR_PATH;
vgProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT, ival);
break;
case '6': /* enable / disable transmission */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT);
if (ival & VGSVSENSOR_TRANSMISSION)
ival &= ~VGSVSENSOR_TRANSMISSION;
else ival |= VGSVSENSOR_TRANSMISSION;
vgProp(vgGetSVSensor(0), VGSVSENSOR_COMPONENT, ival);
break;
case ' ': /* enable / disable the sensor */
if (vgGetSVSensorObserv(vgGetSVSensor(0)) == NULL)
vgSVSensorObserv(vgGetSVSensor(0), vgGetObserv(0));
else vgSVSensorObserv(vgGetSVSensor(0), NULL);
break;
case 'b': /* enable / disable black hot */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_BLACKHOT);
vgProp(vgGetSVSensor(0), VGSVSENSOR_BLACKHOT, !ival);
break;
case 'd': /* decrease the time of day */
fval = vgGetProp(vgGetEnvfx(0), VGEPHEM_CURRENTTIME) - 0.05f;
if (fval < 0) fval += 24.0f;
vgProp(vgGetEnvfx(0), VGEPHEM_CURRENTTIME, fval);
break;
case 'D': /* increase the time of day */
fval = vgGetProp(vgGetEnvfx(0), VGEPHEM_CURRENTTIME) + 0.05f;
if (fval > 24) fval -= 24.0f;
vgProp(vgGetEnvfx(0), VGEPHEM_CURRENTTIME, fval);
break;
case 'f': /* enable / disable fog */
ival = (int) vgGetProp(vgGetGfx(0), VGGFX_FOG);
vgProp(vgGetGfx(0), VGGFX_FOG, !ival);
break;
case 'g': /* decrease the gain */
fval = vgGetProp(vgGetSVSensor(0), VGSVSENSOR_GAIN);
vgProp(vgGetSVSensor(0), VGSVSENSOR_GAIN, fval - 0.1f);
break;
case 'G': /* increase the gain */
fval = vgGetProp(vgGetSVSensor(0), VGSVSENSOR_GAIN);
vgProp(vgGetSVSensor(0), VGSVSENSOR_GAIN, fval + 0.1f);
break;
case 'l': /* enable / disable lighting */
ival = (int) vgGetProp(vgGetGfx(0), VGGFX_LIGHTING);
vgProp(vgGetGfx(0), VGGFX_LIGHTING, !ival);
break;
case 'i': /* get framebuffer contents and bring up saoimage */
vgAddFunc(vgGetSVSensor(0), VGSVSENSOR_POSTDRAW,
(vgCallback *) postDrawCB, vgGetChan(0));
break;
case 'o': /* decrease the offset */
fval = vgGetProp(vgGetSVSensor(0), VGSVSENSOR_OFFSET);
vgProp(vgGetSVSensor(0), VGSVSENSOR_OFFSET, fval - 0.1f);
break;
case 'O': /* increase the offset */
fval = vgGetProp(vgGetSVSensor(0), VGSVSENSOR_OFFSET);
vgProp(vgGetSVSensor(0), VGSVSENSOR_OFFSET, fval + 0.1f);
break;
case 'p': /* print the contents of the sensor */
vgPrint(vgGetSVSensor(0));
break;
case 's': /* select the statistics mode */
ival = ((int) vgGetProp(vgGetChan(0), VGCHAN_STATSSEL)) + 1;
if (ival > VGCHAN_FILL) ival = VGCHAN_STATSOFF;
vgProp(vgGetChan(0), VGCHAN_STATSSEL, ival);
break;
case 'S': /* select the solution method */
ival = (int) vgGetProp(vgGetSVSensor(0), VGSVSENSOR_SOLUTION);
if (ival == VGSVSENSOR_REFLECTION)
ival = VGSVSENSOR_EMISSION;
else if (ival == VGSVSENSOR_EMISSION)
ival = VGSVSENSOR_REFLECTION | VGSVSENSOR_EMISSION;
else ival = VGSVSENSOR_REFLECTION;
vgProp(vgGetSVSensor(0), VGSVSENSOR_SOLUTION, ival);
break;
case 't': /* enable / disable texture */
ival = (int) vgGetProp(vgGetGfx(0), VGGFX_TEXTURE);
vgProp(vgGetGfx(0), VGGFX_TEXTURE, !ival);
break;
case 'T': /* enable / disable transparency */
ival = (int) vgGetProp(vgGetGfx(0), VGGFX_TRANSPARENCY);
vgProp(vgGetGfx(0), VGGFX_TRANSPARENCY, !ival);
break;
case 'w': /* enable / disable wireframe */
ival = (int) vgGetProp(vgGetGfx(0), VGGFX_WIREFRAME);
vgProp(vgGetGfx(0), VGGFX_WIREFRAME, !ival);
break;
case 'x': /* enable / disable the motion model */
if (vgGetProp(vgGetMot(0), VGCOMMON_ENABLED))
vgProp(vgGetMot(0), VGCOMMON_ENABLED, VG_OFF);
else vgProp(vgGetMot(0), VGCOMMON_ENABLED, VG_ON);
break;
default: break;
}
}
}
static void postDrawCB(vgSVSensor *svsensor, vgChannel *channel)
{
char str[VG_MAXSTRING];
int wattsPerCm2 = VG_FALSE;
int i, band, ox, oy, sx, sy, numPixel, numBit, maxVal, ival;
float conv[3], convFact, *image, fval;
FILE *fp;
/* get the conversion factor used to convert from W/cm2/sr to color */
vgGetSVChanData(channel, VGSVCHAN_CONVFACT, conv);
/* make sure we copy pixels from a color band that's got some data */
if (conv[0] > 0) {
band = GL_RED;
convFact = conv[0];
glGetIntegerv(GL_RED_BITS, &numBit);
}
else if (conv[1] > 0) {
band = GL_GREEN;
convFact = conv[1];
glGetIntegerv(GL_GREEN_BITS, &numBit);
}
else if (conv[2] > 0) {
band = GL_BLUE;
convFact = conv[2];
glGetIntegerv(GL_GREEN_BITS, &numBit);
}
else {
vgNotify(VG_WARN, VG_APP, "all color bands are off");
return;
}
/* get the channel origin and size */
pfGetChanOrigin(vgGetPfChan(channel), &ox, &oy);
pfGetChanSize(vgGetPfChan(channel), &sx, &sy);
/* read the image from the frame buffer */
numPixel = sx * sy;
image = (float *) vgMalloc(numPixel * sizeof(float), vgGetSharedArena());
glReadPixels(ox, oy, sx, sy, band, GL_FLOAT, image);
/* if we want the data in W/cm2 instead of W/cm2/sr, we need to take */
/* the channel field of view into account */
if (wattsPerCm2 == VG_TRUE) {
float hfov, vfov;
vgGetChanFOV(channel, &hfov, &vfov);
convFact *= PF_DEG2RAD(PF_DEG2RAD((hfov / sx) * (vfov * sy)));
}
/* convert the pixel data to either W/cm2/sr or W/cm2 */
maxVal = ((int) pow(2.0f, numBit)) - 1;
for (i=0;i<numPixel;i++) {
ival = image[i] * maxVal;
fval = (ival + 0.5f) / maxVal;
image[i] = fval / convFact;
}
#ifndef WIN32
/* write the image to a file */
if ((fp = fopen("/usr/tmp/data.img", "w")) == NULL) {
vgNotify(VG_WARN, VG_APP, "unable to open file \"/usr/tmp/data.img\"");
return;
}
fwrite(image, sizeof(float), numPixel, fp);
fclose(fp);
vgFree(image);
/* run saoimage */
if (getenv("NUMCOLORLEVELS")) {
sprintf(str, "/usr/local/PSI/bin/saoimage -p %s -ll -r4 %d %d "
"/usr/tmp/data.img; " "/bin/rm -f /usr/tmp/data.img &",
getenv("NUMCOLORLEVELS"), sx, sy);
}
else {
sprintf(str, "/usr/local/PSI/bin/saoimage -ll -r4 %d %d "
"/usr/tmp/data.img; " "/bin/rm -f /usr/tmp/data.img &", sx, sy);
}
if (system(str) == -1)
vgNotify(VG_WARN, VG_APP, "unable to execute saoimage");
#endif
/* uninstall the callback */
vgDelFunc(svsensor, VGSVSENSOR_POSTDRAW, (vgCallback *) postDrawCB, channel);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -