void test_transformations(double phi, double theta, double r) { typedef bg::model::point<T, 3, bg::cs::cartesian> cartesian_type; cartesian_type p; // 1: using spherical coordinates { typedef bg::model::point<T, 3, bg::cs::spherical<DegreeOrRadian> > spherical_type; spherical_type sph1; assign_values(sph1, phi, theta, r); BOOST_CHECK(transform(sph1, p)); spherical_type sph2; BOOST_CHECK(transform(p, sph2)); BOOST_CHECK_CLOSE(bg::get<0>(sph1), bg::get<0>(sph2), 0.001); BOOST_CHECK_CLOSE(bg::get<1>(sph1), bg::get<1>(sph2), 0.001); } // 2: using spherical coordinates on unit sphere { typedef bg::model::point<T, 2, bg::cs::spherical<DegreeOrRadian> > spherical_type; spherical_type sph1, sph2; assign_values(sph1, phi, theta); BOOST_CHECK(transform(sph1, p)); BOOST_CHECK(transform(p, sph2)); BOOST_CHECK_CLOSE(bg::get<0>(sph1), bg::get<0>(sph2), 0.001); BOOST_CHECK_CLOSE(bg::get<1>(sph1), bg::get<1>(sph2), 0.001); } }
inline void test_null_distance_3d() { Point p; bg::assign_values(p, 1, 2, 4); Box b; assign_values(b, 1, 2, 3, 4, 5, 6); typedef bg::strategy::distance::pythagoras_point_box<> pythagoras_pb_type; typedef typename bg::strategy::distance::services::return_type < pythagoras_pb_type, Point, Box >::type return_type; pythagoras_pb_type pythagoras_pb; return_type result = pythagoras_pb.apply(p, b); BOOST_CHECK_EQUAL(result, return_type(0)); bg::assign_values(p, 1, 3, 4); result = pythagoras_pb.apply(p, b); BOOST_CHECK_EQUAL(result, return_type(0)); bg::assign_values(p, 2, 3, 4); result = pythagoras_pb.apply(p, b); BOOST_CHECK_EQUAL(result, return_type(0)); }
inline void test_arbitrary_3d() { Box b; assign_values(b, 0, 0, 0, 1, 2, 3); Point p; bg::assign_values(p, 9, 8, 7); { typedef bg::strategy::distance::pythagoras_point_box<> strategy_type; typedef typename bg::strategy::distance::services::return_type < strategy_type, Point, Box >::type return_type; strategy_type strategy; return_type result = strategy.apply(p, b); BOOST_CHECK_CLOSE(result, return_type(10.77032961427), 0.001); } { // Check comparable distance typedef bg::strategy::distance::comparable::pythagoras_point_box<> strategy_type; typedef typename bg::strategy::distance::services::return_type < strategy_type, Point, Box >::type return_type; strategy_type strategy; return_type result = strategy.apply(p, b); BOOST_CHECK_EQUAL(result, return_type(116)); } }
inline void test_axis_3d() { Box b; assign_values(b, 0, 0, 0, 1, 1, 1); Point p; bg::assign_values(p, 2, 0, 0); typedef bg::strategy::distance::pythagoras_point_box<> pythagoras_pb_type; typedef typename bg::strategy::distance::services::return_type < pythagoras_pb_type, Point, Box >::type return_type; pythagoras_pb_type pythagoras_pb; return_type result = pythagoras_pb.apply(p, b); BOOST_CHECK_EQUAL(result, return_type(1)); bg::assign_values(p, 0, 2, 0); result = pythagoras_pb.apply(p, b); BOOST_CHECK_EQUAL(result, return_type(1)); bg::assign_values(p, 0, 0, 2); result = pythagoras_pb.apply(p, b); BOOST_CHECK_CLOSE(result, return_type(1), 0.001); }
static inline void init_rescale_policy(Geometry1 const& geometry1, Geometry2 const& geometry2, Point& min_point, RobustPoint& min_robust_point, Factor& factor) { // Get bounding boxes model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry1); model::box<Point> env2 = geometry::return_envelope<model::box<Point> >(geometry2); geometry::expand(env, env2); // TODO: merge this with implementation above // Scale this to integer-range typedef typename promote_floating_point < typename geometry::coordinate_type<Point>::type >::type num_type; num_type const diff = boost::numeric_cast<num_type>(detail::get_max_size(env)); num_type const range = 10000000.0; // Define a large range to get precise integer coordinates num_type const half = 0.5; factor = math::equals(diff, num_type()) ? 1 : boost::numeric_cast<num_type>( boost::numeric_cast<boost::long_long_type>(half + range / diff)); // Assign input/output minimal points detail::assign_point_from_index<0>(env, min_point); num_type const two = 2; boost::long_long_type const min_coordinate = boost::numeric_cast<boost::long_long_type>(-range / two); assign_values(min_robust_point, min_coordinate, min_coordinate); }
/* Main asks the user to input a card and then calls assign_values */ int main() { while (card_name[0] != 'X') { puts(prompt_for_user); fgets(card_name, 3, stdin); printf("The card name is %s\n", card_name); assign_values(card_name, &value); } return 0; }
int Poker(void) { cdhs suit; int i, pips; card deck[52]; for (i = 0; i < 52; ++i) { pips = i % 13 + 1; if (i < 13) suit = clubs; else if (i < 26) suit = diamonds; else if (i < 39) suit = hearts; else suit = spades; deck[i] = assign_values(pips, suit); } play_poker(deck); return 0; }
inline void test_services() { namespace bgsd = bg::strategy::distance; namespace services = bg::strategy::distance::services; { // Compile-check if there is a strategy for this type typedef typename services::default_strategy < bg::point_tag, bg::box_tag, Point, Box >::type pythagoras_pb_strategy_type; // reverse geometry tags typedef typename services::default_strategy < bg::box_tag, bg::point_tag, Box, Point >::type reversed_pythagoras_pb_strategy_type; boost::ignore_unused < pythagoras_pb_strategy_type, reversed_pythagoras_pb_strategy_type >(); } Point p; bg::assign_values(p, 1, 2, 3); Box b; assign_values(b, 4, 5, 6, 14, 15, 16); double const sqr_expected = 3*3 + 3*3 + 3*3; // 27 double const expected = sqrt(sqr_expected); // sqrt(27)=5.1961524227 // 1: normal, calculate distance: typedef bgsd::pythagoras_point_box<CalculationType> strategy_type; BOOST_CONCEPT_ASSERT ( (bg::concepts::PointDistanceStrategy<strategy_type, Point, Box>) ); typedef typename bgsd::services::return_type < strategy_type, Point, Box >::type return_type; strategy_type strategy; return_type result = strategy.apply(p, b); BOOST_CHECK_CLOSE(result, return_type(expected), 0.001); // 2: the strategy should return the same result if we reverse parameters // result = strategy.apply(p2, p1); // BOOST_CHECK_CLOSE(result, return_type(expected), 0.001); // 3: "comparable" to construct a "comparable strategy" for Point/Box // a "comparable strategy" is a strategy which does not calculate the exact distance, but // which returns results which can be mutually compared (e.g. avoid sqrt) // 3a: "comparable_type" typedef typename services::comparable_type < strategy_type >::type comparable_type; // 3b: "get_comparable" comparable_type comparable = bgsd::services::get_comparable < strategy_type >::apply(strategy); typedef typename bgsd::services::return_type < comparable_type, Point, Box >::type comparable_return_type; comparable_return_type c_result = comparable.apply(p, b); BOOST_CHECK_CLOSE(c_result, return_type(sqr_expected), 0.001); // 4: the comparable_type should have a distance_strategy_constructor as well, // knowing how to compare something with a fixed distance comparable_return_type c_dist5 = services::result_from_distance < comparable_type, Point, Box >::apply(comparable, 5.0); comparable_return_type c_dist6 = services::result_from_distance < comparable_type, Point, Box >::apply(comparable, 6.0); // If this is the case: BOOST_CHECK(c_dist5 < c_result && c_result < c_dist6); // This should also be the case return_type dist5 = services::result_from_distance < strategy_type, Point, Box >::apply(strategy, 5.0); return_type dist6 = services::result_from_distance < strategy_type, Point, Box >::apply(strategy, 6.0); BOOST_CHECK(dist5 < result && result < dist6); }
//Main--------------------------------------------------------------------------------------------- int main(int argc, char* argv[]) { //Variables from MyModel.h--------------------------------------------------------------------- /* create a spherical object */ SPHERE obj1 = { 1.0, 1.0, 1.0, /* center of the circle */ 1.0, /* radius of the circle */ 0.75 }; /* diffuse reflection coefficient */ /* create a polygon object */ POLY4 obj2 = { 0.0, 0.0, 0.0, /* v0 */ 0.0, 0.0, 2.0, /* v1 */ 2.0, 0.0, 2.0, /* v2 */ 2.0, 0.0, 0.0, /* v3 */ 0.0, 1.0, 0.0, /* normal of the polygon */ 0.8 }; /* diffuse reflection coefficient */ unsigned char img[ROWS][COLS]; float xmin = 0.0175; float ymin = -0.0175; float xmax = -0.0175; float ymax = 0.0175; float focal = 0.05; /* focal length simulating 50 mm lens */ /* definition of the camera parameters */ float VRP[3] = { 1.0, 2.0, 3.5 }; float VPN[3] = { 0.0, -1.0, -2.5 }; float VUP[3] = { 0.0, 1.0, 0.0 }; /* definition of light source */ float LRP[3] = { -10.0, 10.0, 2.0 }; /* light position */ float Ip = 200.0; /* intensity of the point light source */ //--------------------------------------------------------------------------------------------- int i, j; int c; Xform3d TIN1, RT1; Xform3d Mcw; Point3d Pvpn, Pvup, Pvrp; Pvpn = assign_values(VPN); Pvup = assign_values(VUP); Pvrp = assign_values(VRP); translationInverse(VRP, TIN1); rotationTranspose(&Pvpn, &Pvup, RT1); multXforms(TIN1, RT1, Mcw); // initiate buffer for (i = 0; i < ROWS; i++) { for (j = 0; j < COLS; j++) { img[i][j] = 0; } } for (i = 0; i < ROWS; i++) { for (j = 0; j < COLS; j++) { Ray V; V.a = (Point3dPtr)malloc(sizeof(Point3d)); V.b = (Point3dPtr)malloc(sizeof(Point3d)); rayConstruction(i, j, focal, xmin, xmax, ymin, ymax, Mcw, &Pvrp, &V);// construct Ray V c = rayTracing(V, obj1, obj2, LRP, Ip); img[i][j] = c; free(V.a); free(V.b); } } // function output the final image to binary, then change to tiff or other format by using third party tools, such as Photoshop etc. FILE * fp; fp = fopen("Ray.raw", "wb"); fwrite(img, sizeof(unsigned char), sizeof(img), fp); fclose(fp); return 0; }
//Ray and Polygon Intersection--------------------------------------------------------------------------------------------------- float rayPolygonIntersection(Ray ray, POLY4 poly, Point3dPtr n2, Point3dPtr interp2, float *kd2) { float t; float temp1, temp2; float projectPlane[4][2]; float projPoint[2]; float p0[2]; float p1[2]; float p2[2]; float p3[2]; float Array[4]; int c; float D; Point3d np; D = -1 * (poly.N[0] * poly.v[0][0] + poly.N[1] * poly.v[0][1] + poly.N[2] * poly.v[0][2]); // Put Vertax #1 to calculate value of D np = assign_values(poly.N); temp1 = dotProduct(&np, ray.a) + D; temp2 = dotProduct(&np, ray.b); t = -1 * (temp1 / temp2); *kd2 = poly.kd; // The surface normal------------------------------------------------------------------------------------------------ n2->x = poly.N[0]; n2->y = poly.N[1]; n2->z = poly.N[2]; // The intersection point-------------------------------------------------------------------------------------------- interp2->x = ray.a->x + ray.b->x*t; interp2->y = ray.a->y + ray.b->y*t; interp2->z = ray.a->z + ray.b->z*t; // Get Projection of intersection point-------------------------------------------------------------------------------------------- findProjPoint(poly.N, interp2, projPoint); // Get a Projection Plane------------------------------------------------------------------------------------------------------ findProjPlane(poly.N, poly.v, projectPlane); float S0[4]; float S1[4]; S0[0] = projectPlane[0][0]; S0[1] = projectPlane[1][0]; S0[2] = projectPlane[2][0]; S0[3] = projectPlane[3][0]; S1[0] = projectPlane[0][1]; S1[1] = projectPlane[1][1]; S1[2] = projectPlane[2][1]; S1[3] = projectPlane[3][1]; c = pnpoly(4, S0, S1, projPoint[0], projPoint[1]); if ((temp2 > 0.0f) || (temp2 = 0.0f)) return 0.0f; // Ray and Polygon parallel, intersection rejection else { if (c != 0) return t; //The distance else return 0.0f; } }
void get_dc(int dc_direct_resolution, int *number_direct_coefficients) /* calculates a set of daylight coefficients depending on site */ { float patches_per_row[8][2]; int i=0, j=0,k=0; double angle_unit; /* Tregenza distribution */ patches_per_row[0][0]=90; patches_per_row[0][1]=1; patches_per_row[1][0]=84; patches_per_row[1][1]=30; patches_per_row[2][0]=72; patches_per_row[2][1]=30; /* 24 */ patches_per_row[3][0]=60; patches_per_row[3][1]=24;/* 28 */ patches_per_row[4][0]=48; patches_per_row[4][1]=24; patches_per_row[5][0]=36; patches_per_row[5][1]=18; patches_per_row[6][0]=24; patches_per_row[6][1]=12; patches_per_row[7][0]=12; patches_per_row[7][1]=6; /* calculate diffuse dcs */ k=0; for(i=1; i<= 7; i++){ angle_unit=360.0/patches_per_row[i][1]; for( j=0; j<patches_per_row[i][1]; j++){ diffuse_pts[k][0]=patches_per_row[i][0]; diffuse_pts[k][1]=(float)(angle_unit*(j + 0.5)); k++; } } diffuse_pts[144][0]=0; diffuse_pts[144][1]=0; /* get limits for the altitude angles of the sun */ if (dc_direct_resolution==1){ assign_values(12,21, number_direct_coefficients); }else{ for(j=0; j< 24; j++){ for(i=1; i< 13; i++){ direct_calendar[i][j][0] = (float)j; direct_calendar[i][j][1]=0; direct_calendar[i][j][2]=0; direct_calendar[i][j][3]=0; } } /*Julian date of December 21: */ assign_values(12,21,number_direct_coefficients); /*Julian date of February 21: */ assign_values(2,21,number_direct_coefficients); /*Julian date of March 21: */ assign_values(3,21,number_direct_coefficients); /*Julian date of April 21: */ assign_values(4,21,number_direct_coefficients); /*Julian date of June 21: */ assign_values(6,21,number_direct_coefficients); } }