File: visual.rules

package info (click to toggle)
polymake 3.0r2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,752 kB
  • ctags: 30,928
  • sloc: cpp: 151,785; perl: 32,510; ansic: 3,597; java: 2,654; python: 278; makefile: 181; xml: 103; sh: 79
file content (376 lines) | stat: -rw-r--r-- 12,731 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#  Copyright (c) 1997-2015
#  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.
#-------------------------------------------------------------------------------


###############################################################################
#
#  some common colors
#
package Visual::Color;

# file with symbolic color names (as shipped with X11 system)
custom $RGBtxt_path;

CONFIGURE_OPT {
   find_file_and_confirm($RGBtxt_path, "rgb.txt",
                         qw( /usr/X11/lib/X11 /usr/share/X11 /usr/X11/share/X11 /usr/X11R6/lib/X11
                             /usr/local/X11/lib/X11 /usr/local/X11R6/lib/X11 /usr/openwin/lib/X11 
                             /usr/local/lib/X11 ),
                         { prompt => "color name database",
                           abort => "disable\nusing symbolic color names in visualization methods" });
}

# @topic custom
# All colors defined here are RGB values in integer representation (0..255)
# You may use symbolic names defined in the file $RGBtxt as well.

# facets in famous polymake-green
custom $facets="119 236 158";

# edges of facets and graphs: black
custom $edges="0 0 0";

# vertices: red
custom $vertices="255 0 0";

# color for artificial facets resulting from cutting off
custom $cutoff="255 0 0";

###############################################################################
#
#  geometric primitives and decoration attributes
#

package application;

require Visual;
require Visual::DynamicCoords;
require Visual::PointSet;
require Visual::Wire;
require Visual::Polygon;
require Visual::Polygons;

# @category Visualization
# A color described as a Red-Green-Blue triple.
# Can be constructed from a list of three integral values from the range 0..255,
# or a list of three floating-point values from the range 0..1,
# or one of symbolic names listed in the system-wide file ''rgb.txt''.

declare property_type RGB : c++ (include=>["polymake/color.h"]) {

   type_method parse {
      if ($_[1] =~ /[^\s\d.]/) {
         # symbolic color name?
         Visual::get_sym_color($_[1]) // croak("unknown color name '$_[1]'");
      } else {
         &Core::CPlusPlus::construct_parsed;
      }
   }

   method construct(Int,Int,Int) : c++;

   method construct(Float,Float,Float) : c++;

   method toInt { join($_[1] || " ", map { POSIX::ceil($_*255) } @{$_[0]}) }

   method toHex { sprintf "#%02X%02X%02X", map { POSIX::ceil($_*255) } @{$_[0]} }

   method toFloat { my $sep=$_[1] || " "; sprintf "%.4g$sep%.4g$sep%.4g", @{$_[0]} }
}

# @category Visualization
# A color described as a Hue-Saturation-Value triple.
# Is convertible to and from an RGB representation.

declare property_type HSV : c++ (include=>["polymake/color.h"]) {

   method construct(Float,Float,Float) : c++;

   method construct(RGB) : c++;

   method toFloat { my $sep=$_[1] || " "; sprintf "%.4g$sep%.4g$sep%.4g", @{$_[0]} }
}

property_type RGB {

   method construct(HSV) : c++;
}


# @topic property_types/Visualization/Flexible
# This is a pseudo-type for documentation purposes only.
# Many options of visualization functions modifying the appearance of some set of graphical elements
# like points, edges, facets, etc. accept a wide range of possible values, allowing for different grades
# of flexibility (and complexity):
#
#  SCALAR  the same attribute value is applied to all elements
#  ARRAY   each element gets its individual attribute value
#  HASH    elements found in the hash get their individual attribute values, for the rest the appropriate default applies
#  SUB     a piece of code computing the attribute value for the given element
#
# Unless specified explicitly in the detailed option description, the indices, keys, or
# subroutine arguments used for retrieval of the attribute values are just the zero-based ordinal numbers of the elements.


# @topic property_types/Color
# @category Visualization
# This is a pseudo-type for documentation purposes only.
# A function expecting an argument or option of type //Color// can digest an object of type [[RGB]] or [[HSV]]
# as well as a string with an RGB value in hex notation "#RRGGBB" or a symbolic color name.


# @topic objects/Visual::Object
# @category Visualization
# The common base class of all visualization artifacts produced by various user methods
# like VISUAL, VISUAL_GRAPH, SCHLEGEL, etc.  Visual objects can be passed to functions
# explicitly calling visualization software like //jreality()// or //povray()//.

# @topic objects/Visual::Container
# @category Visualization
# The common base class of all visual objects composed of several simpler objects.
# Instances of such classes can carry default decoration attributes applied to all contained objects.
# @super Visual::Object

# @category Visualization
# Common attributes modifying the appearance of PointSets and all visual objects derived thereof.
# Please be aware that no one visualization program interfaced to polymake supports all of them.
# Unsupported options are normally ignored.

options %Visual::PointSet::decorations=(
   # String  the name of the drawing
   Title => undef,

   # String  the name of this visual object in the drawing
   Name => undef,

   # Bool  if set to true, the visual object is not rendered
   #       (useful for interactive visualization programs allowing for switching details on and off)
   Hidden => 0,

   # String  if set to "hidden", no point labels are displayed
   PointLabels => undef,

   # String  alias for PointLabels
   VertexLabels => undef,

   # Flexible<Color>  color of the spheres or rectangles representing the points
   PointColor => undef,

   # Flexible<Color>  alias for PointColor
   VertexColor => undef,

   # Flexible<Float>  scaling factor for the size of the spheres or rectangles representing the points
   PointThickness => undef,

   # Flexible<Float>  alias for PointThickness
   VertexThickness => undef,

   # Flexible<Color>  color of the border line of rectangles representing the points
   PointBorderColor => undef,

   # Flexible<Float>  alias for PointBorderColor
   VertexBorderColor => undef,

   # Flexible<Float>  scaling factor for the thickness of the border line of rectangles representing the points
   PointBorderThickness => undef,

   # Flexible<Float>  alias for PointBorderThickness
   VertexBorderThickness => undef,

   # Flexible<String>  if set to "hidden", neither point nor its label is rendered
   PointStyle => undef,

   # Flexible<String>  alias for PointStyle
   VertexStyle => undef,

   # Vector<Float>  ViewPoint for Sketch visualization
   ViewPoint => undef,

   # Vector<Float>  ViewDirection for Sketch visualization
   ViewDirection => undef,

   # Vector<Float>  ViewUp for Sketch visualization
   ViewUp => undef,

   # Float  scale for Sketch visualization
   Scale => undef,

   # Flexible<String>  Defines the alignment of the vertex labels: left, right or center
   LabelAlignment => undef,
);

# @category Visualization
# Attributes modifying the appearance of "wire frameworks".
# Unlike the rest, the flexible edge attributes are retrieved using the //edge iterator// as an index/key/argument.

options %Visual::Wire::decorations=(
   %Visual::PointSet::decorations,

   # Flexible<Color>  color of the lines representing the edges
   EdgeColor => undef,

   # Flexible<Float>  scaling factor for the thickness of the lines representing the edges
   EdgeThickness => undef,

   # EdgeMap<String>  textual labels to be placed along the edges
   EdgeLabels => undef,

   # Flexible<String>  if set to "hidden", neither the edge nor its label is rendered
   EdgeStyle => undef,
);


# @category Visualization
# Attributes modifying the appearance of filled polygons.

options %Visual::Polygon::decorations=(
   %Visual::PointSet::decorations,

   # Color  filling color of the polygon
   FacetColor => undef,

   # Float  transparency factor of the polygon between 0 (opaque) and 1 (completely translucent)
   FacetTransparency => undef,

   # String  if set to "hidden", the inner area of the polygon is not rendered
   FacetStyle => enum("hidden"),

   # Color  color of the boundary lines
   EdgeColor => undef,

   # Float  scaling factor for the thickness of the boundary lines
   EdgeThickness => undef,

   # String  if set to "hidden", the boundary lines are not rendered
   EdgeStyle => enum("hidden"),
);


# @category Visualization
# Attributes modifying the appearance of a set of polygons (like a polygonal surface).

options %Visual::Polygons::decorations=(
   %Visual::PointSet::decorations,

   # Flexible<Color>  filling color of the polygons
   FacetColor => undef,

   # Flexible<Float>  transparency factor of the polygons between 0 (opaque) and 1 (completely translucent)
   FacetTransparency => undef,

   # Flexible<String>  if set to "hidden", the inner area of the polygons are not rendered at all
   FacetStyle => undef,

   # String  if set to "hidden", the facet labels are not displayed (in the most cases this is the default behavior)
   FacetLabels => enum("hidden"),

   # Color  color of the boundary lines
   EdgeColor => undef,

   # Float  scaling factor for the thickness of the boundary lines
   EdgeThickness => undef,

   # String  if set to "hidden", the boundary lines are not rendered
   EdgeStyle => enum("hidden"),
);


###############################################################################
#
#  basic visualization functions
#

# @category Visualization
# Create a composite drawing of several objects.
# @param Visual::Object vis_obj ... objects to be drawn together
# @option String Title name of the whole drawing; per default the name of the first Object is taken.
# @options %Visual::Polygons::decorations
# @return Visual::Container if called in void context, immediately starts the preferred rendering program.
# @example Draw a pretty 8-pointed star:
# > compose(cube(2)->VISUAL,cross(2,sqrt(2))->VISUAL,Title=>"A pretty star.",VertexLabels=>"hidden");

user_function compose(Visual::Object+, %) {
   my ($obj_list, $decor)=@_;
   my $vc=new Visual::Container(Title => delete $decor->{Title} // $obj_list->[0]->Title // $obj_list->[0]->Name,
                                defaults => $decor);
   $vc->elements=$obj_list;
   visualize($vc);
}

# @category Visualization
# Add new objects to a composite drawing.
# @param Visual::Container vis_container drawing produced by some visualization function
# @param Visual::Object vis_obj ... objects to be added
# @option String Title  new name for the drawing
# @option any decorations  to be applied to all components as default values.
# @return Visual::Container if called in void context, immediately starts the preferred rendering program.

user_function compose(Visual::Container, Visual::Object+, %) {
   my ($container, $obj_list, $decor)=@_;
   if (defined (my $title=delete $decor->{Title})) {
      $container->Title=$title;
   }
   push %{$container->defaults}, %$decor if keys %$decor;
   push @{$container->elements}, @$obj_list;
   visualize($container);
}

function bounding_box(Visual::DynamicCoords) {
   my $emb=shift;
   my $dummy=@$emb;     # enforce computations
   bounding_box($emb->coord);
}

sub enforce_static_coord {
   my ($vis, $attr)=@_;
   my $dummy=@{$vis->$attr};
}

function enforce_static(Visual::Object) { }

function enforce_static(Visual::Container) {
   my $c=shift;
   foreach my $vis (@{$c->elements}) {
      enforce_static($vis);
   }
}

function enforce_static(Visual::PointSet) {
   enforce_static_coord($_[0], "Vertices");
}

function enforce_static($) {
   croak( "don't know how to disable dynamic coordinates in ", (ref($_[0]) || "'$_[0]'") ) unless is_ARRAY($_[0]);
   foreach (@{$_[0]}) {
      enforce_static($_);
   }
}

# @category Visualization
# Suppress creation of dynamic (interactive) scenes.
# @param Visual::Object vis_obj drawing, e.g. created by ''VISUAL_GRAPH'' or ''SCHLEGEL''.
# @return Visual::Object if called in void context, immediately starts the preferred rendering program.

user_function static(Visual::Object) {
   enforce_static($_[0]);
   visualize($_[0]);
}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: