File: visual.rules

package info (click to toggle)
polymake 3.2r4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,564 kB
  • sloc: cpp: 153,464; perl: 40,590; ansic: 2,829; java: 2,654; python: 589; sh: 219; xml: 117; makefile: 63
file content (116 lines) | stat: -rw-r--r-- 4,264 bytes parent folder | download
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
#  Copyright (c) 1997-2018
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.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.
#-------------------------------------------------------------------------------


# creates an array of colors to distinguish generators and
# pseudo-vertices of a tropical polytope 
sub choose_colors($$$$) {
  my ($points,$pseudovertices,$p_color,$pv_color)=@_;
  my $indices = points_in_pseudovertices($points,$pseudovertices);
   
  my @pseudovertex_colors = map {$indices->contains($_) ? $pv_color : $p_color} (0..$pseudovertices->rows()-1);
  return @pseudovertex_colors;
} 

package Visual::TropicalPolytope;
use Polymake::Struct (
	[ '@ISA' => 'Container' ],
	[ '$Polytope' => '#%' ],
);

package Visual::Color;

custom $polytopegenerators="255 255 0"; 

options %Visual::TropicalPolytope::decorations=(
	%Visual::Polygons::decorations,
    
	# Flexible<Int> The visualization is always in affine coordinates. This chooses the chart.
	Chart => 0,
    
    # Flexible<Color> color of the finite [[POINTS]] of a polytope 
    GeneratorColor => $Visual::Color::polytopegenerators,

    # Flexible<Color> color of the finite [[PSEUDOVERTICES]] of a polytope 
    PseudovertexColor => $Visual::Color::vertices,
);

object Polytope {


# @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 = $$decor{"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);

                my @pseudovertex_colors=choose_colors($this->POINTS,$vertices,$$decor{"PseudovertexColor"},$$decor{"GeneratorColor"});

                $vertices = tdehomog($vertices,$chart);

                delete $$decor{"GeneratorColor"};
                delete $$decor{"PseudovertexColor"};
		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 = $$decor{"Chart"};
		delete($$decor{"Chart"});

		my $vertices = tdehomog($this->PSEUDOVERTICES,$chart);
		my $cells = $this->MAXIMAL_COVECTOR_CELLS;
                my @pseudovertex_colors=choose_colors($this->POINTS,$this->PSEUDOVERTICES,$$decor{"PseudovertexColor"},$$decor{"GeneratorColor"});
                delete $$decor{"GeneratorColor"};
                delete $$decor{"PseudovertexColor"};
		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: