1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-------------------------------------------------------------------------------
package Visual::PointConfiguration;
use Polymake::Struct (
[ '@ISA' => 'Container' ],
[ '$PointConfiguration' => '#%' ],
);
# where to keep the view transformation matrix etc.
method representative { $_[0]->PointConfiguration }
method basis_solid { $_[0]->elements->[0] }
# Visualize the [[TRIANGULATION]] of a point configuration
# @param Array<Set<Int>> t facets of the triangulation
# @options %Visual::Polygons::decorations
# @return Visual::PointConfiguration
user_method TRIANGULATION(; $=$_[0]->PointConfiguration->TRIANGULATION->FACETS, %Visual::Polygons::decorations) {
my ($self, $TR, $decor)=@_;
my $d=$self->PointConfiguration->VECTOR_AMBIENT_DIM-1;
if ($d > 3) {
die "don't know how to visualize the triangulation of a $d-d configuration\n";
}
my $skeleton=$self->basis_solid;
$skeleton->VertexStyle="hidden";
$skeleton->FacetStyle="hidden";
my $labels= delete $decor->{VertexLabels};
if ($labels ne "hidden") {
$labels=$skeleton->VertexLabels;
} else {
undef $labels;
}
my $Points=$skeleton->Vertices;
my $Signs=triang_sign($TR, $self->PointConfiguration->POINTS);
$self->Name="Triangulation of ".$self->PointConfiguration->name;
push @{$self->elements}, [ $self->PointConfiguration->CONVEX_HULL->VisualSimplices($TR,$Points,$Signs,$labels,$decor) ];
visualize($self);
}
# Visualize a [[POLYTOPAL_SUBDIVISION]] of a point configuration.
# @param Int index Index of the subdivision to visualize
# @options %Visual::Polygons::decorations
# @options %geometric_options
# @return Visual::PointConfiguration
user_method POLYTOPAL_SUBDIVISION(;$=0,%Visual::Polygons::decorations, %geometric_options) {
my ($self, $index, $decor, $geom)=@_;
my $d=$self->PointConfiguration->VECTOR_AMBIENT_DIM-1;
if ($d > 3) {
die "don't know how to visualize the polytopal subdivision of a $d-d configuration\n";
}
$self->Name="Polytopal subdivision of ".$self->PointConfiguration->name;
my $pc=$self->PointConfiguration->POINTS;
my $psd=$self->PointConfiguration->POLYTOPAL_SUBDIVISION->[$index]->MAXIMAL_CELLS;
my @faces=();
my $skeleton=$self->basis_solid;
# $skeleton->EdgeStyle="hidden";
if ( $d == 3 ) {
$skeleton->FacetStyle="hidden";
foreach (@{$psd}) {
my $p=new polytope::Polytope<Rational>(POINTS=>$pc->minor($_,All));
my $P=new Visual::Polygons( Vertices => Visual::transform_float(dehomogenize(convert_to<Float>($p->VERTICES)),$geom->{Transformation},$geom->{Offset}),
Facets => $p->VIF_CYCLIC_NORMAL,
VertexLabels => "hidden",
FacetNeighbors => $p->NEIGHBOR_FACETS_CYCLIC_NORMAL,
Closed => 1,
NEdges => $p->N_EDGES,
$decor
);
push @faces, new Visual::Polytope(Polytope=>$p,$P);
}
} else {
foreach (@{$psd}) {
my $p=new polytope::Polytope<Rational>(POINTS=>$pc->minor($_,All));
my $P=new Visual::Polygon(Vertices => Visual::transform_float(dehomogenize(convert_to<Float>($p->VERTICES)),$geom->{Transformation},$geom->{Offset}),
VertexLabels => "hidden",
Facet => $p->VIF_CYCLIC_NORMAL->[0],
NEdges => $p->N_EDGES,
$decor
);
push @{faces}, new Visual::Polytope(Polytope=>$p,$P);
}
}
compose($self,@faces);
}
package Visual::Color;
# Color for the non-vertices.
custom $non_vertices="255 255 0";
# @topic objects/Visual::PointConfiguration
# @category Visualization
# Visualization of the point configuration.
object PointConfiguration {
# @category Visualization
# Visualize the [[POINTS]] of a point configuration.
# @options %Visual::Polygons::decorations
# @options %geometric_options
# @return Visual::Object
user_method VISUAL_POINTS(%Visual::Polygons::decorations, %geometric_options) : POINTS, NON_VERTICES, N_POINTS {
my ($this, $decor, $geom)=@_;
my @colors = map { exists $this->NON_VERTICES->{$_} ? $Visual::Color::non_vertices : $Visual::Color::vertices } @{range(0,$this->N_POINTS-1)};
visualize( new Visual::PointSet(Name => $this->name,
Points => Visual::transform_float(dehomogenize(convert_to<Float>($this->POINTS)),$geom->{Transformation},$geom->{Offset}),
PointLabels =>$this->lookup("LABELS"),
PointColor => \@colors,
$decor
));
}
# @category Visualization
# Visualize a point configuration.
# @options %Visual::Polygons::decorations
# @options %geometric_options
# @return Visual::PointConfiguration
user_method VISUAL(%Visual::Polygons::decorations, %geometric_options) : POINTS, NON_VERTICES, N_POINTS, PIF_CYCLIC_NORMAL {
my ($this, $decor, $geom)=@_;
my @colors = map { exists $this->NON_VERTICES->{$_} ? $Visual::Color::non_vertices : $Visual::Color::vertices } @{range(0,$this->N_POINTS-1)};
my $P= $this->VECTOR_DIM==3
? new Visual::Polygon( Name => $this->name,
Points => Visual::transform_float(dehomogenize(convert_to<Float>($this->POINTS)),$geom->{Transformation},$geom->{Offset}),
PointLabels =>$this->lookup("POINT_LABELS") ,
PointColor => \@colors,
Facet => $this->PIF_CYCLIC_NORMAL->[0],
FacetTransparency => 0.5,
NEdges => $this->CONVEX_HULL->N_EDGES,
$decor
)
: new Visual::Polygons( Name => $this->name,
Points => Visual::transform_float(dehomogenize(convert_to<Float>($this->POINTS)),$geom->{Transformation},$geom->{Offset}),
PointLabels => $this->lookup("POINT_LABELS"),
PointColor => \@colors,
Facets => $this->PIF_CYCLIC_NORMAL,
FacetNeighbors => $this->CONVEX_HULL->NEIGHBOR_FACETS_CYCLIC_NORMAL,
FacetNormals => Visual::transform_float_facets(convert_to<Float>($this->CONVEX_HULL->FACETS),$geom->{Transformation},$geom->{Offset}),
FacetLabels => $this->CONVEX_HULL->lookup("FACET_LABELS") || "hidden",
FacetTransparency => 0.5,
Closed => 1,
NEdges => $this->CONVEX_HULL->N_EDGES,
$decor
);
visualize( new Visual::PointConfiguration(Name => $this->name, PointConfiguration => $this, $P));
}
precondition : VECTOR_DIM { $this->VECTOR_DIM>=3 }
precondition : VECTOR_AMBIENT_DIM { $this->VECTOR_AMBIENT_DIM<=4 }
precondition : BOUNDED;
# @hide
user_method VISUAL(%Visual::Polygons::decorations, %geometric_options) : POINTS, GRAPH.ADJACENCY {
my ($this, $decor, $geom)=@_;
my $pc=$this->VISUAL_POINTS(Name=>'points', $decor, $geom);
my $G=$this->GRAPH->VISUAL(Name=>$this->name, Coord=>Visual::transform_float(dehomogenize(convert_to<Float>($this->POINTS)),$geom->{Transformation},$geom->{Offset}), $decor);
visualize( new Visual::PointConfiguration(Name => $this->name, PointConfiguration => $this, $G, $pc) );
}
precondition : VECTOR_DIM { $this->VECTOR_DIM==2 }
precondition : VECTOR_AMBIENT_DIM { $this->VECTOR_AMBIENT_DIM<=4 }
precondition : BOUNDED;
}
package Visual::VectorConfiguration;
use Polymake::Struct (
[ '@ISA' => 'Container' ],
[ '$VectorConfiguration' => '#%' ],
);
object VectorConfiguration {
# @category Visualization
# Visualize a vector configuration.
# @options %Visual::Polygons::decorations
# @options %geometric_options_linear
# @return Visual::PointConfiguration
user_method VISUAL(%Visual::Polygons::decorations, %geometric_options_linear) : VECTORS, N_VECTORS {
my ($this, $decor, $geom)=@_;
visualize( new Visual::PointSet(Name => $this->name,
Points => Visual::transform_float(convert_to<Float>($this->VECTORS),$geom->{Transformation}),
PointLabels =>$this->lookup("LABELS"),
$decor
));
}
precondition : VECTOR_AMBIENT_DIM { $this->VECTOR_AMBIENT_DIM<=3 }
}
# Local Variables:
# mode: perl
# cperl-indent-level:4
# indent-tabs-mode:nil
# End:
|