Skip to content

Commit 360b9fd

Browse files
committed
make Lattice only a container
1 parent ff7a15c commit 360b9fd

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,6 @@ sub PDL::Graphics::TriD::Spheres::gdraw {
156156
PDL::gl_spheres($points, 0.025, 15, 15);
157157
}
158158

159-
sub PDL::Graphics::TriD::Lattice::gdraw {
160-
my($this,$points) = @_;
161-
barf "Need 3D points AND colours"
162-
if grep $_->ndims < 3, $points, $this->{Colors};
163-
my $options = $this->{Options};
164-
my $shading = $options->{Shading};
165-
if ($shading == 0 or $options->{Lines}) {
166-
glDisable(GL_LIGHTING);
167-
PDL::gl_line_strip_col($points, $shading ? [0,0,0] : $this->{Colors});
168-
PDL::gl_line_strip_col($points->xchg(1,2), $shading ? [0,0,0] : $this->{Colors}->xchg(1,2));
169-
}
170-
}
171-
172159
sub PDL::Graphics::TriD::Triangles::gdraw {
173160
my ($this,$points) = @_;
174161
my $options = $this->{Options};

lib/PDL/Graphics/TriD/Objects.pm

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This provides the following class hierarchy:
1313
PDL::Graphics::TriD::Object base class for containers
1414
├ PDL::Graphics::TriD::Arrows lines with arrowheads
1515
├ PDL::Graphics::TriD::Trigrid polygons
16+
├ PDL::Graphics::TriD::Lattice colored lattice, maybe filled/shaded
1617
└ PDL::Graphics::TriD::GObject (abstract) base class for drawables
1718
1819
PDL::Graphics::TriD::GObject (abstract) base class for drawables
@@ -21,7 +22,6 @@ This provides the following class hierarchy:
2122
├ PDL::Graphics::TriD::Lines separate lines
2223
├ PDL::Graphics::TriD::LineStrip continuous paths
2324
├ PDL::Graphics::TriD::Triangles just polygons
24-
├ PDL::Graphics::TriD::Lattice colored lattice, maybe filled/shaded
2525
└ PDL::Graphics::TriD::Labels text labels
2626
2727
=head1 DESCRIPTION
@@ -195,11 +195,10 @@ sub cdummies { $_[1]->dummy(1,$_[2]->getdim(1)); }
195195
# 0 1 2 3 4,0,1,1,5,4 5,1,2,2,6,5 6,2,3,3,7,6
196196
package PDL::Graphics::TriD::Lattice;
197197
use PDL::Graphics::OpenGLQ;
198-
use base qw/PDL::Graphics::TriD::GObject/;
198+
use base qw/PDL::Graphics::TriD::Object/;
199199
sub cdummies {
200200
my $shading = $_[0]{Options}{Shading};
201201
!$shading ? $_[1]->dummy(1)->dummy(1) :
202-
$shading == 1 ? $_[1]->dummy(1,$_[2]->getdim(2)-1)->dummy(1,$_[2]->getdim(1)-1) :
203202
$_[1]->slice(":," . join ',', map "*$_", ($_[2]->dims)[1,2])
204203
}
205204
sub r_type {return "SURF2D";}
@@ -212,10 +211,14 @@ sub get_valid_options { +{
212211
ShowNormals => 0,
213212
}}
214213
sub new {
215-
my ($class,$points,$colors,$options) = @_;
216-
my $this = $class->SUPER::new($points,$colors,$options);
217-
($points, $options) = @$this{qw(Points Options)};
218-
if ($options->{Shading} or $options->{ShowNormals}) {
214+
my $options = ref($_[-1]) eq 'HASH' ? pop : {};
215+
my ($class,$points,$colors) = @_;
216+
my $this = $class->SUPER::new($options);
217+
$points = $this->normalise_as($class->r_type,$points);
218+
$colors = $this->normalise_as("COLOR",$colors,$points);
219+
$options = $this->{Options};
220+
my $shading = $options->{Shading};
221+
if ($shading) {
219222
my (undef, $x, $y, @extradims) = $points->dims;
220223
my $inds = PDL::ulong(0,1,$x,$x+1,$x,1)->slice(',*'.($x-1).',*'.($y-1));
221224
$inds = $inds->dupN(1,1,@extradims) if @extradims;
@@ -224,6 +227,11 @@ sub new {
224227
my %less = %$options; delete @less{qw(Lines)};
225228
$this->add_object(PDL::Graphics::TriD::Triangles->new($points->clump(1..2+@extradims), $faceidx, $colors, \%less));
226229
}
230+
if ($shading == 0 or $options->{Lines}) {
231+
my $lcolors = $shading ? $this->cdummies(PDL::float(0,0,0),$points) : $colors;
232+
$this->add_object(PDL::Graphics::TriD::LineStrip->new($points, $lcolors));
233+
$this->add_object(PDL::Graphics::TriD::LineStrip->new($points->xchg(1,2), $lcolors->xchg(1,2)));
234+
}
227235
$this;
228236
}
229237

0 commit comments

Comments
 (0)