GLI_FORCE_INLINE coord_linear_border<texelcoord_type, samplecoord_type> make_coord_linear_border(texelcoord_type const & TexelDim, samplecoord_type const & SampleCoord) { coord_linear_border<texelcoord_type, samplecoord_type> Coord; samplecoord_type const TexelDimF(TexelDim); samplecoord_type const TexelLast = TexelDimF - samplecoord_type(1); samplecoord_type const ScaledCoord(SampleCoord * TexelLast); samplecoord_type const ScaledCoordFloor(floor(ScaledCoord)); samplecoord_type const ScaledCoordCeil(ceil(ScaledCoord)); Coord.Blend = ScaledCoord - ScaledCoordFloor; Coord.TexelFloor = texelcoord_type(ScaledCoordFloor); Coord.TexelCeil = texelcoord_type(ScaledCoordCeil); Coord.UseTexelFloor = in_interval(Coord.TexelFloor, texelcoord_type(0), TexelDim - 1); Coord.UseTexelCeil = in_interval(Coord.TexelCeil, texelcoord_type(0), TexelDim - 1); return Coord; }
inline coord_nearest<texelcoord_type, samplecoord_type> make_coord_nearest(texelcoord_type const & TexelDim, samplecoord_type const & SampleCoord) { samplecoord_type const TexelLast(samplecoord_type(TexelDim) - samplecoord_type(1)); coord_nearest<texelcoord_type, samplecoord_type> Coord; Coord.Texel = texelcoord_type(round(SampleCoord * TexelLast)); Coord.UseTexel = in_interval(Coord.Texel, texelcoord_type(0), TexelDim - 1); return Coord; }
/* Extend the interval i to include the minimum and maximum of a 1-dimensional Bezier segment given by control points x0..x3. For efficiency, x0 in i is assumed as a precondition. */ static void bezier_limits(double x0, double x1, double x2, double x3, interval_t *i) { double a, b, c, d, r; double t, x; /* the min and max of a cubic curve segment are attained at one of at most 4 critical points: the 2 endpoints and at most 2 local extrema. We don't check the first endpoint, because all our curves are cyclic so it's more efficient not to check endpoints twice. */ /* endpoint */ extend(i, x3); /* optimization: don't bother calculating extrema if all control points are already in i */ if (in_interval(i, x1) && in_interval(i, x2)) { return; } /* solve for extrema. at^2 + bt + c = 0 */ a = -3*x0 + 9*x1 - 9*x2 + 3*x3; b = 6*x0 - 12*x1 + 6*x2; c = -3*x0 + 3*x1; d = b*b - 4*a*c; if (d > 0) { r = sqrt(d); t = (-b-r)/(2*a); if (t > 0 && t < 1) { x = bezier(t, x0, x1, x2, x3); extend(i, x); } t = (-b+r)/(2*a); if (t > 0 && t < 1) { x = bezier(t, x0, x1, x2, x3); extend(i, x); } } return; }
static texel_type call(texture_type const & Texture, fetch_type Fetch, samplecoord_type const & SampleCoordWrap, size_type Layer, size_type Face, interpolate_type Level, texel_type const & BorderColor) { size_type const LevelIndex = static_cast<size_type>(Level); texelcoord_type const TexelDim(Texture.dimensions(LevelIndex)); samplecoord_type const TexelLast(samplecoord_type(TexelDim) - samplecoord_type(1)); texelcoord_type const TexelCoord = texelcoord_type(round(SampleCoordWrap * TexelLast)); typename texelcoord_type::bool_type const UseTexelCoord = in_interval(TexelCoord, texelcoord_type(0), TexelDim - 1); texel_type Texel(BorderColor); if(all(UseTexelCoord)) Texel = Fetch(Texture, TexelCoord, Layer, Face, LevelIndex); return Texel; }
/* * Main. */ int main(int argc, char **argv) { int thread_count = 0; /* Number of threads that will run */ int tc_parsing_result = 0; /* thread_count parsing result */ int cspc_parsing_result = 0; /* crit_sect_pass_count parsing result */ pthread_t *threads = 0; /* List of created threads */ int *thread_ids = 0; /* List of created threads IDs */ pthread_attr_t thread_attrs; /* Thread attributes */ int i = 0; /* For loop counter */ int rc = 0; /* Return code */ /* Disable buffering on stdout */ setbuf(stdout, NULL); /* Program arguments check and parsing */ if (argc != 3) { /* Invalid number of arguments */ print_help(argv[0]); return EXIT_FAILURE; } /* There are 3 arguments, so parse them... */ tc_parsing_result = str2int(argv[1], &thread_count); cspc_parsing_result = str2int(argv[2], &crit_sect_pass_count); /* ...and check whether they are valid */ if (0 == tc_parsing_result || 0 == cspc_parsing_result || !in_interval(thread_count, 1, INT_MAX) || !in_interval(crit_sect_pass_count, 0, INT_MAX)) { /* Invalid arguments */ print_help(argv[0]); return EXIT_FAILURE; } /* Allocate dynamic memory for the desired number of threads */ threads = (pthread_t *) malloc(thread_count * sizeof(pthread_t)); thread_ids = (int *) malloc(thread_count * sizeof(int)); if (threads == NULL || thread_ids == NULL) { fprintf(stderr, "insufficient memory\n"); return EXIT_FAILURE; } /* Create attributes for all threads (to make all threads joinable) */ rc = pthread_attr_init(&thread_attrs); if (rc != 0) { /* Cleanup */ free(threads); free(thread_ids); fprintf(stderr, "pthread_attr_init() error: %d\n", rc); return EXIT_FAILURE; } rc = pthread_attr_setdetachstate(&thread_attrs, PTHREAD_CREATE_JOINABLE); if (rc != 0) { /* Cleanup */ free(threads); free(thread_ids); pthread_attr_destroy(&thread_attrs); fprintf(stderr, "pthread_attr_setdetachstate() error: %d\n", rc); return EXIT_FAILURE; } /* Create the selected number of threads */ for (i = 0; i < thread_count; ++i) { thread_ids[i] = i + 1; rc = pthread_create(&threads[i], &thread_attrs, thread_loop, &thread_ids[i]); if (rc != 0) { pthread_attr_destroy(&thread_attrs); fprintf(stderr, "pthread_create() error: %d\n", rc); return EXIT_FAILURE; } } /* Thread attributes are not necessary anymore, so destroy them */ pthread_attr_destroy(&thread_attrs); /* Wait until all threads terminates */ for (i = 0; i < thread_count; ++i) { rc = pthread_join(threads[i], NULL); if (rc != 0) { fprintf(stderr, "pthread_join() error: %d\n", rc); return EXIT_FAILURE; } } /* Cleanup */ free(threads); free(thread_ids); return EXIT_SUCCESS; }
/* bool BBox::intersect_triangle_left(ISectTri &tri, double plane, int axis) { if (tri.point0[axis]<=plane) return true; if (tri.point1[axis]<=plane) return true; if (tri.point2[axis]<=plane) return true; return false; } bool BBox::intersect_triangle_right(ISectTri &tri, double plane, int axis) { if (tri.point0[axis]>=plane) return true; if (tri.point1[axis]>=plane) return true; if (tri.point2[axis]>=plane) return true; return false; } */ bool BBox::intersect_triangle(ISectTri &tri) { Vec3f tmin_corner = min_corner - Vec3f(f_eps); Vec3f tmax_corner = max_corner + Vec3f(f_eps); // Vertex in box test: // If any of the triangle vertices are inside the box then // the triangle intersects the box if (in_interval(tmin_corner[0],tri.point0[0],tmax_corner[0]) && in_interval(tmin_corner[1],tri.point0[1],tmax_corner[1]) && in_interval(tmin_corner[2],tri.point0[2],tmax_corner[2])) return true; if (in_interval(tmin_corner[0],tri.point1[0],tmax_corner[0]) && in_interval(tmin_corner[1],tri.point1[1],tmax_corner[1]) && in_interval(tmin_corner[2],tri.point1[2],tmax_corner[2])) return true; if (in_interval(tmin_corner[0],tri.point2[0],tmax_corner[0]) && in_interval(tmin_corner[1],tri.point2[1],tmax_corner[1]) && in_interval(tmin_corner[2],tri.point2[2],tmax_corner[2])) return true; // Triangle outside box test: // If all of the triangle vertices are outside one of the planes // defining the sides of the box then the triangle can be trivially // rejected as outside int i; for(i=0;i<3;i++) if (tri.point0[i]<tmin_corner[i] && tri.point1[i]<tmin_corner[i] && tri.point2[i]<tmin_corner[i]) return false; for(i=0;i<3;i++) if (tri.point0[i]>tmax_corner[i] && tri.point1[i]>tmax_corner[i] && tri.point2[i]>tmax_corner[i]) return false; // Triangle edges - box intersection test if (intersect_edge_box(tri.point0, tri.point1)) return true; if (intersect_edge_box(tri.point1, tri.point2)) return true; if (intersect_edge_box(tri.point2, tri.point0)) return true; // Box diagonal - triangle intersection test, 4 tests in total Vec3f corner0; Vec3f corner1; Vec3f tmin_corner_e = tmin_corner; Vec3f tmax_corner_e = tmax_corner; corner0.set(tmin_corner_e[0],tmin_corner_e[1],tmin_corner_e[2]); corner1.set(tmax_corner_e[0],tmax_corner_e[1],tmax_corner_e[2]); if (ray_triangle(corner0, corner1, tri)) return true; corner0.set(tmax_corner_e[0],tmin_corner_e[1],tmin_corner_e[2]); corner1.set(tmin_corner_e[0],tmax_corner_e[1],tmax_corner_e[2]); if (ray_triangle(corner0, corner1, tri)) return true; corner0.set(tmin_corner_e[0],tmax_corner_e[1],tmin_corner_e[2]); corner1.set(tmax_corner_e[0],tmin_corner_e[1],tmax_corner_e[2]); if (ray_triangle(corner0, corner1, tri)) return true; corner0.set(tmin_corner_e[0],tmin_corner_e[1],tmax_corner_e[2]); corner1.set(tmax_corner_e[0],tmax_corner_e[1],tmin_corner_e[2]); if (ray_triangle(corner0, corner1, tri)) return true; // None succeded return false; }
bool ZoneBox::contain_point (const double z, const double x, const double y) const { return in_interval (z, *bottom, *top) && in_interval (x, *left, *right) && in_interval (y, *front, *back); }