Skip to content

Commit eb32a92

Browse files
committed
incorporate SLattice_S into Lattice with options
1 parent 57dd95b commit eb32a92

File tree

7 files changed

+26
-51
lines changed

7 files changed

+26
-51
lines changed

demos/DemoTkTriD.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ sub Torusdemos{
306306
{Shading=>2}
307307
);
308308
}else{
309-
$data=PDL::Graphics::TriD::SLattice_S->new([$x,$y,$z]);
309+
$data=PDL::Graphics::TriD::Lattice->new([$x,$y,$z], {Shading=>3, Lighting=>1, Smooth=>1});
310310
}
311311
$graph->add_dataseries($data,"Torus$demo");
312312
}

demos/test5.p

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ my @objs = (
1919
['Lattice', {Shading=>0}],
2020
['Lattice', {Shading=>1}],
2121
['Lattice', {Shading=>2}],
22-
['SLattice_S', {Smooth=>0}],
23-
['SLattice_S'],
22+
['Lattice', {Shading=>3, Lighting => 1}],
23+
['Lattice', {Shading=>3, Lighting => 1, Smooth=>1}],
2424
);
2525
my $i = 0;
2626
@objs = map [$i++, @$_], @objs;

demos/tvrml.p

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ $name = $g->add_dataseries(PDL::Graphics::TriD::Points->new($pdl,$cols));
3232
$g->bind_default($name);
3333
$name = $g->add_dataseries(PDL::Graphics::TriD::Lattice->new([SURF2D,$x]));
3434
$g->bind_default($name);
35-
$name = $g->add_dataseries(PDL::Graphics::TriD::SLattice_S->new([SURF2D,$x+1],$cx,
36-
{Smooth=>1,Lines=>0}));
35+
$name = $g->add_dataseries(PDL::Graphics::TriD::Lattice->new([SURF2D,$x+1],$cx,
36+
{Smooth=>1,Lines=>0,Shading=>3, Lighting=>1, Smooth=>1}));
3737
$g->bind_default($name);
3838
$g->scalethings();
3939
describe3d('A simple test of

demos/tvrml2.p

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ $name = $g->add_dataseries(PDL::Graphics::TriD::Points->new($pdl,$cols));
3838
$g->bind_default($name);
3939
$name = $g->add_dataseries(PDL::Graphics::TriD::Lattice->new([SURF2D,$x]));
4040
$g->bind_default($name);
41-
$name = $g->add_dataseries(PDL::Graphics::TriD::SLattice_S->new([SURF2D,$x+1],$cx,
42-
{Smooth=>1,Lines=>0}));
41+
$name = $g->add_dataseries(PDL::Graphics::TriD::Lattice->new([SURF2D,$x+1],$cx,
42+
{Smooth=>1,Lines=>0,Shading=>3, Lighting=>1, Smooth=>1}}));
4343
$g->bind_default($name);
4444
$g->scalethings();
4545
$win = PDL::Graphics::TriD::get_current_window();

lib/PDL/Graphics/TriD.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ as produced by L<PDL::ImageND/contour_segments>.
319319
320320
3D rendered image plot, defined by a variety of contexts
321321
322-
Implemented by L<PDL::Graphics::TriD::SLattice_S>.
322+
Implemented by L<PDL::Graphics::TriD::Lattice> defaulting to C<< Shading=>3, Smooth => 1, Lighting => 1 >>.
323323
324324
The variant, C<imag3d_ns>, is implemented by L<PDL::Graphics::TriD::Lattice> defaulting to C<< Shading=>2 >>.
325325
@@ -907,8 +907,9 @@ sub PDL::imag3d_ns { &checkargs;
907907
}
908908

909909
*imag3d=*imag3d=\&PDL::imag3d;
910+
my %imag3d_defs = (Shading => 3, Smooth => 1, Lighting => 1);
910911
sub PDL::imag3d { &checkargs;
911-
graph_object(PDL::Graphics::TriD::SLattice_S->new(@_));
912+
graph_object(_mod_defaults('PDL::Graphics::TriD::Lattice', \%imag3d_defs, @_));
912913
}
913914

914915
sub _mod_defaults {

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,19 @@ sub PDL::Graphics::TriD::Lattice::gdraw {
197197
$this->_lattice_lines($points,$this->{Colors});
198198
} else {
199199
glShadeModel($shading == 1 ? GL_FLAT : GL_SMOOTH);
200-
_lattice_slice(\&PDL::gl_triangles, $points, $this->{Colors});
200+
my $f = 'PDL::gl_triangles';
201+
$f .= '_' . ($this->{Options}{Smooth} ? 'w' : '') . 'n_mat' if $shading > 2;
202+
{ no strict 'refs'; $f = \&$f; }
203+
_lattice_slice($f, $points, $this->{Options}{Smooth} ? $this->{Normals} : (), $this->{Colors});
201204
$this->_lattice_lines($points) if $this->{Options}{Lines};
202205
}
206+
if ($this->{Options}{ShowNormals}) {
207+
die "No normals to show!" if !defined $this->{Normals};
208+
my $arrows = $points->append($points + $this->{Normals}*0.1)->splitdim(0,3);
209+
glDisable(GL_LIGHTING);
210+
glColor3d(1,1,1);
211+
PDL::Graphics::OpenGLQ::gl_arrows($arrows, 0, 1, 0.5, 0.02);
212+
}
203213
}
204214

205215
sub PDL::Graphics::TriD::LineStrip::gdraw {
@@ -235,29 +245,6 @@ sub PDL::Graphics::TriD::Contours::gdraw {
235245
}
236246
}
237247

238-
sub PDL::Graphics::TriD::SLattice_S::gdraw {
239-
my($this,$points) = @_;
240-
barf "Need 3D points"
241-
if grep $_->ndims < 3, $points;
242-
glShadeModel(GL_SMOOTH); # By-vertex doesn't make sense otherwise.
243-
my $f = 'PDL::gl_triangles_';
244-
$f .= 'w' if $this->{Options}{Smooth};
245-
$f .= 'n_mat';
246-
{ no strict 'refs'; $f = \&$f; }
247-
my @pdls = $points;
248-
push @pdls, $this->{Normals} if $this->{Options}{Smooth};
249-
push @pdls, $this->{Colors};
250-
_lattice_slice($f, @pdls);
251-
$this->_lattice_lines($points) if $this->{Options}{Lines};
252-
if ($this->{Options}{ShowNormals}) {
253-
die "No normals to show!" if !defined $this->{Normals};
254-
my $arrows = $points->append($points + $this->{Normals}*0.1)->splitdim(0,3);
255-
glDisable(GL_LIGHTING);
256-
glColor3d(1,1,1);
257-
PDL::Graphics::OpenGLQ::gl_arrows($arrows, 0, 1, 0.5, 0.02);
258-
}
259-
}
260-
261248
sub PDL::Graphics::TriD::Trigrid::gdraw {
262249
my($this,$points) = @_;
263250
my $faces = $points->dice_axis(1,$this->{Faceidx}->flat)->splitdim(1,3);

lib/PDL/Graphics/TriD/Objects.pm

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ This provides the following class hierarchy:
1717
├ PDL::Graphics::TriD::LineStrip continuous paths
1818
├ PDL::Graphics::TriD::Trigrid polygons
1919
└ PDL::Graphics::TriD::GObject_Lattice (abstract) base class
20-
├ PDL::Graphics::TriD::Lattice colored lattice
21-
└ PDL::Graphics::TriD::SLattice_S ...filled, smooth-shaded, and with normals
20+
└ PDL::Graphics::TriD::Lattice colored lattice
2221
2322
=head1 DESCRIPTION
2423
@@ -192,32 +191,20 @@ sub get_valid_options { +{
192191

193192
package PDL::Graphics::TriD::Lattice;
194193
use base qw/PDL::Graphics::TriD::GObject_Lattice/;
194+
use fields qw/Normals/;
195195
sub cdummies {
196196
my $shading = $_[0]{Options}{Shading};
197197
!$shading ? $_[1]->dummy(1)->dummy(1) :
198198
$shading == 1 ? $_[1]->dummy(1,$_[2]->getdim(2)-1)->dummy(1,$_[2]->getdim(1)-1) :
199-
$_[1]->dummy(1,$_[2]->getdim(2))->dummy(1,$_[2]->getdim(1));
200-
}
201-
sub get_valid_options { +{
202-
UseDefcols => 0,
203-
Lines => 1,
204-
Lighting => 0,
205-
Shading => 2, # 0=no fill, 1=flat colour per triangle, 2=smooth colour per vertex
206-
}}
207-
208-
# colors associated with vertices
209-
package PDL::Graphics::TriD::SLattice_S;
210-
use base qw/PDL::Graphics::TriD::GObject_Lattice/;
211-
use fields qw/Normals/;
212-
sub cdummies {
213199
$_[1]->slice(":," . join ',', map "*$_", ($_[2]->dims)[1,2])
214200
}
215201
sub get_valid_options { +{
216202
UseDefcols => 0,
217203
Lines => 1,
218-
Smooth => 1,
204+
Lighting => 0,
205+
Shading => 2, # 0=no fill, 1=flat colour per triangle, 2=smooth colour per vertex, 3=colors associated with vertices
206+
Smooth => 0,
219207
ShowNormals => 0,
220-
Lighting => 1,
221208
}}
222209
sub new {
223210
my ($class,$points,$colors,$options) = @_;

0 commit comments

Comments
 (0)