@@ -12,14 +12,14 @@ This provides the following class hierarchy:
1212
1313 PDL::Graphics::TriD::Object base class for containers
1414 ├ PDL::Graphics::TriD::Arrows lines with arrowheads
15+ ├ PDL::Graphics::TriD::Trigrid polygons
1516 └ PDL::Graphics::TriD::GObject (abstract) base class for drawables
1617
1718 PDL::Graphics::TriD::GObject (abstract) base class for drawables
1819 ├ PDL::Graphics::TriD::Points individual points
1920 ├ PDL::Graphics::TriD::Spheres fat 3D points :)
2021 ├ PDL::Graphics::TriD::Lines separate lines
2122 ├ PDL::Graphics::TriD::LineStrip continuous paths
22- ├ PDL::Graphics::TriD::Trigrid polygons
2323 ├ PDL::Graphics::TriD::Triangles just polygons
2424 ├ PDL::Graphics::TriD::Lattice colored lattice, maybe filled/shaded
2525 └ PDL::Graphics::TriD::Labels text labels
@@ -120,27 +120,39 @@ sub get_valid_options { +{
120120
121121package PDL::Graphics::TriD::Trigrid ;
122122use PDL::Graphics::OpenGLQ;
123- use base qw/ PDL::Graphics::TriD::GObject/ ;
124- use fields qw/ Faceidx FaceNormals VertexNormals/ ;
123+ use base qw/ PDL::Graphics::TriD::Object/ ;
125124sub new {
126125 my $options = ref ($_ [-1]) eq ' HASH' ? pop : {};
127126 my ($type ,$points ,$faceidx ,$colors ) = @_ ;
128- my $this = $type -> SUPER::new($points , $colors , $ options );
127+ my $this = $type -> SUPER::new($options );
129128 # faceidx is 2D pdl of indices into points for each face
130- $faceidx = $this -> { Faceidx } = $ faceidx-> ulong;
129+ $faceidx = $faceidx -> ulong;
131130 $options = $this -> {Options };
132- if ($options -> {ShowNormals }) {
133- my ($fn , $vn ) = triangle_normals($this -> {Points }, $faceidx );
134- $this -> {VertexNormals } = $vn if $options -> {Smooth } or $options -> {ShowNormals };
135- $this -> {FaceNormals } = $fn if !$options -> {Smooth } or $options -> {ShowNormals };
136- }
137131 my %less = %$options ; delete @less {qw( ShowNormals Lines) };
138132 $less {Shading } = 3 if $options -> {Shading };
139133 $this -> add_object(PDL::Graphics::TriD::Triangles-> new($points , $faceidx -> clump(1..$faceidx -> ndims-1), $colors , \%less ));
140- if ($options -> {Lines }) {
134+ if ($options -> {Lines } or $options -> { ShowNormals } ) {
141135 $points = PDL::Graphics::TriD::realcoords($type -> r_type,$points );
142- my $faces = $points -> dice_axis(1,$this -> {Faceidx }-> flat)-> splitdim(1,3);
143- $this -> add_object(PDL::Graphics::TriD::Lines-> new($faces -> dice_axis(1,[0,1,2,0]), PDL::float(0,0,0)));
136+ my $faces = $points -> dice_axis(1,$faceidx -> flat)-> splitdim(1,3);
137+ if ($options -> {Lines }) {
138+ $this -> add_object(PDL::Graphics::TriD::Lines-> new($faces -> dice_axis(1,[0,1,2,0]), PDL::float(0,0,0)));
139+ }
140+ if ($options -> {ShowNormals }) {
141+ my ($fn , $vn ) = triangle_normals($points , $faceidx );
142+ my $facecentres = $faces -> transpose-> avgover;
143+ my $facearrows = $facecentres -> append($facecentres + $fn *0.1)-> splitdim(0,3)-> clump(1,2);
144+ my ($fromind , $toind ) = PDL-> sequence(PDL::ulong,2,$facecentres -> dim(1))-> t-> dog;
145+ $this -> add_object(PDL::Graphics::TriD::Arrows-> new(
146+ $facearrows , PDL::float(0.5,0.5,0.5),
147+ { From => $fromind , To => $toind , ArrowLen => 0.5, ArrowWidth => 0.2 },
148+ ));
149+ my $vertarrows = $points -> append($points + $vn *0.1)-> splitdim(0,3)-> clump(1,2);
150+ ($fromind , $toind ) = PDL-> sequence(PDL::ulong,2,$points -> dim(1))-> t-> dog;
151+ $this -> add_object(PDL::Graphics::TriD::Arrows-> new(
152+ $vertarrows , PDL::float(1,1,1),
153+ { From => $fromind , To => $toind , ArrowLen => 0.5, ArrowWidth => 0.2 },
154+ ));
155+ }
144156 }
145157 $this ;
146158}
0 commit comments