コード例 #1
0
int
dev_view(			/* assign new driver view */
	VIEW	*nv
)
{
	if (nv->type == VT_PAR ||		/* check view legality */
			nv->horiz > 160. || nv->vert > 160.) {
		error(COMMAND, "illegal view type/angle");
		nv->type = odev.v.type;
		nv->horiz = odev.v.horiz;
		nv->vert = odev.v.vert;
		return(0);
	}
	if (nv->vfore > FTINY) {
		error(COMMAND, "cannot handle fore clipping");
		nv->vfore = 0.;
		return(0);
	}
	if (nv != &odev.v) {
		if (!FEQ(nv->horiz,odev.v.horiz) ||	/* resize window? */
				!FEQ(nv->vert,odev.v.vert)) {
			int	dw = DisplayWidth(ourdisplay,ourscreen);
			int	dh = DisplayHeight(ourdisplay,ourscreen);

			dw -= 25;	/* for window frame */
			dh -= 50;
			odev.hres = 2.*VIEWDIST/pwidth *
					tan(PI/180./2.*nv->horiz);
			odev.vres = 2.*VIEWDIST/pheight *
					tan(PI/180./2.*nv->vert);
			if (odev.hres > dw) {
				odev.vres = dw * odev.vres / odev.hres;
				odev.hres = dw;
			}
			if (odev.vres > dh) {
				odev.hres = dh * odev.hres / odev.vres;
				odev.vres = dh;
			}
			XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
			dev_input();	/* get resize event */
		}
		odev.v = *nv;
	}
	if (nxtzmax > FTINY) {
		curzmax = nxtzmax;
		nxtzmax = 0.;
	}
	glClear(GL_DEPTH_BUFFER_BIT);
	qtReplant();
	return(1);
}
コード例 #2
0
HostMatrix<float> RadialBasisFunction::Test(HostMatrix<float> &Input){

	DeviceMatrix<float> dev_input(Input);

	DeviceMatrix<float> device_activ_matrix(dev_input.Rows(),dCenters.Rows(),ColumnMajor);

	KernelActivationMatrix(device_activ_matrix.Pointer(),dev_input.Pointer(),dCenters.Pointer(),dev_input.Columns(),dCenters.Columns(),device_activ_matrix.Columns(),device_activ_matrix.Rows(),scaling_factor,device_c_width.Pointer());

	DeviceMatrix<float> d_Output(device_activ_matrix.Rows(),dWeights.Columns(),ColumnMajor);
	device_activ_matrix.Multiply(device_activ_matrix,dWeights,d_Output);
	HostMatrix<float> Output(d_Output);

	return Output;	
}
コード例 #3
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
static int
dev_view(			/* assign new driver view */
	register VIEW	*nv
)
{
	int	newhres = hres, newvres = vres;
	double	wa, va;
					/* check view legality */
	if (nv->type != VT_PER) {
		error(COMMAND, "illegal view type");
		nv->type = VT_PER;
	}
	if ((nv->horiz > 160.) | (nv->vert > 160.)) {
		error(COMMAND, "illegal view angle");
		if (nv->horiz > 160.)
			nv->horiz = 160.;
		if (nv->vert > 160.)
			nv->vert = 160.;
	}
	if ((hres != 0) & (vres != 0)) {
		wa = (vres*pheight)/(hres*pwidth);
		va = viewaspect(nv);
		if (va > wa+.05) {
			newvres = (pwidth/pheight)*va*newhres + .5;
			if (newvres > maxvres) {
				newvres = maxvres;
				newhres = (pheight/pwidth)/va*newvres + .5;
			}
		} else if (va < wa-.05) {
			newhres = (pheight/pwidth)/va*newvres + .5;
			if (newhres > maxhres) {
				newhres = maxhres;
				newvres = (pwidth/pheight)*va*newhres + .5;
			}
		}
		if ((newhres != hres) | (newvres != vres)) {
			no_render++;
			XResizeWindow(ourdisplay, gwind, newhres, newvres);
			do
				dev_input(0);		/* get resize event */
			while ((newhres != hres) | (newvres != vres));
			no_render--;
		}
	}
	thisview = *nv;
	setglpersp(&thisview);
	render();
	return(1);
}
コード例 #4
0
void
dev_open(
	char  *id
)
{
	extern char	*getenv();
	static RGBPRIMS	myprims = STDPRIMS;
	static int	atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
				GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
				GLX_DEPTH_SIZE,15, None};
	char	*ev;
	double	gamval = GAMMA;
	RGBPRIMP	dpri = stdprims;
	XSetWindowAttributes	ourwinattr;
	XWMHints	ourxwmhints;
	XSizeHints	oursizhints;
					/* set quadtree globals */
	qtMinNodesiz = 3;
	qtDepthEps = 0.07;
					/* open display server */
	ourdisplay = XOpenDisplay(NULL);
	if (ourdisplay == NULL)
		error(USER, "cannot open X-windows; DISPLAY variable set?\n");
					/* find a usable visual */
	ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
	if (ourvinf == NULL)
		error(USER, "no suitable visuals available");
					/* get a context */
	gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
					/* set gamma and tone mapping */
	if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
			|| (ev = getenv("DISPLAY_GAMMA")) != NULL)
		gamval = atof(ev);
	if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
			sscanf(ev, "%f %f %f %f %f %f %f %f",
				&myprims[RED][CIEX],&myprims[RED][CIEY],
				&myprims[GRN][CIEX],&myprims[GRN][CIEY],
				&myprims[BLU][CIEX],&myprims[BLU][CIEY],
				&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
		dpri = myprims;
	tmGlobal = tmInit(mytmflags(), dpri, gamval);
	if (tmGlobal == NULL)
		error(SYSTEM, "not enough memory in dev_open");
					/* open window */
	ourwinattr.background_pixel = ourblack;
	ourwinattr.border_pixel = ourblack;
	ourwinattr.event_mask = ourmask;
					/* this is stupid */
	ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
				ourvinf->visual, AllocNone);
	gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
		DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
		DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
		BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
		CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
	if (gwind == 0)
		error(SYSTEM, "cannot create window\n");
   	XStoreName(ourdisplay, gwind, id);
					/* set window manager hints */
	ourxwmhints.flags = InputHint|IconPixmapHint;
	ourxwmhints.input = True;
	ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
			gwind, x11icon_bits, x11icon_width, x11icon_height);
	XSetWMHints(ourdisplay, gwind, &ourxwmhints);
	oursizhints.min_width = MINWIDTH;
	oursizhints.min_height = MINHEIGHT;
	oursizhints.flags = PMinSize;
	XSetNormalHints(ourdisplay, gwind, &oursizhints);
					/* set GLX context */
	glXMakeCurrent(ourdisplay, gwind, gctx);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glShadeModel(GL_FLAT);
	glDisable(GL_DITHER);
	glDisable(GL_CULL_FACE);
	glMatrixMode(GL_PROJECTION);
	glOrtho(0., 1., 0., 1., -.01, 1.01);
	glTranslated(0., 0., -1.01);
					/* figure out sensible view */
	pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
			DisplayWidth(ourdisplay, ourscreen);
	pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
			DisplayHeight(ourdisplay, ourscreen);
	odev.v = stdview;
	odev.v.type = VT_PER;
					/* map the window */
	XMapWindow(ourdisplay, gwind);
	dev_input();			/* sets size and view angles */
					/* allocate our leaf pile */
	if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
			DisplayHeight(ourdisplay,ourscreen) * 3 /
			(qtMinNodesiz*qtMinNodesiz*2)))
		error(SYSTEM, "insufficient memory for value storage");
	odev.name = id;
	odev.ifd = ConnectionNumber(ourdisplay);
					/* initialize cone array */
	initcones();
}
コード例 #5
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
static void
dev_open(			/* initialize GLX driver */
	char  *id
)
{
	static int	atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4,
				GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4,
				GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None};
	XSetWindowAttributes	ourwinattr;
	XWMHints	ourxwmhints;
					/* open display server */
	ourdisplay = XOpenDisplay(NULL);
	if (ourdisplay == NULL)
		error(USER, "cannot open X-windows; DISPLAY variable set?\n");
					/* find a usable visual */
	ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
	if (ourvinf == NULL)
		error(USER, "no suitable visuals available");
					/* get a context */
	gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
					/* open window */
	ourwinattr.background_pixel = ourblack;
	ourwinattr.border_pixel = ourblack;
	ourwinattr.event_mask = ourmask;
					/* this is stupid */
	ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
				ourvinf->visual, AllocNone);
	gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
		DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
		DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
		BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
		CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
	if (gwind == 0)
		error(SYSTEM, "cannot create window\n");
   	XStoreName(ourdisplay, gwind, id);
#ifndef NOSTEREO
	if (stereo)			/* check if stereo working */
		switch (XSGIQueryStereoMode(ourdisplay, gwind)) {
		case STEREO_TOP:
		case STEREO_BOTTOM:
			break;
		case STEREO_OFF:
			error(USER,
		"wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
		case X_STEREO_UNSUPPORTED:
			error(USER, "stereo not supported on this screen");
		default:
			error(INTERNAL, "unknown stereo mode");
		}
#endif
					/* set window manager hints */
	ourxwmhints.flags = InputHint|IconPixmapHint;
	ourxwmhints.input = True;
	ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind,
		(char *)glradicon_bits, glradicon_width, glradicon_height);
	XSetWMHints(ourdisplay, gwind, &ourxwmhints);
					/* set GLX context */
	glXMakeCurrent(ourdisplay, gwind, gctx);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	glShadeModel(GL_SMOOTH);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glEnable(GL_LIGHTING);
	glFrontFace(GL_CCW);
	glCullFace(GL_BACK);
	if (backvis)
		glDisable(GL_CULL_FACE);
	else
		glEnable(GL_CULL_FACE);
	glDrawBuffer(GL_BACK);
					/* figure out sensible view */
	pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
			DisplayWidth(ourdisplay, ourscreen);
	pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
			DisplayHeight(ourdisplay, ourscreen);
	if (stereo) {			/* set stereo mode */
		setstereobuf(STEREO_BUFFER_LEFT);
		pheight *= 2.;
	}
					/* map the window */
	XMapWindow(ourdisplay, gwind);
	no_render++;
	do
		dev_input(0);		/* get resize event */
	while ((hres == 0) & (vres == 0));
	no_render--;
	rgl_checkerr("initializing GLX");
}
コード例 #6
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
int
main(
	int	argc,
	char	*argv[]
)
{
	char	*viewsel = NULL;
	long	vwintvl = 0;
	int	i;

	progname = argv[0];
	for (i = 1; i < argc && argv[i][0] == '-'; i++)
		switch (argv[i][1]) {
		case 'v':
			viewsel = argv[++i];
			break;
		case 'w':
			nowarn = !nowarn;
			break;
		case 's':
			silent = !silent;
			break;
		case 'S':
			stereo = !stereo;
			break;
		case 'c':
			vwintvl = atoi(argv[++i]);
			break;
		case 'b':
			backvis = !backvis;
			break;
		default:
			goto userr;
		}
	if (i >= argc)
		goto userr;
#ifdef NOSTEREO
	if (stereo)
		error(INTERNAL, "stereo not supported in this version");
#endif
					/* run rad and get views */
	runrad(argc-i, argv+i);
					/* check view */
	if (viewsel != NULL) {
		if (viewsel[0] == '-') {
			char	*ve = viewsel;
			if (!sscanview(&thisview, viewsel) ||
					(ve = setview(&thisview)) != NULL) {
				fprintf(stderr, "%s: bad view: %s\n",
						progname, ve);
				quit(1);
			}
			currentview = -1;
		} else if ((currentview = findvw(viewsel)) < 0) {
			fprintf(stderr, "%s: no such view: %s\n",
						progname, viewsel);
			quit(1);
		}
	}
					/* open GL */
	dev_open(radfile = argv[i]);
					/* load octree or scene files */
	if (octree != NULL) {
		displist = rgl_octlist(octree, NULL, NULL, NULL);
		startrtrace(octree);
	} else
		displist = rgl_filelist(nscenef, scene, NULL);
					/* set initial view */
	dev_view(currentview < 0 ? &thisview : vwl[currentview].v);
					/* input/render loop */
	while (dev_input(vwintvl))
		;
					/* all done */
	quit(0);
userr:
	fprintf(stderr,
		"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n",
			argv[0]);
	quit(1);
	return 1; /* pro forma return */
}
コード例 #7
0
ファイル: rhdisp.c プロジェクト: Pizookies/Radiance
int
main(
	int	argc,
	char	*argv[]
)
{
	int	rdy, inp, res = 0, pause = 0;

	progname = argv[0];
	if (argc < 3)
		error(USER, "bad command line arguments");
					/* open our device */
	dev_open(argv[1]);
					/* open server process i/o */
	sstdout = fdopen(atoi(argv[2]), "w");
	if (argc < 4 || (inp = atoi(argv[3])) < 0)
		sstdin = NULL;
	else
		sstdin = fdopen(inp, "r");
					/* set command error vector */
	erract[COMMAND].pf = eputs;
#ifdef DEBUG
	tmodesw = time(NULL);
#endif
					/* enter main loop */
	do {
		rdy = disp_wait();
		if (rdy & RDY_SRV) {		/* process server result */
			res = serv_result();
			if (pause && res != DS_SHUTDOWN) {
				serv_request(DR_ATTEN, 0, NULL);
				while ((res = serv_result()) != DS_ACKNOW &&
						res != DS_SHUTDOWN)
					;
			}
		}
		if (rdy & RDY_DEV) {		/* user input from driver */
			inp = dev_input();
			if (inp & DFL(DC_SETVIEW))
				new_view(&odev.v);
			else if (inp & DFL(DC_LASTVIEW))
				new_view(NULL);
			if (inp & DFL(DC_REDRAW))
				imm_mode = beam_sync(1) > 0;
			if (inp & DFL(DC_GETVIEW))
				printview();
			if (inp & DFL(DC_FOCUS))
				set_focus(odev_args);
			if (inp & DFL(DC_KILL)) {
				serv_request(DR_KILL, 0, NULL);
				pause = 0;
			}
			if (inp & DFL(DC_CLOBBER))
				serv_request(DR_CLOBBER, 0, NULL);
			if (inp & DFL(DC_RESTART)) {
				serv_request(DR_RESTART, 0, NULL);
				pause = 0;
			}
			if (inp & DFL(DC_RESUME)) {
				serv_request(DR_NOOP, 0, NULL);
				pause = 0;
			}
			if (inp & DFL(DC_PAUSE))
				pause = 1;
			if (inp & DFL(DC_QUIT))
				serv_request(DR_SHUTDOWN, 0, NULL);
		}
		if (rdy & RDY_SIN && !imm_mode)	/* user input from sstdin */
			switch (usr_input()) {
			case DC_PAUSE:
				pause = 1;
				break;
			case DC_RESUME:
				serv_request(DR_NOOP, 0, NULL);
				/* fall through */
			case DC_KILL:
			case DC_RESTART:
				pause = 0;
				break;
			}
	} while (res != DS_SHUTDOWN);
#ifdef DEBUG
	if (timm && nimmrays)
		fprintf(stderr,
			"%s: %.1f rays recalled/second (%ld rays total)\n",
				progname, (double)nimmrays/timm, nimmrays);
	if (tadd && naddrays)
		fprintf(stderr,
			"%s: %.1f rays calculated/second (%ld rays total)\n",
				progname, (double)naddrays/tadd, naddrays);
#endif
					/* all done */
	quit(0);
	return 0; /* pro forma return */
}
コード例 #8
0
int main()
{
    try {
        std::vector<cl::Device> devices;

        // select platform
        cl::Platform platform = selectPlatform();

        // select device
        platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
        cl::Device device = selectDevice(devices);

        // create context
        context = cl::Context(devices);

        // create command queue
        queue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);

        // load opencl source
        std::ifstream cl_file("inclusive_scan.cl");

        std::string cl_string{std::istreambuf_iterator<char>(cl_file),
                    std::istreambuf_iterator<char>()};

        cl::Program::Sources source(1,
                                    std::make_pair(cl_string.c_str(),
                                                   cl_string.length() + 1));

        // create programm
        program = cl::Program(context, source);

        // compile opencl source
        try {
            program.build(devices);

            size_t input_size;
            std::ifstream input_file("input.txt");
            input_file >> input_size;

            std::vector<float> input(input_size);

//            for (size_t i = 0; i < input_size; ++i) {
//                input[i] = i % 10;
//            }

            for (int i = 0; i < input_size; i++) {
                input_file >> input[i];
            }

            std::vector<float> output(input_size, 0);

            cl::Buffer dev_input (context, CL_MEM_READ_ONLY, sizeof(float) * input_size);
            queue.enqueueWriteBuffer(dev_input, CL_TRUE, 0, sizeof(float) * input_size, &input[0]);

            cl::Buffer dev_output = inclusive_scan(dev_input, input_size);

            queue.enqueueReadBuffer(dev_output, CL_TRUE, 0, sizeof(float) * input_size, &output[0]);
            queue.finish();

            cpu_check(input, output);

            std::ofstream output_file("output.txt");
            for (int i = 0; i < input_size; i++) {
                output_file << output[i] << " ";
            }

        }
        catch (cl::Error const & e) {
            std::string log_str = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
            std::cout << std::endl << e.what() << " : " << e.err() << std::endl;
            std::cout << log_str;
            return 0;
        }


    }
    catch (cl::Error const & e) {
        std::cout << "Error: " << e.what() << " #" << e.err() << std::endl;
    }

    return 0;
}