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
|
# 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.
#-------------------------------------------------------------------------------
package Geomview::Viewer;
CREDIT geomview
Geomview is an interactive 3D viewing program, originally developed
at The Geometry Center, at the University of Minnesota.
http://www.geomview.org/
# path to the main geomview executable
custom $geomview;
CONFIGURE {
find_program($geomview, "geomview");
}
# @category Visualization
# Use [[wiki:external_software#geomview|geomview]], an alternative tool for the visualization
# of 3- or 4-dimensional geometrical objects.
label geomview
###########################################################################################
#
# Drawing methods for graphical primitives defined in this module
#
use Geomview;
sub point_appearance {
my $P=shift;
my $style=$P->VertexStyle;
( defined($style) && !is_code($style) && $style =~ $Visual::hidden_re
? () :
defined($P->VertexColor)
? (pointColors => $P->VertexColor) : (),
points => $P->Points,
dim => $P->Dim,
);
}
sub facet_appearance {
my $P=shift;
my $style=$P->FacetStyle;
if (defined($style) && !is_code($style) && $style =~ $Visual::hidden_re) {
( appearance => "-face +edge ".($P->Closed ? "" : " -backcull") );
} else {
my $transp=$P->FacetTransparency;
( defined($transp)
? is_code($transp)
? ( appearance => "face transparent -edge",
facetAlpha => $transp,
)
: ( appearance => "face transparent -edge material { alpha $transp }" )
: $P->Closed ? () : ( appearance => "-backcull" ),
defined($P->FacetColor)
? ( facetColors => $P->FacetColor) : ()
);
}
}
sub line_appearance {
my ($G)=@_;
my ($appearance, @params);
my $thickness=$G->EdgeThickness;
if (defined($thickness) && !is_code($thickness)) {
$appearance="linewidth $thickness";
}
if (defined (my $color=$G->EdgeColor)) {
if (is_code($color)) {
@params=( lineColors => $color );
} else {
$appearance.=" material { edgecolor " . $color->toFloat . " }";
}
}
push @params, ( appearance => $appearance ) if $appearance;
@params;
}
global_method geomview.geometry: draw(Visual::PointSet, @) {
my ($self, $P)=@_;
my $geom=new Geomview::OFF( name => $P->Name,
point_appearance($P),
facets => [ ],
);
$self->append($geom);
}
global_method geomview.geometry: draw(Visual::Polygon, @) {
my ($self, $P)=@_;
my $geom=new Geomview::OFF( name => $P->Name,
point_appearance($P),
facets => $P->Facets,
facet_appearance($P),
);
$self->append($geom);
}
global_method geomview.geometry: draw(Visual::Polygons, @) {
my ($self, $P)=@_;
my $geom=new Geomview::OFF( name => $P->Name,
point_appearance($P),
facets => $P->Facets,
facet_appearance($P),
);
$self->append($geom);
}
global_method geomview.graph: draw(Visual::WireBase, @) {
my ($self, $G)=@_;
my $geom=new Geomview::SKEL( name => $G->Name,
points => $G->Vertices,
dim => $G->Dim,
lines => $G->all_edges,
n_lines => $G->n_edges,
line_appearance($G),
);
$self->append($geom);
}
###########################################################################################
#
# Implementation of the Viewer interface
#
use BackgroundViewer;
use Polymake::Struct [ '@ISA' => 'Background::Viewer' ];
sub file_suffix { ".gcl" }
sub new {
my $self=&_new;
$self->graphics=new Geomview::File;
$self;
}
sub command {
my ($self, $filename)=@_;
"$geomview $filename";
}
sub new_drawing {
my ($self, $title)=@_;
push @{$self->graphics->geom}, new geom($title);
$self;
}
sub append {
my $self=shift;
$self->graphics->geom->[-1]->append(@_);
}
###########################################################################################
#
# Writes to a gcl file without starting a GUI
#
package Geomview::File::Writer;
import Visual::FileWriter(multiple => 1);
###########################################################################################
package application;
# @category Visualization
# Run [[wiki:external_software#geomview|geomview]] to display given visual objects.
#
# @param Visual::Object vis_obj ... objects to display
#
# @option String File "filename" or "AUTO"
# Store the objects in a ''gcl'' (geomview control language) file instead of starting the interactive GUI.
# The geometric data in ''OFF'' format is embedded in the Lisp-style commands, but can be easily extracted
# using any text editor, if needed.
#
# The ''.gcl'' suffix is automatically added to the file name.
#
# Specify //AUTO// if you want the filename be automatically derived
# from the drawing title.
#
# You can also use any expression allowed for the ''open'' function,
# including "-" for terminal output, "&HANDLE" for an already opened file handle,
# or "| program" for a pipe.
user_function geomview(Visual::Object+, { File => undef }) {
visualize_explicit(@_, "Geomview");
}
# Local Variables:
# mode: perl
# cperl-indent-level:3
# End:
|