ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/lsys/rad_int.cpp
Revision: 1.1
Committed: Thu Nov 6 14:31:24 2008 UTC (15 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 * radiance interface
3 */
4
5 #include "config.h"
6
7 #include <iostream>
8 #include <algorithm>
9
10 #include "rad_int.h"
11
12 rad_int::rad_int (ostream &out) t_no
13 : o(out)
14 {
15 }
16
17 rad_int::~rad_int () t_no
18 {
19 }
20
21 void rad_int::begin_fig () t_no
22 {
23 x1 = 1e10; y1 = 1e10; z1 = 1e10;
24 x2 = -1e10; y2 = -1e10; z2 = -1e10;
25 }
26
27 void rad_int::end_fig () t_no
28 {
29 x1 -= 0.1; y1 -= 0.1; z1 -= 0.1;
30 x2 += 0.1; y2 += 0.1; z2 += 0.2;
31 }
32
33 void rad_int::clip (const vec &v) t_no
34 {
35 if (x1 > v[0]) x1 = v[0];
36 if (y1 > v[1]) y1 = v[1];
37 if (z1 > v[2]) z1 = v[2];
38
39 if (x2 < v[0]) x2 = v[0];
40 if (y2 < v[1]) y2 = v[1];
41 if (z2 < v[2]) z2 = v[2];
42 }
43
44 void rad_int::check_attrs (const attribute_set &attr) t_err
45 {
46 width = attr ("width",1);
47 material = attr ("material", "plain");
48 }
49
50 void rad_int::segment (const point &a, const point &b) t_err
51 {
52 check_attrs (a.attr);
53
54 clip (a.v);
55 clip (b.v);
56
57 o << material << " cylinder cylinder\n"
58 << "0\n0\n7\n"
59 << "\t" << a.v[0] << "\t" << a.v[1] << "\t" << a.v[2] << endl
60 << "\t" << b.v[0] << "\t" << b.v[1] << "\t" << b.v[2] << endl
61 << "\t" << width << endl << endl;
62 }
63
64 void rad_int::object (const points &v) t_err
65 {
66 points p = v;
67 // cerr << "polygon "; for (points::const_iterator j = v.begin (); j != v.end (); j++) cerr << j->first << " "; cerr << endl;
68 if (v.size () < 3)
69 return;
70
71 if (winding (p) < 0)
72 reverse (p.begin (), p.end ());
73
74 check_attrs (p.front ().attr);
75
76 points::const_iterator a, b, c;
77 c = p.begin ();
78 a = c++;
79 b = c++;
80
81 clip (a->v);
82 clip (b->v);
83 while (c != p.end ())
84 {
85 clip (c->v);
86 o << material << " polygon triangle\n"
87 << "0\n0\n9\n"
88 << "\t" << a->v[0] << "\t" << a->v[1] << "\t" << a->v[2] << endl
89 << "\t" << b->v[0] << "\t" << b->v[1] << "\t" << b->v[2] << endl
90 << "\t" << c->v[0] << "\t" << c->v[1] << "\t" << c->v[2] << endl;
91 ++b; ++c;
92 }
93
94 #if 0
95 o << material << " polygon polygon\n"
96 << "0\n0\n" << v.size ()*3 << endl;
97
98 for(points::const_iterator i = v.begin (); i != v.end(); ++i)
99 {
100 // check_attrs (i->attr);
101 o << "\t" << i->v[0] << "\t" << i->v[1] << "\t" << i->v[2] << endl;
102 clip (i->v);
103 }
104 #endif
105
106 o << endl;
107 }
108
109