Skip to content

Commit c508bcb

Browse files
committed
make Lattice contain Triangles instead of draw itself
1 parent 29cf3fe commit c508bcb

File tree

2 files changed

+3
-40
lines changed

2 files changed

+3
-40
lines changed

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -162,46 +162,11 @@ sub PDL::Graphics::TriD::Lattice::gdraw {
162162
if grep $_->ndims < 3, $points, $this->{Colors};
163163
my $options = $this->{Options};
164164
my $shading = $options->{Shading};
165-
my $faces = !defined $this->{Faceidx} ? undef : $points->clump(1..$points->ndims-1)->dice_axis(1,$this->{Faceidx}->flat)->splitdim(1,3);
166-
my $colours = !defined $this->{Faceidx} ? undef : $this->{Colors}->clump(1..$this->{Colors}->ndims-1)->dice_axis(1,$this->{Faceidx}->flat)->splitdim(1,3);
167-
if ($shading) {
168-
glShadeModel($shading == 1 ? GL_FLAT : GL_SMOOTH);
169-
my $f = 'PDL::gl_triangles';
170-
$f .= '_wn' if $shading > 2;
171-
{ no strict 'refs'; $f = \&$f; }
172-
if ($shading > 2) { glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); }
173-
my $tmpn = $shading <= 2 ? undef : $options->{Smooth}
174-
? $this->{VertexNormals}->dice_axis(1,$this->{Faceidx}->flat)
175-
->splitdim(1,$this->{Faceidx}->dim(0)) : $this->{FaceNormals}->dummy(1,3);
176-
$f->($faces, $shading > 2 ? $tmpn : (), $colours);
177-
if ($shading > 2) { glDisable(GL_COLOR_MATERIAL); }
178-
}
179165
if ($shading == 0 or $options->{Lines}) {
180166
glDisable(GL_LIGHTING);
181167
PDL::gl_line_strip_col($points, $shading ? [0,0,0] : $this->{Colors});
182168
PDL::gl_line_strip_col($points->xchg(1,2), $shading ? [0,0,0] : $this->{Colors}->xchg(1,2));
183169
}
184-
if ($options->{ShowNormals}) {
185-
die "No normals to show!" if !grep defined $this->{$_}, qw(FaceNormals VertexNormals);
186-
if (defined $this->{VertexNormals}) {
187-
my $points_clumped = $points->clump(1..$points->ndims-1);
188-
my $arrows = $points_clumped->append($points_clumped + $this->{VertexNormals}*0.1)->splitdim(0,3)->clump(1,2);
189-
glDisable(GL_LIGHTING);
190-
my ($tv, $ti) = PDL::Graphics::OpenGLQ::gen_arrowheads($arrows,sequence(ulong,2,$points_clumped->dim(1))->t->dog,
191-
0.5, 0.2);
192-
PDL::gl_triangles($tv->dice_axis(1,$ti)->splitdim(1,3), [1,1,1]);
193-
PDL::gl_lines_col($arrows,[1,1,1]);
194-
}
195-
if (defined $this->{FaceNormals}) {
196-
my $facecentres = $faces->transpose->avgover;
197-
my $facearrows = $facecentres->append($facecentres + $this->{FaceNormals}*0.1)->splitdim(0,3)->clump(1,2);
198-
glDisable(GL_LIGHTING);
199-
my ($tv, $ti) = PDL::Graphics::OpenGLQ::gen_arrowheads($facearrows,sequence(ulong,2,$facecentres->dim(1))->t->dog,
200-
0.5, 0.2);
201-
PDL::gl_triangles($tv->dice_axis(1,$ti)->splitdim(1,3), [0.5,0.5,0.5]);
202-
PDL::gl_lines_col($facearrows,[0.5,0.5,0.5]);
203-
}
204-
}
205170
}
206171

207172
sub PDL::Graphics::TriD::Triangles::gdraw {

lib/PDL/Graphics/TriD/Objects.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ sub cdummies { $_[1]->dummy(1,$_[2]->getdim(1)); }
200200
package PDL::Graphics::TriD::Lattice;
201201
use PDL::Graphics::OpenGLQ;
202202
use base qw/PDL::Graphics::TriD::GObject/;
203-
use fields qw/VertexNormals Faceidx FaceNormals/;
204203
sub cdummies {
205204
my $shading = $_[0]{Options}{Shading};
206205
!$shading ? $_[1]->dummy(1)->dummy(1) :
@@ -225,10 +224,9 @@ sub new {
225224
my $inds = PDL::ulong(0,1,$x,$x+1,$x,1)->slice(',*'.($x-1).',*'.($y-1));
226225
$inds = $inds->dupN(1,1,@extradims) if @extradims;
227226
my $indadd = PDL->sequence($x,$y,@extradims)->slice('*1,:-2,:-2');
228-
my $faceidx = $this->{Faceidx} = ($inds + $indadd)->splitdim(0,3)->clump(1..3+@extradims);
229-
my ($fn, $vn) = triangle_normals($points->clump(1..2+@extradims), $faceidx);
230-
$this->{VertexNormals} = $vn if $options->{Smooth} or $options->{ShowNormals};
231-
$this->{FaceNormals} = $fn if !$options->{Smooth} or $options->{ShowNormals};
227+
my $faceidx = ($inds + $indadd)->splitdim(0,3)->clump(1..3+@extradims);
228+
my %less = %$options; delete @less{qw(Lines)};
229+
$this->add_object(PDL::Graphics::TriD::Triangles->new($points->clump(1..2+@extradims), $faceidx, $colors, \%less));
232230
}
233231
$this;
234232
}

0 commit comments

Comments
 (0)