====== Tutorial for Visualization ======
This tutorial contains some examples for the visualization of the different objects dealt with in polymake.
===== Intro =====
The most straighforward way of visualizing things in ''%%polymake%%'' is by using the ''%%VISUAL%%'' method that visualizable objects provide. For example, you can look at the 3-simplex by doing this:
> simplex(3)->VISUAL;
> help 'objects/Polytope/methods/Visualization';
These methods are for visualization.
-------------------
Subtopics of polytope/objects/Polytope/methods/Visualization:
GALE, SCHLEGEL, VISUAL, VISUAL_DUAL, VISUAL_DUAL_FACE_LATTICE, VISUAL_DUAL_GRAPH, VISUAL_FACE_LATTICE, VISUAL_GRAPH, VISUAL_ORBIT_COLORED_GRAPH, write_stl
Subtopics of objects/Polytope/methods/Visualization:
GALE, SCHLEGEL, VISUAL, VISUAL_BOUNDED_GRAPH, VISUAL_DUAL, VISUAL_DUAL_FACE_LATTICE,
VISUAL_DUAL_GRAPH, VISUAL_FACE_LATTICE, VISUAL_GRAPH, VISUAL_TRIANGULATION_BOUNDARY
Most visualization methods provide a variety of parameters. Get a list for the method of yout choice (here: ''%%VISUAL%%'') by typing
> help 'objects/Polytope/methods/Visualization/VISUAL';
VISUAL(Options) -> Visual::Polytope
Visualize a polytope as a graph (if 1d), or as a solid object (if 2d or 3d),
or as a Schlegel diagram (4d).
Options: Attributes modifying the appearance of a set of polygons (like a polygonal surface).
__FacetColor__ => Flexible filling color of the polygons
__FacetTransparency__ => Flexible transparency factor of the polygons between 0 (opaque) and 1 (completely translucent)
__FacetStyle__ => Flexible if set to "hidden", the inner area of the polygons are not rendered at all
__FacetLabels__ => String if set to "hidden", the facet labels are not displayed (in the most cases this is the default behavior)
__EdgeColor__ => Color color of the boundary lines
__EdgeThickness__ => Float scaling factor for the thickness of the boundary lines
__EdgeStyle__ => String if set to "hidden", the boundary lines are not rendered
__Title__ => String the name of the drawing
__Name__ => String the name of this visual object in the drawing
__Hidden__ => Bool if set to true, the visual object is not rendered
(useful for interactive visualization programs allowing for switching details on and off)
__PointLabels__ => String if set to "hidden", no point labels are displayed
__VertexLabels__ => String alias for PointLabels
__PointColor__ => Flexible color of the spheres or rectangles representing the points
__VertexColor__ => Flexible alias for PointColor
__PointThickness__ => Flexible scaling factor for the size of the spheres or rectangles representing the points
__VertexThickness__ => Flexible alias for PointThickness
__PointBorderColor__ => Flexible color of the border line of rectangles representing the points
__VertexBorderColor__ => Flexible alias for PointBorderColor
__PointBorderThickness__ => Flexible scaling factor for the thickness of the border line of rectangles representing the points
__VertexBorderThickness__ => Flexible alias for PointBorderThickness
__PointStyle__ => Flexible if set to "hidden", neither point nor its label is rendered
__VertexStyle__ => Flexible alias for PointStyle
__ViewPoint__ => Vector ViewPoint for Sketch visualization
__ViewDirection__ => Vector ViewDirection for Sketch visualization
__ViewUp__ => Vector ViewUp for Sketch visualization
__Scale__ => Float scale for Sketch visualization
__LabelAlignment__ => Flexible Defines the alignment of the vertex labels: left, right or center
Options: 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.
__EdgeColor__ => Flexible color of the lines representing the edges
__EdgeThickness__ => Flexible scaling factor for the thickness of the lines representing the edges
__EdgeLabels__ => EdgeMap textual labels to be placed along the edges
__EdgeStyle__ => Flexible if set to "hidden", neither the edge nor its label is rendered
__Title__ => String the name of the drawing
__Name__ => String the name of this visual object in the drawing
__Hidden__ => Bool if set to true, the visual object is not rendered
(useful for interactive visualization programs allowing for switching details on and off)
__PointLabels__ => String if set to "hidden", no point labels are displayed
__VertexLabels__ => String alias for PointLabels
__PointColor__ => Flexible color of the spheres or rectangles representing the points
__VertexColor__ => Flexible alias for PointColor
__PointThickness__ => Flexible scaling factor for the size of the spheres or rectangles representing the points
__VertexThickness__ => Flexible alias for PointThickness
__PointBorderColor__ => Flexible color of the border line of rectangles representing the points
__VertexBorderColor__ => Flexible alias for PointBorderColor
__PointBorderThickness__ => Flexible scaling factor for the thickness of the border line of rectangles representing the points
__VertexBorderThickness__ => Flexible alias for PointBorderThickness
__PointStyle__ => Flexible if set to "hidden", neither point nor its label is rendered
__VertexStyle__ => Flexible alias for PointStyle
__ViewPoint__ => Vector ViewPoint for Sketch visualization
__ViewDirection__ => Vector ViewDirection for Sketch visualization
__ViewUp__ => Vector ViewUp for Sketch visualization
__Scale__ => Float scale for Sketch visualization
__LabelAlignment__ => Flexible Defines the alignment of the vertex labels: left, right or center
Options: 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.
__Title__ => String the name of the drawing
__Name__ => String the name of this visual object in the drawing
__Hidden__ => Bool if set to true, the visual object is not rendered
(useful for interactive visualization programs allowing for switching details on and off)
__PointLabels__ => String if set to "hidden", no point labels are displayed
__VertexLabels__ => String alias for PointLabels
__PointColor__ => Flexible color of the spheres or rectangles representing the points
__VertexColor__ => Flexible alias for PointColor
__PointThickness__ => Flexible scaling factor for the size of the spheres or rectangles representing the points
__VertexThickness__ => Flexible alias for PointThickness
__PointBorderColor__ => Flexible color of the border line of rectangles representing the points
__VertexBorderColor__ => Flexible alias for PointBorderColor
__PointBorderThickness__ => Flexible scaling factor for the thickness of the border line of rectangles representing the points
__VertexBorderThickness__ => Flexible alias for PointBorderThickness
__PointStyle__ => Flexible if set to "hidden", neither point nor its label is rendered
__VertexStyle__ => Flexible alias for PointStyle
__ViewPoint__ => Vector ViewPoint for Sketch visualization
__ViewDirection__ => Vector ViewDirection for Sketch visualization
__ViewUp__ => Vector ViewUp for Sketch visualization
__Scale__ => Float scale for Sketch visualization
__LabelAlignment__ => Flexible Defines the alignment of the vertex labels: left, right or center
Options: Options for visualizing objects with homogeneous coordinates like Polytope, PolyhedralComplex, SubdivisionOfPoints and PointConfiguration.
__BoundingFacets__ => Matrix useful for unbounded polyhedra
__Transformation__ => Matrix linear transformation, to be applied after dehomogenization
__Offset__ => Vector shift, to be applied after dehomogenization and the linear transformation
Returns Visual::Polytope
The syntax for passing parameters can be seen in this example:
simplex(3)->VISUAL(EdgeThickness => 10);
It visualizes a tetrahedron with really thick edges. See the section on [[visual_tutorial#application%20polytope|visual_tutorial#application polytope]] for more.
==== Specifying colors ====
Some visualization methods requite you to specify colors. There are various ways of doing this in polymake, i.e. the color red may be given by
* the String ''%%'red%%''', which will be looked up in rgb.txt to obtain the rgb values,
* the String ''%%'1 0 0%%''', which contains three decimal values in the interval [0,1] corresponding to the 'r g b'-values of the color,
* the String ''%%'255 0 0%%''', which contains three integer values in the interval [0,255] corresponding to the 'r g b'-values of the color,
* an object ''%%new RGB(1,0,0)%%'' of polymake's RGB class.
===== application polytope =====
The application 'polytope' contains a large amount of visualization routines. Most of them allow you to change the way things look a various ways. See the following subsections for examples.
==== Changing vertex attributes ====
It is possible to change the way the vertices are displayed directly from the command line. In the following we will explain how to change the color, labels, and size of the vertices.
=== Colors ===
There are different ways to specify the colors of the vertices. You may choose a single color for all vertices or set each vertex color individually.
**Single color**: To specify one color for all vertices use the //VertexColor// attribute of the //VISUAL// method:
> simplex(3)->VISUAL(VertexColor=> '0 100 200');
> simplex(3)->VISUAL(VertexColor=>['red','green','blue','yellow']);
polytope > simplex(3)->VISUAL(VertexColor=>['red','0 1 0',new RGB(0,0,1),'255 255 0']);
See [[visual_tutorial#Specifying%20Colors|]] for different ways to specify colors.
**Function**: You may also pass a function, i.e. a perl ''%%sub%%'', to the //VertexColors// attribute that returns a color depending on the vertex index. The following line produces a tetrahedron with colors ranging from black for vertex 0 to yellow for vertex 3:
polytope > simplex(3)->VISUAL(VertexColor=> sub { $i = shift; new RGB($i*0.33,$i*0.33,0); });
{{:tutorials:release:4.6:visual_tutorial:visual_vertexcolor_sub.jpg}}
=== Labels ===
The labels can be specified either by an array or a function that returns a label depending on the index of the vertex.
%%**%% Array of labels %%**%%: To label the vertices of a tetrahedron by A, B, C, and D we just pass the array ''%%["A", "B", "C", "D"]%%'' to the //VertexLabels// attribute:
> simplex(3)->VISUAL(VertexLabels=>["A", "B", "C", "D"]);
> simplex(3)->VISUAL(VertexLabels=>["", "", "My favorite vertex", ""]);
> $tet = simplex(3);
> $tet->VISUAL(VertexLabels=> sub { my $i = shift; return $tet->VERTICES->[$i]; });
> $tet->VISUAL(VertexLabels=> sub { my $i = shift; return convert_to(dehomogenize($tet->VERTICES->[$i]));});
> simplex(3)->VISUAL(VertexThickness=>2);
> simplex(3)->VISUAL(VertexThickness=>[1,2,3,4]);
> cube(3)->VISUAL(VertexThickness=> sub { my $i = shift; if($i%2 == 0) { return 2; } else {return 1;} });
> cube(3)->VISUAL(VertexStyle=>"hidden");
> $c1=cube(3,0);
> $c2=transform($c1,new Matrix([[1,-1,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]));
> compose($c1->VISUAL,$c2->VISUAL);
:::perl
> $my_polytope = cube(3);
> sketch($my_polytope->VISUAL,File=>"myfile.sketch");
When you downloaded the Sketch interpreter ([[http://sketch4latex.sourceforge.net/|link]]) you can use it to create your TikZ file via:
:::perl
sketch myfile.sketch > myfile.tikz
The drawback is that the produced TikZ code is quite cryptic and not really readable or editable anymore. If you do want to create TikZ code which is easier to edit afterwards, you might want to use polymake's TikZ interface via:
:::perl
> tikz($my_polytope->VISUAL,File=>"myfile.tikz");
For a different viewing angle you may use jReality. Rotate the polytope into the position you want and click the ''%%'save view%%''' button on the bottom of the jReality window. Then produce the TikZ or Sketch output.
==== jReality ====
The jReality viewer offers a versatile perspective for your favourite tools on 4 Panel which may be enabled/disabled on the toolbar or using the keyboard shortcuts Alt+Shift+(Up|Down|Left|Right) or the window menu. The "Visualization", "Split geometries", "Content Appearance", and "Navigator" Plugin(usually in the Left- resp. Right-Slot) may be used to change the appearance of the displayed geometry. How to achieve your desired parameters is explained in the following section.
=== Appearance ===
There are several objects which control the appearance of a geometry in jreality:
- geometry attributes,
- appearances at a specific scene graph nodes, and
- the content appearance.
The most versatile point to set different parameters for the appearance is via geometry attributes. This is needed, for example, if every vertex of the displayed geometry should have its own thickness or color like in VISUAL_GRAPH->VERTEX_COLORS. These may only be edited via jreality's bean-shell, which requires knowledge of the jreality API and in particular the attribute handling.
An appearance at a scene graph node (every VISUAL object is put into one of these) may have its own appearance which stores single values for colors/thicknesses of vertices/edges/faces. Hence this does not allow, e.g., to assign a different color to each vertex. But editing is a little easier, since it is possible to use jreality's navigator. The navigator displays the entire scene graph. The polymake part of the scene graph starts with "root->content->Polymake Root". The VISUALs are stored in separate geometry nodes with its appearances. In each of the appearance you find the RenderingHints and Shader that either inherit properties of the content appearance or override them with their own values. This is already much less tedious than using the beanshell.
The content appearance comes into play if no other appearances exist in the content subtree, i.e. neither specific node appearances nor geometry attributes. The sizes/thicknesses set in the content appearance are multiplied with the values of the specified values deeper in the tree, but colors will only apply if nothing else is set.
So to be able to change the colors of the faces/edges/vertices of the geometry using the content appearance you need to get rid settings in the other appearances and geometry attributes. This may be done using the "clear attributes" and "clear appearance" item of the polymake menu.
=== Save View ===
Clicking the "Save View" button on the bottom of the jReality window attaches a "ViewTransformation" matrix to your object (read [[reference/clients#attachments|this]] if you don't know how attachments work). It contains the transformaiton necessary to convert the coordinates of your object to the coordinates of the (possibly rotated, translated etc. by you in the interactive visualization) object as you currently see it. This information is then used by jReality and Sketch to display the object in exactly that way if you visualize it the next time.