head	1.11;
access;
symbols
	bobbase:1.11
	bob:1.11.1
	r2_1:1.11
	r2_0:1.11
	r1_1_beta:1.11
	r1_1_alpha:1.10
	r1_0:1.10
	r0_11:1.10
	r0_10:1.6
	r0_9:1.3;
locks
	thoth:1.11.1.1; strict;
comment	@# @;


1.11
date	94.07.25.17.26.39;	author thoth;	state Exp;
branches
	1.11.1.1;
next	1.10;

1.10
date	94.03.30.14.00.50;	author thoth;	state Exp;
branches;
next	1.9;

1.9
date	94.03.14.15.52.54;	author thoth;	state Exp;
branches;
next	1.8;

1.8
date	94.02.22.18.49.29;	author thoth;	state Exp;
branches;
next	1.7;

1.7
date	94.02.12.19.44.25;	author thoth;	state Exp;
branches;
next	1.6;

1.6
date	94.01.31.15.56.13;	author thoth;	state Exp;
branches;
next	1.5;

1.5
date	94.01.07.15.24.40;	author thoth;	state Exp;
branches;
next	1.4;

1.4
date	93.12.29.17.33.18;	author thoth;	state Exp;
branches;
next	1.3;

1.3
date	93.11.17.18.39.17;	author thoth;	state Exp;
branches;
next	1.2;

1.2
date	93.09.21.11.44.15;	author thoth;	state Exp;
branches;
next	1.1;

1.1
date	93.09.15.13.03.41;	author thoth;	state Exp;
branches;
next	;

1.11.1.1
date	95.01.13.19.58.04;	author thoth;	state Exp;
branches;
next	;


desc
@generator for C headers for convolutions.
@


1.11
log
@Name sanitization
@
text
@#!/local/bin/perl

#
#	Copyright 1993, Center for Computer Vision and Visualization,
#	University of Florida.  All rights reserved.
#

#
# $Log: gen-conv-h.perl,v $
# Revision 1.10  1994/03/30  14:00:50  thoth
# Ability to emit friend or normal declarations for convolutions.
#
# Revision 1.9  1994/03/14  15:52:54  thoth
# inline versions of convolutions can now be turned off.
#
# Revision 1.8  1994/02/22  18:49:29  thoth
# New template-template convolutions.
#
# Revision 1.7  1994/02/12  19:44:25  thoth
# Rehack of template operation specifications.
#
# Revision 1.6  1994/01/31  15:56:13  thoth
# removed cruft.
#
# Revision 1.5  1994/01/07  15:24:40  thoth
# Image class is now CoreImage and named image types are
# Image<P,T>.
#
# Revision 1.4  1993/12/29  17:33:18  thoth
# New operator scheme that prevents the need for trivial Image conversions.
#
# Revision 1.3  1993/11/17  18:39:17  thoth
# template reductions are now supported.
# forward convolutions are now supported.
#
# Revision 1.2  1993/09/21  11:44:15  thoth
# the convolution description files can now have arbitrary
# white space in the operation specifications.
#
# Revision 1.1  93/09/15  13:03:41  thoth
# Initial revision
# 
# Revision 1.2  93/05/27  11:46:09  thoth
# Copyright Notices
# 
# Revision 1.1  93/03/18  11:22:28  thoth
# Initial revision
# 

sub is_image {
    return $_[0] =~ /^I\(.*\)$/;
}

sub is_template {
    return $_[0] =~ /^T\(.*\)$/;
}

sub is_basic {
    return !&is_image(@@_) && !&is_template(@@_);
}

sub base_type {
    local($_) = @@_;
    if (/^[TI]\((.*)\)$/) {
	return $1;
    } else {
	return $_;
    }
}

sub param_code_of {
    local($_) = @@_;
    if (/^T\((.*)\)$/) {
	return "IA_DDTemplate<IA_Image<IA_Point<int>,$1> >";
    } elsif (/^I\((.*)\)$/) {
	return "IA_CoreImage<IA_Point<int>,$1>";
    } else {
	return $_;
    }
}

sub return_code_of {
    local($_) = @@_;
    if (/^T\((.*)\)$/) {
	return "IA_DDTemplate<IA_Image<IA_Point<int>,$1> >";
    } elsif (/^I\((.*)\)$/) {
	return "IA_Image<IA_Point<int>,$1>";
    } else {
	return $_;
    }
}

#
#
#

$friendly = 0;
# if 1, emit friend declarations suitable for use inside a class definition.
# if 0 emit declarations suitable for use anywhere else.

# parse flags

while (@@ARGV) {
    local ($_) = shift(@@ARGV);
    if ($_ eq "-friends") {
	$friendly=1;
    } else {
	unshift(@@ARGV, $_);
	last;
    }
}

while (<>) {
    next if /^\s*$/;

    if (/^#/) {
	print "//", $';
	next;
    }

    print "// $_";

    @@_ = split;

    $sort = shift(@@_);

    if ($sort eq "convolution") {

	local ($name) = shift(@@_);

	local ($_);

	local($zero);
	while (@@_) {
	    $_ = $_[0];
	    if (/^zero=/) {
		$zero = $';
	    } else {
		last;
	    }
	    shift(@@_);
	}

	local($rval, $lhs, $rhs, @@blah) = @@_;

	die "extra arguments on convolution line: ", join(" ", @@blah)
	    if (@@blah);

	while ($_=<>) {
	    chop;
	    last if $_ eq "end";

	    die "unknown convolution field: $_\n"
		unless (/^(init|accum|accvar|final):\s*/);
	}

	if (&is_image($rval) && &is_image($lhs) && &is_template($rhs)) {
	    # backward template convolution

	    local ($baserval, $baselhs, $baserhs) =
		(&base_type($rval),&base_type($lhs),&base_type($rhs));
	    print "friend " if $friendly;
	    print &return_code_of($rval), " $name(",
	    "const ", &param_code_of($lhs), " &img,\n",
	    "\t\tconst ", &param_code_of($rhs), " &templ,\n",
	    "\t\tIA_Set<IA_Point<int> > dest_ps);\n";
	    print "\n";

	    if (!$friendly) {
		print "#ifndef NO_INLINE_CONVS\n";
		print "inline ";
		print &return_code_of($rval), " $name(",
		"const ", &param_code_of($lhs), " &img,\n",
		"\t\tconst ", &param_code_of($rhs), " &templ) {\n",
		"    return $name(img, templ, img.domain());\n",
		"}\n";
		print "#endif // NO_INLINE_CONVS\n\n";
	    }
	} elsif (&is_image($rval) && &is_template($lhs) && &is_image($rhs)) {
	    # forward template convolution

	    local ($baserval, $baselhs, $baserhs) =
		(&base_type($rval),&base_type($lhs),&base_type($rhs));
	    print "friend " if $friendly;
	    print &return_code_of($rval), " $name(",
	    "const ", &param_code_of($lhs), " &templ,\n",
	    "\t\tconst ", &param_code_of($rhs), " &img,\n",
	    "\t\tIA_Set<IA_Point<int> > dest_ps);\n";
	    print "\n";

	    if (!$friendly) {
		print "#ifndef NO_INLINE_CONVS\n";
		print "inline ";
		print &return_code_of($rval), " $name(",
		"const ", &param_code_of($lhs), " &templ,\n",
		"\t\tconst ", &param_code_of($rhs), " &img) {\n",
		"    return $name(templ, img, img.domain());\n",
		"}\n";
		print "#endif // NO_INLINE_CONVS\n\n";
	    }
	} elsif (&is_template($rval)
		 && &is_template($lhs)
		 && &is_template($rhs)) {
	    local ($baserval, $baselhs, $baserhs) =
		(&base_type($rval),&base_type($lhs),&base_type($rhs));
	    print "friend " if $friendly;
	    print &return_code_of($rval), " $name(",
	    "const ", &param_code_of($lhs), " &templ,\n",
	    "\t\tconst ", &param_code_of($rhs), " &img);\n";
	    print "\n";

	} else {
	    die "Unknown argument configuration to convolution: $rval $lhs $rhs";
	}

    } elsif ($sort eq "reduction") {

	local ($name) = shift(@@_);

	local ($_);

	local($zero);
	while (@@_) {
	    $_ = $_[0];
	    if (/^zero=/) {
		$zero = $';
	    } else {
		last;
	    }
	    shift(@@_);
	}

	local($rval, $arg, @@blah) = @@_;

	die "extra arguments on convolution line: ", join(" ", @@blah)
	    if (@@blah);

	while ($_ = <>) {
	    chop;
	    last if $_ eq "end";

	    if (/^accum:\s*/) {
		$accum = $';
	    } else {
		die "unknown reduction field: $_\n";
	    }
	}
	defined $accum || die "no accumulator for reduction $name\n";

	if (&is_image($rval) && &is_template($arg)) {
	    print "friend " if $friendly;
	    print &return_code_of($rval), " $name(\n",
	    "\tIA_Set<IA_Point<int> > domain,\n",
	    "\t", &param_code_of($arg), " templ,\n",
	    "\tIA_Set<IA_Point<int> > dest_domain);\n\n";
	} else {
	    die "Unknown argument configuration to reduction: $rval $arg\n";
	}
    } elsif  ($sort eq "binary") {

	local ($name) = shift(@@_);

	local ($_);

	local($zero, $gamma);
	while (@@_) {
	    $_ = $_[0];
	    if (/^zero=/) {
		$zero = $';
	    } elsif (/^gamma=/) {
		$gamma = $';
	    } else {
		last;
	    }
	    shift(@@_);
	}

	local($rval, $lhs, $rhs, @@blah) = @@_;

	die "extra arguments on convolution line: ", join(" ", @@blah)
	    if (@@blah);

	if (&is_template($rval) && &is_template($lhs) && &is_template($rhs)) {
	    print "friend " if $friendly;
	    print &return_code_of($rval), " $name(\n",
	    "\tconst ", &param_code_of($lhs), " &t1,\n",
	    "\tconst ", &param_code_of($rhs), " &t2);\n\n";
	} else {
	    die "Unknown argument configuration to binary: $rval $lhs $rhs";
	}
    } else {
	die "Unknown template operation $sort\n";
    }
}
@


1.11.1.1
log
@CoreImage has been re-merged with Image.  All special stuff should be
friends of FBI now.
@
text
@d9 1
a9 4
# $Log: h-gen-conv.perl,v $
# Revision 1.11  1994/07/25  17:26:39  thoth
# Name sanitization
#
d76 1
a76 1
	return "IA_Image<IA_Point<int>,$1>";
@


1.10
log
@Ability to emit friend or normal declarations for convolutions.
@
text
@d10 3
d74 1
a74 1
	return "IA_DDTemplate<IA_Image<IA_IntPoint,$1> >";
d76 1
a76 1
	return "IA_CoreImage<IA_IntPoint,$1>";
d85 1
a85 1
	return "IA_DDTemplate<IA_Image<IA_IntPoint,$1> >";
d87 1
a87 1
	return "IA_Image<IA_IntPoint,$1>";
d166 1
a166 1
	    "\t\tIA_Set<IA_IntPoint> dest_ps);\n";
d188 1
a188 1
	    "\t\tIA_Set<IA_IntPoint> dest_ps);\n";
d253 1
a253 1
	    "\tIA_IntPointSet domain,\n",
d255 1
a255 1
	    "\tIA_IntPointSet dest_domain);\n\n";
@


1.9
log
@inline versions of convolutions can now be turned off.
@
text
@d10 3
d94 16
d159 1
a159 1
	    print "friend ";
d166 10
a175 8
	    print "#ifndef NO_INLINE_CONVS\n";
	    print "inline friend ";
	    print &return_code_of($rval), " $name(",
	    "const ", &param_code_of($lhs), " &img,\n",
	    "\t\tconst ", &param_code_of($rhs), " &templ) {\n",
	    "    return $name(img, templ, img.domain());\n",
	    "}\n";
	    print "#endif // NO_INLINE_CONVS\n\n";
d181 1
a181 1
	    print "friend ";
d188 10
a197 8
	    print "#ifndef NO_INLINE_CONVS\n";
	    print "inline friend ";
	    print &return_code_of($rval), " $name(",
	    "const ", &param_code_of($lhs), " &templ,\n",
	    "\t\tconst ", &param_code_of($rhs), " &img) {\n",
	    "    return $name(templ, img, img.domain());\n",
	    "}\n";
	    print "#endif // NO_INLINE_CONVS\n\n";
d203 1
a203 1
	    print "friend ";
d210 1
a210 1
	    die "Unknown argument configuration to convolution: $rval $lhs $rhs\n";
d248 2
a249 1
	    print "friend ", &return_code_of($rval), " $name(\n",
d281 2
a282 1
	    print "friend ", &return_code_of($rval), " $name(\n",
d286 1
a286 1
	    die "Unknown argument configuration to binary: $rval $lhs $rhs\n";
@


1.8
log
@New template-template convolutions.
@
text
@d10 3
d147 1
d153 2
a154 1
	    "}\n\n";
d167 1
d173 2
a174 1
	    "}\n\n";
@


1.7
log
@Rehack of template operation specifications.
@
text
@d10 3
d168 11
@


1.6
log
@removed cruft.
@
text
@d10 3
d38 47
a99 3
	local($rtype, $name, $itype, $ttype, @@blah) = @@_;
	#unless ($ttype =~ m-/-) {die "template type must be of form image/base\n";}
	$titype = "IA_Image<IA_IntPoint,$ttype> ";
d101 1
a101 1
	@@_ = @@blah;
d103 2
a105 1

d107 1
a107 2
	    $_ = shift(@@_);

d111 1
a111 1
		warn "Unknown option $_. ";
d113 1
d116 5
d126 1
a126 1
		unless (/^(init|accum|accvar|final|forw_init|forw_accumvar):\s*/);
d129 2
a130 7
	# backward template convolution
	print "friend ";
	print "IA_Image<IA_IntPoint,$rtype> $name(",
	"const IA_CoreImage<IA_IntPoint,$itype> &img,\n",
	"\t\tconst IA_DDTemplate<$titype> &templ,\n",
	"\t\tIA_Set<IA_IntPoint> dest_ps);\n";
	print "\n";
d132 8
a139 7
	print "inline friend ";
	print "IA_Image<IA_IntPoint,$rtype> $name(",
	"const IA_CoreImage<IA_IntPoint,$itype> &img,\n",
	"\t\tconst IA_DDTemplate<$titype> &templ) {\n",
	"    return $name(img, templ, img.domain());\n",
	"}\n";
	print "\n";
d141 8
a148 7
	# forward template convolution
	print "friend ";
	print "IA_Image<IA_IntPoint,$rtype> $name(",
	"const IA_DDTemplate<$titype> &templ,\n",
	"\t\tconst IA_CoreImage<IA_IntPoint,$itype> &img,\n",
	"\t\tIA_Set<IA_IntPoint> dest_ps);\n";
	print "\n";
d150 19
a168 7
	print "inline friend ";
	print "IA_Image<IA_IntPoint,$rtype> $name(",
	"const IA_DDTemplate<$titype> &templ,\n",
	"\t\tconst IA_CoreImage<IA_IntPoint,$itype> &img) {\n",
	"    return $name(templ, img, img.domain());\n",
	"}\n";
	print "\n";
a169 2
	local($rtype, $name, $ttype, @@blah) = @@_;
	$titype = "IA_Image<IA_IntPoint,$ttype> ";
d171 1
a171 1
	@@_ =  @@blah;
d173 2
a175 1

d177 1
a177 2
	    $_ = shift(@@_);

d181 1
a181 1
		warn "Unknown option $_. ";
d183 1
d186 5
d203 41
a243 5
	print "friend ";
	print "IA_Image<IA_IntPoint,$rtype> $name(\n",
	"\tIA_IntPointSet domain,\n",
	"\tIA_DDTemplate<$titype > templ,\n",
	"\tIA_IntPointSet dest_domain);\n\n";
@


1.5
log
@Image class is now CoreImage and named image types are
Image<P,T>.
@
text
@d10 4
a33 31

sub file_subst {
	local ($fname,
		$init, $accum, $final,
		$rtype, $name, $itype, $ttype, $zero) = @@_;
	open(FILE, "<$fname") ||
		die "couldn't open $fname";
	local($_);
	local($/) = -1;
	$_ = <FILE>;

	s/\bINITIALIZE\b/$init/g;
	s/\bACCUMULATE\b/$accum/g;
	s/\bRESULT\b/$final/g;

	s/\bRTYPE\b/$rtype/g;
	s/CONV/$name/g;
	s/\bITYPE\b/$itype/g;
	s/\bTTYPE\b/$ttype/g;
	s/\bZERO\b/$zero/g;

	s/\bIVAL\b/(base[offsets[i]])/g;
	s/\bTVAL\b/(templ_data[i])/g;
	s/\bIRESULT\b/(*valp)/g;

	print $_;

	$/ = '\n';

	close(FILE);
}
@


1.4
log
@New operator scheme that prevents the need for trivial Image conversions.
@
text
@d10 3
d79 1
a79 1
	$titype = "/*PROMOTE*/IA_Image<IA_IntPoint,$ttype> ";
d105 2
a106 2
	print "/*PROMOTE*/IA_Image<IA_IntPoint,$rtype> $name(",
	"const IA_Image<IA_IntPoint,$itype> &img,\n",
d112 2
a113 2
	print "/*PROMOTE*/IA_Image<IA_IntPoint,$rtype> $name(",
	"const IA_Image<IA_IntPoint,$itype> &img,\n",
d121 1
a121 1
	print "/*PROMOTE*/IA_Image<IA_IntPoint,$rtype> $name(",
d123 1
a123 1
	"\t\tconst IA_Image<IA_IntPoint,$itype> &img,\n",
d128 1
a128 1
	print "/*PROMOTE*/IA_Image<IA_IntPoint,$rtype> $name(",
d130 1
a130 1
	"\t\tconst IA_Image<IA_IntPoint,$itype> &img) {\n",
d136 1
a136 1
	$titype = "/*PROMOTE*/IA_Image<IA_IntPoint,$ttype> ";
d165 1
a165 1
	print "/*PROMOTE*/IA_Image<IA_IntPoint,$rtype> $name(\n",
@


1.3
log
@template reductions are now supported.
forward convolutions are now supported.
@
text
@d10 4
d76 1
a76 1
	$titype = "IA_Image<IA_IntPoint,$ttype> ";
d102 1
a102 1
	print "IA_Image<IA_IntPoint,$rtype> $name(",
d109 1
a109 1
	print "IA_Image<IA_IntPoint,$rtype> $name(",
d118 1
a118 1
	print "IA_Image<IA_IntPoint,$rtype> $name(",
d125 1
a125 1
	print "IA_Image<IA_IntPoint,$rtype> $name(",
d133 1
a133 1
	$titype = "IA_Image<IA_IntPoint,$ttype> ";
d162 1
a162 1
	print "IA_Image<IA_IntPoint,$rtype> $name(\n",
@


1.2
log
@the convolution description files can now have arbitrary
white space in the operation specifications.
@
text
@d9 5
a13 1
# $Log:	gen-conv-h.perl,v $
d67 1
a67 3
    local($rtype, $name, $itype, $ttype, @@blah) = @@_;
   #unless ($ttype =~ m-/-) {die "template type must be of form image/base\n";}
    $titype = "IA_Image<IA_IntPoint,$ttype> ";
d69 4
a72 1
    @@_ = @@blah;
d74 1
a74 1
    local($zero);
d76 1
a76 2
    while (@@_) {
	$_ = shift(@@_);
d78 4
a81 1
	if (/^zero=/) {
d83 1
a83 1
	} else {
d85 1
a86 1
    }
d88 3
a90 2
    $_ = <>; chop;
    /^init:\s*/ || die "no initiazlier for convolution $name\n";
d92 3
a94 8
    $_ = <>; chop;
    /^accum:\s*/ || die "no accumulator for convolution $name\n";

    $_ = <>; chop;
    if (/^accvar:\s*/) {
	$_ = <>; chop;
    }
    /^final:\s*/ || die "no final for convolution $name\n";
d96 3
a98 2
    print "friend ";
    print "IA_Image<IA_IntPoint,$rtype> $name(",
d102 1
a102 1
    print "\n";
d104 2
a105 2
    print "inline friend ";
    print "IA_Image<IA_IntPoint,$rtype> $name(",
d110 53
a162 1
    print "\n";
@


1.1
log
@Initial revision
@
text
@d10 3
d82 1
a82 1
    /^init:\t/ || die "no initiazlier for convolution $name\n";
d85 1
a85 1
    /^accum:\t/ || die "no accumulator for convolution $name\n";
d88 1
a88 1
    if (/^accvar:\t/) {
d91 1
a91 1
    /^final:\t/ || die "no final for convolution $name\n";
d96 1
a96 1
	"\t\tconst IA_DDTemplate<$titype> &invtempl,\n",
d98 8
@
