1########################################################################
2#  This program is free software; you can redistribute it and/or
3#  modify it under the terms of the GNU General Public License
4#  as published by the Free Software Foundation; either version 2
5#  of the License, or (at your option) any later version.
6#
7#  This program is distributed in the hope that it will be useful,
8#  but WITHOUT ANY WARRANTY; without even the implied warranty of
9#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10#  GNU General Public License for more details.
11#
12#  You should have received a copy of the GNU General Public License
13#  along with this program; if not, write to the Free Software
14#  Foundation, Inc., 51 Franklin Street, Fifth Floor,
15#  Boston, MA  02110-1301, USA.
16#
17#  ---
18#  Copyright (C) 2011-2015, Simon Hampe <simon.hampe@googlemail.com>
19#
20#  ---
21#  Copyright (c) 2016-2021
22#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
23#  Technische Universität Berlin, Germany
24#  https://polymake.org
25#
26#  Contains functions to visualize the domain of a TropicalRationalFunction or
27#  a Morphism.
28#
29########################################################################
30
31package Visual::Cycle;
32
33#Visualization options for TropicalRationalFunction/Morphism->VISUAL
34options %Visual::Cycle::FunctionDecorations=(
35	%Visual::Cycle::BoundingDecorations,
36
37	# String, if set to "show", the function labels indicatingt the affine linear representation of each function
38	# on each cone are computed
39	FunctionLabels => enum("hidden", "show"),
40);
41
42object TropicalRationalFunction {
43
44# @category Visualization
45# Visualizes the domain of the function. Works exactly as VISUAL of WeightedComplex, but has additional option
46# @options
47# @option String FunctionLabels If set to "show", textual function representations are diplayed on cones. False by default
48	user_method VISUAL(%Visual::Cycle::FunctionDecorations, {CutOff => $Visual::Color::cutoff}) : DOMAIN, VERTEX_VALUES, LINEALITY_VALUES {
49
50		my ($this,$decor,$cutoff_decor)=@_;
51
52		my $showFunctionLabels = 0;
53		if(defined($$decor{"FunctionLabels"})) {
54			if($$decor{"FunctionLabels"} eq "show") {
55				$showFunctionLabels = 1;
56			}
57		}
58		delete($$decor{"FunctionLabels"});
59
60		my $domain = $this->DOMAIN;
61
62		my @labels = ();
63		if($showFunctionLabels == 1) {
64			my $ray_values = $this->VERTEX_VALUES;
65			my $lin_values = $this->LINEALITY_VALUES;
66
67			my ($M,$L);
68			if($ray_values->dim() > 0) {
69				$M = new Matrix<Rational>($ray_values);
70				$M = transpose($M);
71			}
72			else {
73				$M = new Matrix<Rational>(0,1);
74			}
75			if($lin_values->dim() > 0) {
76				$L = new Matrix<Rational>($lin_values);
77				$L = transpose($L);
78			}
79			else {
80				$L = new Matrix<Rational>(0,1);
81			}
82
83			@labels = computeFunctionLabels($domain,$M,$L,0);
84			$$decor{"ConeLabels"} = new Array<String>(\@labels);
85		}
86
87
88		$domain->VISUAL($decor,$cutoff_decor);
89	}
90}
91
92
93object Morphism {
94
95# @category Visualization
96# Visualizes the domain of the morphism. Works exactly as VISUAL of WeightedComplex, but has additional option
97# @options
98# @option String FunctionLabels If set to "show", textual function representations are diplayed on cones. False by default
99user_method VISUAL(%Visual::Cycle::FunctionDecorations, {CutOff => $Visual::Color::cutoff}) : DOMAIN, VERTEX_VALUES, LINEALITY_VALUES {
100
101    my ($this,$decor,$cutoff_decor)= @_;
102
103    my $showFunctionLabels = 0;
104    if(defined($$decor{"FunctionLabels"})) {
105      if($$decor{"FunctionLabels"} eq "show") {
106	$showFunctionLabels = 1;
107      }
108    }
109    delete($$decor{"FunctionLabels"});
110
111    my $domain = $this->DOMAIN;
112
113    my @labels = ();
114    if($showFunctionLabels == 1) {
115      my $M = $this->VERTEX_VALUES;
116      my $L = $this->LINEALITY_VALUES;
117
118      @labels = computeFunctionLabels($domain,$M,$L,1);
119      $$decor{"ConeLabels"} = new Array<String>(\@labels);
120    }
121
122
123    $domain->VISUAL($decor,$cutoff_decor);
124}
125}
126