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
|
# 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.
#-------------------------------------------------------------------------------
# Functions defined here deliver filters for comparing output files produced by various visualisation functions
# with specimen files.
# The purpose of these filters is to remove variable parts of the output like timestamps or
# architecture-dependent values like point coordinates computed by spring embedder.
# Each filter is an anonymous subroutine expecting the current line in $_.
###################################################################################
sub filter_JVX {
sub {
s{(^\s*<meta (?:date|generator)=)".*?"(\s*/>)}{$1"XXX"$2};
}
}
sub filter_JVX_random_points {
my $dim=shift;
--$dim;
( filter_JVX(),
sub {
s{(^\s* <p (?:\s+ name=".*?")? >) [0-9.e+-]+ (?:\s+ [0-9.e+-]+){$dim} (</p>)}{${1}XXX${2}}x;
}
)
}
###################################################################################
sub filter_OFF_random_points {
my $dim=shift;
--$dim;
my $active=0;
sub {
if ($active==0) {
$active=-1 if /SKEL|COFF/;
} elsif ($active<0) {
($active)=/^(\d+)/; # number of points on the following lines
} else {
--$active;
s{^ [0-9.e+-]+ (?:\s+ [0-9.e+-]+){$dim} $}{XXX}x;
}
}
}
###################################################################################
sub filter_Java_random_points {
my $dim=shift;
--$dim;
sub {
s{\{ [0-9.e+-]+ (?:, [0-9.e+-]+){$dim} \}}{{XXX}}x;
}
}
###################################################################################
sub filter_PS_random_points {
sub {
s{(%%(?:Page)?BoundingBox:)(?: [0-9.]+){4}$}{$1 X Y X Y}
or
s{(?: [0-9.]+){4} (edge)$}{X Y X Y $1}
or
s{(?: [0-9.]+){2} (CenteredLabel)$}{X Y $1}
}
}
###################################################################################
sub filter_MP {
sub {
s{^(% (?:produced by polymake for|date:)) .*}{$1 XXX};
}
}
sub filter_MP_random_points {
my $dim=shift;
--$dim;
( filter_MP(),
sub {
s{(^\s* p\[\d+\] \s* := \s* \() [0-9.-]+ (?:, [0-9.-]+){$dim} (\))}{${1}XXX${2}}x;
}
)
}
###################################################################################
sub filter_graphviz {
# remove name
sub {
s{^(di)*graph\s+"(.*)"\s+}{};
}
}
###################################################################################
sub filter_POV {
# remove absolute paths
sub {
s{(?:/[^/]+)+?(/povray/)}{/XXX$1};
}
}
sub filter_POV_random_points {
my $dim=shift;
--$dim;
( filter_POV(),
sub {
s{< [0-9.e+-]+ (?:, [0-9.e+-]+){$dim} >}{XXX}x;
}
)
}
###################################################################################
sub filter_sketch {
# remove comments and take care of floating errors
sub {
s{^%.*}{};
s{\.(\d{4})\d+}{\.$1}g;
s{(\d+)\.9999}{$1+1}e;
s{(\d+)\.0000}{$1};
s{-0([^.])}{0$1};
}
}
###################################################################################
sub filter_svg {
my ($nocoord) = @_;
my $comment = 0;
# remove comments and take care of floating errors
sub {
if ($_ =~ s{^\s*<!--.*$}{}) {
$comment = 1;
return;
}
if ($_ =~ s{^\s*-->}{}) {
$comment = 0;
return;
}
if ($comment) {
undef $_;
return;
}
if (/style="([^"]*)"/) {
my $style = join("; ", sort(split(/;\s*/,$1)));
s{style="([^"]*)"}{style="$style"}g;
}
s{<(\w+)\s+>}{<$1>}g;
s{<!--.*-->}{}g;
if ($nocoord) {
s{"(?:-?\d+(?:\.\d+)? ?)+"}{X.XXX}g;
} else {
s{\.(\d{1})\d+}{\.$1}g;
s{(\d+)\.9}{$1+1}e;
s{(\d+)\.0}{$1};
}
}
}
sub filter_svg_random_points {
filter_svg(true);
}
###################################################################################
sub filter_threejs {
my ($nocoord) = @_;
my $in_common_code_block = 0;
# remove comments, timestamp and code that does not depend on the object to visualize and take care of floating errors
sub {
if ($_ =~ s{^// COMMON_CODE_BLOCK_BEGIN\b\K.*$}{}) {
$in_common_code_block = 1;
return;
}
if ($_ =~ s{^// COMMON_CODE_BLOCK_END\b\K.*$}{}) {
$in_common_code_block = 0;
return;
}
if ($in_common_code_block) {
undef $_;
return;
}
s{^//.*}{};
s{<!--.*-->}{}g;
if ($nocoord) {
s{new PMPoint\(\K(\s*-?\d+(?:\.\d+)\s*),(?-1),(?-1)(?=\))}{XXX,XXX,XXX}g;
}
s{\.(\d{2})\d+}{\.$1}g;
s{(\d+)\.99}{$1+1}e;
s{(\d+)\.00}{$1};
s{-0([^.])}{0$1};
s{^polymake for .*$}{};
s{^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) \w{3} .*$}{};
s{^<div id=\"model[0-9]*\"></div>}{<div id=\"model\"></div>};
# strip absolute paths from resource links
s{src='\K/.*?/(?=js/)}{};
}
}
sub filter_threejs_random_points {
filter_threejs(true);
}
# Local Variables:
# mode: perl
# cperl-indent-level:3
# End:
|