|
9 | 9 | package PDL::Graphics::TriD::Image; |
10 | 10 | use strict; |
11 | 11 | use warnings; |
12 | | -our @ISA=qw/PDL::Graphics::TriD::GObject/; |
| 12 | +use PDL::Graphics::TriD::Objects; |
| 13 | +use base qw/PDL::Graphics::TriD::GObject/; |
13 | 14 | use PDL::Lite; |
14 | 15 |
|
15 | | -sub get_valid_options { +{ |
16 | | - UseDefcols => 0, |
17 | | - Lighting => 0, |
18 | | -}} |
19 | | - |
20 | 16 | my $defaultvert = PDL->pdl([ |
21 | 17 | [0,0,0], |
22 | 18 | [1,0,0], |
23 | 19 | [1,1,0], |
24 | 20 | [0,1,0] |
25 | 21 | ]); |
| 22 | +sub get_valid_options { +{ |
| 23 | + UseDefcols => 0, |
| 24 | + Lighting => 0, |
| 25 | + FullScreen => 0, |
| 26 | + Points => $defaultvert, |
| 27 | +}} |
26 | 28 |
|
27 | 29 | # r,g,b = 0..1 |
28 | 30 | sub new { |
29 | | - my($type,$color,$opts) = @_; |
30 | | - my $im = PDL::Graphics::TriD::realcoords('COLOR',$color); |
31 | | - my $this = { |
32 | | - Im => $im, |
33 | | - Options => $opts, |
34 | | - Points => $defaultvert, |
35 | | - }; |
36 | | - if(defined $opts->{Points}) { |
37 | | - $this->{Points} = $opts->{Points}; |
38 | | - if("ARRAY" eq ref $this->{Points}) { |
39 | | - $this->{Points} = PDL->pdl($this->{Points}); |
40 | | - } |
41 | | - } |
42 | | - bless $this,$type; |
43 | | -} |
44 | | - |
45 | | -sub get_points { |
46 | | - return $_[0]->{Points}; |
47 | | -} |
48 | | - |
49 | | -# In the future, have this happen automatically by the ndarrays. |
50 | | -sub data_changed { |
51 | | - my($this) = @_; |
52 | | - $this->changed; |
| 31 | + my $opts = ref($_[-1]) eq 'HASH' ? pop : $_[0]->get_valid_options; |
| 32 | + my ($type,$color) = @_; |
| 33 | + my $points = PDL->topdl($opts->{Points} // $defaultvert); |
| 34 | + $type->SUPER::new($points, $color, $opts); |
53 | 35 | } |
54 | 36 |
|
55 | 37 | # ND ndarray -> 2D |
56 | 38 | sub flatten { |
57 | 39 | my ($this,$bin_align) = @_; |
58 | | - my @dims = $this->{Im}->dims; |
| 40 | + my @dims = $this->{Colors}->dims; |
59 | 41 | shift @dims; # get rid of the '3' |
60 | 42 | my $xd = $dims[0]; my $yd = $dims[1]; |
61 | 43 | my $xdr = $xd; my $ydr = $yd; |
@@ -93,7 +75,7 @@ sub flatten { |
93 | 75 |
|
94 | 76 | if($#dims > 1) { |
95 | 77 | # print "XALL: $xd $yd $xdr $ydr $txd $tyd\n"; |
96 | | -# print "DIMS: ",(join ',',$this->{Im}->dims),"\n"; |
| 78 | +# print "DIMS: ",(join ',',$this->{Colors}->dims),"\n"; |
97 | 79 | } |
98 | 80 |
|
99 | 81 | # $PDL::debug=1; |
@@ -131,7 +113,7 @@ sub flatten { |
131 | 113 | # $foop->dump; |
132 | 114 | print "ASSGNFOOP!\n" if $PDL::debug; |
133 | 115 |
|
134 | | - $foop .= $this->{Im}; |
| 116 | + $foop .= $this->{Colors}; |
135 | 117 | # print "P: $p\n"; |
136 | 118 | return wantarray() ? ($p,$xd,$yd,$txd,$tyd) : $p; |
137 | 119 | } |
|
0 commit comments