our
@ISA
=qw/PDL::Graphics::TriD::Object/;
my
$defaultvert
= PDL->pdl([
[0,0,0],
[1,0,0],
[1,1,0],
[0,1,0]
]);
sub
new {
my
(
$type
,
$color
,
$opts
) =
@_
;
my
$im
= PDL::Graphics::TriD::realcoords(
'COLOR'
,
$color
);
my
$this
= {
Im
=>
$im
,
Opts
=>
$opts
,
Points
=>
$defaultvert
,
};
if
(
defined
$opts
->{Points}) {
$this
->{Points} =
$opts
->{Points};
if
(
"ARRAY"
eq
ref
$this
->{Points}) {
$this
->{Points} = PDL->pdl(
$this
->{Points});
}
}
bless
$this
,
$type
;
}
sub
get_points {
return
$_
[0]->{Points};
}
sub
data_changed {
my
(
$this
) =
@_
;
$this
->changed;
}
sub
flatten {
my
(
$this
,
$bin_align
) =
@_
;
my
@dims
=
$this
->{Im}->dims;
shift
@dims
;
my
$xd
=
$dims
[0];
my
$yd
=
$dims
[1];
my
$xdr
=
$xd
;
my
$ydr
=
$yd
;
my
$ind
= 0;
my
$xm
= 0;
my
$ym
= 0;
for
(
@dims
[2..
$#dims
]) {
if
(
$ind
% 2 == 0) {
$xd
++;
$xd
*=
$_
;
$xdr
++;
$xdr
*=
$_
;
$xm
++;
}
else
{
$yd
++;
$yd
*=
$_
;
$ydr
++;
$ydr
*=
$_
;
$ym
++;
}
$ind
++;
}
$xd
-=
$xm
;
$yd
-=
$ym
;
my
(
$txd
,
$tyd
,
$xxd
,
$yyd
);
if
(
$bin_align
) {
for
(
$txd
= 0;
$txd
< 12 and 2*
*$txd
<
$xdr
;
$txd
++) {};
for
(
$tyd
= 0;
$tyd
< 12 and 2*
*$tyd
<
$ydr
;
$tyd
++) {};
$txd
= 2*
*$txd
;
$tyd
= 2*
*$tyd
;
$xxd
= (
$xdr
>
$txd
?
$xdr
:
$txd
);
$yyd
= (
$ydr
>
$tyd
?
$ydr
:
$tyd
);
if
(
$#dims
> 1) {
}
}
else
{
$xxd
=
$txd
=
$xdr
;
$yyd
=
$tyd
=
$ydr
;
}
my
$p
= PDL->zeroes(PDL::float(),3,
$xxd
,
$yyd
);
if
(
defined
$this
->{Opts}{Bg}) {
$p
.=
$this
->{Opts}{Bg};
}
my
$foop
=
$p
->slice(
":,0:"
.(
$xdr
-1).
",0:"
.(
$ydr
-1));
$ind
=
$#dims
;
my
$firstx
= 1;
my
$firsty
= 1;
my
$spi
;
for
(
@dims
[
reverse
(2..
$#dims
)]) {
if
(
$ind
% 2 == 0) {
$spi
=
$foop
->getdim(1)/
$_
;
$foop
=
$foop
->splitdim(1,
$spi
)->slice(
":,0:-2"
)->
mv(2,3);
}
else
{
$spi
=
$foop
->getdim(2)/
$_
;
$foop
=
$foop
->splitdim(2,
$spi
)->slice(
":,:,0:-2"
);
}
$ind
++;
}
print
"ASSGNFOOP!\n"
if
$PDL::debug
;
$foop
.=
$this
->{Im};
return
wantarray
() ? (
$p
,
$xd
,
$yd
,
$txd
,
$tyd
) :
$p
;
}
sub
toimage {
my
(
$this
) =
@_
;
return
$this
->flatten(0);
}
1;