repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/grid.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * grid.cpp - spatial subdivision efficiency structures */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define GRID_PRIVATE #include "grid.h" #ifndef cbrt #define cbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/3.0) : \ ((x) < 0.0 ? -pow((double)-(x), 1.0/3.0) : 0.0)) #define qbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/4.0) : \ ((x) < 0.0 ? -pow((double)-(x), 1.0/4.0) : 0.0)) #endif static object_methods grid_methods = { (void (*)(void *, void *))(grid_intersect), (void (*)(void *, void *, void *, void *))(NULL), grid_bbox, grid_free }; extern bool silent_mode; object * newgrid(int xsize, int ysize, int zsize, vector min, vector max) { grid * g; g = (grid *) rt_getmem(sizeof(grid)); memset(g, 0, sizeof(grid)); g->methods = &grid_methods; g->id = new_objectid(); g->xsize = xsize; g->ysize = ysize; g->zsize = zsize; g->min = min; g->max = max; VSub(&g->max, &g->min, &g->voxsize); g->voxsize.x /= (flt) g->xsize; g->voxsize.y /= (flt) g->ysize; g->voxsize.z /= (flt) g->zsize; g->cells = (objectlist **) rt_getmem(xsize*ysize*zsize*sizeof(objectlist *)); memset(g->cells, 0, xsize*ysize*zsize * sizeof(objectlist *)); /* fprintf(stderr, "New grid, size: %8d %8d %8d\n", g->xsize, g->ysize, g->zsize); */ return (object *) g; } static int grid_bbox(void * obj, vector * min, vector * max) { grid * g = (grid *) obj; *min = g->min; *max = g->max; return 1; } static void grid_free(void * v) { int i, numvoxels; grid * g = (grid *) v; /* loop through all voxels and free the object lists */ numvoxels = g->xsize * g->ysize * g->zsize; for (i=0; i<numvoxels; i++) { objectlist * lcur, * ltemp; lcur = g->cells[i]; while (lcur != NULL) { ltemp = lcur; lcur = lcur->next; free(ltemp); } } /* free the grid cells */ free(g->cells); /* free all objects on the grid object list */ free_objects(g->objects); free(g); } static void globalbound(object ** rootlist, vector * gmin, vector * gmax) { vector min, max; object * cur; if (*rootlist == NULL) /* don't bound non-existant objects */ return; gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE; gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE; cur=*rootlist; while (cur != NULL) { /* Go! */ min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE; max.x = FHUGE; max.y = FHUGE; max.z = FHUGE; if (cur->methods->bbox((void *) cur, &min, &max)) { gmin->x = MYMIN( gmin->x , min.x); gmin->y = MYMIN( gmin->y , min.y); gmin->z = MYMIN( gmin->z , min.z); gmax->x = MYMAX( gmax->x , max.x); gmax->y = MYMAX( gmax->y , max.y); gmax->z = MYMAX( gmax->z , max.z); } cur=(object *)cur->nextobj; } } static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax) { vector min, max, cellmin, cellmax; objectlist * cur; int numinbounds = 0; cur = g->cells[index->z*g->xsize*g->ysize + index->y*g->xsize + index->x]; if (cur == NULL) /* don't bound non-existant objects */ return 0; cellmin.x = voxel2x(g, index->x); cellmin.y = voxel2y(g, index->y); cellmin.z = voxel2z(g, index->z); cellmax.x = cellmin.x + g->voxsize.x; cellmax.y = cellmin.y + g->voxsize.y; cellmax.z = cellmin.z + g->voxsize.z; cmin->x = FHUGE; cmin->y = FHUGE; cmin->z = FHUGE; cmax->x = -FHUGE; cmax->y = -FHUGE; cmax->z = -FHUGE; while (cur != NULL) { /* Go! */ min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE; max.x = FHUGE; max.y = FHUGE; max.z = FHUGE; if (cur->obj->methods->bbox((void *) cur->obj, &min, &max)) { if ((min.x >= cellmin.x) && (max.x <= cellmax.x) && (min.y >= cellmin.y) && (max.y <= cellmax.y) && (min.z >= cellmin.z) && (max.z <= cellmax.z)) { cmin->x = MYMIN( cmin->x , min.x); cmin->y = MYMIN( cmin->y , min.y); cmin->z = MYMIN( cmin->z , min.z); cmax->x = MYMAX( cmax->x , max.x); cmax->y = MYMAX( cmax->y , max.y); cmax->z = MYMAX( cmax->z , max.z); numinbounds++; } } cur=cur->next; } /* in case we get a 0.0 sized axis on the cell bounds, we'll */ /* use the original cell bounds */ if ((cmax->x - cmin->x) < EPSILON) { cmax->x += EPSILON; cmin->x -= EPSILON; } if ((cmax->y - cmin->y) < EPSILON) { cmax->y += EPSILON; cmin->y -= EPSILON; } if ((cmax->z - cmin->z) < EPSILON) { cmax->z += EPSILON; cmin->z -= EPSILON; } return numinbounds; } static int countobj(object * root) { object * cur; /* counts the number of objects on a list */ int numobj; numobj=0; cur=root; while (cur != NULL) { cur=(object *)cur->nextobj; numobj++; } return numobj; } //This is unused /* static int countobjlist(objectlist * root) { objectlist * cur; int numobj; numobj=0; cur = root; while (cur != NULL) { cur = cur->next; numobj++; } return numobj; } */ int engrid_scene(object ** list) { grid * g; int numobj, numcbrt; vector gmin, gmax; gridindex index; if (*list == NULL) return 0; numobj = countobj(*list); if ( !silent_mode ) fprintf(stderr, "Scene contains %d bounded objects.\n", numobj); if (numobj > 16) { numcbrt = (int) cbrt(4*numobj); globalbound(list, &gmin, &gmax); g = (grid *) newgrid(numcbrt, numcbrt, numcbrt, gmin, gmax); engrid_objlist(g, list); numobj = countobj(*list); g->nextobj = *list; *list = (object *) g; /* now create subgrids.. */ for (index.z=0; index.z<g->zsize; index.z++) { for (index.y=0; index.y<g->ysize; index.y++) { for (index.x=0; index.x<g->xsize; index.x++) { engrid_cell(g, &index); } } } } return 1; } void engrid_objlist(grid * g, object ** list) { object * cur, * next, **prev; if (*list == NULL) return; prev = list; cur = *list; while (cur != NULL) { next = (object *)cur->nextobj; if (engrid_object(g, cur)) *prev = next; else prev = (object **) &cur->nextobj; cur = next; } } static int engrid_cell(grid * gold, gridindex *index) { vector gmin, gmax, gsize; flt len; int numobj, numcbrt, xs, ys, zs; grid * g; objectlist **list; objectlist * newobj; list = &gold->cells[index->z*gold->xsize*gold->ysize + index->y*gold->xsize + index->x]; if (*list == NULL) return 0; numobj = cellbound(gold, index, &gmin, &gmax); VSub(&gmax, &gmin, &gsize); len = 1.0 / (MYMAX( MYMAX(gsize.x, gsize.y), gsize.z )); gsize.x *= len; gsize.y *= len; gsize.z *= len; if (numobj > 16) { numcbrt = (int) cbrt(2*numobj); xs = (int) ((flt) numcbrt * gsize.x); if (xs < 1) xs = 1; ys = (int) ((flt) numcbrt * gsize.y); if (ys < 1) ys = 1; zs = (int) ((flt) numcbrt * gsize.z); if (zs < 1) zs = 1; g = (grid *) newgrid(xs, ys, zs, gmin, gmax); engrid_objectlist(g, list); newobj = (objectlist *) rt_getmem(sizeof(objectlist)); newobj->obj = (object *) g; newobj->next = *list; *list = newobj; g->nextobj = gold->objects; gold->objects = (object *) g; } return 1; } static int engrid_objectlist(grid * g, objectlist ** list) { objectlist * cur, * next, **prev; int numsucceeded = 0; if (*list == NULL) return 0; prev = list; cur = *list; while (cur != NULL) { next = cur->next; if (engrid_object(g, cur->obj)) { *prev = next; free(cur); numsucceeded++; } else { prev = &cur->next; } cur = next; } return numsucceeded; } static int engrid_object(grid * g, object * obj) { vector omin, omax; gridindex low, high; int x, y, z, zindex, yindex, voxindex; objectlist * tmp; if (obj->methods->bbox(obj, &omin, &omax)) { if (!pos2grid(g, &omin, &low) || !pos2grid(g, &omax, &high)) { return 0; /* object is not wholly contained in the grid */ } } else { return 0; /* object is unbounded */ } /* add the object to the complete list of objects in the grid */ obj->nextobj = g->objects; g->objects = obj; /* add this object to all voxels it inhabits */ for (z=low.z; z<=high.z; z++) { zindex = z * g->xsize * g->ysize; for (y=low.y; y<=high.y; y++) { yindex = y * g->xsize; for (x=low.x; x<=high.x; x++) { voxindex = x + yindex + zindex; tmp = (objectlist *) rt_getmem(sizeof(objectlist)); tmp->next = g->cells[voxindex]; tmp->obj = obj; g->cells[voxindex] = tmp; } } } return 1; } static int pos2grid(grid * g, vector * pos, gridindex * index) { index->x = (int) ((pos->x - g->min.x) / g->voxsize.x); index->y = (int) ((pos->y - g->min.y) / g->voxsize.y); index->z = (int) ((pos->z - g->min.z) / g->voxsize.z); if (index->x == g->xsize) index->x--; if (index->y == g->ysize) index->y--; if (index->z == g->zsize) index->z--; if (index->x < 0 || index->x > g->xsize || index->y < 0 || index->y > g->ysize || index->z < 0 || index->z > g->zsize) return 0; if (pos->x < g->min.x || pos->x > g->max.x || pos->y < g->min.y || pos->y > g->max.y || pos->z < g->min.z || pos->z > g->max.z) return 0; return 1; } /* the real thing */ static void grid_intersect(grid * g, ray * ry) { flt tnear, tfar, offset; vector curpos, tmax, tdelta, pdeltaX, pdeltaY, pdeltaZ, nXp, nYp, nZp; gridindex curvox, step, out; int voxindex; objectlist * cur; if (ry->flags & RT_RAY_FINISHED) return; if (!grid_bounds_intersect(g, ry, &tnear, &tfar)) return; if (ry->maxdist < tnear) return; curpos = Raypnt(ry, tnear); pos2grid(g, &curpos, &curvox); offset = tnear; /* Setup X iterator stuff */ if (fabs(ry->d.x) < EPSILON) { tmax.x = FHUGE; tdelta.x = 0.0; step.x = 0; out.x = 0; /* never goes out of bounds on this axis */ } else if (ry->d.x < 0.0) { tmax.x = offset + ((voxel2x(g, curvox.x) - curpos.x) / ry->d.x); tdelta.x = g->voxsize.x / - ry->d.x; step.x = out.x = -1; } else { tmax.x = offset + ((voxel2x(g, curvox.x + 1) - curpos.x) / ry->d.x); tdelta.x = g->voxsize.x / ry->d.x; step.x = 1; out.x = g->xsize; } /* Setup Y iterator stuff */ if (fabs(ry->d.y) < EPSILON) { tmax.y = FHUGE; tdelta.y = 0.0; step.y = 0; out.y = 0; /* never goes out of bounds on this axis */ } else if (ry->d.y < 0.0) { tmax.y = offset + ((voxel2y(g, curvox.y) - curpos.y) / ry->d.y); tdelta.y = g->voxsize.y / - ry->d.y; step.y = out.y = -1; } else { tmax.y = offset + ((voxel2y(g, curvox.y + 1) - curpos.y) / ry->d.y); tdelta.y = g->voxsize.y / ry->d.y; step.y = 1; out.y = g->ysize; } /* Setup Z iterator stuff */ if (fabs(ry->d.z) < EPSILON) { tmax.z = FHUGE; tdelta.z = 0.0; step.z = 0; out.z = 0; /* never goes out of bounds on this axis */ } else if (ry->d.z < 0.0) { tmax.z = offset + ((voxel2z(g, curvox.z) - curpos.z) / ry->d.z); tdelta.z = g->voxsize.z / - ry->d.z; step.z = out.z = -1; } else { tmax.z = offset + ((voxel2z(g, curvox.z + 1) - curpos.z) / ry->d.z); tdelta.z = g->voxsize.z / ry->d.z; step.z = 1; out.z = g->zsize; } pdeltaX = ry->d; VScale(&pdeltaX, tdelta.x); pdeltaY = ry->d; VScale(&pdeltaY, tdelta.y); pdeltaZ = ry->d; VScale(&pdeltaZ, tdelta.z); nXp = Raypnt(ry, tmax.x); nYp = Raypnt(ry, tmax.y); nZp = Raypnt(ry, tmax.z); voxindex = curvox.z*g->xsize*g->ysize + curvox.y*g->xsize + curvox.x; while (1) { if (tmax.x < tmax.y && tmax.x < tmax.z) { cur = g->cells[voxindex]; while (cur != NULL) { if (ry->mbox[cur->obj->id] != ry->serial) { ry->mbox[cur->obj->id] = ry->serial; cur->obj->methods->intersect(cur->obj, ry); } cur = cur->next; } curvox.x += step.x; if (ry->maxdist < tmax.x || curvox.x == out.x) break; voxindex += step.x; tmax.x += tdelta.x; curpos = nXp; nXp.x += pdeltaX.x; nXp.y += pdeltaX.y; nXp.z += pdeltaX.z; } else if (tmax.z < tmax.y) { cur = g->cells[voxindex]; while (cur != NULL) { if (ry->mbox[cur->obj->id] != ry->serial) { ry->mbox[cur->obj->id] = ry->serial; cur->obj->methods->intersect(cur->obj, ry); } cur = cur->next; } curvox.z += step.z; if (ry->maxdist < tmax.z || curvox.z == out.z) break; voxindex += step.z*g->xsize*g->ysize; tmax.z += tdelta.z; curpos = nZp; nZp.x += pdeltaZ.x; nZp.y += pdeltaZ.y; nZp.z += pdeltaZ.z; } else { cur = g->cells[voxindex]; while (cur != NULL) { if (ry->mbox[cur->obj->id] != ry->serial) { ry->mbox[cur->obj->id] = ry->serial; cur->obj->methods->intersect(cur->obj, ry); } cur = cur->next; } curvox.y += step.y; if (ry->maxdist < tmax.y || curvox.y == out.y) break; voxindex += step.y*g->xsize; tmax.y += tdelta.y; curpos = nYp; nYp.x += pdeltaY.x; nYp.y += pdeltaY.y; nYp.z += pdeltaY.z; } if (ry->flags & RT_RAY_FINISHED) break; } } //This is unused /* static void voxel_intersect(grid * g, ray * ry, int voxindex) { objectlist * cur; cur = g->cells[voxindex]; while (cur != NULL) { cur->obj->methods->intersect(cur->obj, ry); cur = cur->next; } } */ static int grid_bounds_intersect(grid * g, ray * ry, flt *nr, flt *fr) { flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < g->min.x) || (ry->o.x > g->max.x)) return 0; } else { tx1 = (g->min.x - ry->o.x) / ry->d.x; tx2 = (g->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return 0; if (tfar < 0.0) return 0; if (ry->d.y == 0.0) { if ((ry->o.y < g->min.y) || (ry->o.y > g->max.y)) return 0; } else { ty1 = (g->min.y - ry->o.y) / ry->d.y; ty2 = (g->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return 0; if (tfar < 0.0) return 0; if (ry->d.z == 0.0) { if ((ry->o.z < g->min.z) || (ry->o.z > g->max.z)) return 0; } else { tz1 = (g->min.z - ry->o.z) / ry->d.z; tz2 = (g->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return 0; if (tfar < 0.0) return 0; *nr = tnear; *fr = tfar; return 1; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/bndbox.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * bndbox.h - This file contains the defines for bounding boxes etc. * * $Id: bndbox.h,v 1.2 2007-02-22 17:54:15 Exp $ */ typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector min; vector max; object * objlist; } bndbox; bndbox * newbndbox(vector min, vector max); #ifdef BNDBOX_PRIVATE static int bndbox_bbox(void * obj, vector * min, vector * max); static void free_bndbox(void * v); static void bndbox_intersect(bndbox *, ray *); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/quadric.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * quadric.cpp - This file contains the functions for dealing with quadrics. */ #include "machine.h" #include "types.h" #include "macros.h" #include "quadric.h" #include "vector.h" #include "intersect.h" #include "util.h" int quadric_bbox(void * obj, vector * min, vector * max) { return 0; } static object_methods quadric_methods = { (void (*)(void *, void *))(quadric_intersect), (void (*)(void *, void *, void *, void *))(quadric_normal), quadric_bbox, free }; quadric * newquadric() { quadric * q; q=(quadric *) rt_getmem(sizeof(quadric)); memset(q, 0, sizeof(quadric)); q->ctr.x=0.0; q->ctr.y=0.0; q->ctr.z=0.0; q->methods = &quadric_methods; return q; } void quadric_intersect(quadric * q, ray * ry) { flt Aq, Bq, Cq; flt t1, t2; flt disc; vector rd; vector ro; rd=ry->d; VNorm(&rd); ro.x = ry->o.x - q->ctr.x; ro.y = ry->o.y - q->ctr.y; ro.z = ry->o.z - q->ctr.z; Aq = (q->mat.a*(rd.x * rd.x)) + (2.0 * q->mat.b * rd.x * rd.y) + (2.0 * q->mat.c * rd.x * rd.z) + (q->mat.e * (rd.y * rd.y)) + (2.0 * q->mat.f * rd.y * rd.z) + (q->mat.h * (rd.z * rd.z)); Bq = 2.0 * ( (q->mat.a * ro.x * rd.x) + (q->mat.b * ((ro.x * rd.y) + (rd.x * ro.y))) + (q->mat.c * ((ro.x * rd.z) + (rd.x * ro.z))) + (q->mat.d * rd.x) + (q->mat.e * ro.y * rd.y) + (q->mat.f * ((ro.y * rd.z) + (rd.y * ro.z))) + (q->mat.g * rd.y) + (q->mat.h * ro.z * rd.z) + (q->mat.i * rd.z) ); Cq = (q->mat.a * (ro.x * ro.x)) + (2.0 * q->mat.b * ro.x * ro.y) + (2.0 * q->mat.c * ro.x * ro.z) + (2.0 * q->mat.d * ro.x) + (q->mat.e * (ro.y * ro.y)) + (2.0 * q->mat.f * ro.y * ro.z) + (2.0 * q->mat.g * ro.y) + (q->mat.h * (ro.z * ro.z)) + (2.0 * q->mat.i * ro.z) + q->mat.j; if (Aq == 0.0) { t1 = - Cq / Bq; add_intersection(t1, (object *) q, ry); } else { disc=(Bq*Bq - 4.0 * Aq * Cq); if (disc > 0.0) { disc=sqrt(disc); t1 = (-Bq + disc) / (2.0 * Aq); t2 = (-Bq - disc) / (2.0 * Aq); add_intersection(t1, (object *) q, ry); add_intersection(t2, (object *) q, ry); } } } void quadric_normal(quadric * q, vector * pnt, ray * incident, vector * N) { N->x = (q->mat.a*(pnt->x - q->ctr.x) + q->mat.b*(pnt->y - q->ctr.y) + q->mat.c*(pnt->z - q->ctr.z) + q->mat.d); N->y = (q->mat.b*(pnt->x - q->ctr.x) + q->mat.e*(pnt->y - q->ctr.y) + q->mat.f*(pnt->z - q->ctr.z) + q->mat.g); N->z = (q->mat.c*(pnt->x - q->ctr.x) + q->mat.f*(pnt->y - q->ctr.y) + q->mat.h*(pnt->z - q->ctr.z) + q->mat.i); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/parse.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * parse.cpp - an UltraLame (tm) parser for simple data files... */ // Try preventing lots of GCC warnings about ignored results of fscanf etc. #if !__INTEL_COMPILER #if __GNUC__<4 || __GNUC__==4 && __GNUC_MINOR__<5 // For older versions of GCC, disable use of __wur in GLIBC #undef _FORTIFY_SOURCE #define _FORTIFY_SOURCE 0 #else // Starting from 4.5, GCC has a suppression option #pragma GCC diagnostic ignored "-Wunused-result" #endif #endif //__INTEL_COMPILER #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <ctype.h> /* needed for toupper(), macro.. */ #include "types.h" #include "api.h" /* rendering API */ #define PARSE_INTERNAL #include "parse.h" /* self protos */ #undef PARSE_INTERNAL static texentry textable[NUMTEXS]; /* texture lookup table */ static texentry defaulttex; /* The default texture when a lookup fails */ static int numtextures; /* number of TEXDEF textures */ static int numobjectsparsed; /* total number of objects parsed so far */ static color scenebackcol; /* scene background color */ static int stringcmp(const char * a, const char * b) { size_t i, s, l; s=strlen(a); l=strlen(b); if (s != l) return 1; for (i=0; i<s; i++) { if (toupper(a[i]) != toupper(b[i])) { return 1; } } return 0; } static void reset_tex_table(void) { apitexture apitex; numtextures=0; memset(&textable, 0, sizeof(textable)); apitex.col.r=1.0; apitex.col.g=1.0; apitex.col.b=1.0; apitex.ambient=0.1; apitex.diffuse=0.9; apitex.specular=0.0; apitex.opacity=1.0; apitex.texturefunc=0; defaulttex.tex=rt_texture(&apitex); } static errcode add_texture(void * tex, char name[TEXNAMELEN]) { textable[numtextures].tex=tex; strcpy(textable[numtextures].name, name); numtextures++; if (numtextures > NUMTEXS) { fprintf(stderr, "Parse: %d textures allocated, texture slots full!\n", numtextures); numtextures--; /* keep writing over last texture if we've run out.. */ return PARSEALLOCERR; } return PARSENOERR; } static void * find_texture(char name[TEXNAMELEN]) { int i; for (i=0; i<numtextures; i++) { if (strcmp(name, textable[i].name) == 0) return textable[i].tex; } fprintf(stderr, "Undefined texture '%s', using default. \n",name); return(defaulttex.tex); } apiflt degtorad(apiflt deg) { apiflt tmp; tmp=deg * 3.1415926 / 180.0; return tmp; } static void degvectoradvec(vector * degvec) { vector tmp; tmp.x=degtorad(degvec->x); tmp.y=degtorad(degvec->y); tmp.z=degtorad(degvec->z); *degvec=tmp; } static void InitRot3d(RotMat * rot, apiflt x, apiflt y, apiflt z) { rot->rx1=cos(y)*cos(z); rot->rx2=sin(x)*sin(y)*cos(z) - cos(x)*sin(z); rot->rx3=sin(x)*sin(z) + cos(x)*cos(z)*sin(y); rot->ry1=cos(y)*sin(z); rot->ry2=cos(x)*cos(z) + sin(x)*sin(y)*sin(z); rot->ry3=cos(x)*sin(y)*sin(z) - sin(x)*cos(z); rot->rz1=sin(y); rot->rz2=sin(x)*cos(y); rot->rz3=cos(x)*cos(y); } static void Rotate3d(RotMat * rot, vector * vec) { vector tmp; tmp.x=(vec->x*(rot->rx1) + vec->y*(rot->rx2) + vec->z*(rot->rx3)); tmp.y=(vec->x*(rot->ry1) + vec->y*(rot->ry2) + vec->z*(rot->ry3)); tmp.z=(vec->x*(rot->rz1) + vec->y*(rot->rz2) + vec->z*(rot->rz3)); *vec=tmp; } static void Scale3d(vector * scale, vector * vec) { vec->x=vec->x * scale->x; vec->y=vec->y * scale->y; vec->z=vec->z * scale->z; } static void Trans3d(vector * trans, vector * vec) { vec->x+=trans->x; vec->y+=trans->y; vec->z+=trans->z; } static errcode GetString(FILE * dfile, const char * string) { char data[255]; fscanf(dfile,"%s",data); if (stringcmp(data, string) != 0) { fprintf(stderr, "parse: Expected %s, got %s \n",string, data); fprintf(stderr, "parse: Error while parsing object: %d \n",numobjectsparsed); return PARSEBADSYNTAX; } return PARSENOERR; } unsigned int readmodel(char * modelfile, SceneHandle scene) { FILE * dfile; errcode rc; reset_tex_table(); dfile=NULL; dfile=fopen(modelfile,"r"); if (dfile==NULL) { return PARSEBADFILE; } rc = GetScenedefs(dfile, scene); if (rc != PARSENOERR) return rc; scenebackcol.r = 0.0; /* default background is black */ scenebackcol.g = 0.0; scenebackcol.b = 0.0; numobjectsparsed=0; while ((rc = GetObject(dfile, scene)) == PARSENOERR) { numobjectsparsed++; } fclose(dfile); if (rc == PARSEEOF) rc = PARSENOERR; rt_background(scene, scenebackcol); return rc; } static errcode GetScenedefs(FILE * dfile, SceneHandle scene) { vector Ccenter, Cview, Cup; apiflt zoom, aspectratio; int raydepth, antialiasing; char outfilename[200]; int xres, yres, verbose; float a,b,c; errcode rc = PARSENOERR; rc |= GetString(dfile, "BEGIN_SCENE"); rc |= GetString(dfile, "OUTFILE"); fscanf(dfile, "%s", outfilename); #ifdef _WIN32 if (strcmp (outfilename, "/dev/null") == 0) { strcpy (outfilename, "NUL:"); } #endif rc |= GetString(dfile, "RESOLUTION"); fscanf(dfile, "%d %d", &xres, &yres); rc |= GetString(dfile, "VERBOSE"); fscanf(dfile, "%d", &verbose); rt_scenesetup(scene, outfilename, xres, yres, verbose); rc |= GetString(dfile, "CAMERA"); rc |= GetString(dfile, "ZOOM"); fscanf(dfile, "%f", &a); zoom=a; rc |= GetString(dfile, "ASPECTRATIO"); fscanf(dfile, "%f", &b); aspectratio=b; rc |= GetString(dfile, "ANTIALIASING"); fscanf(dfile, "%d", &antialiasing); rc |= GetString(dfile, "RAYDEPTH"); fscanf(dfile, "%d", &raydepth); rc |= GetString(dfile, "CENTER"); fscanf(dfile,"%f %f %f", &a, &b, &c); Ccenter.x = a; Ccenter.y = b; Ccenter.z = c; rc |= GetString(dfile, "VIEWDIR"); fscanf(dfile,"%f %f %f", &a, &b, &c); Cview.x = a; Cview.y = b; Cview.z = c; rc |= GetString(dfile, "UPDIR"); fscanf(dfile,"%f %f %f", &a, &b, &c); Cup.x = a; Cup.y = b; Cup.z = c; rc |= GetString(dfile, "END_CAMERA"); rt_camerasetup(scene, zoom, aspectratio, antialiasing, raydepth, Ccenter, Cview, Cup); return rc; } static errcode GetObject(FILE * dfile, SceneHandle scene) { char objtype[80]; fscanf(dfile, "%s", objtype); if (!stringcmp(objtype, "END_SCENE")) { return PARSEEOF; /* end parsing */ } if (!stringcmp(objtype, "TEXDEF")) { return GetTexDef(dfile); } if (!stringcmp(objtype, "TEXALIAS")) { return GetTexAlias(dfile); } if (!stringcmp(objtype, "BACKGROUND")) { return GetBackGnd(dfile); } if (!stringcmp(objtype, "CYLINDER")) { return GetCylinder(dfile); } if (!stringcmp(objtype, "FCYLINDER")) { return GetFCylinder(dfile); } if (!stringcmp(objtype, "POLYCYLINDER")) { return GetPolyCylinder(dfile); } if (!stringcmp(objtype, "SPHERE")) { return GetSphere(dfile); } if (!stringcmp(objtype, "PLANE")) { return GetPlane(dfile); } if (!stringcmp(objtype, "RING")) { return GetRing(dfile); } if (!stringcmp(objtype, "BOX")) { return GetBox(dfile); } if (!stringcmp(objtype, "SCALARVOL")) { return GetVol(dfile); } if (!stringcmp(objtype, "TRI")) { return GetTri(dfile); } if (!stringcmp(objtype, "STRI")) { return GetSTri(dfile); } if (!stringcmp(objtype, "LIGHT")) { return GetLight(dfile); } if (!stringcmp(objtype, "SCAPE")) { return GetLandScape(dfile); } if (!stringcmp(objtype, "TPOLYFILE")) { return GetTPolyFile(dfile); } fprintf(stderr, "Found bad token: %s expected an object type\n", objtype); return PARSEBADSYNTAX; } static errcode GetVector(FILE * dfile, vector * v1) { float a, b, c; fscanf(dfile, "%f %f %f", &a, &b, &c); v1->x=a; v1->y=b; v1->z=c; return PARSENOERR; } static errcode GetColor(FILE * dfile, color * c1) { float r, g, b; int rc; rc = GetString(dfile, "COLOR"); fscanf(dfile, "%f %f %f", &r, &g, &b); c1->r=r; c1->g=g; c1->b=b; return rc; } static errcode GetTexDef(FILE * dfile) { char texname[TEXNAMELEN]; fscanf(dfile, "%s", texname); add_texture(GetTexBody(dfile), texname); return PARSENOERR; } static errcode GetTexAlias(FILE * dfile) { char texname[TEXNAMELEN]; char aliasname[TEXNAMELEN]; fscanf(dfile, "%s", texname); fscanf(dfile, "%s", aliasname); add_texture(find_texture(aliasname), texname); return PARSENOERR; } static errcode GetTexture(FILE * dfile, void ** tex) { char tmp[255]; errcode rc = PARSENOERR; fscanf(dfile, "%s", tmp); if (!stringcmp("TEXTURE", tmp)) { *tex = GetTexBody(dfile); } else *tex = find_texture(tmp); return rc; } void * GetTexBody(FILE * dfile) { char tmp[255]; float a,b,c,d, phong, phongexp, phongtype; apitexture tex; void * voidtex; errcode rc; rc = GetString(dfile, "AMBIENT"); fscanf(dfile, "%f", &a); tex.ambient=a; rc |= GetString(dfile, "DIFFUSE"); fscanf(dfile, "%f", &b); tex.diffuse=b; rc |= GetString(dfile, "SPECULAR"); fscanf(dfile, "%f", &c); tex.specular=c; rc |= GetString(dfile, "OPACITY"); fscanf(dfile, "%f", &d); tex.opacity=d; fscanf(dfile, "%s", tmp); if (!stringcmp("PHONG", tmp)) { fscanf(dfile, "%s", tmp); if (!stringcmp("METAL", tmp)) { phongtype = RT_PHONG_METAL; } else if (!stringcmp("PLASTIC", tmp)) { phongtype = RT_PHONG_PLASTIC; } else { phongtype = RT_PHONG_PLASTIC; } fscanf(dfile, "%f", &phong); GetString(dfile, "PHONG_SIZE"); fscanf(dfile, "%f", &phongexp); fscanf(dfile, "%s", tmp); } else { phong = 0.0; phongexp = 100.0; phongtype = RT_PHONG_PLASTIC; } fscanf(dfile, "%f %f %f", &a, &b, &c); tex.col.r = a; tex.col.g = b; tex.col.b = c; rc |= GetString(dfile, "TEXFUNC"); fscanf(dfile, "%d", &tex.texturefunc); if (tex.texturefunc >= 7) { /* if its an image map, we need a filename */ fscanf(dfile, "%s", tex.imap); } if (tex.texturefunc != 0) { rc |= GetString(dfile, "CENTER"); rc |= GetVector(dfile, &tex.ctr); rc |= GetString(dfile, "ROTATE"); rc |= GetVector(dfile, &tex.rot); rc |= GetString(dfile, "SCALE"); rc |= GetVector(dfile, &tex.scale); } if (tex.texturefunc == 9) { rc |= GetString(dfile, "UAXIS"); rc |= GetVector(dfile, &tex.uaxs); rc |= GetString(dfile, "VAXIS"); rc |= GetVector(dfile, &tex.vaxs); } voidtex = rt_texture(&tex); rt_tex_phong(voidtex, phong, phongexp, (int) phongtype); if (rc == 0) { printf("Error parsing file\n"); } return voidtex; } static errcode GetLight(FILE * dfile) { apiflt rad; vector ctr; apitexture tex; float a; errcode rc; memset(&tex, 0, sizeof(apitexture)); rc = GetString(dfile,"CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile,"RAD"); fscanf(dfile,"%f",&a); /* read in radius */ rad=a; rc |= GetColor(dfile, &tex.col); rt_light(rt_texture(&tex), ctr, rad); return rc; } static errcode GetBackGnd(FILE * dfile) { float r,g,b; fscanf(dfile, "%f %f %f", &r, &g, &b); scenebackcol.r=r; scenebackcol.g=g; scenebackcol.b=b; return PARSENOERR; } static errcode GetCylinder(FILE * dfile) { apiflt rad; vector ctr, axis; void * tex; float a; errcode rc; rc = GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "AXIS"); rc |= GetVector(dfile, &axis); rc |= GetString(dfile, "RAD"); fscanf(dfile, "%f", &a); rad=a; rc |= GetTexture(dfile, &tex); rt_cylinder(tex, ctr, axis, rad); return rc; } static errcode GetFCylinder(FILE * dfile) { apiflt rad; vector ctr, axis; vector pnt1, pnt2; void * tex; float a; errcode rc; rc = GetString(dfile, "BASE"); rc |= GetVector(dfile, &pnt1); rc |= GetString(dfile, "APEX"); rc |= GetVector(dfile, &pnt2); ctr=pnt1; axis.x=pnt2.x - pnt1.x; axis.y=pnt2.y - pnt1.y; axis.z=pnt2.z - pnt1.z; rc |= GetString(dfile, "RAD"); fscanf(dfile, "%f", &a); rad=a; rc |= GetTexture(dfile, &tex); rt_fcylinder(tex, ctr, axis, rad); return rc; } static errcode GetPolyCylinder(FILE * dfile) { apiflt rad; vector * temp; void * tex; float a; int numpts, i; errcode rc; rc = GetString(dfile, "POINTS"); fscanf(dfile, "%d", &numpts); temp = (vector *) malloc(numpts * sizeof(vector)); for (i=0; i<numpts; i++) { rc |= GetVector(dfile, &temp[i]); } rc |= GetString(dfile, "RAD"); fscanf(dfile, "%f", &a); rad=a; rc |= GetTexture(dfile, &tex); rt_polycylinder(tex, temp, numpts, rad); free(temp); return rc; } static errcode GetSphere(FILE * dfile) { apiflt rad; vector ctr; void * tex; float a; errcode rc; rc = GetString(dfile,"CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "RAD"); fscanf(dfile,"%f",&a); rad=a; rc |= GetTexture(dfile, &tex); rt_sphere(tex, ctr, rad); return rc; } static errcode GetPlane(FILE * dfile) { vector normal; vector ctr; void * tex; errcode rc; rc = GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "NORMAL"); rc |= GetVector(dfile, &normal); rc |= GetTexture(dfile, &tex); rt_plane(tex, ctr, normal); return rc; } static errcode GetVol(FILE * dfile) { vector min, max; int x,y,z; char fname[255]; void * tex; errcode rc; rc = GetString(dfile, "MIN"); rc |= GetVector(dfile, &min); rc |= GetString(dfile, "MAX"); rc |= GetVector(dfile, &max); rc |= GetString(dfile, "DIM"); fscanf(dfile, "%d %d %d ", &x, &y, &z); rc |= GetString(dfile, "FILE"); fscanf(dfile, "%s", fname); rc |= GetTexture(dfile, &tex); rt_scalarvol(tex, min, max, x, y, z, fname, NULL); return rc; } static errcode GetBox(FILE * dfile) { vector min, max; void * tex; errcode rc; rc = GetString(dfile, "MIN"); rc |= GetVector(dfile, &min); rc |= GetString(dfile, "MAX"); rc |= GetVector(dfile, &max); rc |= GetTexture(dfile, &tex); rt_box(tex, min, max); return rc; } static errcode GetRing(FILE * dfile) { vector normal; vector ctr; void * tex; float a,b; errcode rc; rc = GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "NORMAL"); rc |= GetVector(dfile, &normal); rc |= GetString(dfile, "INNER"); fscanf(dfile, " %f ", &a); rc |= GetString(dfile, "OUTER"); fscanf(dfile, " %f ", &b); rc |= GetTexture(dfile, &tex); rt_ring(tex, ctr, normal, a, b); return rc; } static errcode GetTri(FILE * dfile) { vector v0,v1,v2; void * tex; errcode rc; rc = GetString(dfile, "V0"); rc |= GetVector(dfile, &v0); rc |= GetString(dfile, "V1"); rc |= GetVector(dfile, &v1); rc |= GetString(dfile, "V2"); rc |= GetVector(dfile, &v2); rc |= GetTexture(dfile, &tex); rt_tri(tex, v0, v1, v2); return rc; } static errcode GetSTri(FILE * dfile) { vector v0,v1,v2,n0,n1,n2; void * tex; errcode rc; rc = GetString(dfile, "V0"); rc |= GetVector(dfile, &v0); rc |= GetString(dfile, "V1"); rc |= GetVector(dfile, &v1); rc |= GetString(dfile, "V2"); rc |= GetVector(dfile, &v2); rc |= GetString(dfile, "N0"); rc |= GetVector(dfile, &n0); rc |= GetString(dfile, "N1"); rc |= GetVector(dfile, &n1); rc |= GetString(dfile, "N2"); rc |= GetVector(dfile, &n2); rc |= GetTexture(dfile, &tex); rt_stri(tex, v0, v1, v2, n0, n1, n2); return rc; } static errcode GetLandScape(FILE * dfile) { void * tex; vector ctr; apiflt wx, wy; int m, n; float a,b; errcode rc; rc = GetString(dfile, "RES"); fscanf(dfile, "%d %d", &m, &n); rc |= GetString(dfile, "SCALE"); fscanf(dfile, "%f %f", &a, &b); wx=a; wy=b; rc |= GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetTexture(dfile, &tex); rt_landscape(tex, m, n, ctr, wx, wy); return rc; } static errcode GetTPolyFile(FILE * dfile) { void * tex; vector ctr, rot, scale; vector v1, v2, v0; char ifname[255]; FILE *ifp; int v; RotMat RotA; errcode rc; rc = GetString(dfile, "SCALE"); rc |= GetVector(dfile, &scale); rc |= GetString(dfile, "ROT"); rc |= GetVector(dfile, &rot); degvectoradvec(&rot); InitRot3d(&RotA, rot.x, rot.y, rot.z); rc |= GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "FILE"); fscanf(dfile, "%s", ifname); rc |= GetTexture(dfile, &tex); if ((ifp=fopen(ifname, "r")) == NULL) { fprintf(stderr, "Can't open data file %s for input!! Aborting...\n", ifname); return PARSEBADSUBFILE; } while (!feof(ifp)) { fscanf(ifp, "%d", &v); if (v != 3) { break; } v=0; rc |= GetVector(ifp, &v0); rc |= GetVector(ifp, &v1); rc |= GetVector(ifp, &v2); Scale3d(&scale, &v0); Scale3d(&scale, &v1); Scale3d(&scale, &v2); Rotate3d(&RotA, &v0); Rotate3d(&RotA, &v1); Rotate3d(&RotA, &v2); Trans3d(&ctr, &v0); Trans3d(&ctr, &v1); Trans3d(&ctr, &v2); rt_tri(tex, v1, v0, v2); } fclose(ifp); return rc; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/light.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * light.h - this file includes declarations and defines for light sources. * * $Id: light.h,v 1.2 2007-02-22 17:54:15 Exp $ */ typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector ctr; flt rad; } point_light; point_light * newlight(void *, vector, flt); #ifdef LIGHT_PRIVATE static int light_bbox(void * obj, vector * min, vector * max); static void light_intersect(point_light *, ray *); static void light_normal(point_light *, vector *, ray *, vector *); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/sphere.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sphere.cpp - This file contains the functions for dealing with spheres. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define SPHERE_PRIVATE #include "sphere.h" static object_methods sphere_methods = { (void (*)(void *, void *))(sphere_intersect), (void (*)(void *, void *, void *, void *))(sphere_normal), sphere_bbox, free }; object * newsphere(void * tex, vector ctr, flt rad) { sphere * s; s=(sphere *) rt_getmem(sizeof(sphere)); memset(s, 0, sizeof(sphere)); s->methods = &sphere_methods; s->tex=(texture *)tex; s->ctr=ctr; s->rad=rad; return (object *) s; } static int sphere_bbox(void * obj, vector * min, vector * max) { sphere * s = (sphere *) obj; min->x = s->ctr.x - s->rad; min->y = s->ctr.y - s->rad; min->z = s->ctr.z - s->rad; max->x = s->ctr.x + s->rad; max->y = s->ctr.y + s->rad; max->z = s->ctr.z + s->rad; return 1; } static void sphere_intersect(sphere * spr, ray * ry) { flt b, disc, t1, t2, temp; vector V; VSUB(spr->ctr, ry->o, V); VDOT(b, V, ry->d); VDOT(temp, V, V); disc=b*b + spr->rad*spr->rad - temp; if (disc<=0.0) return; disc=sqrt(disc); t2=b+disc; if (t2 <= SPEPSILON) return; add_intersection(t2, (object *) spr, ry); t1=b-disc; if (t1 > SPEPSILON) add_intersection(t1, (object *) spr, ry); } static void sphere_normal(sphere * spr, vector * pnt, ray * incident, vector * N) { VSub((vector *) pnt, &(spr->ctr), N); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/util.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * util.cpp - Contains all of the timing functions for various platforms. */ #include "machine.h" #include "types.h" #include "macros.h" #include "util.h" #include "light.h" #include "global.h" #include "ui.h" void rt_finalize(void); #if !defined( _WIN32 ) #include <sys/time.h> #include <unistd.h> void rt_sleep(int msec) { usleep(msec*1000); } #else //_WIN32 #undef OLDUNIXTIME #undef STDTIME void rt_sleep(int msec) { #if !WIN8UI_EXAMPLE Sleep(msec); #else std::chrono::milliseconds sleep_time( msec ); std::this_thread::sleep_for( sleep_time ); #endif } timer gettimer(void) { return GetTickCount (); } flt timertime(timer st, timer fn) { double ttime, start, end; start = ((double) st) / ((double) 1000.00); end = ((double) fn) / ((double) 1000.00); ttime = end - start; return ttime; } #endif /* _WIN32 */ /* if we're on a Unix with gettimeofday() we'll use newer timers */ #if defined( STDTIME ) struct timezone tz; timer gettimer(void) { timer t; gettimeofday(&t, &tz); return t; } flt timertime(timer st, timer fn) { double ttime, start, end; start = (st.tv_sec+1.0*st.tv_usec / 1000000.0); end = (fn.tv_sec+1.0*fn.tv_usec / 1000000.0); ttime = end - start; return ttime; } #endif /* STDTIME */ /* use the old fashioned Unix time functions */ #if defined( OLDUNIXTIME ) timer gettimer(void) { return time(NULL); } flt timertime(timer st, timer fn) { return difftime(fn, st);; } #endif /* OLDUNIXTIME */ /* random other helper utility functions */ int rt_meminuse(void) { return rt_mem_in_use; } void * rt_getmem(unsigned int bytes) { void * mem; mem=malloc( bytes ); if (mem!=NULL) { rt_mem_in_use += bytes; } else { rtbomb("No more memory!!!!"); } return mem; } unsigned int rt_freemem(void * addr) { unsigned int bytes; free(addr); bytes=0; rt_mem_in_use -= bytes; return bytes; } void rtbomb(const char * msg) { rt_ui_message(MSG_ERR, msg); rt_ui_message(MSG_ABORT, "Rendering Aborted."); rt_finalize(); exit(1); } void rtmesg(const char * msg) { rt_ui_message(MSG_0, msg); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/grid.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * grid.h - spatial subdivision efficiency structures * * $Id: grid.h,v 1.2 2007-02-22 17:54:15 Exp $ * */ int engrid_scene(object ** list); object * newgrid(int xsize, int ysize, int zsize, vector min, vector max); #ifdef GRID_PRIVATE typedef struct objectlist { struct objectlist * next; /* next link in the list */ object * obj; /* the actual object */ } objectlist; typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ int xsize; /* number of cells along the X direction */ int ysize; /* number of cells along the Y direction */ int zsize; /* number of cells along the Z direction */ vector min; /* the minimum coords for the box containing the grid */ vector max; /* the maximum coords for the box containing the grid */ vector voxsize; /* the size of a grid cell/voxel */ object * objects; /* all objects contained in the grid */ objectlist ** cells; /* the grid cells themselves */ } grid; typedef struct { int x; /* Voxel X address */ int y; /* Voxel Y address */ int z; /* Voxel Z address */ } gridindex; /* * Convert from voxel number along X/Y/Z to corresponding coordinate. */ #define voxel2x(g,X) ((X) * (g->voxsize.x) + (g->min.x)) #define voxel2y(g,Y) ((Y) * (g->voxsize.y) + (g->min.y)) #define voxel2z(g,Z) ((Z) * (g->voxsize.z) + (g->min.z)) /* * And vice-versa. */ #define x2voxel(g,x) (((x) - g->min.x) / g->voxsize.x) #define y2voxel(g,y) (((y) - g->min.y) / g->voxsize.y) #define z2voxel(g,z) (((z) - g->min.z) / g->voxsize.z) static int grid_bbox(void * obj, vector * min, vector * max); static void grid_free(void * v); static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax); void engrid_objlist(grid * g, object ** list); static int engrid_object(grid * g, object * obj); static int engrid_objectlist(grid * g, objectlist ** list); static int engrid_cell(grid *, gridindex *); static int pos2grid(grid * g, vector * pos, gridindex * index); static void grid_intersect(grid *, ray *); //static void voxel_intersect(grid * g, ray * ry, int voxaddr); static int grid_bounds_intersect(grid * g, ray * ry, flt *near, flt *far); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/texture.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * texture.cpp - This file contains functions for implementing textures. */ #include "machine.h" #include "types.h" #include "macros.h" #include "texture.h" #include "coordsys.h" #include "imap.h" #include "vector.h" #include "box.h" /* plain vanilla texture solely based on object color */ color standard_texture(vector * hit, texture * tex, ray * ry) { return tex->col; } /* cylindrical image map */ color image_cyl_texture(vector * hit, texture * tex, ray * ry) { vector rh; flt u,v; rh.x=hit->x - tex->ctr.x; rh.z=hit->y - tex->ctr.y; rh.y=hit->z - tex->ctr.z; xyztocyl(rh, 1.0, &u, &v); u = u * tex->scale.x; u = u + tex->rot.x; u=fmod(u, 1.0); if (u < 0.0) u+=1.0; v = v * tex->scale.y; v = v + tex->rot.y; v=fmod(v, 1.0); if (v < 0.0) v+=1.0; return ImageMap((rawimage *)tex->img, u, v); } /* spherical image map */ color image_sphere_texture(vector * hit, texture * tex, ray * ry) { vector rh; flt u,v; rh.x=hit->x - tex->ctr.x; rh.y=hit->y - tex->ctr.y; rh.z=hit->z - tex->ctr.z; xyztospr(rh, &u, &v); u = u * tex->scale.x; u = u + tex->rot.x; u=fmod(u, 1.0); if (u < 0.0) u+=1.0; v = v * tex->scale.y; v = v + tex->rot.y; v=fmod(v, 1.0); if (v < 0.0) v+=1.0; return ImageMap((rawimage *)tex->img, u, v); } /* planar image map */ color image_plane_texture(vector * hit, texture * tex, ray * ry) { vector pnt; flt u,v; pnt.x=hit->x - tex->ctr.x; pnt.y=hit->y - tex->ctr.y; pnt.z=hit->z - tex->ctr.z; VDOT(u, tex->uaxs, pnt); /* VDOT(len, tex->uaxs, tex->uaxs); u = u / sqrt(len); */ VDOT(v, tex->vaxs, pnt); /* VDOT(len, tex->vaxs, tex->vaxs); v = v / sqrt(len); */ u = u * tex->scale.x; u = u + tex->rot.x; u = fmod(u, 1.0); if (u < 0.0) u += 1.0; v = v * tex->scale.y; v = v + tex->rot.y; v = fmod(v, 1.0); if (v < 0.0) v += 1.0; return ImageMap((rawimage *)tex->img, u, v); } color grit_texture(vector * hit, texture * tex, ray * ry) { int rnum; flt fnum; color col; rnum=rand() % 4096; fnum=(rnum / 4096.0 * 0.2) + 0.8; col.r=tex->col.r * fnum; col.g=tex->col.g * fnum; col.b=tex->col.b * fnum; return col; } color checker_texture(vector * hit, texture * tex, ray * ry) { long x,y,z; flt xh,yh,zh; color col; xh=hit->x - tex->ctr.x; x=(long) ((fabs(xh) * 3) + 0.5); x=x % 2; yh=hit->y - tex->ctr.y; y=(long) ((fabs(yh) * 3) + 0.5); y=y % 2; zh=hit->z - tex->ctr.z; z=(long) ((fabs(zh) * 3) + 0.5); z=z % 2; if (((x + y + z) % 2)==1) { col.r=1.0; col.g=0.2; col.b=0.0; } else { col.r=0.0; col.g=0.2; col.b=1.0; } return col; } color cyl_checker_texture(vector * hit, texture * tex, ray * ry) { long x,y; vector rh; flt u,v; color col; rh.x=hit->x - tex->ctr.x; rh.y=hit->y - tex->ctr.y; rh.z=hit->z - tex->ctr.z; xyztocyl(rh, 1.0, &u, &v); x=(long) (fabs(u) * 18.0); x=x % 2; y=(long) (fabs(v) * 10.0); y=y % 2; if (((x + y) % 2)==1) { col.r=1.0; col.g=0.2; col.b=0.0; } else { col.r=0.0; col.g=0.2; col.b=1.0; } return col; } color wood_texture(vector * hit, texture * tex, ray * ry) { flt radius, angle; int grain; color col; flt x,y,z; x=(hit->x - tex->ctr.x) * 1000; y=(hit->y - tex->ctr.y) * 1000; z=(hit->z - tex->ctr.z) * 1000; radius=sqrt(x*x + z*z); if (z == 0.0) angle=3.1415926/2.0; else angle=atan(x / z); radius=radius + 3.0 * sin(20 * angle + y / 150.0); grain=((int) (radius + 0.5)) % 60; if (grain < 40) { col.r=0.8; col.g=1.0; col.b=0.2; } else { col.r=0.0; col.g=0.0; col.b=0.0; } return col; } #define NMAX 28 short int NoiseMatrix[NMAX][NMAX][NMAX]; void InitNoise(void) { byte x,y,z,i,j,k; for (x=0; x<NMAX; x++) { for (y=0; y<NMAX; y++) { for (z=0; z<NMAX; z++) { NoiseMatrix[x][y][z]=rand() % 12000; if (x==NMAX-1) i=0; else i=x; if (y==NMAX-1) j=0; else j=y; if (z==NMAX-1) k=0; else k=z; NoiseMatrix[x][y][z]=NoiseMatrix[i][j][k]; } } } } int Noise(flt x, flt y, flt z) { byte ix, iy, iz; flt ox, oy, oz; int p000, p001, p010, p011; int p100, p101, p110, p111; int p00, p01, p10, p11; int p0, p1; int d00, d01, d10, d11; int d0, d1, d; x=fabs(x); y=fabs(y); z=fabs(z); ix=((int) x) % (NMAX-1); iy=((int) y) % (NMAX-1); iz=((int) z) % (NMAX-1); ox=(x - ((int) x)); oy=(y - ((int) y)); oz=(z - ((int) z)); p000=NoiseMatrix[ix][iy][iz]; p001=NoiseMatrix[ix][iy][iz+1]; p010=NoiseMatrix[ix][iy+1][iz]; p011=NoiseMatrix[ix][iy+1][iz+1]; p100=NoiseMatrix[ix+1][iy][iz]; p101=NoiseMatrix[ix+1][iy][iz+1]; p110=NoiseMatrix[ix+1][iy+1][iz]; p111=NoiseMatrix[ix+1][iy+1][iz+1]; d00=p100-p000; d01=p101-p001; d10=p110-p010; d11=p111-p011; p00=(int) ((int) d00*ox) + p000; p01=(int) ((int) d01*ox) + p001; p10=(int) ((int) d10*ox) + p010; p11=(int) ((int) d11*ox) + p011; d0=p10-p00; d1=p11-p01; p0=(int) ((int) d0*oy) + p00; p1=(int) ((int) d1*oy) + p01; d=p1-p0; return (int) ((int) d*oz) + p0; } color marble_texture(vector * hit, texture * tex, ray * ry) { flt i,d; flt x,y,z; color col; x=hit->x; y=hit->y; z=hit->z; x=x * 1.0; d=x + 0.0006 * Noise(x, (y * 1.0), (z * 1.0)); d=d*(((int) d) % 25); i=0.0 + 0.10 * fabs(d - 10.0 - 20.0 * ((int) d * 0.05)); if (i > 1.0) i=1.0; if (i < 0.0) i=0.0; /* col.r=i * tex->col.r; col.g=i * tex->col.g; col.b=i * tex->col.b; */ col.r = (1.0 + sin(i * 6.28)) / 2.0; col.g = (1.0 + sin(i * 16.28)) / 2.0; col.b = (1.0 + cos(i * 30.28)) / 2.0; return col; } color gnoise_texture(vector * hit, texture * tex, ray * ry) { color col; flt f; f=Noise((hit->x - tex->ctr.x), (hit->y - tex->ctr.y), (hit->z - tex->ctr.z)); if (f < 0.01) f=0.01; if (f > 1.0) f=1.0; col.r=tex->col.r * f; col.g=tex->col.g * f; col.b=tex->col.b * f; return col; } void InitTextures(void) { InitNoise(); ResetImages(); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/pthread_w.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef EMULATE_PTHREADS #ifndef _PTHREAD_H_DEFINED #define _PTHREAD_H_DEFINED #include <windows.h> #include <errno.h> #ifndef ENOTSUP #define ENOTSUP EPERM #endif /* just need <stddef.h> on Windows to get size_t defined */ #include <stddef.h> #define ERROR_PTHREAD 1000 #define ERROR_MODE 1001 #define ERROR_UNIMPL 1002 /* Basics */ struct pthread_s { HANDLE winthread_handle; DWORD winthread_id; }; typedef struct pthread_s *pthread_t; /* one of the few types that's pointer, not struct */ typedef struct { int i; /* not yet defined... */ } pthread_attr_t; /* Mutex */ typedef struct { int i; /* not yet defined... */ } pthread_mutexattr_t; typedef struct { CRITICAL_SECTION critsec; } pthread_mutex_t; /* Function prototypes */ extern int pthread_create (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); extern int pthread_join (pthread_t th, void **thread_return); extern void pthread_exit (void *retval); extern int pthread_mutex_init (pthread_mutex_t *mutex, pthread_mutexattr_t *mutex_attr); extern int pthread_mutex_destroy (pthread_mutex_t *mutex); extern int pthread_mutex_lock (pthread_mutex_t *mutex); extern int pthread_mutex_unlock (pthread_mutex_t *mutex); #endif /* _PTHREAD_H_DEFINED */ #endif /* EMULATE_PTHREADS */
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/ui.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ui.cpp - Contains functions for dealing with user interfaces */ #include "machine.h" #include "types.h" #include "macros.h" #include "util.h" #include "ui.h" static void (* rt_static_ui_message) (int, const char *) = NULL; static void (* rt_static_ui_progress) (int) = NULL; static int (* rt_static_ui_checkaction) (void) = NULL; extern bool silent_mode; void set_rt_ui_message(void (* func) (int, const char *)) { rt_static_ui_message = func; } void set_rt_ui_progress(void (* func) (int)) { rt_static_ui_progress = func; } void rt_ui_message(int level, const char * msg) { if (rt_static_ui_message == NULL) { if ( !silent_mode ) { fprintf(stderr, "%s\n", msg); fflush (stderr); } } else { rt_static_ui_message(level, msg); } } void rt_ui_progress(int percent) { if (rt_static_ui_progress != NULL) rt_static_ui_progress(percent); else { if ( !silent_mode ) { fprintf(stderr, "\r %3d%% Complete \r", percent); fflush(stderr); } } } int rt_ui_checkaction(void) { if (rt_static_ui_checkaction != NULL) return rt_static_ui_checkaction(); else return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/apitrigeom.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * apitrigeom.h - header for functions to generate triangle tesselated * geometry for use with OpenGL, XGL, etc. * */ void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad); void rt_tri_cylinder(void * tex, vector ctr, vector axis, apiflt rad); void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b); void rt_tri_plane(void * tex, vector ctr, vector norm); void rt_tri_box(void * tex, vector min, vector max);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/triangle.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * triangle.h - This file contains the defines for triangles etc. * * $Id: triangle.h,v 1.2 2007-02-22 17:54:16 Exp $ */ object * newtri(void *, vector, vector, vector); object * newstri(void *, vector, vector, vector, vector, vector, vector); #ifdef TRIANGLE_PRIVATE #define TRIXMAJOR 0 #define TRIYMAJOR 1 #define TRIZMAJOR 2 typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector edge2; vector edge1; vector v0; } tri; typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector edge2; vector edge1; vector v0; vector n0; vector n1; vector n2; } stri; static int tri_bbox(void * obj, vector * min, vector * max); static void tri_intersect(tri *, ray *); static void tri_normal(tri *, vector *, ray *, vector *); static void stri_normal(stri *, vector *, ray *, vector *); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/machine.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * machine.h - This is the machine specific include file * * $Id: machine.h,v 1.2 2007-02-22 17:54:15 Exp $ */ #include <stdio.h> #include <cstdlib> #include <string.h> #include <math.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> using namespace std; #define STDTIME
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/vector.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vector.cpp - This file contains all of the vector arithmetic functions. */ #include "machine.h" #include "types.h" #include "macros.h" flt VDot(vector *a, vector *b) { return (a->x*b->x + a->y*b->y + a->z*b->z); } void VCross(vector * a, vector * b, vector * c) { c->x = (a->y * b->z) - (a->z * b->y); c->y = (a->z * b->x) - (a->x * b->z); c->z = (a->x * b->y) - (a->y * b->x); } flt VLength(vector * a) { return (flt) sqrt((a->x * a->x) + (a->y * a->y) + (a->z * a->z)); } void VNorm(vector * a) { flt len; len=sqrt((a->x * a->x) + (a->y * a->y) + (a->z * a->z)); if (len != 0.0) { a->x /= len; a->y /= len; a->z /= len; } } void VAdd(vector * a, vector * b, vector * c) { c->x = (a->x + b->x); c->y = (a->y + b->y); c->z = (a->z + b->z); } void VSub(vector * a, vector * b, vector * c) { c->x = (a->x - b->x); c->y = (a->y - b->y); c->z = (a->z - b->z); } void VAddS(flt a, vector * A, vector * B, vector * C) { C->x = (a * A->x) + B->x; C->y = (a * A->y) + B->y; C->z = (a * A->z) + B->z; } vector Raypnt(ray * a, flt t) { vector temp; temp.x=a->o.x + (a->d.x * t); temp.y=a->o.y + (a->d.y * t); temp.z=a->o.z + (a->d.z * t); return temp; } void VScale(vector * a, flt s) { a->x *= s; a->y *= s; a->z *= s; } void ColorAddS(color * a, color * b, flt s) { a->r += b->r * s; a->g += b->g * s; a->b += b->b * s; } void ColorAccum(color * a, color * b) { a->r += b->r; a->g += b->g; a->b += b->b; } void ColorScale(color * a, flt s) { a->r *= s; a->g *= s; a->b *= s; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/ui.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ui.h - defines for user interface functions * * $Id: ui.h,v 1.2 2007-02-22 17:54:16 Exp $ */ /* Different types of message, for levels of verbosity etc */ #define MSG_0 100 #define MSG_1 101 #define MSG_2 102 #define MSG_3 103 #define MSG_4 104 #define MSG_5 105 #define MSG_ERR 200 #define MSG_ABORT 300 void rt_ui_message(int, const char *); void rt_ui_progress(int); int rt_ui_checkaction(void);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/parse.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * parse.h - this file contains defines for model file reading. * * $Id: parse.h,v 1.2 2007-02-22 17:54:16 Exp $ */ #define PARSENOERR 0 #define PARSEBADFILE 1 #define PARSEBADSUBFILE 2 #define PARSEBADSYNTAX 4 #define PARSEEOF 8 #define PARSEALLOCERR 16 unsigned int readmodel(char *, SceneHandle); #ifdef PARSE_INTERNAL #define NUMTEXS 32768 #define TEXNAMELEN 24 typedef struct { double rx1; double rx2; double rx3; double ry1; double ry2; double ry3; double rz1; double rz2; double rz3; } RotMat; typedef struct { char name[TEXNAMELEN]; void * tex; } texentry; #ifdef _ERRCODE_DEFINED #define errcode errcode_t #endif//_ERRCODE_DEFINED typedef unsigned int errcode; static errcode add_texture(void * tex, char name[TEXNAMELEN]); static errcode GetString(FILE *, const char *); static errcode GetScenedefs(FILE *, SceneHandle); static errcode GetColor(FILE *, color *); static errcode GetVector(FILE *, vector *); static errcode GetTexDef(FILE *); static errcode GetTexAlias(FILE *); static errcode GetTexture(FILE *, void **); void * GetTexBody(FILE *); static errcode GetBackGnd(FILE *); static errcode GetCylinder(FILE *); static errcode GetFCylinder(FILE *); static errcode GetPolyCylinder(FILE *); static errcode GetSphere(FILE *); static errcode GetPlane(FILE *); static errcode GetRing(FILE *); static errcode GetBox(FILE *); static errcode GetVol(FILE *); static errcode GetTri(FILE *); static errcode GetSTri(FILE *); static errcode GetLight(FILE *); static errcode GetLandScape(FILE *); static errcode GetTPolyFile(FILE *); // GetMGFFile is not used //static errcode GetMGFFile(FILE *, SceneHandle); static errcode GetObject(FILE *, SceneHandle); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/vol.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vol.cpp - Volume rendering helper routines etc. */ #include <stdio.h> #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "util.h" #include "vol.h" #include "box.h" #include "trace.h" #include "ui.h" #include "light.h" #include "shade.h" int scalarvol_bbox(void * obj, vector * min, vector * max) { box * b = (box *) obj; *min = b->min; *max = b->max; return 1; } void * newscalarvol(void * intex, vector min, vector max, int xs, int ys, int zs, char * fname, scalarvol * invol) { box * bx; texture * tx, * tex; scalarvol * vol; tex=(texture *)intex; tex->shadowcast = 0; /* doesn't cast a shadow */ tx=(texture *)rt_getmem(sizeof(texture)); /* is the volume data already loaded? */ if (invol==NULL) { vol=(scalarvol *)rt_getmem(sizeof(scalarvol)); vol->loaded=0; vol->data=NULL; } else vol=invol; vol->opacity=tex->opacity; vol->xres=xs; vol->yres=ys; vol->zres=zs; strcpy(vol->name, fname); tx->ctr.x = 0.0; tx->ctr.y = 0.0; tx->ctr.z = 0.0; tx->rot = tx->ctr; tx->scale = tx->ctr; tx->uaxs = tx->ctr; tx->vaxs = tx->ctr; tx->islight = 0; tx->shadowcast = 0; /* doesn't cast a shadow */ tx->col = tex->col; tx->ambient = 1.0; tx->diffuse = 0.0; tx->specular = 0.0; tx->opacity = 1.0; tx->img = vol; tx->texfunc = (color(*)(void *, void *, void *))(scalar_volume_texture); bx=newbox(tx, min, max); tx->obj = (void *) bx; /* XXX hack! */ return (void *) bx; } color VoxelColor(flt scalar) { color col; if (scalar > 1.0) scalar = 1.0; if (scalar < 0.0) scalar = 0.0; if (scalar < 0.25) { col.r = scalar * 4.0; col.g = 0.0; col.b = 0.0; } else { if (scalar < 0.75) { col.r = 1.0; col.g = (scalar - 0.25) * 2.0; col.b = 0.0; } else { col.r = 1.0; col.g = 1.0; col.b = (scalar - 0.75) * 4.0; } } return col; } color scalar_volume_texture(vector * hit, texture * tex, ray * ry) { color col, col2; box * bx; flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; flt t, tdist, dt, sum, tt; vector pnt, bln; scalarvol * vol; flt scalar, transval; int x, y, z; unsigned char * ptr; bx=(box *) tex->obj; vol=(scalarvol *)bx->tex->img; col.r=0.0; col.g=0.0; col.b=0.0; tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return col; } else { tx1 = (bx->min.x - ry->o.x) / ry->d.x; tx2 = (bx->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (ry->d.y == 0.0) { if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return col; } else { ty1 = (bx->min.y - ry->o.y) / ry->d.y; ty2 = (bx->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (ry->d.z == 0.0) { if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return col; } else { tz1 = (bx->min.z - ry->o.z) / ry->d.z; tz2 = (bx->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (tnear < 0.0) tnear=0.0; tdist=sqrt((flt) (vol->xres*vol->xres + vol->yres*vol->yres + vol->zres*vol->zres)); tt = (vol->opacity / tdist); bln.x=fabs(bx->min.x - bx->max.x); bln.y=fabs(bx->min.y - bx->max.y); bln.z=fabs(bx->min.z - bx->max.z); dt=sqrt(bln.x*bln.x + bln.y*bln.y + bln.z*bln.z) / tdist; sum=0.0; /* move the volume residency check out of loop.. */ if (!vol->loaded) { LoadVol(vol); vol->loaded=1; } for (t=tnear; t<=tfar; t+=dt) { pnt.x=((ry->o.x + (ry->d.x * t)) - bx->min.x) / bln.x; pnt.y=((ry->o.y + (ry->d.y * t)) - bx->min.y) / bln.y; pnt.z=((ry->o.z + (ry->d.z * t)) - bx->min.z) / bln.z; x=(int) ((vol->xres - 1.5) * pnt.x + 0.5); y=(int) ((vol->yres - 1.5) * pnt.y + 0.5); z=(int) ((vol->zres - 1.5) * pnt.z + 0.5); ptr = vol->data + ((vol->xres * vol->yres * z) + (vol->xres * y) + x); scalar = (flt) ((flt) 1.0 * ((int) ptr[0])) / 255.0; sum += tt * scalar; transval = tt * scalar; col2 = VoxelColor(scalar); if (sum < 1.0) { col.r += transval * col2.r; col.g += transval * col2.g; col.b += transval * col2.b; if (sum < 0.0) sum=0.0; } else { sum=1.0; } } if (sum < 1.0) { /* spawn transmission rays / refraction */ color transcol; transcol = shade_transmission(ry, hit, 1.0 - sum); col.r += transcol.r; /* add the transmitted ray */ col.g += transcol.g; /* to the diffuse and */ col.b += transcol.b; /* transmission total.. */ } return col; } void LoadVol(scalarvol * vol) { FILE * dfile; char msgtxt[2048]; dfile=fopen(vol->name, "r"); if (dfile==NULL) { char msgtxt[2048]; sprintf(msgtxt, "Vol: can't open %s for input!!! Aborting\n",vol->name); rt_ui_message(MSG_ERR, msgtxt); rt_ui_message(MSG_ABORT, "Rendering Aborted."); exit(1); } sprintf(msgtxt, "loading %dx%dx%d volume set from %s", vol->xres, vol->yres, vol->zres, vol->name); rt_ui_message(MSG_0, msgtxt); vol->data = (unsigned char *)rt_getmem(vol->xres * vol->yres * vol->zres); fread(vol->data, 1, (vol->xres * vol->yres * vol->zres), dfile); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/jpeg.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * jpeg.cpp - This file deals with JPEG format image files (reading/writing) */ /* * This code requires support from the Independent JPEG Group's libjpeg. * For our puposes, we're interested only in the 3 byte per pixel 24 bit * RGB output. Probably won't implement any decent checking at this point. */ #include <stdio.h> #include "machine.h" #include "types.h" #include "util.h" #include "imageio.h" /* error codes etc */ #include "jpeg.h" /* the protos for this file */ #if !defined(USEJPEG) int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata) { return IMAGEUNSUP; } #else #include "jpeglib.h" /* the IJG jpeg library headers */ int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata) { FILE * ifp; struct jpeg_decompress_struct cinfo; /* JPEG decompression struct */ struct jpeg_error_mgr jerr; /* JPEG Error handler */ JSAMPROW row_pointer[1]; /* output row buffer */ int row_stride; /* physical row width in output buf */ /* open input file before doing any JPEG decompression setup */ if ((ifp = fopen(name, "rb")) == NULL) return IMAGEBADFILE; /* Could not open image, return error */ /* * Note: The Independent JPEG Group's library does not have a way * of returning errors without the use of setjmp/longjmp. * This is a problem in multi-threaded environment, since setjmp * and longjmp are declared thread-unsafe by many vendors currently. * For now, JPEG decompression errors will result in the "default" * error handling provided by the JPEG library, which is an error * message and a fatal call to exit(). I'll have to work around this * or find a reasonably thread-safe way of doing setjmp/longjmp.. */ cinfo.err = jpeg_std_error(&jerr); /* Set JPEG error handler to default */ jpeg_create_decompress(&cinfo); /* Create decompression context */ jpeg_stdio_src(&cinfo, ifp); /* Set input mechanism to stdio type */ jpeg_read_header(&cinfo, TRUE); /* Read the JPEG header for info */ jpeg_start_decompress(&cinfo); /* Prepare for actual decompression */ *xres = cinfo.output_width; /* set returned image width */ *yres = cinfo.output_height; /* set returned image height */ /* Calculate the size of a row in the image */ row_stride = cinfo.output_width * cinfo.output_components; /* Allocate the image buffer which will be returned to the ray tracer */ *imgdata = (unsigned char *) malloc(row_stride * cinfo.output_height); /* decompress the JPEG, one scanline at a time into the buffer */ while (cinfo.output_scanline < cinfo.output_height) { row_pointer[0] = &((*imgdata)[(cinfo.output_scanline)*row_stride]); jpeg_read_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_decompress(&cinfo); /* Tell the JPEG library to cleanup */ jpeg_destroy_decompress(&cinfo); /* Destroy JPEG decompression context */ fclose(ifp); /* Close the input file */ return IMAGENOERR; /* No fatal errors */ } #endif
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/vector.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vector.h - This file contains declarations of vector functions * * $Id: vector.h,v 1.2 2007-02-22 17:54:17 Exp $ */ flt VDot(vector *, vector *); void VCross(vector *, vector *, vector *); flt VLength(vector *); void VNorm(vector *); void VAdd(vector *, vector *, vector *); void VSub(vector *, vector *, vector *); void VAddS(flt, vector *, vector *, vector *); vector Raypnt(ray *, flt); void VScale(vector * a, flt s); void ColorAddS(color * a, color * b, flt s); void ColorAccum(color * a, color * b); void ColorScale(color * a, flt s);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/imageio.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * imageio.h - This file deals with reading/writing image files * * $Id: imageio.h,v 1.2 2007-02-22 17:54:15 Exp $ */ /* For our puposes, we're interested only in the 3 byte per pixel 24 bit truecolor sort of file.. */ #define IMAGENOERR 0 /* no error */ #define IMAGEBADFILE 1 /* can't find or can't open the file */ #define IMAGEUNSUP 2 /* the image file is an unsupported format */ #define IMAGEALLOCERR 3 /* not enough remaining memory to load this image */ #define IMAGEREADERR 4 /* failed read, short reads etc */ int readimage(rawimage *);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/coordsys.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * coordsys.h - defines for coordinate system routines. * * $Id: coordsys.h,v 1.2 2007-02-22 17:54:15 Exp $ */ #define TWOPI 6.2831853 void xytopolar(flt, flt, flt, flt *, flt *); void xyztocyl(vector, flt, flt *, flt *); void xyztospr(vector, flt *, flt *);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/ring.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ring.h - This file contains the defines for rings etc. * * $Id: ring.h,v 1.2 2007-02-22 17:54:16 Exp $ */ object * newring(void * tex, vector ctr, vector norm, flt in, flt out); #ifdef RING_PRIVATE typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector ctr; vector norm; flt inrad; flt outrad; } ring; static int ring_bbox(void * obj, vector * min, vector * max); static void ring_intersect(ring *, ray *); static void ring_normal(ring *, vector *, ray * incident, vector *); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/apigeom.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * api.cpp - This file contains all of the API calls that are defined for * external driver code to use. */ #include "machine.h" #include "types.h" #include "api.h" #include "macros.h" #include "vector.h" #define MyVNorm(a) VNorm ((vector *) a) void rt_polycylinder(void * tex, vector * points, int numpts, apiflt rad) { vector a; int i; if ((points == NULL) || (numpts == 0)) { return; } if (numpts > 0) { rt_sphere(tex, points[0], rad); if (numpts > 1) { for (i=1; i<numpts; i++) { a.x = points[i].x - points[i-1].x; a.y = points[i].y - points[i-1].y; a.z = points[i].z - points[i-1].z; rt_fcylinder(tex, points[i-1], a, rad); rt_sphere(tex, points[i], rad); } } } } void rt_heightfield(void * tex, vector ctr, int m, int n, apiflt * field, apiflt wx, apiflt wy) { int xx,yy; vector v0, v1, v2; apiflt xoff, yoff, zoff; xoff=ctr.x - (wx / 2.0); yoff=ctr.z - (wy / 2.0); zoff=ctr.y; for (yy=0; yy<(n-1); yy++) { for (xx=0; xx<(m-1); xx++) { v0.x=wx*(xx )/(m*1.0) + xoff; v0.y=field[(yy )*m + (xx )] + zoff; v0.z=wy*(yy )/(n*1.0) + yoff; v1.x=wx*(xx + 1)/(m*1.0) + xoff; v1.y=field[(yy )*m + (xx + 1)] + zoff; v1.z=wy*(yy )/(n*1.0) + yoff; v2.x=wx*(xx + 1)/(m*1.0) + xoff; v2.y=field[(yy + 1)*m + (xx + 1)] + zoff; v2.z=wy*(yy + 1)/(n*1.0) + yoff; rt_tri(tex, v1, v0, v2); v0.x=wx*(xx )/(m*1.0) + xoff; v0.y=field[(yy )*m + (xx )] + zoff; v0.z=wy*(yy )/(n*1.0) + yoff; v1.x=wx*(xx )/(m*1.0) + xoff; v1.y=field[(yy + 1)*m + (xx )] + zoff; v1.z=wy*(yy + 1)/(n*1.0) + yoff; v2.x=wx*(xx + 1)/(m*1.0) + xoff; v2.y=field[(yy + 1)*m + (xx + 1)] + zoff; v2.z=wy*(yy + 1)/(n*1.0) + yoff; rt_tri(tex, v0, v1, v2); } } } /* end of heightfield */ static void rt_sheightfield(void * tex, vector ctr, int m, int n, apiflt * field, apiflt wx, apiflt wy) { vector * vertices; vector * normals; vector offset; apiflt xinc, yinc; int x, y, addr; vertices = (vector *) malloc(m*n*sizeof(vector)); normals = (vector *) malloc(m*n*sizeof(vector)); offset.x = ctr.x - (wx / 2.0); offset.y = ctr.z - (wy / 2.0); offset.z = ctr.y; xinc = wx / ((apiflt) m); yinc = wy / ((apiflt) n); /* build vertex list */ for (y=0; y<n; y++) { for (x=0; x<m; x++) { addr = y*m + x; vertices[addr] = rt_vector( x * xinc + offset.x, field[addr] + offset.z, y * yinc + offset.y); } } /* build normals from vertex list */ for (x=1; x<m; x++) { normals[x] = normals[(n - 1)*m + x] = rt_vector(0.0, 1.0, 0.0); } for (y=1; y<n; y++) { normals[y*m] = normals[y*m + (m-1)] = rt_vector(0.0, 1.0, 0.0); } for (y=1; y<(n-1); y++) { for (x=1; x<(m-1); x++) { addr = y*m + x; normals[addr] = rt_vector( -(field[addr + 1] - field[addr - 1]) / (2.0 * xinc), 1.0, -(field[addr + m] - field[addr - m]) / (2.0 * yinc)); MyVNorm(&normals[addr]); } } /* generate actual triangles */ for (y=0; y<(n-1); y++) { for (x=0; x<(m-1); x++) { addr = y*m + x; rt_stri(tex, vertices[addr], vertices[addr + 1 + m], vertices[addr + 1], normals[addr], normals[addr + 1 + m], normals[addr + 1]); rt_stri(tex, vertices[addr], vertices[addr + m], vertices[addr + 1 + m], normals[addr], normals[addr + m], normals[addr + 1 + m]); } } free(normals); free(vertices); } /* end of smoothed heightfield */ static void adjust(apiflt *base, int xres, int yres, apiflt wx, apiflt wy, int xa, int ya, int x, int y, int xb, int yb) { apiflt d, v; if (base[x + (xres*y)]==0.0) { d=(abs(xa - xb) / (xres * 1.0))*wx + (abs(ya - yb) / (yres * 1.0))*wy; v=(base[xa + (xres*ya)] + base[xb + (xres*yb)]) / 2.0 + (((((rand() % 1000) - 500.0)/500.0)*d) / 8.0); if (v < 0.0) v=0.0; if (v > (xres + yres)) v=(xres + yres); base[x + (xres * y)]=v; } } static void subdivide(apiflt *base, int xres, int yres, apiflt wx, apiflt wy, int x1, int y1, int x2, int y2) { long x,y; if (((x2 - x1) < 2) && ((y2 - y1) < 2)) { return; } x=(x1 + x2) / 2; y=(y1 + y2) / 2; adjust(base, xres, yres, wx, wy, x1, y1, x, y1, x2, y1); adjust(base, xres, yres, wx, wy, x2, y1, x2, y, x2, y2); adjust(base, xres, yres, wx, wy, x1, y2, x, y2, x2, y2); adjust(base, xres, yres, wx, wy, x1, y1, x1, y, x1, y2); if (base[x + xres*y]==0.0) { base[x + (xres * y)]=(base[x1 + xres*y1] + base[x2 + xres*y1] + base[x2 + xres*y2] + base[x1 + xres*y2] )/4.0; } subdivide(base, xres, yres, wx, wy, x1, y1 ,x ,y); subdivide(base, xres, yres, wx, wy, x, y1, x2, y); subdivide(base, xres, yres, wx, wy, x, y, x2, y2); subdivide(base, xres, yres, wx, wy, x1, y, x, y2); } void rt_landscape(void * tex, int m, int n, vector ctr, apiflt wx, apiflt wy) { int totalsize, x, y; apiflt * field; totalsize=m*n; srand(totalsize); field=(apiflt *) malloc(totalsize*sizeof(apiflt)); for (y=0; y<n; y++) { for (x=0; x<m; x++) { field[x + y*m]=0.0; } } field[0 + 0]=1.0 + (rand() % 100)/100.0; field[m - 1]=1.0 + (rand() % 100)/100.0; field[0 + m*(n - 1)]=1.0 + (rand() % 100)/100.0; field[m - 1 + m*(n - 1)]=1.0 + (rand() % 100)/100.0; subdivide(field, m, n, wx, wy, 0, 0, m-1, n-1); rt_sheightfield(tex, ctr, m, n, field, wx, wy); free(field); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/pthread.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef EMULATE_PTHREADS #include <assert.h> #include "pthread_w.h" /* Basics */ int pthread_create (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { pthread_t th; if (thread == NULL) return EINVAL; *thread = NULL; if (start_routine == NULL) return EINVAL; th = (pthread_t) malloc (sizeof (pthread_s)); memset (th, 0, sizeof (pthread_s)); th->winthread_handle = CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE) start_routine, arg, 0, &th->winthread_id); if (th->winthread_handle == NULL) return EAGAIN; /* GetLastError() */ *thread = th; return 0; } int pthread_join (pthread_t th, void **thread_return) { BOOL b_ret; DWORD dw_ret; if (thread_return) *thread_return = NULL; if ((th == NULL) || (th->winthread_handle == NULL)) return EINVAL; dw_ret = WaitForSingleObject (th->winthread_handle, INFINITE); if (dw_ret != WAIT_OBJECT_0) return ERROR_PTHREAD; /* dw_ret == WAIT_FAILED; GetLastError() */ if (thread_return) { BOOL e_ret; DWORD exit_val; e_ret = GetExitCodeThread (th->winthread_handle, &exit_val); if (!e_ret) return ERROR_PTHREAD; /* GetLastError() */ *thread_return = (void *)(size_t) exit_val; } b_ret = CloseHandle (th->winthread_handle); if (!b_ret) return ERROR_PTHREAD; /* GetLastError() */ memset (th, 0, sizeof (pthread_s)); free (th); th = NULL; return 0; } void pthread_exit (void *retval) { /* specific to PTHREAD_TO_WINTHREAD */ ExitThread ((DWORD) ((size_t) retval)); /* thread becomes signalled so its death can be waited upon */ /*NOTREACHED*/ assert (0); return; /* void fnc; can't return an error code */ } /* Mutex */ int pthread_mutex_init (pthread_mutex_t *mutex, pthread_mutexattr_t *mutex_attr) { InitializeCriticalSection (&mutex->critsec); return 0; } int pthread_mutex_destroy (pthread_mutex_t *mutex) { return 0; } int pthread_mutex_lock (pthread_mutex_t *mutex) { EnterCriticalSection (&mutex->critsec); return 0; } int pthread_mutex_unlock (pthread_mutex_t *mutex) { LeaveCriticalSection (&mutex->critsec); return 0; } #endif /* EMULATE_PTHREADS */
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/imageio.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * imageio.cpp - This file deals with reading/writing image files */ /* For our puposes, we're interested only in the 3 byte per pixel 24 bit * truecolor sort of file.. */ #include <stdio.h> #include "machine.h" #include "types.h" #include "util.h" #include "imageio.h" #include "ppm.h" /* PPM files */ #include "tgafile.h" /* Truevision Targa files */ #include "jpeg.h" /* JPEG files */ static int fakeimage(char * name, int * xres, int * yres, unsigned char ** imgdata) { int i, imgsize; fprintf(stderr, "Error loading image %s. Faking it.\n", name); *xres = 2; *yres = 2; imgsize = 3 * (*xres) * (*yres); *imgdata = (unsigned char *)rt_getmem(imgsize); for (i=0; i<imgsize; i++) { (*imgdata)[i] = 255; } return IMAGENOERR; } int readimage(rawimage * img) { int rc; int xres, yres; unsigned char * imgdata = NULL; char * name = img->name; if (strstr(name, ".ppm")) { rc = readppm(name, &xres, &yres, &imgdata); } else if (strstr(name, ".tga")) { rc = readtga(name, &xres, &yres, &imgdata); } else if (strstr(name, ".jpg")) { rc = readjpeg(name, &xres, &yres, &imgdata); } else if (strstr(name, ".gif")) { rc = IMAGEUNSUP; } else if (strstr(name, ".png")) { rc = IMAGEUNSUP; } else if (strstr(name, ".tiff")) { rc = IMAGEUNSUP; } else if (strstr(name, ".rgb")) { rc = IMAGEUNSUP; } else if (strstr(name, ".xpm")) { rc = IMAGEUNSUP; } else { rc = readppm(name, &xres, &yres, &imgdata); } switch (rc) { case IMAGEREADERR: fprintf(stderr, "Short read encountered while loading image %s\n", name); rc = IMAGENOERR; /* remap to non-fatal error */ break; case IMAGEUNSUP: fprintf(stderr, "Cannot read unsupported image format for image %s\n", name); break; } /* If the image load failed, create a tiny white colored image to fake it */ /* this allows a scene to render even when a file can't be loaded */ if (rc != IMAGENOERR) { rc = fakeimage(name, &xres, &yres, &imgdata); } /* If we succeeded in loading the image, return it. */ if (rc == IMAGENOERR) { img->xres = xres; img->yres = yres; img->bpp = 3; img->data = imgdata; } return rc; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/trace.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * trace.h - This file contains the declarations and defines for the trace module * * $Id: trace.h,v 1.2 2007-02-22 17:54:16 Exp $ */ extern char *global_buffer; typedef struct { int tid; int nthr; scenedef scene; char * buffer; int startx; int stopx; int starty; int stopy; } thr_parms; typedef struct { int startx; int stopx; int starty; int stopy; } patch; typedef struct { void * tga; int iwidth; int iheight; int startx; int starty; int stopx; int stopy; char * buffer; } thr_io_parms; color trace(ray *); void * thread_trace(thr_parms * parms); void thread_trace1(thr_parms *, patch *, int depth); void thread_trace2(thr_parms *, patch *); void * thread_io(void *); void trace_shm(scenedef, /*char *,*/ int, int, int, int); void trace_region(scenedef, void *, int, int, int, int);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/render.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * render.cpp - This file contains the main program and driver for the raytracer. */ #include "machine.h" #include "types.h" #include "macros.h" #include "tgafile.h" #include "trace.h" #include "render.h" #include "util.h" #include "light.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" #include "objbound.h" #include "grid.h" /* how many pieces to divide each scanline into */ #define NUMHORZDIV 1 void renderscene(scenedef scene) { //char msgtxt[2048]; //void * outfile; /* Grid based accerlation scheme */ if (scene.boundmode == RT_BOUNDING_ENABLED) engrid_scene(&rootobj); /* grid */ /* Not used now if (scene.verbosemode) { sprintf(msgtxt, "Opening %s for output.", scene.outfilename); rt_ui_message(MSG_0, msgtxt); } createtgafile(scene.outfilename, (unsigned short) scene.hres, (unsigned short) scene.vres); outfile = opentgafile(scene.outfilename); */ trace_region (scene, 0/*outfile*/, 0, 0, scene.hres, scene.vres); //fclose((FILE *)outfile); } /* end of renderscene() */
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/extvol.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vol.h - Volume rendering definitions etc. * * * $Id: extvol.h,v 1.2 2007-02-22 17:54:15 Exp $ */ typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector min; vector max; flt ambient; flt diffuse; flt opacity; int samples; flt (* evaluator)(flt, flt, flt); } extvol; extvol * newextvol(void * voidtex, vector min, vector max, int samples, flt (* evaluator)(flt, flt, flt)); color ext_volume_texture(vector *, texture *, ray *);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/bndbox.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * bndbox.cpp - This file contains the functions for dealing with bounding boxes. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define BNDBOX_PRIVATE #include "bndbox.h" static object_methods bndbox_methods = { (void (*)(void *, void *))(bndbox_intersect), (void (*)(void *, void *, void *, void *))(NULL), bndbox_bbox, free_bndbox }; bndbox * newbndbox(vector min, vector max) { bndbox * b; b=(bndbox *) rt_getmem(sizeof(bndbox)); memset(b, 0, sizeof(bndbox)); b->min=min; b->max=max; b->methods = &bndbox_methods; b->objlist=NULL; b->tex=NULL; b->nextobj=NULL; return b; } static int bndbox_bbox(void * obj, vector * min, vector * max) { bndbox * b = (bndbox *) obj; *min = b->min; *max = b->max; return 1; } static void free_bndbox(void * v) { bndbox * b = (bndbox *) v; free_objects(b->objlist); free(b); } static void bndbox_intersect(bndbox * bx, ray * ry) { flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; object * obj; ray newray; /* eliminate bounded rays whose bounds do not intersect */ /* the bounds of the box.. */ if (ry->flags & RT_RAY_BOUNDED) { if ((ry->s.x > bx->max.x) && (ry->e.x > bx->max.x)) return; if ((ry->s.x < bx->min.x) && (ry->e.x < bx->min.x)) return; if ((ry->s.y > bx->max.y) && (ry->e.y > bx->max.y)) return; if ((ry->s.y < bx->min.y) && (ry->e.y < bx->min.y)) return; if ((ry->s.z > bx->max.z) && (ry->e.z > bx->max.z)) return; if ((ry->s.z < bx->min.z) && (ry->e.z < bx->min.z)) return; } tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return; } else { tx1 = (bx->min.x - ry->o.x) / ry->d.x; tx2 = (bx->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return; if (tfar < 0.0) return; if (ry->d.y == 0.0) { if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return; } else { ty1 = (bx->min.y - ry->o.y) / ry->d.y; ty2 = (bx->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return; if (tfar < 0.0) return; if (ry->d.z == 0.0) { if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return; } else { tz1 = (bx->min.z - ry->o.z) / ry->d.z; tz2 = (bx->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return; if (tfar < 0.0) return; /* intersect all of the enclosed objects */ newray=*ry; newray.flags |= RT_RAY_BOUNDED; RAYPNT(newray.s , (*ry) , tnear); RAYPNT(newray.e , (*ry) , (tfar + EPSILON)); obj = bx->objlist; while (obj != NULL) { obj->methods->intersect(obj, &newray); obj = (object *)obj->nextobj; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/imap.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * imap.cpp - This file contains code for doing image map type things. */ #include "machine.h" #include "types.h" #include "imap.h" #include "util.h" #include "imageio.h" rawimage * imagelist[MAXIMGS]; int numimages; void ResetImages(void) { int i; numimages=0; for (i=0; i<MAXIMGS; i++) { imagelist[i]=NULL; } } void LoadImage(rawimage * image) { if (!image->loaded) { readimage(image); image->loaded=1; } } color ImageMap(rawimage * image, flt u, flt v) { color col, colx, colx2; flt x,y, px, py; int x1, x2, y1, y2; unsigned char * ptr; unsigned char * ptr2; if (!image->loaded) { LoadImage(image); image->loaded=1; } if ((u <= 1.0) && (u >=0.0) && (v <= 1.0) && (v >= 0.0)) { x=(image->xres - 1.0) * u; /* floating point X location */ y=(image->yres - 1.0) * v; /* floating point Y location */ px = x - ((int) x); py = y - ((int) y); x1 = (int) x; x2 = x1 + 1; y1 = (int) y; y2 = y1 + 1; ptr = image->data + ((image->xres * y1) + x1) * 3; ptr2 = image->data + ((image->xres * y1) + x2) * 3; colx.r = (flt) ((flt)ptr[0] + px*((flt)ptr2[0] - (flt) ptr[0])) / 255.0; colx.g = (flt) ((flt)ptr[1] + px*((flt)ptr2[1] - (flt) ptr[1])) / 255.0; colx.b = (flt) ((flt)ptr[2] + px*((flt)ptr2[2] - (flt) ptr[2])) / 255.0; ptr = image->data + ((image->xres * y2) + x1) * 3; ptr2 = image->data + ((image->xres * y2) + x2) * 3; colx2.r = ((flt)ptr[0] + px*((flt)ptr2[0] - (flt)ptr[0])) / 255.0; colx2.g = ((flt)ptr[1] + px*((flt)ptr2[1] - (flt)ptr[1])) / 255.0; colx2.b = ((flt)ptr[2] + px*((flt)ptr2[2] - (flt)ptr[2])) / 255.0; col.r = colx.r + py*(colx2.r - colx.r); col.g = colx.g + py*(colx2.g - colx.g); col.b = colx.b + py*(colx2.b - colx.b); } else { col.r=0.0; col.g=0.0; col.b=0.0; } return col; } rawimage * AllocateImage(char * filename) { rawimage * newimage = NULL; int i, intable; size_t len; intable=0; if (numimages!=0) { for (i=0; i<numimages; i++) { if (!strcmp(filename, imagelist[i]->name)) { newimage=imagelist[i]; intable=1; } } } if (!intable) { newimage=(rawimage *)rt_getmem(sizeof(rawimage)); newimage->loaded=0; newimage->xres=0; newimage->yres=0; newimage->bpp=0; newimage->data=NULL; len=strlen(filename); if (len > 80) rtbomb("Filename too long in image map!!"); strcpy(newimage->name, filename); imagelist[numimages]=newimage; /* add new one to the table */ numimages++; /* increment the number of images */ } return newimage; } void DeallocateImage(rawimage * image) { image->loaded=0; rt_freemem(image->data); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/box.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * box.h - This file contains the defines for boxes etc. * * $Id: box.h,v 1.2 2007-02-22 17:54:15 Exp $ */ typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector min; vector max; } box; box * newbox(void * tex, vector min, vector max); void box_intersect(box *, ray *); void box_normal(box *, vector *, ray * incident, vector *);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/coordsys.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * coordsys.cpp - Routines to translate from one coordinate system to another. */ #include "machine.h" #include "types.h" #include "coordsys.h" void xytopolar(flt x, flt y, flt rad, flt * u, flt * v) { flt r1; r1=x*x + y*y; *v=sqrt(r1 / (rad*rad)); if (y<0.0) *u=1.0 - acos(x/sqrt(r1))/TWOPI; else *u= acos(x/sqrt(r1))/TWOPI; } void xyztocyl(vector pnt, flt height, flt * u, flt * v) { flt r1; r1=pnt.x*pnt.x + pnt.y*pnt.y; *v=pnt.z / height; if (pnt.y<0.0) *u=1.0 - acos(pnt.x/sqrt(r1))/TWOPI; else *u=acos(pnt.x/sqrt(r1))/TWOPI; } void xyztospr(vector pnt, flt * u, flt * v) { flt r1, phi, theta; r1=sqrt(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z); phi=acos(-pnt.y/r1); *v=phi/3.1415926; theta=acos((pnt.x/r1)/sin(phi))/TWOPI; if (pnt.z > 0.0) *u = theta; else *u = 1 - theta; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/plane.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * plane.cpp - This file contains the functions for dealing with planes. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define PLANE_PRIVATE #include "plane.h" static object_methods plane_methods = { (void (*)(void *, void *))(plane_intersect), (void (*)(void *, void *, void *, void *))(plane_normal), plane_bbox, free }; object * newplane(void * tex, vector ctr, vector norm) { plane * p; p=(plane *) rt_getmem(sizeof(plane)); memset(p, 0, sizeof(plane)); p->methods = &plane_methods; p->tex = (texture *)tex; p->norm = norm; VNorm(&p->norm); p->d = -VDot(&ctr, &p->norm); return (object *) p; } static int plane_bbox(void * obj, vector * min, vector * max) { return 0; } static void plane_intersect(plane * pln, ray * ry) { flt t,td; t=-(pln->d + VDot(&pln->norm, &ry->o)); td=VDot(&pln->norm, &ry->d); if (td != 0.0) { t /= td; if (t > 0.0) add_intersection(t,(object *) pln, ry); } } static void plane_normal(plane * pln, vector * pnt, ray * incident, vector * N) { *N=pln->norm; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon_video.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "common/gui/video.h" class tachyon_video : public video { public: bool updating_mode; bool recycling; bool pausing; void on_process(); void on_key(int key); }; extern class tachyon_video *video;
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/ppm.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ppm.cpp - This file deals with PPM format image files (reading/writing) */ /* For our puposes, we're interested only in the 3 byte per pixel 24 bit truecolor sort of file.. Probably won't implement any decent checking at this point, probably choke on things like the # comments.. */ // Try preventing lots of GCC warnings about ignored results of fscanf etc. #if !__INTEL_COMPILER #if __GNUC__<4 || __GNUC__==4 && __GNUC_MINOR__<5 // For older versions of GCC, disable use of __wur in GLIBC #undef _FORTIFY_SOURCE #define _FORTIFY_SOURCE 0 #else // Starting from 4.5, GCC has a suppression option #pragma GCC diagnostic ignored "-Wunused-result" #endif #endif //__INTEL_COMPILER #include <stdio.h> #include "machine.h" #include "types.h" #include "util.h" #include "imageio.h" /* error codes etc */ #include "ppm.h" static int getint(FILE * dfile) { char ch[200]; int i; int num; num=0; while (num==0) { fscanf(dfile, "%s", ch); while (ch[0]=='#') { fgets(ch, 200, dfile); } num=sscanf(ch, "%d", &i); } return i; } int readppm(char * name, int * xres, int * yres, unsigned char **imgdata) { char data[200]; FILE * ifp; int i; size_t bytesread; int datasize; ifp=fopen(name, "r"); if (ifp==NULL) { return IMAGEBADFILE; /* couldn't open the file */ } fscanf(ifp, "%s", data); if (strcmp(data, "P6")) { fclose(ifp); return IMAGEUNSUP; /* not a format we support */ } *xres=getint(ifp); *yres=getint(ifp); i=getint(ifp); /* eat the maxval number */ fread(&i, 1, 1, ifp); /* eat the newline */ datasize = 3 * (*xres) * (*yres); *imgdata=(unsigned char *)rt_getmem(datasize); bytesread=fread(*imgdata, 1, datasize, ifp); fclose(ifp); if (bytesread != datasize) return IMAGEREADERR; return IMAGENOERR; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/global.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * global.h - any/all global data items etc should be in this file * * $Id: global.h,v 1.2 2007-02-22 17:54:15 Exp $ * */ /* stuff moved from intersect.c */ extern object * rootobj; extern point_light * lightlist[MAXLIGHTS]; extern int numlights; extern unsigned int numobjects; extern unsigned int rt_mem_in_use; extern int parinitted; extern int graphicswindowopen;
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/imap.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * imap.h - This file contains defines etc for doing image map type things. * * $Id: imap.h,v 1.2 2007-02-22 17:54:15 Exp $ */ void ResetImage(void); void LoadImage(rawimage *); color ImageMap(rawimage *, flt, flt); rawimage * AllocateImage(char *); void DeallocateImage(rawimage *); void ResetImages(void);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/cylinder.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cylinder.h - This file contains the defines for cylinders etc. * * $Id: cylinder.h,v 1.2 2007-02-22 17:54:15 Exp $ */ object * newcylinder(void *, vector, vector, flt); object * newfcylinder(void *, vector, vector, flt); #ifdef CYLINDER_PRIVATE typedef struct { unsigned int id; /* Unique Object serial number */ void * nextobj; /* pointer to next object in list */ object_methods * methods; /* this object's methods */ texture * tex; /* object texture */ vector ctr; vector axis; flt rad; } cylinder; static void cylinder_intersect(cylinder *, ray *); static void fcylinder_intersect(cylinder *, ray *); static int cylinder_bbox(void * obj, vector * min, vector * max); static int fcylinder_bbox(void * obj, vector * min, vector * max); static void cylinder_normal(cylinder *, vector *, ray *, vector *); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/vol.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vol.h - Volume rendering definitions etc. * * * $Id: vol.h,v 1.2 2007-02-22 17:54:17 Exp $ */ void * newscalarvol(void * intex, vector min, vector max, int xs, int ys, int zs, char * fname, scalarvol * invol); void LoadVol(scalarvol *); color scalar_volume_texture(vector *, texture *, ray *);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/objbound.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * objbound.cpp - This file contains the functions to find bounding boxes * for the various primitives */ #include "machine.h" #include "types.h" #include "macros.h" #include "bndbox.h" #define OBJBOUND_PRIVATE #include "objbound.h" static void globalbound(object ** rootlist, vector * gmin, vector * gmax) { vector min, max; object * cur; if (*rootlist == NULL) /* don't bound non-existant objects */ return; gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE; gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE; cur=*rootlist; while (cur != NULL) { /* Go! */ min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE; max.x = FHUGE; max.y = FHUGE; max.z = FHUGE; cur->methods->bbox((void *) cur, &min, &max); gmin->x = MYMIN( gmin->x , min.x); gmin->y = MYMIN( gmin->y , min.y); gmin->z = MYMIN( gmin->z , min.z); gmax->x = MYMAX( gmax->x , max.x); gmax->y = MYMAX( gmax->y , max.y); gmax->z = MYMAX( gmax->z , max.z); cur=(object *)cur->nextobj; } } static int objinside(object * obj, vector * min, vector * max) { vector omin, omax; if (obj == NULL) /* non-existant object, shouldn't get here */ return 0; if (obj->methods->bbox((void *) obj, &omin, &omax)) { if ((min->x <= omin.x) && (min->y <= omin.y) && (min->z <= omin.z) && (max->x >= omax.x) && (max->y >= omax.y) && (max->z >= omax.z)) { return 1; } } return 0; } static int countobj(object * root) { object * cur; /* counts the number of objects on a list */ int numobj; numobj=0; cur=root; while (cur != NULL) { cur=(object *)cur->nextobj; numobj++; } return numobj; } static void movenextobj(object * thisobj, object ** root) { object * cur, * tmp; /* move the object after thisobj to the front of the object list */ /* headed by root */ if (thisobj != NULL) { if (thisobj->nextobj != NULL) { cur=(object *)thisobj->nextobj; /* the object to be moved */ thisobj->nextobj = cur->nextobj; /* link around the moved obj */ tmp=*root; /* store the root node */ cur->nextobj=tmp; /* attach root to cur */ *root=cur; /* make cur, the new root */ } } } static void octreespace(object ** rootlist, int maxoctnodes) { object * cur; vector gmin, gmax, gctr; vector cmin1, cmin2, cmin3, cmin4, cmin5, cmin6, cmin7, cmin8; vector cmax1, cmax2, cmax3, cmax4, cmax5, cmax6, cmax7, cmax8; bndbox * box1, * box2, * box3, * box4; bndbox * box5, * box6, * box7, * box8; if (*rootlist == NULL) /* don't subdivide non-existant data */ return; globalbound(rootlist, &gmin, &gmax); /* find global min and max */ gctr.x = ((gmax.x - gmin.x) / 2.0) + gmin.x; gctr.y = ((gmax.y - gmin.y) / 2.0) + gmin.y; gctr.z = ((gmax.z - gmin.z) / 2.0) + gmin.z; cmin1=gmin; cmax1=gctr; box1 = newbndbox(cmin1, cmax1); cmin2=gmin; cmin2.x=gctr.x; cmax2=gmax; cmax2.y=gctr.y; cmax2.z=gctr.z; box2 = newbndbox(cmin2, cmax2); cmin3=gmin; cmin3.y=gctr.y; cmax3=gmax; cmax3.x=gctr.x; cmax3.z=gctr.z; box3 = newbndbox(cmin3, cmax3); cmin4=gmin; cmin4.x=gctr.x; cmin4.y=gctr.y; cmax4=gmax; cmax4.z=gctr.z; box4 = newbndbox(cmin4, cmax4); cmin5=gmin; cmin5.z=gctr.z; cmax5=gctr; cmax5.z=gmax.z; box5 = newbndbox(cmin5, cmax5); cmin6=gctr; cmin6.y=gmin.y; cmax6=gmax; cmax6.y=gctr.y; box6 = newbndbox(cmin6, cmax6); cmin7=gctr; cmin7.x=gmin.x; cmax7=gctr; cmax7.y=gmax.y; cmax7.z=gmax.z; box7 = newbndbox(cmin7, cmax7); cmin8=gctr; cmax8=gmax; box8 = newbndbox(cmin8, cmax8); cur = *rootlist; while (cur != NULL) { if (objinside((object *)cur->nextobj, &cmin1, &cmax1)) { movenextobj(cur, &box1->objlist); } else if (objinside((object *)cur->nextobj, &cmin2, &cmax2)) { movenextobj(cur, &box2->objlist); } else if (objinside((object *)cur->nextobj, &cmin3, &cmax3)) { movenextobj(cur, &box3->objlist); } else if (objinside((object *)cur->nextobj, &cmin4, &cmax4)) { movenextobj(cur, &box4->objlist); } else if (objinside((object *)cur->nextobj, &cmin5, &cmax5)) { movenextobj(cur, &box5->objlist); } else if (objinside((object *)cur->nextobj, &cmin6, &cmax6)) { movenextobj(cur, &box6->objlist); } else if (objinside((object *)cur->nextobj, &cmin7, &cmax7)) { movenextobj(cur, &box7->objlist); } else if (objinside((object *)cur->nextobj, &cmin8, &cmax8)) { movenextobj(cur, &box8->objlist); } else { cur=(object *)cur->nextobj; } } /* new scope, for redefinition of cur, and old */ { bndbox * cur, * old; old=box1; cur=box2; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box3; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box4; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box5; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box6; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box7; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box8; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } old->nextobj=*rootlist; if (countobj(box1->objlist) > 0) { globalbound(&box1->objlist, &box1->min, &box1->max); *rootlist=(object *) box1; } else { *rootlist=(object *) box1->nextobj; } } /**** end of special cur and old scope */ if (countobj(box1->objlist) > maxoctnodes) { octreespace(&box1->objlist, maxoctnodes); } if (countobj(box2->objlist) > maxoctnodes) { octreespace(&box2->objlist, maxoctnodes); } if (countobj(box3->objlist) > maxoctnodes) { octreespace(&box3->objlist, maxoctnodes); } if (countobj(box4->objlist) > maxoctnodes) { octreespace(&box4->objlist, maxoctnodes); } if (countobj(box5->objlist) > maxoctnodes) { octreespace(&box5->objlist, maxoctnodes); } if (countobj(box6->objlist) > maxoctnodes) { octreespace(&box6->objlist, maxoctnodes); } if (countobj(box7->objlist) > maxoctnodes) { octreespace(&box7->objlist, maxoctnodes); } if (countobj(box8->objlist) > maxoctnodes) { octreespace(&box8->objlist, maxoctnodes); } } void dividespace(int maxoctnodes, object **toplist) { bndbox * gbox; vector gmin, gmax; if (countobj(*toplist) > maxoctnodes) { globalbound(toplist, &gmin, &gmax); octreespace(toplist, maxoctnodes); gbox = newbndbox(gmin, gmax); gbox->objlist = NULL; gbox->tex = NULL; gbox->nextobj=NULL; gbox->objlist=*toplist; *toplist=(object *) gbox; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/jpeg.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * jpeg.h - This file deals with JPEG format image files (reading/writing) * * $Id: jpeg.h,v 1.2 2007-02-22 17:54:15 Exp $ */ int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/api.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***************************************************************************** * api.h - The declarations and prototypes needed so that 3rd party driver * * code can run the raytracer. Third party driver code should * * only use the functions in this header file to interface with * * the rendering engine. * *************************************************************************** */ /* * $Id: api.h,v 1.2 2007-02-22 17:54:15 Exp $ */ /********************************************/ /* Types defined for use with the API calls */ /********************************************/ #ifdef USESINGLEFLT typedef float apiflt; /* generic floating point number */ #else typedef double apiflt; /* generic floating point number */ #endif typedef void * SceneHandle; typedef struct { int texturefunc; /* which texture function to use */ color col; /* base object color */ int shadowcast; /* does the object cast a shadow */ apiflt ambient; /* ambient lighting */ apiflt diffuse; /* diffuse reflection */ apiflt specular; /* specular reflection */ apiflt opacity; /* how opaque the object is */ vector ctr; /* origin of texture */ vector rot; /* rotation of texture around origin */ vector scale; /* scale of texture in x,y,z */ vector uaxs; /* planar map u axis */ vector vaxs; /* planar map v axis */ char imap[96]; /* name of image map */ } apitexture; /******************************************************************* * NOTE: The value passed in apitexture.texturefunc corresponds to * the meanings given in this table: * * 0 - No texture function is applied other than standard lighting. * 1 - 3D checkerboard texture. Red & Blue checkers through 3d space. * 2 - Grit texture, roughens up the surface of the object a bit. * 3 - 3D marble texture. Makes a 3D swirl pattern through the object. * 4 - 3D wood texture. Makes a 3D wood pattern through the object. * 5 - 3D gradient noise function. * 6 - I've forgotten :-) * 7 - Cylindrical Image Map **** IMAGE MAPS REQUIRE the filename * 8 - Spherical Image Map of the image be put in imap[] * 9 - Planar Image Map part of the texture... * planar requires uaxs, and vaxs.. * *******************************************************************/ /********************************************/ /* Functions implemented to provide the API */ /********************************************/ vector rt_vector(apiflt x, apiflt y, apiflt z); /* helper to make vectors */ color rt_color(apiflt r, apiflt g, apiflt b); /* helper to make colors */ void rt_initialize();/* reset raytracer, memory deallocation */ void rt_finalize(void); /* close down for good.. */ SceneHandle rt_newscene(void); /* allocate new scene */ void rt_deletescene(SceneHandle); /* delete a scene */ void rt_renderscene(SceneHandle); /* raytrace the current scene */ void rt_outputfile(SceneHandle, const char * outname); void rt_resolution(SceneHandle, int hres, int vres); void rt_verbose(SceneHandle, int v); void rt_rawimage(SceneHandle, unsigned char *rawimage); void rt_background(SceneHandle, color); /* Parameter values for rt_boundmode() */ #define RT_BOUNDING_DISABLED 0 #define RT_BOUNDING_ENABLED 1 void rt_boundmode(SceneHandle, int); void rt_boundthresh(SceneHandle, int); /* Parameter values for rt_displaymode() */ #define RT_DISPLAY_DISABLED 0 #define RT_DISPLAY_ENABLED 1 void rt_displaymode(SceneHandle, int); void rt_scenesetup(SceneHandle, char *, int, int, int); /* scene, output filename, horizontal resolution, vertical resolution, verbose mode */ void rt_camerasetup(SceneHandle, apiflt, apiflt, int, int, vector, vector, vector); /* camera parms: scene, zoom, aspectratio, antialiasing, raydepth, camera center, view direction, up direction */ void * rt_texture(apitexture *); /* pointer to the texture struct that would have been passed to each object() call in older revisions.. */ void rt_light(void * , vector, apiflt); /* add a light */ /* light parms: texture, center, radius */ void rt_sphere(void *, vector, apiflt); /* add a sphere */ /* sphere parms: texture, center, radius */ void rt_scalarvol(void *, vector, vector, int, int, int, char *, void *); void rt_extvol(void *, vector, vector, int, apiflt (* evaluator)(apiflt, apiflt, apiflt)); void rt_box(void *, vector, vector); /* box parms: texture, min, max */ void rt_plane(void *, vector, vector); /* plane parms: texture, center, normal */ void rt_ring(void *, vector, vector, apiflt, apiflt); /* ring parms: texture, center, normal, inner, outer */ void rt_tri(void *, vector, vector, vector); /* tri parms: texture, vertex 0, vertex 1, vertex 2 */ void rt_stri(void *, vector, vector, vector, vector, vector, vector); /* stri parms: texture, vertex 0, vertex 1, vertex 2, norm 0, norm 1, norm 2 */ void rt_heightfield(void *, vector, int, int, apiflt *, apiflt, apiflt); /* field parms: texture, center, m, n, field, wx, wy */ void rt_landscape(void *, int, int, vector, apiflt, apiflt); void rt_quadsphere(void *, vector, apiflt); /* add quadric sphere */ /* sphere parms: texture, center, radius */ void rt_cylinder(void *, vector, vector, apiflt); void rt_fcylinder(void *, vector, vector, apiflt); void rt_polycylinder(void *, vector *, int, apiflt); /* new texture handling routines */ void rt_tex_color(void * voidtex, color col); #define RT_PHONG_PLASTIC 0 #define RT_PHONG_METAL 1 void rt_tex_phong(void * voidtex, apiflt phong, apiflt phongexp, int type);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/intersect.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * intersect.h - This file contains the declarations and defines for the * functions that manage intersection, bounding and CSG.. * * $Id: intersect.h,v 1.2 2007-02-22 17:54:15 Exp $ */ unsigned int new_objectid(void); unsigned int max_objectid(void); void add_object(object *); void reset_object(void); void free_objects(object *); void intersect_objects(ray *); void reset_intersection(intersectstruct *); void add_intersection(flt, object *, ray *); int closest_intersection(flt *, object **, intersectstruct *); int next_intersection(object **, object *, intersectstruct *); int shadow_intersection(intersectstruct * intstruct, flt maxdist);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/shade.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * shade.h - This file contains declarations and definitions for the shader. * * $Id: shade.h,v 1.2 2007-02-22 17:54:16 Exp $ */ void reset_lights(void); void add_light(point_light *); color shader(ray *); color shade_reflection(ray *, vector *, vector *, flt); color shade_transmission(ray *, vector *, flt); flt shade_phong(ray * incident, vector * hit, vector * N, vector * L, flt specpower);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/objbound.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * objbound.h - defines for object bounding code. * * $Id: objbound.h,v 1.2 2007-02-22 17:54:15 Exp $ */ void dividespace(int, object **); #ifdef OBJBOUND_PRIVATE static void globalbound(object **, vector *, vector *); static int objinside(object * obj, vector * min, vector * max); static int countobj(object *); static void movenextobj(object *, object **); static void octreespace(object **, int); #endif
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/camera.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * camera.h - This file contains the defines for camera routines etc. * * $Id: camera.h,v 1.2 2007-02-22 17:54:15 Exp $ */ ray camray(scenedef *, int, int);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/render.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * render.h - This file contains the defines for the top level functions * * $Id: render.h,v 1.2 2007-02-22 17:54:16 Exp $ */ void renderscene(scenedef);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/texture.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * texture.h This file contains all of the includes and defines for the texture * mapping part of the shader. * * $Id: texture.h,v 1.2 2007-02-22 17:54:16 Exp $ */ void InitTextures(void); color standard_texture(vector *, texture *, ray *); color image_cyl_texture(vector *, texture *, ray *); color image_sphere_texture(vector *, texture *, ray *); color image_plane_texture(vector *, texture *, ray *); color checker_texture(vector *, texture *, ray *); color cyl_checker_texture(vector *, texture *, ray *); color grit_texture(vector *, texture *, ray *); color wood_texture(vector *, texture *, ray *); color marble_texture(vector *, texture *, ray *); color gnoise_texture(vector *, texture *, ray *); int Noise(flt, flt, flt); void InitTextures(void);
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/cylinder.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cylinder.cpp - This file contains the functions for dealing with cylinders. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define CYLINDER_PRIVATE #include "cylinder.h" static object_methods cylinder_methods = { (void (*)(void *, void *))(cylinder_intersect), (void (*)(void *, void *, void *, void *))(cylinder_normal), cylinder_bbox, free }; static object_methods fcylinder_methods = { (void (*)(void *, void *))(fcylinder_intersect), (void (*)(void *, void *, void *, void *))(cylinder_normal), fcylinder_bbox, free }; object * newcylinder(void * tex, vector ctr, vector axis, flt rad) { cylinder * c; c=(cylinder *) rt_getmem(sizeof(cylinder)); memset(c, 0, sizeof(cylinder)); c->methods = &cylinder_methods; c->tex=(texture *) tex; c->ctr=ctr; c->axis=axis; c->rad=rad; return (object *) c; } static int cylinder_bbox(void * obj, vector * min, vector * max) { return 0; /* infinite / unbounded object */ } static void cylinder_intersect(cylinder * cyl, ray * ry) { vector rc, n, D, O; flt t, s, tin, tout, ln, d; rc.x = ry->o.x - cyl->ctr.x; rc.y = ry->o.y - cyl->ctr.y; rc.z = ry->o.z - cyl->ctr.z; VCross(&ry->d, &cyl->axis, &n); VDOT(ln, n, n); ln=sqrt(ln); /* finish length calculation */ if (ln == 0.0) { /* ray is parallel to the cylinder.. */ VDOT(d, rc, cyl->axis); D.x = rc.x - d * cyl->axis.x; D.y = rc.y - d * cyl->axis.y; D.z = rc.z - d * cyl->axis.z; VDOT(d, D, D); d = sqrt(d); tin = -FHUGE; tout = FHUGE; /* if (d <= cyl->rad) then ray is inside cylinder.. else outside */ } VNorm(&n); VDOT(d, rc, n); d = fabs(d); if (d <= cyl->rad) { /* ray intersects cylinder.. */ VCross(&rc, &cyl->axis, &O); VDOT(t, O, n); t = - t / ln; VCross(&n, &cyl->axis, &O); VNorm(&O); VDOT(s, ry->d, O); s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s); tin = t - s; add_intersection(tin, (object *) cyl, ry); tout = t + s; add_intersection(tout, (object *) cyl, ry); } } static void cylinder_normal(cylinder * cyl, vector * pnt, ray * incident, vector * N) { vector a,b,c; flt t; VSub((vector *) pnt, &(cyl->ctr), &a); c=cyl->axis; VNorm(&c); VDOT(t, a, c); b.x = c.x * t + cyl->ctr.x; b.y = c.y * t + cyl->ctr.y; b.z = c.z * t + cyl->ctr.z; VSub(pnt, &b, N); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { /* make cylinder double sided */ N->x=-N->x; N->y=-N->y; N->z=-N->z; } } object * newfcylinder(void * tex, vector ctr, vector axis, flt rad) { cylinder * c; c=(cylinder *) rt_getmem(sizeof(cylinder)); memset(c, 0, sizeof(cylinder)); c->methods = &fcylinder_methods; c->tex=(texture *) tex; c->ctr=ctr; c->axis=axis; c->rad=rad; return (object *) c; } static int fcylinder_bbox(void * obj, vector * min, vector * max) { cylinder * c = (cylinder *) obj; vector mintmp, maxtmp; mintmp.x = c->ctr.x; mintmp.y = c->ctr.y; mintmp.z = c->ctr.z; maxtmp.x = c->ctr.x + c->axis.x; maxtmp.y = c->ctr.y + c->axis.y; maxtmp.z = c->ctr.z + c->axis.z; min->x = MYMIN(mintmp.x, maxtmp.x); min->y = MYMIN(mintmp.y, maxtmp.y); min->z = MYMIN(mintmp.z, maxtmp.z); min->x -= c->rad; min->y -= c->rad; min->z -= c->rad; max->x = MYMAX(mintmp.x, maxtmp.x); max->y = MYMAX(mintmp.y, maxtmp.y); max->z = MYMAX(mintmp.z, maxtmp.z); max->x += c->rad; max->y += c->rad; max->z += c->rad; return 1; } static void fcylinder_intersect(cylinder * cyl, ray * ry) { vector rc, n, O, hit, tmp2, ctmp4; flt t, s, tin, tout, ln, d, tmp, tmp3; rc.x = ry->o.x - cyl->ctr.x; rc.y = ry->o.y - cyl->ctr.y; rc.z = ry->o.z - cyl->ctr.z; VCross(&ry->d, &cyl->axis, &n); VDOT(ln, n, n); ln=sqrt(ln); /* finish length calculation */ if (ln == 0.0) { /* ray is parallel to the cylinder.. */ return; /* in this case, we want to miss or go through the "hole" */ } VNorm(&n); VDOT(d, rc, n); d = fabs(d); if (d <= cyl->rad) { /* ray intersects cylinder.. */ VCross(&rc, &cyl->axis, &O); VDOT(t, O, n); t = - t / ln; VCross(&n, &cyl->axis, &O); VNorm(&O); VDOT(s, ry->d, O); s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s); tin = t - s; RAYPNT(hit, (*ry), tin); ctmp4=cyl->axis; VNorm(&ctmp4); tmp2.x = hit.x - cyl->ctr.x; tmp2.y = hit.y - cyl->ctr.y; tmp2.z = hit.z - cyl->ctr.z; VDOT(tmp, tmp2, ctmp4); VDOT(tmp3, cyl->axis, cyl->axis); if ((tmp > 0.0) && (tmp < sqrt(tmp3))) add_intersection(tin, (object *) cyl, ry); tout = t + s; RAYPNT(hit, (*ry), tout); tmp2.x = hit.x - cyl->ctr.x; tmp2.y = hit.y - cyl->ctr.y; tmp2.z = hit.z - cyl->ctr.z; VDOT(tmp, tmp2, ctmp4); VDOT(tmp3, cyl->axis, cyl->axis); if ((tmp > 0.0) && (tmp < sqrt(tmp3))) add_intersection(tout, (object *) cyl, ry); } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon.serial/trace.serial.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" // shared but read-only so could be private too static thr_parms *all_parms; static scenedef scene; static int startx; static int stopx; static int starty; static int stopy; static flt jitterscale; static int totaly; static color_t render_one_pixel (int x, int y, unsigned int *local_mbox, unsigned int &serial, int startx, int stopx, int starty, int stopy) { /* private vars moved inside loop */ ray primary, sample; color col, avcol; int R,G,B; intersectstruct local_intersections; int alias; /* end private */ primary=camray(&scene, x, y); primary.intstruct = &local_intersections; primary.flags = RT_RAY_REGULAR; serial++; primary.serial = serial; primary.mbox = local_mbox; primary.maxdist = FHUGE; primary.scene = &scene; col=trace(&primary); serial = primary.serial; /* perform antialiasing if enabled.. */ if (scene.antialiasing > 0) { for (alias=0; alias < scene.antialiasing; alias++) { serial++; /* increment serial number */ sample=primary; /* copy the regular primary ray to start with */ sample.serial = serial; { sample.d.x+=((std::rand() % 100) - 50) / jitterscale; sample.d.y+=((std::rand() % 100) - 50) / jitterscale; sample.d.z+=((std::rand() % 100) - 50) / jitterscale; } avcol=trace(&sample); serial = sample.serial; /* update our overall serial # */ col.r += avcol.r; col.g += avcol.g; col.b += avcol.b; } col.r /= (scene.antialiasing + 1.0); col.g /= (scene.antialiasing + 1.0); col.b /= (scene.antialiasing + 1.0); } /* Handle overexposure and underexposure here... */ R=(int) (col.r*255); if (R > 255) R = 255; else if (R < 0) R = 0; G=(int) (col.g*255); if (G > 255) G = 255; else if (G < 0) G = 0; B=(int) (col.b*255); if (B > 255) B = 255; else if (B < 0) B = 0; return video->get_color(R, G, B); } static void parallel_thread (void) { // thread-local storage unsigned int serial = 1; unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); unsigned int * local_mbox = (unsigned int *) alloca(mboxsize); memset(local_mbox,0,mboxsize); for (int y = starty; y < stopy; y++) { { drawing_area drawing(startx, totaly-y, stopx-startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } } if(!video->next_frame()) return; } } void * thread_trace(thr_parms * parms) { // shared but read-only so could be private too all_parms = parms; scene = parms->scene; startx = parms->startx; stopx = parms->stopx; starty = parms->starty; stopy = parms->stopy; jitterscale = 40.0*(scene.hres + scene.vres); totaly = parms->scene.vres-1; parallel_thread (); return(NULL); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon.serial/tachyon.serial.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /****************************************************************************** The tachyon sample program is for use with the Guided Vtune Tutorial. Please refer to the github's readme for instructions. *******************************************************************************/ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" // shared but read-only so could be private too static thr_parms* all_parms; static scenedef scene; static int startx; static int stopx; static int starty; static int stopy; static flt jitterscale; static int totaly; // This function is shared among all implementations: static color_t render_one_pixel(int x, int y, unsigned int* local_mbox, unsigned int& serial, int startx, int stopx, int starty, int stopy) { /* private vars moved inside loop */ ray primary; color col; int R, G, B; intersectstruct local_intersections; /* end private */ primary = camray(&scene, x, y); primary.intstruct = &local_intersections; primary.flags = RT_RAY_REGULAR; serial++; primary.serial = serial; primary.mbox = local_mbox; primary.maxdist = FHUGE; primary.scene = &scene; col = trace(&primary); serial = primary.serial; /* Handle overexposure and underexposure here... */ R = (int)(col.r * 255); if (R > 255) R = 255; else if (R < 0) R = 0; G = (int)(col.g * 255); if (G > 255) G = 255; else if (G < 0) G = 0; B = (int)(col.b * 255); if (B > 255) B = 255; else if (B < 0) B = 0; return video->get_color(R, G, B); } #if DO_ITT_NOTIFY #include"ittnotify.h" #endif // This is the solely serial version of this function. After running this and profiling with Vtune, you will see that // this code may run a lot quicker if the work was divided among threads. static void parallel_thread(void) { unsigned int serial = 1; unsigned int mboxsize = sizeof(unsigned int) * (max_objectid() + 20); unsigned int* local_mbox = (unsigned int*)alloca(mboxsize); memset(local_mbox, 0, mboxsize); for (int y = starty; y < stopy; y++) { { drawing_area drawing(startx, totaly - y, stopx - startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } } if (!video->next_frame()) return; } } // This function is shared among all implementations. void* thread_trace(thr_parms* parms) { // shared but read-only so could be private too all_parms = parms; scene = parms->scene; startx = parms->startx; stopx = parms->stopx; starty = parms->starty; stopy = parms->stopy; jitterscale = 40.0 * (scene.hres + scene.vres); totaly = parms->scene.vres - 1; #if DO_ITT_NOTIFY __itt_resume(); #endif parallel_thread(); #if DO_ITT_NOTIFY __itt_pause(); #endif return(NULL); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon.tbb/tachyon.tbb.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /****************************************************************************** The tachyon sample program is for use with the Guided Vtune Tutorial. Please refer to the github's readme for build instructions. *******************************************************************************/ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" #include <tbb/tbb.h> // Initialize the mutex to be used later: tbb::spin_mutex mtx; // shared but read-only so could be private too static thr_parms* all_parms; static scenedef scene; static int startx; static int stopx; static int starty; static int stopy; static flt jitterscale; static int totaly; // This function is shared among all implementations: static color_t render_one_pixel(int x, int y, unsigned int* local_mbox, unsigned int& serial, int startx, int stopx, int starty, int stopy) { /* private vars moved inside loop */ ray primary; color col; int R, G, B; intersectstruct local_intersections; /* end private */ primary = camray(&scene, x, y); primary.intstruct = &local_intersections; primary.flags = RT_RAY_REGULAR; serial++; primary.serial = serial; primary.mbox = local_mbox; primary.maxdist = FHUGE; primary.scene = &scene; col = trace(&primary); serial = primary.serial; /* Handle overexposure and underexposure here... */ R = (int)(col.r * 255); if (R > 255) R = 255; else if (R < 0) R = 0; G = (int)(col.g * 255); if (G > 255) G = 255; else if (G < 0) G = 0; B = (int)(col.b * 255); if (B > 255) B = 255; else if (B < 0) B = 0; return video->get_color(R, G, B); } #if DO_ITT_NOTIFY #include"ittnotify.h" #endif // To start off with our TBB implementation, we are being overly cautious and adding a mutex // lock around our for loop. The idea behind this is there is a chance multiple threads are accessing // the same variables, so we can add a mutex lock around it to only allow one thread to access that section // at a time. Run this with Vtune to see what improvements can be made. static void parallel_thread(void) { unsigned int mboxsize = sizeof(unsigned int) * (max_objectid() + 20); tbb::parallel_for(starty, stopy, [mboxsize](int y) { tbb::spin_mutex::scoped_lock lock(mtx); unsigned int serial = 1; unsigned int local_mbox[mboxsize]; memset(local_mbox, 0, mboxsize); drawing_area drawing(startx, totaly - y, stopx - startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } video->next_frame(); } ); } // This function is shared among all implementations: void* thread_trace(thr_parms* parms) { // shared but read-only so could be private too all_parms = parms; scene = parms->scene; startx = parms->startx; stopx = parms->stopx; starty = parms->starty; stopy = parms->stopy; jitterscale = 40.0 * (scene.hres + scene.vres); totaly = parms->scene.vres - 1; #if DO_ITT_NOTIFY __itt_resume(); #endif parallel_thread(); #if DO_ITT_NOTIFY __itt_pause(); #endif return(NULL); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon.tbb/tachyon.tbb_optimized.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /****************************************************************************** The tachyon sample program is for use with the Guided Vtune Tutorial. Please refer to the github's readme for build instructions. *******************************************************************************/ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" #include <tbb/tbb.h> // shared but read-only so could be private too static thr_parms* all_parms; static scenedef scene; static int startx; static int stopx; static int starty; static int stopy; static flt jitterscale; static int totaly; // This function is shared among all implementations: static color_t render_one_pixel(int x, int y, unsigned int* local_mbox, unsigned int& serial, int startx, int stopx, int starty, int stopy) { /* private vars moved inside loop */ ray primary; color col; int R, G, B; intersectstruct local_intersections; /* end private */ primary = camray(&scene, x, y); primary.intstruct = &local_intersections; primary.flags = RT_RAY_REGULAR; serial++; primary.serial = serial; primary.mbox = local_mbox; primary.maxdist = FHUGE; primary.scene = &scene; col = trace(&primary); serial = primary.serial; /* Handle overexposure and underexposure here... */ R = (int)(col.r * 255); if (R > 255) R = 255; else if (R < 0) R = 0; G = (int)(col.g * 255); if (G > 255) G = 255; else if (G < 0) G = 0; B = (int)(col.b * 255); if (B > 255) B = 255; else if (B < 0) B = 0; return video->get_color(R, G, B); } #if DO_ITT_NOTIFY #include"ittnotify.h" #endif // After removing the mutex, we find that the protection of variables is not actually needed. // Since they are local to the individual threads, each thread cannot actually access the other // variables. Profile this with Vtune and notice the differences. static void parallel_thread(void) { unsigned int mboxsize = sizeof(unsigned int) * (max_objectid() + 20); tbb::parallel_for(starty, stopy, [mboxsize](int y) { unsigned int serial = 1; unsigned int local_mbox[mboxsize]; memset(local_mbox, 0, mboxsize); drawing_area drawing(startx, totaly - y, stopx - startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } video->next_frame(); } ); } // This function is shared among all implementations: void* thread_trace(thr_parms* parms) { // shared but read-only so could be private too all_parms = parms; scene = parms->scene; startx = parms->startx; stopx = parms->stopx; starty = parms->starty; stopy = parms->stopy; jitterscale = 40.0 * (scene.hres + scene.vres); totaly = parms->scene.vres - 1; #if DO_ITT_NOTIFY __itt_resume(); #endif parallel_thread(); #if DO_ITT_NOTIFY __itt_pause(); #endif return(NULL); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/common/gui/video.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= #ifndef __VIDEO_H__ #define __VIDEO_H__ #include <cassert> #if _MSC_VER #include <stddef.h> // for uintptr_t #else #include <stdint.h> // for uintptr_t #endif #if _WIN32 || _WIN64 #include <windows.h> #else #include <unistd.h> #endif typedef unsigned int color_t; typedef unsigned char colorcomp_t; typedef signed char depth_t; #define UNUSED(x) (void)(x) //! Class for getting access to drawing memory class drawing_memory { #ifdef __TBB_MIC_OFFLOAD // The address is kept as uintptr_t since // the compiler could not offload a pointer #endif uintptr_t my_address; public: depth_t pixel_depth; int sizex, sizey; //! Get drawing memory inline char* get_address() const { return reinterpret_cast<char*>(my_address); } //! Get drawing memory size inline int get_size() const { return ((pixel_depth>16) ? 4:2) * sizex * sizey; } //! Set drawing memory inline void set_address(char *mem) { my_address = reinterpret_cast<uintptr_t>(mem); } friend class drawing_area; friend class video; }; //! Simple proxy class for managing of different video systems class video { //! colorspace information color_t red_mask; depth_t red_shift; color_t green_mask; depth_t green_shift; color_t blue_mask; depth_t blue_shift; depth_t depth; friend class drawing_area; public: //! Constructor video(); //! Destructor ~video(); //! member to set window name const char *title; //! true is enable to show fps bool calc_fps; //! if true: on windows fork processing thread for on_process(), on non-windows note that next_frame() is called concurrently. bool threaded; //! true while running within main_loop() bool running; //! if true, do gui updating bool updating; //! initialize graphical video system bool init_window(int sizex, int sizey); //! initialize console. returns true if console is available bool init_console(); //! terminate video system void terminate(); //! Do standard event & processing loop. Use threaded = true to separate event/updating loop from frame processing void main_loop(); //! Process next frame bool next_frame(); //! Change window title void show_title(); //! translate RGB components into packed type inline color_t get_color(colorcomp_t red, colorcomp_t green, colorcomp_t blue) const; //! Get drawing memory descriptor inline drawing_memory get_drawing_memory() const; //! code of the ESCape key static const int esc_key = 27; //! Mouse events handler. virtual void on_mouse(int x, int y, int key) { } //! Mouse events handler. virtual void on_key(int key) { } //! Main processing loop. Redefine with your own virtual void on_process() { while(next_frame()); } #ifdef _WINDOWS //! Windows specific members //! if VIDEO_WINMAIN isn't defined then set this just before init() by arguments of WinMain static HINSTANCE win_hInstance; static int win_iCmdShow; //! optionally call it just before init() to set own. Use ascii strings convention void win_set_class(WNDCLASSEX &); //! load and set accelerator table from resources void win_load_accelerators(int idc); #endif }; //! Drawing class class drawing_area { public: const int start_x, start_y, size_x, size_y; //! constructors drawing_area(int x, int y, int sizex, int sizey); inline drawing_area(int x, int y, int sizex, int sizey, const drawing_memory &dmem); //! destructor inline ~drawing_area(); //! update the image void update(); //! set current position. local_x could be bigger then size_x inline void set_pos(int local_x, int local_y); //! put pixel in current position with incremental address calculating to next right pixel inline void put_pixel(color_t color); //! draw pixel at position by packed color void set_pixel(int localx, int localy, color_t color) { set_pos(localx, localy); put_pixel(color); } private: const depth_t pixel_depth; const size_t base_index, max_index, index_stride; unsigned int* const ptr32; size_t index; }; extern int g_sizex; extern int g_sizey; extern unsigned int *g_pImg; inline drawing_memory video::get_drawing_memory() const { drawing_memory dmem; dmem.pixel_depth = depth; dmem.my_address = reinterpret_cast<uintptr_t>(g_pImg); dmem.sizex = g_sizex; dmem.sizey = g_sizey; return dmem; } inline color_t video::get_color(colorcomp_t red, colorcomp_t green, colorcomp_t blue) const { if(red_shift == 16) // only for depth == 24 && red_shift > blue_shift return (red<<16) | (green<<8) | blue; else if(depth >= 24) return #if __ANDROID__ // Setting Alpha to 0xFF 0xFF000000 | #endif (red<<red_shift) | (green<<green_shift) | (blue<<blue_shift); else if(depth > 0) { depth_t bs = blue_shift, rs = red_shift; if(blue_shift < 0) blue >>= -bs, bs = 0; else /*red_shift < 0*/ red >>= -rs, rs = 0; return ((red<<rs)&red_mask) | ((green<<green_shift)&green_mask) | ((blue<<bs)&blue_mask); } else { // UYVY colorspace unsigned y, u, v; y = red * 77 + green * 150 + blue * 29; // sum(77+150+29=256) * max(=255): limit->2^16 u = (2048 + (blue << 3) - (y >> 5)) >> 4; // (limit->2^12)>>4 v = (2048 + (red << 3) - (y >> 5)) >> 4; y = y >> 8; return u | (y << 8) | (v << 16) | (y << 24); } } inline drawing_area::drawing_area(int x, int y, int sizex, int sizey, const drawing_memory &dmem) : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(dmem.pixel_depth), base_index(y*dmem.sizex + x), max_index(dmem.sizex*dmem.sizey), index_stride(dmem.sizex), ptr32(reinterpret_cast<unsigned int*>(dmem.my_address)) { UNUSED(max_index); assert(x < dmem.sizex); assert(y < dmem.sizey); assert(x+sizex <= dmem.sizex); assert(y+sizey <= dmem.sizey); index = base_index; // current index } inline void drawing_area::set_pos(int local_x, int local_y) { index = base_index + local_x + local_y*index_stride; } inline void drawing_area::put_pixel(color_t color) { assert(index < max_index); if(pixel_depth > 16) ptr32[index++] = color; else if(pixel_depth > 0) ((unsigned short*)ptr32)[index++] = (unsigned short)color; else { // UYVY colorspace if(index&1) color >>= 16; ((unsigned short*)ptr32)[index++] = (unsigned short)color; } } inline drawing_area::~drawing_area() { #if ! __TBB_DEFINE_MIC update(); #endif } #if defined(_WINDOWS) && (defined(VIDEO_WINMAIN) || defined(VIDEO_WINMAIN_ARGS) ) #include <cstdlib> //! define WinMain for subsystem:windows. #ifdef VIDEO_WINMAIN_ARGS int main(int, char *[]); #else int main(); #endif int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR szCmdLine, int iCmdShow) { video::win_hInstance = hInstance; video::win_iCmdShow = iCmdShow; #ifdef VIDEO_WINMAIN_ARGS return main(__argc, __argv); #else return main(); #endif } #endif #endif// __VIDEO_H__
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/common/gui/winvideo.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /////// Common internal implementation of Windows-specific stuff ////////////// /////// Must be the first included header ////////////// #ifndef __WINVIDEO_H__ #define __WINVIDEO_H__ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE #endif // Check that the target Windows version has all API calls requried. #ifndef _WIN32_WINNT # define _WIN32_WINNT 0x0400 #endif #if _WIN32_WINNT<0x0400 # define YIELD_TO_THREAD() Sleep(0) #else # define YIELD_TO_THREAD() SwitchToThread() #endif #include "video.h" #include <fcntl.h> #include <io.h> #include <iostream> #include <fstream> #pragma comment(lib, "gdi32.lib") #pragma comment(lib, "user32.lib") // maximum mumber of lines the output console should have static const WORD MAX_CONSOLE_LINES = 500; const COLORREF RGBKEY = RGB(8, 8, 16); // at least 8 for 16-bit palette HWND g_hAppWnd; // The program's window handle HANDLE g_handles[2] = {0,0};// thread and wake up event unsigned int * g_pImg = 0; // drawing memory int g_sizex, g_sizey; static video * g_video = 0; WNDPROC g_pUserProc = 0; HINSTANCE video::win_hInstance = 0; int video::win_iCmdShow = 0; static WNDCLASSEX * gWndClass = 0; static HACCEL hAccelTable = 0; static DWORD g_msec = 0; static int g_fps = 0, g_updates = 0, g_skips = 0; bool DisplayError(LPSTR lpstrErr, HRESULT hres = 0); // always returns false LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); //! Create window bool WinInit(HINSTANCE hInstance, int nCmdShow, WNDCLASSEX *uwc, const char *title, bool fixedsize) { WNDCLASSEX wndclass; // Our app's windows class if(uwc) { memcpy(&wndclass, uwc, sizeof(wndclass)); g_pUserProc = uwc->lpfnWndProc; } else { memset(&wndclass, 0, sizeof(wndclass)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.lpszClassName = title; } wndclass.cbSize = sizeof(wndclass); wndclass.hInstance = hInstance; wndclass.lpfnWndProc = InternalWndProc; wndclass.style |= CS_HREDRAW | CS_VREDRAW; wndclass.hbrBackground = CreateSolidBrush(RGBKEY); if( !RegisterClassExA(&wndclass) ) return false; int xaddend = GetSystemMetrics(fixedsize?SM_CXFIXEDFRAME:SM_CXFRAME)*2; int yaddend = GetSystemMetrics(fixedsize?SM_CYFIXEDFRAME:SM_CYFRAME)*2 + GetSystemMetrics(SM_CYCAPTION); if(wndclass.lpszMenuName) yaddend += GetSystemMetrics(SM_CYMENU); // Setup the new window's physical parameters - and tell Windows to create it g_hAppWnd = CreateWindowA(wndclass.lpszClassName, // Window class name title, // Window caption !fixedsize ? WS_OVERLAPPEDWINDOW : // Window style WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX, CW_USEDEFAULT, // Initial x pos: use default placement 0, // Initial y pos: not used here g_sizex+xaddend,// Initial x size g_sizey+yaddend,// Initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // Creation parameters return g_hAppWnd != NULL; } //! create console window with redirection static bool RedirectIOToConsole(void) { int hConHandle; size_t lStdHandle; CONSOLE_SCREEN_BUFFER_INFO coninfo; FILE *fp; // allocate a console for this app AllocConsole(); // set the screen buffer to be big enough to let us scroll text GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); coninfo.dwSize.Y = MAX_CONSOLE_LINES; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); // redirect unbuffered STDOUT to the console lStdHandle = (size_t)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); if(hConHandle <= 0) return false; fp = _fdopen( hConHandle, "w" ); *stdout = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); // redirect unbuffered STDERR to the console lStdHandle = (size_t)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); if(hConHandle > 0) { fp = _fdopen( hConHandle, "w" ); *stderr = *fp; setvbuf( stderr, NULL, _IONBF, 0 ); } // redirect unbuffered STDIN to the console lStdHandle = (size_t)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); if(hConHandle > 0) { fp = _fdopen( hConHandle, "r" ); *stdin = *fp; setvbuf( stdin, NULL, _IONBF, 0 ); } // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog // point to console as well std::ios::sync_with_stdio(); return true; } video::video() : red_mask(0xff0000), red_shift(16), green_mask(0xff00), green_shift(8), blue_mask(0xff), blue_shift(0), depth(24) { assert(g_video == 0); g_video = this; title = "Video"; running = threaded = calc_fps = false; updating = true; } //! optionally call it just before init() to set own void video::win_set_class(WNDCLASSEX &wcex) { gWndClass = &wcex; } void video::win_load_accelerators(int idc) { hAccelTable = LoadAccelerators(win_hInstance, MAKEINTRESOURCE(idc)); } bool video::init_console() { if(RedirectIOToConsole()) { if(!g_pImg && g_sizex && g_sizey) g_pImg = new unsigned int[g_sizex * g_sizey]; if(g_pImg) running = true; return true; } return false; } video::~video() { if(g_video) terminate(); } DWORD WINAPI thread_video(LPVOID lpParameter) { video *v = (video*)lpParameter; v->on_process(); return 0; } static bool loop_once(video *v) { // screen update notify if(int updates = g_updates) { g_updates = 0; if(g_video->updating) { g_skips += updates-1; g_fps++; } else g_skips += updates; UpdateWindow(g_hAppWnd); } // update fps DWORD msec = GetTickCount(); if(v->calc_fps && msec >= g_msec+1000) { double sec = (msec - g_msec)/1000.0; char buffer[256], n = _snprintf(buffer, 128, "%s: %d fps", v->title, int(double(g_fps + g_skips)/sec)); if(g_skips) _snprintf(buffer+n, 128, " - %d skipped = %d updates", int(g_skips/sec), int(g_fps/sec)); SetWindowTextA(g_hAppWnd, buffer); g_msec = msec; g_skips = g_fps = 0; } // event processing, including painting MSG msg; if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ if( msg.message == WM_QUIT ) { v->running = false; return false; } if( !hAccelTable || !TranslateAccelerator(msg.hwnd, hAccelTable, &msg) ){ TranslateMessage(&msg); DispatchMessage(&msg); } return true; // try again } return false; } //! Do standard event loop void video::main_loop() { // let Windows draw and unroll the window InvalidateRect(g_hAppWnd, 0, false); g_msec = GetTickCount(); // let's stay for 0,5 sec while(g_msec + 500 > GetTickCount()) { loop_once(this); Sleep(1); } g_msec = GetTickCount(); // now, start main process if(threaded) { g_handles[0] = CreateThread ( NULL, // LPSECURITY_ATTRIBUTES security_attrs 0, // SIZE_T stacksize (LPTHREAD_START_ROUTINE) thread_video, this, // argument 0, 0); if(!g_handles[0]) { DisplayError((char*)"Can't create thread"); return; } else // harmless race is possible here g_handles[1] = CreateEvent(NULL, false, false, NULL); while(running) { while(loop_once(this)); YIELD_TO_THREAD(); // give time for processing when running on single CPU DWORD r = MsgWaitForMultipleObjects(2, g_handles, false, INFINITE, QS_ALLINPUT^QS_MOUSEMOVE); if(r == WAIT_OBJECT_0) break; // thread terminated } running = false; if(WaitForSingleObject(g_handles[0], 3000) == WAIT_TIMEOUT){ // there was not enough time for graceful shutdown, killing the example with code 1. exit(1); } if(g_handles[0]) CloseHandle(g_handles[0]); if(g_handles[1]) CloseHandle(g_handles[1]); g_handles[0] = g_handles[1] = 0; } else on_process(); } //! Refresh screen picture bool video::next_frame() { if(!running) return false; g_updates++; // Fast but inaccurate counter. The data race here is benign. if(!threaded) while(loop_once(this)); else if(g_handles[1]) { SetEvent(g_handles[1]); YIELD_TO_THREAD(); } return true; } //! Change window title void video::show_title() { if(g_hAppWnd) SetWindowTextA(g_hAppWnd, title); } #endif //__WINVIDEO_H__
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/common/gui/gdivideo.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= // common Windows parts #include "winvideo.h" // include GDI+ headers #include <gdiplus.h> // and another headers #include <stdio.h> // tag linking library #pragma comment(lib, "gdiplus.lib") // global specific variables Gdiplus::Bitmap * g_pBitmap; // main drawing bitmap ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartupInput gdiplusStartupInput;// GDI+ //! display system error bool DisplayError(LPSTR lpstrErr, HRESULT hres) { static bool InError = false; if (!InError) { InError = true; LPCSTR lpMsgBuf; if(!hres) hres = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hres, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); MessageBox(g_hAppWnd, lpstrErr, lpMsgBuf, MB_OK|MB_ICONERROR); LocalFree( (HLOCAL)lpMsgBuf ); InError = false; } return false; } //! Win event processing function LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) { case WM_MOVE: // Check to make sure our window exists before we tell it to repaint. // This will fail the first time (while the window is being created). if (hwnd) { InvalidateRect(hwnd, NULL, FALSE); UpdateWindow(hwnd); } return 0L; case WM_PAINT: { PAINTSTRUCT ps; Gdiplus::Graphics graphics( BeginPaint(hwnd, &ps) ); // redraw just requested area. This call is as fast as simple DrawImage() call. if(g_video->updating) graphics.DrawImage(g_pBitmap, (INT)ps.rcPaint.left, (INT)ps.rcPaint.top, (INT)ps.rcPaint.left, (INT)ps.rcPaint.top, (INT)ps.rcPaint.right, (INT)ps.rcPaint.bottom, Gdiplus::UnitPixel); EndPaint(hwnd, &ps); } return 0L; // Proccess all mouse and keyboard events case WM_LBUTTONDOWN: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), 1); break; case WM_LBUTTONUP: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), -1); break; case WM_RBUTTONDOWN: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), 2); break; case WM_RBUTTONUP: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), -2); break; case WM_MBUTTONDOWN: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), 3); break; case WM_MBUTTONUP: g_video->on_mouse( (int)LOWORD(lParam), (int)HIWORD(lParam), -3); break; case WM_CHAR: g_video->on_key( (int)wParam); break; // some useless stuff case WM_ERASEBKGND: return 1; // keeps erase-background events from happening, reduces chop case WM_DISPLAYCHANGE: return 0; // Now, shut down the window... case WM_DESTROY: PostQuitMessage(0); return 0; } // call user defined proc, if exists return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam); } ///////////// video functions //////////////// bool video::init_window(int sizex, int sizey) { assert(win_hInstance != 0); g_sizex = sizex; g_sizey = sizey; if (!WinInit(win_hInstance, win_iCmdShow, gWndClass, title, true)) { DisplayError((char*)"Unable to initialize the program's window."); return false; } ShowWindow(g_hAppWnd, SW_SHOW); Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); g_pImg = new unsigned int[sizex*sizey]; g_pBitmap = new Gdiplus::Bitmap(g_sizex, g_sizey, 4*g_sizex, PixelFormat32bppRGB, (BYTE*)g_pImg ); running = true; return true; } void video::terminate() { if(g_pBitmap) { delete g_pBitmap; g_pBitmap = 0; } Gdiplus::GdiplusShutdown(gdiplusToken); g_video = 0; running = false; if(g_pImg) { delete[] g_pImg; g_pImg = 0; } } //////////// drawing area constructor & destructor ///////////// drawing_area::drawing_area(int x, int y, int sizex, int sizey) : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(24), base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex), ptr32(g_pImg) { assert(x < g_sizex); assert(y < g_sizey); assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey); index = base_index; // current index } void drawing_area::update() { if(g_video->updating) { RECT r; r.left = start_x; r.right = start_x + size_x; r.top = start_y; r.bottom = start_y + size_y; InvalidateRect(g_hAppWnd, &r, false); } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/common/utility/fast_random.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= #ifndef FAST_RANDOM_H_ #define FAST_RANDOM_H_ namespace utility{ //------------------------------------------------------------------------ // FastRandom //------------------------------------------------------------------------ namespace internal{ size_t GetPrime ( size_t seed ); } //! A fast random number generator. /** Uses linear congruential method. */ class FastRandom { size_t x, a; public: //! Get a random number. unsigned short get() { return get(x); } //! Get a random number for the given seed; update the seed for next use. unsigned short get( size_t& seed ) { unsigned short r = (unsigned short)(seed>>16); seed = seed*a+1; return r; } //! Construct a random number generator. FastRandom( size_t seed ) { x = seed*internal::GetPrime(seed); a = internal::GetPrime(x); } }; } namespace utility { namespace internal{ //! Table of primes used by fast random-number generator (FastRandom). static const unsigned Primes[] = { 0x9e3779b1, 0xffe6cc59, 0x2109f6dd, 0x43977ab5, 0xba5703f5, 0xb495a877, 0xe1626741, 0x79695e6b, 0xbc98c09f, 0xd5bee2b3, 0x287488f9, 0x3af18231, 0x9677cd4d, 0xbe3a6929, 0xadc6a877, 0xdcf0674b, 0xbe4d6fe9, 0x5f15e201, 0x99afc3fd, 0xf3f16801, 0xe222cfff, 0x24ba5fdb, 0x0620452d, 0x79f149e3, 0xc8b93f49, 0x972702cd, 0xb07dd827, 0x6c97d5ed, 0x085a3d61, 0x46eb5ea7, 0x3d9910ed, 0x2e687b5b, 0x29609227, 0x6eb081f1, 0x0954c4e1, 0x9d114db9, 0x542acfa9, 0xb3e6bd7b, 0x0742d917, 0xe9f3ffa7, 0x54581edb, 0xf2480f45, 0x0bb9288f, 0xef1affc7, 0x85fa0ca7, 0x3ccc14db, 0xe6baf34b, 0x343377f7, 0x5ca19031, 0xe6d9293b, 0xf0a9f391, 0x5d2e980b, 0xfc411073, 0xc3749363, 0xb892d829, 0x3549366b, 0x629750ad, 0xb98294e5, 0x892d9483, 0xc235baf3, 0x3d2402a3, 0x6bdef3c9, 0xbec333cd, 0x40c9520f }; size_t GetPrime ( size_t seed ) { return Primes[seed%(sizeof(Primes)/sizeof(Primes[0]))]; } } } #endif /* FAST_RANDOM_H_ */
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/common/utility/utility.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= #ifndef UTILITY_H_ #define UTILITY_H_ #if __TBB_MIC_OFFLOAD #pragma offload_attribute (push,target(mic)) #include <exception> #include <cstdio> #pragma offload_attribute (pop) #endif // __TBB_MIC_OFFLOAD #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <sstream> #include <numeric> #include <stdexcept> #include <memory> #include <cassert> #include <iostream> #include <cstdlib> // TBB headers should not be used, as some examples may need to be built without TBB. namespace utility{ namespace internal{ #if ((__GNUC__*100+__GNUC_MINOR__>=404 && __GXX_EXPERIMENTAL_CXX0X__) || _MSC_VER >= 1600) && (!__INTEL_COMPILER || __INTEL_COMPILER >= 1200 ) // std::unique_ptr is available, and compiler can use it #define smart_ptr std::unique_ptr using std::swap; #else #if __INTEL_COMPILER && __GXX_EXPERIMENTAL_CXX0X__ // std::unique_ptr is unavailable, so suppress std::auto_prt<> deprecation warning #pragma warning(disable: 1478) #endif #define smart_ptr std::auto_ptr // in some C++ libraries, std::swap does not work with std::auto_ptr template<typename T> void swap( std::auto_ptr<T>& ptr1, std::auto_ptr<T>& ptr2 ) { std::auto_ptr<T> tmp; tmp = ptr2; ptr2 = ptr1; ptr1 = tmp; } #endif //TODO: add tcs template<class dest_type> dest_type& string_to(std::string const& s, dest_type& result){ std::stringstream stream(s); stream>>result; if ((!stream)||(stream.fail())){ throw std::invalid_argument("error converting string '"+std::string(s)+"'"); } return result; } template<class dest_type> dest_type string_to(std::string const& s){ dest_type result; return string_to(s,result); } template<typename> struct is_bool { static bool value(){return false;}}; template<> struct is_bool<bool> { static bool value(){return true;}}; class type_base { type_base& operator=(const type_base&); public: const std::string name; const std::string description; type_base (std::string a_name, std::string a_description) : name(a_name), description(a_description) {} virtual void parse_and_store (const std::string & s)=0; virtual std::string value() const =0; virtual smart_ptr<type_base> clone()const =0; virtual ~type_base(){} }; template <typename type> class type_impl : public type_base { private: type_impl& operator=(const type_impl&); typedef bool(*validating_function_type)(const type&); private: type & target; validating_function_type validating_function; public: type_impl(std::string a_name, std::string a_description, type & a_target, validating_function_type a_validating_function = NULL) : type_base (a_name,a_description), target(a_target),validating_function(a_validating_function) {}; void parse_and_store (const std::string & s){ try{ const bool is_bool = internal::is_bool<type>::value(); if (is_bool && s.empty()){ //to avoid directly assigning true //(as it will impose additional layer of indirection) //so, simply pass it as string internal::string_to("1",target); }else { internal::string_to(s,target); } }catch(std::invalid_argument& e){ std::stringstream str; str <<"'"<<s<<"' is incorrect input for argument '"<<name<<"'" <<" ("<<e.what()<<")"; throw std::invalid_argument(str.str()); } if (validating_function){ if (!((validating_function)(target))){ std::stringstream str; str <<"'"<<target<<"' is invalid value for argument '"<<name<<"'"; throw std::invalid_argument(str.str()); } } } virtual std::string value()const{ std::stringstream str; str<<target; return str.str(); } virtual smart_ptr<type_base> clone() const { return smart_ptr<type_base>(new type_impl(*this)); } }; class argument{ private: smart_ptr<type_base> p_type; bool matched_; public: argument(argument const& other) : p_type(other.p_type.get() ? (other.p_type->clone()).release() : NULL) ,matched_(other.matched_) {} argument& operator=(argument a){ this->swap(a); return *this; } void swap(argument& other){ internal::swap(p_type, other.p_type); std::swap(matched_,other.matched_); } template<class type> argument(std::string a_name, std::string a_description, type& dest, bool(*a_validating_function)(const type&)= NULL) :p_type(new type_impl<type>(a_name,a_description,dest,a_validating_function)) ,matched_(false) {} std::string value()const{ return p_type->value(); } std::string name()const{ return p_type->name; } std::string description() const{ return p_type->description; } void parse_and_store(const std::string & s){ p_type->parse_and_store(s); matched_=true; } bool is_matched() const{return matched_;} }; } // namespace internal class cli_argument_pack{ typedef std::map<std::string,internal::argument> args_map_type; typedef std::vector<std::string> args_display_order_type; typedef std::vector<std::string> positional_arg_names_type; private: args_map_type args_map; args_display_order_type args_display_order; positional_arg_names_type positional_arg_names; std::set<std::string> bool_args_names; private: void add_arg(internal::argument const& a){ std::pair<args_map_type::iterator, bool> result = args_map.insert(std::make_pair(a.name(),a)); if (!result.second){ throw std::invalid_argument("argument with name: '"+a.name()+"' already registered"); } args_display_order.push_back(a.name()); } public: template<typename type> cli_argument_pack& arg(type& dest,std::string const& name, std::string const& description, bool(*validate)(const type &)= NULL){ internal::argument a(name,description,dest,validate); add_arg(a); if (internal::is_bool<type>::value()){ bool_args_names.insert(name); } return *this; } //Positional means that argument name can be omitted in actual CL //only key to match values for parameters with template<typename type> cli_argument_pack& positional_arg(type& dest,std::string const& name, std::string const& description, bool(*validate)(const type &)= NULL){ internal::argument a(name,description,dest,validate); add_arg(a); if (internal::is_bool<type>::value()){ bool_args_names.insert(name); } positional_arg_names.push_back(name); return *this; } void parse(std::size_t argc, char const* argv[]){ { std::size_t current_positional_index=0; for (std::size_t j=1;j<argc;j++){ internal::argument* pa = NULL; std::string argument_value; const char * const begin=argv[j]; const char * const end=begin+std::strlen(argv[j]); const char * const assign_sign = std::find(begin,end,'='); struct throw_unknown_parameter{ static void _(std::string const& location){ throw std::invalid_argument(std::string("unknown parameter starting at:'")+location+"'"); }}; //first try to interpret it like parameter=value string if (assign_sign!=end){ std::string name_found = std::string(begin,assign_sign); args_map_type::iterator it = args_map.find(name_found ); if(it!=args_map.end()){ pa= &((*it).second); argument_value = std::string(assign_sign+1,end); }else { throw_unknown_parameter::_(argv[j]); } } //then see is it a named flag else{ args_map_type::iterator it = args_map.find(argv[j] ); if(it!=args_map.end()){ pa= &((*it).second); argument_value = ""; } //then try it as positional argument without name specified else if (current_positional_index < positional_arg_names.size()){ std::stringstream str(argv[j]); args_map_type::iterator found_positional_arg = args_map.find(positional_arg_names.at(current_positional_index)); //TODO: probably use of smarter assert would help here assert(found_positional_arg!=args_map.end()/*&&"positional_arg_names and args_map are out of sync"*/); if (found_positional_arg==args_map.end()){ throw std::logic_error("positional_arg_names and args_map are out of sync"); } pa= &((*found_positional_arg).second); argument_value = argv[j]; current_positional_index++; }else { //TODO: add tc to check throw_unknown_parameter::_(argv[j]); } } assert(pa); if (pa->is_matched()){ throw std::invalid_argument(std::string("several values specified for: '")+pa->name()+"' argument"); } pa->parse_and_store(argument_value); } } } std::string usage_string(const std::string& binary_name)const{ std::string command_line_params; std::string summary_description; for (args_display_order_type::const_iterator it = args_display_order.begin();it!=args_display_order.end();++it){ const bool is_bool = (0!=bool_args_names.count((*it))); args_map_type::const_iterator argument_it = args_map.find(*it); //TODO: probably use of smarter assert would help here assert(argument_it!=args_map.end()/*&&"args_display_order and args_map are out of sync"*/); if (argument_it==args_map.end()){ throw std::logic_error("args_display_order and args_map are out of sync"); } const internal::argument & a = (*argument_it).second; command_line_params +=" [" + a.name() + (is_bool ?"":"=value")+ "]"; summary_description +=" " + a.name() + " - " + a.description() +" ("+a.value() +")" + "\n"; } std::string positional_arg_cl; for (positional_arg_names_type::const_iterator it = positional_arg_names.begin();it!=positional_arg_names.end();++it){ positional_arg_cl +=" ["+(*it); } for (std::size_t i=0;i<positional_arg_names.size();++i){ positional_arg_cl+="]"; } command_line_params+=positional_arg_cl; std::stringstream str; using std::endl; str << " Program usage is:" << endl << " " << binary_name << command_line_params << endl << endl << " where:" << endl << summary_description ; return str.str(); } }; // class cli_argument_pack namespace internal { template<typename T> bool is_power_of_2( T val ) { size_t intval = size_t(val); return (intval&(intval-1)) == size_t(0); } int step_function_plus(int previous, double step){ return static_cast<int>(previous+step); } int step_function_multiply(int previous, double multiply){ return static_cast<int>(previous*multiply); } // "Power-of-2 ladder": nsteps is the desired number of steps between any subsequent powers of 2. // The actual step is the quotient of the nearest smaller power of 2 divided by that number (but at least 1). // E.g., '1:32:#4' means 1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32 int step_function_power2_ladder(int previous, double nsteps){ int steps = int(nsteps); assert( is_power_of_2(steps) ); // must be a power of 2 // The actual step is 1 until the value is twice as big as nsteps if( previous < 2*steps ) return previous+1; // calculate the previous power of 2 int prev_power2 = previous/2; // start with half the given value int rshift = 1; // and with the shift of 1; while( int shifted = prev_power2>>rshift ) { // shift the value right; while the result is non-zero, prev_power2 |= shifted; // add the bits set in 'shifted'; rshift <<= 1; // double the shift, as twice as many top bits are set; } // repeat. ++prev_power2; // all low bits set; now it's just one less than the desired power of 2 assert( is_power_of_2(prev_power2) ); assert( (prev_power2<=previous)&&(2*prev_power2>previous) ); // The actual step value is the previous power of 2 divided by steps return previous + (prev_power2/steps); } typedef int (* step_function_ptr_type)(int,double); struct step_function_descriptor { char mnemonic; step_function_ptr_type function; public: step_function_descriptor(char a_mnemonic, step_function_ptr_type a_function) : mnemonic(a_mnemonic), function(a_function) {} private: void operator=(step_function_descriptor const&); }; step_function_descriptor step_function_descriptors[] = { step_function_descriptor('*',step_function_multiply), step_function_descriptor('+',step_function_plus), step_function_descriptor('#',step_function_power2_ladder) }; template<typename T, size_t N> inline size_t array_length(const T(&)[N]) { return N; } struct thread_range_step { step_function_ptr_type step_function; double step_function_argument; thread_range_step ( step_function_ptr_type step_function_, double step_function_argument_) :step_function(step_function_),step_function_argument(step_function_argument_) { if (!step_function_) throw std::invalid_argument("step_function for thread range step should not be NULL"); } int operator()(int previous)const { assert(0<=previous); // test 0<=first and loop discipline const int ret = step_function(previous,step_function_argument); assert(previous<ret); return ret; } friend std::istream& operator>>(std::istream& input_stream, thread_range_step& step){ char function_char; double function_argument; input_stream >> function_char >> function_argument; size_t i = 0; while ((i<array_length(step_function_descriptors)) && (step_function_descriptors[i].mnemonic!=function_char)) ++i; if (i >= array_length(step_function_descriptors)){ throw std::invalid_argument("unknown step function mnemonic: "+std::string(1,function_char)); } else if ((function_char=='#') && !is_power_of_2(function_argument)) { throw std::invalid_argument("the argument of # should be a power of 2"); } step.step_function = step_function_descriptors[i].function; step.step_function_argument = function_argument; return input_stream; } }; } // namespace internal struct thread_number_range{ int (*auto_number_of_threads)(); int first; // 0<=first (0 can be used as a special value) int last; // first<=last internal::thread_range_step step; thread_number_range( int (*auto_number_of_threads_)(),int low_=1, int high_=-1 , internal::thread_range_step step_ = internal::thread_range_step(internal::step_function_power2_ladder,4) ) : auto_number_of_threads(auto_number_of_threads_), first(low_), last((high_>-1) ? high_ : auto_number_of_threads_()) ,step(step_) { if (first<0) { throw std::invalid_argument("negative value not allowed"); } if (first>last) { throw std::invalid_argument("decreasing sequence not allowed"); } } friend std::istream& operator>>(std::istream& i, thread_number_range& range){ try{ std::string s; i>>s; struct string_to_number_of_threads{ int auto_value; string_to_number_of_threads(int auto_value_):auto_value(auto_value_){} int operator()(const std::string & value)const{ return (value=="auto")? auto_value : internal::string_to<int>(value); } }; string_to_number_of_threads string_to_number_of_threads(range.auto_number_of_threads()); int low, high; std::size_t colon = s.find(':'); if ( colon == std::string::npos ){ low = high = string_to_number_of_threads(s); } else { //it is a range std::size_t second_colon = s.find(':',colon+1); low = string_to_number_of_threads(std::string(s, 0, colon)); //not copying the colon high = string_to_number_of_threads(std::string(s, colon+1, second_colon - (colon+1))); //not copying the colons if (second_colon != std::string::npos){ internal::string_to(std::string(s,second_colon + 1),range.step); } } range = thread_number_range(range.auto_number_of_threads,low,high,range.step); }catch(std::invalid_argument&){ i.setstate(std::ios::failbit); throw; } return i; } friend std::ostream& operator<<(std::ostream& o, thread_number_range const& range){ using namespace internal; size_t i = 0; for (; i < array_length(step_function_descriptors) && step_function_descriptors[i].function != range.step.step_function; ++i ) {} if (i >= array_length(step_function_descriptors)){ throw std::invalid_argument("unknown step function for thread range"); } o<<range.first<<":"<<range.last<<":"<<step_function_descriptors[i].mnemonic<<range.step.step_function_argument; return o; } }; // struct thread_number_range //TODO: fix unused warning here //TODO: update the thread range description in the .html files static const char* thread_number_range_desc="number of threads to use; a range of the form low[:high[:(+|*|#)step]]," "\n\twhere low and optional high are non-negative integers or 'auto' for the default choice," "\n\tand optional step expression specifies how thread numbers are chosen within the range." "\n\tSee examples/common/index.html for detailed description." ; inline void report_elapsed_time(double seconds){ std::cout << "elapsed time : "<<seconds<<" seconds \n"; } inline void parse_cli_arguments(int argc, const char* argv[], utility::cli_argument_pack cli_pack){ bool show_help = false; cli_pack.arg(show_help,"-h","show this message"); bool invalid_input=false; try { cli_pack.parse(argc,argv); }catch(std::exception& e){ std::cerr <<"error occurred while parsing command line."<<std::endl <<"error text: "<<e.what()<<std::endl <<std::flush; invalid_input =true; } if (show_help || invalid_input){ std::cout<<cli_pack.usage_string(argv[0])<<std::flush; std::exit(0); } } inline void parse_cli_arguments(int argc, char* argv[], utility::cli_argument_pack cli_pack){ parse_cli_arguments(argc, const_cast<const char**>(argv), cli_pack); } } #endif /* UTILITY_H_ */
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon.openmp/tachyon.openmp.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /****************************************************************************** The tachyon sample program is for use with the Guided Vtune Tutorial. Please refer to the github's readme for build instructions. *******************************************************************************/ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" #include <omp.h> // shared but read-only so could be private too static thr_parms* all_parms; static scenedef scene; static int startx; static int stopx; static int starty; static int stopy; static flt jitterscale; static int totaly; // This function is shared among all implementations: static color_t render_one_pixel(int x, int y, unsigned int* local_mbox, unsigned int& serial, int startx, int stopx, int starty, int stopy) { /* private vars moved inside loop */ ray primary; color col; int R, G, B; intersectstruct local_intersections; /* end private */ primary = camray(&scene, x, y); primary.intstruct = &local_intersections; primary.flags = RT_RAY_REGULAR; serial++; primary.serial = serial; primary.mbox = local_mbox; primary.maxdist = FHUGE; primary.scene = &scene; col = trace(&primary); serial = primary.serial; /* Handle overexposure and underexposure here... */ R = (int)(col.r * 255); if (R > 255) R = 255; else if (R < 0) R = 0; G = (int)(col.g * 255); if (G > 255) G = 255; else if (G < 0) G = 0; B = (int)(col.b * 255); if (B > 255) B = 255; else if (B < 0) B = 0; return video->get_color(R, G, B); } #if DO_ITT_NOTIFY #include"ittnotify.h" #endif // To start off with our OpenMP implementation, we are using a very simple parallel for pragma. // Run this with Vtune to see what improvements can be made. static void parallel_thread(void) { unsigned int mboxsize = sizeof(unsigned int) * (max_objectid() + 20); #pragma omp parallel for for (int y = starty; y < stopy; y++) { unsigned int serial = 1; unsigned int local_mbox[mboxsize]; memset(local_mbox, 0, mboxsize); drawing_area drawing(startx, totaly - y, stopx - startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } video->next_frame(); } } // This function is shared among all implementations: void* thread_trace(thr_parms* parms) { // shared but read-only so could be private too all_parms = parms; scene = parms->scene; startx = parms->startx; stopx = parms->stopx; starty = parms->starty; stopy = parms->stopy; jitterscale = 40.0 * (scene.hres + scene.vres); totaly = parms->scene.vres - 1; #if DO_ITT_NOTIFY __itt_resume(); #endif parallel_thread(); #if DO_ITT_NOTIFY __itt_pause(); #endif return(NULL); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/src/tachyon.openmp/tachyon.openmp_optimized.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /****************************************************************************** The tachyon sample program is for use with the Guided Vtune Tutorial. Please refer to the github's readme for build instructions. *******************************************************************************/ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" // shared but read-only so could be private too static thr_parms* all_parms; static scenedef scene; static int startx; static int stopx; static int starty; static int stopy; static flt jitterscale; static int totaly; // This function is shared among all implementations: static color_t render_one_pixel(int x, int y, unsigned int* local_mbox, unsigned int& serial, int startx, int stopx, int starty, int stopy) { /* private vars moved inside loop */ ray primary; color col; int R, G, B; intersectstruct local_intersections; /* end private */ primary = camray(&scene, x, y); primary.intstruct = &local_intersections; primary.flags = RT_RAY_REGULAR; serial++; primary.serial = serial; primary.mbox = local_mbox; primary.maxdist = FHUGE; primary.scene = &scene; col = trace(&primary); serial = primary.serial; /* Handle overexposure and underexposure here... */ R = (int)(col.r * 255); if (R > 255) R = 255; else if (R < 0) R = 0; G = (int)(col.g * 255); if (G > 255) G = 255; else if (G < 0) G = 0; B = (int)(col.b * 255); if (B > 255) B = 255; else if (B < 0) B = 0; return video->get_color(R, G, B); } #if DO_ITT_NOTIFY #include"ittnotify.h" #endif // VTune shows that each thread stops independently of each other, so faster threads will wait for // slower threads to complete. Adding schedule(dynamic) allows the faster threads to steal work // from the slower threads, making execution faster. static void parallel_thread(void) { unsigned int mboxsize = sizeof(unsigned int) * (max_objectid() + 20); #pragma omp parallel for schedule(dynamic) for (int y = starty; y < stopy; y++) { unsigned int serial = 1; unsigned int local_mbox[mboxsize]; memset(local_mbox, 0, mboxsize); drawing_area drawing(startx, totaly - y, stopx - startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } video->next_frame(); } } // This function is shared among all implementations: void* thread_trace(thr_parms* parms) { // shared but read-only so could be private too all_parms = parms; scene = parms->scene; startx = parms->startx; stopx = parms->stopx; starty = parms->starty; stopy = parms->stopy; jitterscale = 40.0 * (scene.hres + scene.vres); totaly = parms->scene.vres - 1; #if DO_ITT_NOTIFY __itt_resume(); #endif parallel_thread(); #if DO_ITT_NOTIFY __itt_pause(); #endif return(NULL); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/windows/msvs/resource.h
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= // #define IDC_MYICON 2 #define IDD_GUI 102 #define IDS_APP_TITLE 103 #define IDI_GUI 107 #define IDI_SMALL 108 #define IDC_GUI 109 #define IDR_MAINFRAME 128 #define IDC_STATIC -1
h
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/ring.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ring.cpp - This file contains the functions for dealing with rings. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define RING_PRIVATE #include "ring.h" static object_methods ring_methods = { (void (*)(void *, void *))(ring_intersect), (void (*)(void *, void *, void *, void *))(ring_normal), ring_bbox, free }; object * newring(void * tex, vector ctr, vector norm, flt inrad, flt outrad) { ring * r; r=(ring *) rt_getmem(sizeof(ring)); memset(r, 0, sizeof(ring)); r->methods = &ring_methods; r->tex = (texture *)tex; r->ctr = ctr; r->norm = norm; r->inrad = inrad; r->outrad= outrad; return (object *) r; } static int ring_bbox(void * obj, vector * min, vector * max) { ring * r = (ring *) obj; min->x = r->ctr.x - r->outrad; min->y = r->ctr.y - r->outrad; min->z = r->ctr.z - r->outrad; max->x = r->ctr.x + r->outrad; max->y = r->ctr.y + r->outrad; max->z = r->ctr.z + r->outrad; return 1; } static void ring_intersect(ring * rng, ray * ry) { flt d; flt t,td; vector hit, pnt; d = -VDot(&(rng->ctr), &(rng->norm)); t=-(d+VDot(&(rng->norm), &(ry->o))); td=VDot(&(rng->norm),&(ry->d)); if (td != 0.0) { t= t / td; if (t>=0.0) { hit=Raypnt(ry, t); VSUB(hit, rng->ctr, pnt); VDOT(td, pnt, pnt); td=sqrt(td); if ((td > rng->inrad) && (td < rng->outrad)) add_intersection(t,(object *) rng, ry); } } } static void ring_normal(ring * rng, vector * pnt, ray * incident, vector * N) { *N=rng->norm; VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/box.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * box.cpp - This file contains the functions for dealing with boxes. */ #include "machine.h" #include "types.h" #include "macros.h" #include "box.h" #include "vector.h" #include "intersect.h" #include "util.h" int box_bbox(void * obj, vector * min, vector * max) { box * b = (box *) obj; *min = b->min; *max = b->max; return 1; } static object_methods box_methods = { (void (*)(void *, void *))(box_intersect), (void (*)(void *, void *, void *, void *))(box_normal), box_bbox, free }; box * newbox(void * tex, vector min, vector max) { box * b; b=(box *) rt_getmem(sizeof(box)); memset(b, 0, sizeof(box)); b->methods = &box_methods; b->tex = (texture *)tex; b->min = min; b->max = max; return b; } void box_intersect(box * bx, ray * ry) { flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return; } else { tx1 = (bx->min.x - ry->o.x) / ry->d.x; tx2 = (bx->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return; if (tfar < 0.0) return; if (ry->d.y == 0.0) { if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return; } else { ty1 = (bx->min.y - ry->o.y) / ry->d.y; ty2 = (bx->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return; if (tfar < 0.0) return; if (ry->d.z == 0.0) { if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return; } else { tz1 = (bx->min.z - ry->o.z) / ry->d.z; tz2 = (bx->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return; if (tfar < 0.0) return; add_intersection(tnear, (object *) bx, ry); add_intersection(tfar, (object *) bx, ry); } void box_normal(box * bx, vector * pnt, ray * incident, vector * N) { vector a, b, c; flt t; c.x=(bx->max.x + bx->min.x) / 2.0; c.y=(bx->max.y + bx->min.y) / 2.0; c.z=(bx->max.z + bx->min.z) / 2.0; VSub((vector *) pnt, &c, N); b=(*N); a.x=fabs(N->x); a.y=fabs(N->y); a.z=fabs(N->z); N->x=0.0; N->y=0.0; N->z=0.0; t=MYMAX(a.x, MYMAX(a.y, a.z)); if (t==a.x) N->x=b.x; if (t==a.y) N->y=b.y; if (t==a.z) N->z=b.z; VNorm(N); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/camera.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * camera.cpp - This file contains all of the functions for doing camera work. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "camera.h" #include "util.h" ray camray(scenedef *scene, int x, int y) { ray ray1, newray; vector projcent; vector projpixel; flt px, py, sx, sy; sx = (flt) scene->hres; sy = (flt) scene->vres; /* calculate the width and height of the image plane given the */ /* aspect ratio, image resolution, and zoom factor */ px=((sx / sy) / scene->aspectratio) / scene->camzoom; py=1.0 / scene->camzoom; /* assuming viewvec is a unit vector, then the center of the */ /* image plane is the camera center + vievec */ projcent.x = scene->camcent.x + scene->camviewvec.x; projcent.y = scene->camcent.y + scene->camviewvec.y; projcent.z = scene->camcent.z + scene->camviewvec.z; /* starting from the center of the image plane, we move the */ /* center of the pel we're calculating, to */ /* projcent + (rightvec * x distance) */ ray1.o=projcent; ray1.d=scene->camrightvec; projpixel=Raypnt(&ray1, ((x*px/sx) - (px / 2.0))); /* starting from the horizontally translated pel, we move the */ /* center of the pel we're calculating, to */ /* projcent + (upvec * y distance) */ ray1.o=projpixel; ray1.d=scene->camupvec; projpixel=Raypnt(&ray1, ((y*py/sy) - (py / 2.0))); /* now that we have the exact pel center in the image plane */ /* we create the real primary ray that will be used by the */ /* rest of the system. */ /* The ray is expected to be re-normalized elsewhere, we're */ /* only really concerned about getting its direction right. */ newray.o=scene->camcent; VSub(&projpixel, &scene->camcent, &newray.d); newray.depth = scene->raydepth; newray.flags = RT_RAY_REGULAR; /* camera only generates primary rays */ return newray; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/main.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define VIDEO_WINMAIN_ARGS #include "types.h" #include "api.h" /* The ray tracing library API */ #include "parse.h" /* Support for my own file format */ #include "ui.h" #include "util.h" #include "tachyon_video.h" #include "common/utility/utility.h" #if WIN8UI_EXAMPLE #include "tbb/tbb.h" volatile long global_startTime = 0; volatile long global_elapsedTime = 0; volatile bool global_isCancelled = false; volatile int global_number_of_threads; #endif #ifndef DEFAULT_MODELFILE #define DEFAULT_MODELFILE balls.dat #endif SceneHandle global_scene; int global_xsize; /* size of graphic image rendered in window (from hres, vres) */ int global_ysize; int global_xwinsize; /* size of window (may be larger than above) */ int global_ywinsize; char *global_window_title; bool global_usegraphics; bool silent_mode = false; /* silent mode */ class tachyon_video *video = 0; typedef struct { int foundfilename; /* was a model file name found in the args? */ char filename[1024]; /* model file to render */ int useoutfilename; /* command line override of output filename */ char outfilename[1024]; /* name of output image file */ int verbosemode; /* verbose flags */ int antialiasing; /* antialiasing setting */ int displaymode; /* display mode */ int boundmode; /* bounding mode */ int boundthresh; /* bounding threshold */ int usecamfile; /* use camera file */ char camfilename[1024]; /* camera filename */ } argoptions; void initoptions(argoptions * opt) { memset(opt, 0, sizeof(argoptions)); opt->foundfilename = -1; opt->useoutfilename = -1; opt->verbosemode = -1; opt->antialiasing = -1; opt->displaymode = -1; opt->boundmode = -1; opt->boundthresh = -1; opt->usecamfile = -1; } #if WIN8UI_EXAMPLE int CreateScene() { char* filename = "Assets/balls.dat"; global_scene = rt_newscene(); rt_initialize(); if ( readmodel(filename, global_scene) != 0 ) { rt_finalize(); return -1; } // need these early for create_graphics_window() so grab these here... scenedef *scene = (scenedef *) global_scene; // scene->hres and scene->vres should be equal to screen resolution scene->hres = global_xwinsize = global_xsize; scene->vres = global_ywinsize = global_ysize; return 0; } unsigned int __stdcall example_main(void *) { try { if ( CreateScene() != 0 ) exit(-1); tachyon_video tachyon; tachyon.threaded = true; tachyon.init_console(); // always using window even if(!global_usegraphics) global_usegraphics = tachyon.init_window(global_xwinsize, global_ywinsize); if(!tachyon.running) exit(-1); video = &tachyon; for(;;) { global_elapsedTime = 0; global_startTime=(long) time(NULL); global_isCancelled=false; if (video)video->running = true; tbb::task_scheduler_init init (global_number_of_threads); memset(g_pImg, 0, sizeof(unsigned int) * global_xsize * global_ysize); tachyon.main_loop(); global_elapsedTime = (long)(time(NULL)-global_startTime); video->running=false; //The timer to restart drawing then it is complete. int timer=50; while( ( !global_isCancelled && (timer--)>0 ) ){ rt_sleep( 100 ); } } return NULL; } catch ( std::exception& e ) { std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n"; return 1; } } #else static char *window_title_string (int argc, const char **argv) { int i; char *name; name = (char *) malloc (8192); char *title = getenv ("TITLE"); if( title ) strcpy( name, title ); else { if(strrchr(argv[0], '\\')) strcpy (name, strrchr(argv[0], '\\')+1); else if(strrchr(argv[0], '/')) strcpy (name, strrchr(argv[0], '/')+1); else strcpy (name, *argv[0]?argv[0]:"Tachyon"); } for (i = 1; i < argc; i++) { strcat (name, " "); strcat (name, argv[i]); } #ifdef _DEBUG strcat (name, " (DEBUG BUILD)"); #endif return name; } int useoptions(argoptions * opt, SceneHandle scene) { if (opt->useoutfilename == 1) { rt_outputfile(scene, opt->outfilename); } if (opt->verbosemode == 1) { rt_verbose(scene, 1); } if (opt->antialiasing != -1) { /* need new api code for this */ } if (opt->displaymode != -1) { rt_displaymode(scene, opt->displaymode); } if (opt->boundmode != -1) { rt_boundmode(scene, opt->boundmode); } if (opt->boundthresh != -1) { rt_boundthresh(scene, opt->boundthresh); } return 0; } argoptions ParseCommandLine(int argc, const char *argv[]) { argoptions opt; initoptions(&opt); bool nobounding = false; bool nodisp = false; string filename; utility::parse_cli_arguments(argc,argv, utility::cli_argument_pack() .positional_arg(filename,"dataset", "Model file") .positional_arg(opt.boundthresh,"boundthresh","bounding threshold value") .arg(nodisp,"no-display-updating","disable run-time display updating") .arg(nobounding,"no-bounding","disable bounding technique") .arg(silent_mode,"silent","no output except elapsed time") ); // changed by om 28/12/2015 if (filename.empty()){ opt.foundfilename = -1; } else { strcpy(opt.filename, filename.c_str()); opt.foundfilename = 1; } // end changed by om 28/12/2015 opt.displaymode = nodisp ? RT_DISPLAY_DISABLED : RT_DISPLAY_ENABLED; opt.boundmode = nobounding ? RT_BOUNDING_DISABLED : RT_BOUNDING_ENABLED; return opt; } int CreateScene(argoptions &opt) { char *filename; global_scene = rt_newscene(); rt_initialize(); /* process command line overrides */ useoptions(&opt, global_scene); filename = opt.filename; if (readmodel(filename, global_scene) != 0) { fprintf(stderr, "Parser returned a non-zero error code reading %s\n", filename); fprintf(stderr, "Aborting Render...\n"); //fflush(stderr); rt_finalize(); return -1; } // need these early for create_graphics_window() so grab these here... scenedef *scene = (scenedef *) global_scene; global_xsize = scene->hres; global_ysize = scene->vres; global_xwinsize = global_xsize; global_ywinsize = global_ysize; // add some here to leave extra blank space on bottom for status etc. return 0; } int main (int argc, char *argv[]) { const char *modelfile; FILE *stream; FILE * dfile; if ((stream = freopen("errorfile.txt", "w", stdout)) == NULL) exit(-1); try { timer mainStartTime = gettimer(); global_window_title = window_title_string (argc, (const char**)argv); argoptions opt = ParseCommandLine(argc, (const char**)argv); // Change by om #ifdef DEFAULT_MODELFILE #if _WIN32||_WIN64 #define _GLUE_FILENAME(x) "..\\dat\\" #x #else #define _GLUE_FILENAME(x) #x #endif #define GLUE_FILENAME(x) _GLUE_FILENAME(x) if (opt.foundfilename == -1) modelfile = GLUE_FILENAME(DEFAULT_MODELFILE); else #endif//DEFAULT_MODELFILE modelfile = opt.filename; dfile = fopen(modelfile, "r"); if (dfile == NULL) { printf("Model file %s not found\n", modelfile); fflush(stdout); fclose(stream); return -1; } fclose(dfile); // end change by om if ( CreateScene(opt) != 0 ) return -1; tachyon_video tachyon; tachyon.threaded = true; tachyon.init_console(); tachyon.title = global_window_title; // always using window even if(!global_usegraphics) global_usegraphics = tachyon.init_window(global_xwinsize, global_ywinsize); if(!tachyon.running) return -1; video = &tachyon; tachyon.main_loop(); utility::report_elapsed_time(timertime(mainStartTime, gettimer())); return 0; } catch ( std::exception& e ) { std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n"; return 1; } } #endif
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/global.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * global.cpp - any/all global data items etc should be in this file */ #include "types.h" #include "machine.h" #include "sphere.h" #include "light.h" /* stuff moved from intersect.c */ object * rootobj = NULL; /* starts out empty. */ point_light * lightlist[MAXLIGHTS]; int numlights = 0; unsigned int numobjects = 0; /* used to assign unique object ID's */ /* used in util.c */ unsigned int rt_mem_in_use = 0; /* used in api.c */ int parinitted = 0; int graphicswindowopen = 0;
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/tgafile.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * tgafile.cpp - This file contains the code to write 24 bit targa files... */ #include "machine.h" #include "types.h" #include "util.h" #include "ui.h" #include "imageio.h" #include "tgafile.h" void createtgafile(char *name, unsigned short width, unsigned short height) { int filesize; FILE * ofp; filesize = 3*width*height + 18 - 10; if (name==NULL) exit(1); else { ofp=fopen(name, "w+b"); if (ofp == NULL) { char msgtxt[2048]; sprintf(msgtxt, "Cannot create %s for output!", name); rt_ui_message(MSG_ERR, msgtxt); rt_ui_message(MSG_ABORT, "Rendering Aborted."); exit(1); } fputc(0, ofp); /* IdLength */ fputc(0, ofp); /* ColorMapType */ fputc(2, ofp); /* ImageTypeCode */ fputc(0, ofp); /* ColorMapOrigin, low byte */ fputc(0, ofp); /* ColorMapOrigin, high byte */ fputc(0, ofp); /* ColorMapLength, low byte */ fputc(0, ofp); /* ColorMapLength, high byte */ fputc(0, ofp); /* ColorMapEntrySize */ fputc(0, ofp); /* XOrigin, low byte */ fputc(0, ofp); /* XOrigin, high byte */ fputc(0, ofp); /* YOrigin, low byte */ fputc(0, ofp); /* YOrigin, high byte */ fputc((width & 0xff), ofp); /* Width, low byte */ fputc(((width >> 8) & 0xff), ofp); /* Width, high byte */ fputc((height & 0xff), ofp); /* Height, low byte */ fputc(((height >> 8) & 0xff), ofp); /* Height, high byte */ fputc(24, ofp); /* ImagePixelSize */ fputc(0x20, ofp); /* ImageDescriptorByte 0x20 == flip vertically */ fseek(ofp, filesize, 0); fprintf(ofp, "9876543210"); fclose(ofp); } } void * opentgafile(char * filename) { FILE * ofp; ofp=fopen(filename, "r+b"); if (ofp == NULL) { char msgtxt[2048]; sprintf(msgtxt, "Cannot open %s for output!", filename); rt_ui_message(MSG_ERR, msgtxt); rt_ui_message(MSG_ABORT, "Rendering Aborted."); exit(1); } return ofp; } void writetgaregion(void * voidofp, int iwidth, int iheight, int startx, int starty, int stopx, int stopy, char * buffer) { int y, totalx, totaly; char * bufpos; long filepos; size_t numbytes; FILE * ofp = (FILE *) voidofp; totalx = stopx - startx + 1; totaly = stopy - starty + 1; for (y=0; y<totaly; y++) { bufpos=buffer + (totalx*3)*(totaly-y-1); filepos=18 + iwidth*3*(iheight - starty - totaly + y + 1) + (startx - 1)*3; if (filepos >= 18) { fseek(ofp, filepos, 0); numbytes = fwrite(bufpos, 3, totalx, ofp); if (numbytes != totalx) { char msgtxt[256]; sprintf(msgtxt, "File write problem, %d bytes written.", (int)numbytes); rt_ui_message(MSG_ERR, msgtxt); } } else { rt_ui_message(MSG_ERR, "writetgaregion: file ptr out of range!!!\n"); return; /* don't try to continue */ } } } int readtga(char * name, int * xres, int * yres, unsigned char **imgdata) { int format, width, height, w1, w2, h1, h2, depth, flags; int imgsize, i, tmp; size_t bytesread; FILE * ifp; ifp=fopen(name, "r"); if (ifp==NULL) { return IMAGEBADFILE; /* couldn't open the file */ } /* read the targa header */ getc(ifp); /* ID length */ getc(ifp); /* colormap type */ format = getc(ifp); /* image type */ getc(ifp); /* color map origin */ getc(ifp); /* color map origin */ getc(ifp); /* color map length */ getc(ifp); /* color map length */ getc(ifp); /* color map entry size */ getc(ifp); /* x origin */ getc(ifp); /* x origin */ getc(ifp); /* y origin */ getc(ifp); /* y origin */ w1 = getc(ifp); /* width (low) */ w2 = getc(ifp); /* width (hi) */ h1 = getc(ifp); /* height (low) */ h2 = getc(ifp); /* height (hi) */ depth = getc(ifp); /* image pixel size */ flags = getc(ifp); /* image descriptor byte */ if ((format != 2) || (depth != 24)) { fclose(ifp); return IMAGEUNSUP; /* unsupported targa format */ } width = ((w2 << 8) | w1); height = ((h2 << 8) | h1); imgsize = 3 * width * height; *imgdata = (unsigned char *)rt_getmem(imgsize); bytesread = fread(*imgdata, 1, imgsize, ifp); fclose(ifp); /* flip image vertically */ if (flags == 0x20) { int rowsize = 3 * width; unsigned char * copytmp; copytmp = (unsigned char *)malloc(rowsize); for (i=0; i<height / 2; i++) { memcpy(copytmp, &((*imgdata)[rowsize*i]), rowsize); memcpy(&(*imgdata)[rowsize*i], &(*imgdata)[rowsize*(height - 1 - i)], rowsize); memcpy(&(*imgdata)[rowsize*(height - 1 - i)], copytmp, rowsize); } free(copytmp); } /* convert from BGR order to RGB order */ for (i=0; i<imgsize; i+=3) { tmp = (*imgdata)[i]; /* Blue */ (*imgdata)[i] = (*imgdata)[i+2]; /* Red */ (*imgdata)[i+2] = tmp; /* Blue */ } *xres = width; *yres = height; if (bytesread != imgsize) return IMAGEREADERR; return IMAGENOERR; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/apitrigeom.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * apitrigeom.cpp - This file contains code for generating triangle tesselated * geometry, for use with OpenGL, XGL, etc. */ #include "machine.h" #include "types.h" #include "api.h" #include "macros.h" #include "vector.h" #define MyVNorm(a) VNorm ((vector *) a) #define MyVCross(a,b,c) VCross ((vector *) a, (vector *) b, (vector *) c) #define MyVAddS(x,a,b,c) VAddS ((flt) x, (vector *) a, (vector *) b, (vector *) c) #define CYLFACETS 36 #define RINGFACETS 36 #define SPHEREFACETS 25 void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) { vector x, y, z, tmp; double u, v, u2, v2; int j; vector p1, p2, p3, p4; vector n1, n2; z = axis; MyVNorm(&z); tmp.x = z.y - 2.1111111; tmp.y = -z.z + 3.14159267; tmp.z = z.x - 3.915292342341; MyVNorm(&z); MyVNorm(&tmp); MyVCross(&z, &tmp, &x); MyVNorm(&x); MyVCross(&x, &z, &y); MyVNorm(&y); for (j=0; j<CYLFACETS; j++) { u = rad * sin((6.28 * j) / (CYLFACETS - 1.0)); v = rad * cos((6.28 * j) / (CYLFACETS - 1.0)); u2 = rad * sin((6.28 * (j + 1.0)) / (CYLFACETS - 1.0)); v2 = rad * cos((6.28 * (j + 1.0)) / (CYLFACETS - 1.0)); p1.x = p1.y = p1.z = 0.0; p4 = p3 = p2 = p1; MyVAddS(u, &x, &p1, &p1); MyVAddS(v, &y, &p1, &p1); n1 = p1; MyVNorm(&n1); MyVAddS(1.0, &ctr, &p1, &p1); MyVAddS(u2, &x, &p2, &p2); MyVAddS(v2, &y, &p2, &p2); n2 = p2; MyVNorm(&n2); MyVAddS(1.0, &ctr, &p2, &p2); MyVAddS(1.0, &axis, &p1, &p3); MyVAddS(1.0, &axis, &p2, &p4); rt_stri(tex, p1, p2, p3, n1, n2, n1); rt_stri(tex, p3, p2, p4, n1, n2, n2); } } void rt_tri_cylinder(void * tex, vector ctr, vector axis, apiflt rad) { rt_fcylinder(tex, ctr, axis, rad); } void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) { vector x, y, z, tmp; double u, v, u2, v2; int j; vector p1, p2, p3, p4; vector n1, n2; z = norm; MyVNorm(&z); tmp.x = z.y - 2.1111111; tmp.y = -z.z + 3.14159267; tmp.z = z.x - 3.915292342341; MyVNorm(&z); MyVNorm(&tmp); MyVCross(&z, &tmp, &x); MyVNorm(&x); MyVCross(&x, &z, &y); MyVNorm(&y); for (j=0; j<RINGFACETS; j++) { u = sin((6.28 * j) / (RINGFACETS - 1.0)); v = cos((6.28 * j) / (RINGFACETS - 1.0)); u2 = sin((6.28 * (j + 1.0)) / (RINGFACETS - 1.0)); v2 = cos((6.28 * (j + 1.0)) / (RINGFACETS - 1.0)); p1.x = p1.y = p1.z = 0.0; p4 = p3 = p2 = p1; MyVAddS(u, &x, &p1, &p1); MyVAddS(v, &y, &p1, &p1); n1 = p1; MyVNorm(&n1); MyVAddS(a, &n1, &ctr, &p1); MyVAddS(b, &n1, &ctr, &p3); MyVAddS(u2, &x, &p2, &p2); MyVAddS(v2, &y, &p2, &p2); n2 = p2; MyVNorm(&n2); MyVAddS(a, &n2, &ctr, &p2); MyVAddS(b, &n2, &ctr, &p4); rt_stri(tex, p1, p2, p3, norm, norm, norm); rt_stri(tex, p3, p2, p4, norm, norm, norm); } } void rt_tri_box(void * tex, vector min, vector max) { /* -XY face */ rt_tri(tex, rt_vector(min.x, min.y, min.z), rt_vector(min.x, max.y, min.z), rt_vector(max.x, max.y, min.z)); rt_tri(tex, rt_vector(min.x, min.y, min.z), rt_vector(max.x, max.y, min.z), rt_vector(max.x, min.y, min.z)); /* +XY face */ rt_tri(tex, rt_vector(min.x, min.y, max.z), rt_vector(max.x, max.y, max.z), rt_vector(min.x, max.y, max.z)); rt_tri(tex, rt_vector(min.x, min.y, max.z), rt_vector(max.x, min.y, max.z), rt_vector(max.x, max.y, max.z)); /* -YZ face */ rt_tri(tex, rt_vector(min.x, min.y, min.z), rt_vector(min.x, max.y, max.z), rt_vector(min.x, min.y, max.z)); rt_tri(tex, rt_vector(min.x, min.y, min.z), rt_vector(min.x, max.y, min.z), rt_vector(min.x, max.y, max.z)); /* +YZ face */ rt_tri(tex, rt_vector(max.x, min.y, min.z), rt_vector(max.x, min.y, max.z), rt_vector(max.x, max.y, max.z)); rt_tri(tex, rt_vector(max.x, min.y, min.z), rt_vector(max.x, max.y, max.z), rt_vector(max.x, max.y, min.z)); /* -XZ face */ rt_tri(tex, rt_vector(min.x, min.y, min.z), rt_vector(min.x, min.y, max.z), rt_vector(max.x, min.y, max.z)); rt_tri(tex, rt_vector(min.x, min.y, min.z), rt_vector(max.x, min.y, max.z), rt_vector(max.x, min.y, min.z)); /* +XZ face */ rt_tri(tex, rt_vector(min.x, max.y, min.z), rt_vector(max.x, max.y, max.z), rt_vector(min.x, max.y, max.z)); rt_tri(tex, rt_vector(min.x, max.y, min.z), rt_vector(max.x, max.y, min.z), rt_vector(max.x, max.y, max.z)); } void rt_tri_sphere(void * tex, vector ctr, apiflt rad) { } void rt_tri_plane(void * tex, vector ctr, vector norm) { rt_tri_ring(tex, ctr, norm, 0.0, 10000.0); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/shade.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * shade.cpp - This file contains the functions that perform surface shading. */ #include "machine.h" #include "types.h" #include "macros.h" #include "light.h" #include "intersect.h" #include "vector.h" #include "trace.h" #include "global.h" #include "shade.h" void reset_lights(void) { numlights=0; } void add_light(point_light * li) { lightlist[numlights]=li; numlights++; } color shader(ray * incident) { color col, diffuse, phongcol; vector N, L, hit; ray shadowray; flt inten, t, Llen; object * obj; int numints, i; point_light * li; numints=closest_intersection(&t, &obj, incident->intstruct); /* find the number of intersections */ /* and return the closest one. */ if (numints < 1) { /* if there weren't any object intersections then return the */ /* background color for the pixel color. */ return incident->scene->background; } if (obj->tex->islight) { /* if the current object is a light, then we */ return obj->tex->col; /* will only use the objects ambient color */ } RAYPNT(hit, (*incident), t) /* find the point of intersection from t */ obj->methods->normal(obj, &hit, incident, &N); /* find the surface normal */ /* execute the object's texture function */ col = obj->tex->texfunc(&hit, obj->tex, incident); diffuse.r = 0.0; diffuse.g = 0.0; diffuse.b = 0.0; phongcol = diffuse; if ((obj->tex->diffuse > 0.0) || (obj->tex->phong > 0.0)) { for (i=0; i<numlights; i++) { /* loop for light contributions */ li=lightlist[i]; /* set li=to the current light */ VSUB(li->ctr, hit, L) /* find the light vector */ /* calculate the distance to the light from the hit point */ Llen = sqrt(L.x*L.x + L.y*L.y + L.z*L.z) + EPSILON; L.x /= Llen; /* normalize the light direction vector */ L.y /= Llen; L.z /= Llen; VDOT(inten, N, L) /* light intensity */ /* add in diffuse lighting for this light if we're facing it */ if (inten > 0.0) { /* test for a shadow */ shadowray.intstruct = incident->intstruct; shadowray.flags = RT_RAY_SHADOW | RT_RAY_BOUNDED; incident->serial++; shadowray.serial = incident->serial; shadowray.mbox = incident->mbox; shadowray.o = hit; shadowray.d = L; shadowray.maxdist = Llen; shadowray.s = hit; shadowray.e = li->ctr; shadowray.scene = incident->scene; reset_intersection(incident->intstruct); intersect_objects(&shadowray); if (!shadow_intersection(incident->intstruct, Llen)) { /* XXX now that opacity is in the code, have to be more careful */ ColorAddS(&diffuse, &li->tex->col, inten); /* phong type specular highlights */ if (obj->tex->phong > 0.0) { flt phongval; phongval = shade_phong(incident, &hit, &N, &L, obj->tex->phongexp); if (obj->tex->phongtype) ColorAddS(&phongcol, &col, phongval); else ColorAddS(&phongcol, &(li->tex->col), phongval); } } } } } ColorScale(&diffuse, obj->tex->diffuse); col.r *= (diffuse.r + obj->tex->ambient); /* do a product of the */ col.g *= (diffuse.g + obj->tex->ambient); /* diffuse intensity with */ col.b *= (diffuse.b + obj->tex->ambient); /* object color + ambient */ if (obj->tex->phong > 0.0) { ColorAccum(&col, &phongcol); } /* spawn reflection rays if necessary */ /* note: this will overwrite the old intersection list */ if (obj->tex->specular > 0.0) { color specol; specol = shade_reflection(incident, &hit, &N, obj->tex->specular); ColorAccum(&col, &specol); } /* spawn transmission rays / refraction */ /* note: this will overwrite the old intersection list */ if (obj->tex->opacity < 1.0) { color transcol; transcol = shade_transmission(incident, &hit, 1.0 - obj->tex->opacity); ColorAccum(&col, &transcol); } return col; /* return the color of the shaded pixel... */ } color shade_reflection(ray * incident, vector * hit, vector * N, flt specular) { ray specray; color col; vector R; VAddS(-2.0 * (incident->d.x * N->x + incident->d.y * N->y + incident->d.z * N->z), N, &incident->d, &R); specray.intstruct=incident->intstruct; /* what thread are we */ specray.depth=incident->depth - 1; /* go up a level in recursion depth */ specray.flags = RT_RAY_REGULAR; /* infinite ray, to start with */ specray.serial = incident->serial + 1; /* next serial number */ specray.mbox = incident->mbox; specray.o=*hit; specray.d=R; /* reflect incident ray about normal */ specray.o=Raypnt(&specray, EPSILON); /* avoid numerical precision bugs */ specray.maxdist = FHUGE; /* take any intersection */ specray.scene=incident->scene; /* global scenedef info */ col=trace(&specray); /* trace specular reflection ray */ incident->serial = specray.serial; /* update the serial number */ ColorScale(&col, specular); return col; } color shade_transmission(ray * incident, vector * hit, flt trans) { ray transray; color col; transray.intstruct=incident->intstruct; /* what thread are we */ transray.depth=incident->depth - 1; /* go up a level in recursion depth */ transray.flags = RT_RAY_REGULAR; /* infinite ray, to start with */ transray.serial = incident->serial + 1; /* update serial number */ transray.mbox = incident->mbox; transray.o=*hit; transray.d=incident->d; /* ray continues along incident path */ transray.o=Raypnt(&transray, EPSILON); /* avoid numerical precision bugs */ transray.maxdist = FHUGE; /* take any intersection */ transray.scene=incident->scene; /* global scenedef info */ col=trace(&transray); /* trace transmission ray */ incident->serial = transray.serial; ColorScale(&col, trans); return col; } flt shade_phong(ray * incident, vector * hit, vector * N, vector * L, flt specpower){ vector H, V; flt inten; V = incident->d; VScale(&V, -1.0); VAdd(&V, L, &H); VScale(&H, 0.5); VNorm(&H); inten = VDot(N, &H); if (inten > 0.0) inten = pow(inten, specpower); else inten = 0.0; return inten; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/light.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * light.cpp - This file contains declarations and defines for light sources. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define LIGHT_PRIVATE #include "light.h" static object_methods light_methods = { (void (*)(void *, void *))(light_intersect), (void (*)(void *, void *, void *, void *))(light_normal), light_bbox, free }; point_light * newlight(void * tex, vector ctr, flt rad) { point_light * l; l=(point_light *) rt_getmem(sizeof(point_light)); memset(l, 0, sizeof(point_light)); l->methods = &light_methods; l->tex=(texture *)tex; l->ctr=ctr; l->rad=rad; return l; } static int light_bbox(void * obj, vector * min, vector * max) { return 0; /* lights are unbounded currently */ } static void light_intersect(point_light * l, ray * ry) { flt b, disc, t1, t2, temp; vector V; /* Lights do not cast shadows.. */ if (ry->flags & RT_RAY_SHADOW) return; VSUB(l->ctr, ry->o, V); VDOT(b, V, ry->d); VDOT(temp, V, V); disc=b*b + l->rad*l->rad - temp; if (disc<=0.0) return; disc=sqrt(disc); t2=b+disc; if (t2 <= SPEPSILON) return; add_intersection(t2, (object *) l, ry); t1=b-disc; if (t1 > SPEPSILON) add_intersection(t1, (object *) l, ry); } static void light_normal(point_light * l, vector * pnt, ray * incident, vector * N) { VSub((vector *) pnt, &(l->ctr), N); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/extvol.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * extvol.cpp - Volume rendering helper routines etc. */ #include<stdio.h> #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "util.h" #include "box.h" #include "extvol.h" #include "trace.h" #include "sphere.h" #include "light.h" #include "shade.h" #include "global.h" int extvol_bbox(void * obj, vector * min, vector * max) { box * b = (box *) obj; *min = b->min; *max = b->max; return 1; } static object_methods extvol_methods = { (void (*)(void *, void *))(box_intersect), (void (*)(void *, void *, void *, void *))(box_normal), extvol_bbox, free }; extvol * newextvol(void * voidtex, vector min, vector max, int samples, flt (* evaluator)(flt, flt, flt)) { extvol * xvol; texture * tex; tex = (texture *) voidtex; xvol = (extvol *) rt_getmem(sizeof(extvol)); memset(xvol, 0, sizeof(extvol)); xvol->methods = &extvol_methods; xvol->min=min; xvol->max=max; xvol->evaluator = evaluator; xvol->ambient = tex->ambient; xvol->diffuse = tex->diffuse; xvol->opacity = tex->opacity; xvol->samples = samples; xvol->tex = (texture *)rt_getmem(sizeof(texture)); memset(xvol->tex, 0, sizeof(texture)); xvol->tex->ctr.x = 0.0; xvol->tex->ctr.y = 0.0; xvol->tex->ctr.z = 0.0; xvol->tex->rot = xvol->tex->ctr; xvol->tex->scale = xvol->tex->ctr; xvol->tex->uaxs = xvol->tex->ctr; xvol->tex->vaxs = xvol->tex->ctr; xvol->tex->islight = 0; xvol->tex->shadowcast = 0; xvol->tex->col=tex->col; xvol->tex->ambient=1.0; xvol->tex->diffuse=0.0; xvol->tex->specular=0.0; xvol->tex->opacity=1.0; xvol->tex->img=NULL; xvol->tex->texfunc=(color(*)(void *, void *, void *))(ext_volume_texture); xvol->tex->obj = (void *) xvol; /* XXX hack! */ return xvol; } color ExtVoxelColor(flt scalar) { color col; if (scalar > 1.0) scalar = 1.0; if (scalar < 0.0) scalar = 0.0; if (scalar < 0.5) { col.g = 0.0; } else { col.g = (scalar - 0.5) * 2.0; } col.r = scalar; col.b = 1.0 - (scalar / 2.0); return col; } color ext_volume_texture(vector * hit, texture * tex, ray * ry) { color col, col2; box * bx; extvol * xvol; flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; flt t, tdist, dt, ddt, sum, tt; vector pnt, bln; flt scalar, transval; int i; point_light * li; color diffint; vector N, L; flt inten; col.r = 0.0; col.g = 0.0; col.b = 0.0; bx = (box *) tex->obj; xvol = (extvol *) tex->obj; tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return col; } else { tx1 = (bx->min.x - ry->o.x) / ry->d.x; tx2 = (bx->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (ry->d.y == 0.0) { if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return col; } else { ty1 = (bx->min.y - ry->o.y) / ry->d.y; ty2 = (bx->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (ry->d.z == 0.0) { if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return col; } else { tz1 = (bx->min.z - ry->o.z) / ry->d.z; tz2 = (bx->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (tnear < 0.0) tnear=0.0; tdist = xvol->samples; tt = (xvol->opacity / tdist); bln.x=fabs(bx->min.x - bx->max.x); bln.y=fabs(bx->min.y - bx->max.y); bln.z=fabs(bx->min.z - bx->max.z); dt = 1.0 / tdist; sum = 0.0; /* Accumulate color as the ray passes through the voxels */ for (t=tnear; t<=tfar; t+=dt) { if (sum < 1.0) { pnt.x=((ry->o.x + (ry->d.x * t)) - bx->min.x) / bln.x; pnt.y=((ry->o.y + (ry->d.y * t)) - bx->min.y) / bln.y; pnt.z=((ry->o.z + (ry->d.z * t)) - bx->min.z) / bln.z; /* call external evaluator assume 0.0 -> 1.0 range.. */ scalar = xvol->evaluator(pnt.x, pnt.y, pnt.z); transval = tt * scalar; sum += transval; col2 = ExtVoxelColor(scalar); col.r += transval * col2.r * xvol->ambient; col.g += transval * col2.g * xvol->ambient; col.b += transval * col2.b * xvol->ambient; ddt = dt; /* Add in diffuse shaded light sources (no shadows) */ if (xvol->diffuse > 0.0) { /* Calculate the Volume gradient at the voxel */ N.x = (xvol->evaluator(pnt.x - ddt, pnt.y, pnt.z) - xvol->evaluator(pnt.x + ddt, pnt.y, pnt.z)) * 8.0 * tt; N.y = (xvol->evaluator(pnt.x, pnt.y - ddt, pnt.z) - xvol->evaluator(pnt.x, pnt.y + ddt, pnt.z)) * 8.0 * tt; N.z = (xvol->evaluator(pnt.x, pnt.y, pnt.z - ddt) - xvol->evaluator(pnt.x, pnt.y, pnt.z + ddt)) * 8.0 * tt; /* only light surfaces with enough of a normal.. */ if ((N.x*N.x + N.y*N.y + N.z*N.z) > 0.0) { diffint.r = 0.0; diffint.g = 0.0; diffint.b = 0.0; /* add the contribution of each of the lights.. */ for (i=0; i<numlights; i++) { li=lightlist[i]; VSUB(li->ctr, (*hit), L) VNorm(&L); VDOT(inten, N, L) /* only add light if its from the front of the surface */ /* could add back-lighting if we wanted to later.. */ if (inten > 0.0) { diffint.r += inten*li->tex->col.r; diffint.g += inten*li->tex->col.g; diffint.b += inten*li->tex->col.b; } } col.r += col2.r * diffint.r * xvol->diffuse; col.g += col2.g * diffint.g * xvol->diffuse; col.b += col2.b * diffint.b * xvol->diffuse; } } } else { sum=1.0; } } /* Add in transmitted ray from outside environment */ if (sum < 1.0) { /* spawn transmission rays / refraction */ color transcol; transcol = shade_transmission(ry, hit, 1.0 - sum); col.r += transcol.r; /* add the transmitted ray */ col.g += transcol.g; /* to the diffuse and */ col.b += transcol.b; /* transmission total.. */ } return col; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/tachyon_video.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "types.h" #include "api.h" /* The ray tracing library API */ #include "ui.h" #include "util.h" #include "tachyon_video.h" extern SceneHandle global_scene; extern char *global_window_title; extern bool global_usegraphics; void tachyon_video::on_process() { char buf[8192]; flt runtime; scenedef *scene = (scenedef *) global_scene; updating_mode = scene->displaymode == RT_DISPLAY_ENABLED; recycling = false; pausing = false; do { updating = updating_mode; timer start_timer = gettimer(); rt_renderscene(global_scene); timer end_timer = gettimer(); runtime = timertime(start_timer, end_timer); sprintf(buf, "%s: %.3f seconds", global_window_title, runtime); rt_ui_message(MSG_0, buf); title = buf; show_title(); // show time spent for rendering if(!updating) { updating = true; drawing_memory dm = get_drawing_memory(); drawing_area drawing(0, 0, dm.sizex, dm.sizey);// invalidate whole screen } //rt_finalize(); title = global_window_title; show_title(); // reset title to default } while(recycling && running); } void tachyon_video::on_key(int key) { key &= 0xff; recycling = true; if(key == esc_key) running = false; else if(key == ' ') { if(!updating) { updating = true; drawing_memory dm = get_drawing_memory(); drawing_area drawing(0, 0, dm.sizex, dm.sizey);// invalidate whole screen } updating = updating_mode = !updating_mode; } else if(key == 'p') { pausing = !pausing; if(pausing) { title = "Press ESC to exit or 'p' to continue after rendering completion"; show_title(); } } } void rt_finalize(void) { timer t0, t1; t0 = gettimer(); if(global_usegraphics) do { rt_sleep(1); t1 = gettimer(); } while( (timertime(t0, t1) < 10 || video->pausing) && video->next_frame()); #ifdef _WINDOWS else rt_sleep(10000); #endif }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/api.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * api.cpp - This file contains all of the API calls that are defined for * external driver code to use. */ #include "machine.h" #include "types.h" #include "macros.h" #include "box.h" #include "cylinder.h" #include "plane.h" #include "quadric.h" #include "ring.h" #include "sphere.h" #include "triangle.h" #include "vol.h" #include "extvol.h" #include "texture.h" #include "light.h" #include "render.h" #include "camera.h" #include "vector.h" #include "intersect.h" #include "shade.h" #include "util.h" #include "imap.h" #include "global.h" #include "tachyon_video.h" typedef void * SceneHandle; #include "api.h" vector rt_vector(apiflt x, apiflt y, apiflt z) { vector v; v.x = x; v.y = y; v.z = z; return v; } color rt_color(apiflt r, apiflt g, apiflt b) { color c; c.r = r; c.g = g; c.b = b; return c; } void rt_initialize() { rpcmsg msg; reset_object(); reset_lights(); InitTextures(); if (!parinitted) { parinitted=1; msg.type=1; /* setup a ping message */ } } void rt_renderscene(SceneHandle voidscene) { scenedef * scene = (scenedef *) voidscene; renderscene(*scene); } void rt_camerasetup(SceneHandle voidscene, apiflt zoom, apiflt aspectratio, int antialiasing, int raydepth, vector camcent, vector viewvec, vector upvec) { scenedef * scene = (scenedef *) voidscene; vector newupvec; vector newviewvec; vector newrightvec; VCross((vector *) &upvec, &viewvec, &newrightvec); VNorm(&newrightvec); VCross((vector *) &viewvec, &newrightvec, &newupvec); VNorm(&newupvec); newviewvec=viewvec; VNorm(&newviewvec); scene->camzoom=zoom; scene->aspectratio=aspectratio; scene->antialiasing=antialiasing; scene->raydepth=raydepth; scene->camcent=camcent; scene->camviewvec=newviewvec; scene->camrightvec=newrightvec; scene->camupvec=newupvec; } void rt_outputfile(SceneHandle voidscene, const char * outname) { scenedef * scene = (scenedef *) voidscene; strcpy((char *) &scene->outfilename, outname); } void rt_resolution(SceneHandle voidscene, int hres, int vres) { scenedef * scene = (scenedef *) voidscene; scene->hres=hres; scene->vres=vres; } void rt_verbose(SceneHandle voidscene, int v) { scenedef * scene = (scenedef *) voidscene; scene->verbosemode = v; } void rt_rawimage(SceneHandle voidscene, unsigned char *rawimage) { scenedef * scene = (scenedef *) voidscene; scene->rawimage = rawimage; } void rt_background(SceneHandle voidscene, color col) { scenedef * scene = (scenedef *) voidscene; scene->background.r = col.r; scene->background.g = col.g; scene->background.b = col.b; } void rt_boundmode(SceneHandle voidscene, int mode) { scenedef * scene = (scenedef *) voidscene; scene->boundmode = mode; } void rt_boundthresh(SceneHandle voidscene, int threshold) { scenedef * scene = (scenedef *) voidscene; if (threshold > 1) { scene->boundthresh = threshold; } else { rtmesg("Ignoring out-of-range automatic bounding threshold.\n"); rtmesg("Automatic bounding threshold reset to default.\n"); scene->boundthresh = MAXOCTNODES; } } void rt_displaymode(SceneHandle voidscene, int mode) { scenedef * scene = (scenedef *) voidscene; scene->displaymode = mode; } void rt_scenesetup(SceneHandle voidscene, char * outname, int hres, int vres, int verbose) { rt_outputfile(voidscene, outname); rt_resolution(voidscene, hres, vres); rt_verbose(voidscene, verbose); } SceneHandle rt_newscene(void) { scenedef * scene; SceneHandle voidscene; scene = (scenedef *) malloc(sizeof(scenedef)); memset(scene, 0, sizeof(scenedef)); /* clear all valuas to 0 */ voidscene = (SceneHandle) scene; rt_outputfile(voidscene, "/dev/null"); /* default output file (.tga) */ rt_resolution(voidscene, 512, 512); /* 512x512 resolution */ rt_verbose(voidscene, 0); /* verbose messages off */ rt_rawimage(voidscene, NULL); /* raw image output off */ rt_boundmode(voidscene, RT_BOUNDING_ENABLED); /* spatial subdivision on */ rt_boundthresh(voidscene, MAXOCTNODES); /* default threshold */ rt_displaymode(voidscene, RT_DISPLAY_ENABLED); /* video output on */ rt_camerasetup(voidscene, 1.0, 1.0, 0, 6, rt_vector(0.0, 0.0, 0.0), rt_vector(0.0, 0.0, 1.0), rt_vector(0.0, 1.0, 0.0)); return scene; } void rt_deletescene(SceneHandle scene) { if (scene != NULL) free(scene); } void apitextotex(apitexture * apitex, texture * tex) { switch(apitex->texturefunc) { case 0: tex->texfunc=(color(*)(void *, void *, void *))(standard_texture); break; case 1: tex->texfunc=(color(*)(void *, void *, void *))(checker_texture); break; case 2: tex->texfunc=(color(*)(void *, void *, void *))(grit_texture); break; case 3: tex->texfunc=(color(*)(void *, void *, void *))(marble_texture); break; case 4: tex->texfunc=(color(*)(void *, void *, void *))(wood_texture); break; case 5: tex->texfunc=(color(*)(void *, void *, void *))(gnoise_texture); break; case 6: tex->texfunc=(color(*)(void *, void *, void *))(cyl_checker_texture); break; case 7: tex->texfunc=(color(*)(void *, void *, void *))(image_sphere_texture); tex->img=AllocateImage((char *)apitex->imap); break; case 8: tex->texfunc=(color(*)(void *, void *, void *))(image_cyl_texture); tex->img=AllocateImage((char *)apitex->imap); break; case 9: tex->texfunc=(color(*)(void *, void *, void *))(image_plane_texture); tex->img=AllocateImage((char *)apitex->imap); break; default: tex->texfunc=(color(*)(void *, void *, void *))(standard_texture); break; } tex->ctr = apitex->ctr; tex->rot = apitex->rot; tex->scale = apitex->scale; tex->uaxs = apitex->uaxs; tex->vaxs = apitex->vaxs; tex->ambient = apitex->ambient; tex->diffuse = apitex->diffuse; tex->specular = apitex->specular; tex->opacity = apitex->opacity; tex->col = apitex->col; tex->islight = 0; tex->shadowcast = 1; tex->phong = 0.0; tex->phongexp = 0.0; tex->phongtype = 0; } void * rt_texture(apitexture * apitex) { texture * tex; tex=(texture *)rt_getmem(sizeof(texture)); apitextotex(apitex, tex); return(tex); } void rt_tex_color(void * voidtex, color col) { texture * tex = (texture *) voidtex; tex->col = col; } void rt_tex_phong(void * voidtex, apiflt phong, apiflt phongexp, int type) { texture * tex = (texture *) voidtex; tex->phong = phong; tex->phongexp = phongexp; tex->phongtype = type; } void rt_light(void * tex, vector ctr, apiflt rad) { point_light * li; li=newlight(tex, (vector) ctr, rad); li->tex->islight=1; li->tex->shadowcast=1; li->tex->diffuse=0.0; li->tex->specular=0.0; li->tex->opacity=1.0; add_light(li); add_object((object *)li); } void rt_scalarvol(void * tex, vector min, vector max, int xs, int ys, int zs, char * fname, void * invol) { add_object((object *) newscalarvol(tex, (vector)min, (vector)max, xs, ys, zs, fname, (scalarvol *) invol)); } void rt_extvol(void * tex, vector min, vector max, int samples, flt (* evaluator)(flt, flt, flt)) { add_object((object *) newextvol(tex, (vector)min, (vector)max, samples, evaluator)); } void rt_box(void * tex, vector min, vector max) { add_object((object *) newbox(tex, (vector)min, (vector)max)); } void rt_cylinder(void * tex, vector ctr, vector axis, apiflt rad) { add_object(newcylinder(tex, (vector)ctr, (vector)axis, rad)); } void rt_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) { add_object(newfcylinder(tex, (vector)ctr, (vector)axis, rad)); } void rt_plane(void * tex, vector ctr, vector norm) { add_object(newplane(tex, (vector)ctr, (vector)norm)); } void rt_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) { add_object(newring(tex, (vector)ctr, (vector)norm, a, b)); } void rt_sphere(void * tex, vector ctr, apiflt rad) { add_object(newsphere(tex, (vector)ctr, rad)); } void rt_tri(void * tex, vector v0, vector v1, vector v2) { object * trn; trn = newtri(tex, (vector)v0, (vector)v1, (vector)v2); if (trn != NULL) { add_object(trn); } } void rt_stri(void * tex, vector v0, vector v1, vector v2, vector n0, vector n1, vector n2) { object * trn; trn = newstri(tex, (vector)v0, (vector)v1, (vector)v2, (vector)n0, (vector)n1, (vector)n2); if (trn != NULL) { add_object(trn); } } void rt_quadsphere(void * tex, vector ctr, apiflt rad) { quadric * q; flt factor; q=(quadric *) newquadric(); factor= 1.0 / (rad*rad); q->tex=(texture *)tex; q->ctr=ctr; q->mat.a=factor; q->mat.b=0.0; q->mat.c=0.0; q->mat.d=0.0; q->mat.e=factor; q->mat.f=0.0; q->mat.g=0.0; q->mat.h=factor; q->mat.i=0.0; q->mat.j=-1.0; add_object((object *)q); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/triangle.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * triangle.cpp - This file contains the functions for dealing with triangles. */ #include "machine.h" #include "types.h" #include "vector.h" #include "macros.h" #include "intersect.h" #include "util.h" #define TRIANGLE_PRIVATE #include "triangle.h" static object_methods tri_methods = { (void (*)(void *, void *))(tri_intersect), (void (*)(void *, void *, void *, void *))(tri_normal), tri_bbox, free }; static object_methods stri_methods = { (void (*)(void *, void *))(tri_intersect), (void (*)(void *, void *, void *, void *))(stri_normal), tri_bbox, free }; object * newtri(void * tex, vector v0, vector v1, vector v2) { tri * t; vector edge1, edge2, edge3; VSub(&v1, &v0, &edge1); VSub(&v2, &v0, &edge2); VSub(&v2, &v1, &edge3); /* check to see if this will be a degenerate triangle before creation */ if ((VLength(&edge1) >= EPSILON) && (VLength(&edge2) >= EPSILON) && (VLength(&edge3) >= EPSILON)) { t=(tri *) rt_getmem(sizeof(tri)); t->nextobj = NULL; t->methods = &tri_methods; t->tex = (texture *)tex; t->v0 = v0; t->edge1 = edge1; t->edge2 = edge2; return (object *) t; } return NULL; /* was a degenerate triangle */ } object * newstri(void * tex, vector v0, vector v1, vector v2, vector n0, vector n1, vector n2) { stri * t; vector edge1, edge2, edge3; VSub(&v1, &v0, &edge1); VSub(&v2, &v0, &edge2); VSub(&v2, &v1, &edge3); /* check to see if this will be a degenerate triangle before creation */ if ((VLength(&edge1) >= EPSILON) && (VLength(&edge2) >= EPSILON) && (VLength(&edge3) >= EPSILON)) { t=(stri *) rt_getmem(sizeof(stri)); t->nextobj = NULL; t->methods = &stri_methods; t->tex = (texture *)tex; t->v0 = v0; t->edge1 = edge1; t->edge2 = edge2; t->n0 = n0; t->n1 = n1; t->n2 = n2; return (object *) t; } return NULL; /* was a degenerate triangle */ } #define CROSS(dest,v1,v2) \ dest.x=v1.y*v2.z-v1.z*v2.y; \ dest.y=v1.z*v2.x-v1.x*v2.z; \ dest.z=v1.x*v2.y-v1.y*v2.x; #define DOT(v1,v2) (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z) #define SUB(dest,v1,v2) \ dest.x=v1.x-v2.x; \ dest.y=v1.y-v2.y; \ dest.z=v1.z-v2.z; static int tri_bbox(void * obj, vector * min, vector * max) { tri * t = (tri *) obj; vector v1, v2; VAdd(&t->v0, &t->edge1, &v1); VAdd(&t->v0, &t->edge2, &v2); min->x = MYMIN( t->v0.x , MYMIN( v1.x , v2.x )); min->y = MYMIN( t->v0.y , MYMIN( v1.y , v2.y )); min->z = MYMIN( t->v0.z , MYMIN( v1.z , v2.z )); max->x = MYMAX( t->v0.x , MYMAX( v1.x , v2.x )); max->y = MYMAX( t->v0.y , MYMAX( v1.y , v2.y )); max->z = MYMAX( t->v0.z , MYMAX( v1.z , v2.z )); return 1; } static void tri_intersect(tri * trn, ray * ry) { vector tvec, pvec, qvec; flt det, inv_det, t, u, v; /* begin calculating determinant - also used to calculate U parameter */ CROSS(pvec, ry->d, trn->edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = DOT(trn->edge1, pvec); if (det > -EPSILON && det < EPSILON) return; inv_det = 1.0 / det; /* calculate distance from vert0 to ray origin */ SUB(tvec, ry->o, trn->v0); /* calculate U parameter and test bounds */ u = DOT(tvec, pvec) * inv_det; if (u < 0.0 || u > 1.0) return; /* prepare to test V parameter */ CROSS(qvec, tvec, trn->edge1); /* calculate V parameter and test bounds */ v = DOT(ry->d, qvec) * inv_det; if (v < 0.0 || u + v > 1.0) return; /* calculate t, ray intersects triangle */ t = DOT(trn->edge2, qvec) * inv_det; add_intersection(t,(object *) trn, ry); } static void tri_normal(tri * trn, vector * pnt, ray * incident, vector * N) { CROSS((*N), trn->edge1, trn->edge2); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } } static void stri_normal(stri * trn, vector * pnt, ray * incident, vector * N) { flt U, V, W, lensqr; vector P, tmp, norm; CROSS(norm, trn->edge1, trn->edge2); lensqr = DOT(norm, norm); VSUB((*pnt), trn->v0, P); CROSS(tmp, P, trn->edge2); U = DOT(tmp, norm) / lensqr; CROSS(tmp, trn->edge1, P); V = DOT(tmp, norm) / lensqr; W = 1.0 - (U + V); N->x = W*trn->n0.x + U*trn->n1.x + V*trn->n2.x; N->y = W*trn->n0.y + U*trn->n1.y + V*trn->n2.y; N->z = W*trn->n0.z + U*trn->n1.z + V*trn->n2.z; VNorm(N); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/trace_rest.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * trace.cpp - This file contains the functions for firing primary rays * and handling subsequent calculations */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "tgafile.h" #include "trace.h" #include "light.h" #include "shade.h" #include "camera.h" #include "util.h" #include "intersect.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" color trace(ray * primary) { if (primary->depth > 0) { VNorm(&primary->d); reset_intersection(primary->intstruct); intersect_objects(primary); return shader(primary); } /* if ray is truncated, return the background as its color */ return primary->scene->background; } void * thread_io(void * parms) { thr_io_parms p; p= *((thr_io_parms *) parms); writetgaregion(p.tga, p.iwidth, p.iheight, p.startx, p.starty, p.stopx, p.stopy, p.buffer); free(p.buffer); /* free the buffer once we are done with it.. */ free(parms); return(NULL); } void trace_shm(scenedef scene, /*char * buffer, */ int startx, int stopx, int starty, int stopy) { thr_parms * parms; parms = (thr_parms *) rt_getmem(sizeof(thr_parms)); parms->tid=0; parms->nthr=1; parms->scene=scene; parms->startx=startx; parms->stopx=stopx; parms->starty=starty; parms->stopy=stopy; thread_trace(parms); rt_freemem(parms); } void trace_region(scenedef scene, void * tga, int startx, int starty, int stopx, int stopy) { if (scene.verbosemode) { char msgtxt[2048]; sprintf(msgtxt, "Node %3d tracing region %4d, %4d ---> %4d, %4d \n", 0, startx,starty,stopx,stopy); rt_ui_message(MSG_0, msgtxt); } trace_shm(scene, /*buffer,*/ startx, stopx, starty, stopy); /* not used now writetgaregion(tga, scene.hres, scene.vres, startx, starty, stopx, stopy, global_buffer); if (scene.rawimage != NULL) { int x, y; int totalx = stopx - startx + 1; for (y=starty; y<=stopy; y++) { for (x=0; x<scene.hres; x++) { scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3] = global_buffer[(y-starty)*totalx*3 + x*3 + 2]; scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +1] = global_buffer[(y-starty)*totalx*3 + x*3 + 1]; scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +2] = global_buffer[(y-starty)*totalx*3 + x*3]; } } } */ }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/intersect.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * intersect.cpp - This file contains code for CSG and intersection routines. */ #include "machine.h" #include "types.h" #include "intersect.h" #include "light.h" #include "util.h" #include "global.h" unsigned int new_objectid(void) { return numobjects++; /* global used to generate unique object ID's */ } unsigned int max_objectid(void) { return numobjects; } void add_object(object * obj) { object * objtemp; if (obj == NULL) return; obj->id = new_objectid(); objtemp = rootobj; rootobj = obj; obj->nextobj = objtemp; } void free_objects(object * start) { object * cur; object * cur2; cur=start; while (cur->nextobj != NULL) { cur2=(object *)cur->nextobj; cur->methods->free(cur); cur=cur2; } free(cur); } void reset_object(void) { if (rootobj != NULL) free_objects(rootobj); rootobj = NULL; numobjects = 0; /* set number of objects back to 0 */ } void intersect_objects(ray * intray) { object * cur; object temp; temp.nextobj = rootobj; /* setup the initial object pointers.. */ cur = &temp; /* ready, set */ while ((cur=(object *)cur->nextobj) != NULL) cur->methods->intersect(cur, intray); } void reset_intersection(intersectstruct * intstruct) { intstruct->num = 0; intstruct->list[0].t = FHUGE; intstruct->list[0].obj = NULL; intstruct->list[1].t = FHUGE; intstruct->list[1].obj = NULL; } void add_intersection(flt t, object * obj, ray * ry) { intersectstruct * intstruct = ry->intstruct; if (t > EPSILON) { /* if we hit something before maxdist update maxdist */ if (t < ry->maxdist) { ry->maxdist = t; /* if we hit *anything* before maxdist, and we're firing a */ /* shadow ray, then we are finished ray tracing the shadow */ if (ry->flags & RT_RAY_SHADOW) ry->flags |= RT_RAY_FINISHED; } intstruct->num++; intstruct->list[intstruct->num].obj = obj; intstruct->list[intstruct->num].t = t; } } int closest_intersection(flt * t, object ** obj, intersectstruct * intstruct) { int i; *t=FHUGE; for (i=1; i<=intstruct->num; i++) { if (intstruct->list[i].t < *t) { *t=intstruct->list[i].t; *obj=intstruct->list[i].obj; } } return intstruct->num; } int shadow_intersection(intersectstruct * intstruct, flt maxdist) { int i; if (intstruct->num > 0) { for (i=1; i<=intstruct->num; i++) { if ((intstruct->list[i].t < maxdist) && (intstruct->list[i].obj->tex->shadowcast == 1)) { return 1; } } } return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/grid.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * grid.cpp - spatial subdivision efficiency structures */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define GRID_PRIVATE #include "grid.h" #ifndef cbrt #define cbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/3.0) : \ ((x) < 0.0 ? -pow((double)-(x), 1.0/3.0) : 0.0)) #define qbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/4.0) : \ ((x) < 0.0 ? -pow((double)-(x), 1.0/4.0) : 0.0)) #endif static object_methods grid_methods = { (void (*)(void *, void *))(grid_intersect), (void (*)(void *, void *, void *, void *))(NULL), grid_bbox, grid_free }; extern bool silent_mode; object * newgrid(int xsize, int ysize, int zsize, vector min, vector max) { grid * g; g = (grid *) rt_getmem(sizeof(grid)); memset(g, 0, sizeof(grid)); g->methods = &grid_methods; g->id = new_objectid(); g->xsize = xsize; g->ysize = ysize; g->zsize = zsize; g->min = min; g->max = max; VSub(&g->max, &g->min, &g->voxsize); g->voxsize.x /= (flt) g->xsize; g->voxsize.y /= (flt) g->ysize; g->voxsize.z /= (flt) g->zsize; g->cells = (objectlist **) rt_getmem(xsize*ysize*zsize*sizeof(objectlist *)); memset(g->cells, 0, xsize*ysize*zsize * sizeof(objectlist *)); /* fprintf(stderr, "New grid, size: %8d %8d %8d\n", g->xsize, g->ysize, g->zsize); */ return (object *) g; } static int grid_bbox(void * obj, vector * min, vector * max) { grid * g = (grid *) obj; *min = g->min; *max = g->max; return 1; } static void grid_free(void * v) { int i, numvoxels; grid * g = (grid *) v; /* loop through all voxels and free the object lists */ numvoxels = g->xsize * g->ysize * g->zsize; for (i=0; i<numvoxels; i++) { objectlist * lcur, * lnext; lcur = g->cells[i]; while (lcur != NULL) { lnext = lcur->next; free(lcur); } } /* free the grid cells */ free(g->cells); /* free all objects on the grid object list */ free_objects(g->objects); free(g); } static void globalbound(object ** rootlist, vector * gmin, vector * gmax) { vector min, max; object * cur; if (*rootlist == NULL) /* don't bound non-existant objects */ return; gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE; gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE; cur=*rootlist; while (cur != NULL) { /* Go! */ min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE; max.x = FHUGE; max.y = FHUGE; max.z = FHUGE; if (cur->methods->bbox((void *) cur, &min, &max)) { gmin->x = MYMIN( gmin->x , min.x); gmin->y = MYMIN( gmin->y , min.y); gmin->z = MYMIN( gmin->z , min.z); gmax->x = MYMAX( gmax->x , max.x); gmax->y = MYMAX( gmax->y , max.y); gmax->z = MYMAX( gmax->z , max.z); } cur=(object *)cur->nextobj; } } static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax) { vector min, max, cellmin, cellmax; objectlist * cur; int numinbounds = 0; cur = g->cells[index->z*g->xsize*g->ysize + index->y*g->xsize + index->x]; if (cur == NULL) /* don't bound non-existant objects */ return 0; cellmin.x = voxel2x(g, index->x); cellmin.y = voxel2y(g, index->y); cellmin.z = voxel2z(g, index->z); cellmax.x = cellmin.x + g->voxsize.x; cellmax.y = cellmin.y + g->voxsize.y; cellmax.z = cellmin.z + g->voxsize.z; cmin->x = FHUGE; cmin->y = FHUGE; cmin->z = FHUGE; cmax->x = -FHUGE; cmax->y = -FHUGE; cmax->z = -FHUGE; while (cur != NULL) { /* Go! */ min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE; max.x = FHUGE; max.y = FHUGE; max.z = FHUGE; if (cur->obj->methods->bbox((void *) cur->obj, &min, &max)) { if ((min.x >= cellmin.x) && (max.x <= cellmax.x) && (min.y >= cellmin.y) && (max.y <= cellmax.y) && (min.z >= cellmin.z) && (max.z <= cellmax.z)) { cmin->x = MYMIN( cmin->x , min.x); cmin->y = MYMIN( cmin->y , min.y); cmin->z = MYMIN( cmin->z , min.z); cmax->x = MYMAX( cmax->x , max.x); cmax->y = MYMAX( cmax->y , max.y); cmax->z = MYMAX( cmax->z , max.z); numinbounds++; } } cur=cur->next; } /* in case we get a 0.0 sized axis on the cell bounds, we'll */ /* use the original cell bounds */ if ((cmax->x - cmin->x) < EPSILON) { cmax->x += EPSILON; cmin->x -= EPSILON; } if ((cmax->y - cmin->y) < EPSILON) { cmax->y += EPSILON; cmin->y -= EPSILON; } if ((cmax->z - cmin->z) < EPSILON) { cmax->z += EPSILON; cmin->z -= EPSILON; } return numinbounds; } static int countobj(object * root) { object * cur; /* counts the number of objects on a list */ int numobj; numobj=0; cur=root; while (cur != NULL) { cur=(object *)cur->nextobj; numobj++; } return numobj; } static int countobjlist(objectlist * root) { objectlist * cur; int numobj; numobj=0; cur = root; while (cur != NULL) { cur = cur->next; numobj++; } return numobj; } int engrid_scene(object ** list) { grid * g; int numobj, numcbrt; vector gmin, gmax; gridindex index; if (*list == NULL) return 0; numobj = countobj(*list); if ( !silent_mode ) fprintf(stderr, "Scene contains %d bounded objects.\n", numobj); if (numobj > 16) { numcbrt = (int) cbrt(4*numobj); globalbound(list, &gmin, &gmax); g = (grid *) newgrid(numcbrt, numcbrt, numcbrt, gmin, gmax); engrid_objlist(g, list); numobj = countobj(*list); g->nextobj = *list; *list = (object *) g; /* now create subgrids.. */ for (index.z=0; index.z<g->zsize; index.z++) { for (index.y=0; index.y<g->ysize; index.y++) { for (index.x=0; index.x<g->xsize; index.x++) { engrid_cell(g, &index); } } } } return 1; } void engrid_objlist(grid * g, object ** list) { object * cur, * next, **prev; if (*list == NULL) return; prev = list; cur = *list; while (cur != NULL) { next = (object *)cur->nextobj; if (engrid_object(g, cur)) *prev = next; else prev = (object **) &cur->nextobj; cur = next; } } static int engrid_cell(grid * gold, gridindex *index) { vector gmin, gmax, gsize; flt len; int numobj, numcbrt, xs, ys, zs; grid * g; objectlist **list; objectlist * newobj; list = &gold->cells[index->z*gold->xsize*gold->ysize + index->y*gold->xsize + index->x]; if (*list == NULL) return 0; numobj = cellbound(gold, index, &gmin, &gmax); VSub(&gmax, &gmin, &gsize); len = 1.0 / (MYMAX( MYMAX(gsize.x, gsize.y), gsize.z )); gsize.x *= len; gsize.y *= len; gsize.z *= len; if (numobj > 16) { numcbrt = (int) cbrt(2*numobj); xs = (int) ((flt) numcbrt * gsize.x); if (xs < 1) xs = 1; ys = (int) ((flt) numcbrt * gsize.y); if (ys < 1) ys = 1; zs = (int) ((flt) numcbrt * gsize.z); if (zs < 1) zs = 1; g = (grid *) newgrid(xs, ys, zs, gmin, gmax); engrid_objectlist(g, list); newobj = (objectlist *) rt_getmem(sizeof(objectlist)); newobj->obj = (object *) g; newobj->next = *list; *list = newobj; g->nextobj = gold->objects; gold->objects = (object *) g; } return 1; } static int engrid_objectlist(grid * g, objectlist ** list) { objectlist * cur, * next, **prev; int numsucceeded = 0; if (*list == NULL) return 0; prev = list; cur = *list; while (cur != NULL) { next = cur->next; if (engrid_object(g, cur->obj)) { *prev = next; free(cur); numsucceeded++; } else { prev = &cur->next; } cur = next; } return numsucceeded; } static int engrid_object(grid * g, object * obj) { vector omin, omax; gridindex low, high; int x, y, z, zindex, yindex, voxindex; objectlist * tmp; if (obj->methods->bbox(obj, &omin, &omax)) { if (!pos2grid(g, &omin, &low) || !pos2grid(g, &omax, &high)) { return 0; /* object is not wholly contained in the grid */ } } else { return 0; /* object is unbounded */ } /* add the object to the complete list of objects in the grid */ obj->nextobj = g->objects; g->objects = obj; /* add this object to all voxels it inhabits */ for (z=low.z; z<=high.z; z++) { zindex = z * g->xsize * g->ysize; for (y=low.y; y<=high.y; y++) { yindex = y * g->xsize; for (x=low.x; x<=high.x; x++) { voxindex = x + yindex + zindex; tmp = (objectlist *) rt_getmem(sizeof(objectlist)); tmp->next = g->cells[voxindex]; tmp->obj = obj; g->cells[voxindex] = tmp; } } } return 1; } static int pos2grid(grid * g, vector * pos, gridindex * index) { index->x = (int) ((pos->x - g->min.x) / g->voxsize.x); index->y = (int) ((pos->y - g->min.y) / g->voxsize.y); index->z = (int) ((pos->z - g->min.z) / g->voxsize.z); if (index->x == g->xsize) index->x--; if (index->y == g->ysize) index->y--; if (index->z == g->zsize) index->z--; if (index->x < 0 || index->x > g->xsize || index->y < 0 || index->y > g->ysize || index->z < 0 || index->z > g->zsize) return 0; if (pos->x < g->min.x || pos->x > g->max.x || pos->y < g->min.y || pos->y > g->max.y || pos->z < g->min.z || pos->z > g->max.z) return 0; return 1; } /* the real thing */ static void grid_intersect(grid * g, ray * ry) { flt tnear, tfar, offset; vector curpos, tmax, tdelta, pdeltaX, pdeltaY, pdeltaZ, nXp, nYp, nZp; gridindex curvox, step, out; int voxindex; objectlist * cur; if (ry->flags & RT_RAY_FINISHED) return; if (!grid_bounds_intersect(g, ry, &tnear, &tfar)) return; if (ry->maxdist < tnear) return; curpos = Raypnt(ry, tnear); pos2grid(g, &curpos, &curvox); offset = tnear; /* Setup X iterator stuff */ if (fabs(ry->d.x) < EPSILON) { tmax.x = FHUGE; tdelta.x = 0.0; step.x = 0; out.x = 0; /* never goes out of bounds on this axis */ } else if (ry->d.x < 0.0) { tmax.x = offset + ((voxel2x(g, curvox.x) - curpos.x) / ry->d.x); tdelta.x = g->voxsize.x / - ry->d.x; step.x = out.x = -1; } else { tmax.x = offset + ((voxel2x(g, curvox.x + 1) - curpos.x) / ry->d.x); tdelta.x = g->voxsize.x / ry->d.x; step.x = 1; out.x = g->xsize; } /* Setup Y iterator stuff */ if (fabs(ry->d.y) < EPSILON) { tmax.y = FHUGE; tdelta.y = 0.0; step.y = 0; out.y = 0; /* never goes out of bounds on this axis */ } else if (ry->d.y < 0.0) { tmax.y = offset + ((voxel2y(g, curvox.y) - curpos.y) / ry->d.y); tdelta.y = g->voxsize.y / - ry->d.y; step.y = out.y = -1; } else { tmax.y = offset + ((voxel2y(g, curvox.y + 1) - curpos.y) / ry->d.y); tdelta.y = g->voxsize.y / ry->d.y; step.y = 1; out.y = g->ysize; } /* Setup Z iterator stuff */ if (fabs(ry->d.z) < EPSILON) { tmax.z = FHUGE; tdelta.z = 0.0; step.z = 0; out.z = 0; /* never goes out of bounds on this axis */ } else if (ry->d.z < 0.0) { tmax.z = offset + ((voxel2z(g, curvox.z) - curpos.z) / ry->d.z); tdelta.z = g->voxsize.z / - ry->d.z; step.z = out.z = -1; } else { tmax.z = offset + ((voxel2z(g, curvox.z + 1) - curpos.z) / ry->d.z); tdelta.z = g->voxsize.z / ry->d.z; step.z = 1; out.z = g->zsize; } pdeltaX = ry->d; VScale(&pdeltaX, tdelta.x); pdeltaY = ry->d; VScale(&pdeltaY, tdelta.y); pdeltaZ = ry->d; VScale(&pdeltaZ, tdelta.z); nXp = Raypnt(ry, tmax.x); nYp = Raypnt(ry, tmax.y); nZp = Raypnt(ry, tmax.z); voxindex = curvox.z*g->xsize*g->ysize + curvox.y*g->xsize + curvox.x; while (1) { if (tmax.x < tmax.y && tmax.x < tmax.z) { cur = g->cells[voxindex]; while (cur != NULL) { if (ry->mbox[cur->obj->id] != ry->serial) { ry->mbox[cur->obj->id] = ry->serial; cur->obj->methods->intersect(cur->obj, ry); } cur = cur->next; } curvox.x += step.x; if (ry->maxdist < tmax.x || curvox.x == out.x) break; voxindex += step.x; tmax.x += tdelta.x; curpos = nXp; nXp.x += pdeltaX.x; nXp.y += pdeltaX.y; nXp.z += pdeltaX.z; } else if (tmax.z < tmax.y) { cur = g->cells[voxindex]; while (cur != NULL) { if (ry->mbox[cur->obj->id] != ry->serial) { ry->mbox[cur->obj->id] = ry->serial; cur->obj->methods->intersect(cur->obj, ry); } cur = cur->next; } curvox.z += step.z; if (ry->maxdist < tmax.z || curvox.z == out.z) break; voxindex += step.z*g->xsize*g->ysize; tmax.z += tdelta.z; curpos = nZp; nZp.x += pdeltaZ.x; nZp.y += pdeltaZ.y; nZp.z += pdeltaZ.z; } else { cur = g->cells[voxindex]; while (cur != NULL) { if (ry->mbox[cur->obj->id] != ry->serial) { ry->mbox[cur->obj->id] = ry->serial; cur->obj->methods->intersect(cur->obj, ry); } cur = cur->next; } curvox.y += step.y; if (ry->maxdist < tmax.y || curvox.y == out.y) break; voxindex += step.y*g->xsize; tmax.y += tdelta.y; curpos = nYp; nYp.x += pdeltaY.x; nYp.y += pdeltaY.y; nYp.z += pdeltaY.z; } if (ry->flags & RT_RAY_FINISHED) break; } } static void voxel_intersect(grid * g, ray * ry, int voxindex) { objectlist * cur; cur = g->cells[voxindex]; while (cur != NULL) { cur->obj->methods->intersect(cur->obj, ry); cur = cur->next; } } static int grid_bounds_intersect(grid * g, ray * ry, flt *nr, flt *fr) { flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < g->min.x) || (ry->o.x > g->max.x)) return 0; } else { tx1 = (g->min.x - ry->o.x) / ry->d.x; tx2 = (g->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return 0; if (tfar < 0.0) return 0; if (ry->d.y == 0.0) { if ((ry->o.y < g->min.y) || (ry->o.y > g->max.y)) return 0; } else { ty1 = (g->min.y - ry->o.y) / ry->d.y; ty2 = (g->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return 0; if (tfar < 0.0) return 0; if (ry->d.z == 0.0) { if ((ry->o.z < g->min.z) || (ry->o.z > g->max.z)) return 0; } else { tz1 = (g->min.z - ry->o.z) / ry->d.z; tz2 = (g->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return 0; if (tfar < 0.0) return 0; *nr = tnear; *fr = tfar; return 1; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/quadric.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * quadric.cpp - This file contains the functions for dealing with quadrics. */ #include "machine.h" #include "types.h" #include "macros.h" #include "quadric.h" #include "vector.h" #include "intersect.h" #include "util.h" int quadric_bbox(void * obj, vector * min, vector * max) { return 0; } static object_methods quadric_methods = { (void (*)(void *, void *))(quadric_intersect), (void (*)(void *, void *, void *, void *))(quadric_normal), quadric_bbox, free }; quadric * newquadric() { quadric * q; q=(quadric *) rt_getmem(sizeof(quadric)); memset(q, 0, sizeof(quadric)); q->ctr.x=0.0; q->ctr.y=0.0; q->ctr.z=0.0; q->methods = &quadric_methods; return q; } void quadric_intersect(quadric * q, ray * ry) { flt Aq, Bq, Cq; flt t1, t2; flt disc; vector rd; vector ro; rd=ry->d; VNorm(&rd); ro.x = ry->o.x - q->ctr.x; ro.y = ry->o.y - q->ctr.y; ro.z = ry->o.z - q->ctr.z; Aq = (q->mat.a*(rd.x * rd.x)) + (2.0 * q->mat.b * rd.x * rd.y) + (2.0 * q->mat.c * rd.x * rd.z) + (q->mat.e * (rd.y * rd.y)) + (2.0 * q->mat.f * rd.y * rd.z) + (q->mat.h * (rd.z * rd.z)); Bq = 2.0 * ( (q->mat.a * ro.x * rd.x) + (q->mat.b * ((ro.x * rd.y) + (rd.x * ro.y))) + (q->mat.c * ((ro.x * rd.z) + (rd.x * ro.z))) + (q->mat.d * rd.x) + (q->mat.e * ro.y * rd.y) + (q->mat.f * ((ro.y * rd.z) + (rd.y * ro.z))) + (q->mat.g * rd.y) + (q->mat.h * ro.z * rd.z) + (q->mat.i * rd.z) ); Cq = (q->mat.a * (ro.x * ro.x)) + (2.0 * q->mat.b * ro.x * ro.y) + (2.0 * q->mat.c * ro.x * ro.z) + (2.0 * q->mat.d * ro.x) + (q->mat.e * (ro.y * ro.y)) + (2.0 * q->mat.f * ro.y * ro.z) + (2.0 * q->mat.g * ro.y) + (q->mat.h * (ro.z * ro.z)) + (2.0 * q->mat.i * ro.z) + q->mat.j; if (Aq == 0.0) { t1 = - Cq / Bq; add_intersection(t1, (object *) q, ry); } else { disc=(Bq*Bq - 4.0 * Aq * Cq); if (disc > 0.0) { disc=sqrt(disc); t1 = (-Bq + disc) / (2.0 * Aq); t2 = (-Bq - disc) / (2.0 * Aq); add_intersection(t1, (object *) q, ry); add_intersection(t2, (object *) q, ry); } } } void quadric_normal(quadric * q, vector * pnt, ray * incident, vector * N) { N->x = (q->mat.a*(pnt->x - q->ctr.x) + q->mat.b*(pnt->y - q->ctr.y) + q->mat.c*(pnt->z - q->ctr.z) + q->mat.d); N->y = (q->mat.b*(pnt->x - q->ctr.x) + q->mat.e*(pnt->y - q->ctr.y) + q->mat.f*(pnt->z - q->ctr.z) + q->mat.g); N->z = (q->mat.c*(pnt->x - q->ctr.x) + q->mat.f*(pnt->y - q->ctr.y) + q->mat.h*(pnt->z - q->ctr.z) + q->mat.i); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/parse.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * parse.cpp - an UltraLame (tm) parser for simple data files... */ // Try preventing lots of GCC warnings about ignored results of fscanf etc. #if !__INTEL_COMPILER #if __GNUC__<4 || __GNUC__==4 && __GNUC_MINOR__<5 // For older versions of GCC, disable use of __wur in GLIBC #undef _FORTIFY_SOURCE #define _FORTIFY_SOURCE 0 #else // Starting from 4.5, GCC has a suppression option #pragma GCC diagnostic ignored "-Wunused-result" #endif #endif //__INTEL_COMPILER #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <ctype.h> /* needed for toupper(), macro.. */ #include "types.h" #include "api.h" /* rendering API */ #define PARSE_INTERNAL #include "parse.h" /* self protos */ #undef PARSE_INTERNAL static texentry textable[NUMTEXS]; /* texture lookup table */ static texentry defaulttex; /* The default texture when a lookup fails */ static int numtextures; /* number of TEXDEF textures */ static int numobjectsparsed; /* total number of objects parsed so far */ static color scenebackcol; /* scene background color */ static int stringcmp(const char * a, const char * b) { size_t i, s, l; s=strlen(a); l=strlen(b); if (s != l) return 1; for (i=0; i<s; i++) { if (toupper(a[i]) != toupper(b[i])) { return 1; } } return 0; } static void reset_tex_table(void) { apitexture apitex; numtextures=0; memset(&textable, 0, sizeof(textable)); apitex.col.r=1.0; apitex.col.g=1.0; apitex.col.b=1.0; apitex.ambient=0.1; apitex.diffuse=0.9; apitex.specular=0.0; apitex.opacity=1.0; apitex.texturefunc=0; defaulttex.tex=rt_texture(&apitex); } static errcode add_texture(void * tex, char name[TEXNAMELEN]) { textable[numtextures].tex=tex; strcpy(textable[numtextures].name, name); numtextures++; if (numtextures > NUMTEXS) { fprintf(stderr, "Parse: %d textures allocated, texture slots full!\n", numtextures); numtextures--; /* keep writing over last texture if we've run out.. */ return PARSEALLOCERR; } return PARSENOERR; } static void * find_texture(char name[TEXNAMELEN]) { int i; for (i=0; i<numtextures; i++) { if (strcmp(name, textable[i].name) == 0) return textable[i].tex; } fprintf(stderr, "Undefined texture '%s', using default. \n",name); return(defaulttex.tex); } apiflt degtorad(apiflt deg) { apiflt tmp; tmp=deg * 3.1415926 / 180.0; return tmp; } static void degvectoradvec(vector * degvec) { vector tmp; tmp.x=degtorad(degvec->x); tmp.y=degtorad(degvec->y); tmp.z=degtorad(degvec->z); *degvec=tmp; } static void InitRot3d(RotMat * rot, apiflt x, apiflt y, apiflt z) { rot->rx1=cos(y)*cos(z); rot->rx2=sin(x)*sin(y)*cos(z) - cos(x)*sin(z); rot->rx3=sin(x)*sin(z) + cos(x)*cos(z)*sin(y); rot->ry1=cos(y)*sin(z); rot->ry2=cos(x)*cos(z) + sin(x)*sin(y)*sin(z); rot->ry3=cos(x)*sin(y)*sin(z) - sin(x)*cos(z); rot->rz1=sin(y); rot->rz2=sin(x)*cos(y); rot->rz3=cos(x)*cos(y); } static void Rotate3d(RotMat * rot, vector * vec) { vector tmp; tmp.x=(vec->x*(rot->rx1) + vec->y*(rot->rx2) + vec->z*(rot->rx3)); tmp.y=(vec->x*(rot->ry1) + vec->y*(rot->ry2) + vec->z*(rot->ry3)); tmp.z=(vec->x*(rot->rz1) + vec->y*(rot->rz2) + vec->z*(rot->rz3)); *vec=tmp; } static void Scale3d(vector * scale, vector * vec) { vec->x=vec->x * scale->x; vec->y=vec->y * scale->y; vec->z=vec->z * scale->z; } static void Trans3d(vector * trans, vector * vec) { vec->x+=trans->x; vec->y+=trans->y; vec->z+=trans->z; } static errcode GetString(FILE * dfile, const char * string) { char data[255]; fscanf(dfile,"%s",data); if (stringcmp(data, string) != 0) { fprintf(stderr, "parse: Expected %s, got %s \n",string, data); fprintf(stderr, "parse: Error while parsing object: %d \n",numobjectsparsed); return PARSEBADSYNTAX; } return PARSENOERR; } unsigned int readmodel(char * modelfile, SceneHandle scene) { FILE * dfile; errcode rc; reset_tex_table(); dfile=NULL; dfile=fopen(modelfile,"r"); if (dfile==NULL) { return PARSEBADFILE; } rc = GetScenedefs(dfile, scene); if (rc != PARSENOERR) return rc; scenebackcol.r = 0.0; /* default background is black */ scenebackcol.g = 0.0; scenebackcol.b = 0.0; numobjectsparsed=0; while ((rc = GetObject(dfile, scene)) == PARSENOERR) { numobjectsparsed++; } fclose(dfile); if (rc == PARSEEOF) rc = PARSENOERR; rt_background(scene, scenebackcol); return rc; } static errcode GetScenedefs(FILE * dfile, SceneHandle scene) { vector Ccenter, Cview, Cup; apiflt zoom, aspectratio; int raydepth, antialiasing; char outfilename[200]; int xres, yres, verbose; float a,b,c; errcode rc = PARSENOERR; rc |= GetString(dfile, "BEGIN_SCENE"); rc |= GetString(dfile, "OUTFILE"); fscanf(dfile, "%s", outfilename); #ifdef _WIN32 if (strcmp (outfilename, "/dev/null") == 0) { strcpy (outfilename, "NUL:"); } #endif rc |= GetString(dfile, "RESOLUTION"); fscanf(dfile, "%d %d", &xres, &yres); rc |= GetString(dfile, "VERBOSE"); fscanf(dfile, "%d", &verbose); rt_scenesetup(scene, outfilename, xres, yres, verbose); rc |= GetString(dfile, "CAMERA"); rc |= GetString(dfile, "ZOOM"); fscanf(dfile, "%f", &a); zoom=a; rc |= GetString(dfile, "ASPECTRATIO"); fscanf(dfile, "%f", &b); aspectratio=b; rc |= GetString(dfile, "ANTIALIASING"); fscanf(dfile, "%d", &antialiasing); rc |= GetString(dfile, "RAYDEPTH"); fscanf(dfile, "%d", &raydepth); rc |= GetString(dfile, "CENTER"); fscanf(dfile,"%f %f %f", &a, &b, &c); Ccenter.x = a; Ccenter.y = b; Ccenter.z = c; rc |= GetString(dfile, "VIEWDIR"); fscanf(dfile,"%f %f %f", &a, &b, &c); Cview.x = a; Cview.y = b; Cview.z = c; rc |= GetString(dfile, "UPDIR"); fscanf(dfile,"%f %f %f", &a, &b, &c); Cup.x = a; Cup.y = b; Cup.z = c; rc |= GetString(dfile, "END_CAMERA"); rt_camerasetup(scene, zoom, aspectratio, antialiasing, raydepth, Ccenter, Cview, Cup); return rc; } static errcode GetObject(FILE * dfile, SceneHandle scene) { char objtype[80]; fscanf(dfile, "%s", objtype); if (!stringcmp(objtype, "END_SCENE")) { return PARSEEOF; /* end parsing */ } if (!stringcmp(objtype, "TEXDEF")) { return GetTexDef(dfile); } if (!stringcmp(objtype, "TEXALIAS")) { return GetTexAlias(dfile); } if (!stringcmp(objtype, "BACKGROUND")) { return GetBackGnd(dfile); } if (!stringcmp(objtype, "CYLINDER")) { return GetCylinder(dfile); } if (!stringcmp(objtype, "FCYLINDER")) { return GetFCylinder(dfile); } if (!stringcmp(objtype, "POLYCYLINDER")) { return GetPolyCylinder(dfile); } if (!stringcmp(objtype, "SPHERE")) { return GetSphere(dfile); } if (!stringcmp(objtype, "PLANE")) { return GetPlane(dfile); } if (!stringcmp(objtype, "RING")) { return GetRing(dfile); } if (!stringcmp(objtype, "BOX")) { return GetBox(dfile); } if (!stringcmp(objtype, "SCALARVOL")) { return GetVol(dfile); } if (!stringcmp(objtype, "TRI")) { return GetTri(dfile); } if (!stringcmp(objtype, "STRI")) { return GetSTri(dfile); } if (!stringcmp(objtype, "LIGHT")) { return GetLight(dfile); } if (!stringcmp(objtype, "SCAPE")) { return GetLandScape(dfile); } if (!stringcmp(objtype, "TPOLYFILE")) { return GetTPolyFile(dfile); } fprintf(stderr, "Found bad token: %s expected an object type\n", objtype); return PARSEBADSYNTAX; } static errcode GetVector(FILE * dfile, vector * v1) { float a, b, c; fscanf(dfile, "%f %f %f", &a, &b, &c); v1->x=a; v1->y=b; v1->z=c; return PARSENOERR; } static errcode GetColor(FILE * dfile, color * c1) { float r, g, b; int rc; rc = GetString(dfile, "COLOR"); fscanf(dfile, "%f %f %f", &r, &g, &b); c1->r=r; c1->g=g; c1->b=b; return rc; } static errcode GetTexDef(FILE * dfile) { char texname[TEXNAMELEN]; fscanf(dfile, "%s", texname); add_texture(GetTexBody(dfile), texname); return PARSENOERR; } static errcode GetTexAlias(FILE * dfile) { char texname[TEXNAMELEN]; char aliasname[TEXNAMELEN]; fscanf(dfile, "%s", texname); fscanf(dfile, "%s", aliasname); add_texture(find_texture(aliasname), texname); return PARSENOERR; } static errcode GetTexture(FILE * dfile, void ** tex) { char tmp[255]; errcode rc = PARSENOERR; fscanf(dfile, "%s", tmp); if (!stringcmp("TEXTURE", tmp)) { *tex = GetTexBody(dfile); } else *tex = find_texture(tmp); return rc; } void * GetTexBody(FILE * dfile) { char tmp[255]; float a,b,c,d, phong, phongexp, phongtype; apitexture tex; void * voidtex; errcode rc; rc = GetString(dfile, "AMBIENT"); fscanf(dfile, "%f", &a); tex.ambient=a; rc |= GetString(dfile, "DIFFUSE"); fscanf(dfile, "%f", &b); tex.diffuse=b; rc |= GetString(dfile, "SPECULAR"); fscanf(dfile, "%f", &c); tex.specular=c; rc |= GetString(dfile, "OPACITY"); fscanf(dfile, "%f", &d); tex.opacity=d; fscanf(dfile, "%s", tmp); if (!stringcmp("PHONG", tmp)) { fscanf(dfile, "%s", tmp); if (!stringcmp("METAL", tmp)) { phongtype = RT_PHONG_METAL; } else if (!stringcmp("PLASTIC", tmp)) { phongtype = RT_PHONG_PLASTIC; } else { phongtype = RT_PHONG_PLASTIC; } fscanf(dfile, "%f", &phong); GetString(dfile, "PHONG_SIZE"); fscanf(dfile, "%f", &phongexp); fscanf(dfile, "%s", tmp); } else { phong = 0.0; phongexp = 100.0; phongtype = RT_PHONG_PLASTIC; } fscanf(dfile, "%f %f %f", &a, &b, &c); tex.col.r = a; tex.col.g = b; tex.col.b = c; rc |= GetString(dfile, "TEXFUNC"); fscanf(dfile, "%d", &tex.texturefunc); if (tex.texturefunc >= 7) { /* if its an image map, we need a filename */ fscanf(dfile, "%s", tex.imap); } if (tex.texturefunc != 0) { rc |= GetString(dfile, "CENTER"); rc |= GetVector(dfile, &tex.ctr); rc |= GetString(dfile, "ROTATE"); rc |= GetVector(dfile, &tex.rot); rc |= GetString(dfile, "SCALE"); rc |= GetVector(dfile, &tex.scale); } if (tex.texturefunc == 9) { rc |= GetString(dfile, "UAXIS"); rc |= GetVector(dfile, &tex.uaxs); rc |= GetString(dfile, "VAXIS"); rc |= GetVector(dfile, &tex.vaxs); } voidtex = rt_texture(&tex); rt_tex_phong(voidtex, phong, phongexp, (int) phongtype); return voidtex; } static errcode GetLight(FILE * dfile) { apiflt rad; vector ctr; apitexture tex; float a; errcode rc; memset(&tex, 0, sizeof(apitexture)); rc = GetString(dfile,"CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile,"RAD"); fscanf(dfile,"%f",&a); /* read in radius */ rad=a; rc |= GetColor(dfile, &tex.col); rt_light(rt_texture(&tex), ctr, rad); return rc; } static errcode GetBackGnd(FILE * dfile) { float r,g,b; fscanf(dfile, "%f %f %f", &r, &g, &b); scenebackcol.r=r; scenebackcol.g=g; scenebackcol.b=b; return PARSENOERR; } static errcode GetCylinder(FILE * dfile) { apiflt rad; vector ctr, axis; void * tex; float a; errcode rc; rc = GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "AXIS"); rc |= GetVector(dfile, &axis); rc |= GetString(dfile, "RAD"); fscanf(dfile, "%f", &a); rad=a; rc |= GetTexture(dfile, &tex); rt_cylinder(tex, ctr, axis, rad); return rc; } static errcode GetFCylinder(FILE * dfile) { apiflt rad; vector ctr, axis; vector pnt1, pnt2; void * tex; float a; errcode rc; rc = GetString(dfile, "BASE"); rc |= GetVector(dfile, &pnt1); rc |= GetString(dfile, "APEX"); rc |= GetVector(dfile, &pnt2); ctr=pnt1; axis.x=pnt2.x - pnt1.x; axis.y=pnt2.y - pnt1.y; axis.z=pnt2.z - pnt1.z; rc |= GetString(dfile, "RAD"); fscanf(dfile, "%f", &a); rad=a; rc |= GetTexture(dfile, &tex); rt_fcylinder(tex, ctr, axis, rad); return rc; } static errcode GetPolyCylinder(FILE * dfile) { apiflt rad; vector * temp; void * tex; float a; int numpts, i; errcode rc; rc = GetString(dfile, "POINTS"); fscanf(dfile, "%d", &numpts); temp = (vector *) malloc(numpts * sizeof(vector)); for (i=0; i<numpts; i++) { rc |= GetVector(dfile, &temp[i]); } rc |= GetString(dfile, "RAD"); fscanf(dfile, "%f", &a); rad=a; rc |= GetTexture(dfile, &tex); rt_polycylinder(tex, temp, numpts, rad); free(temp); return rc; } static errcode GetSphere(FILE * dfile) { apiflt rad; vector ctr; void * tex; float a; errcode rc; rc = GetString(dfile,"CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "RAD"); fscanf(dfile,"%f",&a); rad=a; rc |= GetTexture(dfile, &tex); rt_sphere(tex, ctr, rad); return rc; } static errcode GetPlane(FILE * dfile) { vector normal; vector ctr; void * tex; errcode rc; rc = GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "NORMAL"); rc |= GetVector(dfile, &normal); rc |= GetTexture(dfile, &tex); rt_plane(tex, ctr, normal); return rc; } static errcode GetVol(FILE * dfile) { vector min, max; int x,y,z; char fname[255]; void * tex; errcode rc; rc = GetString(dfile, "MIN"); rc |= GetVector(dfile, &min); rc |= GetString(dfile, "MAX"); rc |= GetVector(dfile, &max); rc |= GetString(dfile, "DIM"); fscanf(dfile, "%d %d %d ", &x, &y, &z); rc |= GetString(dfile, "FILE"); fscanf(dfile, "%s", fname); rc |= GetTexture(dfile, &tex); rt_scalarvol(tex, min, max, x, y, z, fname, NULL); return rc; } static errcode GetBox(FILE * dfile) { vector min, max; void * tex; errcode rc; rc = GetString(dfile, "MIN"); rc |= GetVector(dfile, &min); rc |= GetString(dfile, "MAX"); rc |= GetVector(dfile, &max); rc |= GetTexture(dfile, &tex); rt_box(tex, min, max); return rc; } static errcode GetRing(FILE * dfile) { vector normal; vector ctr; void * tex; float a,b; errcode rc; rc = GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "NORMAL"); rc |= GetVector(dfile, &normal); rc |= GetString(dfile, "INNER"); fscanf(dfile, " %f ", &a); rc |= GetString(dfile, "OUTER"); fscanf(dfile, " %f ", &b); rc |= GetTexture(dfile, &tex); rt_ring(tex, ctr, normal, a, b); return rc; } static errcode GetTri(FILE * dfile) { vector v0,v1,v2; void * tex; errcode rc; rc = GetString(dfile, "V0"); rc |= GetVector(dfile, &v0); rc |= GetString(dfile, "V1"); rc |= GetVector(dfile, &v1); rc |= GetString(dfile, "V2"); rc |= GetVector(dfile, &v2); rc |= GetTexture(dfile, &tex); rt_tri(tex, v0, v1, v2); return rc; } static errcode GetSTri(FILE * dfile) { vector v0,v1,v2,n0,n1,n2; void * tex; errcode rc; rc = GetString(dfile, "V0"); rc |= GetVector(dfile, &v0); rc |= GetString(dfile, "V1"); rc |= GetVector(dfile, &v1); rc |= GetString(dfile, "V2"); rc |= GetVector(dfile, &v2); rc |= GetString(dfile, "N0"); rc |= GetVector(dfile, &n0); rc |= GetString(dfile, "N1"); rc |= GetVector(dfile, &n1); rc |= GetString(dfile, "N2"); rc |= GetVector(dfile, &n2); rc |= GetTexture(dfile, &tex); rt_stri(tex, v0, v1, v2, n0, n1, n2); return rc; } static errcode GetLandScape(FILE * dfile) { void * tex; vector ctr; apiflt wx, wy; int m, n; float a,b; errcode rc; rc = GetString(dfile, "RES"); fscanf(dfile, "%d %d", &m, &n); rc |= GetString(dfile, "SCALE"); fscanf(dfile, "%f %f", &a, &b); wx=a; wy=b; rc |= GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetTexture(dfile, &tex); rt_landscape(tex, m, n, ctr, wx, wy); return rc; } static errcode GetTPolyFile(FILE * dfile) { void * tex; vector ctr, rot, scale; vector v1, v2, v0; char ifname[255]; FILE *ifp; int v, totalpolys; RotMat RotA; errcode rc; totalpolys=0; rc = GetString(dfile, "SCALE"); rc |= GetVector(dfile, &scale); rc |= GetString(dfile, "ROT"); rc |= GetVector(dfile, &rot); degvectoradvec(&rot); InitRot3d(&RotA, rot.x, rot.y, rot.z); rc |= GetString(dfile, "CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile, "FILE"); fscanf(dfile, "%s", ifname); rc |= GetTexture(dfile, &tex); if ((ifp=fopen(ifname, "r")) == NULL) { fprintf(stderr, "Can't open data file %s for input!! Aborting...\n", ifname); return PARSEBADSUBFILE; } while (!feof(ifp)) { fscanf(ifp, "%d", &v); if (v != 3) { break; } totalpolys++; v=0; rc |= GetVector(ifp, &v0); rc |= GetVector(ifp, &v1); rc |= GetVector(ifp, &v2); Scale3d(&scale, &v0); Scale3d(&scale, &v1); Scale3d(&scale, &v2); Rotate3d(&RotA, &v0); Rotate3d(&RotA, &v1); Rotate3d(&RotA, &v2); Trans3d(&ctr, &v0); Trans3d(&ctr, &v1); Trans3d(&ctr, &v2); rt_tri(tex, v1, v0, v2); } fclose(ifp); return rc; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/sphere.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sphere.cpp - This file contains the functions for dealing with spheres. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define SPHERE_PRIVATE #include "sphere.h" static object_methods sphere_methods = { (void (*)(void *, void *))(sphere_intersect), (void (*)(void *, void *, void *, void *))(sphere_normal), sphere_bbox, free }; object * newsphere(void * tex, vector ctr, flt rad) { sphere * s; s=(sphere *) rt_getmem(sizeof(sphere)); memset(s, 0, sizeof(sphere)); s->methods = &sphere_methods; s->tex=(texture *)tex; s->ctr=ctr; s->rad=rad; return (object *) s; } static int sphere_bbox(void * obj, vector * min, vector * max) { sphere * s = (sphere *) obj; min->x = s->ctr.x - s->rad; min->y = s->ctr.y - s->rad; min->z = s->ctr.z - s->rad; max->x = s->ctr.x + s->rad; max->y = s->ctr.y + s->rad; max->z = s->ctr.z + s->rad; return 1; } static void sphere_intersect(sphere * spr, ray * ry) { flt b, disc, t1, t2, temp; vector V; VSUB(spr->ctr, ry->o, V); VDOT(b, V, ry->d); VDOT(temp, V, V); disc=b*b + spr->rad*spr->rad - temp; if (disc<=0.0) return; disc=sqrt(disc); t2=b+disc; if (t2 <= SPEPSILON) return; add_intersection(t2, (object *) spr, ry); t1=b-disc; if (t1 > SPEPSILON) add_intersection(t1, (object *) spr, ry); } static void sphere_normal(sphere * spr, vector * pnt, ray * incident, vector * N) { VSub((vector *) pnt, &(spr->ctr), N); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { N->x=-N->x; N->y=-N->y; N->z=-N->z; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/util.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * util.cpp - Contains all of the timing functions for various platforms. */ #include "machine.h" #include "types.h" #include "macros.h" #include "util.h" #include "light.h" #include "global.h" #include "ui.h" void rt_finalize(void); #if !defined( _WIN32 ) #include <sys/time.h> #include <unistd.h> void rt_sleep(int msec) { usleep(msec*1000); } #else //_WIN32 #undef OLDUNIXTIME #undef STDTIME void rt_sleep(int msec) { #if !WIN8UI_EXAMPLE Sleep(msec); #else std::chrono::milliseconds sleep_time( msec ); std::this_thread::sleep_for( sleep_time ); #endif } timer gettimer(void) { return GetTickCount (); } flt timertime(timer st, timer fn) { double ttime, start, end; start = ((double) st) / ((double) 1000.00); end = ((double) fn) / ((double) 1000.00); ttime = end - start; return ttime; } #endif /* _WIN32 */ /* if we're on a Unix with gettimeofday() we'll use newer timers */ #if defined( STDTIME ) struct timezone tz; timer gettimer(void) { timer t; gettimeofday(&t, &tz); return t; } flt timertime(timer st, timer fn) { double ttime, start, end; start = (st.tv_sec+1.0*st.tv_usec / 1000000.0); end = (fn.tv_sec+1.0*fn.tv_usec / 1000000.0); ttime = end - start; return ttime; } #endif /* STDTIME */ /* use the old fashioned Unix time functions */ #if defined( OLDUNIXTIME ) timer gettimer(void) { return time(NULL); } flt timertime(timer st, timer fn) { return difftime(fn, st);; } #endif /* OLDUNIXTIME */ /* random other helper utility functions */ int rt_meminuse(void) { return rt_mem_in_use; } void * rt_getmem(unsigned int bytes) { void * mem; mem=malloc( bytes ); if (mem!=NULL) { rt_mem_in_use += bytes; } else { rtbomb("No more memory!!!!"); } return mem; } unsigned int rt_freemem(void * addr) { unsigned int bytes; free(addr); bytes=0; rt_mem_in_use -= bytes; return bytes; } void rtbomb(const char * msg) { rt_ui_message(MSG_ERR, msg); rt_ui_message(MSG_ABORT, "Rendering Aborted."); rt_finalize(); exit(1); } void rtmesg(const char * msg) { rt_ui_message(MSG_0, msg); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/texture.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * texture.cpp - This file contains functions for implementing textures. */ #include "machine.h" #include "types.h" #include "macros.h" #include "texture.h" #include "coordsys.h" #include "imap.h" #include "vector.h" #include "box.h" /* plain vanilla texture solely based on object color */ color standard_texture(vector * hit, texture * tex, ray * ry) { return tex->col; } /* cylindrical image map */ color image_cyl_texture(vector * hit, texture * tex, ray * ry) { vector rh; flt u,v; rh.x=hit->x - tex->ctr.x; rh.z=hit->y - tex->ctr.y; rh.y=hit->z - tex->ctr.z; xyztocyl(rh, 1.0, &u, &v); u = u * tex->scale.x; u = u + tex->rot.x; u=fmod(u, 1.0); if (u < 0.0) u+=1.0; v = v * tex->scale.y; v = v + tex->rot.y; v=fmod(v, 1.0); if (v < 0.0) v+=1.0; return ImageMap((rawimage *)tex->img, u, v); } /* spherical image map */ color image_sphere_texture(vector * hit, texture * tex, ray * ry) { vector rh; flt u,v; rh.x=hit->x - tex->ctr.x; rh.y=hit->y - tex->ctr.y; rh.z=hit->z - tex->ctr.z; xyztospr(rh, &u, &v); u = u * tex->scale.x; u = u + tex->rot.x; u=fmod(u, 1.0); if (u < 0.0) u+=1.0; v = v * tex->scale.y; v = v + tex->rot.y; v=fmod(v, 1.0); if (v < 0.0) v+=1.0; return ImageMap((rawimage *)tex->img, u, v); } /* planar image map */ color image_plane_texture(vector * hit, texture * tex, ray * ry) { vector pnt; flt u,v; pnt.x=hit->x - tex->ctr.x; pnt.y=hit->y - tex->ctr.y; pnt.z=hit->z - tex->ctr.z; VDOT(u, tex->uaxs, pnt); /* VDOT(len, tex->uaxs, tex->uaxs); u = u / sqrt(len); */ VDOT(v, tex->vaxs, pnt); /* VDOT(len, tex->vaxs, tex->vaxs); v = v / sqrt(len); */ u = u * tex->scale.x; u = u + tex->rot.x; u = fmod(u, 1.0); if (u < 0.0) u += 1.0; v = v * tex->scale.y; v = v + tex->rot.y; v = fmod(v, 1.0); if (v < 0.0) v += 1.0; return ImageMap((rawimage *)tex->img, u, v); } color grit_texture(vector * hit, texture * tex, ray * ry) { int rnum; flt fnum; color col; rnum=rand() % 4096; fnum=(rnum / 4096.0 * 0.2) + 0.8; col.r=tex->col.r * fnum; col.g=tex->col.g * fnum; col.b=tex->col.b * fnum; return col; } color checker_texture(vector * hit, texture * tex, ray * ry) { long x,y,z; flt xh,yh,zh; color col; xh=hit->x - tex->ctr.x; x=(long) ((fabs(xh) * 3) + 0.5); x=x % 2; yh=hit->y - tex->ctr.y; y=(long) ((fabs(yh) * 3) + 0.5); y=y % 2; zh=hit->z - tex->ctr.z; z=(long) ((fabs(zh) * 3) + 0.5); z=z % 2; if (((x + y + z) % 2)==1) { col.r=1.0; col.g=0.2; col.b=0.0; } else { col.r=0.0; col.g=0.2; col.b=1.0; } return col; } color cyl_checker_texture(vector * hit, texture * tex, ray * ry) { long x,y; vector rh; flt u,v; color col; rh.x=hit->x - tex->ctr.x; rh.y=hit->y - tex->ctr.y; rh.z=hit->z - tex->ctr.z; xyztocyl(rh, 1.0, &u, &v); x=(long) (fabs(u) * 18.0); x=x % 2; y=(long) (fabs(v) * 10.0); y=y % 2; if (((x + y) % 2)==1) { col.r=1.0; col.g=0.2; col.b=0.0; } else { col.r=0.0; col.g=0.2; col.b=1.0; } return col; } color wood_texture(vector * hit, texture * tex, ray * ry) { flt radius, angle; int grain; color col; flt x,y,z; x=(hit->x - tex->ctr.x) * 1000; y=(hit->y - tex->ctr.y) * 1000; z=(hit->z - tex->ctr.z) * 1000; radius=sqrt(x*x + z*z); if (z == 0.0) angle=3.1415926/2.0; else angle=atan(x / z); radius=radius + 3.0 * sin(20 * angle + y / 150.0); grain=((int) (radius + 0.5)) % 60; if (grain < 40) { col.r=0.8; col.g=1.0; col.b=0.2; } else { col.r=0.0; col.g=0.0; col.b=0.0; } return col; } #define NMAX 28 short int NoiseMatrix[NMAX][NMAX][NMAX]; void InitNoise(void) { unsigned char x,y,z,i,j,k; for (x=0; x<NMAX; x++) { for (y=0; y<NMAX; y++) { for (z=0; z<NMAX; z++) { NoiseMatrix[x][y][z]=rand() % 12000; if (x==NMAX-1) i=0; else i=x; if (y==NMAX-1) j=0; else j=y; if (z==NMAX-1) k=0; else k=z; NoiseMatrix[x][y][z]=NoiseMatrix[i][j][k]; } } } } int Noise(flt x, flt y, flt z) { unsigned char ix, iy, iz; flt ox, oy, oz; int p000, p001, p010, p011; int p100, p101, p110, p111; int p00, p01, p10, p11; int p0, p1; int d00, d01, d10, d11; int d0, d1, d; x=fabs(x); y=fabs(y); z=fabs(z); ix=((int) x) % (NMAX-1); iy=((int) y) % (NMAX-1); iz=((int) z) % (NMAX-1); ox=(x - ((int) x)); oy=(y - ((int) y)); oz=(z - ((int) z)); p000=NoiseMatrix[ix][iy][iz]; p001=NoiseMatrix[ix][iy][iz+1]; p010=NoiseMatrix[ix][iy+1][iz]; p011=NoiseMatrix[ix][iy+1][iz+1]; p100=NoiseMatrix[ix+1][iy][iz]; p101=NoiseMatrix[ix+1][iy][iz+1]; p110=NoiseMatrix[ix+1][iy+1][iz]; p111=NoiseMatrix[ix+1][iy+1][iz+1]; d00=p100-p000; d01=p101-p001; d10=p110-p010; d11=p111-p011; p00=(int) ((int) d00*ox) + p000; p01=(int) ((int) d01*ox) + p001; p10=(int) ((int) d10*ox) + p010; p11=(int) ((int) d11*ox) + p011; d0=p10-p00; d1=p11-p01; p0=(int) ((int) d0*oy) + p00; p1=(int) ((int) d1*oy) + p01; d=p1-p0; return (int) ((int) d*oz) + p0; } color marble_texture(vector * hit, texture * tex, ray * ry) { flt i,d; flt x,y,z; color col; x=hit->x; y=hit->y; z=hit->z; x=x * 1.0; d=x + 0.0006 * Noise(x, (y * 1.0), (z * 1.0)); d=d*(((int) d) % 25); i=0.0 + 0.10 * fabs(d - 10.0 - 20.0 * ((int) d * 0.05)); if (i > 1.0) i=1.0; if (i < 0.0) i=0.0; /* col.r=i * tex->col.r; col.g=i * tex->col.g; col.b=i * tex->col.b; */ col.r = (1.0 + sin(i * 6.28)) / 2.0; col.g = (1.0 + sin(i * 16.28)) / 2.0; col.b = (1.0 + cos(i * 30.28)) / 2.0; return col; } color gnoise_texture(vector * hit, texture * tex, ray * ry) { color col; flt f; f=Noise((hit->x - tex->ctr.x), (hit->y - tex->ctr.y), (hit->z - tex->ctr.z)); if (f < 0.01) f=0.01; if (f > 1.0) f=1.0; col.r=tex->col.r * f; col.g=tex->col.g * f; col.b=tex->col.b * f; return col; } void InitTextures(void) { InitNoise(); ResetImages(); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/ui.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ui.cpp - Contains functions for dealing with user interfaces */ #include "machine.h" #include "types.h" #include "macros.h" #include "util.h" #include "ui.h" static void (* rt_static_ui_message) (int, const char *) = NULL; static void (* rt_static_ui_progress) (int) = NULL; static int (* rt_static_ui_checkaction) (void) = NULL; extern bool silent_mode; void set_rt_ui_message(void (* func) (int, const char *)) { rt_static_ui_message = func; } void set_rt_ui_progress(void (* func) (int)) { rt_static_ui_progress = func; } void rt_ui_message(int level, const char * msg) { if (rt_static_ui_message == NULL) { if ( !silent_mode ) { fprintf(stderr, "%s\n", msg); fflush (stderr); } } else { rt_static_ui_message(level, msg); } } void rt_ui_progress(int percent) { if (rt_static_ui_progress != NULL) rt_static_ui_progress(percent); else { if ( !silent_mode ) { fprintf(stderr, "\r %3d%% Complete \r", percent); fflush(stderr); } } } int rt_ui_checkaction(void) { if (rt_static_ui_checkaction != NULL) return rt_static_ui_checkaction(); else return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/vector.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vector.cpp - This file contains all of the vector arithmetic functions. */ #include "machine.h" #include "types.h" #include "macros.h" flt VDot(vector *a, vector *b) { return (a->x*b->x + a->y*b->y + a->z*b->z); } void VCross(vector * a, vector * b, vector * c) { c->x = (a->y * b->z) - (a->z * b->y); c->y = (a->z * b->x) - (a->x * b->z); c->z = (a->x * b->y) - (a->y * b->x); } flt VLength(vector * a) { return (flt) sqrt((a->x * a->x) + (a->y * a->y) + (a->z * a->z)); } void VNorm(vector * a) { flt len; len=sqrt((a->x * a->x) + (a->y * a->y) + (a->z * a->z)); if (len != 0.0) { a->x /= len; a->y /= len; a->z /= len; } } void VAdd(vector * a, vector * b, vector * c) { c->x = (a->x + b->x); c->y = (a->y + b->y); c->z = (a->z + b->z); } void VSub(vector * a, vector * b, vector * c) { c->x = (a->x - b->x); c->y = (a->y - b->y); c->z = (a->z - b->z); } void VAddS(flt a, vector * A, vector * B, vector * C) { C->x = (a * A->x) + B->x; C->y = (a * A->y) + B->y; C->z = (a * A->z) + B->z; } vector Raypnt(ray * a, flt t) { vector temp; temp.x=a->o.x + (a->d.x * t); temp.y=a->o.y + (a->d.y * t); temp.z=a->o.z + (a->d.z * t); return temp; } void VScale(vector * a, flt s) { a->x *= s; a->y *= s; a->z *= s; } void ColorAddS(color * a, color * b, flt s) { a->r += b->r * s; a->g += b->g * s; a->b += b->b * s; } void ColorAccum(color * a, color * b) { a->r += b->r; a->g += b->g; a->b += b->b; } void ColorScale(color * a, flt s) { a->r *= s; a->g *= s; a->b *= s; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/vol.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vol.cpp - Volume rendering helper routines etc. */ #include <stdio.h> #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "util.h" #include "vol.h" #include "box.h" #include "trace.h" #include "ui.h" #include "light.h" #include "shade.h" int scalarvol_bbox(void * obj, vector * min, vector * max) { box * b = (box *) obj; *min = b->min; *max = b->max; return 1; } void * newscalarvol(void * intex, vector min, vector max, int xs, int ys, int zs, char * fname, scalarvol * invol) { box * bx; texture * tx, * tex; scalarvol * vol; tex=(texture *)intex; tex->shadowcast = 0; /* doesn't cast a shadow */ tx=(texture *)rt_getmem(sizeof(texture)); /* is the volume data already loaded? */ if (invol==NULL) { vol=(scalarvol *)rt_getmem(sizeof(scalarvol)); vol->loaded=0; vol->data=NULL; } else vol=invol; vol->opacity=tex->opacity; vol->xres=xs; vol->yres=ys; vol->zres=zs; strcpy(vol->name, fname); tx->ctr.x = 0.0; tx->ctr.y = 0.0; tx->ctr.z = 0.0; tx->rot = tx->ctr; tx->scale = tx->ctr; tx->uaxs = tx->ctr; tx->vaxs = tx->ctr; tx->islight = 0; tx->shadowcast = 0; /* doesn't cast a shadow */ tx->col = tex->col; tx->ambient = 1.0; tx->diffuse = 0.0; tx->specular = 0.0; tx->opacity = 1.0; tx->img = vol; tx->texfunc = (color(*)(void *, void *, void *))(scalar_volume_texture); bx=newbox(tx, min, max); tx->obj = (void *) bx; /* XXX hack! */ return (void *) bx; } color VoxelColor(flt scalar) { color col; if (scalar > 1.0) scalar = 1.0; if (scalar < 0.0) scalar = 0.0; if (scalar < 0.25) { col.r = scalar * 4.0; col.g = 0.0; col.b = 0.0; } else { if (scalar < 0.75) { col.r = 1.0; col.g = (scalar - 0.25) * 2.0; col.b = 0.0; } else { col.r = 1.0; col.g = 1.0; col.b = (scalar - 0.75) * 4.0; } } return col; } color scalar_volume_texture(vector * hit, texture * tex, ray * ry) { color col, col2; box * bx; flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; flt t, tdist, dt, sum, tt; vector pnt, bln; scalarvol * vol; flt scalar, transval; int x, y, z; unsigned char * ptr; bx=(box *) tex->obj; vol=(scalarvol *)bx->tex->img; col.r=0.0; col.g=0.0; col.b=0.0; tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return col; } else { tx1 = (bx->min.x - ry->o.x) / ry->d.x; tx2 = (bx->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (ry->d.y == 0.0) { if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return col; } else { ty1 = (bx->min.y - ry->o.y) / ry->d.y; ty2 = (bx->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (ry->d.z == 0.0) { if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return col; } else { tz1 = (bx->min.z - ry->o.z) / ry->d.z; tz2 = (bx->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return col; if (tfar < 0.0) return col; if (tnear < 0.0) tnear=0.0; tdist=sqrt((flt) (vol->xres*vol->xres + vol->yres*vol->yres + vol->zres*vol->zres)); tt = (vol->opacity / tdist); bln.x=fabs(bx->min.x - bx->max.x); bln.y=fabs(bx->min.y - bx->max.y); bln.z=fabs(bx->min.z - bx->max.z); dt=sqrt(bln.x*bln.x + bln.y*bln.y + bln.z*bln.z) / tdist; sum=0.0; /* move the volume residency check out of loop.. */ if (!vol->loaded) { LoadVol(vol); vol->loaded=1; } for (t=tnear; t<=tfar; t+=dt) { pnt.x=((ry->o.x + (ry->d.x * t)) - bx->min.x) / bln.x; pnt.y=((ry->o.y + (ry->d.y * t)) - bx->min.y) / bln.y; pnt.z=((ry->o.z + (ry->d.z * t)) - bx->min.z) / bln.z; x=(int) ((vol->xres - 1.5) * pnt.x + 0.5); y=(int) ((vol->yres - 1.5) * pnt.y + 0.5); z=(int) ((vol->zres - 1.5) * pnt.z + 0.5); ptr = vol->data + ((vol->xres * vol->yres * z) + (vol->xres * y) + x); scalar = (flt) ((flt) 1.0 * ((int) ptr[0])) / 255.0; sum += tt * scalar; transval = tt * scalar; col2 = VoxelColor(scalar); if (sum < 1.0) { col.r += transval * col2.r; col.g += transval * col2.g; col.b += transval * col2.b; if (sum < 0.0) sum=0.0; } else { sum=1.0; } } if (sum < 1.0) { /* spawn transmission rays / refraction */ color transcol; transcol = shade_transmission(ry, hit, 1.0 - sum); col.r += transcol.r; /* add the transmitted ray */ col.g += transcol.g; /* to the diffuse and */ col.b += transcol.b; /* transmission total.. */ } return col; } void LoadVol(scalarvol * vol) { FILE * dfile; size_t status; char msgtxt[2048]; dfile=fopen(vol->name, "r"); if (dfile==NULL) { char msgtxt[2048]; sprintf(msgtxt, "Vol: can't open %s for input!!! Aborting\n",vol->name); rt_ui_message(MSG_ERR, msgtxt); rt_ui_message(MSG_ABORT, "Rendering Aborted."); exit(1); } sprintf(msgtxt, "loading %dx%dx%d volume set from %s", vol->xres, vol->yres, vol->zres, vol->name); rt_ui_message(MSG_0, msgtxt); vol->data = (unsigned char *)rt_getmem(vol->xres * vol->yres * vol->zres); status=fread(vol->data, 1, (vol->xres * vol->yres * vol->zres), dfile); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/jpeg.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * jpeg.cpp - This file deals with JPEG format image files (reading/writing) */ /* * This code requires support from the Independent JPEG Group's libjpeg. * For our puposes, we're interested only in the 3 byte per pixel 24 bit * RGB output. Probably won't implement any decent checking at this point. */ #include <stdio.h> #include "machine.h" #include "types.h" #include "util.h" #include "imageio.h" /* error codes etc */ #include "jpeg.h" /* the protos for this file */ #if !defined(USEJPEG) int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata) { return IMAGEUNSUP; } #else #include "jpeglib.h" /* the IJG jpeg library headers */ int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata) { FILE * ifp; struct jpeg_decompress_struct cinfo; /* JPEG decompression struct */ struct jpeg_error_mgr jerr; /* JPEG Error handler */ JSAMPROW row_pointer[1]; /* output row buffer */ int row_stride; /* physical row width in output buf */ /* open input file before doing any JPEG decompression setup */ if ((ifp = fopen(name, "rb")) == NULL) return IMAGEBADFILE; /* Could not open image, return error */ /* * Note: The Independent JPEG Group's library does not have a way * of returning errors without the use of setjmp/longjmp. * This is a problem in multi-threaded environment, since setjmp * and longjmp are declared thread-unsafe by many vendors currently. * For now, JPEG decompression errors will result in the "default" * error handling provided by the JPEG library, which is an error * message and a fatal call to exit(). I'll have to work around this * or find a reasonably thread-safe way of doing setjmp/longjmp.. */ cinfo.err = jpeg_std_error(&jerr); /* Set JPEG error handler to default */ jpeg_create_decompress(&cinfo); /* Create decompression context */ jpeg_stdio_src(&cinfo, ifp); /* Set input mechanism to stdio type */ jpeg_read_header(&cinfo, TRUE); /* Read the JPEG header for info */ jpeg_start_decompress(&cinfo); /* Prepare for actual decompression */ *xres = cinfo.output_width; /* set returned image width */ *yres = cinfo.output_height; /* set returned image height */ /* Calculate the size of a row in the image */ row_stride = cinfo.output_width * cinfo.output_components; /* Allocate the image buffer which will be returned to the ray tracer */ *imgdata = (unsigned char *) malloc(row_stride * cinfo.output_height); /* decompress the JPEG, one scanline at a time into the buffer */ while (cinfo.output_scanline < cinfo.output_height) { row_pointer[0] = &((*imgdata)[(cinfo.output_scanline)*row_stride]); jpeg_read_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_decompress(&cinfo); /* Tell the JPEG library to cleanup */ jpeg_destroy_decompress(&cinfo); /* Destroy JPEG decompression context */ fclose(ifp); /* Close the input file */ return IMAGENOERR; /* No fatal errors */ } #endif
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/apigeom.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * api.cpp - This file contains all of the API calls that are defined for * external driver code to use. */ #include "machine.h" #include "types.h" #include "api.h" #include "macros.h" #include "vector.h" #define MyVNorm(a) VNorm ((vector *) a) void rt_polycylinder(void * tex, vector * points, int numpts, apiflt rad) { vector a; int i; if ((points == NULL) || (numpts == 0)) { return; } if (numpts > 0) { rt_sphere(tex, points[0], rad); if (numpts > 1) { for (i=1; i<numpts; i++) { a.x = points[i].x - points[i-1].x; a.y = points[i].y - points[i-1].y; a.z = points[i].z - points[i-1].z; rt_fcylinder(tex, points[i-1], a, rad); rt_sphere(tex, points[i], rad); } } } } void rt_heightfield(void * tex, vector ctr, int m, int n, apiflt * field, apiflt wx, apiflt wy) { int xx,yy; vector v0, v1, v2; apiflt xoff, yoff, zoff; xoff=ctr.x - (wx / 2.0); yoff=ctr.z - (wy / 2.0); zoff=ctr.y; for (yy=0; yy<(n-1); yy++) { for (xx=0; xx<(m-1); xx++) { v0.x=wx*(xx )/(m*1.0) + xoff; v0.y=field[(yy )*m + (xx )] + zoff; v0.z=wy*(yy )/(n*1.0) + yoff; v1.x=wx*(xx + 1)/(m*1.0) + xoff; v1.y=field[(yy )*m + (xx + 1)] + zoff; v1.z=wy*(yy )/(n*1.0) + yoff; v2.x=wx*(xx + 1)/(m*1.0) + xoff; v2.y=field[(yy + 1)*m + (xx + 1)] + zoff; v2.z=wy*(yy + 1)/(n*1.0) + yoff; rt_tri(tex, v1, v0, v2); v0.x=wx*(xx )/(m*1.0) + xoff; v0.y=field[(yy )*m + (xx )] + zoff; v0.z=wy*(yy )/(n*1.0) + yoff; v1.x=wx*(xx )/(m*1.0) + xoff; v1.y=field[(yy + 1)*m + (xx )] + zoff; v1.z=wy*(yy + 1)/(n*1.0) + yoff; v2.x=wx*(xx + 1)/(m*1.0) + xoff; v2.y=field[(yy + 1)*m + (xx + 1)] + zoff; v2.z=wy*(yy + 1)/(n*1.0) + yoff; rt_tri(tex, v0, v1, v2); } } } /* end of heightfield */ static void rt_sheightfield(void * tex, vector ctr, int m, int n, apiflt * field, apiflt wx, apiflt wy) { vector * vertices; vector * normals; vector offset; apiflt xinc, yinc; int x, y, addr; vertices = (vector *) malloc(m*n*sizeof(vector)); normals = (vector *) malloc(m*n*sizeof(vector)); offset.x = ctr.x - (wx / 2.0); offset.y = ctr.z - (wy / 2.0); offset.z = ctr.y; xinc = wx / ((apiflt) m); yinc = wy / ((apiflt) n); /* build vertex list */ for (y=0; y<n; y++) { for (x=0; x<m; x++) { addr = y*m + x; vertices[addr] = rt_vector( x * xinc + offset.x, field[addr] + offset.z, y * yinc + offset.y); } } /* build normals from vertex list */ for (x=1; x<m; x++) { normals[x] = normals[(n - 1)*m + x] = rt_vector(0.0, 1.0, 0.0); } for (y=1; y<n; y++) { normals[y*m] = normals[y*m + (m-1)] = rt_vector(0.0, 1.0, 0.0); } for (y=1; y<(n-1); y++) { for (x=1; x<(m-1); x++) { addr = y*m + x; normals[addr] = rt_vector( -(field[addr + 1] - field[addr - 1]) / (2.0 * xinc), 1.0, -(field[addr + m] - field[addr - m]) / (2.0 * yinc)); MyVNorm(&normals[addr]); } } /* generate actual triangles */ for (y=0; y<(n-1); y++) { for (x=0; x<(m-1); x++) { addr = y*m + x; rt_stri(tex, vertices[addr], vertices[addr + 1 + m], vertices[addr + 1], normals[addr], normals[addr + 1 + m], normals[addr + 1]); rt_stri(tex, vertices[addr], vertices[addr + m], vertices[addr + 1 + m], normals[addr], normals[addr + m], normals[addr + 1 + m]); } } free(normals); free(vertices); } /* end of smoothed heightfield */ static void adjust(apiflt *base, int xres, int yres, apiflt wx, apiflt wy, int xa, int ya, int x, int y, int xb, int yb) { apiflt d, v; if (base[x + (xres*y)]==0.0) { d=(abs(xa - xb) / (xres * 1.0))*wx + (abs(ya - yb) / (yres * 1.0))*wy; v=(base[xa + (xres*ya)] + base[xb + (xres*yb)]) / 2.0 + (((((rand() % 1000) - 500.0)/500.0)*d) / 8.0); if (v < 0.0) v=0.0; if (v > (xres + yres)) v=(xres + yres); base[x + (xres * y)]=v; } } static void subdivide(apiflt *base, int xres, int yres, apiflt wx, apiflt wy, int x1, int y1, int x2, int y2) { long x,y; if (((x2 - x1) < 2) && ((y2 - y1) < 2)) { return; } x=(x1 + x2) / 2; y=(y1 + y2) / 2; adjust(base, xres, yres, wx, wy, x1, y1, x, y1, x2, y1); adjust(base, xres, yres, wx, wy, x2, y1, x2, y, x2, y2); adjust(base, xres, yres, wx, wy, x1, y2, x, y2, x2, y2); adjust(base, xres, yres, wx, wy, x1, y1, x1, y, x1, y2); if (base[x + xres*y]==0.0) { base[x + (xres * y)]=(base[x1 + xres*y1] + base[x2 + xres*y1] + base[x2 + xres*y2] + base[x1 + xres*y2] )/4.0; } subdivide(base, xres, yres, wx, wy, x1, y1 ,x ,y); subdivide(base, xres, yres, wx, wy, x, y1, x2, y); subdivide(base, xres, yres, wx, wy, x, y, x2, y2); subdivide(base, xres, yres, wx, wy, x1, y, x, y2); } void rt_landscape(void * tex, int m, int n, vector ctr, apiflt wx, apiflt wy) { int totalsize, x, y; apiflt * field; totalsize=m*n; srand(totalsize); field=(apiflt *) malloc(totalsize*sizeof(apiflt)); for (y=0; y<n; y++) { for (x=0; x<m; x++) { field[x + y*m]=0.0; } } field[0 + 0]=1.0 + (rand() % 100)/100.0; field[m - 1]=1.0 + (rand() % 100)/100.0; field[0 + m*(n - 1)]=1.0 + (rand() % 100)/100.0; field[m - 1 + m*(n - 1)]=1.0 + (rand() % 100)/100.0; subdivide(field, m, n, wx, wy, 0, 0, m-1, n-1); rt_sheightfield(tex, ctr, m, n, field, wx, wy); free(field); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/pthread.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef EMULATE_PTHREADS #include <assert.h> #include "pthread_w.h" /* Basics */ int pthread_create (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { pthread_t th; if (thread == NULL) return EINVAL; *thread = NULL; if (start_routine == NULL) return EINVAL; th = (pthread_t) malloc (sizeof (pthread_s)); memset (th, 0, sizeof (pthread_s)); th->winthread_handle = CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE) start_routine, arg, 0, &th->winthread_id); if (th->winthread_handle == NULL) return EAGAIN; /* GetLastError() */ *thread = th; return 0; } int pthread_join (pthread_t th, void **thread_return) { BOOL b_ret; DWORD dw_ret; if (thread_return) *thread_return = NULL; if ((th == NULL) || (th->winthread_handle == NULL)) return EINVAL; dw_ret = WaitForSingleObject (th->winthread_handle, INFINITE); if (dw_ret != WAIT_OBJECT_0) return ERROR_PTHREAD; /* dw_ret == WAIT_FAILED; GetLastError() */ if (thread_return) { BOOL e_ret; DWORD exit_val; e_ret = GetExitCodeThread (th->winthread_handle, &exit_val); if (!e_ret) return ERROR_PTHREAD; /* GetLastError() */ *thread_return = (void *)(size_t) exit_val; } b_ret = CloseHandle (th->winthread_handle); if (!b_ret) return ERROR_PTHREAD; /* GetLastError() */ memset (th, 0, sizeof (pthread_s)); free (th); th = NULL; return 0; } void pthread_exit (void *retval) { /* specific to PTHREAD_TO_WINTHREAD */ ExitThread ((DWORD) ((size_t) retval)); /* thread becomes signalled so its death can be waited upon */ /*NOTREACHED*/ assert (0); return; /* void fnc; can't return an error code */ } /* Mutex */ int pthread_mutex_init (pthread_mutex_t *mutex, pthread_mutexattr_t *mutex_attr) { InitializeCriticalSection (&mutex->critsec); return 0; } int pthread_mutex_destroy (pthread_mutex_t *mutex) { return 0; } int pthread_mutex_lock (pthread_mutex_t *mutex) { EnterCriticalSection (&mutex->critsec); return 0; } int pthread_mutex_unlock (pthread_mutex_t *mutex) { LeaveCriticalSection (&mutex->critsec); return 0; } #endif /* EMULATE_PTHREADS */
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/imageio.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * imageio.cpp - This file deals with reading/writing image files */ /* For our puposes, we're interested only in the 3 byte per pixel 24 bit * truecolor sort of file.. */ #include <stdio.h> #include "machine.h" #include "types.h" #include "util.h" #include "imageio.h" #include "ppm.h" /* PPM files */ #include "tgafile.h" /* Truevision Targa files */ #include "jpeg.h" /* JPEG files */ static int fakeimage(char * name, int * xres, int * yres, unsigned char ** imgdata) { int i, imgsize; fprintf(stderr, "Error loading image %s. Faking it.\n", name); *xres = 2; *yres = 2; imgsize = 3 * (*xres) * (*yres); *imgdata = (unsigned char *)rt_getmem(imgsize); for (i=0; i<imgsize; i++) { (*imgdata)[i] = 255; } return IMAGENOERR; } int readimage(rawimage * img) { int rc; int xres, yres; unsigned char * imgdata = NULL; char * name = img->name; if (strstr(name, ".ppm")) { rc = readppm(name, &xres, &yres, &imgdata); } else if (strstr(name, ".tga")) { rc = readtga(name, &xres, &yres, &imgdata); } else if (strstr(name, ".jpg")) { rc = readjpeg(name, &xres, &yres, &imgdata); } else if (strstr(name, ".gif")) { rc = IMAGEUNSUP; } else if (strstr(name, ".png")) { rc = IMAGEUNSUP; } else if (strstr(name, ".tiff")) { rc = IMAGEUNSUP; } else if (strstr(name, ".rgb")) { rc = IMAGEUNSUP; } else if (strstr(name, ".xpm")) { rc = IMAGEUNSUP; } else { rc = readppm(name, &xres, &yres, &imgdata); } switch (rc) { case IMAGEREADERR: fprintf(stderr, "Short read encountered while loading image %s\n", name); rc = IMAGENOERR; /* remap to non-fatal error */ break; case IMAGEUNSUP: fprintf(stderr, "Cannot read unsupported image format for image %s\n", name); break; } /* If the image load failed, create a tiny white colored image to fake it */ /* this allows a scene to render even when a file can't be loaded */ if (rc != IMAGENOERR) { rc = fakeimage(name, &xres, &yres, &imgdata); } /* If we succeeded in loading the image, return it. */ if (rc == IMAGENOERR) { img->xres = xres; img->yres = yres; img->bpp = 3; img->data = imgdata; } return rc; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/render.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * render.cpp - This file contains the main program and driver for the raytracer. */ #include "machine.h" #include "types.h" #include "macros.h" #include "tgafile.h" #include "trace.h" #include "render.h" #include "util.h" #include "light.h" #include "global.h" #include "ui.h" #include "tachyon_video.h" #include "objbound.h" #include "grid.h" /* how many pieces to divide each scanline into */ #define NUMHORZDIV 1 void renderscene(scenedef scene) { //char msgtxt[2048]; //void * outfile; /* Grid based accerlation scheme */ if (scene.boundmode == RT_BOUNDING_ENABLED) engrid_scene(&rootobj); /* grid */ /* Not used now if (scene.verbosemode) { sprintf(msgtxt, "Opening %s for output.", scene.outfilename); rt_ui_message(MSG_0, msgtxt); } createtgafile(scene.outfilename, (unsigned short) scene.hres, (unsigned short) scene.vres); outfile = opentgafile(scene.outfilename); */ trace_region (scene, 0/*outfile*/, 0, 0, scene.hres, scene.vres); //fclose((FILE *)outfile); } /* end of renderscene() */
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/bndbox.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * bndbox.cpp - This file contains the functions for dealing with bounding boxes. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define BNDBOX_PRIVATE #include "bndbox.h" static object_methods bndbox_methods = { (void (*)(void *, void *))(bndbox_intersect), (void (*)(void *, void *, void *, void *))(NULL), bndbox_bbox, free_bndbox }; bndbox * newbndbox(vector min, vector max) { bndbox * b; b=(bndbox *) rt_getmem(sizeof(bndbox)); memset(b, 0, sizeof(bndbox)); b->min=min; b->max=max; b->methods = &bndbox_methods; b->objlist=NULL; b->tex=NULL; b->nextobj=NULL; return b; } static int bndbox_bbox(void * obj, vector * min, vector * max) { bndbox * b = (bndbox *) obj; *min = b->min; *max = b->max; return 1; } static void free_bndbox(void * v) { bndbox * b = (bndbox *) v; free_objects(b->objlist); free(b); } static void bndbox_intersect(bndbox * bx, ray * ry) { flt a, tx1, tx2, ty1, ty2, tz1, tz2; flt tnear, tfar; object * obj; ray newray; /* eliminate bounded rays whose bounds do not intersect */ /* the bounds of the box.. */ if (ry->flags & RT_RAY_BOUNDED) { if ((ry->s.x > bx->max.x) && (ry->e.x > bx->max.x)) return; if ((ry->s.x < bx->min.x) && (ry->e.x < bx->min.x)) return; if ((ry->s.y > bx->max.y) && (ry->e.y > bx->max.y)) return; if ((ry->s.y < bx->min.y) && (ry->e.y < bx->min.y)) return; if ((ry->s.z > bx->max.z) && (ry->e.z > bx->max.z)) return; if ((ry->s.z < bx->min.z) && (ry->e.z < bx->min.z)) return; } tnear= -FHUGE; tfar= FHUGE; if (ry->d.x == 0.0) { if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return; } else { tx1 = (bx->min.x - ry->o.x) / ry->d.x; tx2 = (bx->max.x - ry->o.x) / ry->d.x; if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; } if (tx1 > tnear) tnear=tx1; if (tx2 < tfar) tfar=tx2; } if (tnear > tfar) return; if (tfar < 0.0) return; if (ry->d.y == 0.0) { if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return; } else { ty1 = (bx->min.y - ry->o.y) / ry->d.y; ty2 = (bx->max.y - ry->o.y) / ry->d.y; if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; } if (ty1 > tnear) tnear=ty1; if (ty2 < tfar) tfar=ty2; } if (tnear > tfar) return; if (tfar < 0.0) return; if (ry->d.z == 0.0) { if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return; } else { tz1 = (bx->min.z - ry->o.z) / ry->d.z; tz2 = (bx->max.z - ry->o.z) / ry->d.z; if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; } if (tz1 > tnear) tnear=tz1; if (tz2 < tfar) tfar=tz2; } if (tnear > tfar) return; if (tfar < 0.0) return; /* intersect all of the enclosed objects */ newray=*ry; newray.flags |= RT_RAY_BOUNDED; RAYPNT(newray.s , (*ry) , tnear); RAYPNT(newray.e , (*ry) , (tfar + EPSILON)); obj = bx->objlist; while (obj != NULL) { obj->methods->intersect(obj, &newray); obj = (object *)obj->nextobj; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/imap.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * imap.cpp - This file contains code for doing image map type things. */ #include "machine.h" #include "types.h" #include "imap.h" #include "util.h" #include "imageio.h" rawimage * imagelist[MAXIMGS]; int numimages; void ResetImages(void) { int i; numimages=0; for (i=0; i<MAXIMGS; i++) { imagelist[i]=NULL; } } void LoadImage(rawimage * image) { if (!image->loaded) { readimage(image); image->loaded=1; } } color ImageMap(rawimage * image, flt u, flt v) { color col, colx, colx2; flt x,y, px, py; int x1, x2, y1, y2; unsigned char * ptr; unsigned char * ptr2; if (!image->loaded) { LoadImage(image); image->loaded=1; } if ((u <= 1.0) && (u >=0.0) && (v <= 1.0) && (v >= 0.0)) { x=(image->xres - 1.0) * u; /* floating point X location */ y=(image->yres - 1.0) * v; /* floating point Y location */ px = x - ((int) x); py = y - ((int) y); x1 = (int) x; x2 = x1 + 1; y1 = (int) y; y2 = y1 + 1; ptr = image->data + ((image->xres * y1) + x1) * 3; ptr2 = image->data + ((image->xres * y1) + x2) * 3; colx.r = (flt) ((flt)ptr[0] + px*((flt)ptr2[0] - (flt) ptr[0])) / 255.0; colx.g = (flt) ((flt)ptr[1] + px*((flt)ptr2[1] - (flt) ptr[1])) / 255.0; colx.b = (flt) ((flt)ptr[2] + px*((flt)ptr2[2] - (flt) ptr[2])) / 255.0; ptr = image->data + ((image->xres * y2) + x1) * 3; ptr2 = image->data + ((image->xres * y2) + x2) * 3; colx2.r = ((flt)ptr[0] + px*((flt)ptr2[0] - (flt)ptr[0])) / 255.0; colx2.g = ((flt)ptr[1] + px*((flt)ptr2[1] - (flt)ptr[1])) / 255.0; colx2.b = ((flt)ptr[2] + px*((flt)ptr2[2] - (flt)ptr[2])) / 255.0; col.r = colx.r + py*(colx2.r - colx.r); col.g = colx.g + py*(colx2.g - colx.g); col.b = colx.b + py*(colx2.b - colx.b); } else { col.r=0.0; col.g=0.0; col.b=0.0; } return col; } rawimage * AllocateImage(char * filename) { rawimage * newimage = NULL; int i, intable; size_t len; intable=0; if (numimages!=0) { for (i=0; i<numimages; i++) { if (!strcmp(filename, imagelist[i]->name)) { newimage=imagelist[i]; intable=1; } } } if (!intable) { newimage=(rawimage *)rt_getmem(sizeof(rawimage)); newimage->loaded=0; newimage->xres=0; newimage->yres=0; newimage->bpp=0; newimage->data=NULL; len=strlen(filename); if (len > 80) rtbomb("Filename too long in image map!!"); strcpy(newimage->name, filename); imagelist[numimages]=newimage; /* add new one to the table */ numimages++; /* increment the number of images */ } return newimage; } void DeallocateImage(rawimage * image) { image->loaded=0; rt_freemem(image->data); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/coordsys.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * coordsys.cpp - Routines to translate from one coordinate system to another. */ #include "machine.h" #include "types.h" #include "coordsys.h" void xytopolar(flt x, flt y, flt rad, flt * u, flt * v) { flt r1; r1=x*x + y*y; *v=sqrt(r1 / (rad*rad)); if (y<0.0) *u=1.0 - acos(x/sqrt(r1))/TWOPI; else *u= acos(x/sqrt(r1))/TWOPI; } void xyztocyl(vector pnt, flt height, flt * u, flt * v) { flt r1; r1=pnt.x*pnt.x + pnt.y*pnt.y; *v=pnt.z / height; if (pnt.y<0.0) *u=1.0 - acos(pnt.x/sqrt(r1))/TWOPI; else *u=acos(pnt.x/sqrt(r1))/TWOPI; } void xyztospr(vector pnt, flt * u, flt * v) { flt r1, phi, theta; r1=sqrt(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z); phi=acos(-pnt.y/r1); *v=phi/3.1415926; theta=acos((pnt.x/r1)/sin(phi))/TWOPI; if (pnt.z > 0.0) *u = theta; else *u = 1 - theta; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/plane.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * plane.cpp - This file contains the functions for dealing with planes. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define PLANE_PRIVATE #include "plane.h" static object_methods plane_methods = { (void (*)(void *, void *))(plane_intersect), (void (*)(void *, void *, void *, void *))(plane_normal), plane_bbox, free }; object * newplane(void * tex, vector ctr, vector norm) { plane * p; p=(plane *) rt_getmem(sizeof(plane)); memset(p, 0, sizeof(plane)); p->methods = &plane_methods; p->tex = (texture *)tex; p->norm = norm; VNorm(&p->norm); p->d = -VDot(&ctr, &p->norm); return (object *) p; } static int plane_bbox(void * obj, vector * min, vector * max) { return 0; } static void plane_intersect(plane * pln, ray * ry) { flt t,td; t=-(pln->d + VDot(&pln->norm, &ry->o)); td=VDot(&pln->norm, &ry->d); if (td != 0.0) { t /= td; if (t > 0.0) add_intersection(t,(object *) pln, ry); } } static void plane_normal(plane * pln, vector * pnt, ray * incident, vector * N) { *N=pln->norm; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/ppm.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ppm.cpp - This file deals with PPM format image files (reading/writing) */ /* For our puposes, we're interested only in the 3 byte per pixel 24 bit truecolor sort of file.. Probably won't implement any decent checking at this point, probably choke on things like the # comments.. */ // Try preventing lots of GCC warnings about ignored results of fscanf etc. #if !__INTEL_COMPILER #if __GNUC__<4 || __GNUC__==4 && __GNUC_MINOR__<5 // For older versions of GCC, disable use of __wur in GLIBC #undef _FORTIFY_SOURCE #define _FORTIFY_SOURCE 0 #else // Starting from 4.5, GCC has a suppression option #pragma GCC diagnostic ignored "-Wunused-result" #endif #endif //__INTEL_COMPILER #include <stdio.h> #include "machine.h" #include "types.h" #include "util.h" #include "imageio.h" /* error codes etc */ #include "ppm.h" static int getint(FILE * dfile) { char ch[200]; int i; int num; num=0; while (num==0) { fscanf(dfile, "%s", ch); while (ch[0]=='#') { fgets(ch, 200, dfile); } num=sscanf(ch, "%d", &i); } return i; } int readppm(char * name, int * xres, int * yres, unsigned char **imgdata) { char data[200]; FILE * ifp; int i; size_t bytesread; int datasize; ifp=fopen(name, "r"); if (ifp==NULL) { return IMAGEBADFILE; /* couldn't open the file */ } fscanf(ifp, "%s", data); if (strcmp(data, "P6")) { fclose(ifp); return IMAGEUNSUP; /* not a format we support */ } *xres=getint(ifp); *yres=getint(ifp); i=getint(ifp); /* eat the maxval number */ fread(&i, 1, 1, ifp); /* eat the newline */ datasize = 3 * (*xres) * (*yres); *imgdata=(unsigned char *)rt_getmem(datasize); bytesread=fread(*imgdata, 1, datasize, ifp); fclose(ifp); if (bytesread != datasize) return IMAGEREADERR; return IMAGENOERR; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/objbound.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * objbound.cpp - This file contains the functions to find bounding boxes * for the various primitives */ #include "machine.h" #include "types.h" #include "macros.h" #include "bndbox.h" #define OBJBOUND_PRIVATE #include "objbound.h" static void globalbound(object ** rootlist, vector * gmin, vector * gmax) { vector min, max; object * cur; if (*rootlist == NULL) /* don't bound non-existant objects */ return; gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE; gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE; cur=*rootlist; while (cur != NULL) { /* Go! */ min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE; max.x = FHUGE; max.y = FHUGE; max.z = FHUGE; cur->methods->bbox((void *) cur, &min, &max); gmin->x = MYMIN( gmin->x , min.x); gmin->y = MYMIN( gmin->y , min.y); gmin->z = MYMIN( gmin->z , min.z); gmax->x = MYMAX( gmax->x , max.x); gmax->y = MYMAX( gmax->y , max.y); gmax->z = MYMAX( gmax->z , max.z); cur=(object *)cur->nextobj; } } static int objinside(object * obj, vector * min, vector * max) { vector omin, omax; if (obj == NULL) /* non-existant object, shouldn't get here */ return 0; if (obj->methods->bbox((void *) obj, &omin, &omax)) { if ((min->x <= omin.x) && (min->y <= omin.y) && (min->z <= omin.z) && (max->x >= omax.x) && (max->y >= omax.y) && (max->z >= omax.z)) { return 1; } } return 0; } static int countobj(object * root) { object * cur; /* counts the number of objects on a list */ int numobj; numobj=0; cur=root; while (cur != NULL) { cur=(object *)cur->nextobj; numobj++; } return numobj; } static void movenextobj(object * thisobj, object ** root) { object * cur, * tmp; /* move the object after thisobj to the front of the object list */ /* headed by root */ if (thisobj != NULL) { if (thisobj->nextobj != NULL) { cur=(object *)thisobj->nextobj; /* the object to be moved */ thisobj->nextobj = cur->nextobj; /* link around the moved obj */ tmp=*root; /* store the root node */ cur->nextobj=tmp; /* attach root to cur */ *root=cur; /* make cur, the new root */ } } } static void octreespace(object ** rootlist, int maxoctnodes) { object * cur; vector gmin, gmax, gctr; vector cmin1, cmin2, cmin3, cmin4, cmin5, cmin6, cmin7, cmin8; vector cmax1, cmax2, cmax3, cmax4, cmax5, cmax6, cmax7, cmax8; bndbox * box1, * box2, * box3, * box4; bndbox * box5, * box6, * box7, * box8; int skipobj; if (*rootlist == NULL) /* don't subdivide non-existant data */ return; skipobj=0; globalbound(rootlist, &gmin, &gmax); /* find global min and max */ gctr.x = ((gmax.x - gmin.x) / 2.0) + gmin.x; gctr.y = ((gmax.y - gmin.y) / 2.0) + gmin.y; gctr.z = ((gmax.z - gmin.z) / 2.0) + gmin.z; cmin1=gmin; cmax1=gctr; box1 = newbndbox(cmin1, cmax1); cmin2=gmin; cmin2.x=gctr.x; cmax2=gmax; cmax2.y=gctr.y; cmax2.z=gctr.z; box2 = newbndbox(cmin2, cmax2); cmin3=gmin; cmin3.y=gctr.y; cmax3=gmax; cmax3.x=gctr.x; cmax3.z=gctr.z; box3 = newbndbox(cmin3, cmax3); cmin4=gmin; cmin4.x=gctr.x; cmin4.y=gctr.y; cmax4=gmax; cmax4.z=gctr.z; box4 = newbndbox(cmin4, cmax4); cmin5=gmin; cmin5.z=gctr.z; cmax5=gctr; cmax5.z=gmax.z; box5 = newbndbox(cmin5, cmax5); cmin6=gctr; cmin6.y=gmin.y; cmax6=gmax; cmax6.y=gctr.y; box6 = newbndbox(cmin6, cmax6); cmin7=gctr; cmin7.x=gmin.x; cmax7=gctr; cmax7.y=gmax.y; cmax7.z=gmax.z; box7 = newbndbox(cmin7, cmax7); cmin8=gctr; cmax8=gmax; box8 = newbndbox(cmin8, cmax8); cur = *rootlist; while (cur != NULL) { if (objinside((object *)cur->nextobj, &cmin1, &cmax1)) { movenextobj(cur, &box1->objlist); } else if (objinside((object *)cur->nextobj, &cmin2, &cmax2)) { movenextobj(cur, &box2->objlist); } else if (objinside((object *)cur->nextobj, &cmin3, &cmax3)) { movenextobj(cur, &box3->objlist); } else if (objinside((object *)cur->nextobj, &cmin4, &cmax4)) { movenextobj(cur, &box4->objlist); } else if (objinside((object *)cur->nextobj, &cmin5, &cmax5)) { movenextobj(cur, &box5->objlist); } else if (objinside((object *)cur->nextobj, &cmin6, &cmax6)) { movenextobj(cur, &box6->objlist); } else if (objinside((object *)cur->nextobj, &cmin7, &cmax7)) { movenextobj(cur, &box7->objlist); } else if (objinside((object *)cur->nextobj, &cmin8, &cmax8)) { movenextobj(cur, &box8->objlist); } else { skipobj++; cur=(object *)cur->nextobj; } } /* new scope, for redefinition of cur, and old */ { bndbox * cur, * old; old=box1; cur=box2; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box3; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box4; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box5; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box6; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box7; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } cur=box8; if (countobj(cur->objlist) > 0) { old->nextobj=cur; globalbound(&cur->objlist, &cur->min, &cur->max); old=cur; } old->nextobj=*rootlist; if (countobj(box1->objlist) > 0) { globalbound(&box1->objlist, &box1->min, &box1->max); *rootlist=(object *) box1; } else { *rootlist=(object *) box1->nextobj; } } /**** end of special cur and old scope */ if (countobj(box1->objlist) > maxoctnodes) { octreespace(&box1->objlist, maxoctnodes); } if (countobj(box2->objlist) > maxoctnodes) { octreespace(&box2->objlist, maxoctnodes); } if (countobj(box3->objlist) > maxoctnodes) { octreespace(&box3->objlist, maxoctnodes); } if (countobj(box4->objlist) > maxoctnodes) { octreespace(&box4->objlist, maxoctnodes); } if (countobj(box5->objlist) > maxoctnodes) { octreespace(&box5->objlist, maxoctnodes); } if (countobj(box6->objlist) > maxoctnodes) { octreespace(&box6->objlist, maxoctnodes); } if (countobj(box7->objlist) > maxoctnodes) { octreespace(&box7->objlist, maxoctnodes); } if (countobj(box8->objlist) > maxoctnodes) { octreespace(&box8->objlist, maxoctnodes); } } void dividespace(int maxoctnodes, object **toplist) { bndbox * gbox; vector gmin, gmax; if (countobj(*toplist) > maxoctnodes) { globalbound(toplist, &gmin, &gmax); octreespace(toplist, maxoctnodes); gbox = newbndbox(gmin, gmax); gbox->objlist = NULL; gbox->tex = NULL; gbox->nextobj=NULL; gbox->objlist=*toplist; *toplist=(object *) gbox; } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/cylinder.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= /* The original source for this example is Copyright (c) 1994-2008 John E. Stone All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cylinder.cpp - This file contains the functions for dealing with cylinders. */ #include "machine.h" #include "types.h" #include "macros.h" #include "vector.h" #include "intersect.h" #include "util.h" #define CYLINDER_PRIVATE #include "cylinder.h" static object_methods cylinder_methods = { (void (*)(void *, void *))(cylinder_intersect), (void (*)(void *, void *, void *, void *))(cylinder_normal), cylinder_bbox, free }; static object_methods fcylinder_methods = { (void (*)(void *, void *))(fcylinder_intersect), (void (*)(void *, void *, void *, void *))(cylinder_normal), fcylinder_bbox, free }; object * newcylinder(void * tex, vector ctr, vector axis, flt rad) { cylinder * c; c=(cylinder *) rt_getmem(sizeof(cylinder)); memset(c, 0, sizeof(cylinder)); c->methods = &cylinder_methods; c->tex=(texture *) tex; c->ctr=ctr; c->axis=axis; c->rad=rad; return (object *) c; } static int cylinder_bbox(void * obj, vector * min, vector * max) { return 0; /* infinite / unbounded object */ } static void cylinder_intersect(cylinder * cyl, ray * ry) { vector rc, n, D, O; flt t, s, tin, tout, ln, d; rc.x = ry->o.x - cyl->ctr.x; rc.y = ry->o.y - cyl->ctr.y; rc.z = ry->o.z - cyl->ctr.z; VCross(&ry->d, &cyl->axis, &n); VDOT(ln, n, n); ln=sqrt(ln); /* finish length calculation */ if (ln == 0.0) { /* ray is parallel to the cylinder.. */ VDOT(d, rc, cyl->axis); D.x = rc.x - d * cyl->axis.x; D.y = rc.y - d * cyl->axis.y; D.z = rc.z - d * cyl->axis.z; VDOT(d, D, D); d = sqrt(d); tin = -FHUGE; tout = FHUGE; /* if (d <= cyl->rad) then ray is inside cylinder.. else outside */ } VNorm(&n); VDOT(d, rc, n); d = fabs(d); if (d <= cyl->rad) { /* ray intersects cylinder.. */ VCross(&rc, &cyl->axis, &O); VDOT(t, O, n); t = - t / ln; VCross(&n, &cyl->axis, &O); VNorm(&O); VDOT(s, ry->d, O); s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s); tin = t - s; add_intersection(tin, (object *) cyl, ry); tout = t + s; add_intersection(tout, (object *) cyl, ry); } } static void cylinder_normal(cylinder * cyl, vector * pnt, ray * incident, vector * N) { vector a,b,c; flt t; VSub((vector *) pnt, &(cyl->ctr), &a); c=cyl->axis; VNorm(&c); VDOT(t, a, c); b.x = c.x * t + cyl->ctr.x; b.y = c.y * t + cyl->ctr.y; b.z = c.z * t + cyl->ctr.z; VSub(pnt, &b, N); VNorm(N); if (VDot(N, &(incident->d)) > 0.0) { /* make cylinder double sided */ N->x=-N->x; N->y=-N->y; N->z=-N->z; } } object * newfcylinder(void * tex, vector ctr, vector axis, flt rad) { cylinder * c; c=(cylinder *) rt_getmem(sizeof(cylinder)); memset(c, 0, sizeof(cylinder)); c->methods = &fcylinder_methods; c->tex=(texture *) tex; c->ctr=ctr; c->axis=axis; c->rad=rad; return (object *) c; } static int fcylinder_bbox(void * obj, vector * min, vector * max) { cylinder * c = (cylinder *) obj; vector mintmp, maxtmp; mintmp.x = c->ctr.x; mintmp.y = c->ctr.y; mintmp.z = c->ctr.z; maxtmp.x = c->ctr.x + c->axis.x; maxtmp.y = c->ctr.y + c->axis.y; maxtmp.z = c->ctr.z + c->axis.z; min->x = MYMIN(mintmp.x, maxtmp.x); min->y = MYMIN(mintmp.y, maxtmp.y); min->z = MYMIN(mintmp.z, maxtmp.z); min->x -= c->rad; min->y -= c->rad; min->z -= c->rad; max->x = MYMAX(mintmp.x, maxtmp.x); max->y = MYMAX(mintmp.y, maxtmp.y); max->z = MYMAX(mintmp.z, maxtmp.z); max->x += c->rad; max->y += c->rad; max->z += c->rad; return 1; } static void fcylinder_intersect(cylinder * cyl, ray * ry) { vector rc, n, O, hit, tmp2, ctmp4; flt t, s, tin, tout, ln, d, tmp, tmp3; rc.x = ry->o.x - cyl->ctr.x; rc.y = ry->o.y - cyl->ctr.y; rc.z = ry->o.z - cyl->ctr.z; VCross(&ry->d, &cyl->axis, &n); VDOT(ln, n, n); ln=sqrt(ln); /* finish length calculation */ if (ln == 0.0) { /* ray is parallel to the cylinder.. */ return; /* in this case, we want to miss or go through the "hole" */ } VNorm(&n); VDOT(d, rc, n); d = fabs(d); if (d <= cyl->rad) { /* ray intersects cylinder.. */ VCross(&rc, &cyl->axis, &O); VDOT(t, O, n); t = - t / ln; VCross(&n, &cyl->axis, &O); VNorm(&O); VDOT(s, ry->d, O); s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s); tin = t - s; RAYPNT(hit, (*ry), tin); ctmp4=cyl->axis; VNorm(&ctmp4); tmp2.x = hit.x - cyl->ctr.x; tmp2.y = hit.y - cyl->ctr.y; tmp2.z = hit.z - cyl->ctr.z; VDOT(tmp, tmp2, ctmp4); VDOT(tmp3, cyl->axis, cyl->axis); if ((tmp > 0.0) && (tmp < sqrt(tmp3))) add_intersection(tin, (object *) cyl, ry); tout = t + s; RAYPNT(hit, (*ry), tout); tmp2.x = hit.x - cyl->ctr.x; tmp2.y = hit.y - cyl->ctr.y; tmp2.z = hit.z - cyl->ctr.z; VDOT(tmp, tmp2, ctmp4); VDOT(tmp3, cyl->axis, cyl->axis); if ((tmp > 0.0) && (tmp < sqrt(tmp3))) add_intersection(tout, (object *) cyl, ry); } }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/common/gui/convideo.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= #include "video.h" #include <cassert> #include <stdio.h> unsigned int * g_pImg = 0; int g_sizex, g_sizey; static video *g_video = 0; static int g_fps = 0; #if _WIN32 || _WIN64 static DWORD g_msec = 0; #ifdef _WINDOWS HINSTANCE video::win_hInstance = 0; int video::win_iCmdShow = 0; void video::win_set_class(WNDCLASSEX &wcex) { } void video::win_load_accelerators(int idc) { } #endif //_WINDOWS #else #include <sched.h> #include <sys/time.h> struct timeval g_time; #endif //_WIN32||_WIN64 #define CALC_FPS_ENABLED ((WINAPI_FAMILY != WINAPI_FAMILY_APP) && (!__ANDROID__)) video::video() // OpenGL* RGBA byte order for little-endian CPU : red_mask(0xff), red_shift(0), green_mask(0xff00), green_shift(8), blue_mask(0xff0000), blue_shift(16), depth(24) { assert(g_video == 0); g_video = this; title = "Video"; updating = calc_fps = false; } bool video::init_window(int x, int y) { g_sizex = x; g_sizey = y; g_pImg = new unsigned int[x*y]; running = true; return false; } bool video::init_console() { running = true; return true; } void video::terminate() { #if CALC_FPS_ENABLED if(calc_fps) { double fps = g_fps; #if _WIN32 || _WIN64 fps /= (GetTickCount()-g_msec)/1000.0; #else struct timezone tz; struct timeval end_time; gettimeofday(&end_time, &tz); fps /= (end_time.tv_sec+1.0*end_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0); #endif printf("%s: %.1f fps\n", title, fps); } #endif g_video = 0; running = false; if(g_pImg) { delete[] g_pImg; g_pImg = 0; } } video::~video() { if(g_video) terminate(); } //! Count and display FPS count in titlebar bool video::next_frame() { #if CALC_FPS_ENABLED if(calc_fps){ if(!g_fps) { #if _WIN32 || _WIN64 g_msec = GetTickCount(); #else struct timezone tz; gettimeofday(&g_time, &tz); #endif } g_fps++; } #endif return running; } //! Do standard loop void video::main_loop() { on_process(); } //! Change window title void video::show_title() { } ///////////////////////////////////////////// public methods of video class /////////////////////// drawing_area::drawing_area(int x, int y, int sizex, int sizey) : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(24), base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex), ptr32(g_pImg) { assert(x < g_sizex); assert(y < g_sizey); assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey); index = base_index; // current index } void drawing_area::update() {}
cpp
oneAPI-samples
data/projects/oneAPI-samples/Tools/VTuneProfiler/tachyon/linux/src/common/gui/d2dvideo.cpp
//============================================================== // // SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, // http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ // // Copyright (C) Intel Corporation // // THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT // NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. // // ============================================================= // common Windows parts #include "winvideo.h" // and another headers #include <cassert> #include <stdio.h> #include <dxsdkver.h> #if _DXSDK_PRODUCT_MAJOR < 9 #error DXSDK Version 9 and above required. #endif #include <d2d1.h> #include <d2d1helper.h> #pragma comment(lib, "d2d1.lib") ID2D1Factory *m_pD2DFactory; ID2D1HwndRenderTarget *m_pRenderTarget; ID2D1Bitmap *m_pBitmap; D2D1_SIZE_U bitmapSize; HANDLE g_hVSync; #include <DXErr.h> #pragma comment(lib, "DxErr.lib") //! Create a dialog box and tell the user what went wrong bool DisplayError(LPSTR lpstrErr, HRESULT hres) { if(hres != S_OK){ static bool InError = false; int retval = 0; if (!InError) { InError = true; const char *message = hres?DXGetErrorString(hres):0; retval = MessageBoxA(g_hAppWnd, lpstrErr, hres?message:"Error!", MB_OK|MB_ICONERROR); InError = false; } } return false; } void DrawBitmap() { HRESULT hr = S_OK; if (m_pRenderTarget) { m_pRenderTarget->BeginDraw(); if (m_pBitmap) hr = m_pBitmap->CopyFromMemory(NULL,(BYTE*)g_pImg, 4*g_sizex); DisplayError( "DrawBitmap error", hr ); m_pRenderTarget->DrawBitmap(m_pBitmap); m_pRenderTarget->EndDraw(); } return; } inline void mouse(int k, LPARAM lParam) { int x = (int)LOWORD(lParam); int y = (int)HIWORD(lParam); RECT rc; GetClientRect(g_hAppWnd, &rc); g_video->on_mouse( x*g_sizex/(rc.right - rc.left), y*g_sizey/(rc.bottom - rc.top), k ); } //! Win event processing function LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) { case WM_MOVE: // Check to make sure our window exists before we tell it to repaint. // This will fail the first time (while the window is being created). if (hwnd) { InvalidateRect(hwnd, NULL, FALSE); UpdateWindow(hwnd); } return 0L; case WM_SIZE: case WM_PAINT: if( g_video->running && g_video->updating ) { DrawBitmap(); Sleep(0); } break; // Proccess all mouse and keyboard events case WM_LBUTTONDOWN: mouse( 1, lParam ); break; case WM_LBUTTONUP: mouse(-1, lParam ); break; case WM_RBUTTONDOWN: mouse( 2, lParam ); break; case WM_RBUTTONUP: mouse(-2, lParam ); break; case WM_MBUTTONDOWN: mouse( 3, lParam ); break; case WM_MBUTTONUP: mouse(-3, lParam ); break; case WM_CHAR: g_video->on_key( (int)wParam); break; // some useless stuff case WM_ERASEBKGND: return 1; // keeps erase-background events from happening, reduces chop case WM_DISPLAYCHANGE: return 0; // Now, shut down the window... case WM_DESTROY: PostQuitMessage(0); return 0; } // call user defined proc, if exists return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam); } bool video::init_window(int sizex, int sizey) { assert(win_hInstance != 0); g_sizex = sizex; g_sizey = sizey; if (!WinInit(win_hInstance, win_iCmdShow, gWndClass, title, false)) { DisplayError("Unable to initialize the program's window."); return false; } ShowWindow(g_hAppWnd, SW_SHOW); g_pImg = new unsigned int[sizex*sizey]; HRESULT hr = S_OK; hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory); // Create a Direct2D render target. if (SUCCEEDED(hr) && !m_pRenderTarget){ RECT rc; GetClientRect(g_hAppWnd, &rc); bitmapSize = D2D1::SizeU( rc.right - rc.left, rc.bottom - rc.top ); hr = m_pD2DFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(g_hAppWnd, bitmapSize), &m_pRenderTarget ); if (SUCCEEDED(hr) && !m_pBitmap){ D2D1_PIXEL_FORMAT pixelFormat = D2D1::PixelFormat( DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE ); D2D1_BITMAP_PROPERTIES bitmapProperties; bitmapProperties.pixelFormat = pixelFormat; m_pRenderTarget->GetDpi( &bitmapProperties.dpiX, &bitmapProperties.dpiY ); m_pRenderTarget->CreateBitmap(bitmapSize,bitmapProperties,&m_pBitmap); m_pRenderTarget->DrawBitmap(m_pBitmap); } } running = true; return true; } void video::terminate() { if (m_pBitmap) m_pBitmap->Release(); if (m_pRenderTarget) m_pRenderTarget->Release(); if (m_pD2DFactory) m_pD2DFactory->Release(); g_video = 0; running = false; if(g_pImg) { delete[] g_pImg; g_pImg = 0; } } //////////// drawing area constructor & destructor ///////////// drawing_area::drawing_area(int x, int y, int sizex, int sizey) : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(24), base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex), ptr32(g_pImg) { assert(x < g_sizex); assert(y < g_sizey); assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey); index = base_index; // current index } void drawing_area::update() { if(g_video->updating) { RECT r; r.left = start_x; r.right = start_x + size_x; r.top = start_y; r.bottom = start_y + size_y; InvalidateRect(g_hAppWnd, &r, false); } }
cpp