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
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://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.
#-------------------------------------------------------------------------------
use Visual::Drawing;
package Geomview::File;
use Polymake::Struct (
'@geom',
);
my $setup=<<'.';
(bbox-draw "world" no)
.
sub toString {
my ($self)=@_;
$setup . join("", map { $_->toString } @{$self->geom});
}
package Geomview::geom;
use Polymake::Struct (
[ '@ISA' => 'Visual::Drawing' ],
);
sub header {
my ($self)=@_;
my $id=$self->title;
if (length($id)) {
$id =~ s/\s/_/g;
} else {
$id="unnamed";
}
"(geometry $id { LIST\n";
}
sub trailer {
"} # end LIST\n)\n";
}
package Geomview::element;
sub new {
my $class=shift;
my $self=bless { @_ }, $class;
$self;
}
sub name : lvalue { (shift)->{name} }
sub toString {
my ($self)=@_;
"{" .
( defined($self->{appearance}) && " appearance { $self->{appearance} }\n" ) .
$self->contents .
"}\n";
}
sub points {
my ($self)=@_;
join("\n", map { Visual::print3dcoords($_) } @{$self->{points}})."\n";
}
sub colored_points {
my ($self)=@_;
my ($p, $c)=@$self{qw( points pointColors )};
my $i=-1;
is_code($c)
? join("", map { Visual::print3dcoords($_) . " " . $c->(++$i)->toFloat . " 0\n" } @$p)
: do { $c=$c->toFloat; join("", map { Visual::print3dcoords($_) . " $c 0\n" } @$p) }
}
sub facets {
my ($self)=@_;
join("", map { scalar(@$_) . " @$_\n" } @{$self->facets})
}
sub colored_facets {
my ($self)=@_;
my ($f, $c, $a)=@$self{qw( facets facetColors facetAlpha )};
my $i=-1;
$c=$c->toFloat unless is_code($c);
join("", map { ++$i; scalar(@$_) . " @$_ " .
(ref($c) ? $c->($i)->toFloat : $c) .
(defined($a) && " " . $a->($i)) . "\n"
} @$f)
}
sub lines {
my ($self)=@_;
my $text="";
for (my $l=$self->{lines}; $l; ++$l) {
$text.="2 @$l\n";
}
$text
}
sub colored_lines {
my ($self)=@_;
my $c=$self->{lineColors};
$c=$c->toFloat unless is_code($c);
my $text="";
for (my $l=$self->{lines}; $l; ++$l) {
$text.="2 @$l " . (ref($c) ? $c->($l)->toFloat : $c) . "\n";
}
}
package Geomview::OFF;
@ISA=qw( Geomview::element );
sub dim {
my ($self)=@_;
"OFF\n" . scalar(@{$self->{points}}) . " " . scalar(@{$self->{facets}}) . " 0\n"
}
sub contents {
my ($self)=@_;
( defined $self->{pointColors}
? "C" . $self->dim . $self->colored_points
: $self->dim . $self->points ) .
( defined $self->{facetColors} ? $self->colored_facets : $self->facets )
}
package Geomview::SKEL;
@ISA=qw( Geomview::element );
sub dim {
my ($self)=@_;
"SKEL\n" . scalar(@{$self->{points}}) . " " . $self->{n_lines} . "\n"
}
sub contents {
my ($self)=@_;
$self->dim . $self->points .
( defined $self->{lineColors} ? $self->colored_lines : $self->lines )
}
1
# Local Variables:
# c-basic-offset:3
# End:
|