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
|
# Copyright (c) 1997-2021
# 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::Color;
# default color for the finite [[POINTS]] of a tropical polytope
custom $polytopegenerators = "255 255 0";
package Visual::TropicalPolytope;
use Polymake::Struct (
[ '@ISA' => 'Container' ],
[ '$Polytope' => '#%' ],
);
options %decorations = (
%Visual::Polygons::decorations,
# Flexible<Int> The visualization is always in affine coordinates. This chooses the chart.
Chart => 0,
# [complete color] Flexible<Color> color of the finite [[POINTS]] of a polytope
GeneratorColor => $Visual::Color::polytopegenerators,
# [complete color] Flexible<Color> color of the finite [[PSEUDOVERTICES]] of a polytope
PseudovertexColor => $Visual::Color::vertices,
# String Labels of [[PSEUDOVERTICES]] of a polytope
PseudovertexLabels => 'hidden',
# Flexible<Float> Thickness of [[PSEUDOVERTICES]] of a tropical polytope
PseudovertexThickness => undef,
);
object Polytope {
# creates an array of colors to distinguish generators and
# pseudo-vertices of a tropical polytope
sub pseudovertex_colors($$$$) {
my ($points, $pseudovertices, $p_color, $pv_color) = @_;
my $indices = points_in_pseudovertices($points, $pseudovertices);
map { $indices->contains($_) ? $pv_color : $p_color } (0..$pseudovertices->rows()-1);
}
# @category Visualization
# Visualize the subdivision of the polytope induced by [[POINTS]].
# @options %Visual::TropicalPolytope::decorations
# @return fan::Visual::PolyhedralFan
user_method VISUAL(%Visual::TropicalPolytope::decorations) {
my ($this, $decor) = @_;
my $chart = delete $decor->{Chart};
my $used_pvs = new Set<Int>();
for my $i (0 .. $this->POLYTOPE_MAXIMAL_COVECTOR_CELLS->rows()-1) {
$used_pvs += $this->POLYTOPE_MAXIMAL_COVECTOR_CELLS->row($i);
}
my $vertices = new Matrix<Scalar>($this->PSEUDOVERTICES->minor($used_pvs,All));
my $cells = $this->POLYTOPE_MAXIMAL_COVECTOR_CELLS->minor(All, $used_pvs);
# the order is crucial here
my @pseudovertex_colors = pseudovertex_colors($this->POINTS, $vertices, delete $decor->{PseudovertexColor}, delete $decor->{GeneratorColor});
foreach (keys %$decor) {
$decor->{s/Pseudovertex/Vertex/r} = delete $decor->{$_};
}
my @codedecor = Visual::get_code_decor_keys($decor, "Vertex");
$decor = scalar(@codedecor) ? Visual::decor_subset($decor,$used_pvs,\@codedecor) : $decor;
$vertices = tdehomog($vertices,$chart);
my $p = new fan::PolyhedralComplex(VERTICES=>$vertices, MAXIMAL_POLYTOPES=>$cells);
$p->VISUAL(VertexColor => \@pseudovertex_colors, $decor);
}
# @category Visualization
# Visualize the subdivision of the torus induced by [[POINTS]].
# @options %Visual::TropicalPolytope::decorations
# @return fan::Visual::PolyhedralFan
user_method VISUAL_SUBDIVISION(%Visual::TropicalPolytope::decorations) {
my ($this, $decor) = @_;
my $chart = delete $decor->{"Chart"};
my $vertices = tdehomog($this->PSEUDOVERTICES,$chart);
my $cells = $this->MAXIMAL_COVECTOR_CELLS;
my @pseudovertex_colors = pseudovertex_colors($this->POINTS, $this->PSEUDOVERTICES, delete $decor->{PseudovertexColor}, delete $decor->{GeneratorColor});
foreach (keys %$decor) {
$decor->{s/Pseudovertex/Vertex/r} = delete $decor->{$_};
}
my $p = new fan::PolyhedralComplex(VERTICES=>$vertices, MAXIMAL_POLYTOPES=>$cells);
$p->VISUAL(VertexColor => \@pseudovertex_colors, $decor);
}
# @category Visualization
# Visualize the arrangement of hyperplanes with apices in the [[POINTS]] of the tropical polytope.
# @return fan::Visual::PolyhedralFan
user_method VISUAL_HYPERPLANE_ARRANGEMENT(%Visual::Polygons::decorations) : VERTICES, PROJECTIVE_AMBIENT_DIM {
my ($this, $decor) = @_;
points2hypersurface($this->POINTS)->VISUAL($decor);
}
precondition : PROJECTIVE_AMBIENT_DIM { $this->PROJECTIVE_AMBIENT_DIM<=3 }
}
# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End:
|