/* * radiance interface */ #include "config.h" #include #include #include "rad_int.h" rad_int::rad_int (ostream &out) t_no : o(out) { } rad_int::~rad_int () t_no { } void rad_int::begin_fig () t_no { x1 = 1e10; y1 = 1e10; z1 = 1e10; x2 = -1e10; y2 = -1e10; z2 = -1e10; } void rad_int::end_fig () t_no { x1 -= 0.1; y1 -= 0.1; z1 -= 0.1; x2 += 0.1; y2 += 0.1; z2 += 0.2; } void rad_int::clip (const vec &v) t_no { if (x1 > v[0]) x1 = v[0]; if (y1 > v[1]) y1 = v[1]; if (z1 > v[2]) z1 = v[2]; if (x2 < v[0]) x2 = v[0]; if (y2 < v[1]) y2 = v[1]; if (z2 < v[2]) z2 = v[2]; } void rad_int::check_attrs (const attribute_set &attr) t_err { width = attr ("width",1); material = attr ("material", "plain"); } void rad_int::segment (const point &a, const point &b) t_err { check_attrs (a.attr); clip (a.v); clip (b.v); o << material << " cylinder cylinder\n" << "0\n0\n7\n" << "\t" << a.v[0] << "\t" << a.v[1] << "\t" << a.v[2] << endl << "\t" << b.v[0] << "\t" << b.v[1] << "\t" << b.v[2] << endl << "\t" << width << endl << endl; } void rad_int::object (const points &v) t_err { points p = v; // cerr << "polygon "; for (points::const_iterator j = v.begin (); j != v.end (); j++) cerr << j->first << " "; cerr << endl; if (v.size () < 3) return; if (winding (p) < 0) reverse (p.begin (), p.end ()); check_attrs (p.front ().attr); points::const_iterator a, b, c; c = p.begin (); a = c++; b = c++; clip (a->v); clip (b->v); while (c != p.end ()) { clip (c->v); o << material << " polygon triangle\n" << "0\n0\n9\n" << "\t" << a->v[0] << "\t" << a->v[1] << "\t" << a->v[2] << endl << "\t" << b->v[0] << "\t" << b->v[1] << "\t" << b->v[2] << endl << "\t" << c->v[0] << "\t" << c->v[1] << "\t" << c->v[2] << endl; ++b; ++c; } #if 0 o << material << " polygon polygon\n" << "0\n0\n" << v.size ()*3 << endl; for(points::const_iterator i = v.begin (); i != v.end(); ++i) { // check_attrs (i->attr); o << "\t" << i->v[0] << "\t" << i->v[1] << "\t" << i->v[2] << endl; clip (i->v); } #endif o << endl; }