Skip to content

Commit e905044

Browse files
committed
::Image use inheritance
1 parent 299768e commit e905044

File tree

2 files changed

+17
-35
lines changed

2 files changed

+17
-35
lines changed

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ sub PDL::Graphics::TriD::Contours::gdraw {
210210
# A special construct which always faces the display and takes the entire window
211211
# The quick method is to use texturing for the good effect.
212212
sub PDL::Graphics::TriD::Image::gdraw {
213-
my($this,$vert) = @_;
213+
my ($this,$vert) = @_;
214214
my ($p,$xd,$yd,$txd,$tyd) = $this->flatten(1); # do binary alignment
215-
if(!defined $vert) {$vert = $this->{Points}}
215+
$vert //= $this->{Points};
216216
barf "Need 3,4 vert"
217217
if grep $_->dim(1) < 4 || $_->dim(0) != 3, $vert;
218218
if ($this->{Options}{FullScreen}) {

lib/PDL/Graphics/TriD/Image.pm

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,35 @@
99
package PDL::Graphics::TriD::Image;
1010
use strict;
1111
use warnings;
12-
our @ISA=qw/PDL::Graphics::TriD::GObject/;
12+
use PDL::Graphics::TriD::Objects;
13+
use base qw/PDL::Graphics::TriD::GObject/;
1314
use PDL::Lite;
1415

15-
sub get_valid_options { +{
16-
UseDefcols => 0,
17-
Lighting => 0,
18-
}}
19-
2016
my $defaultvert = PDL->pdl([
2117
[0,0,0],
2218
[1,0,0],
2319
[1,1,0],
2420
[0,1,0]
2521
]);
22+
sub get_valid_options { +{
23+
UseDefcols => 0,
24+
Lighting => 0,
25+
FullScreen => 0,
26+
Points => $defaultvert,
27+
}}
2628

2729
# r,g,b = 0..1
2830
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);
5335
}
5436

5537
# ND ndarray -> 2D
5638
sub flatten {
5739
my ($this,$bin_align) = @_;
58-
my @dims = $this->{Im}->dims;
40+
my @dims = $this->{Colors}->dims;
5941
shift @dims; # get rid of the '3'
6042
my $xd = $dims[0]; my $yd = $dims[1];
6143
my $xdr = $xd; my $ydr = $yd;
@@ -93,7 +75,7 @@ sub flatten {
9375

9476
if($#dims > 1) {
9577
# 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";
9779
}
9880

9981
# $PDL::debug=1;
@@ -131,7 +113,7 @@ sub flatten {
131113
# $foop->dump;
132114
print "ASSGNFOOP!\n" if $PDL::debug;
133115

134-
$foop .= $this->{Im};
116+
$foop .= $this->{Colors};
135117
# print "P: $p\n";
136118
return wantarray() ? ($p,$xd,$yd,$txd,$tyd) : $p;
137119
}

0 commit comments

Comments
 (0)