@@ -128,31 +128,13 @@ sub new {
128128 # faceidx is 2D pdl of indices into points for each face
129129 $faceidx = $faceidx -> ulong;
130130 $options = $this -> {Options };
131- my %less = %$options ; delete @less {qw( ShowNormals Lines) };
131+ my %less = %$options ; delete @less {qw( Lines) };
132132 $less {Shading } = 3 if $options -> {Shading };
133133 $this -> add_object(PDL::Graphics::TriD::Triangles-> new($points , $faceidx -> clump(1..$faceidx -> ndims-1), $colors , \%less ));
134- if ($options -> {Lines } or $options -> { ShowNormals } ) {
134+ if ($options -> {Lines }) {
135135 $points = PDL::Graphics::TriD::realcoords($type -> r_type,$points );
136136 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- }
137+ $this -> add_object(PDL::Graphics::TriD::Lines-> new($faces -> dice_axis(1,[0,1,2,0]), PDL::float(0,0,0)));
156138 }
157139 $this ;
158140}
@@ -177,10 +159,29 @@ sub new {
177159 my $this = $type -> SUPER::new($points ,$colors ,$options );
178160 $faceidx = $this -> {Faceidx } = $faceidx -> ulong; # (3,nfaces) indices
179161 $options = $this -> {Options };
180- if ($options -> {Shading }) {
162+ if ($options -> {Shading } or $options -> { ShowNormals } ) {
181163 my ($fn , $vn ) = triangle_normals($this -> {Points }, $faceidx );
182- $this -> {VertexNormals } = $vn if $options -> {Smooth };
183- $this -> {FaceNormals } = $fn if !$options -> {Smooth };
164+ if ($options -> {Shading }) {
165+ $this -> {VertexNormals } = $vn if $options -> {Smooth };
166+ $this -> {FaceNormals } = $fn if !$options -> {Smooth };
167+ }
168+ if ($options -> {ShowNormals }) {
169+ $points = PDL::Graphics::TriD::realcoords($type -> r_type,$points );
170+ my $faces = $points -> dice_axis(1,$faceidx -> flat)-> splitdim(1,3);
171+ my $facecentres = $faces -> transpose-> avgover;
172+ my $facearrows = $facecentres -> append($facecentres + $fn *0.1)-> splitdim(0,3)-> clump(1,2);
173+ my ($fromind , $toind ) = PDL-> sequence(PDL::ulong,2,$facecentres -> dim(1))-> t-> dog;
174+ $this -> add_object(PDL::Graphics::TriD::Arrows-> new(
175+ $facearrows , PDL::float(0.5,0.5,0.5),
176+ { From => $fromind , To => $toind , ArrowLen => 0.5, ArrowWidth => 0.2 },
177+ ));
178+ my $vertarrows = $points -> append($points + $vn *0.1)-> splitdim(0,3)-> clump(1,2);
179+ ($fromind , $toind ) = PDL-> sequence(PDL::ulong,2,$points -> dim(1))-> t-> dog;
180+ $this -> add_object(PDL::Graphics::TriD::Arrows-> new(
181+ $vertarrows , PDL::float(1,1,1),
182+ { From => $fromind , To => $toind , ArrowLen => 0.5, ArrowWidth => 0.2 },
183+ ));
184+ }
184185 }
185186 $this ;
186187}
@@ -189,6 +190,7 @@ sub get_valid_options { +{
189190 Shading => 1, # 0=no shading, 1=flat colour per triangle, 2=smooth colour per vertex, 3=colors associated with vertices
190191 Smooth => 0,
191192 Lighting => 0,
193+ ShowNormals => 0,
192194}}
193195sub cdummies { $_ [1]-> dummy(1,$_ [2]-> getdim(1)); }
194196
0 commit comments