Initial commit: ArgyllCMS v3.5.0 and multichannel profiling research
This commit is contained in:
96
Argyll_V3.5.0/rspl/Jamfile
Executable file
96
Argyll_V3.5.0/rspl/Jamfile
Executable file
@@ -0,0 +1,96 @@
|
||||
|
||||
# Regular spline library
|
||||
|
||||
# Optimization and Debug flags
|
||||
|
||||
#PREF_CCFLAGS += $(CCOPTFLAG) ; # Turn optimisation on
|
||||
PREF_CCFLAGS += $(CCDEBUGFLAG) ; # Debugging flags
|
||||
#PREF_CCFLAGS += $(CCPROFFLAG) ; # Profile flags
|
||||
#PREF_LINKFLAGS += $(LINKPROFFLAG) ; # Profile flags
|
||||
#PREF_CCFLAGS += $(CCHEAPDEBUG) ; # Heap Debugging flags
|
||||
PREF_LINKFLAGS += $(LINKDEBUGFLAG) ; # Link with debug info
|
||||
|
||||
SCAT = scat ; # Use thps scattered interpolation library
|
||||
|
||||
#Products
|
||||
Libraries = librspl ;
|
||||
Headers = rspl.h ;
|
||||
|
||||
#Install
|
||||
#InstallLib $(DESTDIR)$(PREFIX)/lib : $(Libraries) ;
|
||||
#InstallFile $(DESTDIR)$(PREFIX)/h : $(Headers) ;
|
||||
|
||||
# Multi-dimensional regular spline library
|
||||
Library librspl : rspl.c $(SCAT).c rev.c gam.c spline.c opt.c : : : ../h ../numlib ../plot ;
|
||||
|
||||
HDRS = ../h ../numlib ../plot $(TIFFINC) ;
|
||||
LINKLIBS = librspl ../plot/libplot ../numlib/libnum ../numlib/libui ../plot/libvrml ../icc/libicc $(TIFFLIB) $(JPEGLIB) ;
|
||||
|
||||
# Test programs
|
||||
LINKFLAGS += $(GUILINKFLAGS) ;
|
||||
|
||||
MainsFromSources revbench.c c1.c cw1.c cw3.c c1df.c t2d.c t2ddf.c t3d.c t3ddf.c tnd.c trnd.c ;
|
||||
|
||||
BUILD_TESTS = false ;
|
||||
|
||||
if $(BUILD_TESTS) {
|
||||
|
||||
HDRS = ../h ../numlib ../plot ../icc ../rspl ../xicc ../gamut ../cgats ../spectro $(TIFFINC) ;
|
||||
LINKLIBS = ../xicc/libxicc ../gamut/libgamut ../spectro/libinsttypes librspl
|
||||
../cgats/libcgats ../icc/libicc ../plot/libplot ../plot/libvrml
|
||||
../spectro/libconv ../numlib/libnum ../numlib/libui $(TIFFLIB) $(JPEGLIB) ;
|
||||
|
||||
# Smoothness factor tuning test in Nd.
|
||||
Main smtnd : smtnd.c ;
|
||||
|
||||
# Smoothness factor tuning test in Nd.
|
||||
Main smtmpp : smtmpp.c ;
|
||||
|
||||
# Main rand_check : rand_check.c ;
|
||||
|
||||
# Main tt : tt.c ;
|
||||
|
||||
HDRS = ;
|
||||
LINKLIBS = ;
|
||||
|
||||
Main sm1 : sm1.c ;
|
||||
Main sm2 : sm2.c ;
|
||||
Main sm3 : sm3.c ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Test code
|
||||
if ( $(HOME) = "D:\\usr\\graeme" && $(PWD) = "/src/argyll/rspl" )
|
||||
|| ( $(HOME) = "/Users/graeme" && $(PWD) = "/Users/graeme/src/argyll/rspl" ) {
|
||||
# Main tt : tt.c : : ../xicc : : : ../plot/libvrml ../icc/libicc ;
|
||||
|
||||
Main lchw : lchw.c : : : ../h ../numlib ../icc ../plot : : ../plot/libplot ../icc/libicc ../numlib/libui ../numlib/libnum ;
|
||||
Main lchw_solve : lchw_solve.c : : : ../h ../numlib ../icc ../plot : : ../plot/libplot ../icc/libicc ../numlib/libui ../numlib/libnum ;
|
||||
Main lchw_deriv : lchw_deriv.c : : : ../h ../numlib ../icc ../plot : : ../plot/libplot ../icc/libicc ../numlib/libui ../numlib/libnum ;
|
||||
Main lchw_2deriv : lchw_2deriv.c : : : ../h ../numlib ../icc ../plot : : ../plot/libplot ../icc/libicc ../numlib/libui ../numlib/libnum ;
|
||||
Main crossv : crossv.c : : : ../h ../numlib ../plot : : ../plot/libplot ../numlib/libui ../numlib/libnum ;
|
||||
|
||||
}
|
||||
|
||||
if $(BUILD_JUNK) {
|
||||
|
||||
HDRS = ../h ../numlib ;
|
||||
LINKLIBS = ..//numlib/libnum ;
|
||||
|
||||
#Main temp : temp.c ;
|
||||
|
||||
MainsFromSources prime.c combo.c combo2.c combo3.c combo4.c combo5.c combo9.c ;
|
||||
|
||||
#Main cache : cache.c ;
|
||||
|
||||
# Nearest point test code
|
||||
Main nptest : nptest.c ;
|
||||
|
||||
# Nearest object test code
|
||||
Main notest : notest.c ;
|
||||
|
||||
#direct mlbs scattered interpolation test
|
||||
Main mlbs_test : mlbs_test.c ;
|
||||
}
|
||||
|
||||
662
Argyll_V3.5.0/rspl/License.txt
Executable file
662
Argyll_V3.5.0/rspl/License.txt
Executable file
@@ -0,0 +1,662 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
39
Argyll_V3.5.0/rspl/Readme.txt
Executable file
39
Argyll_V3.5.0/rspl/Readme.txt
Executable file
@@ -0,0 +1,39 @@
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
rspl now supports different resolution grids in each dimension.
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
This is the second generation Regular Spline library.
|
||||
|
||||
It contains scattered data point to regular grid interpolation,
|
||||
as well as spline smoothing, and the reverse interpolation
|
||||
code. This version is more modular, and uses better solution
|
||||
algorithms than the earlier REGSPL, and generally replaces it.
|
||||
|
||||
The reverse interpolation algorithms support features needed
|
||||
for devices like CMYK printers, such as total ink limiting,
|
||||
black locus selection, gamut boundary detection, vector
|
||||
and nearest gamut clipping.
|
||||
|
||||
It has been written with operation with 6 color printing
|
||||
devices in mind (ie. 3 extra degrees of freedom, and hence
|
||||
a 3 dimensional inking locus), although this usage is likely
|
||||
to be unwealdy.
|
||||
|
||||
|
||||
Misc test files:
|
||||
|
||||
c1.c Test 1D curves. First test is to check tracking at multiple resolutions
|
||||
c1df.c Test 1D curve with weak default function.
|
||||
c1i.c Test 1D curve with incremental points
|
||||
sm1.c Discover 1D smoothness factor vs resolution tracking factor
|
||||
sm2.c Discover 2D smoothness factor vs resolution tracking factor
|
||||
sm3.c Discover 3D smoothness factor vs resolution tracking factor
|
||||
t2d.c Test 2D fitting. Test againt two resolutions.
|
||||
t2ddf.c Test 2D fitting with weak default function.
|
||||
t3d.c Test 3D fitting. Test againt two resolutions.
|
||||
t3ddf.c Test 3D fitting with weak default function.
|
||||
tnd.c Simple test of 4D
|
||||
trnd.c Simple test of 4D reverse lookup.
|
||||
smtnd.c Sythetic function, nD multi-parameter fitting test function.
|
||||
smtmpp.c MPP function, nD multi-parameter fitting test function.
|
||||
|
||||
36
Argyll_V3.5.0/rspl/afiles
Executable file
36
Argyll_V3.5.0/rspl/afiles
Executable file
@@ -0,0 +1,36 @@
|
||||
Readme.txt
|
||||
License.txt
|
||||
afiles
|
||||
Jamfile
|
||||
rspl.h
|
||||
rspl_imp.h
|
||||
rspl.c
|
||||
rev.h
|
||||
rev.c
|
||||
scat.c
|
||||
scat2.c
|
||||
mlbs.c
|
||||
mlbs.h
|
||||
opt.c
|
||||
gam.h
|
||||
gam.c
|
||||
revbench.c
|
||||
c1.c
|
||||
cw1.c
|
||||
cw3.c
|
||||
c1df.c
|
||||
spline.c
|
||||
t2d.c
|
||||
t2ddf.c
|
||||
t3d.c
|
||||
t3ddf.c
|
||||
tnd.c
|
||||
trnd.c
|
||||
sm1.c
|
||||
sm2.c
|
||||
sm3.c
|
||||
stest.c
|
||||
smtnd.c
|
||||
smtmpp.c
|
||||
rspl1.h
|
||||
rspl1.c
|
||||
388
Argyll_V3.5.0/rspl/c1.c
Normal file
388
Argyll_V3.5.0/rspl/c1.c
Normal file
@@ -0,0 +1,388 @@
|
||||
|
||||
/************************************************/
|
||||
/* Investigate various curve approximations */
|
||||
/************************************************/
|
||||
|
||||
/* Discrete regularized spline versions */
|
||||
/* Standard test + Random testing */
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 4/10/95
|
||||
* Date: 5/4/96
|
||||
*
|
||||
* Copyright 1995, 1996 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#undef DIAG
|
||||
#undef DIAG2
|
||||
#undef GLOB_CHECK
|
||||
#define RES2 /* Do multiple test at various resolutions */
|
||||
#define AVGDEV 0.005 /* Average deviation of function data */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "copyright.h"
|
||||
#include "aconfig.h"
|
||||
#include "numlib.h"
|
||||
#include "rspl.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
void usage(void);
|
||||
|
||||
#define TRIALS 20 /* Number of random trials */
|
||||
#define SKIP 0 /* Number of random trials to skip */
|
||||
|
||||
#define MIN_PNTS 5
|
||||
#define MAX_PNTS 40
|
||||
|
||||
#define MIN_RES 20
|
||||
#define MAX_RES 2000
|
||||
|
||||
double xa[MAX_PNTS];
|
||||
double ya[MAX_PNTS];
|
||||
|
||||
#define XRES 100
|
||||
|
||||
#define PNTS1 10
|
||||
#define GRES1 400
|
||||
//#define GRES 800
|
||||
double t1xa[PNTS1] = { 0.2, 0.25, 0.30, 0.35, 0.40, 0.44, 0.48, 0.51, 0.64, 0.75 };
|
||||
double t1ya[PNTS1] = { 0.3, 0.35, 0.4, 0.41, 0.42, 0.46, 0.5, 0.575, 0.48, 0.75 };
|
||||
|
||||
#ifndef NEVER
|
||||
|
||||
// Reverse in x */
|
||||
#define PNTS2 10
|
||||
#define GRES2 400
|
||||
double t2xa[PNTS2] = { 0.25, 0.36, 0.49, 0.52, 0.56, 0.60, 0.65, 0.70, 0.75, 0.8 };
|
||||
double t2ya[PNTS2] = { 0.75, 0.48, 0.575, 0.5, 0.46, 0.42, 0.41, 0.4, 0.35, 0.3 };
|
||||
|
||||
#else
|
||||
|
||||
#define PNTS2 10
|
||||
#define GRES2 400
|
||||
// reverse in y
|
||||
double t2xa[PNTS2] = { 0.2, 0.25, 0.30, 0.35, 0.40, 0.44, 0.48, 0.51, 0.64, 0.75 };
|
||||
double t2ya[PNTS2] = { 0.7, 0.65, 0.6, 0.59, 0.58, 0.54, 0.5, 0.425, 0.52, 0.25 };
|
||||
|
||||
#endif /* NEVER */
|
||||
|
||||
//#define PNTS2 2
|
||||
//#define GRES2 5
|
||||
//double t2xa[PNTS2] = { 0.0, 1.0 };
|
||||
//double t2ya[PNTS2] = { 0.33, 0.66 };
|
||||
|
||||
co test_points[MAX_PNTS];
|
||||
|
||||
double lin(double x, double xa[], double ya[], int n);
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 1D rspl interpolation\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: c1 [options]\n");
|
||||
fprintf(stderr," -s smooth Use given smoothness (default 1.0)\n");
|
||||
fprintf(stderr," -x Use auto smoothing\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
int i,j, n;
|
||||
double x;
|
||||
double xx[XRES];
|
||||
double yy[6][XRES];
|
||||
rspl *rss; /* incremental solution version */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
double smooth = 1.0;
|
||||
int autosm = 0;
|
||||
double avgdev[MXDO];
|
||||
|
||||
low[0] = 0.0;
|
||||
high[0] = 1.0;
|
||||
avgdev[0] = AVGDEV;
|
||||
|
||||
error_program = "c1";
|
||||
check_if_not_interactive();
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* smoothness */
|
||||
else if (argv[fa][1] == 's') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
smooth = atof(na);
|
||||
}
|
||||
|
||||
else if (argv[fa][1] == 'x') {
|
||||
autosm = 1;
|
||||
}
|
||||
else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
for (n = 0; n < TRIALS; n++) {
|
||||
double lrand = 0.0; /* Amount of level randomness */
|
||||
int pnts;
|
||||
int fres;
|
||||
|
||||
if (n == 0) { /* Standard versions */
|
||||
#ifdef NEVER /* Doubled up points */
|
||||
pnts = 2 * PNTS;
|
||||
fres = GRES;
|
||||
for (i = 0; i < pnts; i++) {
|
||||
xa[i * 2 + 0] = t1xa[i] - 0.01;
|
||||
ya[i * 2 + 0] = t1ya[i];
|
||||
xa[i * 2 + 1] = t1xa[i] + 0.01;
|
||||
ya[i * 2 + 1] = t1ya[i];
|
||||
}
|
||||
#else
|
||||
pnts = PNTS1;
|
||||
fres = GRES1;
|
||||
for (i = 0; i < pnts; i++) {
|
||||
xa[i] = t1xa[i];
|
||||
ya[i] = t1ya[i];
|
||||
}
|
||||
#endif
|
||||
printf("Trial %d, points = %d, res = %d, level randomness = %f\n",n,pnts,fres,lrand);
|
||||
} else if (n == 1) { /* Second test versions */
|
||||
pnts = PNTS2;
|
||||
fres = GRES2;
|
||||
for (i = 0; i < pnts; i++) {
|
||||
xa[i] = t2xa[i];
|
||||
ya[i] = t2ya[i];
|
||||
}
|
||||
printf("Trial %d, points = %d, res = %d, level randomness = %f\n",n,pnts,fres,lrand);
|
||||
} else { /* Random versions */
|
||||
lrand = d_rand(0.0,0.1); /* Amount of level randomness */
|
||||
pnts = i_rand(MIN_PNTS,MAX_PNTS);
|
||||
fres = i_rand(MIN_RES,MAX_RES);
|
||||
|
||||
printf("Trial %d, points = %d, res = %d, level randomness = %f\n",n,pnts,fres,lrand);
|
||||
|
||||
/* Create X values */
|
||||
xa[0] = d_rand(0.5,1.0);
|
||||
for (i = 1; i < pnts; i++)
|
||||
xa[i] = xa[i-1] + d_rand(0.5,1.0);
|
||||
for (i = 0; i < pnts; i++) /* Divide out */
|
||||
xa[i] = (xa[i]/xa[pnts-1]);
|
||||
|
||||
/* Create y values */
|
||||
ya[0] = xa[0];
|
||||
for (i = 0; i < pnts; i++)
|
||||
ya[i] = ya[i-1] + d_rand(0.2,1.0) + d_rand(-0.2,0.3) + d_rand(-0.2,0.3);
|
||||
for (i = 0; i < pnts; i++) /* Divide out */
|
||||
ya[i] = (ya[i]/ya[pnts-1]);
|
||||
}
|
||||
|
||||
if (n < SKIP)
|
||||
continue;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS,
|
||||
1, /* di */
|
||||
1); /* fdi */
|
||||
|
||||
for (i = 0; i < pnts; i++) {
|
||||
test_points[i].p[0] = xa[i];
|
||||
test_points[i].v[0] = ya[i];
|
||||
}
|
||||
gres[0] = fres;
|
||||
|
||||
#ifdef RES2
|
||||
if (n != 0) {
|
||||
#endif
|
||||
/* Fit to scattered data */
|
||||
rss->fit_rspl(rss,
|
||||
0 | (autosm ? RSPL_AUTOSMOOTH : 0) ,
|
||||
test_points, /* Test points */
|
||||
pnts, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
smooth, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL); /* iwidth */
|
||||
|
||||
|
||||
/* Display the result */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
xx[i] = x;
|
||||
yy[0][i] = lin(x,xa,ya,pnts);
|
||||
tp.p[0] = x;
|
||||
rss->interp(rss, &tp);
|
||||
yy[1][i] = tp.v[0];
|
||||
if (yy[1][i] < -20.0)
|
||||
yy[1][i] = -20.0;
|
||||
else if (yy[1][i] > 120.0)
|
||||
yy[1][i] = 120.0;
|
||||
}
|
||||
|
||||
do_plot(xx,yy[0],yy[1],NULL,XRES);
|
||||
|
||||
#ifdef RES2
|
||||
} else { /* Multiple resolution version */
|
||||
int gresses[5];
|
||||
for (j = 0; j < 5; j++) {
|
||||
#ifndef NEVER
|
||||
if (j == 0)
|
||||
gres[0] = fres/8;
|
||||
else if (j == 1)
|
||||
gres[0] = fres/4;
|
||||
else if (j == 2)
|
||||
gres[0] = fres/2;
|
||||
else if (j == 3)
|
||||
gres[0] = fres;
|
||||
else
|
||||
gres[0] = fres * 2;
|
||||
#else /* Check sensitivity to griding of data points */
|
||||
if (j == 0)
|
||||
gres[0] = 192;
|
||||
else if (j == 1)
|
||||
gres[0] = 193;
|
||||
else if (j == 2)
|
||||
gres[0] = 194;
|
||||
else if (j == 3)
|
||||
gres[0] = 195;
|
||||
else
|
||||
gres[0] = 196;
|
||||
#endif
|
||||
gresses[j] = gres[0];
|
||||
|
||||
rss->fit_rspl(rss,
|
||||
0 | (autosm ? RSPL_AUTOSMOOTH : 0) ,
|
||||
test_points, /* Test points */
|
||||
pnts, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
smooth, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL); /* iwidth */
|
||||
|
||||
/* Get the result */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
xx[i] = x;
|
||||
yy[0][i] = lin(x,xa,ya,pnts);
|
||||
tp.p[0] = x;
|
||||
rss->interp(rss, &tp);
|
||||
yy[1+j][i] = tp.v[0];
|
||||
if (yy[1+j][i] < -20.0)
|
||||
yy[1+j][i] = -20.0;
|
||||
else if (yy[1+j][i] > 120.0)
|
||||
yy[1+j][i] = 120.0;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Black = lin, Red = %d, Green = %d, Blue = %d, Yellow = %d, Purple = %d\n",
|
||||
gresses[0], gresses[1], gresses[2], gresses[3], gresses[4]);
|
||||
do_plot6(xx,yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],XRES);
|
||||
}
|
||||
#endif /* RES2 */
|
||||
} /* next trial */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Simple linear interpolation */
|
||||
double
|
||||
lin(
|
||||
double x,
|
||||
double xa[],
|
||||
double ya[],
|
||||
int n) {
|
||||
int i;
|
||||
double y;
|
||||
|
||||
if (x < xa[0])
|
||||
return ya[0];
|
||||
else if (x > xa[n-1])
|
||||
return ya[n-1];
|
||||
|
||||
for (i = 0; i < (n-1); i++)
|
||||
if (x >=xa[i] && x <= xa[i+1])
|
||||
break;
|
||||
|
||||
x = (x - xa[i])/(xa[i+1] - xa[i]);
|
||||
|
||||
y = ya[i] + (ya[i+1] - ya[i]) * x;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Next u function done with optimization */
|
||||
|
||||
/* Structure to hold data for optimization function */
|
||||
struct _edatas {
|
||||
rspl *rss;
|
||||
int j;
|
||||
}; typedef struct _edatas edatas;
|
||||
|
||||
#ifdef GLOB_CHECK
|
||||
/* Overall Global optimization method */
|
||||
/* Definition of the optimization function handed to powell() */
|
||||
double efunc2(void *edata, double p[])
|
||||
{
|
||||
int j;
|
||||
double rv;
|
||||
rspl *rss = (rspl *)edata;
|
||||
for (j = 0; j < rss->nig; j++) /* Ugg */
|
||||
rss->u[j].v = p[j];
|
||||
rv = rss->efactor(rss);
|
||||
#ifdef DIAG2
|
||||
/* printf("%c%e",cr_char,rv); */
|
||||
printf("%e\n",rv);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
solveu(rss)
|
||||
rspl *rss;
|
||||
{
|
||||
int j;
|
||||
double *cp;
|
||||
double *s;
|
||||
|
||||
cp = dvector(0,rss->nig);
|
||||
s = dvector(0,rss->nig);
|
||||
for (j = 0; j < rss->nig; j++) /* Ugg */
|
||||
{
|
||||
cp[j] = rss->u[j].v;
|
||||
s[j] = 0.1;
|
||||
}
|
||||
powell(rss->nig,cp,s,1e-7,1000,efunc2,(void *)rss);
|
||||
}
|
||||
#endif /* GLOB_CHECK */
|
||||
313
Argyll_V3.5.0/rspl/c1df.c
Normal file
313
Argyll_V3.5.0/rspl/c1df.c
Normal file
@@ -0,0 +1,313 @@
|
||||
|
||||
/************************************************/
|
||||
/* Investigate various curve approximations */
|
||||
/************************************************/
|
||||
|
||||
/* Discrete regularized spline versions */
|
||||
/* Standard test with weak default function */
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 20/11/2005
|
||||
*
|
||||
* Copyright 1995, 1996, 2005 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#undef DIAG
|
||||
#undef DIAG2
|
||||
#undef GLOB_CHECK
|
||||
#define RES2 /* Do multiple test at various resolutions */
|
||||
#undef EXTRAFIT /* Test extra fitting effort */
|
||||
#define SMOOTH 1.0
|
||||
#define AVGDEV 0.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "copyright.h"
|
||||
#include "aconfig.h"
|
||||
#include "numlib.h"
|
||||
#include "rspl.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
void usage(void);
|
||||
|
||||
#define TRIALS 15 /* Number of random trials */
|
||||
#define SKIP 0 /* Number of random trials to skip */
|
||||
|
||||
#define MIN_PNTS 1
|
||||
#define MAX_PNTS 7
|
||||
|
||||
#define MIN_RES 20
|
||||
#define MAX_RES 300
|
||||
|
||||
double xa[MAX_PNTS];
|
||||
double ya[MAX_PNTS];
|
||||
double wa[MAX_PNTS];
|
||||
|
||||
#define XRES 100
|
||||
|
||||
#define PNTS 2
|
||||
#define GRES 200
|
||||
//double t1xa[PNTS] = { 0.325, 0.625 };
|
||||
//double t1ya[PNTS] = { 0.4, 0.70 };
|
||||
double t1xa[PNTS] = { 0.325, 0.625 };
|
||||
double t1ya[PNTS] = { 0.5, 0.8 };
|
||||
double t1wa[PNTS] = { 1.0, 1.0 };
|
||||
cow test_points[MAX_PNTS];
|
||||
|
||||
double lin(double x, double xa[], double ya[], int n);
|
||||
|
||||
/* Weak default function */
|
||||
static void wfunc(void *cbntx, double *out, double *in) {
|
||||
out[0] = in[0];
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 1D rspl interpolation with weak default function\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: c1df [options]\n");
|
||||
fprintf(stderr," -w wweight Set weak default function weight (default 1.0)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
int i,j, n;
|
||||
double x;
|
||||
double xx[XRES];
|
||||
double yy[6][XRES];
|
||||
rspl *rss; /* incremental solution version */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
double avgdev[MXDO];
|
||||
double wweight = 1.0;
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?') {
|
||||
usage();
|
||||
|
||||
} else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
wweight = atof(na);
|
||||
} else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
low[0] = 0.0;
|
||||
high[0] = 1.0;
|
||||
avgdev[0] = AVGDEV;
|
||||
|
||||
error_program = "Curve1";
|
||||
|
||||
for (n = 0; n < TRIALS; n++) {
|
||||
double lrand = 0.0; /* Amount of level randomness */
|
||||
int pnts;
|
||||
int fres;
|
||||
|
||||
if (n == 0) { /* Standard versions */
|
||||
pnts = PNTS;
|
||||
fres = GRES;
|
||||
for (i = 0; i < pnts; i++) {
|
||||
xa[i] = t1xa[i];
|
||||
ya[i] = t1ya[i];
|
||||
wa[i] = t1wa[i];
|
||||
}
|
||||
printf("Trial %d, points = %d, res = %d, level randomness = %f\n",n,pnts,fres,lrand);
|
||||
} else { /* Random versions */
|
||||
double xmx;
|
||||
lrand = d_rand(0.0,0.1); /* Amount of level randomness */
|
||||
pnts = i_rand(MIN_PNTS,MAX_PNTS);
|
||||
fres = i_rand(MIN_RES,MAX_RES);
|
||||
|
||||
printf("Trial %d, points = %d, res = %d, level randomness = %f\n",n,pnts,fres,lrand);
|
||||
|
||||
/* Create X values */
|
||||
xa[0] = d_rand(0.3, 0.5);
|
||||
for (i = 1; i < pnts; i++)
|
||||
xa[i] = xa[i-1] + d_rand(0.2,0.7);
|
||||
xmx = d_rand(0.6, 0.9);
|
||||
for (i = 0; i < pnts; i++) /* Divide out */
|
||||
xa[i] *= (xmx/xa[pnts-1]);
|
||||
|
||||
/* Create y values */
|
||||
for (i = 0; i < pnts; i++) {
|
||||
ya[i] = xa[i] + d_rand(-lrand,lrand);
|
||||
wa[i] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (n < SKIP)
|
||||
continue;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, 1, /* di */
|
||||
1); /* fdi */
|
||||
|
||||
for (i = 0; i < pnts; i++) {
|
||||
test_points[i].p[0] = xa[i];
|
||||
test_points[i].v[0] = ya[i];
|
||||
test_points[i].w = wa[i];
|
||||
}
|
||||
gres[0] = fres;
|
||||
|
||||
#ifdef RES2
|
||||
if (n != 0) {
|
||||
#endif
|
||||
/* Fit to scattered data */
|
||||
rss->fit_rspl_w_df(rss,
|
||||
#ifdef EXTRAFIT
|
||||
RSPL_EXTRAFIT | /* Extra fit flag */
|
||||
#endif
|
||||
0,
|
||||
test_points, /* Test points */
|
||||
pnts, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
low, high, /* Data scale */
|
||||
SMOOTH, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL, /* iwidth */
|
||||
wweight, /* weak function weight */
|
||||
NULL, /* No context */
|
||||
wfunc /* Weak function */
|
||||
);
|
||||
|
||||
/* Display the result */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
xx[i] = x;
|
||||
yy[0][i] = lin(x,xa,ya,pnts);
|
||||
tp.p[0] = x;
|
||||
rss->interp(rss, &tp);
|
||||
yy[1][i] = tp.v[0];
|
||||
if (yy[1][i] < -0.2)
|
||||
yy[1][i] = -0.2;
|
||||
else if (yy[1][i] > 1.2)
|
||||
yy[1][i] = 1.2;
|
||||
}
|
||||
|
||||
do_plot(xx,yy[0],yy[1],NULL,XRES);
|
||||
|
||||
#ifdef RES2
|
||||
} else { /* Multiple resolution version */
|
||||
int gresses[5];
|
||||
for (j = 0; j < 5; j++) {
|
||||
#ifndef NEVER
|
||||
if (j == 0)
|
||||
gres[0] = fres/8;
|
||||
else if (j == 1)
|
||||
gres[0] = fres/4;
|
||||
else if (j == 2)
|
||||
gres[0] = fres/2;
|
||||
else if (j == 3)
|
||||
gres[0] = fres;
|
||||
else
|
||||
gres[0] = fres * 2;
|
||||
#else /* Check sensitivity to griding of data points */
|
||||
if (j == 0)
|
||||
gres[0] = 192;
|
||||
else if (j == 1)
|
||||
gres[0] = 193;
|
||||
else if (j == 2)
|
||||
gres[0] = 194;
|
||||
else if (j == 3)
|
||||
gres[0] = 195;
|
||||
else
|
||||
gres[0] = 196;
|
||||
#endif
|
||||
gresses[j] = gres[0];
|
||||
|
||||
rss->fit_rspl_w_df(rss,
|
||||
#ifdef EXTRAFIT
|
||||
RSPL_EXTRAFIT | /* Extra fit flag */
|
||||
#endif
|
||||
0,
|
||||
test_points, /* Test points */
|
||||
pnts, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
low, high, /* Data scale */
|
||||
SMOOTH, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL, /* iwidth */
|
||||
wweight, /* weak function weight */
|
||||
NULL, /* No context */
|
||||
wfunc /* Weak function */
|
||||
);
|
||||
|
||||
/* Get the result */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
xx[i] = x;
|
||||
yy[0][i] = lin(x,xa,ya,pnts);
|
||||
tp.p[0] = x;
|
||||
rss->interp(rss, &tp);
|
||||
yy[1+j][i] = tp.v[0];
|
||||
if (yy[1+j][i] < -0.2)
|
||||
yy[1+j][i] = -0.2;
|
||||
else if (yy[1+j][i] > 1.2)
|
||||
yy[1+j][i] = 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Black = lin, Red = %d, Green = %d, Blue = %d, Yellow = %d, Purple = %d\n",
|
||||
gresses[0], gresses[1], gresses[2], gresses[3], gresses[4]);
|
||||
do_plot6(xx,yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],XRES);
|
||||
}
|
||||
#endif /* RES2 */
|
||||
} /* next trial */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
lin(
|
||||
double x,
|
||||
double xa[],
|
||||
double ya[],
|
||||
int n)
|
||||
{
|
||||
int i;
|
||||
double y;
|
||||
|
||||
if (x < xa[0])
|
||||
return ya[0];
|
||||
else if (x > xa[n-1])
|
||||
return ya[n-1];
|
||||
|
||||
for (i = 0; i < (n-1); i++)
|
||||
if (x >=xa[i] && x <= xa[i+1])
|
||||
break;
|
||||
|
||||
x = (x - xa[i])/(xa[i+1] - xa[i]);
|
||||
|
||||
y = ya[i] + (ya[i+1] - ya[i]) * x;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
309
Argyll_V3.5.0/rspl/cw1.c
Normal file
309
Argyll_V3.5.0/rspl/cw1.c
Normal file
@@ -0,0 +1,309 @@
|
||||
|
||||
/************************************************/
|
||||
/* Investigate various curve approximations */
|
||||
/************************************************/
|
||||
|
||||
/* Discrete regularized spline versions */
|
||||
/* Test variable grid spacing in 1D */
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 4/10/95
|
||||
* Date: 5/4/96
|
||||
*
|
||||
* Copyright 1995, 2013 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#undef DIAG
|
||||
#undef DIAG2
|
||||
#undef GLOB_CHECK
|
||||
#define AVGDEV 0.0 /* Average deviation of function data */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "copyright.h"
|
||||
#include "aconfig.h"
|
||||
#include "numlib.h"
|
||||
#include "rspl.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
double lin();
|
||||
void usage(void);
|
||||
|
||||
#define TRIALS 1 /* Number of random trials */
|
||||
#define XRES 100 /* Plotting res */
|
||||
|
||||
|
||||
#define PNTS1 10
|
||||
#define GRES1 100
|
||||
|
||||
/* Function that we're approximating */
|
||||
static double func(double val) {
|
||||
double out;
|
||||
int sgn = 0;
|
||||
|
||||
if (val < 0.0) {
|
||||
sgn = 1;
|
||||
val = -val;
|
||||
}
|
||||
|
||||
out = pow(val, 2.5);
|
||||
|
||||
if (sgn)
|
||||
out = -out;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Grid spacing power */
|
||||
#define GRIDPOW 1.5
|
||||
|
||||
/* Scattered data sample spacing power */
|
||||
#define SAMPPOW 1.3
|
||||
|
||||
|
||||
co test_points[PNTS1];
|
||||
|
||||
double ipos[GRES1];
|
||||
double *iposes[1] = { ipos };
|
||||
|
||||
double powlike(double vv, double pp);
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 1D rspl interpolation variable grid spacing\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: c1 [options]\n");
|
||||
fprintf(stderr," -s smooth Use given smoothness (default 1.0)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
int i,j, n;
|
||||
double x;
|
||||
double xx1[XRES];
|
||||
double yy1[6][XRES];
|
||||
double xx2[XRES];
|
||||
double yy2[6][XRES];
|
||||
rspl *rss; /* incremental solution version */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
double smooth = 1.0;
|
||||
double avgdev[MXDO];
|
||||
|
||||
low[0] = 0.0;
|
||||
high[0] = 1.0;
|
||||
avgdev[0] = AVGDEV;
|
||||
|
||||
error_program = "c1";
|
||||
check_if_not_interactive();
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* smoothness */
|
||||
else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
smooth = atof(na);
|
||||
}
|
||||
else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
/* Only one trial */
|
||||
for (n = 0; n < TRIALS; n++) {
|
||||
double lrand = 0.0; /* Amount of level randomness */
|
||||
int pnts;
|
||||
int fres;
|
||||
|
||||
pnts = PNTS1;
|
||||
fres = GRES1;
|
||||
gres[0] = fres;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS,
|
||||
1, /* di */
|
||||
1); /* fdi */
|
||||
|
||||
/* For each grid spacing test */
|
||||
for (j = 0; j < 2; j++) {
|
||||
|
||||
for (i = 0; i < pnts; i++) {
|
||||
double val, out;
|
||||
|
||||
val = i/(pnts - 1.0);
|
||||
|
||||
if (j == 0) { /* Linear */
|
||||
// out = func(val + d_rand(-0.001, 0.001));
|
||||
out = func(val);
|
||||
test_points[i].p[0] = val;
|
||||
test_points[i].v[0] = out;
|
||||
|
||||
} else { /* power 2.0 grid spacing */
|
||||
val = pow(val, SAMPPOW); /* sample point spacing */
|
||||
|
||||
// out = func(val + d_rand(-0.001, 0.001));
|
||||
out = func(val);
|
||||
val = powlike(val, 1.0/GRIDPOW); /* To grid spacing */
|
||||
test_points[i].p[0] = val;
|
||||
test_points[i].v[0] = out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set grid position info */
|
||||
for (i = 0; i < gres[0]; i++) {
|
||||
double val, out;
|
||||
|
||||
val = i/(gres[0] - 1.0);
|
||||
if (j == 1)
|
||||
val = powlike(val, 1.0/GRIDPOW); /* To grid spacing */
|
||||
ipos[i] = val;
|
||||
}
|
||||
|
||||
rss->fit_rspl(rss,
|
||||
0,
|
||||
test_points, /* Test points */
|
||||
pnts, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
smooth, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
j == 0 ? NULL : iposes); /* iwidth */
|
||||
|
||||
/* Show the result full scale */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
xx1[i] = x;
|
||||
yy1[0][i] = func(x);
|
||||
tp.p[0] = x;
|
||||
if (j == 1)
|
||||
tp.p[0] = powlike(tp.p[0], 1.0/GRIDPOW); /* Grid spacing input */
|
||||
rss->interp(rss, &tp);
|
||||
yy1[1+j][i] = tp.v[0];
|
||||
if (yy1[1+j][i] < -0.2)
|
||||
yy1[1+j][i] = -0.2;
|
||||
else if (yy1[1+j][i] > 1.2)
|
||||
yy1[1+j][i] = 1.2;
|
||||
}
|
||||
|
||||
/* Show the result magnified */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
x *= 0.1;
|
||||
xx2[i] = x;
|
||||
yy2[0][i] = func(x);
|
||||
tp.p[0] = x;
|
||||
if (j == 1)
|
||||
tp.p[0] = powlike(tp.p[0], 1.0/GRIDPOW); /* Grid spacing input */
|
||||
rss->interp(rss, &tp);
|
||||
yy2[1+j][i] = tp.v[0];
|
||||
if (yy2[1+j][i] < -0.2)
|
||||
yy2[1+j][i] = -0.2;
|
||||
else if (yy2[1+j][i] > 1.2)
|
||||
yy2[1+j][i] = 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Full scale: Black = ref, Red = even, Green = pow2\n");
|
||||
do_plot6(xx1,yy1[0],yy1[1],yy1[2],NULL,NULL,NULL,XRES);
|
||||
|
||||
printf("Magnified: Black = ref, Red = even, Green = pow2\n");
|
||||
do_plot6(xx2,yy2[0],yy2[1],yy2[2],NULL,NULL,NULL,XRES);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* A power-like function, based on Graphics Gems adjustment curve. */
|
||||
/* Avoids "toe" problem of pure power. */
|
||||
/* Adjusted so that "power" 2 and 0.5 agree with real power at 0.5 */
|
||||
|
||||
double powlike(double vv, double pp) {
|
||||
double tt, g;
|
||||
|
||||
if (pp >= 1.0) {
|
||||
g = 2.0 * (pp - 1.0);
|
||||
vv = vv/(g - g * vv + 1.0);
|
||||
} else {
|
||||
g = 2.0 - 2.0/pp;
|
||||
vv = (vv - g * vv)/(1.0 - g * vv);
|
||||
}
|
||||
|
||||
return vv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Next u function done with optimization */
|
||||
|
||||
/* Structure to hold data for optimization function */
|
||||
struct _edatas {
|
||||
rspl *rss;
|
||||
int j;
|
||||
}; typedef struct _edatas edatas;
|
||||
|
||||
#ifdef GLOB_CHECK
|
||||
/* Overall Global optimization method */
|
||||
/* Definition of the optimization function handed to powell() */
|
||||
double efunc2(void *edata, double p[])
|
||||
{
|
||||
int j;
|
||||
double rv;
|
||||
rspl *rss = (rspl *)edata;
|
||||
for (j = 0; j < rss->nig; j++) /* Ugg */
|
||||
rss->u[j].v = p[j];
|
||||
rv = rss->efactor(rss);
|
||||
#ifdef DIAG2
|
||||
/* printf("%c%e",cr_char,rv); */
|
||||
printf("%e\n",rv);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
solveu(rss)
|
||||
rspl *rss;
|
||||
{
|
||||
int j;
|
||||
double *cp;
|
||||
double *s;
|
||||
|
||||
cp = dvector(0,rss->nig);
|
||||
s = dvector(0,rss->nig);
|
||||
for (j = 0; j < rss->nig; j++) /* Ugg */
|
||||
{
|
||||
cp[j] = rss->u[j].v;
|
||||
s[j] = 0.1;
|
||||
}
|
||||
powell(rss->nig,cp,s,1e-7,1000,efunc2,(void *)rss);
|
||||
}
|
||||
#endif /* GLOB_CHECK */
|
||||
326
Argyll_V3.5.0/rspl/cw3.c
Normal file
326
Argyll_V3.5.0/rspl/cw3.c
Normal file
@@ -0,0 +1,326 @@
|
||||
|
||||
/************************************************/
|
||||
/* Investigate various curve approximations */
|
||||
/************************************************/
|
||||
|
||||
/* Discrete regularized spline versions */
|
||||
/* Test variable grid spacing in 3D */
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 28/11/2013
|
||||
*
|
||||
* Copyright 1995, 2013 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#undef DIAG
|
||||
#undef DIAG2
|
||||
#undef GLOB_CHECK
|
||||
#define AVGDEV 0.0 /* Average deviation of function data */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "copyright.h"
|
||||
#include "aconfig.h"
|
||||
#include "counters.h"
|
||||
#include "numlib.h"
|
||||
#include "rspl.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
double lin();
|
||||
void usage(void);
|
||||
|
||||
#define TRIALS 1 /* Number of random trials */
|
||||
#define XRES 100 /* Plotting res */
|
||||
|
||||
|
||||
#define PNTS1 20
|
||||
#define GRES1 33
|
||||
|
||||
/* Function that we're approximating */
|
||||
static double func(double val) {
|
||||
double out;
|
||||
int sgn = 0;
|
||||
|
||||
if (val < 0.0) {
|
||||
sgn = 1;
|
||||
val = -val;
|
||||
}
|
||||
|
||||
out = pow(val, 2.4);
|
||||
|
||||
if (sgn)
|
||||
out = -out;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Grid spacing power */
|
||||
#define GRIDPOW 1.8
|
||||
|
||||
/* Scattered data sample spacing power */
|
||||
#define SAMPPOW 1.3
|
||||
|
||||
|
||||
co test_points[PNTS1 * PNTS1 * PNTS1];
|
||||
|
||||
double ipos[GRES1];
|
||||
double *iposes[3] = { ipos, ipos, ipos };
|
||||
|
||||
double powlike(double vv, double pp);
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 3D rspl interpolation variable grid spacing\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: c1 [options]\n");
|
||||
fprintf(stderr," -s smooth Use given smoothness (default 1.0)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
int i, j, e, f, n;
|
||||
double x;
|
||||
double xx1[XRES];
|
||||
double yy1[6][XRES];
|
||||
double xx2[XRES];
|
||||
double yy2[6][XRES];
|
||||
rspl *rss; /* incremental solution version */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
double smooth = 1.0;
|
||||
double avgdev[MXDO];
|
||||
|
||||
low[0] = 0.0;
|
||||
low[1] = 0.0;
|
||||
low[2] = 0.0;
|
||||
high[0] = 1.0;
|
||||
high[1] = 1.0;
|
||||
high[2] = 1.0;
|
||||
avgdev[0] = AVGDEV;
|
||||
avgdev[1] = AVGDEV;
|
||||
avgdev[2] = AVGDEV;
|
||||
|
||||
error_program = "c1";
|
||||
check_if_not_interactive();
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* smoothness */
|
||||
else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
smooth = atof(na);
|
||||
}
|
||||
else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
for (n = 0; n < TRIALS; n++) {
|
||||
double lrand = 0.0; /* Amount of level randomness */
|
||||
int di = 3;
|
||||
int pnts = PNTS1;
|
||||
int tpnts = PNTS1 * PNTS1 * PNTS1;
|
||||
int fres;
|
||||
|
||||
fres = GRES1;
|
||||
gres[0] = fres;
|
||||
gres[1] = fres;
|
||||
gres[2] = fres;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS,
|
||||
3, /* di */
|
||||
3); /* fdi */
|
||||
|
||||
/* For each grid spacing test */
|
||||
for (j = 0; j < 2; j++) {
|
||||
DCOUNT(gc, MXDIDO, di, 0, 0, pnts);
|
||||
|
||||
/* Set the scattered data points (actually grid) */
|
||||
DC_INIT(gc);
|
||||
for (i = 0; !DC_DONE(gc); i++) {
|
||||
|
||||
for (f = 0; f < 3; f++) {
|
||||
double val, out;
|
||||
|
||||
val = gc[f]/(pnts - 1.0);
|
||||
|
||||
if (j == 0) { /* Linear */
|
||||
// out = func(val + d_rand(-0.001, 0.001));
|
||||
out = func(val);
|
||||
test_points[i].p[f] = val;
|
||||
test_points[i].v[f] = out;
|
||||
|
||||
} else { /* power 2.0 grid spacing */
|
||||
val = pow(val, SAMPPOW); /* sample point spacing */
|
||||
|
||||
// out = func(val + d_rand(-0.001, 0.001));
|
||||
out = func(val);
|
||||
val = powlike(val, 1.0/GRIDPOW); /* To grid spacing */
|
||||
test_points[i].p[f] = val;
|
||||
test_points[i].v[f] = out;
|
||||
}
|
||||
}
|
||||
DC_INC(gc);
|
||||
}
|
||||
|
||||
/* Set grid position info. This is the same for each input axis */
|
||||
for (i = 0; i < gres[0]; i++) {
|
||||
double val, out;
|
||||
|
||||
val = i/(gres[0] - 1.0);
|
||||
if (j == 1)
|
||||
val = powlike(val, 1.0/GRIDPOW); /* To grid spacing */
|
||||
ipos[i] = val;
|
||||
}
|
||||
|
||||
printf("Fitting rspl....\n");
|
||||
rss->fit_rspl(rss,
|
||||
0,
|
||||
test_points, /* Test points */
|
||||
tpnts, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
smooth, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
j == 0 ? NULL : iposes); /* iwidth */
|
||||
|
||||
/* Show the result full scale of one axis and corresponding output */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
xx1[i] = x;
|
||||
yy1[0][i] = func(x);
|
||||
tp.p[0] = x;
|
||||
tp.p[1] = tp.p[2] = 0.0;
|
||||
if (j == 1)
|
||||
tp.p[0] = powlike(tp.p[0], 1.0/GRIDPOW); /* Grid spacing input */
|
||||
rss->interp(rss, &tp);
|
||||
yy1[1+j][i] = tp.v[0];
|
||||
if (yy1[1+j][i] < -0.2)
|
||||
yy1[1+j][i] = -0.2;
|
||||
else if (yy1[1+j][i] > 1.2)
|
||||
yy1[1+j][i] = 1.2;
|
||||
}
|
||||
|
||||
/* Show the result magnified */
|
||||
for (i = 0; i < XRES; i++) {
|
||||
co tp; /* Test point */
|
||||
x = i/(double)(XRES-1);
|
||||
x *= 0.1;
|
||||
xx2[i] = x;
|
||||
yy2[0][i] = func(x);
|
||||
tp.p[0] = x;
|
||||
tp.p[1] = tp.p[2] = 0.0;
|
||||
if (j == 1)
|
||||
tp.p[0] = powlike(tp.p[0], 1.0/GRIDPOW); /* Grid spacing input */
|
||||
rss->interp(rss, &tp);
|
||||
yy2[1+j][i] = tp.v[0];
|
||||
if (yy2[1+j][i] < -0.2)
|
||||
yy2[1+j][i] = -0.2;
|
||||
else if (yy2[1+j][i] > 1.2)
|
||||
yy2[1+j][i] = 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Full scale: Black = lin, Red = even, Green = pow2\n");
|
||||
do_plot6(xx1,yy1[0],yy1[1],yy1[2],NULL,NULL,NULL,XRES);
|
||||
|
||||
printf("Magnified: Black = lin, Red = even, Green = pow2\n");
|
||||
do_plot6(xx2,yy2[0],yy2[1],yy2[2],NULL,NULL,NULL,XRES);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A power-like function, based on Graphics Gems adjustment curve. */
|
||||
/* Avoids "toe" problem of pure power. */
|
||||
/* Adjusted so that "power" 2 and 0.5 agree with real power at 0.5 */
|
||||
|
||||
double powlike(double vv, double pp) {
|
||||
double tt, g;
|
||||
|
||||
if (pp >= 1.0) {
|
||||
g = 2.0 * (pp - 1.0);
|
||||
vv = vv/(g - g * vv + 1.0);
|
||||
} else {
|
||||
g = 2.0 - 2.0/pp;
|
||||
vv = (vv - g * vv)/(1.0 - g * vv);
|
||||
}
|
||||
|
||||
return vv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Next u function done with optimization */
|
||||
|
||||
/* Structure to hold data for optimization function */
|
||||
struct _edatas {
|
||||
rspl *rss;
|
||||
int j;
|
||||
}; typedef struct _edatas edatas;
|
||||
|
||||
#ifdef GLOB_CHECK
|
||||
/* Overall Global optimization method */
|
||||
/* Definition of the optimization function handed to powell() */
|
||||
double efunc2(void *edata, double p[])
|
||||
{
|
||||
int j;
|
||||
double rv;
|
||||
rspl *rss = (rspl *)edata;
|
||||
for (j = 0; j < rss->nig; j++) /* Ugg */
|
||||
rss->u[j].v = p[j];
|
||||
rv = rss->efactor(rss);
|
||||
#ifdef DIAG2
|
||||
/* printf("%c%e",cr_char,rv); */
|
||||
printf("%e\n",rv);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
solveu(rss)
|
||||
rspl *rss;
|
||||
{
|
||||
int j;
|
||||
double *cp;
|
||||
double *s;
|
||||
|
||||
cp = dvector(0,rss->nig);
|
||||
s = dvector(0,rss->nig);
|
||||
for (j = 0; j < rss->nig; j++) /* Ugg */
|
||||
{
|
||||
cp[j] = rss->u[j].v;
|
||||
s[j] = 0.1;
|
||||
}
|
||||
powell(rss->nig,cp,s,1e-7,1000,efunc2,(void *)rss);
|
||||
}
|
||||
#endif /* GLOB_CHECK */
|
||||
1278
Argyll_V3.5.0/rspl/gam.c
Normal file
1278
Argyll_V3.5.0/rspl/gam.c
Normal file
File diff suppressed because it is too large
Load Diff
131
Argyll_V3.5.0/rspl/gam.h
Normal file
131
Argyll_V3.5.0/rspl/gam.h
Normal file
@@ -0,0 +1,131 @@
|
||||
#ifndef RSPL_GAM_H
|
||||
#define RSPL_GAM_H
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional regularized spline data structure
|
||||
*
|
||||
* Precise gamut surface, gamut pruning, ink limiting and K min/max
|
||||
* support routine.s
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2008/11/21
|
||||
*
|
||||
* Copyright 1999 - 2008 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*
|
||||
* Latest simplex/linear equation version.
|
||||
*/
|
||||
|
||||
/* In practice the gamut is only ever computed for 2D or 3D output */
|
||||
/* dimensions. The gamut surface is composed of simplexes ("triangles") */
|
||||
/* of dimensions fdi-1, with fdi vertices */
|
||||
|
||||
#include "llist.h"
|
||||
|
||||
#define MXNE 16 /* Maximum number of edges per triangle allowed */
|
||||
|
||||
#define VHASHSIZE 6863 /* Vertex hash index size */
|
||||
#define EHASHSIZE 2659 /* Edge hash index size */
|
||||
#define THASHSIZE 2659 /* Triangle hash index size */
|
||||
|
||||
/* ----------------------------------------- */
|
||||
|
||||
/* Vertex node - all vertex nodes are part of the grid */
|
||||
struct _rvert {
|
||||
struct _rvert *next; /* Hash linked list */
|
||||
int n; /* Index number of vertex */
|
||||
int gix; /* Grid index - used to identify and order nodes */
|
||||
float *fg; /* Pointer to grid data */
|
||||
|
||||
// double p[MXDO]; /* Poistion of node */
|
||||
double v[MXDO]; /* Output value of node */
|
||||
double r[MXDO]; /* Radial coordinates */
|
||||
struct _rvert *list; /* Next in linked list */
|
||||
}; typedef struct _rvert rvert;
|
||||
|
||||
/* ------------------------------------ */
|
||||
|
||||
/* An edge shared by one or more triangle in the mesh */
|
||||
struct _redge {
|
||||
struct _redge *next; /* Hash linked list */
|
||||
int n; /* Serial number */
|
||||
// float *f[MXDO-1]; /* fdi-1 grid vertices of edge in base simplex order. */
|
||||
struct _rvert *v[MXDO-1]; /* fdi-1 Vertices of edge in base simplex order. */
|
||||
double pe[MXDO+1]; /* Plane equation for edge for side of edge testing. */
|
||||
/* fdi for normal + constant */
|
||||
int nt; /* Total number of triangles that share this edge */
|
||||
int npt; /* Positive side triangles that share this edge */
|
||||
int nnt; /* Negative side triangles that share this edge */
|
||||
struct _rtri *t[MXNE]; /* nt triangles edge is part of */
|
||||
|
||||
struct _redge *list; /* Next in linked list */
|
||||
}; typedef struct _redge redge;
|
||||
|
||||
/* ------------------------------------ */
|
||||
|
||||
/* A "triangle" (simplex dimension fdi-1) in the surface mesh */
|
||||
struct _rtri {
|
||||
struct _rtri *next; /* Hash linked list */
|
||||
int n; /* Serial number */
|
||||
// float *f[MXDO]; /* fdi grid vertices in gix order */
|
||||
struct _rvert *v[MXDO]; /* fdi vertices in gix order */
|
||||
|
||||
// struct _redge *e[((MXDO+1) * MXDO)/2]; /* Edges in vertex sorted order */
|
||||
// double mix[2][MXDO]; /* nn: Bounding box min and max */
|
||||
|
||||
struct _rtri *list; /* Next in linked list */
|
||||
}; typedef struct _rtri rtri;
|
||||
|
||||
/* ----------------------------------------- */
|
||||
/* Gamut info stored in main rspl function */
|
||||
struct _gam_struct {
|
||||
int inited;
|
||||
|
||||
double cent[MXDO]; /* Center of radial distance calculation */
|
||||
double scale[MXDO]; /* Scale of radial distance calculation */
|
||||
|
||||
void (*outf)(void *cntxf, double *out, double *in); /* Optional rspl val -> output value */
|
||||
void *cntxf; /* Context for function */
|
||||
void (*outb)(void *cntxb, double *out, double *in); /* Optional output value -> rspl val */
|
||||
void *cntxb; /* Context for function */
|
||||
|
||||
ssxinfo ssi[MXDO-1]; /* Sub-simplex information for sdi from 0..fdi-1 */
|
||||
|
||||
int rvert_no; /* Number of rverts allocated */
|
||||
int vhsize; /* Vertex hash list size */
|
||||
rvert **verts; /* Hash list, NULL if not allocated */
|
||||
rvert *vtop; /* Top of list of vertices */
|
||||
rvert *vbot; /* Bottom of list of vertices */
|
||||
|
||||
int redge_no; /* Number of redges allocated */
|
||||
int ehsize; /* Edge hash list size */
|
||||
redge **edges; /* Edges between the triangles linked list */
|
||||
redge *etop; /* Top of list of edges */
|
||||
redge *ebot; /* Bottom of list of edges */
|
||||
|
||||
int rtri_no; /* Number of rtris allocated */
|
||||
int thsize; /* Triangle hash list size */
|
||||
rtri **tris; /* Hash list, NULL if not allocated */
|
||||
rtri *ttop; /* Surface triangles linked list */
|
||||
|
||||
}; typedef struct _gam_struct gam_struct;
|
||||
|
||||
#endif /* RSPL_GAM_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
602
Argyll_V3.5.0/rspl/mlbs.c
Normal file
602
Argyll_V3.5.0/rspl/mlbs.c
Normal file
@@ -0,0 +1,602 @@
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
*
|
||||
* Scattered Data Interpolation with multilevel B-splines library.
|
||||
* This can be used by rspl, or independently by any other routine.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2001/1/1
|
||||
*
|
||||
* Copyright 2000 - 2001 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is from the paper
|
||||
* "Scattered Data Interpolation with Multilevel B-Splines"
|
||||
* by Seungyong Lee, George Wolberg and Sung Yong Shin,
|
||||
* IEEE Transactions on Visualisation and Computer Graphics
|
||||
* Vol. 3, No. 3, July-September 1997, pp 228.
|
||||
*/
|
||||
|
||||
/* TTBD:
|
||||
*
|
||||
* Figure out why the results are rubbish ?
|
||||
*
|
||||
* Can this be adapted to be adaptive in it smoothness,
|
||||
* like the non-linear regularized spline stuff that Don Bone used ?
|
||||
*
|
||||
* Get rid of error() calls - return status instead
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "numlib.h"
|
||||
#include "mlbs.h"
|
||||
|
||||
#ifndef NUMSUP_H
|
||||
void error(char *fmt, ...), warning(char *fmt, ...);
|
||||
#endif
|
||||
|
||||
static void delete_mlbs(mlbs *p);
|
||||
static int lookup_mlbs(mlbs *p, co *c);
|
||||
|
||||
/* Allocate a new empty mlbs */
|
||||
mlbs *alloc_mlbs(
|
||||
int di, /* Input dimensionality */
|
||||
int fdi, /* Output dimesionality */
|
||||
int res, /* Target resolution */
|
||||
double smf /* Smoothing factor */
|
||||
) {
|
||||
mlbs *p;
|
||||
if ((p = (mlbs *)malloc(sizeof(mlbs))) == NULL)
|
||||
error("Malloc mlbs failed");
|
||||
|
||||
p->di = di;
|
||||
p->fdi = fdi;
|
||||
p->tres = res;
|
||||
p->smf = smf;
|
||||
p->s = NULL;
|
||||
|
||||
p->lookup = lookup_mlbs;
|
||||
p->del = delete_mlbs;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static void delete_slbs(slbs *s);
|
||||
|
||||
static void delete_mlbs(mlbs *p) {
|
||||
|
||||
if (p != NULL) {
|
||||
delete_slbs(p->s);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new empty slbs */
|
||||
static slbs *new_slbs(
|
||||
mlbs *p, /* Parent mlbs */
|
||||
int res /* Resolution of this slbs */
|
||||
) {
|
||||
slbs *s;
|
||||
int e, f;
|
||||
double *_lat, *lat; /* Latice base address */
|
||||
int ix, oe, oo[MXDI]; /* Neighborhood offset index, counter */
|
||||
|
||||
if ((s = (slbs *)malloc(sizeof(slbs))) == NULL)
|
||||
error("Malloc slbs failed");
|
||||
|
||||
s->p = p;
|
||||
s->res = res;
|
||||
|
||||
for (s->lsize = p->fdi, s->nsize = 1, e = 0; e < p->di; e++) {
|
||||
s->coi[e] = s->lsize; /* (double) increment in this input dimension */
|
||||
s->lsize *= (res + 2); /* Latice in 1D +/- 1 */
|
||||
s->nsize *= 4; /* Neighborhood of 4 */
|
||||
}
|
||||
|
||||
if ((s->_lat = (double *)malloc(s->lsize * sizeof(double))) == NULL)
|
||||
error("Malloc slbs latice failed");
|
||||
|
||||
/* Compute the base address */
|
||||
for (s->loff = 0, e = 0; e < p->di; e++) {
|
||||
s->loff += s->coi[e]; /* Offset by 1 in each input dimension */
|
||||
}
|
||||
s->lat = s->_lat + s->loff;
|
||||
|
||||
/* Figure the cell width */
|
||||
for (e = 0; e < p->di; e++)
|
||||
s->w[e] = (p->h[e] - p->l[e])/(res-1.0);
|
||||
|
||||
/* Setup neighborhood cache info */
|
||||
if ((s->n = (neigh *)malloc(s->nsize * sizeof(neigh))) == NULL)
|
||||
error("Malloc slbs neighborhood failed");
|
||||
|
||||
for (oe = 0; oe < p->di; oe++)
|
||||
oo[oe] = 0;
|
||||
|
||||
for(ix = oe = 0; oe < p->di; ix++) {
|
||||
int xo;
|
||||
for (xo = e = 0; e < p->di; e++) {
|
||||
s->n[ix].c[e] = oo[e];
|
||||
xo += s->coi[e] * oo[e]; /* Accumulate latice offset */
|
||||
}
|
||||
s->n[ix].xo = xo;
|
||||
s->n[ix].w = 0.0;
|
||||
|
||||
/* Increment destination offset counter */
|
||||
for (oe = 0; oe < p->di; oe++) {
|
||||
if (++oo[oe] <= 3) /* Counting from 0 ... 3 */
|
||||
break;
|
||||
oo[oe] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Destroy a slbs */
|
||||
static void delete_slbs(slbs *s) {
|
||||
if (s != NULL) {
|
||||
free(s->_lat);
|
||||
free(s->n);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump the 2D -> 1D contents of an slbs */
|
||||
static void dump_slbs(slbs *s) {
|
||||
int e, f;
|
||||
int ce, co[MXDI]; /* latice counter */
|
||||
mlbs *p = s->p; /* Parent object */
|
||||
|
||||
/* Init the counter */
|
||||
for (ce = 0; ce < p->di; ce++)
|
||||
co[ce] = -1;
|
||||
ce = 0;
|
||||
|
||||
f = 0;
|
||||
while(ce < p->di) {
|
||||
double v;
|
||||
int off = 0; /* Latice offset */
|
||||
for (e = 0; e < p->di; e++) {
|
||||
off += co[e] * s->coi[e]; /* Accumulate latice offset */
|
||||
}
|
||||
v = s->lat[off + f]; /* Value of this latice point */
|
||||
|
||||
printf("Latice at [%d][%d] = %f\n",co[1],co[0],v);
|
||||
|
||||
/* Increment the latice counter */
|
||||
for (ce = 0; ce < p->di; ce++) {
|
||||
if (++co[ce] <= s->res) /* Counting from -1 ... s->res */
|
||||
break;
|
||||
co[ce] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise an slbs with a linear approximation to the scattered data */
|
||||
static void linear_slbs(
|
||||
slbs *s
|
||||
) {
|
||||
int i, e, f;
|
||||
mlbs *p = s->p; /* Parent object */
|
||||
double **A; /* A matrix holding scattered data points */
|
||||
double *B; /* B matrix holding RHS & solution */
|
||||
|
||||
/* Allocate the matricies */
|
||||
B = dvector(0, p->npts-1);
|
||||
A = dmatrix(0, p->npts-1, 0, p->di);
|
||||
|
||||
/* For each output dimension, solve the linear equation coeficients */
|
||||
for (f = 0; f < p->fdi; f++) {
|
||||
int ce, co[MXDI]; /* latice counter */
|
||||
|
||||
/* Init A[][] with the scattered data points positions */
|
||||
/* Also init B[] with the value for this output dimension */
|
||||
for (i = 0; i < p->npts; i++) {
|
||||
for (e = 0; e < p->di; e++)
|
||||
A[i][e] = p->pts[i].p[e];
|
||||
A[i][e] = 1.0;
|
||||
B[i] = p->pts[i].v[f];
|
||||
}
|
||||
|
||||
/* Solve the equation A.x = b using SVD */
|
||||
/* (The w[] values are thresholded for best accuracy) */
|
||||
/* Return non-zero if no solution found */
|
||||
if (svdsolve(A, B, p->npts, p->di+1) != 0)
|
||||
error("SVD least squares failed");
|
||||
/* A[][] will have been changed, and B[] holds the p->di+1 coefficients */
|
||||
|
||||
/* Use the coefficients to initialise the slbs values */
|
||||
for (ce = 0; ce < p->di; ce++)
|
||||
co[ce] = -1;
|
||||
ce = 0;
|
||||
|
||||
while(ce < p->di) {
|
||||
double v = B[p->di]; /* Constant */
|
||||
int off = 0; /* Latice offset */
|
||||
for (e = 0; e < p->di; e++) {
|
||||
double lv;
|
||||
lv = p->l[e] + s->w[e] * co[e]; /* Input value for this latice location */
|
||||
v += B[e] * lv;
|
||||
off += co[e] * s->coi[e]; /* Accumulate latice offset */
|
||||
}
|
||||
s->lat[off + f] = v; /* Value of this latice point */
|
||||
|
||||
/* Increment the latice counter */
|
||||
for (ce = 0; ce < p->di; ce++) {
|
||||
if (++co[ce] <= s->res) /* Counting from -1 ... s->res */
|
||||
break;
|
||||
co[ce] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
free_dmatrix(A, 0, p->npts-1, 0, p->di);
|
||||
free_dvector(B, 0, p->npts-1);
|
||||
}
|
||||
|
||||
/* Do a latice refinement - upsample the current */
|
||||
/* source latice to the destination latice. */
|
||||
static void refine_slbs(
|
||||
slbs *ds, /* Destination slbs */
|
||||
slbs *ss /* Source slbs */
|
||||
) {
|
||||
mlbs *p = ss->p; /* Parent object */
|
||||
int ce, co[MXDI]; /* Source coordinate counter */
|
||||
int six; /* Source index */
|
||||
int dix; /* destination index */
|
||||
static double _wt[5] = { 1.0/8.0, 4.0/8.0, 6.0/8.0, 4.0/8.0, 1.0/8.0 };
|
||||
static double *wt = &_wt[2]; /* 1D Distribution weighting */
|
||||
|
||||
/* Zero the destination latice before accumulating values */
|
||||
for (dix = 0; dix < ds->lsize; dix++)
|
||||
ds->_lat[dix] = 0.0;
|
||||
|
||||
/* Now for each source latice entry, add weighted portions */
|
||||
/* to the associated destination points */
|
||||
|
||||
/* Init the source coordinate counter */
|
||||
for (ce = 0; ce < p->di; ce++)
|
||||
co[ce] = -1;
|
||||
ce = 0;
|
||||
six = -ss->loff;
|
||||
|
||||
while(ce < p->di) {
|
||||
int oe, oo[MXDI]; /* Destination offset counter */
|
||||
|
||||
//printf("Source coord %d %d, offset %d, value %f\n",co[0], co[1], six, ss->lat[six]);
|
||||
/* calc destination index, and init offest counter */
|
||||
for (dix = oe = 0; oe < p->di; oe++) {
|
||||
oo[oe] = -2;
|
||||
dix += co[oe] * 2 * ds->coi[oe]; /* Accumulate dest offset */
|
||||
}
|
||||
oe = 0;
|
||||
|
||||
//printf("Dest coord %d %d\n",co[0] * 2, co[1] * 2);
|
||||
/* For all the offsets from the destination point */
|
||||
while(oe < p->di) {
|
||||
int e, f, dixo; /* Destination index offset */
|
||||
double w = 1.0; /* Weighting */
|
||||
|
||||
//printf("dest offset %d %d\n",oo[0], oo[1]);
|
||||
/* Compute dest index offset, and check that we are not outside the destination */
|
||||
for (dixo = e = 0; e < p->di; e++) {
|
||||
int x = co[e] * 2 + oo[e]; /* dest coord */
|
||||
dixo += oo[e] * ds->coi[e]; /* Accumulate dest offset */
|
||||
//printf("x[%d] = %d\n",e, x);
|
||||
w *= wt[oo[e]]; /* Compute distribution weighting */
|
||||
if (x < -1 || x > ds->res)
|
||||
break; /* No good */
|
||||
}
|
||||
if (e >= p->di) { /* We are within the destination latice */
|
||||
//if ((co[0] * 2 + oo[0]) == 0 && (co[1] * 2 + oo[1]) == 0) {
|
||||
//printf("Source coord %d %d, offset %d, value %f\n",co[0], co[1], six, ss->lat[six]);
|
||||
//printf("Dest coord %d %d ix %d, weight %f\n",co[0] * 2 + oo[0], co[1] * 2 + oo[1], dix+dixo, w);
|
||||
//}
|
||||
|
||||
for (f = 0; f < p->fdi; f++) { /* Distribute weighted values */
|
||||
double v = ss->lat[six + f];
|
||||
//if ((co[0] * 2 + oo[0]) == 0 && (co[1] * 2 + oo[1]) == 0)
|
||||
//printf("Value being dist %f, weighted value %f\n", v, v * w);
|
||||
ds->lat[dix + dixo + f] += v * w;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment destination offset counter */
|
||||
for (oe = 0; oe < p->di; oe++) {
|
||||
if (++oo[oe] <= 2) /* Counting from -2 ... +2 */
|
||||
break;
|
||||
oo[oe] = -2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the source index and coordinat counter */
|
||||
six += p->fdi;
|
||||
for (ce = 0; ce < p->di; ce++) {
|
||||
if (++co[ce] <= ss->res) /* Counting from -1 ... ss->res */
|
||||
break;
|
||||
co[ce] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the Cubic B-spline weightings for a given t */
|
||||
void basis(double b[4], double t) {
|
||||
double _t3, _t2, _t1, _3t3, _3t2, _3t1, _6t2;
|
||||
|
||||
_t1 = t/6.0;
|
||||
_t2 = _t1 * _t1;
|
||||
_t3 = _t2 * _t1;
|
||||
_3t1 = 3.0 * _t1;
|
||||
_3t2 = 3.0 * _t2;
|
||||
_3t3 = 3.0 * _t3;
|
||||
_6t2 = 6.0 * _t2;
|
||||
|
||||
b[0] = - _t3 + _3t2 - _3t1 + 1.0/6.0;
|
||||
b[1] = _3t3 - _6t2 + 4.0/6.0;
|
||||
b[2] = -_3t3 + _3t2 + _3t1 + 1.0/6.0;
|
||||
b[3] = _t3;
|
||||
}
|
||||
|
||||
|
||||
/* Improve an slbs to make it closer to the scattered data */
|
||||
static void improve_slbs(
|
||||
slbs *s
|
||||
) {
|
||||
int i, e, f;
|
||||
mlbs *p = s->p; /* Parent object */
|
||||
double *delta; /* Delta accumulation */
|
||||
double *omega; /* Omega accumulation */
|
||||
|
||||
/* Allocate temporary accumulation arrays */
|
||||
if ((delta = (double *)calloc(sizeof(double), s->lsize)) == NULL)
|
||||
error("Malloc slbs temp latice failed");
|
||||
delta += s->loff;
|
||||
if ((omega = (double *)calloc(sizeof(double), s->lsize)) == NULL)
|
||||
error("Malloc slbs temp latice failed");
|
||||
omega += s->loff;
|
||||
|
||||
/* For each scattered data point */
|
||||
for (i = 0; i < p->npts; i++) {
|
||||
int ix; /* Latice index of base of neighborhood */
|
||||
double b[MXDI][4]; /* B-spline basis factors for each dimension */
|
||||
double sws; /* Sum of all the basis factors squared */
|
||||
double ve[MXDO]; /* Current output value error */
|
||||
int nn; /* Neighbor counter */
|
||||
|
||||
/* Figure out our neighborhood */
|
||||
for (ix = e = 0; e < p->di; e++) {
|
||||
int x;
|
||||
double t, sp, fp;
|
||||
sp = (p->pts[i].p[e] - p->l[e])/s->w[e]; /* Scaled position */
|
||||
fp = floor(sp);
|
||||
x = (int)(fp - 1.0); /* Grid coordinate */
|
||||
ix += s->coi[e] * x; /* Accume latice offset */
|
||||
t = sp - fp; /* Spline parameter */
|
||||
basis(b[e], t); /* Compute basis function values */
|
||||
}
|
||||
|
||||
/* Compute the grid basis weight functions, */
|
||||
/* the sum of the weights squared, and the current */
|
||||
/* output value estimate. */
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
ve[f] = p->pts[i].v[f]; /* Target output value */
|
||||
for (sws = 0.0, nn = 0; nn < s->nsize; nn++) {
|
||||
double w;
|
||||
for (w = 1.0, e = 0; e < p->di; e++)
|
||||
w *= b[e][s->n[nn].c[e]];
|
||||
s->n[nn].w = w; /* cache weighting */
|
||||
sws += w * w;
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
ve[f] -= w * s->lat[ix + s->n[nn].xo + f]; /* Subtract current aprox value */
|
||||
}
|
||||
//printf("Error at point %d = %f\n",i,ve[0]);
|
||||
|
||||
/* Accumulate the delta and omega factors */
|
||||
/* for this resolutions improvement. */
|
||||
for (nn = 0; nn < s->nsize; nn++) {
|
||||
double ws, ww, w = s->n[nn].w;
|
||||
int xo = ix + s->n[nn].xo; /* Latice offset */
|
||||
ww = w * w;
|
||||
ws = ww * w/sws; /* Scale factor for delta */
|
||||
omega[xo] += ww; /* Accumulate omega */
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
delta[xo + f] += ws * ve[f]; /* Accumulate delta */
|
||||
//printf("Distributing omega %f to %d %d\n",ww,s->n[nn].c[0],s->n[nn].c[1]);
|
||||
//printf("Distributing delta %f to %d %d\n",ws * ve[0],s->n[nn].c[0],s->n[nn].c[1]);
|
||||
}
|
||||
}
|
||||
|
||||
omega -= s->loff; /* Base them back to -1 corner */
|
||||
delta -= s->loff;
|
||||
|
||||
/* Go through the delta and omega arrays, */
|
||||
/* compute and add the refinements to the current */
|
||||
/* B-spline control latice. */
|
||||
for (i = 0; i < s->lsize; i++) {
|
||||
double om = omega[i];
|
||||
if (om != 0.0) {
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
s->_lat[i] += delta[i + f]/om;
|
||||
//printf("Adjusting latice index %d by %f to give %f\n",i, delta[i]/om, s->_lat[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Done with temporary arrays */
|
||||
free(omega);
|
||||
free(delta);
|
||||
}
|
||||
|
||||
/* Return the interpolated value for a given point */
|
||||
/* Return NZ if input point is out of range */
|
||||
static int lookup_mlbs(
|
||||
mlbs *p,
|
||||
co *c /* Point to interpolate */
|
||||
) {
|
||||
slbs *s = p->s;
|
||||
int e, f;
|
||||
int ix; /* Latice index of base of neighborhood */
|
||||
double b[MXDI][4]; /* B-spline basis factors for each dimension */
|
||||
int nn; /* Neighbor counter */
|
||||
|
||||
/* Figure out our neighborhood */
|
||||
for (ix = e = 0; e < p->di; e++) {
|
||||
int x;
|
||||
double t, sp, fp;
|
||||
sp = c->p[e];
|
||||
if (sp < p->l[e] || sp > p->h[e])
|
||||
return 1;
|
||||
sp = (sp - p->l[e])/s->w[e]; /* Scaled position */
|
||||
fp = floor(sp);
|
||||
x = (int)(fp - 1.0); /* Grid coordinate */
|
||||
ix += s->coi[e] * x; /* Accume latice offset */
|
||||
t = sp - fp; /* Spline parameter */
|
||||
basis(b[e], t); /* Compute basis function values */
|
||||
}
|
||||
|
||||
/* Compute the the current output value. */
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
c->v[f] = 0.0;
|
||||
for (nn = 0; nn < s->nsize; nn++) {
|
||||
double w;
|
||||
for (w = 1.0, e = 0; e < p->di; e++)
|
||||
w *= b[e][s->n[nn].c[e]];
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
c->v[f] += w * s->lat[ix + s->n[nn].xo + f]; /* Accume spline value */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Take a list of scattered data points, */
|
||||
/* and setup the mlbs. */
|
||||
static void set_mlbs(
|
||||
mlbs *p, /* mlbs to set up */
|
||||
dpnts *pts, /* scattered data points and weights */
|
||||
int npts, /* number of scattered data points */
|
||||
double *l, /* Input data range, low (May be NULL) */
|
||||
double *h /* Input data range, high (May be NULL) */
|
||||
) {
|
||||
int res;
|
||||
int i, e, f;
|
||||
slbs *s0 = NULL, *s1;
|
||||
|
||||
/* Establish the input data range */
|
||||
for (e = 0; e < p->di; e++) {
|
||||
if (l == NULL)
|
||||
p->l[e] = 1e60;
|
||||
else
|
||||
p->l[e] = l[e];
|
||||
if (h == NULL)
|
||||
p->h[e] = -1e60;
|
||||
else
|
||||
p->h[e] = h[e];
|
||||
}
|
||||
for (i = 0; i < npts; i++) {
|
||||
for (e = 0; e < p->di; e++) {
|
||||
if (pts[i].p[e] < p->l[e])
|
||||
p->l[e] = pts[i].p[e];
|
||||
if (pts[i].p[e] > p->h[e])
|
||||
p->h[e] = pts[i].p[e];
|
||||
}
|
||||
}
|
||||
|
||||
/* Make point data available during init */
|
||||
p->pts = pts;
|
||||
p->npts = npts;
|
||||
|
||||
/* Create an initial slbs */
|
||||
res = 2;
|
||||
if ((s1 = new_slbs(p, 2)) == NULL)
|
||||
error("new_slbs failed");
|
||||
|
||||
/* Set it up with a linear first approximation */
|
||||
linear_slbs(s1);
|
||||
//dump_slbs(s1);
|
||||
|
||||
/* Build up the resolution */
|
||||
for (; res < p->tres;) {
|
||||
|
||||
res = 2 * res -1;
|
||||
|
||||
printf("~1 doing resolution %d\n",res);
|
||||
delete_slbs(s0);
|
||||
s0 = s1;
|
||||
if ((s1 = new_slbs(p, res)) == NULL)
|
||||
error("new_slbs failed");
|
||||
|
||||
refine_slbs(s1, s0);
|
||||
//dump_slbs(s1);
|
||||
improve_slbs(s1);
|
||||
}
|
||||
|
||||
delete_slbs(s0);
|
||||
p->s = s1; /* Final resolution */
|
||||
|
||||
/* We can't assume point data will stick around */
|
||||
p->pts = NULL;
|
||||
p->npts = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Create a new empty mlbs */
|
||||
mlbs *new_mlbs(
|
||||
int di, /* Input dimensionality */
|
||||
int fdi, /* Output dimesionality */
|
||||
int res, /* Minimum final resolution */
|
||||
dpnts *pts, /* scattered data points and weights */
|
||||
int npts, /* number of scattered data points */
|
||||
double *l, /* Input data range, low (May be NULL) */
|
||||
double *h, /* Input data range, high (May be NULL) */
|
||||
double smf /* Smoothing factor */
|
||||
) {
|
||||
mlbs *p;
|
||||
|
||||
if ((p = alloc_mlbs(di, fdi, res, smf)) == NULL)
|
||||
return p;
|
||||
|
||||
set_mlbs(p, pts, npts, l, h);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifndef NUMSUP_H
|
||||
/* Basic printf type error() and warning() routines */
|
||||
|
||||
void
|
||||
error(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fprintf(stderr,"stest: Error - ");
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
void
|
||||
warning(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fprintf(stderr,"stest: Warning - ");
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#endif /* NUMSUP_H */
|
||||
|
||||
77
Argyll_V3.5.0/rspl/mlbs.h
Normal file
77
Argyll_V3.5.0/rspl/mlbs.h
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
*
|
||||
* Scattered Data Interpolation with multilevel B-splines library.
|
||||
* This can be used by rspl, or independently by any other routine.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2001/1/1
|
||||
*
|
||||
* Copyright 2000 - 2001 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is from the paper
|
||||
* "Scattered Data Interpolation with Multilevel B-Splines"
|
||||
* by Seungyong Lee, George Wolberg and Sung Yong Shin,
|
||||
* IEEE Transactions on Visualisation and Computer Graphics
|
||||
* Vol. 3, No. 3, July-September 1997, pp 228.
|
||||
*/
|
||||
|
||||
#include "rspl.h" /* Define some common elements */
|
||||
|
||||
/* Neighborhood latice cache data */
|
||||
typedef struct {
|
||||
int c[MXDI]; /* Coordinate */
|
||||
int xo; /* Offset into slbs latice */
|
||||
double w; /* B-spline basis weight */
|
||||
} neigh;
|
||||
|
||||
/* Structure that represents a resolution level of B-splines */
|
||||
struct _slbs {
|
||||
struct _mlbs *p; /* Parent structure */
|
||||
int res; /* Basic resolution */
|
||||
int coi[MXDI]; /* Double increment for each input dimension into latice */
|
||||
double *lat; /* Control latice, extending from +/- 1 from 0..res-1 */
|
||||
double *_lat; /* Allocation base of lat */
|
||||
int lsize, loff; /* Number of doubles in _lat, offset of lat from _lat */
|
||||
double w[MXDI]; /* Input data cell width */
|
||||
neigh *n; /* Neighborhood latice cache */
|
||||
int nsize; /* Number of n entries */
|
||||
}; typedef struct _slbs slbs;
|
||||
|
||||
/* Structure that represents the whole scattered interpolation state */
|
||||
struct _mlbs {
|
||||
int di; /* Input dimensions */
|
||||
int fdi; /* Output dimensions */
|
||||
int tres; /* Target resolution */
|
||||
double smf; /* Smoothing factor */
|
||||
int npts; /* Number of data points */
|
||||
dpnts *pts; /* Coordinate points and weights (valid while creating) */
|
||||
double l[MXDI], h[MXDI]; /* Input data range, cell width */
|
||||
slbs *s; /* Current B-spline latice */
|
||||
|
||||
int (*lookup)(struct _mlbs *p, co *c);
|
||||
|
||||
void (*del)(struct _mlbs *p);
|
||||
|
||||
}; typedef struct _mlbs mlbs;
|
||||
|
||||
|
||||
/* Create a new empty mlbs */
|
||||
mlbs *new_mlbs(
|
||||
int di, /* Input dimensionality */
|
||||
int fdi, /* Output dimesionality */
|
||||
int res, /* Minimum final resolution */
|
||||
dpnts *pts, /* scattered data points and weights */
|
||||
int npts, /* number of scattered data points */
|
||||
double *l, /* Input data range, low (May be NULL) */
|
||||
double *h, /* Input data range, high (May be NULL) */
|
||||
double smf /* Smoothing factor */
|
||||
);
|
||||
|
||||
719
Argyll_V3.5.0/rspl/opt.c
Normal file
719
Argyll_V3.5.0/rspl/opt.c
Normal file
@@ -0,0 +1,719 @@
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional regularized splines
|
||||
* optimiser based initialiser.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2001/5/16
|
||||
*
|
||||
* Copyright 1996 - 2001 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
/* This file contains an rspl initialiser that */
|
||||
/* works from an optimisation function callback. */
|
||||
/* It is intended to support the creation of optimised */
|
||||
/* color separations, although this usage is not hard coded */
|
||||
/* here. */
|
||||
|
||||
/* TTBD:
|
||||
*
|
||||
* !!! fix so that this can also be used for smoothed
|
||||
* inversion, ie. PCS -> DevN, as well as
|
||||
* separation PseudoCMY/K -> DevN.
|
||||
*
|
||||
* Plan:
|
||||
* Have additional callback function used for invert,
|
||||
* called at grid initialisation that initialised
|
||||
* the target values to fixed PCS values.
|
||||
* For separation, these are dynamic, and adjusted by
|
||||
* the usual optimisation callback.
|
||||
* (Or can the usual callback figure out when the
|
||||
* initial initialisation is needed ?)
|
||||
*
|
||||
* Need to return average/extrapolated surround values
|
||||
* on the edge, just like fit, so smoothness can be
|
||||
* evaluated in inversion.
|
||||
* Provide another mechanism for sep to know
|
||||
* it is on the edge of the grid, and should expand
|
||||
* gamut if possible.
|
||||
*
|
||||
* Get rid of error() calls - return status instead
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "rspl_imp.h"
|
||||
#include "numlib.h"
|
||||
#include "counters.h" /* Counter macros */
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
/* Tuning parameters */
|
||||
#define TOL 1e-6 /* Tollerance of result */
|
||||
#define GRATIO 1.7 /* Multi-grid ratio */
|
||||
#define SMOOTH 80.0 /* Set nominal smoothing (1.0) */
|
||||
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
/* Implemented in rspl.c: */
|
||||
extern void alloc_grid(rspl *s);
|
||||
|
||||
extern int is_mono(rspl *s);
|
||||
|
||||
/* Convention is to use:
|
||||
i to index grid points u.a
|
||||
n to index data points d.a
|
||||
e to index position dimension di
|
||||
f to index output function dimension fdi
|
||||
j misc and cube corners
|
||||
k misc
|
||||
*/
|
||||
|
||||
/* ================================================= */
|
||||
/* Structure to hold temporary data for multi-grid caliculations */
|
||||
/* Only used in this file. */
|
||||
struct _omgtp {
|
||||
rspl *s; /* Associated rspl */
|
||||
|
||||
/* Configuration data */
|
||||
int tdi; /* Target guide values dimensionality (must be <= MXDI) */
|
||||
/* (Typically the Lab aim values corresponding to this pseudo device value) */
|
||||
int adi; /* Additional grid point data allowance (must be <= 2 * MXDI) */
|
||||
/* (Typically black locus range) */
|
||||
|
||||
double (*func)(void *fdata, double *inout, double *surav, int first, double *cw);
|
||||
/* Optimisation function */
|
||||
void *fdata; /* Pointer to opaque data needed by callback function */
|
||||
|
||||
struct {
|
||||
double cw[MXDI]; /* Curvature weight factor for each dimension */
|
||||
} sf;
|
||||
|
||||
/* Grid points data */
|
||||
struct {
|
||||
int res[MXDI]; /* Single dimension grid resolution for each dimension */
|
||||
int bres, brix; /* Biggest resolution and its index */
|
||||
double mres; /* Geometric mean res[] */
|
||||
int no; /* Total number of points in grid = res ^ di */
|
||||
datai l,h,w; /* Grid low, high, grid cell width */
|
||||
|
||||
|
||||
double *a; /* Grid point data */
|
||||
/* Array is res ^ di entries double[fdi+tdi+adi] */
|
||||
/* The output values start at offset 0, the */
|
||||
/* target data values start at offset fdi, and */
|
||||
/* the additional data starts at offset fdi+tdi. */
|
||||
int pss; /* Grid point structure size = fdi+tdi */
|
||||
|
||||
/* Grid array offset lookups */
|
||||
int ci[MXDI]; /* Grid coordinate increments for each dimension */
|
||||
int fci[MXDI]; /* Grid coordinate increments for each dimension in doubles */
|
||||
int *hi; /* 2^di Combination offset for sequence through cube. */
|
||||
int *fhi; /* Combination offset for sequence through cube of */
|
||||
/* 2^di points, starting at base, in floats */
|
||||
int a_hi[DEF2MXDI]; /* Default allocation for *hi */
|
||||
int a_fhi[DEF2MXDI];/* Default allocation for *fhi */
|
||||
} g;
|
||||
|
||||
}; typedef struct _omgtp omgtp;
|
||||
|
||||
/* ================================================= */
|
||||
static omgtp *new_omgtp(rspl *s, int tdi, int adi, int mxres,
|
||||
double (*func)(void *fdata, double *inout, double *surav, int first, double *cw),
|
||||
void *fdata);
|
||||
static void free_omgtp(omgtp *m);
|
||||
static void solve_gres(omgtp *m, double tol);
|
||||
static void init_soln(omgtp *m1, omgtp *m2);
|
||||
static void init_fsoln(omgtp *m, double **vdata);
|
||||
|
||||
/* Initialise the regular spline from the optimisation callback function. */
|
||||
/* The target data is auxiliary data used to "target" the optimisation */
|
||||
/* callback function. */
|
||||
/* The callback function arguments are as follows:
|
||||
* void *fdata,
|
||||
* double *inout, Pointers to fdi+tdi+adi values for the grid point being optimised.
|
||||
* double *surav, Pointers to fdi+tdi values which are the average of the
|
||||
* neighbors of this grid point. Pointer will NULL if this
|
||||
* is a surface grid point.
|
||||
* int first, Flag, NZ if this is the first optimisation of this point.
|
||||
* double *cw the (grid resolution) curvature weighting factor for each dimension
|
||||
*
|
||||
* Returns value is the "error" for this point.
|
||||
*/
|
||||
|
||||
int
|
||||
opt_rspl_imp(
|
||||
rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
int tdi, /* Dimensionality of target data */
|
||||
int adi, /* Additional per grid point data allocation */
|
||||
double **vdata, /* di^2 array of function, target and additional values to init */
|
||||
/* array corners with. Corners are ordered with lowest index */
|
||||
/* dimension changing most rapidly. */
|
||||
double (*func)(void *fdata, double *inout, double *surav, int first, double *cw),
|
||||
/* Optimisation function */
|
||||
void *fdata, /* Opaque data needed by function */
|
||||
datai glow, /* Grid low scale - NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution for each dimension */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh /* Data value high normalize - NULL = default 1.0 */
|
||||
) {
|
||||
// int di = s->di
|
||||
int fdi = s->fdi;
|
||||
int i, e, f;
|
||||
// int n;
|
||||
|
||||
/* set debug level */
|
||||
s->debug = (flags >> 24);
|
||||
|
||||
if (flags & RSPL_VERBOSE) /* Turn on progress messages to stdout */
|
||||
s->verbose = 1;
|
||||
if (flags & RSPL_NOVERBOSE) /* Turn off progress messages to stdout */
|
||||
s->verbose = 0;
|
||||
|
||||
s->symdom = (flags & RSPL_SYMDOMAIN) ? 1 : 0; /* Turn on symetric smoothness with gres */
|
||||
|
||||
if (tdi >= MXDI)
|
||||
error("rspl, opt: tdi %d > MXDI %d",tdi,MXDI);
|
||||
|
||||
if (adi >= (2 * MXDI))
|
||||
error("rspl, opt: adi %d > 2 * MXDI %d",adi,2 * MXDI);
|
||||
|
||||
/* transfer desired grid range to structure */
|
||||
s->g.mres = 1.0;
|
||||
s->g.bres = 0;
|
||||
for (e = 0; e < s->di; e++) {
|
||||
if (gres[e] < 2)
|
||||
error("rspl: grid res must be >= 2!");
|
||||
s->g.res[e] = gres[e]; /* record the desired resolution of the grid */
|
||||
s->g.mres *= gres[e];
|
||||
if (gres[e] > s->g.bres) {
|
||||
s->g.bres = gres[e];
|
||||
s->g.brix = e;
|
||||
}
|
||||
|
||||
if (glow == NULL)
|
||||
s->g.l[e] = 0.0;
|
||||
else
|
||||
s->g.l[e] = glow[e];
|
||||
|
||||
if (ghigh == NULL)
|
||||
s->g.h[e] = 1.0;
|
||||
else
|
||||
s->g.h[e] = ghigh[e];
|
||||
}
|
||||
s->g.mres = pow(s->g.mres, 1.0/e); /* geometric mean */
|
||||
|
||||
/* compute width of each grid cell */
|
||||
for (e = 0; e < s->di; e++) {
|
||||
s->g.w[e] = (s->g.h[e] - s->g.l[e])/(double)(gres[e]-1);
|
||||
}
|
||||
|
||||
/* record low and width data normalizing factors */
|
||||
for (f = 0; f < s->fdi; f++) {
|
||||
if (vlow == NULL)
|
||||
s->d.vl[f] = 0.0;
|
||||
else
|
||||
s->d.vl[f] = vlow[f];
|
||||
|
||||
if (vhigh == NULL)
|
||||
s->d.vw[f] = 1.0 - s->d.vl[f];
|
||||
else
|
||||
s->d.vw[f] = vhigh[f] - s->d.vl[f];
|
||||
}
|
||||
|
||||
/* Do optimisation of data points */
|
||||
{
|
||||
int nn, res, sres;
|
||||
double fres, gratio = GRATIO;
|
||||
float *gp; /* rspl grid pointer */
|
||||
double *mgp; /* Temp muligrid pointer */
|
||||
omgtp *m, *om = NULL;
|
||||
|
||||
sres = 4; /* Start at initial grid res of 4 */
|
||||
if (sres > s->g.bres)
|
||||
sres = s->g.bres; /* Drop to target resolution */
|
||||
|
||||
/* Calculate the resolution scaling ratio */
|
||||
if (((double)s->g.bres/(double)sres) <= gratio) {
|
||||
gratio = (double)s->g.bres/(double)sres;
|
||||
nn = 1;
|
||||
} else { /* More than one needed */
|
||||
nn = (int)((log((double)s->g.bres) - log((double)sres))/log(gratio) + 0.5);
|
||||
gratio = exp((log((double)s->g.bres) - log((double)sres))/(double)nn);
|
||||
}
|
||||
|
||||
/* Do each grid resolution in turn */
|
||||
for (fres = (double)sres, res = sres;;) {
|
||||
m = new_omgtp(s, tdi, adi, res, func, fdata);
|
||||
|
||||
if (om == NULL) {
|
||||
init_fsoln(m, vdata); /* Set the initial targets & values from corners */
|
||||
} else {
|
||||
init_soln(m, om); /* Scale targets & values from from previous resolution */
|
||||
free_omgtp(om); /* Free previous grid res solution */
|
||||
}
|
||||
solve_gres(m, TOL * s->g.mres/res); /* Use itterative */
|
||||
|
||||
if (res >= s->g.mres)
|
||||
break; /* Done */
|
||||
|
||||
fres *= gratio;
|
||||
res = (int)(fres + 0.5);
|
||||
if ((res + 1) >= s->g.mres) /* If close enough */
|
||||
res = (int)s->g.mres;
|
||||
om = m;
|
||||
}
|
||||
|
||||
/* Allocate the final rspl grid data */
|
||||
alloc_grid(s);
|
||||
|
||||
/* Transfer result in x[] to appropriate grid point value */
|
||||
for (gp = s->g.a, mgp = m->g.a, i = 0; i < s->g.no; gp += s->g.pss, mgp += m->g.pss, i++)
|
||||
for (f = 0; f < fdi; f++)
|
||||
gp[f] = (float)mgp[f];
|
||||
free_omgtp(m);
|
||||
}
|
||||
|
||||
/* Return non-mono check */
|
||||
return is_mono(s);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - -*/
|
||||
/* omgtp routines */
|
||||
|
||||
/* Create a new omgtp. */
|
||||
/* Grid data will be uninitialised */
|
||||
static omgtp *new_omgtp(
|
||||
rspl *s, /* associated rspl */
|
||||
int tdi, /* Target dimensions */
|
||||
int adi, /* Additional per grid point data allocation */
|
||||
int mxres, /* maximum resolution to create */
|
||||
double (*func)(void *fdata, double *inout, double *surav, int first, double *cw),
|
||||
/* Optimisation function */
|
||||
void *fdata /* Opaque data needed by function */
|
||||
) {
|
||||
omgtp *m;
|
||||
int di = s->di, fdi = s->fdi;
|
||||
// int dno = s->d.no;
|
||||
int gno;
|
||||
int e, g, i;
|
||||
// int f, n, j, k;
|
||||
|
||||
/* Allocate a structure */
|
||||
if ((m = (omgtp *) calloc(1, sizeof(omgtp))) == NULL)
|
||||
error("rspl: malloc failed - omgtp");
|
||||
|
||||
/* Allocate space for cube offset arrays */
|
||||
m->g.hi = m->g.a_hi;
|
||||
m->g.fhi = m->g.a_fhi;
|
||||
if ((1 << di) > DEF2MXDI) {
|
||||
if ((m->g.hi = (int *) malloc(sizeof(int) * (1 << di))) == NULL)
|
||||
error("rspl omgtp malloc failed - hi[]");
|
||||
if ((m->g.fhi = (int *) malloc(sizeof(int) * (1 << di))) == NULL)
|
||||
error("rspl omgtp malloc failed - fhi[]");
|
||||
}
|
||||
|
||||
/* General stuff */
|
||||
m->s = s;
|
||||
m->tdi = tdi;
|
||||
m->adi = adi;
|
||||
m->func = func;
|
||||
m->fdata = fdata;
|
||||
|
||||
/* Grid related */
|
||||
m->g.mres = 1.0;
|
||||
m->g.bres = 0;
|
||||
for (gno = 1, e = 0; e < di; e++) {
|
||||
if (mxres >= s->g.res[e]) /* Shoose smaller of gres and target res */
|
||||
m->g.res[e] = s->g.res[e];
|
||||
else
|
||||
m->g.res[e] = mxres;
|
||||
|
||||
m->g.mres *= m->g.res[e];
|
||||
if (m->g.res[e] > m->g.bres) {
|
||||
m->g.bres = m->g.res[e];
|
||||
m->g.brix = e;
|
||||
}
|
||||
gno *= m->g.res[e];
|
||||
}
|
||||
m->g.mres = pow(m->g.mres, 1.0/e); /* geometric mean */
|
||||
m->g.no = gno;
|
||||
|
||||
m->g.pss = fdi+tdi+adi; /* doubles for each output value + target data + additional data */
|
||||
|
||||
/* record high, low limits, and width of each grid cell */
|
||||
for (e = 0; e < s->di; e++) {
|
||||
m->g.l[e] = s->g.l[e];
|
||||
m->g.h[e] = s->g.h[e];
|
||||
m->g.w[e] = (s->g.h[e] - s->g.l[e])/(double)(m->g.res[e]-1);
|
||||
}
|
||||
|
||||
/* Compute index coordinate increments into linear grid for each dimension */
|
||||
/* ie. 1, gres, gres^2, gres^3 */
|
||||
for (m->g.ci[0] = 1, e = 1; e < di; e++) {
|
||||
m->g.ci[e] = m->g.ci[e-1] * m->g.res[e-1]; /* In grid points */
|
||||
m->g.fci[e] = m->g.ci[e] * m->g.pss; /* In doubles */
|
||||
}
|
||||
|
||||
/* Compute index offsets from base of cube to other corners */
|
||||
for (m->g.hi[0] = 0, e = 0, g = 1; e < di; g *= 2, e++) {
|
||||
for (i = 0; i < g; i++) {
|
||||
m->g.hi[g+i] = m->g.hi[i] + m->g.ci[e]; /* In grid points */
|
||||
m->g.fhi[g+i] = m->g.hi[g+i] * m->g.pss; /* In doubles */
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate space for grid */
|
||||
if ((m->g.a = (double *) malloc(sizeof(double) * gno * m->g.pss)) == NULL)
|
||||
error("rspl malloc failed - multi-grid points");
|
||||
|
||||
/* Compute curvature weighting for matching intermediate resolutions. */
|
||||
/* cw[] is multiplied by the grid curvature_errors_squared[] to keep */
|
||||
/* the same ratio with the sum of data position errors squared. */
|
||||
for (e = 0; e < di; e++) {
|
||||
double rsm; /* Resolution smoothness factor */
|
||||
if (s->symdom)
|
||||
rsm = m->g.res[e]-1.0; /* Relative final grid size */
|
||||
else
|
||||
rsm = m->g.mres-1.0; /* Relative mean final grid size */
|
||||
rsm = pow(rsm,8.0/di);
|
||||
rsm /= pow(200.0,8.0/di)/pow(200.0, 4.0); /* (Scale factor to adjust power) */
|
||||
|
||||
m->sf.cw[e] = (s->smooth * SMOOTH)/(rsm * (double)di);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/* Completely free an omgtp */
|
||||
static void free_omgtp(omgtp *m) {
|
||||
|
||||
free((void *)m->g.a);
|
||||
|
||||
/* Free structure */
|
||||
if (m->g.hi != m->g.a_hi) {
|
||||
free(m->g.hi);
|
||||
free(m->g.fhi);
|
||||
}
|
||||
free((void *)m);
|
||||
}
|
||||
|
||||
/* Set the first targets & values from the corner values. */
|
||||
static void init_fsoln(
|
||||
omgtp *m, /* Destination */
|
||||
double **vdata /* di^2 array of function and target values to init array corners with. */
|
||||
/* Corners are ordered with lowest index dimension changing most rapidly. */
|
||||
/* (Function data at index 0, target data at index fdi) */
|
||||
) {
|
||||
rspl *s = m->s;
|
||||
int di = s->di;
|
||||
int fdi = s->fdi;
|
||||
int gno = m->g.no;
|
||||
int gres_1[MXDI];
|
||||
int e, n;
|
||||
double *gp; /* Pointer to dest g.a[] grid cube base */
|
||||
ECOUNT(gc, MXDIDO, di, 0, m->g.res, 0); /* Counter for output points */
|
||||
double *gw; /* weight for each grid cube corner */
|
||||
double a_gw[DEF2MXDI]; /* default allocation for gw */
|
||||
|
||||
gw = a_gw;
|
||||
if ((1 << di) > DEF2MXDI) {
|
||||
if ((gw = (double *) malloc(sizeof(double) * (1 << di))) == NULL)
|
||||
error("rspl malloc failed - interp_rspl_nl");
|
||||
}
|
||||
|
||||
for (e = 0; e < di; e++)
|
||||
gres_1[e] = m->g.res[e]-1;
|
||||
|
||||
/* For all output grid points (could skip non-surface points ?) */
|
||||
EC_INIT(gc);
|
||||
for (n = 0, gp = m->g.a; n < gno; n++, gp += m->g.pss) {
|
||||
double we[MXDI]; /* 1.0 - Weight in each dimension */
|
||||
|
||||
/* Figure out the pointer to the grid data and its weighting */
|
||||
{
|
||||
gp = m->g.a; /* Base of output array */
|
||||
for (e = 0; e < di; e++)
|
||||
we[e] = (double)gc[e]/gres_1[e]; /* 1.0 - weight */
|
||||
}
|
||||
|
||||
/* Compute corner weights needed for interpolation */
|
||||
{
|
||||
int i, g;
|
||||
gw[0] = 1.0;
|
||||
for (e = 0, g = 1; e < di; g *= 2, e++) {
|
||||
for (i = 0; i < g; i++) {
|
||||
gw[g+i] = gw[i] * we[e];
|
||||
gw[i] *= (1.0 - we[e]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the output values */
|
||||
{
|
||||
int i, f;
|
||||
double w = gw[0];
|
||||
double *d = vdata[0];
|
||||
|
||||
for (f = 0; f < m->g.pss; f++) /* Base of cube */
|
||||
gp[f] = w * d[f];
|
||||
|
||||
for (i = 1; i < (1 << di); i++) { /* For all other corners of cube */
|
||||
w = gw[i]; /* Strength reduce */
|
||||
d = vdata[i];
|
||||
for (f = 0; f < fdi; f++)
|
||||
gp[f] += w * d[f];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EC_INC(gc);
|
||||
}
|
||||
|
||||
if (gw != a_gw)
|
||||
free(gw);
|
||||
}
|
||||
|
||||
|
||||
/* Transfer a device and target values solution from one omgtp to another. */
|
||||
/* (We assume that they are for the same problem) */
|
||||
static void init_soln(
|
||||
omgtp *m1, /* Destination */
|
||||
omgtp *m2 /* Source */
|
||||
) {
|
||||
rspl *s = m1->s;
|
||||
int di = s->di;
|
||||
int gno = m1->g.no;
|
||||
int gres1_1[MXDI];
|
||||
int gres2_1[MXDI];
|
||||
int e, n;
|
||||
double *a; /* Pointer to dest g.a[] grid cube base */
|
||||
ECOUNT(gc, MXDIDO, di, 0, m1->g.res, 0); /* Counter for output points */
|
||||
double *gw; /* weight for each grid cube corner */
|
||||
double a_gw[DEF2MXDI]; /* default allocation for gw */
|
||||
|
||||
gw = a_gw;
|
||||
if ((1 << di) > DEF2MXDI) {
|
||||
if ((gw = (double *) malloc(sizeof(double) * (1 << di))) == NULL)
|
||||
error("rspl malloc failed - interp_rspl_nl");
|
||||
}
|
||||
|
||||
for (e = 0; e < di; e++) {
|
||||
gres1_1[e] = m1->g.res[e]-1;
|
||||
gres2_1[e] = m2->g.res[e]-1;
|
||||
}
|
||||
|
||||
/* For all output grid points */
|
||||
EC_INIT(gc);
|
||||
for (n = 0, a = m1->g.a; n < gno; n++, a += m1->g.pss) {
|
||||
double we[MXDI]; /* 1.0 - Weight in each dimension */
|
||||
double *gp; /* Pointer to source g.a[] grid cube base */
|
||||
|
||||
/* Figure out which grid cell the point falls into */
|
||||
{
|
||||
double t;
|
||||
int mi;
|
||||
gp = m2->g.a; /* Base of solution array */
|
||||
for (e = 0; e < di; e++) {
|
||||
t = (double)gc[e] * gres2_1[e]/gres1_1[e];
|
||||
mi = (int)floor(t); /* Grid coordinate */
|
||||
if (mi < 0) /* Limit to valid cube base index range */
|
||||
mi = 0;
|
||||
else if (mi >= gres2_1[e])
|
||||
mi = gres2_1[e]-1;
|
||||
gp += mi * m2->g.fci[e]; /* Add Index offset for grid cube base in dimen */
|
||||
we[e] = t - (double)mi; /* 1.0 - weight */
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute corner weights needed for interpolation */
|
||||
{
|
||||
int i, g;
|
||||
gw[0] = 1.0;
|
||||
for (e = 0, g = 1; e < di; g *= 2, e++) {
|
||||
for (i = 0; i < g; i++) {
|
||||
gw[g+i] = gw[i] * we[e];
|
||||
gw[i] *= (1.0 - we[e]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the output values */
|
||||
{
|
||||
int i, f;
|
||||
double w = gw[0];
|
||||
double *d = gp + m2->g.fhi[0];
|
||||
|
||||
for (f = 0; f < m1->g.pss; f++) /* Base of cube */
|
||||
a[f] = w * d[f];
|
||||
|
||||
for (i = 1; i < (1 << di); i++) { /* For all other corners of cube */
|
||||
w = gw[i]; /* Strength reduce */
|
||||
d = gp + m2->g.fhi[i];
|
||||
for (f = 0; f < m1->g.pss; f++)
|
||||
a[f] += w * d[f];
|
||||
}
|
||||
|
||||
}
|
||||
EC_INC(gc);
|
||||
}
|
||||
|
||||
if (gw != a_gw)
|
||||
free(gw);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - -*/
|
||||
static double one_itter(omgtp *m, int first);
|
||||
|
||||
/* Itterate the optimisation functions until we are happy things have settled */
|
||||
static void
|
||||
solve_gres(
|
||||
omgtp *m,
|
||||
double tol
|
||||
) {
|
||||
int i;
|
||||
double dtol = tol * 0.1; /* Delta tol limit */
|
||||
double ltt, tt;
|
||||
|
||||
ltt = 1.0;
|
||||
tt = tol * 10.0;
|
||||
|
||||
for (i = 0; i < 500; i++) {
|
||||
if (i == 0)
|
||||
tt = one_itter(m, 1);
|
||||
|
||||
ltt = tt;
|
||||
tt = one_itter(m, 0);
|
||||
|
||||
if (tt < tol || (ltt - tt) < dtol) /* Get within 0.1 % */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Optimise the points values and (optionally) targets */
|
||||
/* Use Red/Black order, return total error after this itteration. */
|
||||
/* Return the total optimisation error */
|
||||
static double
|
||||
one_itter(
|
||||
omgtp *m,
|
||||
int first /* Flag, NZ if this is the first pass at this resolution */
|
||||
) {
|
||||
int di = m->s->di, fdi = m->s->fdi;
|
||||
int tdi = m->tdi;
|
||||
int i, e, f;
|
||||
int gc[MXDI];
|
||||
int *gres = m->g.res;
|
||||
int gres_1[MXDI];
|
||||
DCOUNT(cc, MXDIDO, di, -1, -1, 2); /* Surrounding cube counter */
|
||||
double *gpp; /* Current grid point pointer */
|
||||
double ssum[MXDO+MXDI+2*MXDI]; /* Pointer to surrounding average values */
|
||||
double *surav; /* Surrounding average values */
|
||||
double awt; /* Average weight */
|
||||
double terr = 0.0; /* Total error */
|
||||
int surf; /* This point is on the surface */
|
||||
|
||||
for (e = 0; e < di; e++) {
|
||||
gc[e] = 0; /* init coords */
|
||||
gres_1[e] = gres[e] - 1;
|
||||
}
|
||||
|
||||
/* Until done */
|
||||
for (;;) {
|
||||
|
||||
/* See if we are on the surface */
|
||||
surf = 0;
|
||||
gpp = m->g.a;
|
||||
for (e = 0; e < di; e++) {
|
||||
gpp += m->g.fci[e] * gc[e]; /* Compute pointer to current point */
|
||||
|
||||
if (gc[e] == 0 || gc[e] == gres_1[e])
|
||||
surf = 1;
|
||||
}
|
||||
|
||||
surav = NULL;
|
||||
if (!surf) {
|
||||
|
||||
for (f = 0; f < (fdi + tdi); f++)
|
||||
ssum[f] = 0.0;
|
||||
awt = 0.0;
|
||||
|
||||
/* Average the 3x3 surrounders */
|
||||
DC_INIT(cc)
|
||||
for (i = 0; !DC_DONE(cc); i++ ) {
|
||||
double *gp = m->g.a;
|
||||
|
||||
for (e = 0; e < di; e++) {
|
||||
int j;
|
||||
j = gc[e] + cc[e];
|
||||
if (j < 0 && j > gres_1[e]) { /* outside */
|
||||
break;
|
||||
}
|
||||
gp += m->g.fci[e] * j; /* Compute pointer to surrounder */
|
||||
}
|
||||
if (e >= di) { /* We have a valid point */
|
||||
for (f = 0; f < (fdi + tdi); f++)
|
||||
ssum[f] += gp[f];
|
||||
awt += 1.0;
|
||||
}
|
||||
DC_INC(cc);
|
||||
}
|
||||
if (awt > 0.0) { /* Compute the average */
|
||||
for (f = 0; f < (fdi + tdi); f++)
|
||||
ssum[f] /= awt;
|
||||
surav = ssum;
|
||||
}
|
||||
}
|
||||
|
||||
/* Call optimisation function */
|
||||
terr += m->func(m->fdata, gpp, surav, first, m->sf.cw);
|
||||
|
||||
/* Increment index in red/black order */
|
||||
for (e = 0; e < di; e++) {
|
||||
if (e == 0) {
|
||||
gc[0] += 2; /* Inc coordinate by 2 */
|
||||
} else {
|
||||
gc[e] += 1; /* Inc coordinate */
|
||||
}
|
||||
if (gc[e] < gres[e])
|
||||
break; /* No carry */
|
||||
gc[e] -= gres[e]; /* Reset coord */
|
||||
|
||||
if ((gres[e] & 1) == 0) { /* Compensate for odd grid */
|
||||
gc[0] ^= 1; /* XOR lsb */
|
||||
}
|
||||
}
|
||||
/* Stop on reaching 0 */
|
||||
for(e = 0; e < di; e++)
|
||||
if (gc[e] != 0)
|
||||
break;
|
||||
if (e == di)
|
||||
break; /* Finished */
|
||||
}
|
||||
|
||||
return terr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
13244
Argyll_V3.5.0/rspl/rev.c
Normal file
13244
Argyll_V3.5.0/rspl/rev.c
Normal file
File diff suppressed because it is too large
Load Diff
548
Argyll_V3.5.0/rspl/rev.h
Normal file
548
Argyll_V3.5.0/rspl/rev.h
Normal file
@@ -0,0 +1,548 @@
|
||||
#ifndef RSPL_REV_H
|
||||
#define RSPL_REV_H
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional regularized spline data structure
|
||||
*
|
||||
* Reverse interpolation support code.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 30/1/00
|
||||
*
|
||||
* Copyright 1999 - 2008 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*
|
||||
* Latest simplex/linear equation version.
|
||||
*/
|
||||
|
||||
#undef STATS /* Collect and print reverse cach stats */
|
||||
|
||||
/* Data structures used by reverse lookup code. */
|
||||
/* Note that the reverse lookup code only supports a more limited */
|
||||
/* dimension range than the general rspl code. */
|
||||
|
||||
/*
|
||||
* Note on simplex parameter space.
|
||||
*
|
||||
* Simplex interpolation is normaly done in Baricentric space, where there
|
||||
* is one more baricentric coordinate than dimensions, and the sum of all
|
||||
* the baricentric coordinates must be 1.
|
||||
*
|
||||
* To simplify things, we work in a "Simplex parameter" space, in which
|
||||
* there are only dimension parameters, and each directly corresponds
|
||||
* with a cartesian coordinate, but the parameter order corresponds with
|
||||
* the baricentric order.
|
||||
*
|
||||
* For example, given cartesian sub-coordinates D0, D1, D2
|
||||
* into a (3D) forward interpolation cube, these should be sorted
|
||||
* from smallest to largest, thereby choosing a particular
|
||||
* simplex within a cube, and allowing a correspondence to
|
||||
* the parameter coordinates, ie:
|
||||
*
|
||||
* D2 D0 D1 Smallest -> Largest cartesian sort
|
||||
* P0 P1 P2 Corresponding Parameter coordinates
|
||||
*
|
||||
* B0 = P0 Conversion to Baricentric weighting/coordinates
|
||||
* B1 = P1 - P0
|
||||
* B2 = P2 - P1
|
||||
* B3 = 1 - P2
|
||||
*
|
||||
* The 4 (tetrahedron) vertex values directly correspond to Baricentric
|
||||
* weighting/coordinates, giving the usual interpolation equation of:
|
||||
*
|
||||
* VV0 * B0
|
||||
* + VV1 * B1
|
||||
* + VV2 * B2
|
||||
* + VV3 * B3
|
||||
*
|
||||
* Reversing the Parameter -> Baricentric equations gives the
|
||||
* following interpolation equation using Parameter coordinates:
|
||||
*
|
||||
* (VV0 - VV1) * P0
|
||||
* + (VV1 - VV2) * P1
|
||||
* + (VV2 - VV3) * P2
|
||||
* + VV3
|
||||
*
|
||||
* Note that within the simplex, 0 <= P0 && P0 <= P1 && P1 <= P2 && P2 <= 1
|
||||
*
|
||||
* It is this which is used in rev.c for solving the reverse
|
||||
* interpolation problem.
|
||||
*/
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* Group size information for nn LCh weighted quick accept/reject testing */
|
||||
typedef struct {
|
||||
double bcent[MXRO]; /* Group center location in output space */
|
||||
double brad; /* Output value bounding shere radius */
|
||||
double bradsq; /* Output value bounding shere radius squared */
|
||||
|
||||
double maxDlc; /* Maximum members weighted delta LC (+extra dims) squared */
|
||||
double maxDh; /* Maximum members delta h squared */
|
||||
double maxDh_; /* Maximum members delta h (not squared) */
|
||||
double sratio; /* Minimum members C ratio to Gc squared */
|
||||
double bratio; /* Maximum members C ratio to Gc squared */
|
||||
double Wsratio; /* Minimum members C ratio to Gc squared - pre-weighted */
|
||||
double Wbratio; /* Maximum members C ratio to Gc squared - pre-weighted */
|
||||
double Gc; /* Group center Chrominance squared */
|
||||
double Gc_; /* Group center Chrominance (not squared) */
|
||||
} nn_grp;
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* A structure to hold per simplex coordinate and vertex mapping for ssxinfo. */
|
||||
/* This is relative to the construction cube. A face sub-simplex */
|
||||
/* that is common between cubes, will have a different psxinfo */
|
||||
/* depending on which cube created it. */
|
||||
typedef struct {
|
||||
int face; /* Flag, nz if simplex lies on cube surface */
|
||||
int icomb[MXDI]; /* icomb[] specifies the equation to convert simplex space */
|
||||
/* coordinates back into cartesian space. */
|
||||
/* Index by Absolute[di] -> Simplex Parameter[sdi], */
|
||||
/* -1 == value 0, -2 == value 1 */
|
||||
/* Note that many Abs can map to one Param to form a sum. */
|
||||
int offs[MXDI+1]; /* Offsets to simplex vertices within cube == bit per dim */
|
||||
int goffs[MXDI+1]; /* Offsets to simplex vertices within grid */
|
||||
int foffs[MXDI+1]; /* Fwd grid floating offsets to simplex vertices from cube base */
|
||||
int pmino[MXDI], pmaxo[MXDI]; /* Cube verticy offsets to setup simplex pmin[] and */
|
||||
/* pmax[] bounding box pointers. */
|
||||
} psxinfo;
|
||||
|
||||
/* Sub simplexes of a cube information structure */
|
||||
typedef struct {
|
||||
int sdi; /* Sub-simplex dimensionality */
|
||||
int nospx; /* Number of sub-simplexs per cube */
|
||||
psxinfo *spxi; /* Per sub-simplex info array, NULL if not initialised */
|
||||
} ssxinfo;
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* NOTE :- This should really be re-arranged to be per-sub-simplex caching, */
|
||||
/* rather than fxcell caching. Rather than stash the simplex info in the fxcells, */
|
||||
/* create a separate cache or some other way of sharing the common simplexes. */
|
||||
/* The code that ignores common face simplexes in fxcells could then be removed (?). */
|
||||
|
||||
/* Simplex definition. Each top level fwd interpolation cell, */
|
||||
/* is decomposed into sub-simplexes. Sub-simplexes are of equal or */
|
||||
/* lower dimensionality (ie. faces, edges, vertices) to the cube. */
|
||||
struct _simplex {
|
||||
int refcount; /* reference count */
|
||||
struct _rspl *s; /* Pointer to parent rspl */
|
||||
int ix; /* Construction Fwd cell index */
|
||||
int si; /* Diagnostic - simplex number within level */
|
||||
int sdi; /* Sub-simplex dimensionality */
|
||||
int efdi; /* Effective fdi. This will be = fdi for a non clip */
|
||||
/* plane simplex, and fdi+1 for a clip plane simplex. */
|
||||
/* The DOF (Degress of freedom) within this simplex = sdi - efdi */
|
||||
|
||||
psxinfo *psxi; /* Generic per simplex info (construction cube relative) */
|
||||
int vix[MXRI+1]; /* fwd cell vertex indexes of this simplex [sdi+1] */
|
||||
/* This is a universal identification of this simplex. */
|
||||
struct _simplex *hlink; /* Link to other cells with this hash */
|
||||
unsigned int touch; /* Last touch count. */
|
||||
short flags; /* Various flags */
|
||||
|
||||
#define SPLX_CLIPSX 0x01 /* This is a clip plane simplex */
|
||||
|
||||
#define SPLX_FLAG_1 0x04 /* v, linmin/max initialised */
|
||||
#define SPLX_FLAG_2 0x08 /* lu/svd initialised */
|
||||
#define SPLX_FLAG_2F 0x10 /* lu/svd init. failed */
|
||||
#define SPLX_FLAG_4 0x20 /* locus found */
|
||||
#define SPLX_FLAG_5 0x40 /* auxiliary lu/svd initialised */
|
||||
#define SPLX_FLAG_5F 0x80 /* auxiliary lu/svd init. failed */
|
||||
|
||||
#define SPLX_FLAGS (SPLX_FLAG_1 | SPLX_FLAG_2 | SPLX_FLAG_2F \
|
||||
| SPLX_FLAG_4 | SPLX_FLAG_5 | SPLX_FLAG_5F)
|
||||
|
||||
double v[MXRI+1][MXRO+1]; /* Simplex Vertex values */
|
||||
/* v[0..sdi][0..fdi-1] are the output interpolation values */
|
||||
/* v[0..sdi][fdi] are the ink limit interpolation values */
|
||||
|
||||
/* Baricentric vv[x][y] = (v[y][x] - v[y+1][x]) */
|
||||
/* and vv[x][sdi] = v[sdi][x] */
|
||||
|
||||
/* Note that #num indicates appropriate flag number */
|
||||
/* and *num indicates a validator */
|
||||
|
||||
double p0[MXRI]; /* Simplex base position = construction cube p[0] */
|
||||
double pmin[MXRI]; /* Simplex vertex input space min and */
|
||||
double pmax[MXRI]; /* max values [di] */
|
||||
|
||||
double min[MXRO+1], max[MXRO+1]; /* Simplex vertex output space [fdi+1] and */
|
||||
/* ink limit bounding values at minmax[fdi] */
|
||||
|
||||
/* If sdi == efdi, this holds the LU decomposition, */
|
||||
/* else this holds the SVD and solution locus info */
|
||||
|
||||
char *aloc2; /* Memory allocation for #2 & #4 */
|
||||
|
||||
/* double **d_u; LU decomp of vv, U[0..efdi-1][0..sdi-1] #2 */
|
||||
/* int *d_w; LU decomp of vv, W[0..sdi-1] #2 */
|
||||
|
||||
double **d_u; /* SVD decomp of vv, U[0..efdi-1][0..sdi-1] #2 */
|
||||
double *d_w; /* SVD decomp of vv, W[0..sdi-1] #2 */
|
||||
double **d_v; /* SVD decomp of vv, V[0..sdi-1][0..sdi-1] #2 */
|
||||
|
||||
/* Degrees of freedom = dof = sdi - efdi */
|
||||
double **lo_l; /* Locus coefficients, [0..sdi-1][0..dof-1] #2 */
|
||||
|
||||
double *lo_xb; /* RHS used to compute lo_bd [0..efdi-1] *4 */
|
||||
double *lo_bd; /* Locus base solution, [0..sdi-1] #4 */
|
||||
|
||||
unsigned auxbm; /* aux bitmap mask for ax_lu and ax_svd *5 */
|
||||
int aaux; /* naux count for allocation *5 */
|
||||
int naux; /* naux for calculation (may be < aaux ?) *5 */
|
||||
|
||||
/* if (sdi-efdi = dof) == naux this holds LU of lo_l */
|
||||
/* else this holds the SVD of lo_l */
|
||||
|
||||
char *aloc5; /* Memory allocation for #5 */
|
||||
|
||||
/* double **ax_u; LU decomp of lo_l #5 */
|
||||
/* int *ax_w; Pivot record for ax_lu decomp #5 */
|
||||
|
||||
double **ax_u; /* SVD decomp of lo_l, U[0..naux-1][0..dof-1] #5 */
|
||||
double *ax_w; /* SVD decomp of lo_l, W[0..dof-1] #5 */
|
||||
double **ax_v; /* SVD decomp of lo_l, V[0..dof-1][0..dof-1] #5 */
|
||||
|
||||
}; typedef struct _simplex simplex;
|
||||
|
||||
/* A candidate search (fwd) fxcell (cell cache entry structure) */
|
||||
struct _fxcell {
|
||||
struct _rspl *s; /* Pointer to parent rspl */
|
||||
|
||||
/* Cache information */
|
||||
int ix; /* Corresponding fwd cell index */
|
||||
struct _fxcell *hlink; /* Link to other cells with this hash */
|
||||
struct _fxcell *mrudown;/* Links to next most recently used fxcell */
|
||||
struct _fxcell *mruup;
|
||||
int refcount; /* Reference count */
|
||||
int flags; /* Non-zero if the fxcell has been initialised */
|
||||
#define CELL_FLAG_1 0x01 /* Basic initialisation, including nn_grp */
|
||||
#define CELL_FLAG_2 0x02 /* Simplex information initialised */
|
||||
|
||||
/* Use information */
|
||||
double sort; /* Sort key */
|
||||
double limmin, limmax; /* limit() min/max for this fxcell */
|
||||
|
||||
/* Quick nn distance information */
|
||||
nn_grp g;
|
||||
|
||||
// double bcent[MXRO]; /* Output value bounding shere center */
|
||||
// double brad; /* Output value bounding shere radius */
|
||||
// double bradsq; /* Output value bounding shere radius squared */
|
||||
// double wbrad; /* Output value weighted bounding shere radius */
|
||||
|
||||
double p[POW2MXRI][MXRI]; /* Vertex input positions for this cube. */
|
||||
/* Copied to x->pmin/pmax[] & ink limit */
|
||||
|
||||
double v[POW2MXRI][MXRO+1]; /* Vertex data for this cube. Copied to x->v[] */
|
||||
/* v[][fdi] is the ink limit values, if relevant */
|
||||
|
||||
simplex **sx[MXRI+1]; /* Lists of simplexes that make up this fxcell. */
|
||||
/* Each list indexed by the non-limited simplex */
|
||||
/* dimensionality (similar to sspxi[]) */
|
||||
/* Each list will be NULL if it hasn't been created yet */
|
||||
int sxno[MXRI+1]; /* Corresponding count of each list */
|
||||
|
||||
}; typedef struct _fxcell fxcell;
|
||||
|
||||
/* surface bxcell sl status */
|
||||
typedef enum {
|
||||
bx_uninit = 0, /* sl is not initialised */
|
||||
bx_filled = 1, /* sl has been filled with initial fwd cell vertexes */
|
||||
bx_rethinnd = 2, /* sl vertexes need to be re-thinned */
|
||||
bx_thinned = 3, /* sl vertexes have been thinned */
|
||||
bx_conv = 4 /* sl vertexes have been converted to fwd cell indexes */
|
||||
} bxstat;
|
||||
|
||||
/* Structure to hold bwd cell information for surface list, and also */
|
||||
/* for seed fill bwd cell propogation. (Cells on surface will have two */
|
||||
/* of these) */
|
||||
struct _bxcell{
|
||||
int ix; /* nnrev[] index of this bwd cell */
|
||||
int gc[MXRO]; /* coordinate of this bwd cell */
|
||||
nn_grp g; /* Group nn calculation info */
|
||||
struct _bxcell *ss; /* bwd surface cell to start search from */
|
||||
double sdist; /* Est. wtd distance from this cell to ss */
|
||||
int tix; /* target rev[] index being filled (visited check) */
|
||||
|
||||
bxstat status; /* State of sl list */
|
||||
int *sl; /* fwd vertex seed list for surface bxcells */
|
||||
/* or cell list after conversion to cells */
|
||||
int *dl; /* deleted fwd vertex list for this bxcell */
|
||||
|
||||
int *scell; /* If non-NULL, this is a (non-surface) */
|
||||
/* seeding super bxcell, and scell contains */
|
||||
/* the list of bxcells covered */
|
||||
|
||||
struct _bxcell *slist; /* Linked list of all surface bxcells */
|
||||
struct _bxcell *hlink; /* Linked list of surface bxcells with same ix hash */
|
||||
struct _bxcell *xlist; /* Linked list of surface exploration search region */
|
||||
double emin; /* estimated minimum wtd distance of this cell in current search */
|
||||
struct _bxcell *tlist; /* Linked list of solution surface cells for current search. */
|
||||
|
||||
struct _bxcell *flist; /* Linked list for nnrev[] fill seeds */
|
||||
|
||||
double cc; /* Distance of group from gamut center */
|
||||
double dw; /* Delta width from ocent of furthest point */
|
||||
struct _bxcell *wlist; /* Linked list for shadow bxcells during thinning */
|
||||
|
||||
int debug; /* debug flag - for VRML tagging */
|
||||
}; typedef struct _bxcell bxcell;
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
|
||||
/* Enough space is needed to cache all the fxcells/simplexes */
|
||||
/* for a full aux. locus, or the query will be processed in */
|
||||
/* several "chunks" and will be slower. */
|
||||
/* This sets the basic memory usage of the rev code. */
|
||||
|
||||
#define REV_ACC_GRES_MUL 2.0 /* 2.0 Reverse accelleration grid resolution */
|
||||
/* multiplier over fwd grid resolution */
|
||||
#define REV_ACC_GRES_LIMIT 43 /* Reverse accelln. grid resolution limit before env. mult. */
|
||||
#define REV_MAX_MEM_RATIO 0.3 /* 0.3 Proportion of first 1G of Ram to use */
|
||||
#define REV_MAX_MEM_RATIO2 0.4 /* 0.4 Proportion of rest of Ram to use */
|
||||
/* rev as a fraction of the System RAM. */
|
||||
#define HASH_FILL_RATIO 3 /* 3 Ratio of entries to hash size */
|
||||
|
||||
/* The structure where fxcells and simplexes are allocated and cached. */
|
||||
|
||||
/* Holds the fxcell and simplex match cache specific information */
|
||||
typedef struct {
|
||||
struct _rspl *s; /* Pointer to parent rspl */
|
||||
int nacells; /* Number of allocated cells */
|
||||
int nunlocked; /* Number of unlocked cells that could be freed */
|
||||
int cell_hash_size; /* Current size of cell hash list */
|
||||
fxcell **hashtop; /* Top of hash list [cell_hash_size] */
|
||||
fxcell *mrutop, *mrubot; /* Top and bottom pointers of mru list */
|
||||
/* that tracks allocated fxcells */
|
||||
|
||||
int spx_hash_size; /* Current size of shared face simplex hash list */
|
||||
simplex **spxhashtop; /* Shared face simplex hash index list */
|
||||
int nspx; /* Number of simplexes in hash list */
|
||||
} revcache;
|
||||
|
||||
/* common search information */
|
||||
/* Type of (internal) reverse search */
|
||||
enum ops {
|
||||
exact = 0, /* Search for all input values that exactly map to given output value */
|
||||
clipv = 1, /* Search for input values that map to outermost solution along a vector */
|
||||
clipn = 2, /* Search for input values that map to closest solution */
|
||||
auxil = 3, /* Search for input values that map to given output, and closest to auxiliary target */
|
||||
locus = 4 }; /* Return range of auxiliary values that contains solution */
|
||||
|
||||
/* + possible exact with clip */
|
||||
|
||||
/* Structure to hold clip line state information */
|
||||
typedef struct {
|
||||
struct _rspl *s; /* Pointer to parent rspl */
|
||||
double st[MXRO]; /* start of line - reverse grid base value */
|
||||
double de[MXRO]; /* direction of line */
|
||||
int di[MXRO]; /* incerement in line direction */
|
||||
int ci[MXRO]; /* current rev grid coordinate */
|
||||
double t; /* Parameter 0.0 - 1.0, line finished if t > 1.0 */
|
||||
} line;
|
||||
|
||||
|
||||
/* Structure to hold aux value of an intersection of a */
|
||||
/* solution locus with a sub-simplex. Used when asegs flag is set */
|
||||
typedef struct {
|
||||
double xval; /* Auxiliary value */
|
||||
int nv; /* Number of vertices valid */
|
||||
int vix[MXRI+1]; /* Verticy indexes of sub-simplex involved */
|
||||
} axisec;
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Information needed/cached for reverse lookup */
|
||||
struct _schbase {
|
||||
struct _rspl *s; /* Pointer to parent rspl */
|
||||
|
||||
int flags; /* Hint flags */
|
||||
enum ops op; /* Type of reverse search operation */
|
||||
int ixc; /* Cube index of corner that holds maximum input values */
|
||||
|
||||
int snsdi, ensdi; /* Start and end extra sub-simplex dimensionality */
|
||||
int (*setsort)(struct _schbase *b, fxcell *c); /* Function to triage & set cube sort index */
|
||||
int (*check)(struct _schbase *b, fxcell *c); /* Function to recheck cube worth keeping */
|
||||
int (*compute)(struct _schbase *b, simplex *x); /* Function to compute a simplex solution */
|
||||
|
||||
double v[MXRO+1]; /* Target output value, + ink limit */
|
||||
double av[MXRI]; /* Target auxiliary values */
|
||||
int auxm[MXRI]; /* aux mask flags */
|
||||
unsigned auxbm; /* aux bitmap mask */
|
||||
int naux; /* Number of auxiliary target input values */
|
||||
int auxi[MXRI]; /* aux list of auxiliary target input values */
|
||||
double idist; /* best input distance auxiliary target found (smaller is better) */
|
||||
int iabove; /* Number of auxiliaries at or above zero */
|
||||
|
||||
int canvecclip; /* Non-zero if vector clip direction usable */
|
||||
double cdir[MXRO]; /* Clip vector direction and length wrt. v[] */
|
||||
double ncdir[MXRO]; /* Normalised clip vector */
|
||||
double **cla; /* Clip vector LHS implicit equation matrix [fdi][fdi+1] (inc. ink tgt.) */
|
||||
double clb[MXRO+1]; /* Clip vector RHS implicit equation vector [fdi+1] (inc. ink tgt.) */
|
||||
double cdist; /* Best clip locus distance found (aim is min +ve) :- weighted for nn */
|
||||
int iclip; /* NZ if result is above (disabled) ink limit */
|
||||
|
||||
int mxsoln; /* Maximum number of solutions that we want */
|
||||
int nsoln; /* Current number of solutions found */
|
||||
co *cpp; /* Store solutions here */
|
||||
|
||||
int lxi; /* Locus search axiliary index */
|
||||
double min, max; /* current extreme locus values for locus search */
|
||||
int asegs; /* flag - find all search segments */
|
||||
int axisln; /* Number of elements used in axisl[] */
|
||||
int axislz; /* Space allocated to axisl[] */
|
||||
axisec *axisl; /* Auxiliary intersections */
|
||||
|
||||
int lclistz; /* Allocated space to fxcell sort list */
|
||||
fxcell **lclist; /* Sorted list of pointers to candidate fxcells */
|
||||
|
||||
int pauxcell; /* Indexe of previous call solution fxcell, -1 if not relevant */
|
||||
int plmaxcell; /* Indexe of previous call solution fxcell, -1 if not relevant */
|
||||
int plmincell; /* Indexe of previous call solution fxcell, -1 if not relevant */
|
||||
|
||||
int lsxfilt; /* Allocated space of simplex filter list */
|
||||
char *sxfilt; /* Flag for simplexes that should be in an fxcell */
|
||||
|
||||
int rix; /* Diagnostic - rev[] or nnrev[] index for this point */
|
||||
|
||||
}; typedef struct _schbase schbase;
|
||||
|
||||
/* ----------------------------------------- */
|
||||
|
||||
#ifdef STATS
|
||||
struct _stats {
|
||||
int searchcalls;/* Number of top level searches */
|
||||
int csearched; /* Cells searched */
|
||||
int ssearched; /* Simplexes searched */
|
||||
int sinited; /* Simplexes initialised to base level */
|
||||
int sinited2a; /* Simplexes initialised to 2nd level with LU */
|
||||
int sinited2b; /* Simplexes initialised to 2nd level with SVD */
|
||||
int sinited4i; /* Simplexes invalidated at 4th level */
|
||||
int sinited4; /* Simplexes initialised to 4th level */
|
||||
int sinited5i; /* Simplexes invalidated at 5th level */
|
||||
int sinited5a; /* Simplexes initialised to 5th level with LU */
|
||||
int sinited5b; /* Simplexes initialised to 5th level with SVD */
|
||||
int chits; /* Cells hit in cache */
|
||||
int cmiss; /* Cells misses in cache */
|
||||
}; typedef struct _stats stats;
|
||||
#endif /* STATS */
|
||||
|
||||
/* ----------------------------------------- */
|
||||
/* Reverse info stored in main rspl function */
|
||||
struct _rev_struct {
|
||||
|
||||
/* First section, basic information that doesn't change */
|
||||
/* Has been initialised if inited != 0 */
|
||||
|
||||
int inited; /* Non-zero if first section has been initialised */
|
||||
/* All other sections depend on this. */
|
||||
int fastsetup; /* Flag - NZ if fast setup at cost of slow throughput */
|
||||
|
||||
int probxyz; /* Flag - NZ - guess if XYZ for VRML diagnostics use */
|
||||
|
||||
int lchweighted; /* Non-zero if nearest search is LCh weighted */
|
||||
double lchw[MXRO]; /* LCh nearest weighting */
|
||||
double lchw_sq[MXRO]; /* LCh nearest weighting squared */
|
||||
double lchw_chsq; /* lchw_sq[1] - lchw_sq[2] */
|
||||
|
||||
struct _rev_struct *next; /* Linked list of global instances sharing memory */
|
||||
size_t max_sz; /* Maximum size permitted */
|
||||
size_t sz; /* Total memory current allocated by rev */
|
||||
|
||||
#ifdef NEVER
|
||||
int thissz, lastsz; /* Debug reporting */
|
||||
#endif
|
||||
|
||||
/* Reverse grid lookup information */
|
||||
int res; /* Reverse grid resolution == ncells on a side */
|
||||
int no; /* Total number of points in reverse grid = rev.ares ^ fdi */
|
||||
int coi[MXRO]; /* Coordinate increments for each dimension */
|
||||
int hoi[1 << MXRO]; /* Coordinate increments for progress through cube */
|
||||
datao gl,gh,gw; /* Reverse grid low, high, grid bwd cell width */
|
||||
|
||||
/* Second section, accelleration information that changes with ink limit. */
|
||||
int rev_valid; /* nz if this information in rev[] and nnrev[] is valid */
|
||||
int **rev; /* Exact reverse lookup starting list. */
|
||||
int **nnrev; /* Nearest reverse lookup starting list. */
|
||||
/* These lists are of fwd grid base indexes. */
|
||||
/* [0] is allocation length */
|
||||
/* [1] is the next free entry index (length + 3, not counting -1) */
|
||||
/* [2] is index into share lists, -1 if not shared. */
|
||||
/* Then follows cube indexes */
|
||||
/* Last entry is marked with -1 */
|
||||
|
||||
double ocent[MXRO]; /* rev cell gamut "center" point for thinning and shadow testing. */
|
||||
|
||||
int surflin_en; /* Flag set when suflin is enabled */
|
||||
struct _rspl *surflin; /* gamut surface linearization transform used by logcomp() */
|
||||
double linoff[MXRO]; /* ocent offset after surflin mapping */
|
||||
|
||||
bxcell *surflist; /* Linked list of rev[] bwd cells that contain gamut surface fwd cells. */
|
||||
/* Used to speed up fill_nncell() when rev.fastsetup is set, else NULL */
|
||||
int surf_hash_size; /* Current size of bxcell hash list */
|
||||
bxcell **surfhash; /* bxcell hash index list */
|
||||
|
||||
int **sharelist; /* Array of pointers to shared (fwd grid list sharer) records. */
|
||||
/* Each record is same format as rev[]/nnrev[], except */
|
||||
/* [2] is used to detect scanning the same list. */
|
||||
int sharellen; /* Size of sharelist */
|
||||
int sharelaloc; /* Allocation size of sharelist */
|
||||
|
||||
/* Third section */
|
||||
revcache *cache; /* Where fxcells and simplexes are allocated and cached */
|
||||
/* Sub-dimension simplex information */
|
||||
ssxinfo sspxi[MXRI+1];/* One per sub dimenstionality at offset sdi */
|
||||
|
||||
/* Fourth section */
|
||||
/* Has been initialise if sb != NULL */
|
||||
schbase *sb; /* Structure holding calculated per-search call information */
|
||||
|
||||
unsigned int stouch; /* Simplex touch count to avoid searching shared simplexs twice */
|
||||
#ifdef STATS
|
||||
stats st[5]; /* Set of stats info indexed by enum ops */
|
||||
#endif /* STATS */
|
||||
|
||||
int primsecwarn; /* Not primary or secondary warning has been issued */
|
||||
|
||||
#ifdef CHECK_NNLU
|
||||
int cknn_no; /* Number checked */
|
||||
double cknn_we; /* Worst DE */
|
||||
int cknn_noerrs; /* Number not as good as closet vertex */
|
||||
int cknn_nobsb; /* Number not as good as second closest vertex */
|
||||
int cknn_nonis; /* Number not in surface */
|
||||
#endif /* CHECK_NNLU */
|
||||
|
||||
}; typedef struct _rev_struct rev_struct;
|
||||
|
||||
|
||||
/* ------------------------------------ */
|
||||
/* Utility functions used by other parts of rspl implementation */
|
||||
|
||||
/* Initialise a static sub-simplex verticy information table */
|
||||
void rspl_init_ssimplex_info(struct _rspl *s, /* RSPL object */
|
||||
ssxinfo *xip, /* Pointer to sub-simplex info structure to init. */
|
||||
int sdi); /* Sub-simplex dimensionality (range 0 - di) */
|
||||
|
||||
/* Free the given sub-simplex verticy information */
|
||||
void rspl_free_ssimplex_info(struct _rspl *s,
|
||||
ssxinfo *xip); /* Pointer to sub-simplex info structure */
|
||||
|
||||
#endif /* RSPL_REV_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
311
Argyll_V3.5.0/rspl/revbench.c
Normal file
311
Argyll_V3.5.0/rspl/revbench.c
Normal file
@@ -0,0 +1,311 @@
|
||||
|
||||
/************************************************/
|
||||
/* Benchmark RSPL reverse lookup */
|
||||
/************************************************/
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 31/10/96
|
||||
* Derived from tnd.c
|
||||
* Copyright 1999 - 2000 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "copyright.h"
|
||||
#include "aconfig.h"
|
||||
#include "rspl.h"
|
||||
#include "numlib.h"
|
||||
//#include "ui.h"
|
||||
|
||||
#undef DOLIMIT /* Define to have ink limit */
|
||||
#define LIMITVAL 2.5 /* Total ink limit sum */
|
||||
#undef DOCHECK
|
||||
#define TESTNN /* Test Nearest Clipping */
|
||||
|
||||
#define SHOW_OUTPUT /* Define for printf on each conversion */
|
||||
|
||||
/* 11, 19 give about 60 seconds */
|
||||
#define GRES 17 /* Default grid resolution */
|
||||
#define RRES 43 /* Default reverse test resolution */
|
||||
#define DI 4 /* Dimensions in */
|
||||
#define FDI 3 /* Function (out) Dimensions */
|
||||
#define NIP 10 /* Number of solutions allowed */
|
||||
|
||||
#define flimit(vv) ((vv) < 0.0 ? 0.0 : ((vv) > 1.0 ? 1.0 : (vv)))
|
||||
#define fmin(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define fmin3(a,b,c) (fmin((a), fmin((b),(c))))
|
||||
#define fmax(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define fmax3(a,b,c) (fmax((a), fmax((b),(c))))
|
||||
|
||||
/* Fwd function approximated by rspl */
|
||||
/* Dummy cmyk->rgb conversion. This simulates our device */
|
||||
void func(
|
||||
void *cbctx,
|
||||
double *out,
|
||||
double *in) {
|
||||
double kk;
|
||||
double ci = in[0];
|
||||
double mi = in[1];
|
||||
double yi = in[2];
|
||||
double ki = in[3];
|
||||
double r,g,b;
|
||||
|
||||
ci += ki; /* Add black back in */
|
||||
mi += ki;
|
||||
yi += ki;
|
||||
kk = fmax3(ci,mi,yi);
|
||||
if (kk > 1.0) {
|
||||
ci /= kk;
|
||||
mi /= kk;
|
||||
yi /= kk;
|
||||
}
|
||||
r = 1.0 - ci;
|
||||
g = 1.0 - mi;
|
||||
b = 1.0 - yi;
|
||||
out[0] = flimit(r);
|
||||
out[1] = flimit(g);
|
||||
out[2] = flimit(b);
|
||||
}
|
||||
|
||||
/* Simplex ink limit function */
|
||||
double limitf(
|
||||
void *lcntx,
|
||||
float *in
|
||||
) {
|
||||
int i;
|
||||
double ov;
|
||||
|
||||
for (ov = 0.0, i = 0; i < DI; i++) {
|
||||
ov += in[i];
|
||||
}
|
||||
return ov;
|
||||
}
|
||||
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Benchmark rspl reverse, Version %s\n",ARGYLL_VERSION_STR);
|
||||
fprintf(stderr,"usage: revbench [-f fwdres] [-r revres] [-v level] iccin iccout\n");
|
||||
fprintf(stderr," -v Verbose\n");
|
||||
fprintf(stderr," -f res Set forward grid res\n");
|
||||
fprintf(stderr," -r res Set reverse test res\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
int clutres = GRES;
|
||||
int rres = RRES;
|
||||
int verb = 0;
|
||||
int gres[MXDI];
|
||||
int e;
|
||||
|
||||
clock_t stime,ttime;
|
||||
rspl *rss; /* Multi-resolution regularized spline structure */
|
||||
|
||||
error_program = argv[0];
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* Verbosity */
|
||||
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
|
||||
verb = 1;
|
||||
}
|
||||
else if (argv[fa][1] == 'f' || argv[fa][1] == 'F') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
clutres = atoi(na);
|
||||
}
|
||||
else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
rres = atoi(na);
|
||||
}
|
||||
else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Started benchmark\n");
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, DI, FDI);
|
||||
|
||||
for (e = 0; e < DI; e++)
|
||||
gres[e] = clutres;
|
||||
|
||||
printf("Rspl allocated\n");
|
||||
rss->set_rspl(rss, 0, (void *)NULL, func,
|
||||
NULL, NULL, gres, NULL, NULL);
|
||||
|
||||
printf("Rspl set\n");
|
||||
|
||||
/* Start exploring the reverse test grid */
|
||||
{
|
||||
int ops = 0;
|
||||
double secs;
|
||||
rpsh counter;
|
||||
unsigned rcount;
|
||||
int ii[10];
|
||||
int f, rgres[MXDO];
|
||||
|
||||
int flags = 0; /* rev hint flags */
|
||||
co tp[NIP]; /* Test point */
|
||||
double cvec[4]; /* Text clip vector */
|
||||
int auxm[4]; /* Auxiliary target value valid flag */
|
||||
#ifdef DOCHECK
|
||||
int j;
|
||||
#endif
|
||||
#ifdef NEVER
|
||||
double lmin[4], lmax[4]; /* Locus min/max values */
|
||||
#endif
|
||||
|
||||
#ifdef DOCHECK
|
||||
char *check; /* Check that we hit every cell */
|
||||
#endif /* DOCHECK */
|
||||
|
||||
/* Set auxiliary target mask */
|
||||
auxm[0] = 0;
|
||||
auxm[1] = 0;
|
||||
auxm[2] = 0;
|
||||
auxm[3] = 1;
|
||||
|
||||
#ifdef DOLIMIT
|
||||
rss->rev_set_limit(rss,
|
||||
limitf,
|
||||
NULL,
|
||||
LIMITVAL /* limit maximum value */
|
||||
);
|
||||
#endif /* DOLIMIT */
|
||||
|
||||
printf("Forward resolution %d\n",clutres);
|
||||
printf("Reverse resolution %d\n",rres);
|
||||
|
||||
#ifdef DOCHECK
|
||||
if ((check = (char *)calloc(1, rcount)) == NULL)
|
||||
error("Malloc of check array\n");
|
||||
#endif /* DOCHECK */
|
||||
|
||||
for (f = 0; f < FDI; f++)
|
||||
rgres[f] = rres;
|
||||
|
||||
rcount = rpsh_init(&counter, FDI, (unsigned int *)rgres, ii); /* Initialise counter */
|
||||
|
||||
stime = clock();
|
||||
|
||||
#ifdef TESTNN
|
||||
flags |= RSPL_NEARCLIP;
|
||||
#endif
|
||||
/* Itterate though the grid */
|
||||
for (ops = 0;; ops++) {
|
||||
int r;
|
||||
int e; /* Table index */
|
||||
|
||||
#ifdef DOCHECK
|
||||
check[((ii[2] * rres + ii[1]) * rres) + ii[0]] = 1;
|
||||
#endif /* DOCHECK */
|
||||
|
||||
for (e = 0; e < FDI; e++) { /* Input tables */
|
||||
tp[0].v[e] = ii[e]/(rres-1.0); /* Vertex coordinates */
|
||||
}
|
||||
|
||||
if (verb)
|
||||
printf("Input = %f %f %f\n",tp[0].v[0], tp[0].v[1], tp[0].v[2]);
|
||||
|
||||
#ifdef NEVER /* Do locus lookup explicitly ? */
|
||||
/* Lookup the locus for the auxiliary (Black) chanel */
|
||||
if ((r = rss->rev_locus(rss,
|
||||
auxm, /* auxm Auxiliary mask flags */
|
||||
tp, /* Input and auxiliary values */
|
||||
lmin, /* Locus min/max return values */
|
||||
lmax
|
||||
)) == 0) {
|
||||
/* Rev locus failed - means that it will clip ? */
|
||||
tp[0].p[3] = 0.5;
|
||||
flags = RSPL_WILLCLIP; /* Since there was no locus, we expect to clip */
|
||||
} else {
|
||||
/* Set the auxiliary target */
|
||||
tp[0].p[3] = (lmin[3] + lmax[3])/2.0;
|
||||
flags = RSPL_EXACTAUX; /* Since we got locus, expect exact auxiliary match */
|
||||
}
|
||||
#else
|
||||
tp[0].p[3] = 0.5;
|
||||
flags = RSPL_AUXLOCUS; /* Auxiliary target is proportion of locus */
|
||||
#endif /* NEVER */
|
||||
|
||||
/* Clip vector to 0.5 */
|
||||
cvec[0] = 0.5 - tp[0].v[0];
|
||||
cvec[1] = 0.5 - tp[0].v[1];
|
||||
cvec[2] = 0.5 - tp[0].v[2];
|
||||
cvec[3] = 0.5 - tp[0].v[3];
|
||||
|
||||
/* Do reverse interpolation */
|
||||
if ((r = rss->rev_interp(rss,
|
||||
flags, /* Hint flags */
|
||||
NIP, /* Number of solutions allowed */
|
||||
auxm, /* auxm Auxiliary mask flags */
|
||||
cvec, /* cvec Clip vector direction & length */
|
||||
tp) /* Input and output values */
|
||||
) == 0) {
|
||||
error("rev_interp failed\n");
|
||||
}
|
||||
|
||||
r &= RSPL_NOSOLNS; /* Get number of solutions */
|
||||
|
||||
if (verb)
|
||||
printf("Output 1 of %d: %f, %f, %f, %f%s\n",
|
||||
r & RSPL_NOSOLNS, tp[0].p[0], tp[0].p[1], tp[0].p[2], tp[0].p[3],
|
||||
(r & RSPL_DIDCLIP) ? " [Clipped]" : "");
|
||||
|
||||
|
||||
if (rpsh_inc(&counter, ii))
|
||||
break;
|
||||
|
||||
} /* Next grid point */
|
||||
|
||||
ttime = clock() - stime;
|
||||
secs = (double)ttime/CLOCKS_PER_SEC;
|
||||
printf("Done - %d ops in %f seconds, rate = %f ops/sec\n",ops, secs,ops/secs);
|
||||
#ifdef DOCHECK
|
||||
for (j = 0; j < rcount; j++) {
|
||||
if (check[j] != 1) {
|
||||
printf("~~CHeck error at %d\n",j);
|
||||
}
|
||||
}
|
||||
#endif /* DOCHECK */
|
||||
}
|
||||
|
||||
rss->del(rss);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1686
Argyll_V3.5.0/rspl/rspl.c
Normal file
1686
Argyll_V3.5.0/rspl/rspl.c
Normal file
File diff suppressed because it is too large
Load Diff
681
Argyll_V3.5.0/rspl/rspl.h
Normal file
681
Argyll_V3.5.0/rspl/rspl.h
Normal file
@@ -0,0 +1,681 @@
|
||||
#ifndef RSPL_H
|
||||
#define RSPL_H
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional regularized spline data structure
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2000/10/29
|
||||
*
|
||||
* Copyright 1996 - 2004 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#include "numsup.h"
|
||||
|
||||
/** Configuration **/
|
||||
|
||||
#undef CHECK_NNLU /* [und] Check nn lookup results against exaustive searches */
|
||||
/* as well as other asserts. */
|
||||
|
||||
/** General Limits **/
|
||||
|
||||
#define MXDI 10 /* Maximum input dimensionality */
|
||||
#define MXDO 10 /* Maximum output dimensionality (Is not fully tested!!!) */
|
||||
#define LOG2MXDI 4 /* log2 MXDI */
|
||||
#define DEF2MXDI 16 /* Default allocation size for 2^di (di=4) */
|
||||
#define POW2MXDI 1024 /* 2 ^ MXDI */
|
||||
#define DEF3MXDI 81 /* Default allocation size for 3^di (di=4) */
|
||||
#define POW3MXDI 59049 /* 3 ^ MXDI */
|
||||
#define HACOMPS ((POW3MXDI + 2 * MXDI + 1)/2) /* Maximum number of array components */
|
||||
/* 295255 - not used ? */
|
||||
|
||||
#if MXDI > MXDO /* Maximum of either DI or DO */
|
||||
# define MXDIDO MXDI
|
||||
#else
|
||||
# define MXDIDO MXDO
|
||||
#endif
|
||||
|
||||
/* RESTRICTED SIZE Limits, used for reverse and spline */
|
||||
|
||||
#define MXRI 4 /* Maximum input dimensionality */
|
||||
#define MXRO 10 /* Maximum output dimensionality (Is not fully tested!!!) */
|
||||
#define LOG2MXRI 2 /* log2 MXRI */
|
||||
#define POW2MXRI 16 /* 2 ^ MXRI */
|
||||
#define POW3MXRI 81 /* 3 ^ MXRI */
|
||||
#define POW2MXRO 1024 /* 2 ^ MXRO */
|
||||
|
||||
#if MXRI > MXRO /* Maximum of either RI or RO */
|
||||
# define MXRIRO MXRI
|
||||
#else
|
||||
# define MXRIRO MXRO
|
||||
#endif
|
||||
|
||||
|
||||
/** Definitions **/
|
||||
|
||||
/* General data point position/value structure */
|
||||
/* This is mean't to be compatible with color structure */
|
||||
/* when MXDI and MXDO == 4 */
|
||||
typedef double datai[MXDI];
|
||||
typedef double datao[MXDO];
|
||||
typedef float dati[MXDI];
|
||||
typedef float dato[MXDO];
|
||||
|
||||
/* Restricted size versions */
|
||||
typedef double ratai[MXRI];
|
||||
typedef double ratao[MXRO];
|
||||
typedef float rati[MXRI];
|
||||
typedef float rato[MXRO];
|
||||
|
||||
/* Interface coordinate value */
|
||||
typedef struct {
|
||||
double p[MXDI]; /* coordinate position */
|
||||
double v[MXDO]; /* function values */
|
||||
} co;
|
||||
|
||||
/* Interface coordinate value + weighting */
|
||||
typedef struct {
|
||||
double p[MXDI]; /* coordinate position */
|
||||
double v[MXDO]; /* function values */
|
||||
double w; /* Weight to give this point, nominally 1.0 */
|
||||
} cow;
|
||||
|
||||
/* Interface coordinate value + per out component weighting */
|
||||
typedef struct {
|
||||
double p[MXDI]; /* coordinate position */
|
||||
double v[MXDO]; /* function values */
|
||||
double w[MXDO]; /* Weight to give this point, nominally 1.0 */
|
||||
} coww;
|
||||
|
||||
/* Scattered data Per data point data (internal) */
|
||||
struct _rpnts {
|
||||
double p[MXDI]; /* Data position [di] */
|
||||
double v[MXDO]; /* Data value [fdi] */
|
||||
double k[MXDO]; /* Weight factor (nominally 1.0, less for lower confidence data point) */
|
||||
// double fe; /* Fit error in output pass (ausm) */
|
||||
}; typedef struct _rpnts rpnts;
|
||||
|
||||
/* Hermite interpolation magic data */
|
||||
typedef struct {
|
||||
int p; /* The parameter power combination */
|
||||
int i; /* The surrounding cube vertex index */
|
||||
int j; /* The dimension combination */
|
||||
float wgt;
|
||||
} magic_data;
|
||||
|
||||
#include "rev.h" /* Reverse interpolation defintions */
|
||||
#include "gam.h" /* Gamut defintions */
|
||||
|
||||
/* Sub-fit itteration information */
|
||||
typedef struct {
|
||||
int niters; /* Number of multigrid itterations needed */
|
||||
int **ires; /* Resolution for each itteration and dimension */
|
||||
void **mgtmps[MXDO]; /* Store pointers to re-usable mgtmp when incremental */
|
||||
/* (These don't seem to be used anymore. was incremental removed ?) */
|
||||
} it_info;
|
||||
|
||||
/* Structure for final resolution multi-dimensional regularized spline data */
|
||||
struct _rspl {
|
||||
|
||||
/* Global rspl state */
|
||||
int debug; /* 0 = no debug */
|
||||
int verbose; /* 0 = no verbose */
|
||||
double smooth; /* Smoothness factor */
|
||||
double avgdev[MXDO];
|
||||
/* Average Deviation of function values as proportion of function range. */
|
||||
int symdom; /* 0 = non-symetric smoothness with different grid resolutions, */
|
||||
/* 1 = symetric smoothness with different grid resolutions, */
|
||||
|
||||
int di; /* Input dimensionality */
|
||||
int fdi; /* Output function dimensionality */
|
||||
|
||||
/* Weak default function related information */
|
||||
double weak; /* Weak total weighting, nominal = 1.0 */
|
||||
void *dfctx; /* Opaque function context */
|
||||
void (*dfunc)(void *cbntx, double *out, double *in);
|
||||
/* Function to set from */
|
||||
|
||||
/* Scattered Data point related information */
|
||||
int ausm; /* Automatic smoothing enabled flag. */
|
||||
struct {
|
||||
int no; /* Number of data points in array */
|
||||
rpnts *a; /* Array of data points */
|
||||
datao vl, vw; /* Data value low/width - not used */
|
||||
datao va; /* Data value averages */
|
||||
// double fea; /* Fit error average */
|
||||
} d;
|
||||
|
||||
it_info ii; /* Main itteration information for final rspl */
|
||||
|
||||
it_info as_ii; /* Automatic smoothing pre-fit itteration info */
|
||||
it_info asm_ii; /* Automatic smoothing map itteration info */
|
||||
|
||||
/* Grid points data */
|
||||
struct {
|
||||
int res[MXDI]; /* Single dimension grid resolution for each axis */
|
||||
int bres, brix; /* Biggest resolution and its index */
|
||||
double mres; /* Geometric mean res[] */
|
||||
int no; /* Total number of points in grid = res[0] * res[1] * .. res[di-1] */
|
||||
datai l,h,w; /* Grid low, high, grid cell width */
|
||||
/* This is used to map from the input domain to the grid */
|
||||
|
||||
datao fmin, fmax; /* Min & max values of grid output (function) variables */
|
||||
int fminx[MXDO], fmaxx[MXDO]; /* Grid indexes of points that set min/max output values */
|
||||
double fscale; /* Overall magnitude of output values */
|
||||
double *ipos[MXDI]; /* Optional relative grid cell position for each input dim cell, */
|
||||
/* gres[] entries per dimension. Allows for the possibility of */
|
||||
/* a non-uniform grid spacing, by adjusting the curvature evaluation */
|
||||
/* appropriately. */
|
||||
int fminmax_valid; /* Min/max/scale cached values valid flag. */
|
||||
int limitv_cached; /* Flag: Ink limit values have been set in the grid array */
|
||||
|
||||
#define G_XTRA 3 /* Extra floats per grid point */
|
||||
float *alloc; /* Grid points allocated address */
|
||||
float *a; /* Grid point flags + data */
|
||||
/* Array is res[] ^ di entries float[fdi+G_XTRA], offset by G_XTRA */
|
||||
/* (But is expanded when spline interpolaton is active) */
|
||||
/* float[-1] contains the ink limit function value, L_UNINIT if not initd */
|
||||
/* float[-2] contains the edge flag values, 3 bits per in dim. */
|
||||
/* float[-3] contains the touched flag generation count. */
|
||||
/* (k value for non-linear fit would be another entry.) */
|
||||
/* Flag values are 3 bits for each dimension. Bits 1,0 form */
|
||||
/* 2 bit distance from edge: 0 for on edge of grid, */
|
||||
/* 1 for next row, 2 for 3rd row and beyond. If bit 2 is set, */
|
||||
/* then we are on the lower edge. This limits di to 10 or less, */
|
||||
/* with the two MS bits spare. */
|
||||
int pss; /* Grid point structure size = fdi+G_XTRA */
|
||||
|
||||
/* Uninitialised limit value */
|
||||
#define L_UNINIT ((float)-1e38)
|
||||
|
||||
#define FL_BITS 3 /* flag bits per dimension */
|
||||
/* Macros to access flags. Arguments are a pointer to base grid point and */
|
||||
/* Flag value is distance from edge in bottom 2 bits, values 0, 1 or 2 maximum. */
|
||||
/* bit 2 is set if the distance is to the lower edge. ie: */
|
||||
/* 0 = at top edge */
|
||||
/* 1 = next to top edge */
|
||||
/* 2, 6 = not at or next to any edge */
|
||||
/* 4 = at bottom edge */
|
||||
/* 5 = next to bottom edge */
|
||||
#define FLV(fp) (*((unsigned int *)((fp)-2)))
|
||||
/* Init the flag values to 0 */
|
||||
#define I_FL(fp) (FLV(fp) = 0)
|
||||
/* Return 3 bit flag data */
|
||||
#define G_FL(fp,di) ((FLV(fp) >> (3 * (di))) & 7)
|
||||
/* Set 3 bit flag data */
|
||||
#define S_FL(fp,di,v) (FLV(fp) = (FLV(fp) & ~(7 << (3 * (di)))) | (((v) & 7) << (3 * (di))))
|
||||
|
||||
/* Macro to access touched flag. Arguments are a pointer to base grid point. */
|
||||
#define TOUCHF(fp) (*((unsigned int *)((fp)-3)))
|
||||
|
||||
/* Grid array offset lookups - in floats */
|
||||
int ci[MXDI]; /* Grid coordinate increments for each dimension */
|
||||
int fci[MXDI]; /* Grid coordinate increments for each dimension in floats */
|
||||
int *hi; /* 2^di Combination offset for sequence through cube. */
|
||||
int a_hi[DEF2MXDI]; /* Default allocation for *hi */
|
||||
int *fhi; /* Combination offset for sequence through cube of */
|
||||
/* 2^di points, starting at base, in floats */
|
||||
int a_fhi[DEF2MXDI];/* Default allocation for *hi */
|
||||
|
||||
unsigned int touch; /* Cell touched flag count */
|
||||
} g;
|
||||
|
||||
|
||||
/* Ink limit related information */
|
||||
int limiten; /* Flag - limiting is enabled */
|
||||
double (*limitf)(void *cntx, double *in); /* Optional input space qualifier function. */
|
||||
void *lcntx; /* Context passed to limit() */
|
||||
double limitv; /* Value not to be exceeded by limit() */
|
||||
|
||||
/* Hermite spline interpolation support */
|
||||
struct {
|
||||
magic_data *magic; /* Magic matrix - non-zero elements only, Non-NULL if splining */
|
||||
int nm; /* number in magic data list */
|
||||
int spline; /* Non-zero if spline data is present in g.a */
|
||||
/* Changes from float g.a[res ^ di][fdi+G_XTRA], offset by G_XTRA, */
|
||||
/* to float g.a[res ^ di][(2^di * fdi)+G_XTRA], offset by G_XTRA, */
|
||||
} spline;
|
||||
|
||||
/* Gamut support */
|
||||
gam_struct gam; /* See gam.h */
|
||||
|
||||
/* Reverse Interpolation support */
|
||||
rev_struct rev; /* See rev.h */
|
||||
|
||||
/* Methods */
|
||||
|
||||
/* Free ourselves */
|
||||
void (*del)(struct _rspl *ss);
|
||||
|
||||
/* Combination lags used by various functions */
|
||||
#define RSPL_NOFLAGS 0x0000
|
||||
#define RSPL_AUTOSMOOTH 0x0001 /* Automatically determin local optimal avgdev smoothing */
|
||||
#define RSPL_SYMDOMAIN 0x0004 /* Maintain symetric smoothness with nonsym. resolution */
|
||||
#define RSPL_SET_APXLS 0x0020 /* For set_rspl, adjust samples for aproximate least squares */
|
||||
#define RSPL_FASTREVSETUP 0x0010 /* Do a fast reverse setup at the cost of subsequent speed */
|
||||
#define RSPL_VERBOSE 0x8000 /* Turn on print progress messages */
|
||||
#define RSPL_NOVERBOSE 0x4000 /* Turn off print progress messages */
|
||||
|
||||
/* Initialise from scattered data. */
|
||||
/* Return non-zero if result is non-monotonic */
|
||||
int
|
||||
(*fit_rspl)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
co *d, /* Array holding position and function values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double avgdev[MXDO],
|
||||
/* Average Deviation of function values as proportion of function range, */
|
||||
/* typical value 0.005 (aprox. = 0.564 times the standard deviation) */
|
||||
/* NULL = default 0.005 */
|
||||
double *ipos[MXDI] /* Optional relative grid cell position for each input dim cell, */
|
||||
/* gres[] entries per dimension. Used to scale smoothness criteria */
|
||||
);
|
||||
|
||||
/* Initialise from scattered data, with per point weighting. */
|
||||
/* Return non-zero if result is non-monotonic */
|
||||
int
|
||||
(*fit_rspl_w)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
cow *d, /* Array holding position, function and weight values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double avgdev[MXDO],
|
||||
/* Average Deviation of function values as proportion of function range, */
|
||||
/* typical value 0.005 (aprox. = 0.564 times the standard deviation) */
|
||||
/* NULL = default 0.005 */
|
||||
double *ipos[MXDI] /* Optional relative grid cell position for each input dim cell, */
|
||||
/* gres[] entries per dimension. Used to scale smoothness criteria */
|
||||
);
|
||||
|
||||
/* Initialise from scattered data, with per point individual out weighting. */
|
||||
/* Return non-zero if result is non-monotonic */
|
||||
int
|
||||
(*fit_rspl_ww)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
coww *d, /* Array holding position, function and weight values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double avgdev[MXDO],
|
||||
/* Average Deviation of function values as proportion of function range, */
|
||||
/* typical value 0.005 (aprox. = 0.564 times the standard deviation) */
|
||||
/* NULL = default 0.005 */
|
||||
double *ipos[MXDI] /* Optional relative grid cell position for each input dim cell, */
|
||||
/* gres[] entries per dimension. Used to scale smoothness criteria */
|
||||
);
|
||||
|
||||
/* Initialise from scattered data, with weak default function. */
|
||||
/* Return non-zero if result is non-monotonic */
|
||||
int
|
||||
(*fit_rspl_df)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
co *d, /* Array holding position and function values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double avgdev[MXDO],
|
||||
/* Average Deviation of function values as proportion of function range, */
|
||||
/* typical value 0.005 (aprox. = 0.564 times the standard deviation) */
|
||||
/* NULL = default 0.005 */
|
||||
double *ipos[MXDI],/* Optional relative grid cell position for each input dim cell, */
|
||||
/* gres[] entries per dimension. Used to scale smoothness criteria */
|
||||
double weak, /* Weak weighting, nominal = 1.0 */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, double *out, double *in) /* Function to set from */
|
||||
);
|
||||
|
||||
/* Initialise from scattered data, with per point weighting and weak default function. */
|
||||
/* Return non-zero if result is non-monotonic */
|
||||
int
|
||||
(*fit_rspl_w_df)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
cow *d, /* Array holding position, function and weight values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double avgdev[MXDO],
|
||||
/* Average Deviation of function values as proportion of function range, */
|
||||
/* typical value 0.005 (aprox. = 0.564 times the standard deviation) */
|
||||
/* NULL = default 0.005 */
|
||||
double *ipos[MXDI],/* Optional relative grid cell position for each input dim cell, */
|
||||
/* gres[] entries per dimension. Used to scale smoothness criteria */
|
||||
double weak, /* Weak weighting, nominal = 1.0 */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, double *out, double *in) /* Function to set from */
|
||||
);
|
||||
|
||||
/* Initialize the grid from a provided function. By default the grid */
|
||||
/* values are set to exactly the value returned by func(), unless the */
|
||||
/* RSPL_SET_APXLS flag is set, in which case an attempt is made to have */
|
||||
/* the grid points represent a least squares aproximation to the underlying */
|
||||
/* surface. */
|
||||
/* Grid index values are supplied "under" in[] at *((int*)&in[-e-1]) */
|
||||
/* Return non-monotonic status */
|
||||
int
|
||||
(*set_rspl)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, double *out, double *in), /* Function to set from */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh /* Data value high normalize - NULL = default 1.0 */
|
||||
);
|
||||
|
||||
/* Re-set values from a function. Grid index values are supplied */
|
||||
/* "under" in[] at *((int*)&iv[-e-1]) */
|
||||
/* Return non-monotonic status. Clears all the reverse lookup information. */
|
||||
/* It is assumed that the output range remains unchanged. */
|
||||
/* Existing output values are supplied in out[] */
|
||||
int
|
||||
(*re_set_rspl)(
|
||||
struct _rspl *s,/* this */
|
||||
int flags, /* Combination of flags (not used) */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, double *out, double *in) /* Function to set from */
|
||||
);
|
||||
|
||||
/* Scan the rspl grid point locations and values. Grid index values are */
|
||||
/* supplied "under" in[] at *((int*)&iv[-e-1]) */
|
||||
/* Return non-monotonic status. */
|
||||
void
|
||||
(*scan_rspl)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags (not used) */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, double *out, double *in) /* Function that gets given values */
|
||||
);
|
||||
|
||||
/* Tune a single value. */
|
||||
/* Return 0 on success, 1 if input clipping occured, 2 if output clipping occured */
|
||||
int (*tune_value) (
|
||||
struct _rspl *s, /* Pointer to Lut object */
|
||||
co *p /* Target value */
|
||||
);
|
||||
|
||||
/* Set values by multi-grid optimisation using the provided function. */
|
||||
int (*opt_rspl)(
|
||||
struct _rspl *s,/* this */
|
||||
int flags, /* Combination of flags */
|
||||
int tdi, /* Dimensionality of target data */
|
||||
int adi, /* Additional grid point data allowance */
|
||||
double **vdata, /* di^2 array of function, target and additional values to init */
|
||||
/* array corners with. */
|
||||
double (*func)(void *fdata, double *inout, double *surav, int first, double *cw),
|
||||
/* Optimisation function */
|
||||
void *fdata, /* Opaque data needed by function */
|
||||
datai glow, /* Grid low scale - NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution */
|
||||
datao vlow, /* Data value low normalize - NULL = default 0.0 */
|
||||
datao vhigh /* Data value high normalize - NULL = default 1.0 */
|
||||
);
|
||||
|
||||
/* Filter the existing values using the surrounding 3x3 cells. */
|
||||
/* Grid index values are supplied "under" in[] */
|
||||
void
|
||||
(*filter_rspl)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Combination of flags (not used) */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, float **out, double *in, int cvi) /* Function to set from */
|
||||
);
|
||||
|
||||
/* Do forward interpolation */
|
||||
/* Return 0 if OK, 1 if input was clipped to grid */
|
||||
int (*interp)(
|
||||
struct _rspl *s, /* this */
|
||||
co *p); /* Input and output values */
|
||||
|
||||
/* Do forward 1d interpolation of and return the value. */
|
||||
double (*interp1)( /* Return value */
|
||||
struct _rspl *s, /* this */
|
||||
double in); /* Input value */
|
||||
|
||||
/* Do forward (partial) interpolation to allow input & output curves to be applied, */
|
||||
/* and allow input delta E to be estimated from output delta E. */
|
||||
/* Call with input value in p1[0].p[], */
|
||||
/* In order smallest to largest weight: */
|
||||
/* Return di+1 vertex values in p1[]].v[] and */
|
||||
/* 0-1 sub-cell weight values as (p1[].p[0] - p1[].p[1]). */
|
||||
/* Optionally in input channel order: */
|
||||
/* Returns di+1 partial derivatives + base value in p2[].v[], */
|
||||
/* with matching weight values for each in p2[].p[0] (last weight = 1)*/
|
||||
/* Return 0 if OK, 1 if input was clipped to grid */
|
||||
int (*part_interp)(
|
||||
struct _rspl *s, /* this */
|
||||
co *p1,
|
||||
co *p2); /* optional - return partial derivatives for each input channel */
|
||||
|
||||
/* Do splined forward interpolation. RESTRICTED SIZE */
|
||||
/* Return 0 if OK, 1 if input was clipped to grid */
|
||||
int (*spline_interp)(
|
||||
struct _rspl *s, /* this */
|
||||
co *p); /* Input and output values */
|
||||
|
||||
|
||||
/* ------------------------------- */
|
||||
/* Create a surface gamut representation. */
|
||||
/* Return NZ on error */
|
||||
int (*comp_gamut)(struct _rspl *s,
|
||||
double *cent, /* Optional center of gamut [fdi], default center of out range */
|
||||
double *scale, /* Optional Scale of output values in vector to center [fdi] */
|
||||
/* default 1.0 */
|
||||
void (*outf)(void *cntxf, double *out, double *in), /* Optional rspl val -> output value */
|
||||
void *cntxf, /* Context for function */
|
||||
void (*outb)(void *cntxb, double *out, double *in), /* Optional output value -> rspl val */
|
||||
void *cntxb /* Context for function */
|
||||
);
|
||||
|
||||
/* ------------------------------- */
|
||||
|
||||
/* Set the ink limit information for any reverse interpolation. */
|
||||
/* Calling this will clear the reverse interpolaton cache. */
|
||||
void (*rev_set_limit)(
|
||||
struct _rspl *s, /* this */
|
||||
double (*limitf)(void *lcntx, double *in), /* Optional input space limit function. */
|
||||
/* Function should evaluate in[0..di-1], and return a number */
|
||||
/* that is not to exceed limitv. NULL if not used. */
|
||||
void *lcntx, /* Context passed to limit() */
|
||||
double limitv /* Value that limit() is not to exceed */
|
||||
);
|
||||
|
||||
/* Get the ink limit information for any reverse interpolation. */
|
||||
void (*rev_get_limit)(
|
||||
struct _rspl *s, /* this */
|
||||
double (**limitf)(void *lcntx, double *in),
|
||||
/* Return pointer to function of NULL if not set */
|
||||
void **lcntx, /* return context pointer */
|
||||
double *limitv /* Return limit value */
|
||||
);
|
||||
|
||||
/* Set the RSPL_NEARCLIP LCh weightings. */
|
||||
/* Will only work with L*a*b* like output spaces. */
|
||||
/* Calling this will clear the reverse interpolaton cache. */
|
||||
void (*rev_set_lchw)(
|
||||
struct _rspl *s, /* this */
|
||||
double lchw[MXRO] /* Weighting */
|
||||
);
|
||||
|
||||
/* Possible reverse hint flags */
|
||||
#define RSPL_WILLCLIP 0x0001 /* Hint that clipping will be needed */
|
||||
#define RSPL_EXACTAUX 0x0002 /* Hint that auxiliary target will be matched exactly */
|
||||
#define RSPL_MAXAUX 0x0004 /* If not possible to match exactly, return the */
|
||||
/* closest value larger than the target, rather than */
|
||||
/* absolute closest. */
|
||||
#define RSPL_AUXLOCUS 0x0008 /* Auxiliary target is proportion of locus, not */
|
||||
/* absolute. Implies EXACTAUX hint. */
|
||||
#define RSPL_NEARCLIP 0x0010 /* If clipping occurs, return the nearest solution, */
|
||||
/* rather than the one in the clip direction. */
|
||||
#define RSPL_NONNSETUP 0x0020 /* Sets RSPL_FASTREVSETUP flag, which avoids NN grid */
|
||||
/* setup if this is the first call using RSPL_NEARCLIP. */
|
||||
/* Return value masks */
|
||||
#define RSPL_DIDCLIP 0x8000 /* If this bit is set, at least one soln. and clipping occured */
|
||||
#define RSPL_NOSOLNS 0x7fff /* And return value with this mask to get number of solutions */
|
||||
|
||||
/* Do reverse interpolation given target output values and (optional) auxiliary target */
|
||||
/* input values. Return number of results and clip flag. If return value == mxsoln, then */
|
||||
/* there might be more results. RESTRICTED SIZE */
|
||||
int (*rev_interp)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* Hint flag */
|
||||
int mxsoln, /* Maximum number of solutions allowed for */
|
||||
int *auxm, /* Array of di mask flags, !=0 for valid auxliaries (NULL if no aux) */
|
||||
double cdir[MXRO], /* Clip vector direction and length - NULL if not used */
|
||||
co *p); /* Given target output space value in cpp[0].v[] + */
|
||||
/* target input space auxiliaries in cpp[0].p[], return */
|
||||
/* input space solutions in cpp[0..retval-1].p[], and */
|
||||
/* (possibly) clipped target values in cpp[0].v[] */
|
||||
|
||||
/* Do reverse search for the locus of the auxiliary input values given a target output. */
|
||||
/* Return 1 on finding a valid solution, and 0 if no solutions are found. RESTRICTED SIZE */
|
||||
int (*rev_locus)(
|
||||
struct _rspl *s,/* this */
|
||||
int *auxm, /* Array of di mask flags, !=0 for valid auxliaries (NULL if no aux) */
|
||||
co *cpp, /* Input target value in cpp[0].v[] */
|
||||
double min[MXRI],/* Return minimum auxiliary values */
|
||||
double max[MXRI]); /* Return maximum auxiliary values */
|
||||
|
||||
/* Do reverse search for the auxiliary min/max ranges of the solution locus for the */
|
||||
/* given target output values. RESTRICTED SIZE */
|
||||
/* Return number of locus segments found, up to mxsoln. 0 will be returned if no solutions */
|
||||
/* are found. */
|
||||
int (*rev_locus_segs)(
|
||||
struct _rspl *s,/* this */
|
||||
int *auxm, /* Array of di mask flags, !=0 for valid auxliaries (NULL if no aux) */
|
||||
co *cpp, /* Input value in cpp[0].v[] */
|
||||
int mxsoln, /* Maximum number of solutions allowed for */
|
||||
double min[][MXRI], /* Array of min[MXRI] to hold return segment minimum values. */
|
||||
double max[][MXRI] /* Array of max[MXRI] to hold return segment maximum values. */
|
||||
);
|
||||
|
||||
|
||||
/* ------------------------------- */
|
||||
|
||||
/* Return the min and max of the input values valid in the grid */
|
||||
void (*get_in_range)(
|
||||
struct _rspl *s, /* this */
|
||||
double *min, double *max); /* Return min/max values */
|
||||
|
||||
/* return the min and max of the output values contained in the grid */
|
||||
void (*get_out_range)(
|
||||
struct _rspl *s, /* this */
|
||||
double *min, double *max); /* Return min/max values */
|
||||
|
||||
/* return the grid index of the grid values at the min & max output values */
|
||||
void (*get_out_range_points)(struct _rspl *s, int *minp, int *maxp);
|
||||
|
||||
/* return the overall scale of the output values contained in the grid */
|
||||
double (*get_out_scale)(struct _rspl *s);
|
||||
|
||||
/* return the next touched flag count value. */
|
||||
/* Whenever this rolls over, all the flags in the grid array will be reset */
|
||||
unsigned int (*get_next_touch)(
|
||||
struct _rspl *s); /* this */
|
||||
|
||||
# define wvals ad##jw
|
||||
|
||||
/* Return a pointer to the resolution array */
|
||||
int *(*get_res)(struct _rspl *s);
|
||||
|
||||
/* Return non-zero if this rspl can be */
|
||||
/* used with Restricted Size functions. */
|
||||
int (*within_restrictedsize)(
|
||||
struct _rspl *s); /* this */
|
||||
|
||||
}; typedef struct _rspl rspl;
|
||||
|
||||
/* Create a new, empty rspl object */
|
||||
rspl *new_rspl(int flags, int di, int fdi); /* Input and output dimensiality */
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
/* Utility functions */
|
||||
|
||||
/* The multi-dimensional access sequence is a distributed */
|
||||
/* Gray code sequence, with direction reversal */
|
||||
/* on every alternate power of 2 scale. */
|
||||
/* It is intended to aid cache access locality in multi-dimensional */
|
||||
/* regular sampling. It approximates the Hilbert curve sequence. */
|
||||
|
||||
/* Structure to hold sequencer info */
|
||||
struct _rpsh {
|
||||
int di; /* Dimensionality */
|
||||
unsigned res[MXDI]; /* Resolution per coordinate */
|
||||
unsigned bits[MXDI]; /* Bits per coordinate */
|
||||
unsigned tbits; /* Total bits */
|
||||
unsigned ix; /* Current binary index */
|
||||
unsigned tmask; /* Total 2^n count mask */
|
||||
unsigned count; /* Usable count */
|
||||
}; typedef struct _rpsh rpsh;
|
||||
|
||||
/* Initialise, returns total usable count */
|
||||
unsigned
|
||||
rpsh_init(rpsh *p, int di, unsigned res[], int co[]);
|
||||
|
||||
/* Reset the counter */
|
||||
void rpsh_reset(rpsh *p);
|
||||
|
||||
/* Increment pseudo-hilbert coordinates */
|
||||
/* Return non-zero if count rolls over to 0 */
|
||||
int rpsh_inc(rpsh *p, int co[]);
|
||||
|
||||
#endif /* RSPL_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
485
Argyll_V3.5.0/rspl/rspl1.c
Normal file
485
Argyll_V3.5.0/rspl/rspl1.c
Normal file
@@ -0,0 +1,485 @@
|
||||
|
||||
/* Single dimension regularized spline data structure */
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2000/10/29
|
||||
*
|
||||
* Copyright 1996 - 2010 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
|
||||
* see the License2.txt file for licencing details.
|
||||
*
|
||||
* This is a simple 1D version of rspl, useful for standalone purposes.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include "numsup.h"
|
||||
#include "rspl1.h"
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
# define DBGA g_log, 0 /* First argument to DBGF() */
|
||||
# define DBGF(xx) a1logd xx
|
||||
#else
|
||||
# define DBGF(xx)
|
||||
#endif
|
||||
|
||||
|
||||
/* Do an interpolation based on the grid */
|
||||
/* Use a linear interp between grid points. */
|
||||
/* If the input is outside the grid range, it will */
|
||||
/* be clamped to the nearest grid point. */
|
||||
static int interp(
|
||||
rspl *t,
|
||||
co *p
|
||||
) {
|
||||
int rv = 0;
|
||||
double x, y, xx, w1;
|
||||
int i;
|
||||
|
||||
x = p->p[0];
|
||||
|
||||
if (x < t->gl) {
|
||||
x = t->gl;
|
||||
rv = 1;
|
||||
} else if (x > t->gh) {
|
||||
x = t->gh;
|
||||
rv = 1;
|
||||
}
|
||||
|
||||
xx = (x - t->gl)/t->gw; /* Grid location of point */
|
||||
i = (int)floor(xx); /* Lower grid of point */
|
||||
if (i >= (t->nig-2))
|
||||
i = t->nig-2;
|
||||
|
||||
w1 = xx - (double)i; /* Weight to upper grid point */
|
||||
|
||||
y = ((1.0 - w1) * t->x[i]) + (w1 * t->x[i+1]);
|
||||
|
||||
p->v[0] = y * t->vw + t->vl; /* Rescale the data */
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Use a linear interp between grid points. */
|
||||
/* If the input is outside the grid range, it will */
|
||||
/* be clamped to the nearest grid point. */
|
||||
static double interp1(rspl *t, double in) {
|
||||
co p = { 0 };
|
||||
|
||||
p.p[0] = in;
|
||||
t->interp(t, &p);
|
||||
return p.v[0];
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
static void del_rspl(rspl *t) {
|
||||
if (t != NULL) {
|
||||
if (t->x != NULL)
|
||||
free_dvector(t->x, 0, t->nig);
|
||||
free(t);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise the regular spline from scattered data */
|
||||
/* Return nz on error */
|
||||
static int fit_rspl_imp(
|
||||
struct _rspl *t,/* this */
|
||||
int flags, /* (Not used) */
|
||||
void *d, /* Array holding position and function values of data points */
|
||||
int dtp, /* Flag indicating data type, 0 = (co *), 1 = (cow *), 2 = (coww *) */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int *gres, /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double *avgdev, /* (Not used) */
|
||||
double **ipos /* (not used) */
|
||||
) {
|
||||
int n;
|
||||
double cw;
|
||||
|
||||
DBGF((DBGA, "rspl1:fit_rspl_imp() with %d points called, dtp = %d\n",ndp,dtp));
|
||||
|
||||
/* Allocate space for interpolation grid */
|
||||
t->nig = *gres;
|
||||
|
||||
if ((t->x = dvector(0, t->nig)) == NULL) {
|
||||
DBGF((DBGA, "rspl1:Malloc of vector x failed\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Normalize curve weight to grid resolution. */
|
||||
cw = 0.0000005 * smooth * pow((t->nig-1),4.0) / (t->nig - 2);
|
||||
DBGF((DBGA, "rspl1:cw = %e\n",cw));
|
||||
|
||||
/* cw is multiplied by the sum of grid curvature errors squared to keep */
|
||||
/* the same ratio with the sum of data position errors squared */
|
||||
|
||||
/* Determine the data range */
|
||||
t->xl = 1e300;
|
||||
t->xh = -1e300;
|
||||
t->dl = 1e300;
|
||||
t->dh = -1e300;
|
||||
if (dtp == 0) {
|
||||
co *dd = (co *)d;
|
||||
|
||||
for (n = 0; n < ndp; n++) {
|
||||
if (dd[n].p[0] < t->xl)
|
||||
t->xl = dd[n].p[0];
|
||||
if (dd[n].p[0] > t->xh)
|
||||
t->xh = dd[n].p[0];
|
||||
if (dd[n].v[0] < t->dl)
|
||||
t->dl = dd[n].v[0];
|
||||
if (dd[n].v[0] > t->dh)
|
||||
t->dh = dd[n].v[0];
|
||||
|
||||
DBGF((DBGA, "rspl1:Point %d = %f, %f\n",n,dd[n].p[0],dd[n].v[0]));
|
||||
}
|
||||
} else if (dtp == 1) {
|
||||
cow *dd = (cow *)d;
|
||||
|
||||
for (n = 0; n < ndp; n++) {
|
||||
if (dd[n].p[0] < t->xl)
|
||||
t->xl = dd[n].p[0];
|
||||
if (dd[n].p[0] > t->xh)
|
||||
t->xh = dd[n].p[0];
|
||||
if (dd[n].v[0] < t->dl)
|
||||
t->dl = dd[n].v[0];
|
||||
if (dd[n].v[0] > t->dh)
|
||||
t->dh = dd[n].v[0];
|
||||
DBGF((DBGA, "rspl1:Point %d = %f, %f (%f)\n",n,dd[n].p[0],dd[n].v[0],dd[n].w));
|
||||
}
|
||||
} else {
|
||||
DBGF((DBGA, "rspl1:Internal error, unknown dtp value %d\n",dtp));
|
||||
return 1;
|
||||
}
|
||||
|
||||
t->gl = glow != NULL ? *glow : 0.0;
|
||||
t->gh = ghigh != NULL ? *ghigh : 1.0;
|
||||
|
||||
/* adjust input ranges to encompass data */
|
||||
if (t->xl < t->gl)
|
||||
t->gl = t->xl;
|
||||
if (t->xh > t->gh)
|
||||
t->gh = t->xh;
|
||||
|
||||
/* Set the input and output scaling */
|
||||
t->gw = (t->gh - t->gl)/(double)(t->nig-1);
|
||||
|
||||
t->vl = vlow != NULL ? *vlow : 0.0;
|
||||
t->vw = ((vhigh != NULL ? *vhigh : 1.0) - t->vl);
|
||||
|
||||
DBGF((DBGA, "rspl1:gl %f, gh %f, gw %f, vl %f, vw %f\n",t->gl,t->gh,t->gw,t->vl,t->vw));
|
||||
|
||||
/* create smoothed grid data */
|
||||
{
|
||||
int n,i,k;
|
||||
double **A; /* A matrix of interpoint weights */
|
||||
double *b; /* b vector for RHS of simultabeous equation */
|
||||
|
||||
/* We just store the diagonal of the A matrix */
|
||||
if ((A = dmatrix(0, t->nig, 0, 2)) == NULL) {
|
||||
DBGF((DBGA, "rspl1:Malloc of matrix A failed\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((b = dvector(0,t->nig)) == NULL) {
|
||||
free_dvector(b,0,t->nig);
|
||||
DBGF((DBGA, "rspl1:Malloc of vector b failed\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Initialize the A and b matricies */
|
||||
for (i = 0; i < t->nig; i++) {
|
||||
for (k = 0; k < 3; k++)
|
||||
A[i][k] = 0.0;
|
||||
t->x[i] = b[i] = 0.0;
|
||||
}
|
||||
|
||||
/* Accumulate data dependent factors */
|
||||
for (n = 0; n < ndp; n++) {
|
||||
double bf, cbf;
|
||||
double xv, yv, wv;
|
||||
|
||||
if (dtp == 0) {
|
||||
co *dd = (co *)d;
|
||||
|
||||
xv = dd[n].p[0];
|
||||
yv = dd[n].v[0];
|
||||
wv = 1.0;
|
||||
} else if (dtp == 1) {
|
||||
cow *dd = (cow *)d;
|
||||
|
||||
xv = dd[n].p[0];
|
||||
yv = dd[n].v[0];
|
||||
wv = dd[n].w;
|
||||
} else {
|
||||
DBGF((DBGA, "rspl1:Internal error, unknown dtp value %d\n",dtp));
|
||||
return 1;
|
||||
}
|
||||
yv = (yv - t->vl)/t->vw; /* Normalize the value */
|
||||
|
||||
/* Figure out which grid cell data is in */
|
||||
i = (int)((xv - t->gl)/t->gw); /* Index of next lowest data point */
|
||||
|
||||
bf = ((((double)(i+1) * t->gw) + t->gl) - xv)/t->gw; /* weight to lower grid point */
|
||||
cbf = 1.0 - bf; /* weight to upper grid point */
|
||||
|
||||
b[i] -= 2.0 * bf * -yv * wv; /* dui component due to dn */
|
||||
A[i][0] += 2.0 * bf * bf * wv; /* dui component due to ui */
|
||||
A[i][1] += 2.0 * bf * cbf * wv; /* dui component due to ui+1 */
|
||||
|
||||
if ((i+1) < t->nig) {
|
||||
b[i+1] -= 2.0 * cbf * -yv * wv; /* dui component due to dn */
|
||||
A[i+1][0] += 2.0 * cbf * cbf * wv; /* dui component due to ui */
|
||||
}
|
||||
}
|
||||
|
||||
/* Accumulate curvature dependent factors */
|
||||
for (i = 0; i < t->nig; i++) {
|
||||
|
||||
if ((i-2) >= 0) { /* Curvature of cell below */
|
||||
A[i][0] += 2.0 * cw;
|
||||
}
|
||||
|
||||
if ((i-1) >= 0 && (i+1) < t->nig) { /* Curvature of t cell */
|
||||
A[i][0] += 8.0 * cw;
|
||||
A[i][1] += -4.0 * cw;
|
||||
}
|
||||
if ((i+2) < t->nig) { /* Curvature of cell above */
|
||||
A[i][0] += 2.0 * cw;
|
||||
A[i][1] += -4.0 * cw;
|
||||
A[i][2] += 2.0 * cw;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
DBGF((DBGA, "A matrix:\n"));
|
||||
for (i = 0; i < t->nig; i++) {
|
||||
for (k = 0; k < 3; k++)
|
||||
DBGF((DBGA, "A[%d][%d] = %f\n",i,k,A[i][k]));
|
||||
}
|
||||
DBGF((DBGA, "b vector:\n"));
|
||||
for (i = 0; i < t->nig; i++)
|
||||
DBGF((DBGA, "b[%d] = %f\n",i,b[i]));
|
||||
#endif /* DEBUG */
|
||||
|
||||
/* Apply Cholesky decomposition to A[][] to create L[][] */
|
||||
for (i = 0; i < t->nig; i++) {
|
||||
double sm;
|
||||
for (n = 0; n < 3; n++) {
|
||||
sm = A[i][n];
|
||||
for (k = 1; (n+k) < 3 && (i-k) >=0; k++) {
|
||||
sm -= A[i-k][n+k] * A[i-k][k];
|
||||
}
|
||||
if (n == 0) {
|
||||
if (sm <= 0.0) {
|
||||
free_dvector(b,0,t->nig);
|
||||
free_dmatrix(A,0,t->nig,0,2);
|
||||
DBGF((DBGA, "rspl1:Sum is -ve - loss of accuracy ?\n"));
|
||||
return 1;
|
||||
}
|
||||
A[i][0] = sqrt(sm);
|
||||
} else {
|
||||
A[i][n] = sm/A[i][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Solve L . y = b, storing y in x */
|
||||
for (i = 0; i < t->nig; i++) {
|
||||
double sm;
|
||||
sm = b[i];
|
||||
for (k = 1; k < 3 && (i-k) >= 0; k++) {
|
||||
sm -= A[i-k][k] * t->x[i-k];
|
||||
}
|
||||
t->x[i] = sm/A[i][0];
|
||||
}
|
||||
|
||||
/* Solve LT . x = y */
|
||||
for (i = t->nig-1; i >= 0; i--) {
|
||||
double sm;
|
||||
sm = t->x[i];
|
||||
for (k = 1; k < 3 && (i+k) < t->nig; k++) {
|
||||
sm -= A[i][k] * t->x[i+k];
|
||||
}
|
||||
t->x[i] = sm/A[i][0];
|
||||
}
|
||||
#ifdef DEBUG
|
||||
DBGF((DBGA, "Solution vector:\n"));
|
||||
for (i = 0; i < t->nig; i++) {
|
||||
DBGF((DBGA, "x[%d] = %f\n",i,t->x[i]));
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
free_dvector(b,0,t->nig);
|
||||
free_dmatrix(A,0,t->nig,0,2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initialise from scattered data. */
|
||||
/* Return nz on error */
|
||||
static int fit_rspl(
|
||||
struct _rspl *t,/* this */
|
||||
int flags, /* (Not used) */
|
||||
co *d, /* Array holding position and function values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int *gres, /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double *avgdev, /* (Not used) */
|
||||
double **ipos /* (not used) */
|
||||
) {
|
||||
/* Call implementation with (co *) data */
|
||||
return fit_rspl_imp(t, flags, (void *)d, 0, ndp, glow, ghigh, gres, vlow, vhigh,
|
||||
smooth, avgdev, ipos);
|
||||
}
|
||||
|
||||
/* Return a pointer to the resolution array */
|
||||
static int *get_res(rspl *s) {
|
||||
return &s->nig;
|
||||
}
|
||||
|
||||
/* Initialise the regular spline from scattered data with weights */
|
||||
/* Return nz on error */
|
||||
static int
|
||||
fit_rspl_w(
|
||||
rspl *t, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
cow *d, /* Array holding position, function and weight values of data points */
|
||||
int dno, /* Number of data points */
|
||||
ratai glow, /* Grid low scale - will be expanded to enclose data, NULL = default 0.0 */
|
||||
ratai ghigh, /* Grid high scale - will be expanded to enclose data, NULL = default 1.0 */
|
||||
int *gres, /* Spline grid resolution */
|
||||
ratao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
ratao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double *avgdev, /* (Not used) */
|
||||
double **ipos /* (not used) */
|
||||
) {
|
||||
/* Call implementation with (cow *) data */
|
||||
return fit_rspl_imp(t, flags, (void *)d, 1, dno, glow, ghigh, gres, vlow, vhigh,
|
||||
smooth, avgdev, ipos);
|
||||
}
|
||||
|
||||
/* Initialize the grid from a provided function. */
|
||||
/* Grid index values are supplied "under" in[] at *((int*)&iv[-e-1]) */
|
||||
static int set_rspl(
|
||||
struct _rspl *s,/* this */
|
||||
int flags, /* (Not used) */
|
||||
void *cbctx, /* Opaque function context */
|
||||
void (*func)(void *cbctx, double *out, double *in), /* Function to set from */
|
||||
datai glow, /* Grid low scale, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale, NULL = default 1.0 */
|
||||
int *gres, /* Spline grid resolution for each dimension */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh /* Data value high normalize, NULL = default 1.0 */
|
||||
) {
|
||||
int n;
|
||||
double _iv[2 * MXDI], *iv = &_iv[MXDI]; /* Real index value/table value */
|
||||
double ov[MXDO];
|
||||
|
||||
DBGF((DBGA, "rspl1:set_rspl() callen"));
|
||||
|
||||
/* Allocate space for interpolation grid */
|
||||
s->nig = *gres;
|
||||
|
||||
if ((s->x = dvector(0, s->nig)) == NULL) {
|
||||
DBGF((DBGA, "rspl1:Malloc of vector x failed\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
s->xl = s->gl = glow != NULL ? *glow : 0.0;
|
||||
s->xh = s->gh = ghigh != NULL ? *ghigh : 1.0;
|
||||
|
||||
/* Set the input scaling */
|
||||
s->gw = (s->gh - s->gl)/(double)(s->nig-1);
|
||||
|
||||
/* Set the default output scaling */
|
||||
s->vl = vlow != NULL ? *vlow : 0.0;
|
||||
s->vw = ((vhigh != NULL ? *vhigh : 1.0) - s->vl);
|
||||
|
||||
DBGF((DBGA, "rspl1:gl %f, gh %f, gw %f, vl %f, vw %f\n",s->gl,s->gh,s->gw,s->vl,s->vw));
|
||||
|
||||
/* Lookup the values at the grid points */
|
||||
for (n = 0; n < s->nig; n++) {
|
||||
double vv;
|
||||
|
||||
/* Compute grid pointer and input sample values */
|
||||
iv[0] = s->gl + n * s->gw; /* Input sample values */
|
||||
*((int *)&iv[-1-1]) = n; /* Trick to supply grid index in iv[] */
|
||||
|
||||
/* Apply incolor -> outcolor function we want to represent */
|
||||
func(cbctx, ov, iv);
|
||||
|
||||
s->x[n] = (float)ov[0]; /* Set unscaled output value */
|
||||
|
||||
if (s->x[n] < s->dl)
|
||||
s->dl = s->x[n];
|
||||
if (s->x[n] > s->dh)
|
||||
s->dh = s->x[n];
|
||||
}
|
||||
|
||||
/* Adjust output scaling */
|
||||
s->vw += s->vl; /* Convert to high */
|
||||
if (s->dl < s->vl)
|
||||
s->vl = s->dl;
|
||||
if (s->dh < s->vw)
|
||||
s->vw = s->dh;
|
||||
s->vw -= s->vl; /* Convert to width */
|
||||
|
||||
/* Apply scaling to data */
|
||||
for (n = 0; n < s->nig; n++) {
|
||||
s->x[n] = (s->x[n] - s->vl)/s->vw;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Construct an empty rspl1 */
|
||||
/* Return NULL if something goes wrong. */
|
||||
rspl *new_rspl(int flags, int di, int fdi) {
|
||||
rspl *t; /* this */
|
||||
|
||||
if (flags != RSPL_NOFLAGS || di != 1 || fdi != 1) {
|
||||
DBGF((DBGA, "rspl1:Can't handle general rspl: flags %d, di %d, do %d\n",flags,di,fdi));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((t = (rspl *)calloc(1, sizeof(rspl))) == NULL) {
|
||||
DBGF((DBGA, "rspl1:Malloc of structure failed\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialise the classes methods */
|
||||
t->interp = interp;
|
||||
t->interp1 = interp1;
|
||||
t->fit_rspl = fit_rspl;
|
||||
t->fit_rspl_w = fit_rspl_w;
|
||||
t->set_rspl = set_rspl;
|
||||
t->get_res = get_res;
|
||||
t->del = del_rspl;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
150
Argyll_V3.5.0/rspl/rspl1.h
Normal file
150
Argyll_V3.5.0/rspl/rspl1.h
Normal file
@@ -0,0 +1,150 @@
|
||||
|
||||
#ifndef _RSPL1_H_
|
||||
|
||||
/* Single dimension regularized spline data structure */
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2000/10/29
|
||||
*
|
||||
* Copyright 1996 - 2010 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
|
||||
* see the License2.txt file for licencing details.
|
||||
*
|
||||
* This is a simple 1D version of rspl, useful for standalone purposes.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Might be nice to add support for simple rev lookup, so that
|
||||
* standalone xcal can use it ??
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Make up for possible lack of rspl.h */
|
||||
#ifndef MXDI
|
||||
# define MXDI 10 /* Maximum input dimensionality */
|
||||
# define MXDO 10 /* Maximum output dimensionality (Is not fully tested!!!) */
|
||||
#endif
|
||||
|
||||
/* General data point position/value structure */
|
||||
typedef double datai[1];
|
||||
typedef double datao[1];
|
||||
typedef double ratai[1];
|
||||
typedef double ratao[1];
|
||||
|
||||
/* Interface coordinate value */
|
||||
typedef struct {
|
||||
double p[1]; /* coordinate position */
|
||||
double v[1]; /* function values */
|
||||
} co;
|
||||
|
||||
/* Interface coordinate value */
|
||||
typedef struct {
|
||||
double p[1]; /* coordinate position */
|
||||
double v[1]; /* function values */
|
||||
double w; /* Weight to give this point, nominally 1.0 */
|
||||
} cow;
|
||||
|
||||
#define RSPL_NOFLAGS 0
|
||||
|
||||
struct _rspl {
|
||||
|
||||
/* Private: */
|
||||
int nig; /* number in interpolation grid */
|
||||
double gl,gh,gw;/* Interpolation grid scale low, high, grid cell width */
|
||||
double vl,vw; /* low & range */
|
||||
double xl,xh; /* Actual X data exremes low, high */
|
||||
double dl,dh; /* Actual Y Data scale low, high */
|
||||
double *x; /* Array of nig grid point scaled y values */
|
||||
|
||||
/* Public: */
|
||||
|
||||
/* destructor */
|
||||
void (*del)(struct _rspl *t);
|
||||
|
||||
/* Initialise from scattered data. */
|
||||
/* Returns nz on error */
|
||||
int
|
||||
(*fit_rspl)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* (Not used) */
|
||||
co *d, /* Array holding position and function values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int *gres, /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double *avgdev, /* (Not used) */
|
||||
double **ipos /* (not used) */
|
||||
);
|
||||
|
||||
/* Initialise from scattered data with weighting. */
|
||||
/* Returns nz on error */
|
||||
int
|
||||
(*fit_rspl_w)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* (Not used) */
|
||||
cow *d, /* Array holding position and function values of data points */
|
||||
int ndp, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */
|
||||
int *gres, /* Spline grid resolution, ncells = gres-1 */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth, /* Smoothing factor, 0.0 = default 1.0 */
|
||||
double *avgdev, /* (Not used) */
|
||||
double **ipos /* (not used) */
|
||||
);
|
||||
|
||||
/* Initialize the grid from a provided function. */
|
||||
/* Grid index values are supplied "under" in[] at *((int*)&in[-e-1]) */
|
||||
int
|
||||
(*set_rspl)(
|
||||
struct _rspl *s, /* this */
|
||||
int flags, /* (Not used) */
|
||||
void *cbntx, /* Opaque function context */
|
||||
void (*func)(void *cbntx, double *out, double *in), /* Function to set from */
|
||||
datai glow, /* Grid low scale, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale, NULL = default 1.0 */
|
||||
int gres[MXDI], /* Spline grid resolution */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh /* Data value high normalize - NULL = default 1.0 */
|
||||
);
|
||||
|
||||
/* Do forward interpolation */
|
||||
/* Return 0 if OK, 1 if input was clipped to grid */
|
||||
int (*interp)(
|
||||
struct _rspl *s, /* this */
|
||||
co *p); /* Input and output values */
|
||||
|
||||
/* Do forward 1d interpolation of and return the value. */
|
||||
double (*interp1)( /* Return value */
|
||||
struct _rspl *s, /* this */
|
||||
double in); /* Input value */
|
||||
|
||||
/* Return a pointer to the resolution array */
|
||||
int *(*get_res)(struct _rspl *s);
|
||||
|
||||
}; typedef struct _rspl rspl;
|
||||
|
||||
/* Create a new, empty rspl object */
|
||||
rspl *new_rspl(int flags, int di, int fdi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define _RSPL1_H_
|
||||
#endif /* _RSPL1_H_ */
|
||||
|
||||
|
||||
27
Argyll_V3.5.0/rspl/rspl_imp.h
Normal file
27
Argyll_V3.5.0/rspl/rspl_imp.h
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional regularized spline
|
||||
* Implementation header.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 28/9/96
|
||||
*
|
||||
* Copyright 1996, Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#include "rspl.h"
|
||||
|
||||
#ifndef RSPL_IMP_H
|
||||
|
||||
/* These three factors controll how the monotonic stuff behaves. */
|
||||
#define MCINC 0.05 /* The tollerance for detecting non-monoticity */
|
||||
#define BALLEV 0.8 /* Balance level of adjusted points */
|
||||
#define RADF 0.01 /* Radius factor of nme influence */
|
||||
|
||||
#define RSPL_IMP_H
|
||||
#endif /* RSPL_IMP_H */
|
||||
3109
Argyll_V3.5.0/rspl/scat.c
Normal file
3109
Argyll_V3.5.0/rspl/scat.c
Normal file
File diff suppressed because it is too large
Load Diff
227
Argyll_V3.5.0/rspl/scat2.c
Normal file
227
Argyll_V3.5.0/rspl/scat2.c
Normal file
@@ -0,0 +1,227 @@
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional multilevel spline data fitter
|
||||
* mlbs base version.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2000/11/10
|
||||
*
|
||||
* Copyright 1996 - 2000 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
/* This file contains the scattered data solution specific code */
|
||||
|
||||
/* TTBD:
|
||||
*
|
||||
* mlbs code doesn't work. Results are rubbish.
|
||||
*
|
||||
* Fix bugs ?
|
||||
* merge stest.c into this file.
|
||||
*
|
||||
* Get rid of error() calls - return status instead
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "rspl_imp.h"
|
||||
#include "numlib.h"
|
||||
#include "mlbs.h"
|
||||
|
||||
extern void error(char *fmt, ...), warning(char *fmt, ...);
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
/* Implemented in rspl.c: */
|
||||
extern void alloc_grid(rspl *s);
|
||||
|
||||
extern int is_mono(rspl *s);
|
||||
|
||||
/* ============================================ */
|
||||
void set_from_mlbs(void *cbctx, double *out, double *in) {
|
||||
mlbs *p = (mlbs *)cbctx;
|
||||
co tp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < p->di; i++)
|
||||
tp.p[i] = in[i];
|
||||
|
||||
if (p->lookup(p, &tp))
|
||||
error("Internal, set_from_mlbs failed!");
|
||||
|
||||
for (i = 0; i < p->di; i++)
|
||||
out[i] = tp.v[i];
|
||||
}
|
||||
|
||||
/* Initialise the regular spline from scattered data */
|
||||
/* Return non-zero if non-monotonic */
|
||||
static int
|
||||
fit_rspl_imp(
|
||||
rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
void *d, /* Array holding position and function values of data points */
|
||||
int dtp, /* Flag indicating data type, 0 = (co *), 1 = (cow *) */
|
||||
int dno, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will be expanded to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will be expanded to enclose data, NULL = default 1.0 */
|
||||
int gres, /* Spline grid resolution */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth /* Smoothing factor, nominal = 1.0 */
|
||||
) {
|
||||
int di = s->di, fdi = s->fdi;
|
||||
int i, n, e, f;
|
||||
int rv;
|
||||
int nigc;
|
||||
int bres;
|
||||
mlbs *p;
|
||||
|
||||
/* set debug level */
|
||||
s->debug = (flags >> 24);
|
||||
|
||||
/* Init other flags */
|
||||
if (flags & RSPL_NONMON) /* Enable elimination of non-monoticities */
|
||||
s->nm = 1;
|
||||
else
|
||||
s->nm = 0;
|
||||
|
||||
if (flags & RSPL_VERBOSE) /* Turn on progress messages to stdout */
|
||||
s->verbose = 1;
|
||||
else
|
||||
s->verbose = 0;
|
||||
|
||||
/* Save smoothing factor */
|
||||
s->smooth = smooth;
|
||||
|
||||
/* Stash the data points away */
|
||||
s->d.no = dno; /* Number of data points */
|
||||
|
||||
/* Allocate the scattered data space */
|
||||
if ((s->d.a = (dpnts *) malloc(sizeof(dpnts) * s->d.no)) == NULL)
|
||||
error("rspl malloc failed - data points");
|
||||
|
||||
if (dtp == 0) { /* Default weight */
|
||||
co *dp = (co *)d;
|
||||
|
||||
/* Copy the list into data points */
|
||||
for (n = 0; n < s->d.no; n++) {
|
||||
for (e = 0; e < s->di; e++)
|
||||
s->d.a[n].p[e] = dp[n].p[e];
|
||||
for (f = 0; f < s->fdi; f++)
|
||||
s->d.a[n].v[f] = dp[n].v[f];
|
||||
s->d.a[n].k = 1.0; /* Assume all data points have same weight */
|
||||
}
|
||||
} else { /* Per data point weight */
|
||||
cow *dp = (cow *)d;
|
||||
|
||||
/* Copy the list into data points */
|
||||
for (n = 0; n < s->d.no; n++) {
|
||||
for (e = 0; e < s->di; e++)
|
||||
s->d.a[n].p[e] = dp[n].p[e];
|
||||
for (f = 0; f < s->fdi; f++)
|
||||
s->d.a[n].v[f] = dp[n].v[f];
|
||||
s->d.a[n].k = dp[n].w; /* Weight specified */
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute target B-Spline resolution */
|
||||
/* Make it worst case half the target rspl resolution */
|
||||
for (bres = 2; (2 * bres) < gres; bres = 2 * bres -1)
|
||||
;
|
||||
|
||||
/* Create multilevel B-Spline fit */
|
||||
p = new_mlbs(di, fdi, bres, s->d.a, s->d.no, glow, ghigh, smooth);
|
||||
if (p == NULL)
|
||||
error("new_mlbs() failed");
|
||||
|
||||
/* Create rspl grid points by looking up the B-Spline values */
|
||||
rv = s->set_rspl(s, 0, (void *)p, set_from_mlbs, glow, ghigh, gres, vlow, vhigh);
|
||||
|
||||
/* Don't need B-Spline any more */
|
||||
p->del(p);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Initialise the regular spline from scattered data */
|
||||
/* Return non-zero if non-monotonic */
|
||||
int
|
||||
fit_rspl(
|
||||
rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
co *d, /* Array holding position and function values of data points */
|
||||
int dno, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will be expanded to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will be expanded to enclose data, NULL = default 1.0 */
|
||||
int gres, /* Spline grid resolution */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth /* Smoothing factor, nominal = 1.0 */
|
||||
) {
|
||||
/* Call implementation with (co *) data */
|
||||
return fit_rspl_imp(s, flags, (void *)d, 0, dno, glow, ghigh, gres, vlow, vhigh, smooth);
|
||||
}
|
||||
|
||||
/* Initialise the regular spline from scattered data with weights */
|
||||
/* Return non-zero if non-monotonic */
|
||||
int
|
||||
fit_rspl_w(
|
||||
rspl *s, /* this */
|
||||
int flags, /* Combination of flags */
|
||||
cow *d, /* Array holding position, function and weight values of data points */
|
||||
int dno, /* Number of data points */
|
||||
datai glow, /* Grid low scale - will be expanded to enclose data, NULL = default 0.0 */
|
||||
datai ghigh, /* Grid high scale - will be expanded to enclose data, NULL = default 1.0 */
|
||||
int gres, /* Spline grid resolution */
|
||||
datao vlow, /* Data value low normalize, NULL = default 0.0 */
|
||||
datao vhigh, /* Data value high normalize - NULL = default 1.0 */
|
||||
double smooth /* Smoothing factor, nominal = 1.0 */
|
||||
) {
|
||||
/* Call implementation with (cow *) data */
|
||||
return fit_rspl_imp(s, flags, (void *)d, 1, dno, glow, ghigh, gres, vlow, vhigh, smooth);
|
||||
}
|
||||
|
||||
/* Init scattered data elements in rspl */
|
||||
void
|
||||
init_data(rspl *s) {
|
||||
s->d.no = 0;
|
||||
s->d.a = NULL;
|
||||
s->fit_rspl = fit_rspl;
|
||||
s->fit_rspl_w = fit_rspl_w;
|
||||
}
|
||||
|
||||
/* Free the scattered data allocation */
|
||||
void
|
||||
free_data(rspl *s) {
|
||||
if (s->d.a != NULL) {
|
||||
free((void *)s->d.a);
|
||||
s->d.a = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
88
Argyll_V3.5.0/rspl/sm1.c
Normal file
88
Argyll_V3.5.0/rspl/sm1.c
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
/* Test smoothness scaling behaviour for 1D */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
double trans(double *v, int luord, double vv);
|
||||
|
||||
double f(double x) {
|
||||
double fp[5] = { +1.0, 0.7, -0.3, 0.0, 0.0 };
|
||||
double y;
|
||||
|
||||
y = trans(fp, 5, x);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int main() {
|
||||
double min = 0.0;
|
||||
double max = 1.0;
|
||||
int i, res = 4;
|
||||
int di = 1;
|
||||
|
||||
#define LOC(xx) (min + (max-min) * (xx)/(res-1.0))
|
||||
|
||||
/* For each resolution */
|
||||
for (i = 0; i < 10; i++, res *= 2) {
|
||||
double tse = 0.0; /* Total squared error */
|
||||
int j;
|
||||
|
||||
/* For each grid point with neigbors */
|
||||
for (j = 1; j < (res-1); j++) {
|
||||
double err;
|
||||
double y1, y2, y3;
|
||||
|
||||
y1 = f(LOC(j-1));
|
||||
y2 = f(LOC(j));
|
||||
y3 = f(LOC(j+1));
|
||||
err = 0.5 * (y3 + y1) - y2;
|
||||
tse += err * err;
|
||||
// tse += fabs(err);
|
||||
}
|
||||
/* Apply adjustments and corrections to error squared */
|
||||
tse *= pow((res-1.0), 4.0); /* Aprox. geometric resolution factor */
|
||||
tse /= pow((res-2.0),(double)di); /* Average squared non-smoothness */
|
||||
|
||||
// tse /= (di * pow((res-2.0),(double)di)); /* Average squared non-smoothness */
|
||||
printf("Res %d, tse = %f\n",res,tse);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Transfer function */
|
||||
double trans(
|
||||
double *v, /* Pointer to first parameter */
|
||||
int luord, /* Number of parameters */
|
||||
double vv /* Source of value */
|
||||
) {
|
||||
double g;
|
||||
int ord;
|
||||
|
||||
for (ord = 0; ord < luord; ord++) {
|
||||
int nsec; /* Number of sections */
|
||||
double sec; /* Section */
|
||||
|
||||
g = v[ord]; /* Parameter */
|
||||
|
||||
nsec = ord + 1; /* Increase sections for each order */
|
||||
|
||||
vv *= (double)nsec;
|
||||
|
||||
sec = floor(vv);
|
||||
if (((int)sec) & 1)
|
||||
g = -g; /* Alternate action in each section */
|
||||
vv -= sec;
|
||||
if (g >= 0.0) {
|
||||
vv = vv/(g - g * vv + 1.0);
|
||||
} else {
|
||||
vv = (vv - g * vv)/(1.0 - g * vv);
|
||||
}
|
||||
vv += sec;
|
||||
vv /= (double)nsec;
|
||||
}
|
||||
|
||||
return vv;
|
||||
}
|
||||
110
Argyll_V3.5.0/rspl/sm2.c
Normal file
110
Argyll_V3.5.0/rspl/sm2.c
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
/* Test smoothness scaling behaviour for 2D */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
double trans(double *v, int luord, double vv);
|
||||
|
||||
double f(double x, double y) {
|
||||
double fp[2][5] = {
|
||||
{ 1.0, 0.7, -0.3, 0.0, 0.0 },
|
||||
{ 1.0, 0.7, -0.3, 0.0, 0.0 }
|
||||
};
|
||||
double v;
|
||||
|
||||
#ifdef NEVER
|
||||
/* 1D function */
|
||||
v = trans(fp[0], 5, x);
|
||||
#else
|
||||
/* 1D on angle */
|
||||
v = trans(fp[0], 5, 0.5 * (x+y));
|
||||
v *= 2.0 * sqrt(2.0); // ?????
|
||||
#endif
|
||||
|
||||
// v = trans(fp[0], 5, x)
|
||||
// + trans(fp[0], 5, y);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int main() {
|
||||
double min = 0.0;
|
||||
double max = 1.0;
|
||||
int di = 2;
|
||||
int i, res = 4;
|
||||
|
||||
#define LOC(xx) (min + (max-min) * (xx)/(res-1.0))
|
||||
|
||||
/* For each resolution */
|
||||
for (i = 0; i < 10; i++, res *= 2) {
|
||||
double tse = 0.0; /* Total squared error */
|
||||
int j, k;
|
||||
|
||||
/* For each grid point with neigbors */
|
||||
for (j = 1; j < (res-1); j++) {
|
||||
for (k = 1; k < (res-1); k++) {
|
||||
double err;
|
||||
double y1, y2, y3;
|
||||
|
||||
y1 = f(LOC(j-1), LOC(k));
|
||||
y2 = f(LOC(j+0), LOC(k));
|
||||
y3 = f(LOC(j+1), LOC(k));
|
||||
err = 0.5 * (y3 + y1) - y2;
|
||||
tse += err * err;
|
||||
// tse += fabs(err);
|
||||
|
||||
y1 = f(LOC(j), LOC(k-1));
|
||||
y2 = f(LOC(j), LOC(k+0));
|
||||
y3 = f(LOC(j), LOC(k+1));
|
||||
err = 0.5 * (y3 + y1) - y2;
|
||||
tse += err * err;
|
||||
// tse += fabs(err);
|
||||
}
|
||||
}
|
||||
/* Apply adjustments and corrections */
|
||||
tse *= pow((res-1.0), 4.0); /* Aprox. geometric resolution factor */
|
||||
tse /= pow((res-2.0),(double)di); /* Average squared non-smoothness */
|
||||
|
||||
// tse /= (di * pow((res-2.0),(double)di)); /* Average squared non-smoothness */
|
||||
printf("Res %d, tse = %f\n",res,tse);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Transfer function */
|
||||
double trans(
|
||||
double *v, /* Pointer to first parameter */
|
||||
int luord, /* Number of parameters */
|
||||
double vv /* Source of value */
|
||||
) {
|
||||
double g;
|
||||
int ord;
|
||||
|
||||
for (ord = 0; ord < luord; ord++) {
|
||||
int nsec; /* Number of sections */
|
||||
double sec; /* Section */
|
||||
|
||||
g = v[ord]; /* Parameter */
|
||||
|
||||
nsec = ord + 1; /* Increase sections for each order */
|
||||
|
||||
vv *= (double)nsec;
|
||||
|
||||
sec = floor(vv);
|
||||
if (((int)sec) & 1)
|
||||
g = -g; /* Alternate action in each section */
|
||||
vv -= sec;
|
||||
if (g >= 0.0) {
|
||||
vv = vv/(g - g * vv + 1.0);
|
||||
} else {
|
||||
vv = (vv - g * vv)/(1.0 - g * vv);
|
||||
}
|
||||
vv += sec;
|
||||
vv /= (double)nsec;
|
||||
}
|
||||
|
||||
return vv;
|
||||
}
|
||||
110
Argyll_V3.5.0/rspl/sm3.c
Normal file
110
Argyll_V3.5.0/rspl/sm3.c
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
/* Test smoothness scaling behaviour for 1D */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
double trans(double *v, int luord, double vv);
|
||||
|
||||
double f(double x, double y, double z) {
|
||||
double fp[5] = { 1.0, 0.7, -0.3, 0.0, 0.0 };
|
||||
double v;
|
||||
|
||||
#ifdef NEVER
|
||||
/* 1D function */
|
||||
v = trans(fp, 5, x);
|
||||
#else
|
||||
/* 1D on angle */
|
||||
v = trans(fp, 5, (x+y+z)/3.0);
|
||||
v *= 3.0 * sqrt(3.0); // ?????
|
||||
#endif
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int main() {
|
||||
double min = 0.0;
|
||||
double max = 1.0;
|
||||
int di = 3;
|
||||
int i, res = 4;
|
||||
|
||||
#define LOC(xx) (min + (max-min) * (xx)/(res-1.0))
|
||||
|
||||
/* For each resolution */
|
||||
for (i = 0; i < 10; i++, res *= 2) {
|
||||
double tse = 0.0; /* Total squared error */
|
||||
int j, k, m;
|
||||
|
||||
/* For each grid point with neigbors */
|
||||
for (j = 1; j < (res-1); j++) {
|
||||
for (k = 1; k < (res-1); k++) {
|
||||
for (m = 1; m < (res-1); m++) {
|
||||
double err;
|
||||
double y1, y2, y3;
|
||||
|
||||
y1 = f(LOC(j-1), LOC(k), LOC(m));
|
||||
y2 = f(LOC(j+0), LOC(k), LOC(m));
|
||||
y3 = f(LOC(j+1), LOC(k), LOC(m));
|
||||
err = 0.5 * (y3 + y1) - y2;
|
||||
tse += err * err;
|
||||
|
||||
y1 = f(LOC(j), LOC(k-1), LOC(m));
|
||||
y2 = f(LOC(j), LOC(k+0), LOC(m));
|
||||
y3 = f(LOC(j), LOC(k+1), LOC(m));
|
||||
err = 0.5 * (y3 + y1) - y2;
|
||||
tse += err * err;
|
||||
|
||||
y1 = f(LOC(j), LOC(k), LOC(m-1));
|
||||
y2 = f(LOC(j), LOC(k), LOC(m+0));
|
||||
y3 = f(LOC(j), LOC(k), LOC(m+1));
|
||||
err = 0.5 * (y3 + y1) - y2;
|
||||
tse += err * err;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Apply adjustments and corrections */
|
||||
tse *= pow((res-1.0), 4.0); /* Aprox. geometric resolution factor */
|
||||
tse /= pow((res-2.0),(double)di); /* Average squared non-smoothness */
|
||||
|
||||
// tse /= (di * pow((res-2.0),(double)di)); /* Average squared non-smoothness */
|
||||
printf("Res %d, tse = %f\n",res,tse);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Transfer function */
|
||||
double trans(
|
||||
double *v, /* Pointer to first parameter */
|
||||
int luord, /* Number of parameters */
|
||||
double vv /* Source of value */
|
||||
) {
|
||||
double g;
|
||||
int ord;
|
||||
|
||||
for (ord = 0; ord < luord; ord++) {
|
||||
int nsec; /* Number of sections */
|
||||
double sec; /* Section */
|
||||
|
||||
g = v[ord]; /* Parameter */
|
||||
|
||||
nsec = ord + 1; /* Increase sections for each order */
|
||||
|
||||
vv *= (double)nsec;
|
||||
|
||||
sec = floor(vv);
|
||||
if (((int)sec) & 1)
|
||||
g = -g; /* Alternate action in each section */
|
||||
vv -= sec;
|
||||
if (g >= 0.0) {
|
||||
vv = vv/(g - g * vv + 1.0);
|
||||
} else {
|
||||
vv = (vv - g * vv)/(1.0 - g * vv);
|
||||
}
|
||||
vv += sec;
|
||||
vv /= (double)nsec;
|
||||
}
|
||||
|
||||
return vv;
|
||||
}
|
||||
1206
Argyll_V3.5.0/rspl/smtmpp.c
Normal file
1206
Argyll_V3.5.0/rspl/smtmpp.c
Normal file
File diff suppressed because it is too large
Load Diff
1219
Argyll_V3.5.0/rspl/smtnd.c
Normal file
1219
Argyll_V3.5.0/rspl/smtnd.c
Normal file
File diff suppressed because it is too large
Load Diff
349
Argyll_V3.5.0/rspl/spline.c
Normal file
349
Argyll_V3.5.0/rspl/spline.c
Normal file
@@ -0,0 +1,349 @@
|
||||
|
||||
/*
|
||||
* Argyll Color Management System
|
||||
* Multi-dimensional regularized spline data structure
|
||||
*
|
||||
* Spline forward interpolation support.
|
||||
*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 12/10/98
|
||||
*
|
||||
* Copyright 1998, Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
/* TTBD:
|
||||
Get rid of error() calls - return status instead
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "rspl_imp.h"
|
||||
#include "numlib.h"
|
||||
|
||||
int spline_interp_rspl(rspl *ss, co *cp);
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
/* Convention is to use:
|
||||
i to index grid points u.a
|
||||
n to index data points d.a
|
||||
e to index position dimension di
|
||||
f to index output function dimension fdi
|
||||
j misc and cube corners
|
||||
k misc
|
||||
*/
|
||||
|
||||
/* ====================================================== */
|
||||
|
||||
/* Init spline elements in rspl */
|
||||
void
|
||||
init_spline(rspl *s) {
|
||||
s->spline.nm = 0;
|
||||
s->spline.spline = 0;
|
||||
s->spline.magic = NULL;
|
||||
|
||||
s->spline_interp = spline_interp_rspl;
|
||||
}
|
||||
|
||||
/* Free up the spline interpolation info */
|
||||
void free_spline(
|
||||
rspl *s /* Pointer to rspl grid */
|
||||
) {
|
||||
if (s->spline.magic != NULL) {
|
||||
free(s->spline.magic);
|
||||
}
|
||||
s->spline.nm = 0;
|
||||
s->spline.spline = 0;
|
||||
}
|
||||
|
||||
/* ====================================================== */
|
||||
/* Setup functions first: */
|
||||
|
||||
/* Hermite spline, magic matrix */
|
||||
/* Indexes are: param powers 0, 1, 2, 3; Offset from base vertex 0,1; Dimension mask 0,1 */
|
||||
static double hmagic[4][2][2] = {
|
||||
{ { 1.0, 0.0}, { 0.0, 0.0} },
|
||||
{ { 0.0, 1.0}, { 0.0, 0.0} },
|
||||
{ {-3.0, -2.0}, { 3.0, -1.0} },
|
||||
{ { 2.0, 1.0}, {-2.0, 1.0} }
|
||||
};
|
||||
|
||||
/* Allocate and initialize tangency information for each grid point */
|
||||
static void make_tang(
|
||||
rspl *s /* Pointer to rspl grid */
|
||||
) {
|
||||
int i,p,j;
|
||||
int di = s->di;
|
||||
int fdi = s->fdi;
|
||||
int nig = s->g.no;
|
||||
float *tp; /* Pointer to tangent values */
|
||||
int nim, mix; /* Number in magic, magic index */
|
||||
float *tang_alloc, *tang; /* Tangency info */
|
||||
float *gt; /* Working grid point */
|
||||
|
||||
//printf("~~make_tang called\n");
|
||||
/* Organized as: tang[[grid]][di combs.][fdi] */
|
||||
/* Allocate space for tangency info */
|
||||
if ((tang_alloc = (float *) malloc(sizeof(float) * nig * (((1 << di) * fdi)+G_XTRA))) == NULL)
|
||||
error("rspl malloc failed - tangecy points");
|
||||
tang = tang_alloc + G_XTRA; /* Offset for flags and non-mono error */
|
||||
|
||||
/* For all grid points */
|
||||
for (tp = tang, gt = s->g.a, i = 0; i < nig; i++, gt += s->g.pss, tp += G_XTRA) {
|
||||
int ee;
|
||||
/* printf("\n~~ grid point %d\n",i); */
|
||||
|
||||
/* Look at surrounding grid points in combinations of +- 1 all dimensions */
|
||||
for (ee = 0; ee < (1 << di); ee++) {
|
||||
double av[MXRO]; /* average */
|
||||
int nia = 0; /* Number in average */
|
||||
int f, ec;
|
||||
|
||||
/* printf("Dim combo %d\n",ee); */
|
||||
/* special case - base value */
|
||||
if (ee == 0) {
|
||||
*((int *)(tp-2)) = *((int *)(gt-2)); /* Copy flags */
|
||||
tp[-1] = gt[-1]; /* Copy ink limit function value */
|
||||
for (f = 0; f < fdi; f++) {
|
||||
*tp++ = gt[f];
|
||||
/* printf("Tang value out %d = %f\n",f,tp[-1]); */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (f = 0; f < fdi; f++)
|
||||
av[f] = 0.0; /* Init average */
|
||||
/* For all surroundin grid points in this combination */
|
||||
for (ec = 0; ec < (1 << di); ec++) {
|
||||
int xo, io, sgn, e, ex;
|
||||
/* printf("~~checking out surrounding combo %d\n",ec); */
|
||||
if (ec & ~ee) {
|
||||
/* printf("~~being skipped\n"); */
|
||||
continue; /* Skip invalid combo */
|
||||
}
|
||||
xo = io = 0; /* Grid float offset */
|
||||
sgn = 1; /* Sign */
|
||||
ex = 0; /* Flag - No extrapolation */
|
||||
for (e = 0; e < di; e++) { /* For each dimension */
|
||||
/* printf("~~checking dimension %d\n",e); */
|
||||
if (!(ee & (1 << e))) {
|
||||
/* printf("~~dimension not active\n"); */
|
||||
continue; /* Dimension is not active */
|
||||
}
|
||||
if (ec & (1 << e)) {
|
||||
/* If + dimension is valid */
|
||||
if (((G_FL(gt,e) & 3) > 0) || (G_FL(gt,e) & 0x4)) {
|
||||
int to = s->g.fci[e]; /* +1 in dimension */
|
||||
io += to; /* real/pivot point */
|
||||
xo += to; /* reflected point */
|
||||
} else {
|
||||
ex = 1; /* Use extrapolation */
|
||||
xo -= s->g.fci[e]; /* -1 in dimension */
|
||||
}
|
||||
} else {
|
||||
sgn = -sgn; /* Reverse sign */
|
||||
/* If - dimension is valid */
|
||||
if (((G_FL(gt,e) & 3) > 0) || !(G_FL(gt,e) & 0x4)) {
|
||||
int to = -s->g.fci[e]; /* -1 in dimension */
|
||||
io += to; /* real/pivot point */
|
||||
xo += to; /* reflected point */
|
||||
} else {
|
||||
ex = 1; /* Use extrapolation */
|
||||
xo += s->g.fci[e]; /* +1 in dimension */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Add surrounding grid points value into the average */
|
||||
if (!ex) {
|
||||
for (f = 0; f < fdi; f++)
|
||||
av[f] += (double)sgn * gt[io + f];
|
||||
} else { /* Extrapolate point beyond edge */
|
||||
/* Use an extrapolation that tries to maintain curvature */
|
||||
for (f = 0; f < fdi; f++) {
|
||||
double v0,v1,v2;
|
||||
v0 = gt[io + f]; /* Pivot point */
|
||||
v1 = gt[xo + f]; /* Reflection of target in pivot */
|
||||
v2 = gt[2 * xo - io + f]; /* Reflection +2 */
|
||||
av[f] += (double)sgn * (3.0 * (v0 - v1) + v2);
|
||||
}
|
||||
}
|
||||
nia++;
|
||||
}
|
||||
for (f = 0; f < fdi; f++) {
|
||||
*tp++ = (float)(av[f]/(double)nia);
|
||||
/* printf("Tang value out %d = %f, average of %d\n",f,tp[-1],nia); */
|
||||
}
|
||||
} /* Next dimension combination */
|
||||
} /* Next grid point */
|
||||
|
||||
/* Create a full sized hermite magic matrix */
|
||||
/* Organized as: magic[4^di][2^di][2^di] */
|
||||
/* = [param power combos][cube vertex index][di combos], */
|
||||
/* but then only store non-zero weight values. */
|
||||
for (i = 0, nim = 1; i < di; nim *= 10, i++); /* Number of entries needed */
|
||||
if (s->spline.magic == NULL) { /* Allocate space for magic matrix info */
|
||||
if ((s->spline.magic = (magic_data *) malloc(sizeof(magic_data) * nim)) == NULL)
|
||||
error("rspl malloc failed - hermite magic matrix data");
|
||||
}
|
||||
|
||||
mix = 0;
|
||||
for (p = 0; p < (1 << (2 * di)); p++) { /* For all combinations of parameter powers */
|
||||
for (i = 0; i < (1 << di); i++) { /* For all corners of cube */
|
||||
for (j = 0; j < (1 << di); j++) { /* For all dimension combinations */
|
||||
int ii;
|
||||
double wgt = 1.0;
|
||||
for (ii = 0; ii < di; ii++) {
|
||||
wgt *= hmagic[3&(p>>(2*ii))][1&(i>>ii)][1&(j>>ii)];
|
||||
}
|
||||
if (wgt != 0.0) { /* record non-zero weight value */
|
||||
s->spline.magic[mix].p = p;
|
||||
s->spline.magic[mix].i = i;
|
||||
s->spline.magic[mix].j = fdi * j; /* Pre-scale */
|
||||
s->spline.magic[mix].wgt = (float)wgt;
|
||||
mix++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* mix should == nim! */
|
||||
s->spline.nm = nim;
|
||||
|
||||
/* Free basic grid info, and substitute tangency enhanced version */
|
||||
/* ~~~~!! need to free any other structures in rspl that depend on */
|
||||
/* ~~~~!! g.pss size, ie. rev stuff ??? */
|
||||
if (s->g.alloc != NULL)
|
||||
free((void *)s->g.alloc);
|
||||
|
||||
s->g.alloc = tang_alloc;
|
||||
s->g.a = tang;
|
||||
|
||||
/* Adjust index tables */
|
||||
s->g.pss = (1 << di) * fdi + G_XTRA;
|
||||
for (i = 0; i < di; i++)
|
||||
s->g.fci[i] = s->g.ci[i] * s->g.pss; /* In floats */
|
||||
for (i = 0; i < (1 << di); i++)
|
||||
s->g.fhi[i] = s->g.hi[i] * s->g.pss; /* In floats */
|
||||
|
||||
s->spline.spline = 1;
|
||||
|
||||
//printf("~~make_tang finished\n");
|
||||
}
|
||||
|
||||
/* Do a Hermite spline smooth interpolation based on the finest grid */
|
||||
/* (To do this more accurately, the data point interpolation within */
|
||||
/* the grid itteration should be of the same order. This increases */
|
||||
/* itteration complexity quite a bit, so we won't bother for the moment.) */
|
||||
/* This code is not optimised for speed. */
|
||||
/* Return 0 if OK, 1 if input was clipped to grid */
|
||||
int spline_interp_rspl(
|
||||
rspl *s,
|
||||
co *cp /* Input value and returned function value */
|
||||
) {
|
||||
int e,f,p,i;
|
||||
int di = s->di;
|
||||
int fdi = s->fdi;
|
||||
double ppw[MXRI][4]; /* Parameter powers of 0, 1, 2, 3 */
|
||||
float *ga[POW2MXRI]; /* Pointers to grid cubes data in tang[] */
|
||||
magic_data *tp; /* Pointer to items in magic matrix */
|
||||
int rv = 0;
|
||||
|
||||
/* printf("~~smooth interp called\n"); */
|
||||
|
||||
/* This is a restricted size function */
|
||||
if (di > MXRI)
|
||||
error("rspl: spline can't handle di = %d",di);
|
||||
if (fdi > MXRO)
|
||||
error("rspl: spline can't handle fdi = %d",fdi);
|
||||
|
||||
if (s->spline.spline == 0) /* Compute tangent info if it doesn't exist */
|
||||
make_tang(s);
|
||||
|
||||
/* Locate grid base point, and position with base cube */
|
||||
ga[0] = s->g.a; /* Base pointer of cube */
|
||||
for (e = 0; e < di; e++) {
|
||||
double t, pe;
|
||||
int mi, gres_1 = s->g.res[e]-1;
|
||||
|
||||
pe = cp->p[e];
|
||||
if (pe < s->g.l[e]) { /* Clip to grid */
|
||||
pe = s->g.l[e];
|
||||
rv = 1;
|
||||
}
|
||||
if (pe > s->g.h[e]) {
|
||||
pe = s->g.h[e];
|
||||
rv = 1;
|
||||
}
|
||||
t = (pe - s->g.l[e])/s->g.w[e];
|
||||
mi = (int)floor(t); /* Grid coordinate */
|
||||
if (mi < 0) /* Limit to valid cube base index range */
|
||||
mi = 0;
|
||||
else if (mi >= gres_1)
|
||||
mi = gres_1-1;
|
||||
ga[0] += s->g.fci[e] * mi; /* Add offset in dimen */
|
||||
t = t - (double)mi;; /* sub-cube offset = parameter in dimension e */
|
||||
ppw[e][0] = 1.0; /* Powers of parameter */
|
||||
ppw[e][1] = t;
|
||||
ppw[e][2] = t * t;
|
||||
ppw[e][3] = t * t * t;
|
||||
}
|
||||
|
||||
/* Compute indexes into cube corners in tangent array */
|
||||
for (i = 1; i < (1 << di); i++)
|
||||
ga[i] = ga[0] + s->g.fhi[i];
|
||||
|
||||
/* Now compute the output values */
|
||||
for (f = 0; f < fdi; f++) /* Zero output value sums */
|
||||
cp->v[f] = 0.0;
|
||||
|
||||
/* For all non-zero combinations of parameter powers */
|
||||
{
|
||||
double ppc = -1000.0; /* Parameter power combination */
|
||||
for (tp = s->spline.magic, p = -1; tp < &s->spline.magic[s->spline.nm]; tp++) {
|
||||
double wgt; /* Magic matrix weight */
|
||||
float *gp; /* Pointer to vertex data */
|
||||
|
||||
if (p != tp->p) { /* Param power needs re-calculating */
|
||||
int pp;
|
||||
p = tp->p;
|
||||
for (ppc = 1.0, pp = 0; pp < di; pp++)
|
||||
ppc *= ppw[pp][3&(p>>(2*pp))]; /* comb. of param powers value */
|
||||
}
|
||||
|
||||
wgt = tp->wgt * ppc; /* matrix times parameter */
|
||||
gp = ga[tp->i] + tp->j; /* Point to base of vertex data */
|
||||
for (f = 0; f < fdi; f++) /* For all output values */
|
||||
cp->v[f] += wgt * gp[f];
|
||||
}
|
||||
}
|
||||
/* printf("~~smooth interp finished\n"); */
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
654
Argyll_V3.5.0/rspl/stest.c
Normal file
654
Argyll_V3.5.0/rspl/stest.c
Normal file
@@ -0,0 +1,654 @@
|
||||
|
||||
/*
|
||||
* Scattered Data Interpolation
|
||||
* with multilevel B-splines
|
||||
* research.
|
||||
*
|
||||
* This is from the paper
|
||||
* "Scattered Data Interpolation with Multilevel B-Splines"
|
||||
* by Seungyong Lee, George Wolberg and Sung Yong Shin,
|
||||
*/
|
||||
|
||||
/*
|
||||
* Author: Graeme W. Gill
|
||||
* Date: 2001/1/1
|
||||
*
|
||||
* Copyright 2000 - 2001 Graeme W. Gill
|
||||
* All rights reserved.
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "../numeric/numlib.h"
|
||||
|
||||
|
||||
#ifndef NUMSUP_H
|
||||
void error(char *fmt, ...), warning(char *fmt, ...);
|
||||
#endif
|
||||
|
||||
#define MXDI 4
|
||||
#define MXDO 4
|
||||
|
||||
/* A control point */
|
||||
typedef struct {
|
||||
double p[MXDI];
|
||||
double v[MXDO];
|
||||
} co;
|
||||
|
||||
/* Neighborhood latice cache data */
|
||||
typedef struct {
|
||||
int c[MXDI]; /* Coordinate */
|
||||
int xo; /* Offset into srbs latice */
|
||||
double w; /* B-spline basis weight */
|
||||
} neigh;
|
||||
|
||||
/* Structure that represents a resolution level of B-splines */
|
||||
struct _srbs {
|
||||
struct _mrbs *p; /* Parent structure */
|
||||
int res; /* Basic resolution */
|
||||
int coi[MXDI]; /* Double increment for each input dimension into latice */
|
||||
double *lat; /* Control latice, extending from +/- 1 from 0..res-1 */
|
||||
double *_lat; /* Allocation base of lat */
|
||||
int lsize, loff; /* Number of doubles in _lat, offset of lat from _lat */
|
||||
double w[MXDI]; /* Input data cell width */
|
||||
neigh *n; /* Neighborhood latice cache */
|
||||
int nsize; /* Number of n entries */
|
||||
}; typedef struct _srbs srbs;
|
||||
|
||||
/* Structure that represents the whole scattered interpolation state */
|
||||
struct _mrbs {
|
||||
int di; /* Input dimensions */
|
||||
int fdi; /* Output dimensions */
|
||||
int tres; /* Target resolution */
|
||||
double smf; /* Smoothing factor */
|
||||
int npts; /* Number of data points */
|
||||
co *pts; /* Coordinate points */
|
||||
double l[MXDI], h[MXDI]; /* Input data range, cell width */
|
||||
srbs *s; /* Current B-spline latice */
|
||||
}; typedef struct _mrbs mrbs;
|
||||
|
||||
static void delete_srbs(srbs *s);
|
||||
|
||||
/* Create a new empty mrbs */
|
||||
static mrbs *new_mrbs(
|
||||
int di, /* Input dimensionality */
|
||||
int fdi, /* Output dimesionality */
|
||||
int res, /* Target resolution */
|
||||
double smf /* Smoothing factor */
|
||||
) {
|
||||
mrbs *p;
|
||||
if ((p = (mrbs *)malloc(sizeof(mrbs))) == NULL)
|
||||
error("Malloc mrbs failed");
|
||||
|
||||
p->di = di;
|
||||
p->fdi = fdi;
|
||||
p->tres = res;
|
||||
p->smf = smf;
|
||||
p->s = NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static void delete_mrbs(mrbs *p) {
|
||||
|
||||
if (p != NULL) {
|
||||
delete_srbs(p->s);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new empty srbs */
|
||||
static srbs *new_srbs(
|
||||
mrbs *p, /* Parent mrbs */
|
||||
int res /* Resolution of this srbs */
|
||||
) {
|
||||
srbs *s;
|
||||
int e, f;
|
||||
double *_lat, *lat; /* Latice base address */
|
||||
int ix, oe, oo[MXDI]; /* Neighborhood offset index, counter */
|
||||
|
||||
if ((s = (srbs *)malloc(sizeof(srbs))) == NULL)
|
||||
error("Malloc srbs failed");
|
||||
|
||||
s->p = p;
|
||||
s->res = res;
|
||||
|
||||
for (s->lsize = p->fdi, s->nsize = 1, e = 0; e < p->di; e++) {
|
||||
s->coi[e] = s->lsize; /* (double) increment in this input dimension */
|
||||
s->lsize *= (res + 2); /* Latice in 1D +/- 1 */
|
||||
s->nsize *= 4; /* Neighborhood of 4 */
|
||||
}
|
||||
|
||||
if ((s->_lat = (double *)malloc(s->lsize * sizeof(double))) == NULL)
|
||||
error("Malloc srbs latice failed");
|
||||
|
||||
/* Compute the base address */
|
||||
for (s->loff = 0, e = 0; e < p->di; e++) {
|
||||
s->loff += s->coi[e]; /* Offset by 1 in each input dimension */
|
||||
}
|
||||
s->lat = s->_lat + s->loff;
|
||||
|
||||
/* Figure the cell width */
|
||||
for (e = 0; e < p->di; e++)
|
||||
s->w[e] = (p->h[e] - p->l[e])/(res-1.0);
|
||||
|
||||
/* Setup neighborhood cache info */
|
||||
if ((s->n = (neigh *)malloc(s->nsize * sizeof(neigh))) == NULL)
|
||||
error("Malloc srbs neighborhood failed");
|
||||
|
||||
for (oe = 0; oe < p->di; oe++)
|
||||
oo[oe] = 0;
|
||||
|
||||
for(ix = oe = 0; oe < p->di; ix++) {
|
||||
int xo;
|
||||
for (xo = e = 0; e < p->di; e++) {
|
||||
s->n[ix].c[e] = oo[e];
|
||||
xo += s->coi[e] * oo[e]; /* Accumulate latice offset */
|
||||
}
|
||||
s->n[ix].xo = xo;
|
||||
s->n[ix].w = 0.0;
|
||||
|
||||
/* Increment destination offset counter */
|
||||
for (oe = 0; oe < p->di; oe++) {
|
||||
if (++oo[oe] <= 3) /* Counting from 0 ... 3 */
|
||||
break;
|
||||
oo[oe] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Destroy a srbs */
|
||||
static void delete_srbs(srbs *s) {
|
||||
if (s != NULL) {
|
||||
free(s->_lat);
|
||||
free(s->n);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump the 2D -> 1D contents of an srbs */
|
||||
static void dump_srbs(srbs *s) {
|
||||
int e, f;
|
||||
int ce, co[MXDI]; /* latice counter */
|
||||
mrbs *p = s->p; /* Parent object */
|
||||
|
||||
/* Init the counter */
|
||||
for (ce = 0; ce < p->di; ce++)
|
||||
co[ce] = -1;
|
||||
ce = 0;
|
||||
|
||||
f = 0;
|
||||
while(ce < p->di) {
|
||||
double v;
|
||||
int off = 0; /* Latice offset */
|
||||
for (e = 0; e < p->di; e++) {
|
||||
off += co[e] * s->coi[e]; /* Accumulate latice offset */
|
||||
}
|
||||
v = s->lat[off + f]; /* Value of this latice point */
|
||||
|
||||
printf("Latice at [%d][%d] = %f\n",co[1],co[0],v);
|
||||
|
||||
/* Increment the latice counter */
|
||||
for (ce = 0; ce < p->di; ce++) {
|
||||
if (++co[ce] <= s->res) /* Counting from -1 ... s->res */
|
||||
break;
|
||||
co[ce] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise an srbs with a linear approximation to the scattered data */
|
||||
static void linear_srbs(
|
||||
srbs *s
|
||||
) {
|
||||
int i, e, f;
|
||||
mrbs *p = s->p; /* Parent object */
|
||||
double **A; /* A matrix holding scattered data points */
|
||||
double *B; /* B matrix holding RHS & solution */
|
||||
|
||||
/* Allocate the matricies */
|
||||
B = dvector(0, p->npts-1);
|
||||
A = dmatrix(0, p->npts-1, 0, p->di);
|
||||
|
||||
/* For each output dimension, solve the linear equation coeficients */
|
||||
for (f = 0; f < p->fdi; f++) {
|
||||
int ce, co[MXDI]; /* latice counter */
|
||||
|
||||
/* Init A[][] with the scattered data points positions */
|
||||
/* Also init B[] with the value for this output dimension */
|
||||
for (i = 0; i < p->npts; i++) {
|
||||
for (e = 0; e < p->di; e++)
|
||||
A[i][e] = p->pts[i].p[e];
|
||||
A[i][e] = 1.0;
|
||||
B[i] = p->pts[i].v[f];
|
||||
}
|
||||
|
||||
/* Solve the equation A.x = b using SVD */
|
||||
/* (The w[] values are thresholded for best accuracy) */
|
||||
/* Return non-zero if no solution found */
|
||||
if (svdsolve(A, B, p->npts, p->di+1) != 0)
|
||||
error("SVD least squares failed");
|
||||
/* A[][] will have been changed, and B[] holds the p->di+1 coefficients */
|
||||
|
||||
/* Use the coefficients to initialise the srbs values */
|
||||
for (ce = 0; ce < p->di; ce++)
|
||||
co[ce] = -1;
|
||||
ce = 0;
|
||||
|
||||
while(ce < p->di) {
|
||||
double v = B[p->di]; /* Constant */
|
||||
int off = 0; /* Latice offset */
|
||||
for (e = 0; e < p->di; e++) {
|
||||
double lv;
|
||||
lv = p->l[e] + s->w[e] * co[e]; /* Input value for this latice location */
|
||||
v += B[e] * lv;
|
||||
off += co[e] * s->coi[e]; /* Accumulate latice offset */
|
||||
}
|
||||
s->lat[off + f] = v; /* Value of this latice point */
|
||||
|
||||
/* Increment the latice counter */
|
||||
for (ce = 0; ce < p->di; ce++) {
|
||||
if (++co[ce] <= s->res) /* Counting from -1 ... s->res */
|
||||
break;
|
||||
co[ce] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
free_dmatrix(A, 0, p->npts-1, 0, p->di);
|
||||
free_dvector(B, 0, p->npts-1);
|
||||
}
|
||||
|
||||
/* Do a latice refinement - upsample the current */
|
||||
/* source latice to the destination latice. */
|
||||
static void refine_srbs(
|
||||
srbs *ds, /* Destination srbs */
|
||||
srbs *ss /* Source srbs */
|
||||
) {
|
||||
mrbs *p = ss->p; /* Parent object */
|
||||
int ce, co[MXDI]; /* Source coordinate counter */
|
||||
int six; /* Source index */
|
||||
int dix; /* destination index */
|
||||
static double _wt[5] = { 1.0/8.0, 4.0/8.0, 6.0/8.0, 4.0/8.0, 1.0/8.0 };
|
||||
static double *wt = &_wt[2]; /* 1D Distribution weighting */
|
||||
|
||||
/* Zero the destination latice before accumulating values */
|
||||
for (dix = 0; dix < ds->lsize; dix++)
|
||||
ds->_lat[dix] = 0.0;
|
||||
|
||||
/* Now for each source latice entry, add weighted portions */
|
||||
/* to the associated destination points */
|
||||
|
||||
/* Init the source coordinate counter */
|
||||
for (ce = 0; ce < p->di; ce++)
|
||||
co[ce] = -1;
|
||||
ce = 0;
|
||||
six = -ss->loff;
|
||||
|
||||
while(ce < p->di) {
|
||||
int oe, oo[MXDI]; /* Destination offset counter */
|
||||
|
||||
//printf("Source coord %d %d, offset %d, value %f\n",co[0], co[1], six, ss->lat[six]);
|
||||
/* calc destination index, and init offest counter */
|
||||
for (dix = oe = 0; oe < p->di; oe++) {
|
||||
oo[oe] = -2;
|
||||
dix += co[oe] * 2 * ds->coi[oe]; /* Accumulate dest offset */
|
||||
}
|
||||
oe = 0;
|
||||
|
||||
//printf("Dest coord %d %d\n",co[0] * 2, co[1] * 2);
|
||||
/* For all the offsets from the destination point */
|
||||
while(oe < p->di) {
|
||||
int e, f, dixo; /* Destination index offset */
|
||||
double w = 1.0; /* Weighting */
|
||||
|
||||
//printf("dest offset %d %d\n",oo[0], oo[1]);
|
||||
/* Compute dest index offset, and check that we are not outside the destination */
|
||||
for (dixo = e = 0; e < p->di; e++) {
|
||||
int x = co[e] * 2 + oo[e]; /* dest coord */
|
||||
dixo += oo[e] * ds->coi[e]; /* Accumulate dest offset */
|
||||
//printf("x[%d] = %d\n",e, x);
|
||||
w *= wt[oo[e]]; /* Compute distribution weighting */
|
||||
if (x < -1 || x > ds->res)
|
||||
break; /* No good */
|
||||
}
|
||||
if (e >= p->di) { /* We are within the destination latice */
|
||||
//if ((co[0] * 2 + oo[0]) == 0 && (co[1] * 2 + oo[1]) == 0) {
|
||||
//printf("Source coord %d %d, offset %d, value %f\n",co[0], co[1], six, ss->lat[six]);
|
||||
//printf("Dest coord %d %d ix %d, weight %f\n",co[0] * 2 + oo[0], co[1] * 2 + oo[1], dix+dixo, w);
|
||||
//}
|
||||
|
||||
for (f = 0; f < p->fdi; f++) { /* Distribute weighted values */
|
||||
double v = ss->lat[six + f];
|
||||
//if ((co[0] * 2 + oo[0]) == 0 && (co[1] * 2 + oo[1]) == 0)
|
||||
//printf("Value being dist %f, weighted value %f\n", v, v * w);
|
||||
ds->lat[dix + dixo + f] += v * w;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment destination offset counter */
|
||||
for (oe = 0; oe < p->di; oe++) {
|
||||
if (++oo[oe] <= 2) /* Counting from -2 ... +2 */
|
||||
break;
|
||||
oo[oe] = -2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the source index and coordinat counter */
|
||||
six += p->fdi;
|
||||
for (ce = 0; ce < p->di; ce++) {
|
||||
if (++co[ce] <= ss->res) /* Counting from -1 ... ss->res */
|
||||
break;
|
||||
co[ce] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the Cubic B-spline weightings for a given t */
|
||||
void basis(double b[4], double t) {
|
||||
double _t3, _t2, _t1, _3t3, _3t2, _3t1, _6t2;
|
||||
|
||||
_t1 = t/6.0;
|
||||
_t2 = _t1 * _t1;
|
||||
_t3 = _t2 * _t1;
|
||||
_3t1 = 3.0 * _t1;
|
||||
_3t2 = 3.0 * _t2;
|
||||
_3t3 = 3.0 * _t3;
|
||||
_6t2 = 6.0 * _t2;
|
||||
|
||||
b[0] = - _t3 + _3t2 - _3t1 + 1.0/6.0;
|
||||
b[1] = _3t3 - _6t2 + 4.0/6.0;
|
||||
b[2] = -_3t3 + _3t2 + _3t1 + 1.0/6.0;
|
||||
b[3] = _t3;
|
||||
}
|
||||
|
||||
|
||||
/* Improve an srbs to make it closer to the scattered data */
|
||||
static void improve_srbs(
|
||||
srbs *s
|
||||
) {
|
||||
int i, e, f;
|
||||
mrbs *p = s->p; /* Parent object */
|
||||
double *delta; /* Delta accumulation */
|
||||
double *omega; /* Omega accumulation */
|
||||
|
||||
/* Allocate temporary accumulation arrays */
|
||||
if ((delta = (double *)calloc(sizeof(double), s->lsize)) == NULL)
|
||||
error("Malloc srbs temp latice failed");
|
||||
delta += s->loff;
|
||||
if ((omega = (double *)calloc(sizeof(double), s->lsize)) == NULL)
|
||||
error("Malloc srbs temp latice failed");
|
||||
omega += s->loff;
|
||||
|
||||
/* For each scattered data point */
|
||||
for (i = 0; i < p->npts; i++) {
|
||||
int ix; /* Latice index of base of neighborhood */
|
||||
double b[MXDI][4]; /* B-spline basis factors for each dimension */
|
||||
double sws; /* Sum of all the basis factors squared */
|
||||
double ve[MXDO]; /* Current output value error */
|
||||
int nn; /* Neighbor counter */
|
||||
|
||||
/* Figure out our neighborhood */
|
||||
for (ix = e = 0; e < p->di; e++) {
|
||||
int x;
|
||||
double t, sp, fp;
|
||||
sp = (p->pts[i].p[e] - p->l[e])/s->w[e]; /* Scaled position */
|
||||
fp = floor(sp);
|
||||
x = (int)(fp - 1.0); /* Grid coordinate */
|
||||
ix += s->coi[e] * x; /* Accume latice offset */
|
||||
t = sp - fp; /* Spline parameter */
|
||||
basis(b[e], t); /* Compute basis function values */
|
||||
}
|
||||
|
||||
/* Compute the grid basis weight functions, */
|
||||
/* the sum of the weights squared, and the current */
|
||||
/* output value estimate. */
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
ve[f] = p->pts[i].v[f]; /* Target output value */
|
||||
for (sws = 0.0, nn = 0; nn < s->nsize; nn++) {
|
||||
double w;
|
||||
for (w = 1.0, e = 0; e < p->di; e++)
|
||||
w *= b[e][s->n[nn].c[e]];
|
||||
s->n[nn].w = w; /* cache weighting */
|
||||
sws += w * w;
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
ve[f] -= w * s->lat[ix + s->n[nn].xo + f]; /* Subtract current aprox value */
|
||||
}
|
||||
printf("Error at point %d = %f\n",i,ve[0]);
|
||||
|
||||
/* Accumulate the delta and omega factors */
|
||||
/* for this resolutions improvement. */
|
||||
for (nn = 0; nn < s->nsize; nn++) {
|
||||
double ws, ww, w = s->n[nn].w;
|
||||
int xo = ix + s->n[nn].xo; /* Latice offset */
|
||||
ww = w * w;
|
||||
ws = ww * w/sws; /* Scale factor for delta */
|
||||
omega[xo] += ww; /* Accumulate omega */
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
delta[xo + f] += ws * ve[f]; /* Accumulate delta */
|
||||
printf("Distributing omega %f to %d %d\n",ww,s->n[nn].c[0],s->n[nn].c[1]);
|
||||
printf("Distributing delta %f to %d %d\n",ws * ve[0],s->n[nn].c[0],s->n[nn].c[1]);
|
||||
}
|
||||
}
|
||||
|
||||
omega -= s->loff; /* Base them back to -1 corner */
|
||||
delta -= s->loff;
|
||||
|
||||
/* Go through the delta and omega arrays, */
|
||||
/* compute and add the refinements to the current */
|
||||
/* B-spline control latice. */
|
||||
for (i = 0; i < s->lsize; i++) {
|
||||
double om = omega[i];
|
||||
if (om != 0.0) {
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
s->_lat[i] += delta[i + f]/om;
|
||||
printf("Adjusting latice index %d by %f to give %f\n",i, delta[i]/om, s->_lat[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Done with temporary arrays */
|
||||
free(omega);
|
||||
free(delta);
|
||||
}
|
||||
|
||||
/* Return the interpolated value for a given point */
|
||||
/* Return NZ if input point is out of range */
|
||||
static int lookup_srbs(
|
||||
mrbs *p,
|
||||
co *c /* Point to interpolate */
|
||||
) {
|
||||
srbs *s = p->s;
|
||||
int e, f;
|
||||
int ix; /* Latice index of base of neighborhood */
|
||||
double b[MXDI][4]; /* B-spline basis factors for each dimension */
|
||||
int nn; /* Neighbor counter */
|
||||
|
||||
/* Figure out our neighborhood */
|
||||
for (ix = e = 0; e < p->di; e++) {
|
||||
int x;
|
||||
double t, sp, fp;
|
||||
sp = c->p[e];
|
||||
if (sp < p->l[e] || sp > p->h[e])
|
||||
return 1;
|
||||
sp = (sp - p->l[e])/s->w[e]; /* Scaled position */
|
||||
fp = floor(sp);
|
||||
x = (int)(fp - 1.0); /* Grid coordinate */
|
||||
ix += s->coi[e] * x; /* Accume latice offset */
|
||||
t = sp - fp; /* Spline parameter */
|
||||
basis(b[e], t); /* Compute basis function values */
|
||||
}
|
||||
|
||||
/* Compute the the current output value. */
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
c->v[f] = 0.0;
|
||||
for (nn = 0; nn < s->nsize; nn++) {
|
||||
double w;
|
||||
for (w = 1.0, e = 0; e < p->di; e++)
|
||||
w *= b[e][s->n[nn].c[e]];
|
||||
for (f = 0; f < p->fdi; f++)
|
||||
c->v[f] += w * s->lat[ix + s->n[nn].xo + f]; /* Accume spline value */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Take a list of scattered data points, */
|
||||
/* and setup the mrbs. */
|
||||
void set_mrbs(
|
||||
mrbs *p, /* mrbs to set up */
|
||||
co *pts, /* scattered data points (taken) */
|
||||
int npts, /* number of scattered data points */
|
||||
double *l, /* Input data range, low (May be NULL) */
|
||||
double *h /* Input data range, high (May be NULL) */
|
||||
) {
|
||||
int res;
|
||||
int i, e, f;
|
||||
srbs *s0 = NULL, *s1;
|
||||
|
||||
/* Establish the input data range */
|
||||
for (e = 0; e < p->di; e++) {
|
||||
if (l == NULL)
|
||||
p->l[e] = 1e60;
|
||||
else
|
||||
p->l[e] = l[e];
|
||||
if (h == NULL)
|
||||
p->h[e] = -1e60;
|
||||
else
|
||||
p->h[e] = h[e];
|
||||
}
|
||||
for (i = 0; i < npts; i++) {
|
||||
for (e = 0; e < p->di; e++) {
|
||||
if (pts[i].p[e] < p->l[e])
|
||||
p->l[e] = pts[i].p[e];
|
||||
if (pts[i].p[e] > p->h[e])
|
||||
p->h[e] = pts[i].p[e];
|
||||
}
|
||||
}
|
||||
|
||||
/* Take ownership the data */
|
||||
p->pts = pts;
|
||||
p->npts = npts;
|
||||
|
||||
/* Create an initial srbs */
|
||||
res = 2;
|
||||
if ((s1 = new_srbs(p, 2)) == NULL)
|
||||
error("new_srbs failed");
|
||||
|
||||
/* Set it up with a linear first approximation */
|
||||
linear_srbs(s1);
|
||||
dump_srbs(s1);
|
||||
|
||||
/* Build up the resolution */
|
||||
for (res = 2 * res -1; res < p->tres; res = 2 * res -1) {
|
||||
|
||||
printf("~1 doing resolution %d\n",res);
|
||||
delete_srbs(s0);
|
||||
s0 = s1;
|
||||
if ((s1 = new_srbs(p, res)) == NULL)
|
||||
error("new_srbs failed");
|
||||
|
||||
refine_srbs(s1, s0);
|
||||
dump_srbs(s1);
|
||||
improve_srbs(s1);
|
||||
}
|
||||
|
||||
delete_srbs(s0);
|
||||
p->s = s1; /* Final resolution */
|
||||
}
|
||||
|
||||
|
||||
/* - - - - - - - - - - - - - - - - */
|
||||
|
||||
/* Some test points */
|
||||
#define NP 5
|
||||
co tpts[NP] = {
|
||||
{ { 1, 5 }, { 3 } },
|
||||
{ { 2, 9 }, { 6 } },
|
||||
{ { 8, 0 }, { 1 } },
|
||||
{ { 5, 4 }, { 10 } },
|
||||
{ { 3, 9 }, { 4 } }
|
||||
};
|
||||
|
||||
#define FRES 33
|
||||
|
||||
int
|
||||
main(void) {
|
||||
double ll[MXDI], hh[MXDI];
|
||||
mrbs *p;
|
||||
int i;
|
||||
|
||||
#ifdef NEVER /* Make points be on a plane */
|
||||
{
|
||||
for (i = 0; i < NP; i++) {
|
||||
tpts[i].v[0] = 0.5 * tpts[i].p[0] + 0.7 * tpts[i].p[1] + 3.0;
|
||||
printf("%f, %f -> %f\n", tpts[i].p[0], tpts[i].p[1], tpts[i].v[0]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
error_program = "stest";
|
||||
|
||||
printf("Starting test\n");
|
||||
p = new_mrbs(2, 1, FRES, 1.0);
|
||||
|
||||
ll[0] = 0.0;
|
||||
ll[1] = 0.0;
|
||||
hh[0] = 10.0;
|
||||
hh[1] = 10.0;
|
||||
set_mrbs(p, tpts, NP, ll, hh);
|
||||
|
||||
printf("Interpolation setup\n");
|
||||
|
||||
/* Check out the accuracy */
|
||||
for (i = 0; i < NP; i++) {
|
||||
co tp;
|
||||
tp.p[0] = tpts[i].p[0];
|
||||
tp.p[1] = tpts[i].p[1];
|
||||
if (lookup_srbs(p, &tp))
|
||||
printf("Point %d, %f %f outside domain\n",i,tpts[i].p[0],tpts[i].p[1]);
|
||||
else {
|
||||
printf("Point %d has value %f, should be %f\n",i,tp.v[0], tpts[i].v[0]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Test done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NUMSUP_H
|
||||
/* Basic printf type error() and warning() routines */
|
||||
|
||||
void
|
||||
error(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fprintf(stderr,"stest: Error - ");
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
void
|
||||
warning(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fprintf(stderr,"stest: Warning - ");
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#endif /* NUMSUP_H */
|
||||
|
||||
1010
Argyll_V3.5.0/rspl/t2d.c
Normal file
1010
Argyll_V3.5.0/rspl/t2d.c
Normal file
File diff suppressed because it is too large
Load Diff
519
Argyll_V3.5.0/rspl/t2ddf.c
Normal file
519
Argyll_V3.5.0/rspl/t2ddf.c
Normal file
@@ -0,0 +1,519 @@
|
||||
/************************************************/
|
||||
/* Test RSPL in 2D with a weak default function */
|
||||
/************************************************/
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 20/11/2005
|
||||
* Derived from cmatch.c
|
||||
* Copyright 1995, 2005 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
|
||||
#define DEBUG
|
||||
#define DETAILED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "aconfig.h"
|
||||
#include "rspl.h"
|
||||
#include "tiffio.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
#ifdef NEVER
|
||||
#define INTERP spline_interp
|
||||
#else
|
||||
#define INTERP interp
|
||||
#endif
|
||||
|
||||
#ifdef NEVER
|
||||
FILE *verbose_out = stdout;
|
||||
int verbose_level = 6; /* Current verbosity level */
|
||||
/* 0 = none */
|
||||
/* !0 = diagnostics */
|
||||
#endif /* NEVER */
|
||||
|
||||
/* rspl flags */
|
||||
#define FLAGS (0 /* | RSPL_EXTRAFIT */)
|
||||
|
||||
#define PLOTRES 256
|
||||
#define WIDTH 400 /* Raster size */
|
||||
#define HEIGHT 400
|
||||
|
||||
#define MAX_ITS 500
|
||||
#define IT_TOL 0.0005
|
||||
#define GRES0 25 /* Default resolutions */
|
||||
#define GRES1 25
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
/* two correction points along x = 0.5 */
|
||||
co test_points1[] = {
|
||||
// {{ 0.5,0.325 },{ 0.4 }}, /* 0 */
|
||||
// {{ 0.5,0.625 },{ 0.70 }} /* 1 */
|
||||
{{ 0.4,0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.4,0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.5,0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.5,0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.6,0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.6,0.625 },{ 0.8 }} /* 1 */
|
||||
};
|
||||
|
||||
#ifdef NEVER
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
void error(char *fmt, ...), warning(char *fmt, ...), verbose(int level, char *fmt, ...);
|
||||
#else
|
||||
#include <varargs.h>
|
||||
void error(), warning(), verbose();
|
||||
#endif
|
||||
#endif /* NEVER */
|
||||
|
||||
void write_rgb_tiff(char *name, int width, int height, unsigned char *data);
|
||||
|
||||
/* Weak default function */
|
||||
/* Linear along y, independent of x */
|
||||
static void wfunc(void *cbntx, double *out, double *in) {
|
||||
out[0] = in[1];
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 2D rspl interpolation with weak default function\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: t2d [options]\n");
|
||||
fprintf(stderr," -t n Test set:\n");
|
||||
fprintf(stderr," * 1 = two points along x\n");
|
||||
fprintf(stderr," -w wweight Set weak default function weight (default 1.0)\n");
|
||||
fprintf(stderr," -r resx,resy Set grid resolutions (def %d %d)\n",GRES0,GRES1);
|
||||
fprintf(stderr," -h Test half scale resolution too\n");
|
||||
fprintf(stderr," -q Test quarter scale resolution too\n");
|
||||
fprintf(stderr," -s Test symetric smoothness\n");
|
||||
fprintf(stderr," -p plot 3 slices, x = 0.5, y = 0.5, x = y\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
rspl *rss; /* Regularized spline structure */
|
||||
rspl *rss2 = NULL; /* Regularized spline structure at half resolution */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
int gres2[MXDI];
|
||||
double avgdev[MXDO];
|
||||
co *test_points = test_points1;
|
||||
int npoints = sizeof(test_points1)/sizeof(co);
|
||||
double wweight = 1.0;
|
||||
int dosym = 0;
|
||||
int doplot = 0;
|
||||
int doh = 0;
|
||||
int doq = 0;
|
||||
int rsv;
|
||||
int flags = FLAGS;
|
||||
|
||||
low[0] = 0.0;
|
||||
low[1] = 0.0;
|
||||
high[0] = 1.0;
|
||||
high[1] = 1.0;
|
||||
gres[0] = GRES0;
|
||||
gres[1] = GRES1;
|
||||
avgdev[0] = 0.0;
|
||||
avgdev[1] = 0.0;
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* test set */
|
||||
else if (argv[fa][1] == 't' || argv[fa][1] == 'T') {
|
||||
int ix;
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
ix = atoi(na);
|
||||
switch (ix) {
|
||||
case 1:
|
||||
test_points = test_points1;
|
||||
npoints = sizeof(test_points1)/sizeof(co);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
} else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
wweight = atof(na);
|
||||
|
||||
} else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
if (sscanf(na, " %d,%d ", &gres[0], &gres[1]) != 2)
|
||||
usage();
|
||||
|
||||
} else if (argv[fa][1] == 'h' || argv[fa][1] == 'H') {
|
||||
doh = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'q' || argv[fa][1] == 'Q') {
|
||||
doh = 1;
|
||||
doq = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'p' || argv[fa][1] == 'P') {
|
||||
doplot = 1;
|
||||
|
||||
} else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
|
||||
dosym = 1;
|
||||
|
||||
} else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (dosym)
|
||||
flags |= RSPL_SYMDOMAIN;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, 2, 1);
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss->fit_rspl_df(rss,
|
||||
flags, /* Non-mon and clip flags */
|
||||
test_points, /* Test points */
|
||||
npoints, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
1.0, /* Smoothing */
|
||||
avgdev, /* Average Deviation */
|
||||
NULL, /* iwidth */
|
||||
wweight, /* weak function weight */
|
||||
NULL, /* No context */
|
||||
wfunc /* Weak function */
|
||||
);
|
||||
|
||||
if (doh) {
|
||||
|
||||
if (doq) {
|
||||
gres2[0] = gres[0]/4;
|
||||
gres2[1] = gres[1]/4;
|
||||
} else {
|
||||
gres2[0] = gres[0]/2;
|
||||
gres2[1] = gres[1]/2;
|
||||
}
|
||||
|
||||
rss2 = new_rspl(RSPL_NOFLAGS, 2, 1);
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss2->fit_rspl_df(rss2,
|
||||
flags, /* Non-mon and clip flags */
|
||||
test_points, /* Test points */
|
||||
npoints, /* Number of test points */
|
||||
low, high, gres2, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
1.0, /* Smoothing */
|
||||
avgdev, /* Average Deviation */
|
||||
NULL, /* iwidth */
|
||||
wweight, /* weak function weight */
|
||||
NULL, /* No context */
|
||||
wfunc /* Weak function */
|
||||
);
|
||||
}
|
||||
|
||||
/* Test the interpolation in 2D */
|
||||
for (rsv = 0; rsv <= doh; rsv++) {
|
||||
double x1 = -0.2;
|
||||
double x2 = 1.2;
|
||||
double y1 = -0.2;
|
||||
double y2 = 1.2;
|
||||
double min = -0.0;
|
||||
double max = 1.0;
|
||||
rspl *rs;
|
||||
unsigned char pa[HEIGHT][WIDTH][3];
|
||||
co tco; /* Test point */
|
||||
double sx,sy;
|
||||
int i,j,k;
|
||||
|
||||
if (rsv == 0)
|
||||
rs = rss;
|
||||
else
|
||||
rs = rss2;
|
||||
|
||||
sx = (x2 - x1)/(double)WIDTH;
|
||||
sy = (y2 - y1)/(double)HEIGHT;
|
||||
|
||||
for (j=0; j < HEIGHT; j++) {
|
||||
tco.p[1] = (double)((HEIGHT-1) - j) * sy + y1;
|
||||
for (i=0; i < WIDTH; i++) {
|
||||
tco.p[0] = (double)i * sx + x1;
|
||||
if (rs->INTERP(rs, &tco)) {
|
||||
pa[j][i][0] = 0; /* Out of bounds in green */
|
||||
pa[j][i][1] = 100;
|
||||
pa[j][i][2] = 0;
|
||||
} else {
|
||||
int m;
|
||||
/* printf("%d %d, %f %f returned %f\n",i,j,tco.p[0],tco.p[1],tco.v[0]); */
|
||||
m = (int)((255.0 * (tco.v[0] - min)/(max - min)) + 0.5);
|
||||
if (m < 0) {
|
||||
pa[j][i][0] = 20; /* Dark blue */
|
||||
pa[j][i][1] = 20;
|
||||
pa[j][i][2] = 50;
|
||||
} else if (m > 255) {
|
||||
pa[j][i][0] = 230; /* Light blue */
|
||||
pa[j][i][1] = 230;
|
||||
pa[j][i][2] = 255;
|
||||
} else {
|
||||
pa[j][i][0] = m; /* Level in grey */
|
||||
pa[j][i][1] = m;
|
||||
pa[j][i][2] = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark vertices in red */
|
||||
for(k = 0; k < npoints; k++) {
|
||||
j = (int)((HEIGHT * (y2 - test_points[k].p[1])/(y2 - y1)) + 0.5);
|
||||
i = (int)((WIDTH * (test_points[k].p[0] - x1)/(x2 - x1)) + 0.5);
|
||||
pa[j][i][0] = 255;
|
||||
pa[j][i][1] = 0;
|
||||
pa[j][i][2] = 0;
|
||||
}
|
||||
write_rgb_tiff(rsv == 0 ? "t2d.tif" : "t2dh.tif" ,WIDTH,HEIGHT,(unsigned char *)pa);
|
||||
}
|
||||
|
||||
/* Plot out 3 slices */
|
||||
if (doplot) {
|
||||
int slice;
|
||||
|
||||
for (slice = 0; slice < 3; slice++) {
|
||||
co tp; /* Test point */
|
||||
double x[PLOTRES];
|
||||
double ya[PLOTRES];
|
||||
double yb[PLOTRES];
|
||||
double xx,yy;
|
||||
double x1,x2,y1,y2;
|
||||
double sx,sy;
|
||||
int i,n;
|
||||
|
||||
/* Set up slice to plot */
|
||||
if (slice == 0) {
|
||||
x1 = 0.5; y1 = 0.0;
|
||||
x2 = 0.5; y2 = 1.0;
|
||||
n = PLOTRES;
|
||||
printf("Plot along y at x = 0.5\n");
|
||||
} else if (slice == 1) {
|
||||
x1 = 0.0; y1 = 0.5;
|
||||
x2 = 1.0; y2 = 0.5;
|
||||
n = PLOTRES;
|
||||
printf("Plot along x at y = 0.5\n");
|
||||
} else {
|
||||
x1 = 0.0; y1 = 0.0;
|
||||
x2 = 1.0; y2 = 1.0;
|
||||
n = PLOTRES;
|
||||
printf("Plot along x = y\n");
|
||||
}
|
||||
|
||||
sx = (x2 - x1)/n;
|
||||
sy = (y2 - y1)/n;
|
||||
|
||||
xx = x1;
|
||||
yy = y1;
|
||||
for (i = 0; i < n; i++) {
|
||||
double vv = i/(n-1.0);
|
||||
x[i] = vv;
|
||||
tp.p[0] = xx;
|
||||
tp.p[1] = yy;
|
||||
|
||||
if (rss->INTERP(rss, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
ya[i] = tp.v[0];
|
||||
|
||||
if (doh) {
|
||||
if (rss2->INTERP(rss2, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
yb[i] = tp.v[0];
|
||||
}
|
||||
|
||||
xx += sx;
|
||||
yy += sy;
|
||||
}
|
||||
|
||||
/* Plot the result */
|
||||
if (doh)
|
||||
do_plot(x,ya,yb,NULL,n);
|
||||
else
|
||||
do_plot(x,ya,NULL,NULL,n);
|
||||
}
|
||||
}
|
||||
|
||||
/* Report the fit */
|
||||
{
|
||||
co tco; /* Test point */
|
||||
int k;
|
||||
double avg = 0;
|
||||
double max = 0.0;
|
||||
|
||||
for(k = 0; k < npoints; k++) {
|
||||
double err;
|
||||
tco.p[0] = test_points[k].p[0];
|
||||
tco.p[1] = test_points[k].p[1];
|
||||
rss->INTERP(rss, &tco);
|
||||
|
||||
err = tco.v[0] - test_points[k].v[0];
|
||||
err = fabs(err);
|
||||
|
||||
avg += err;
|
||||
if (err > max)
|
||||
max = err;
|
||||
}
|
||||
avg /= (double)npoints;
|
||||
printf("Max error %f%%, average %f%%\n",100.0 * max, 100.0 * avg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------- */
|
||||
/* Tiff diagnostic output */
|
||||
|
||||
void
|
||||
write_rgb_tiff(
|
||||
char *name,
|
||||
int width,
|
||||
int height,
|
||||
unsigned char *data
|
||||
) {
|
||||
int y;
|
||||
unsigned char *dp;
|
||||
TIFF *tif;
|
||||
|
||||
if ((tif = TIFFOpen(name, "w")) == NULL) {
|
||||
fprintf(stderr,"Failed to open output TIFF file '%s'\n",name);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
|
||||
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
|
||||
|
||||
for (dp = data, y = 0; y < height; y++, dp += 3 * width) {
|
||||
if (TIFFWriteScanline(tif, (tdata_t)dp, y, 0) < 0) {
|
||||
fprintf(stderr,"WriteScanline Failed at line %d\n",y);
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
(void) TIFFClose(tif);
|
||||
}
|
||||
|
||||
#ifdef NEVER
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Basic printf type error() and warning() routines */
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
error(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
error(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Error - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stdout);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
warning(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
warning(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Warning - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
verbose(int level, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
verbose(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list args;
|
||||
int level;
|
||||
char *fmt;
|
||||
va_start(args);
|
||||
level = va_arg(args, int);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
if (verbose_level >= level)
|
||||
{
|
||||
fprintf(verbose_out,"cmatch: ");
|
||||
vfprintf(verbose_out, fmt, args);
|
||||
fprintf(verbose_out, "\n");
|
||||
fflush(verbose_out);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
#endif /* NEVER */
|
||||
899
Argyll_V3.5.0/rspl/t3d.c
Normal file
899
Argyll_V3.5.0/rspl/t3d.c
Normal file
@@ -0,0 +1,899 @@
|
||||
/************************************************/
|
||||
/* Test RSPL in 3D */
|
||||
/************************************************/
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 22/4/96
|
||||
* Derived from cmatch.c
|
||||
* Copyright 1995 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
|
||||
#define DEBUG
|
||||
#define DETAILED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "aconfig.h"
|
||||
#include "rspl.h"
|
||||
#include "tiffio.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
#ifdef NEVER
|
||||
#define INTERP spline_interp
|
||||
#else
|
||||
#define INTERP interp
|
||||
#endif
|
||||
|
||||
#ifdef NEVER
|
||||
FILE *verbose_out = stdout;
|
||||
int verbose_level = 6; /* Current verbosity level */
|
||||
/* 0 = none */
|
||||
/* !0 = diagnostics */
|
||||
#endif /* NEVER */
|
||||
|
||||
#define PLOTRES 256
|
||||
#define WIDTH 400 /* Raster size */
|
||||
#define HEIGHT 400
|
||||
|
||||
#define MAX_ITS 500
|
||||
#define IT_TOL 0.0005
|
||||
#define GRES0 33 /* Default rspl resolutions */
|
||||
#define GRES1 33
|
||||
#define GRES2 33
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
//double t1xa[PNTS] = { 0.2, 0.25, 0.30, 0.35, 0.40, 0.44, 0.48, 0.51, 0.64, 0.75 };
|
||||
//double t1ya[PNTS] = { 0.3, 0.35, 0.4, 0.41, 0.42, 0.46, 0.5, 0.575, 0.48, 0.75 };
|
||||
|
||||
/* 1D test function repeated 3 times along x = y = 0.5 */
|
||||
co test_points1[] = {
|
||||
{{ 0.4,0.4,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.4,0.4,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.4,0.4,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.4,0.4,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.4,0.4,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.4,0.4,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.4,0.4,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.4,0.4,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.4,0.4,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.4,0.4,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
{{ 0.5,0.4,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.5,0.4,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.5,0.4,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.5,0.4,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.5,0.4,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.5,0.4,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.5,0.4,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.5,0.4,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.5,0.4,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.5,0.4,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
{{ 0.6,0.4,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.6,0.4,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.6,0.4,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.6,0.4,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.6,0.4,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.6,0.4,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.6,0.4,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.6,0.4,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.6,0.4,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.6,0.4,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
|
||||
{{ 0.4,0.5,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.4,0.5,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.4,0.5,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.4,0.5,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.4,0.5,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.4,0.5,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.4,0.5,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.4,0.5,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.4,0.5,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.4,0.5,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
{{ 0.5,0.5,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.5,0.5,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.5,0.5,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.5,0.5,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.5,0.5,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.5,0.5,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.5,0.5,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.5,0.5,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.5,0.5,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.5,0.5,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
{{ 0.6,0.5,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.6,0.5,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.6,0.5,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.6,0.5,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.6,0.5,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.6,0.5,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.6,0.5,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.6,0.5,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.6,0.5,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.6,0.5,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
|
||||
{{ 0.4,0.6,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.4,0.6,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.4,0.6,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.4,0.6,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.4,0.6,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.4,0.6,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.4,0.6,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.4,0.6,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.4,0.6,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.4,0.6,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
{{ 0.5,0.6,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.5,0.6,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.5,0.6,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.5,0.6,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.5,0.6,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.5,0.6,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.5,0.6,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.5,0.6,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.5,0.6,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.5,0.6,0.75 },{ 0.75 }}, /* 9 */
|
||||
|
||||
{{ 0.6,0.6,0.20 },{ 0.30 }}, /* 0 */
|
||||
{{ 0.6,0.6,0.25 },{ 0.35 }}, /* 1 */
|
||||
{{ 0.6,0.6,0.30 },{ 0.40 }}, /* 2 */
|
||||
{{ 0.6,0.6,0.35 },{ 0.41 }}, /* 3 */
|
||||
{{ 0.6,0.6,0.40 },{ 0.42 }}, /* 4 */
|
||||
{{ 0.6,0.6,0.44 },{ 0.46 }}, /* 5 */
|
||||
{{ 0.6,0.6,0.48 },{ 0.50 }}, /* 6 */
|
||||
{{ 0.6,0.6,0.51 },{ 0.575 }}, /* 7 */
|
||||
{{ 0.6,0.6,0.64 },{ 0.48 }}, /* 8 */
|
||||
{{ 0.6,0.6,0.75 },{ 0.75 }} /* 9 */
|
||||
};
|
||||
|
||||
/* function */
|
||||
co test_points2[] = {
|
||||
{{ 0.50915, 0.50936, 0.57048 },{ 0.36209169635 }},
|
||||
{{ 0.85943, 0.84331, 0.81487 },{ 0.91571493013 }},
|
||||
{{ 0.11381, 0.80378, 0.82951 },{ 0.16052707023 }},
|
||||
{{ 0.79087, 0.11157, 0.83913 },{ 0.30641388193 }},
|
||||
{{ 0.16297, 0.23090, 0.96417 },{ 0.15005479047 }},
|
||||
{{ 0.78181, 0.80097, 0.00192 },{ 0.32179402798 }},
|
||||
{{ 0.16141, 0.84321, 0.16561 },{ 0.14446082013 }},
|
||||
{{ 0.79859, 0.11111, 0.15547 },{ -0.1308162293 }},
|
||||
{{ 0.12959, 0.16184, 0.21825 },{ 0.03520247555 }},
|
||||
{{ 1.00000, 0.46395, 0.84399 },{ 0.63914200000 }},
|
||||
{{ 0.48724, 0.76024, 1.00000 },{ 0.64150992880 }},
|
||||
{{ 0.40744, 0.00000, 0.65533 },{ 0.13060244736 }},
|
||||
{{ 0.10931, 0.43216, 0.25195 },{ 0.06329759515 }},
|
||||
{{ 0.69401, 0.99412, 0.55335 },{ 0.75632862795 }},
|
||||
{{ 0.51759, 0.30372, 0.13622 },{ 0.07965761859 }},
|
||||
{{ 0.98628, 0.40857, 0.47688 },{ 0.29286006552 }},
|
||||
{{ 0.44474, 0.26024, 1.00000 },{ 0.37263430380 }},
|
||||
{{ 0.15229, 0.52694, 0.75101 },{ 0.16014862087 }},
|
||||
{{ 0.50968, 0.74522, 0.14058 },{ 0.30725752992 }},
|
||||
{{ 0.82291, 0.10614, 0.49956 },{ 0.07762756903 }},
|
||||
{{ 0.15674, 0.78167, 0.50766 },{ 0.17389174472 }},
|
||||
{{ 0.12961, 0.17234, 0.65990 },{ 0.08236132255 }},
|
||||
{{ 1.00000, 0.83202, 0.35206 },{ 0.61366800000 }},
|
||||
{{ 0.36633, 0.89555, 0.76014 },{ 0.48373766601 }},
|
||||
{{ 0.85641, 0.39194, 0.18691 },{ 0.09699956583 }},
|
||||
{{ 0.50918, 0.23923, 0.42132 },{ 0.16380116928 }},
|
||||
{{ 0.65513, 0.40585, 0.83832 },{ 0.49065371733 }},
|
||||
{{ 0.66726, 0.75472, 0.25419 },{ 0.41666516892 }},
|
||||
{{ 0.22193, 0.58555, 0.13920 },{ 0.13003877385 }},
|
||||
{{ 0.41507, 0.89581, 0.25539 },{ 0.37048608609 }},
|
||||
{{ 0.43231, 0.12362, 0.17297 },{ 0.01981752271 }},
|
||||
{{ 0.78191, 0.63297, 0.72639 },{ 0.64361123257 }}
|
||||
};
|
||||
|
||||
co test_points3[] = {
|
||||
{{ 0.50915, 0.50936, 0.57048 },{ -0.00010 }},
|
||||
{{ 0.85943, 0.84331, 0.81487 },{ 0.46573 }},
|
||||
{{ 0.11381, 0.80378, 0.82951 },{ 0.56085 }},
|
||||
{{ 0.79087, 0.11157, 0.83913 },{ 0.33378 }},
|
||||
{{ 0.16297, 0.23090, 0.96417 },{ 0.38872 }},
|
||||
{{ 0.78181, 0.80097, 0.00192 },{ 0.28654 }},
|
||||
{{ 0.16141, 0.84321, 0.16561 },{ 0.43410 }},
|
||||
{{ 0.79859, 0.11111, 0.15547 },{ 0.35140 }},
|
||||
{{ 0.12959, 0.16184, 0.21825 },{ 0.46711 }},
|
||||
{{ 1.00000, 0.46395, 0.84399 },{ 0.94213 }},
|
||||
{{ 0.48724, 0.76024, 1.00000 },{ 0.00058 }},
|
||||
{{ 0.40744, 0.00000, 0.65533 },{ 0.00859 }},
|
||||
{{ 0.10931, 0.43216, 0.25195 },{ 0.54679 }},
|
||||
{{ 0.69401, 0.99412, 0.55335 },{ 0.12494 }},
|
||||
{{ 0.51759, 0.30372, 0.13622 },{ -0.00126 }},
|
||||
{{ 0.98628, 0.40857, 0.47688 },{ 0.89573 }},
|
||||
{{ 0.44474, 0.26024, 1.00000 },{ 0.00280 }},
|
||||
{{ 0.15229, 0.52694, 0.75101 },{ 0.43807 }},
|
||||
{{ 0.50968, 0.74522, 0.14058 },{ 0.00004 }},
|
||||
{{ 0.82291, 0.10614, 0.49956 },{ 0.40990 }},
|
||||
{{ 0.15674, 0.78167, 0.50766 },{ 0.44271 }},
|
||||
{{ 0.12961, 0.17234, 0.65990 },{ 0.46804 }},
|
||||
{{ 1.00000, 0.83202, 0.35206 },{ 0.90938 }},
|
||||
{{ 0.36633, 0.89555, 0.76014 },{ 0.07020 }},
|
||||
{{ 0.85641, 0.39194, 0.18691 },{ 0.48559 }},
|
||||
{{ 0.50918, 0.23923, 0.42132 },{ -0.00391 }},
|
||||
{{ 0.65513, 0.40585, 0.83832 },{ 0.09449 }},
|
||||
{{ 0.66726, 0.75472, 0.25419 },{ 0.10065 }},
|
||||
{{ 0.22193, 0.58555, 0.13920 },{ 0.28186 }},
|
||||
{{ 0.41507, 0.89581, 0.25539 },{ 0.02877 }},
|
||||
{{ 0.43231, 0.12362, 0.17297 },{ 0.00237 }},
|
||||
{{ 0.78191, 0.63297, 0.72639 },{ 0.29573 }}
|
||||
};
|
||||
|
||||
|
||||
/* x + y^2 + z^1/3 function with one non-monotonic point */
|
||||
co test_points4[] = {
|
||||
{{ 0.1,0.1,0.5 },{ 0.11 }}, /* 0 */
|
||||
{{ 0.2,0.7,0.1 },{ 0.69 }}, /* 1 */
|
||||
{{ 0.8,0.8,0.8 },{ 1.44 }}, /* 2 */
|
||||
{{ 0.5,0.6,0.4 },{ 0.86 }}, /* 3 */
|
||||
{{ 0.2,0.5,0.2 },{ 0.45 }}, /* 4 */
|
||||
{{ 0.3,0.7,0.2 },{ 0.35 }}, /* nm 5 */
|
||||
{{ 0.5,0.4,0.9 },{ 0.66 }}, /* 6 */
|
||||
{{ 0.1,0.9,0.7 },{ 0.91 }}, /* 7 */
|
||||
{{ 0.7,0.2,0.1 },{ 0.74 }}, /* 8 */
|
||||
{{ 0.8,0.4,0.3 },{ 0.96 }}, /* 9 */
|
||||
{{ 0.3,0.3,0.4 },{ 0.39 }} /* 10 */
|
||||
};
|
||||
|
||||
/* doubled up x + y^2 + z^1/3 function with one non-monotonic point */
|
||||
co test_points5[] = {
|
||||
{{ 0.1,0.1,0.5 },{ 0.11 }}, /* 0 */
|
||||
{{ 0.101,0.101,0.501 },{ 0.11 }}, /* 0d */
|
||||
{{ 0.2,0.7,0.1 },{ 0.69 }}, /* 1 */
|
||||
{{ 0.201,0.701,0.101 },{ 0.69 }}, /* 1d */
|
||||
{{ 0.8,0.8,0.8 },{ 1.44 }}, /* 2 */
|
||||
{{ 0.801,0.801,0.801 },{ 1.44 }}, /* 2d */
|
||||
{{ 0.5,0.6,0.4 },{ 0.86 }}, /* 3 */
|
||||
{{ 0.501,0.601,0.401 },{ 0.86 }}, /* 3d */
|
||||
{{ 0.2,0.5,0.2 },{ 0.45 }}, /* 4 */
|
||||
{{ 0.201,0.501,0.201 },{ 0.45 }}, /* 4d */
|
||||
{{ 0.3,0.7,0.2 },{ 0.35 }}, /* nm 5 */
|
||||
{{ 0.301,0.701,0.201 },{ 0.35 }}, /* nm 5d */
|
||||
{{ 0.5,0.4,0.9 },{ 0.66 }}, /* 6 */
|
||||
{{ 0.501,0.401,0.901 },{ 0.66 }}, /* 6d */
|
||||
{{ 0.1,0.9,0.7 },{ 0.91 }}, /* 7 */
|
||||
{{ 0.101,0.901,0.701 },{ 0.91 }}, /* 7d */
|
||||
{{ 0.7,0.2,0.1 },{ 0.74 }}, /* 8 */
|
||||
{{ 0.701,0.201,0.101 },{ 0.74 }}, /* 8d */
|
||||
{{ 0.8,0.4,0.3 },{ 0.96 }}, /* 9 */
|
||||
{{ 0.801,0.401,0.301 },{ 0.96 }}, /* 9d */
|
||||
{{ 0.3,0.3,0.4 },{ 0.39 }}, /* 10 */
|
||||
{{ 0.301,0.301,0.401 },{ 0.39 }} /* 10d */
|
||||
};
|
||||
|
||||
co test_points6[] = {
|
||||
{{ 0.0069, 0.0071, 0.0061 },{ 0.0726 }},
|
||||
{{ 0.0068, 0.0071, 0.0060 },{ 0.0704 }},
|
||||
{{ 0.0069, 0.0072, 0.0062 },{ 0.0720 }},
|
||||
{{ 0.0069, 0.0072, 0.0061 },{ 0.0734 }},
|
||||
{{ 0.0069, 0.0072, 0.0063 },{ 0.0750 }},
|
||||
{{ 0.0070, 0.0072, 0.0062 },{ 0.0779 }},
|
||||
{{ 0.0070, 0.0072, 0.0063 },{ 0.0741 }},
|
||||
{{ 0.0069, 0.0072, 0.0061 },{ 0.0745 }},
|
||||
{{ 0.0069, 0.0072, 0.0061 },{ 0.0747 }},
|
||||
{{ 0.0071, 0.0073, 0.0063 },{ 0.0760 }},
|
||||
{{ 0.0070, 0.0073, 0.0063 },{ 0.0751 }},
|
||||
{{ 0.0070, 0.0073, 0.0062 },{ 0.0759 }},
|
||||
{{ 0.0071, 0.0074, 0.0062 },{ 0.0693 }},
|
||||
{{ 0.0071, 0.0074, 0.0064 },{ 0.0740 }},
|
||||
{{ 0.0072, 0.0075, 0.0064 },{ 0.0741 }},
|
||||
{{ 0.0199, 0.0209, 0.0184 },{ 0.1019 }},
|
||||
{{ 0.0296, 0.0306, 0.0257 },{ 0.1213 }},
|
||||
{{ 0.0627, 0.0651, 0.0548 },{ 0.1779 }},
|
||||
{{ 0.0831, 0.0863, 0.0718 },{ 0.2095 }},
|
||||
{{ 0.1091, 0.1134, 0.0946 },{ 0.2487 }},
|
||||
{{ 0.1442, 0.1497, 0.1227 },{ 0.2949 }},
|
||||
{{ 0.1745, 0.1814, 0.1495 },{ 0.3360 }},
|
||||
{{ 0.1747, 0.1816, 0.1498 },{ 0.3367 }},
|
||||
{{ 0.1747, 0.1816, 0.1496 },{ 0.3364 }},
|
||||
{{ 0.1748, 0.1816, 0.1497 },{ 0.3355 }},
|
||||
{{ 0.1749, 0.1817, 0.1497 },{ 0.3344 }},
|
||||
{{ 0.1748, 0.1817, 0.1498 },{ 0.3356 }},
|
||||
{{ 0.1748, 0.1817, 0.1498 },{ 0.3354 }},
|
||||
{{ 0.1749, 0.1817, 0.1496 },{ 0.3361 }},
|
||||
{{ 0.1749, 0.1818, 0.1498 },{ 0.3368 }},
|
||||
{{ 0.1749, 0.1818, 0.1498 },{ 0.3335 }},
|
||||
{{ 0.1750, 0.1818, 0.1499 },{ 0.3367 }},
|
||||
{{ 0.1750, 0.1819, 0.1500 },{ 0.3362 }},
|
||||
{{ 0.1750, 0.1819, 0.1498 },{ 0.3359 }},
|
||||
{{ 0.1751, 0.1820, 0.1500 },{ 0.3354 }},
|
||||
{{ 0.1752, 0.1821, 0.1501 },{ 0.3355 }},
|
||||
{{ 0.1754, 0.1823, 0.1502 },{ 0.3369 }},
|
||||
{{ 0.1756, 0.1824, 0.1504 },{ 0.3360 }},
|
||||
{{ 0.2743, 0.2842, 0.2367 },{ 0.4381 }},
|
||||
{{ 0.3289, 0.3411, 0.2834 },{ 0.4922 }},
|
||||
{{ 0.4036, 0.4184, 0.3475 },{ 0.5617 }},
|
||||
{{ 0.4689, 0.4854, 0.4020 },{ 0.6147 }},
|
||||
{{ 0.5379, 0.5567, 0.4606 },{ 0.6709 }},
|
||||
{{ 0.7137, 0.7420, 0.6169 },{ 0.8045 }},
|
||||
{{ 0.8730, 0.9105, 0.7433 },{ 0.9150 }},
|
||||
{{ 0.8738, 0.9113, 0.7435 },{ 0.9141 }},
|
||||
{{ 0.8741, 0.9116, 0.7445 },{ 0.9120 }},
|
||||
{{ 0.8744, 0.9118, 0.7443 },{ 0.9173 }},
|
||||
{{ 0.8748, 0.9123, 0.7457 },{ 0.9219 }},
|
||||
{{ 0.8748, 0.9123, 0.7450 },{ 0.9133 }},
|
||||
{{ 0.8748, 0.9124, 0.7445 },{ 0.9210 }},
|
||||
{{ 0.8751, 0.9127, 0.7462 },{ 0.9207 }},
|
||||
{{ 0.8751, 0.9127, 0.7457 },{ 0.9225 }},
|
||||
{{ 0.8754, 0.9130, 0.7454 },{ 0.9137 }},
|
||||
{{ 0.8757, 0.9133, 0.7456 },{ 0.9219 }},
|
||||
{{ 0.8759, 0.9135, 0.7470 },{ 0.9166 }},
|
||||
{{ 0.8761, 0.9137, 0.7469 },{ 0.9162 }},
|
||||
{{ 0.8759, 0.9137, 0.7469 },{ 0.9151 }},
|
||||
{{ 0.8765, 0.9141, 0.7470 },{ 0.9167 }},
|
||||
};
|
||||
|
||||
|
||||
#ifdef NEVER
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
void error(char *fmt, ...), warning(char *fmt, ...), verbose(int level, char *fmt, ...);
|
||||
#else
|
||||
#include <varargs.h>
|
||||
void error(), warning(), verbose();
|
||||
#endif
|
||||
#endif /* NEVER */
|
||||
|
||||
void write_rgb_tiff(char *name, int width, int height, unsigned char *data);
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 3D rspl interpolation\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: t2d [options]\n");
|
||||
fprintf(stderr," -t n Test set:\n");
|
||||
fprintf(stderr," * 1 = 1D test set along x = y = 0.5\n");
|
||||
fprintf(stderr," 2 = Test set 1\n");
|
||||
fprintf(stderr," 3 = Test set 2\n");
|
||||
fprintf(stderr," 4 = x + y^2 + z^1/3 with nonmon point\n");
|
||||
fprintf(stderr," 5 = doubled up x + y^2 + z^1/3 with nonmon point\n");
|
||||
fprintf(stderr," 6 = neutral axis extrapolation\n");
|
||||
fprintf(stderr," -r resx,resy,resz Set grid resolutions (def %d %d %d)\n",GRES0,GRES1,GRES2);
|
||||
fprintf(stderr," -h Test half scale resolution too\n");
|
||||
fprintf(stderr," -q Test quarter scale resolution too\n");
|
||||
fprintf(stderr," -x Use auto smoothing\n");
|
||||
fprintf(stderr," -s Test symetric smoothness\n");
|
||||
fprintf(stderr," -p plot 4 slices, xy = 0.5, yz = 0.5, xz = 0.5, x=y=z\n");
|
||||
fprintf(stderr," -P x1:y1:z1:x2:y2:z2 plot slice from x1,y1,z1,x2,y2,z2\n");
|
||||
fprintf(stderr," -S factor smoothing factor (default 1.0)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
rspl *rss; /* Regularized spline structure */
|
||||
rspl *rss2 = NULL; /* Regularized spline structure at half/quarter resolution */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
int gres2[MXDI];
|
||||
double avgdev[MXDO];
|
||||
co *test_points = test_points1;
|
||||
int npoints = sizeof(test_points1)/sizeof(co);
|
||||
int dosym = 0;
|
||||
int autosm = 0;
|
||||
int doplot = 0;
|
||||
double plotpts[2][3]; /* doplot == 2 start/end points */
|
||||
int doh = 0; /* half scale */
|
||||
int doq = 0;
|
||||
int rsv;
|
||||
double smoothf = 1.0;
|
||||
int flags = RSPL_NOFLAGS;
|
||||
|
||||
low[0] = 0.0;
|
||||
low[1] = 0.0;
|
||||
low[2] = 0.0;
|
||||
high[0] = 1.0;
|
||||
high[1] = 1.0;
|
||||
high[2] = 1.0;
|
||||
gres[0] = GRES0;
|
||||
gres[1] = GRES1;
|
||||
gres[2] = GRES2;
|
||||
avgdev[0] = 0.0;
|
||||
avgdev[1] = 0.0;
|
||||
avgdev[2] = 0.0;
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* test set */
|
||||
else if (argv[fa][1] == 't' || argv[fa][1] == 'T') {
|
||||
int ix;
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
ix = atoi(na);
|
||||
switch (ix) {
|
||||
case 1:
|
||||
test_points = test_points1;
|
||||
npoints = sizeof(test_points1)/sizeof(co);
|
||||
break;
|
||||
case 2:
|
||||
test_points = test_points2;
|
||||
npoints = sizeof(test_points2)/sizeof(co);
|
||||
break;
|
||||
case 3:
|
||||
test_points = test_points3;
|
||||
npoints = sizeof(test_points3)/sizeof(co);
|
||||
break;
|
||||
case 4:
|
||||
test_points = test_points4;
|
||||
npoints = sizeof(test_points4)/sizeof(co);
|
||||
break;
|
||||
case 5:
|
||||
test_points = test_points5;
|
||||
npoints = sizeof(test_points5)/sizeof(co);
|
||||
break;
|
||||
case 6:
|
||||
test_points = test_points6;
|
||||
npoints = sizeof(test_points6)/sizeof(co);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
} else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
if (sscanf(na, " %d,%d,%d ", &gres[0], &gres[1], &gres[2]) != 3)
|
||||
usage();
|
||||
|
||||
} else if (argv[fa][1] == 'h' || argv[fa][1] == 'H') {
|
||||
doh = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'q' || argv[fa][1] == 'Q') {
|
||||
doh = 1;
|
||||
doq = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'p') {
|
||||
doplot = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'P') {
|
||||
doplot = 2;
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
if (sscanf(na,"%lf:%lf:%lf:%lf:%lf:%lf",&plotpts[0][0],&plotpts[0][1],&plotpts[0][2],&plotpts[1][0],&plotpts[1][1],&plotpts[1][2]) != 6) {
|
||||
usage();
|
||||
}
|
||||
|
||||
} else if (argv[fa][1] == 's') {
|
||||
dosym = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'x') {
|
||||
autosm = 1;
|
||||
|
||||
/* smoothing factor */
|
||||
} else if (argv[fa][1] == 'S') {
|
||||
int ix;
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
smoothf = atof(na);
|
||||
|
||||
} else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (autosm)
|
||||
flags |= RSPL_AUTOSMOOTH;
|
||||
|
||||
if (dosym)
|
||||
flags |= RSPL_SYMDOMAIN;
|
||||
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, 3, 1);
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss->fit_rspl(rss,
|
||||
flags, /* Non-mon and clip flags */
|
||||
test_points, /* Test points */
|
||||
npoints, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
smoothf, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL); /* iwidth */
|
||||
if (doh) {
|
||||
|
||||
if (doq) {
|
||||
gres2[0] = gres[0]/4;
|
||||
gres2[1] = gres[1]/4;
|
||||
gres2[2] = gres[2]/4;
|
||||
} else {
|
||||
gres2[0] = gres[0]/2;
|
||||
gres2[1] = gres[1]/2;
|
||||
gres2[2] = gres[2]/2;
|
||||
}
|
||||
|
||||
rss2 = new_rspl(RSPL_NOFLAGS, 3, 1);
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss2->fit_rspl(rss2,
|
||||
flags, /* Non-mon and clip flags */
|
||||
test_points, /* Test points */
|
||||
npoints, /* Number of test points */
|
||||
low, high, gres2, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
smoothf, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL); /* iwidth */
|
||||
}
|
||||
|
||||
/* Test the interpolation with a slice in 2D */
|
||||
for (rsv = 0; rsv <= doh; rsv++) {
|
||||
double z[2][2] = { { 0.1, 0.5 } , { 0.5, 0.9 } };
|
||||
double x1 = -0.2;
|
||||
double x2 = 1.2;
|
||||
double y1 = -0.2;
|
||||
double y2 = 1.2;
|
||||
double min = -0.0;
|
||||
double max = 1.0;
|
||||
rspl *rs;
|
||||
unsigned char pa[HEIGHT][WIDTH][3];
|
||||
co tco; /* Test point */
|
||||
double sx,sy;
|
||||
int i,j,k;
|
||||
|
||||
if (rsv == 0)
|
||||
rs = rss;
|
||||
else
|
||||
rs = rss2;
|
||||
|
||||
sx = (x2 - x1)/(double)WIDTH;
|
||||
sy = (y2 - y1)/(double)HEIGHT;
|
||||
|
||||
for (j=0; j < HEIGHT; j++) {
|
||||
double jj = j/(HEIGHT-1.0);
|
||||
tco.p[1] = (double)((HEIGHT-1) - j) * sy + y1;
|
||||
for (i = 0; i < WIDTH; i++) {
|
||||
double ii = j/(HEIGHT-1.0);
|
||||
tco.p[0] = (double)i * sx + x1;
|
||||
|
||||
tco.p[2] = (1.0-ii) * (1.0-jj) * z[0][0]
|
||||
+ (1.0-ii) * jj * z[0][1]
|
||||
+ ii * (1.0-jj) * z[1][0]
|
||||
+ ii * jj * z[1][1];
|
||||
|
||||
if (rs->INTERP(rs, &tco)) {
|
||||
pa[j][i][0] = 0; /* Out of bounds in green */
|
||||
pa[j][i][1] = 100;
|
||||
pa[j][i][2] = 0;
|
||||
} else {
|
||||
int m;
|
||||
/* printf("%d %d, %f %f returned %f\n",i,j,tco.p[0],tco.p[1],tco.v[0]); */
|
||||
m = (int)((255.0 * (tco.v[0] - min)/(max - min)) + 0.5);
|
||||
if (m < 0) {
|
||||
pa[j][i][0] = 20; /* Dark blue */
|
||||
pa[j][i][1] = 20;
|
||||
pa[j][i][2] = 50;
|
||||
} else if (m > 255) {
|
||||
pa[j][i][0] = 230; /* Light blue */
|
||||
pa[j][i][1] = 230;
|
||||
pa[j][i][2] = 255;
|
||||
} else {
|
||||
pa[j][i][0] = m; /* Level in grey */
|
||||
pa[j][i][1] = m;
|
||||
pa[j][i][2] = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark vertices in red */
|
||||
for(k = 0; k < npoints; k++) {
|
||||
j = (int)((HEIGHT * (y2 - test_points[k].p[1])/(y2 - y1)) + 0.5);
|
||||
i = (int)((WIDTH * (test_points[k].p[0] - x1)/(x2 - x1)) + 0.5);
|
||||
pa[j][i][0] = 255;
|
||||
pa[j][i][1] = 0;
|
||||
pa[j][i][2] = 0;
|
||||
}
|
||||
write_rgb_tiff(rsv == 0 ? "t3d.tif" : "t3dh.tif" ,WIDTH,HEIGHT,(unsigned char *)pa);
|
||||
}
|
||||
|
||||
/* Plot out 4 slices */
|
||||
if (doplot == 1) {
|
||||
int slice;
|
||||
|
||||
for (slice = 0; slice < 4; slice++) {
|
||||
co tp; /* Test point */
|
||||
double x[PLOTRES];
|
||||
double ya[PLOTRES];
|
||||
double yb[PLOTRES];
|
||||
double xx,yy,zz;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double sx,sy,sz;
|
||||
int i,n;
|
||||
|
||||
/* Set up slice to plot */
|
||||
if (slice == 0) {
|
||||
x1 = 0.5; y1 = 0.5, z1 = 0.0;
|
||||
x2 = 0.5; y2 = 0.5, z2 = 1.0;
|
||||
printf("Plot along z at x = y = 0.5\n");
|
||||
n = PLOTRES;
|
||||
} else if (slice == 1) {
|
||||
x1 = 0.0; y1 = 0.5, z1 = 0.5;
|
||||
x2 = 1.0; y2 = 0.5, z2 = 0.5;
|
||||
printf("Plot along x at y = z = 0.5\n");
|
||||
n = PLOTRES;
|
||||
} else if (slice == 2) {
|
||||
x1 = 0.5; y1 = 0.0, z1 = 0.5;
|
||||
x2 = 0.5; y2 = 1.0, z2 = 0.5;
|
||||
printf("Plot along y at x = z = 0.5\n");
|
||||
n = PLOTRES;
|
||||
} else {
|
||||
x1 = 0.0; y1 = 0.0, z1 = 0.0;
|
||||
x2 = 1.0; y2 = 1.0, z2 = 1.0;
|
||||
printf("Plot along x = y = z\n");
|
||||
n = PLOTRES;
|
||||
}
|
||||
|
||||
sx = (x2 - x1)/n;
|
||||
sy = (y2 - y1)/n;
|
||||
sz = (z2 - z1)/n;
|
||||
|
||||
xx = x1;
|
||||
yy = y1;
|
||||
zz = z1;
|
||||
for (i = 0; i < n; i++) {
|
||||
double vv = i/(n-1.0);
|
||||
x[i] = vv;
|
||||
tp.p[0] = xx;
|
||||
tp.p[1] = yy;
|
||||
tp.p[2] = zz;
|
||||
|
||||
if (rss->INTERP(rss, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
ya[i] = tp.v[0];
|
||||
|
||||
if (doh) {
|
||||
if (rss2->INTERP(rss2, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
yb[i] = tp.v[0];
|
||||
}
|
||||
|
||||
xx += sx;
|
||||
yy += sy;
|
||||
zz += sz;
|
||||
}
|
||||
|
||||
/* Plot the result */
|
||||
if (doh)
|
||||
do_plot(x,ya,yb,NULL,n);
|
||||
else
|
||||
do_plot(x,ya,NULL,NULL,n);
|
||||
}
|
||||
} else if (doplot == 2) {
|
||||
co tp; /* Test point */
|
||||
double x[PLOTRES];
|
||||
double ya[PLOTRES];
|
||||
double yb[PLOTRES];
|
||||
double xx,yy,zz;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double sx,sy,sz;
|
||||
int i,n;
|
||||
|
||||
|
||||
x1 = plotpts[0][0];
|
||||
y1 = plotpts[0][1];
|
||||
z1 = plotpts[0][2];
|
||||
x2 = plotpts[1][0];
|
||||
y2 = plotpts[1][1];
|
||||
z2 = plotpts[1][2];
|
||||
|
||||
printf("Plot along z at x = y = 0.5\n");
|
||||
n = PLOTRES;
|
||||
|
||||
sx = (x2 - x1)/n;
|
||||
sy = (y2 - y1)/n;
|
||||
sz = (z2 - z1)/n;
|
||||
|
||||
xx = x1;
|
||||
yy = y1;
|
||||
zz = z1;
|
||||
for (i = 0; i < n; i++) {
|
||||
double vv = i/(n-1.0);
|
||||
x[i] = vv;
|
||||
tp.p[0] = xx;
|
||||
tp.p[1] = yy;
|
||||
tp.p[2] = zz;
|
||||
|
||||
if (rss->INTERP(rss, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
ya[i] = tp.v[0];
|
||||
|
||||
if (doh) {
|
||||
if (rss2->INTERP(rss2, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
yb[i] = tp.v[0];
|
||||
}
|
||||
|
||||
xx += sx;
|
||||
yy += sy;
|
||||
zz += sz;
|
||||
}
|
||||
|
||||
/* Plot the result */
|
||||
if (doh)
|
||||
do_plot(x,ya,yb,NULL,n);
|
||||
else
|
||||
do_plot(x,ya,NULL,NULL,n);
|
||||
}
|
||||
|
||||
/* Report the fit */
|
||||
{
|
||||
co tco; /* Test point */
|
||||
int k;
|
||||
double avg = 0;
|
||||
double max = 0.0;
|
||||
|
||||
for(k = 0; k < npoints; k++) {
|
||||
double err;
|
||||
tco.p[0] = test_points[k].p[0];
|
||||
tco.p[1] = test_points[k].p[1];
|
||||
tco.p[2] = test_points[k].p[2];
|
||||
rss->INTERP(rss, &tco);
|
||||
|
||||
err = tco.v[0] - test_points[k].v[0];
|
||||
err = fabs(err);
|
||||
|
||||
avg += err;
|
||||
if (err > max)
|
||||
max = err;
|
||||
}
|
||||
avg /= (double)npoints;
|
||||
printf("Max error %f%%, average %f%%\n",100.0 * max, 100.0 * avg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------- */
|
||||
/* Tiff diagnostic output */
|
||||
|
||||
void
|
||||
write_rgb_tiff(
|
||||
char *name,
|
||||
int width,
|
||||
int height,
|
||||
unsigned char *data
|
||||
) {
|
||||
int y;
|
||||
unsigned char *dp;
|
||||
TIFF *tif;
|
||||
|
||||
if ((tif = TIFFOpen(name, "w")) == NULL) {
|
||||
fprintf(stderr,"Failed to open output TIFF file '%s'\n",name);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
|
||||
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
|
||||
|
||||
for (dp = data, y = 0; y < height; y++, dp += 3 * width) {
|
||||
if (TIFFWriteScanline(tif, (tdata_t)dp, y, 0) < 0) {
|
||||
fprintf(stderr,"WriteScanline Failed at line %d\n",y);
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
(void) TIFFClose(tif);
|
||||
}
|
||||
|
||||
#ifdef NEVER
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Basic printf type error() and warning() routines */
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
error(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
error(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Error - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stdout);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
warning(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
warning(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Warning - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
verbose(int level, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
verbose(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list args;
|
||||
int level;
|
||||
char *fmt;
|
||||
va_start(args);
|
||||
level = va_arg(args, int);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
if (verbose_level >= level)
|
||||
{
|
||||
fprintf(verbose_out,"cmatch: ");
|
||||
vfprintf(verbose_out, fmt, args);
|
||||
fprintf(verbose_out, "\n");
|
||||
fflush(verbose_out);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
#endif /* NEVER */
|
||||
568
Argyll_V3.5.0/rspl/t3ddf.c
Normal file
568
Argyll_V3.5.0/rspl/t3ddf.c
Normal file
@@ -0,0 +1,568 @@
|
||||
/************************************************/
|
||||
/* Test RSPL in 3D with weak default function */
|
||||
/************************************************/
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 20/11/2005
|
||||
* Derived from cmatch.c
|
||||
* Copyright 1995, 2005 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
|
||||
#define DEBUG
|
||||
#define DETAILED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "aconfig.h"
|
||||
#include "rspl.h"
|
||||
#include "tiffio.h"
|
||||
#include "plot.h"
|
||||
#include "ui.h"
|
||||
|
||||
#ifdef NEVER
|
||||
#define INTERP spline_interp
|
||||
#else
|
||||
#define INTERP interp
|
||||
#endif
|
||||
|
||||
#ifdef NEVER
|
||||
FILE *verbose_out = stdout;
|
||||
int verbose_level = 6; /* Current verbosity level */
|
||||
/* 0 = none */
|
||||
/* !0 = diagnostics */
|
||||
#endif /* NEVER */
|
||||
|
||||
#define PLOTRES 256
|
||||
#define WIDTH 400 /* Raster size */
|
||||
#define HEIGHT 400
|
||||
|
||||
#define MAX_ITS 500
|
||||
#define IT_TOL 0.0005
|
||||
#define GRES0 33 /* Default rspl resolutions */
|
||||
#define GRES1 33
|
||||
#define GRES2 33
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
/* two correction points along x = y = 0.5 */
|
||||
co test_points1[] = {
|
||||
// {{ 0.5, 0.5, 0.325 },{ 0.4 }}, /* 0 */
|
||||
// {{ 0.5, 0.5, 0.625 },{ 0.70 }} /* 1 */
|
||||
|
||||
{{ 0.4, 0.4, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.4, 0.4, 0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.5, 0.4, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.5, 0.4, 0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.6, 0.4, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.6, 0.4, 0.625 },{ 0.8 }}, /* 1 */
|
||||
|
||||
{{ 0.4, 0.5, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.4, 0.5, 0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.5, 0.5, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.5, 0.5, 0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.6, 0.5, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.6, 0.5, 0.625 },{ 0.8 }}, /* 1 */
|
||||
|
||||
{{ 0.4, 0.6, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.4, 0.6, 0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.5, 0.6, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.5, 0.6, 0.625 },{ 0.8 }}, /* 1 */
|
||||
{{ 0.6, 0.6, 0.325 },{ 0.5 }}, /* 0 */
|
||||
{{ 0.6, 0.6, 0.625 },{ 0.8 }} /* 1 */
|
||||
};
|
||||
|
||||
#ifdef NEVER
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
void error(char *fmt, ...), warning(char *fmt, ...), verbose(int level, char *fmt, ...);
|
||||
#else
|
||||
#include <varargs.h>
|
||||
void error(), warning(), verbose();
|
||||
#endif
|
||||
#endif /* NEVER */
|
||||
|
||||
void write_rgb_tiff(char *name, int width, int height, unsigned char *data);
|
||||
|
||||
/* Weak default function */
|
||||
/* Linear along z, independent of x & y */
|
||||
static void wfunc(void *cbntx, double *out, double *in) {
|
||||
out[0] = in[2];
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,"Test 3D rspl interpolation with weak default function\n");
|
||||
fprintf(stderr,"Author: Graeme W. Gill\n");
|
||||
fprintf(stderr,"usage: t2d [options]\n");
|
||||
fprintf(stderr," -t n Test set:\n");
|
||||
fprintf(stderr," * 1 = two points along x & y\n");
|
||||
fprintf(stderr," -w wweight Set weak default function weight (default 1.0)\n");
|
||||
fprintf(stderr," -r resx,resy,resz Set grid resolutions (def %d %d %d)\n",GRES0,GRES1,GRES2);
|
||||
fprintf(stderr," -h Test half scale resolution too\n");
|
||||
fprintf(stderr," -q Test quarter scale resolution too\n");
|
||||
fprintf(stderr," -x Use auto smoothing\n");
|
||||
fprintf(stderr," -s Test symetric smoothness (set asymetric -r !)\n");
|
||||
fprintf(stderr," -s Test symetric smoothness\n");
|
||||
fprintf(stderr," -p plot 4 slices, xy = 0.5, yz = 0.5, xz = 0.5, x=y=z\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fa,nfa; /* argument we're looking at */
|
||||
rspl *rss; /* Regularized spline structure */
|
||||
rspl *rss2 = NULL; /* Regularized spline structure at half/quarter resolution */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
int gres2[MXDI];
|
||||
double avgdev[MXDO];
|
||||
co *test_points = test_points1;
|
||||
int npoints = sizeof(test_points1)/sizeof(co);
|
||||
double wweight = 1.0;
|
||||
int autosm = 0;
|
||||
int dosym = 0;
|
||||
int doplot = 0;
|
||||
int doh = 0;
|
||||
int doq = 0;
|
||||
int rsv;
|
||||
int flags = RSPL_NOFLAGS;
|
||||
|
||||
low[0] = 0.0;
|
||||
low[1] = 0.0;
|
||||
low[2] = 0.0;
|
||||
high[0] = 1.0;
|
||||
high[1] = 1.0;
|
||||
high[2] = 1.0;
|
||||
gres[0] = GRES0;
|
||||
gres[1] = GRES1;
|
||||
gres[2] = GRES2;
|
||||
avgdev[0] = 0.0;
|
||||
avgdev[1] = 0.0;
|
||||
avgdev[2] = 0.0;
|
||||
|
||||
/* Process the arguments */
|
||||
for(fa = 1;fa < argc;fa++) {
|
||||
nfa = fa; /* skip to nfa if next argument is used */
|
||||
if (argv[fa][0] == '-') { /* Look for any flags */
|
||||
char *na = NULL; /* next argument after flag, null if none */
|
||||
|
||||
if (argv[fa][2] != '\000')
|
||||
na = &argv[fa][2]; /* next is directly after flag */
|
||||
else {
|
||||
if ((fa+1) < argc) {
|
||||
if (argv[fa+1][0] != '-') {
|
||||
nfa = fa + 1;
|
||||
na = argv[nfa]; /* next is seperate non-flag argument */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[fa][1] == '?')
|
||||
usage();
|
||||
|
||||
/* test set */
|
||||
else if (argv[fa][1] == 't' || argv[fa][1] == 'T') {
|
||||
int ix;
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
ix = atoi(na);
|
||||
switch (ix) {
|
||||
case 1:
|
||||
test_points = test_points1;
|
||||
npoints = sizeof(test_points1)/sizeof(co);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
} else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
wweight = atof(na);
|
||||
|
||||
} else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
|
||||
fa = nfa;
|
||||
if (na == NULL) usage();
|
||||
if (sscanf(na, " %d,%d,%d ", &gres[0], &gres[1], &gres[2]) != 2)
|
||||
usage();
|
||||
|
||||
} else if (argv[fa][1] == 'h' || argv[fa][1] == 'H') {
|
||||
doh = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'q' || argv[fa][1] == 'Q') {
|
||||
doh = 1;
|
||||
doq = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'p' || argv[fa][1] == 'P') {
|
||||
doplot = 1;
|
||||
|
||||
} else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
|
||||
dosym = 1;
|
||||
|
||||
} else if (argv[fa][1] == 'x') {
|
||||
autosm = 1;
|
||||
|
||||
} else if (argv[fa][1] == 's') {
|
||||
dosym = 1;
|
||||
|
||||
} else
|
||||
usage();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (autosm)
|
||||
flags |= RSPL_AUTOSMOOTH;
|
||||
|
||||
if (dosym)
|
||||
flags |= RSPL_SYMDOMAIN;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, 3, 1);
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss->fit_rspl_df(rss,
|
||||
flags, /* Non-mon and clip flags */
|
||||
test_points, /* Test points */
|
||||
npoints, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
low, high, /* Default data scale */
|
||||
1.0, /* Smoothing */
|
||||
avgdev, /* Average Deviation */
|
||||
NULL, /* iwidth */
|
||||
wweight, /* weak function weight */
|
||||
NULL, /* No context */
|
||||
wfunc /* Weak function */
|
||||
);
|
||||
if (doh) {
|
||||
|
||||
if (doq) {
|
||||
gres2[0] = gres[0]/4;
|
||||
gres2[1] = gres[1]/4;
|
||||
gres2[2] = gres[2]/4;
|
||||
} else {
|
||||
gres2[0] = gres[0]/2;
|
||||
gres2[1] = gres[1]/2;
|
||||
gres2[2] = gres[2]/2;
|
||||
}
|
||||
|
||||
rss2 = new_rspl(RSPL_NOFLAGS, 3, 1);
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss2->fit_rspl_df(rss2,
|
||||
flags, /* Non-mon and clip flags */
|
||||
test_points, /* Test points */
|
||||
npoints, /* Number of test points */
|
||||
low, high, gres2, /* Low, high, resolution of grid */
|
||||
low, high, /* Default data scale */
|
||||
1.0, /* Smoothing */
|
||||
avgdev, /* Average Deviation */
|
||||
NULL, /* iwidth */
|
||||
wweight, /* weak function weight */
|
||||
NULL, /* No context */
|
||||
wfunc /* Weak function */
|
||||
);
|
||||
}
|
||||
|
||||
/* Test the interpolation with a slice in 2D */
|
||||
for (rsv = 0; rsv <= doh; rsv++) {
|
||||
double z[2][2] = { { 0.1, 0.5 }, { 0.5, 0.9 } };
|
||||
double x1 = -0.2;
|
||||
double x2 = 1.2;
|
||||
double y1 = -0.2;
|
||||
double y2 = 1.2;
|
||||
double min = -0.0;
|
||||
double max = 1.0;
|
||||
rspl *rs;
|
||||
unsigned char pa[HEIGHT][WIDTH][3];
|
||||
co tco; /* Test point */
|
||||
double sx,sy;
|
||||
int i,j,k;
|
||||
|
||||
if (rsv == 0)
|
||||
rs = rss;
|
||||
else
|
||||
rs = rss2;
|
||||
|
||||
sx = (x2 - x1)/(double)WIDTH;
|
||||
sy = (y2 - y1)/(double)HEIGHT;
|
||||
|
||||
for (j=0; j < HEIGHT; j++) {
|
||||
double jj = j/(HEIGHT-1.0);
|
||||
tco.p[1] = (double)((HEIGHT-1) - j) * sy + y1;
|
||||
for (i = 0; i < WIDTH; i++) {
|
||||
double ii = j/(HEIGHT-1.0);
|
||||
tco.p[0] = (double)i * sx + x1;
|
||||
|
||||
tco.p[2] = (1.0-ii) * (1.0-jj) * z[0][0]
|
||||
+ (1.0-ii) * jj * z[0][1]
|
||||
+ ii * (1.0-jj) * z[1][0]
|
||||
+ ii * jj * z[1][1];
|
||||
|
||||
if (rs->INTERP(rs, &tco)) {
|
||||
pa[j][i][0] = 0; /* Out of bounds in green */
|
||||
pa[j][i][1] = 100;
|
||||
pa[j][i][2] = 0;
|
||||
} else {
|
||||
int m;
|
||||
/* printf("%d %d, %f %f returned %f\n",i,j,tco.p[0],tco.p[1],tco.v[0]); */
|
||||
m = (int)((255.0 * (tco.v[0] - min)/(max - min)) + 0.5);
|
||||
if (m < 0) {
|
||||
pa[j][i][0] = 20; /* Dark blue */
|
||||
pa[j][i][1] = 20;
|
||||
pa[j][i][2] = 50;
|
||||
} else if (m > 255) {
|
||||
pa[j][i][0] = 230; /* Light blue */
|
||||
pa[j][i][1] = 230;
|
||||
pa[j][i][2] = 255;
|
||||
} else {
|
||||
pa[j][i][0] = m; /* Level in grey */
|
||||
pa[j][i][1] = m;
|
||||
pa[j][i][2] = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark vertices in red */
|
||||
for(k = 0; k < npoints; k++) {
|
||||
j = (int)((HEIGHT * (y2 - test_points[k].p[1])/(y2 - y1)) + 0.5);
|
||||
i = (int)((WIDTH * (test_points[k].p[0] - x1)/(x2 - x1)) + 0.5);
|
||||
pa[j][i][0] = 255;
|
||||
pa[j][i][1] = 0;
|
||||
pa[j][i][2] = 0;
|
||||
}
|
||||
write_rgb_tiff(rsv == 0 ? "t3d.tif" : "t3dh.tif" ,WIDTH,HEIGHT,(unsigned char *)pa);
|
||||
}
|
||||
|
||||
/* Plot out 4 slices */
|
||||
if (doplot) {
|
||||
int slice;
|
||||
|
||||
for (slice = 0; slice < 4; slice++) {
|
||||
co tp; /* Test point */
|
||||
double x[PLOTRES];
|
||||
double ya[PLOTRES];
|
||||
double yb[PLOTRES];
|
||||
double xx,yy,zz;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double sx,sy,sz;
|
||||
int i,n;
|
||||
|
||||
/* Set up slice to plot */
|
||||
if (slice == 0) {
|
||||
x1 = 0.5; y1 = 0.5, z1 = 0.0;
|
||||
x2 = 0.5; y2 = 0.5, z2 = 1.0;
|
||||
printf("Plot along z at x = y = 0.5\n");
|
||||
n = PLOTRES;
|
||||
} else if (slice == 1) {
|
||||
x1 = 0.0; y1 = 0.5, z1 = 0.5;
|
||||
x2 = 1.0; y2 = 0.5, z2 = 0.5;
|
||||
printf("Plot along x at y = z = 0.5\n");
|
||||
n = PLOTRES;
|
||||
} else if (slice == 2) {
|
||||
x1 = 0.5; y1 = 0.0, z1 = 0.5;
|
||||
x2 = 0.5; y2 = 1.0, z2 = 0.5;
|
||||
printf("Plot along y at x = z = 0.5\n");
|
||||
n = PLOTRES;
|
||||
} else {
|
||||
x1 = 0.0; y1 = 0.0, z1 = 0.0;
|
||||
x2 = 1.0; y2 = 1.0, z2 = 1.0;
|
||||
printf("Plot along x = y = z\n");
|
||||
n = PLOTRES;
|
||||
}
|
||||
|
||||
sx = (x2 - x1)/n;
|
||||
sy = (y2 - y1)/n;
|
||||
sz = (z2 - z1)/n;
|
||||
|
||||
xx = x1;
|
||||
yy = y1;
|
||||
zz = z1;
|
||||
for (i = 0; i < n; i++) {
|
||||
double vv = i/(n-1.0);
|
||||
x[i] = vv;
|
||||
tp.p[0] = xx;
|
||||
tp.p[1] = yy;
|
||||
tp.p[2] = zz;
|
||||
|
||||
if (rss->INTERP(rss, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
ya[i] = tp.v[0];
|
||||
|
||||
if (doh) {
|
||||
if (rss2->INTERP(rss2, &tp))
|
||||
tp.v[0] = -0.1;
|
||||
yb[i] = tp.v[0];
|
||||
}
|
||||
|
||||
xx += sx;
|
||||
yy += sy;
|
||||
zz += sz;
|
||||
}
|
||||
|
||||
/* Plot the result */
|
||||
if (doh)
|
||||
do_plot(x,ya,yb,NULL,n);
|
||||
else
|
||||
do_plot(x,ya,NULL,NULL,n);
|
||||
}
|
||||
}
|
||||
|
||||
/* Report the fit */
|
||||
{
|
||||
co tco; /* Test point */
|
||||
int k;
|
||||
double avg = 0;
|
||||
double max = 0.0;
|
||||
|
||||
for(k = 0; k < npoints; k++) {
|
||||
double err;
|
||||
tco.p[0] = test_points[k].p[0];
|
||||
tco.p[1] = test_points[k].p[1];
|
||||
tco.p[2] = test_points[k].p[2];
|
||||
rss->INTERP(rss, &tco);
|
||||
|
||||
err = tco.v[0] - test_points[k].v[0];
|
||||
err = fabs(err);
|
||||
|
||||
avg += err;
|
||||
if (err > max)
|
||||
max = err;
|
||||
}
|
||||
avg /= (double)npoints;
|
||||
printf("Max error %f%%, average %f%%\n",100.0 * max, 100.0 * avg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------- */
|
||||
/* Tiff diagnostic output */
|
||||
|
||||
void
|
||||
write_rgb_tiff(
|
||||
char *name,
|
||||
int width,
|
||||
int height,
|
||||
unsigned char *data
|
||||
) {
|
||||
int y;
|
||||
unsigned char *dp;
|
||||
TIFF *tif;
|
||||
|
||||
if ((tif = TIFFOpen(name, "w")) == NULL) {
|
||||
fprintf(stderr,"Failed to open output TIFF file '%s'\n",name);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
|
||||
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
|
||||
|
||||
for (dp = data, y = 0; y < height; y++, dp += 3 * width) {
|
||||
if (TIFFWriteScanline(tif, (tdata_t)dp, y, 0) < 0) {
|
||||
fprintf(stderr,"WriteScanline Failed at line %d\n",y);
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
(void) TIFFClose(tif);
|
||||
}
|
||||
|
||||
#ifdef NEVER
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Basic printf type error() and warning() routines */
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
error(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
error(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Error - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stdout);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
warning(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
warning(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Warning - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
verbose(int level, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
verbose(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list args;
|
||||
int level;
|
||||
char *fmt;
|
||||
va_start(args);
|
||||
level = va_arg(args, int);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
if (verbose_level >= level)
|
||||
{
|
||||
fprintf(verbose_out,"cmatch: ");
|
||||
vfprintf(verbose_out, fmt, args);
|
||||
fprintf(verbose_out, "\n");
|
||||
fflush(verbose_out);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
#endif /* NEVER */
|
||||
494
Argyll_V3.5.0/rspl/tnd.c
Normal file
494
Argyll_V3.5.0/rspl/tnd.c
Normal file
@@ -0,0 +1,494 @@
|
||||
|
||||
/************************************************/
|
||||
/* Test RSPL in 3/4D */
|
||||
/************************************************/
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 22/4/96
|
||||
* Derived from cmatch.c
|
||||
* Copyright 1995 - 2000 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
|
||||
#undef DEBUG
|
||||
#undef DETAILED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "rspl.h"
|
||||
#include "numlib.h"
|
||||
#include "tiffio.h"
|
||||
//#include "plot.h"
|
||||
|
||||
#ifdef NEVER
|
||||
FILE *verbose_out = stdout;
|
||||
int verbose_level = 6; /* Current verbosity level */
|
||||
/* 0 = none */
|
||||
/* !0 = diagnostics */
|
||||
#endif /* NEVER */
|
||||
|
||||
#define spline_interp interp
|
||||
|
||||
/* rspl flags */
|
||||
#define FLAGS (0 /* */)
|
||||
|
||||
#define TEST_FWD_2D
|
||||
#define TEST_REV_LOOKUP
|
||||
#undef TEST_SLICE
|
||||
#undef TEST_RANDOM_POINTS
|
||||
|
||||
#ifdef TEST_SLICE
|
||||
# include "ui.h"
|
||||
#endif
|
||||
|
||||
#define MAX_ITS 500
|
||||
#define IT_TOL 0.0005
|
||||
#define GRES 17 /* Grid resolution */
|
||||
#define DI 4 /* Dimensions in */
|
||||
#define FDI 4 /* Function (out) Dimensions */
|
||||
#undef NEVER
|
||||
#define ALWAYS
|
||||
|
||||
/* Arbitrary values */
|
||||
static co test_points[] = {
|
||||
{{ 0.1,0.1,0.5,0.0 },{ 0.6, 0.2, 0.3, 0.99 }}, /* 0 */
|
||||
{{ 0.2,0.7,0.1,0.3 },{ 0.3, 0.1, 0.1, 0.45 }}, /* 1 */
|
||||
{{ 0.8,0.8,0.8,0.2 },{ 0.1, 0.7, 0.7, 0.7 }}, /* 2 */
|
||||
{{ 0.5,0.6,0.4,0.9 },{ 0.7, 0.6, 0.5, 0.4 }}, /* 3 */
|
||||
{{ 0.2,0.5,0.2,0.7 },{ 0.2, 0.3, 0.2, 0.2 }}, /* 4 */
|
||||
{{ 0.3,0.7,0.2,0.8 },{ 0.8, 0.9, 0.3, 0.5 }}, /* 5 */
|
||||
{{ 0.5,0.4,0.9,0.3 },{ 0.6, 0.4, 0.2, 0.01 }}, /* 6 */
|
||||
{{ 0.1,0.9,0.7,0.4 },{ 1.0, 0.9, 0.3, 0.6 }}, /* 7 */
|
||||
{{ 0.7,0.2,0.1,0.3 },{ 0.2, 0.3, 0.7, 0.3 }}, /* 8 */
|
||||
{{ 0.8,0.4,0.3,0.7 },{ 0.4, 0.5, 0.6, 0.2 }}, /* 9 */
|
||||
{{ 0.3,0.3,0.4,0.1 },{ 0.8, 0.6, 0.8, 0.1 }} /* 10 */
|
||||
};
|
||||
|
||||
#ifdef NEVER
|
||||
/* Inverting table */
|
||||
static co test_points[] = {
|
||||
{{ 0.1,0.1,0.5,0.0 },{ 0.9, 0.9, 0.5, 1.0 }}, /* 0 */
|
||||
{{ 0.2,0.7,0.1,0.3 },{ 0.8, 0.3, 0.9, 0.7 }}, /* 1 */
|
||||
{{ 0.8,0.8,0.8,0.2 },{ 0.2, 0.2, 0.2, 0.8 }}, /* 2 */
|
||||
{{ 0.5,0.6,0.4,0.9 },{ 0.5, 0.4, 0.6, 0.1 }}, /* 3 */
|
||||
{{ 0.2,0.5,0.2,0.7 },{ 0.8, 0.5, 0.8, 0.3 }}, /* 4 */
|
||||
{{ 0.3,0.7,0.2,0.8 },{ 0.7, 0.3, 0.8, 0.2 }}, /* 5 */
|
||||
{{ 0.5,0.4,0.9,0.3 },{ 0.5, 0.6, 0.1, 0.7 }}, /* 6 */
|
||||
{{ 0.1,0.9,0.7,0.4 },{ 0.9, 0.1, 0.3, 0.6 }}, /* 7 */
|
||||
{{ 0.7,0.2,0.1,0.3 },{ 0.3, 0.8, 0.9, 0.7 }}, /* 8 */
|
||||
{{ 0.8,0.4,0.3,0.7 },{ 0.2, 0.6, 0.7, 0.3 }}, /* 9 */
|
||||
{{ 0.3,0.3,0.4,0.1 },{ 0.7, 0.7, 0.6, 0.9 }} /* 10 */
|
||||
};
|
||||
#endif /* NEVER */
|
||||
|
||||
#ifdef NEVER
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
void error(char *fmt, ...), warning(char *fmt, ...), verbose(int level, char *fmt, ...);
|
||||
#else
|
||||
#include <varargs.h>
|
||||
void error(), warning(), verbose();
|
||||
#endif
|
||||
#endif /* NEVER */
|
||||
|
||||
void write_rgb_tiff(char *name, int width, int height, unsigned char *data);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
co *tps = NULL;
|
||||
int ntps = 0;
|
||||
rspl *rss; /* Multi-resolution regularized spline structure */
|
||||
datai low,high;
|
||||
int gres[MXDI];
|
||||
double avgdev[MXDO];
|
||||
low[0] = 0.0;
|
||||
low[1] = 0.0;
|
||||
low[2] = 0.0;
|
||||
low[3] = 0.0;
|
||||
high[0] = 1.0;
|
||||
high[1] = 1.0;
|
||||
high[2] = 1.0;
|
||||
high[3] = 1.0;
|
||||
gres[0] = GRES;
|
||||
gres[1] = GRES;
|
||||
gres[2] = GRES;
|
||||
gres[3] = GRES;
|
||||
avgdev[0] = 0.0;
|
||||
avgdev[1] = 0.0;
|
||||
avgdev[2] = 0.0;
|
||||
avgdev[3] = 0.0;
|
||||
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, DI, /* di */
|
||||
FDI); /* fdi */
|
||||
|
||||
#ifdef TEST_RANDOM_POINTS
|
||||
{
|
||||
int i;
|
||||
ntps = i_rand(30,150);
|
||||
tps = (co *)malloc(ntps * sizeof(co));
|
||||
for (i = 0; i < ntps; i++) {
|
||||
tps[i].p[0] = d_rand(0.0,1.0);
|
||||
tps[i].p[1] = d_rand(0.0,1.0);
|
||||
tps[i].p[2] = d_rand(0.0,1.0);
|
||||
tps[i].p[3] = d_rand(0.0,1.0);
|
||||
tps[i].v[0] = d_rand(0.0,1.0);
|
||||
tps[i].v[1] = d_rand(0.0,1.0);
|
||||
tps[i].v[2] = d_rand(0.0,1.0);
|
||||
tps[i].v[3] = d_rand(0.0,1.0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
tps = test_points;
|
||||
ntps = sizeof(test_points)/sizeof(co);
|
||||
#endif
|
||||
|
||||
/* Fit to scattered data */
|
||||
rss->fit_rspl(rss,
|
||||
FLAGS, /* Non-mon and clip flags */
|
||||
tps, /* Test points */
|
||||
ntps, /* Number of test points */
|
||||
low, high, gres, /* Low, high, resolution of grid */
|
||||
NULL, NULL, /* Default data scale */
|
||||
1.0, /* Smoothing */
|
||||
avgdev, /* Average deviation */
|
||||
NULL); /* iwidth */
|
||||
/* IT_TOL, MAX_ITS); */
|
||||
|
||||
/* verbose(1,"Regular spline fit error = %f\n",rss->efactor(rss,0)); */
|
||||
|
||||
/* Do a quick check */
|
||||
{
|
||||
co tco; /* Test point */
|
||||
int i,j;
|
||||
double df,sm;
|
||||
for (i = 0; i < ntps; i++) {
|
||||
for (j = 0; j < DI; j++)
|
||||
tco.p[j] = tps[i].p[j];
|
||||
|
||||
rss->spline_interp(rss, &tco);
|
||||
sm = 0.0;
|
||||
for (j = 0; j < DI; j++) {
|
||||
df = tco.v[j] - tps[i].v[j];
|
||||
sm += df * df;
|
||||
}
|
||||
printf("Error at data point %d = %f\n",i,sqrt(sm));
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_REV_LOOKUP
|
||||
{
|
||||
#define NIP 10
|
||||
int i, r;
|
||||
double v[MXDO]; /* Target output value */
|
||||
co tp[NIP], chp; /* Test point, check point */
|
||||
double cvec[4]; /* Text clip vector */
|
||||
int auxm[4]; /* Auxiliary target value valid flag */
|
||||
|
||||
tp[0].v[0] = v[0] = 0.5;
|
||||
tp[0].v[1] = v[1] = 0.5;
|
||||
tp[0].v[2] = v[2] = 0.5;
|
||||
tp[0].v[3] = v[3] = 0.5;
|
||||
|
||||
/* Set auxiliary target */
|
||||
auxm[0] = 0;
|
||||
auxm[1] = 0;
|
||||
auxm[2] = 1;
|
||||
auxm[3] = 0;
|
||||
tp[0].p[0] = -1.0;
|
||||
tp[0].p[1] = -1.0;
|
||||
tp[0].p[2] = 0.5;
|
||||
tp[0].p[3] = -1.0;
|
||||
|
||||
for (i = 1; i < NIP; i++) { /* Make sure we can see changes */
|
||||
tp[i].p[0] = -1.0;
|
||||
tp[i].p[1] = -1.0;
|
||||
tp[i].p[2] = -1.0;
|
||||
tp[i].p[3] = -1.0;
|
||||
}
|
||||
|
||||
/* Clip center */
|
||||
cvec[0] = 0.0 - tp[0].v[0];
|
||||
cvec[1] = 0.0 - tp[0].v[1];
|
||||
cvec[2] = 0.0 - tp[0].v[2];
|
||||
cvec[3] = 0.0 - tp[0].v[3];
|
||||
|
||||
/* Do reverse interpolation ~~~1 */
|
||||
if ((r = rss->rev_interp(rss, 0, NIP, auxm, NULL /*cvec/LChW*/, tp)) > 0) {
|
||||
printf("Total of %d Results\n",r);
|
||||
for (i = 0; i < r; i++)
|
||||
printf("Result %d = %f, %f, %f, %f\n",i, tp[i].p[0],tp[i].p[1],tp[i].p[2],tp[i].p[3]);
|
||||
|
||||
/* Check test result */
|
||||
for (i = 0; i < r; i++) {
|
||||
chp.p[0] = tp[i].p[0];
|
||||
chp.p[1] = tp[i].p[1];
|
||||
chp.p[2] = tp[i].p[2];
|
||||
chp.p[3] = tp[i].p[3];
|
||||
chp.v[0] = -1.0;
|
||||
chp.v[1] = -1.0;
|
||||
chp.v[2] = -1.0;
|
||||
chp.v[3] = -1.0;
|
||||
if (rss->interp(rss, &chp))
|
||||
printf("Fwd check %d failed!\n",i);
|
||||
else {
|
||||
int p;
|
||||
double er = 0.0;
|
||||
for (p = 0; p < FDI; p++)
|
||||
er += (v[p] - chp.v[p]) * (v[p] - chp.v[p]);
|
||||
printf("Fwd check error %d = %f\n",i,er);
|
||||
}
|
||||
}
|
||||
} else
|
||||
printf("Rev lookup result returned none\n");
|
||||
}
|
||||
#endif /* TEST_REV_LOOKUP */
|
||||
|
||||
#ifdef TEST_SLICE
|
||||
/* Test the interpolation */
|
||||
{
|
||||
co tp; /* Test point */
|
||||
double x[50000];
|
||||
double y[50000];
|
||||
double ya[50000];
|
||||
double xx,yy;
|
||||
double x1,x2,y1,y2;
|
||||
double sx,sy;
|
||||
int i,j,n;
|
||||
|
||||
/* Set up slice to plot */
|
||||
x1 = 0.1; y1 = 0.5; /* ~4 */
|
||||
x2 = 0.9; y2 = 0.5;
|
||||
n = 100;
|
||||
|
||||
sx = (x2 - x1)/n;
|
||||
sy = (y2 - y1)/n;
|
||||
|
||||
xx = x1;
|
||||
yy = y1;
|
||||
for (j = i = 0; i < n; i++)
|
||||
{
|
||||
tp.p[0] = xx;
|
||||
tp.p[1] = yy;
|
||||
if (rss->spline_interp(rss, &tp))
|
||||
{
|
||||
tp.v[0] = -0.1;
|
||||
}
|
||||
x[j] = xx;
|
||||
y[j] = tp.v[0];
|
||||
j++;
|
||||
xx += sx;
|
||||
yy += sy;
|
||||
}
|
||||
|
||||
/* Plot the result */
|
||||
do_plot(x,y,NULL,NULL,j);
|
||||
}
|
||||
#endif /* TEST_SLICE */
|
||||
|
||||
#ifdef TEST_FWD_2D
|
||||
/* Test the interpolation in 2D */
|
||||
{
|
||||
#define WIDTH 200
|
||||
#define HEIGHT 200
|
||||
double x1 = -0.2;
|
||||
double x2 = 1.2;
|
||||
double y1 = -0.2;
|
||||
double y2 = 1.2;
|
||||
double min = -0.0;
|
||||
double max = 1.0;
|
||||
|
||||
unsigned char pa[HEIGHT][WIDTH][3];
|
||||
co tco; /* Test point */
|
||||
double sx,sy;
|
||||
int i,j,k;
|
||||
|
||||
sx = (x2 - x1)/(double)WIDTH;
|
||||
sy = (y2 - y1)/(double)HEIGHT;
|
||||
|
||||
tco.p[2] = 0.5; /* Set slice */
|
||||
tco.p[3] = 0.5;
|
||||
for (j=0; j < HEIGHT; j++)
|
||||
{
|
||||
tco.p[1] = (double)((HEIGHT-1) - j) * sy + y1;
|
||||
for (i=0; i < WIDTH; i++)
|
||||
{
|
||||
tco.p[0] = (double)i * sx + x1;
|
||||
if (rss->spline_interp(rss, &tco))
|
||||
{
|
||||
pa[j][i][0] = 0; /* Out of bounds in green */
|
||||
pa[j][i][1] = 100;
|
||||
pa[j][i][2] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int m;
|
||||
/* printf("%d %d, %f %f returned %f\n",i,j,tco.p[0],tco.p[1],tco.v[0]); */
|
||||
m = (int)((255.0 * (tco.v[0] - min)/(max - min)) + 0.5);
|
||||
if (m < 0)
|
||||
{
|
||||
pa[j][i][0] = 0; /* Dark blue */
|
||||
pa[j][i][1] = 0;
|
||||
pa[j][i][2] = 40;
|
||||
}
|
||||
else if (m > 255)
|
||||
{
|
||||
pa[j][i][0] = 220; /* Light blue */
|
||||
pa[j][i][1] = 220;
|
||||
pa[j][i][2] = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
pa[j][i][0] = m; /* Level in grey */
|
||||
pa[j][i][1] = m;
|
||||
pa[j][i][2] = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark vertices in red */
|
||||
for(k = 0; k < ntps; k++)
|
||||
{
|
||||
j = (int)((HEIGHT * (y2 - tps[k].p[1])/(y2 - y1)) + 0.5);
|
||||
i = (int)((WIDTH * (tps[k].p[0] - x1)/(x2 - x1)) + 0.5);
|
||||
pa[j][i][0] = 255;
|
||||
pa[j][i][1] = 0;
|
||||
pa[j][i][2] = 0;
|
||||
}
|
||||
|
||||
write_rgb_tiff("tnd.tif",WIDTH,HEIGHT,(unsigned char *)pa);
|
||||
}
|
||||
#endif /* TEST_FWD_2D */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------- */
|
||||
/* Tiff diagnostic output */
|
||||
|
||||
void
|
||||
write_rgb_tiff(
|
||||
char *name,
|
||||
int width,
|
||||
int height,
|
||||
unsigned char *data
|
||||
) {
|
||||
int y;
|
||||
unsigned char *dp;
|
||||
TIFF *tif;
|
||||
|
||||
if ((tif = TIFFOpen(name, "w")) == NULL) {
|
||||
fprintf(stderr,"Failed to open output TIFF file '%s'\n",name);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
|
||||
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
|
||||
|
||||
for (dp = data, y = 0; y < height; y++, dp += 3 * width) {
|
||||
if (TIFFWriteScanline(tif, (tdata_t)dp, y, 0) < 0) {
|
||||
fprintf(stderr,"WriteScanline Failed at line %d\n",y);
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
(void) TIFFClose(tif);
|
||||
}
|
||||
|
||||
#ifdef NEVER
|
||||
|
||||
/******************************************************************/
|
||||
/* Error/debug output routines */
|
||||
/******************************************************************/
|
||||
|
||||
/* Basic printf type error() and warning() routines */
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
error(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
error(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Error - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stdout);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
warning(char *fmt, ...)
|
||||
#else
|
||||
void
|
||||
warning(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#ifndef __STDC__
|
||||
char *fmt;
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"cmatch: Warning - ");
|
||||
#ifdef __STDC__
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
va_start(args);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
void
|
||||
verbose(int level, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#else
|
||||
verbose(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
va_list args;
|
||||
int level;
|
||||
char *fmt;
|
||||
va_start(args);
|
||||
level = va_arg(args, int);
|
||||
fmt = va_arg(args, char *);
|
||||
#endif
|
||||
if (verbose_level >= level)
|
||||
{
|
||||
fprintf(verbose_out,"cmatch: ");
|
||||
vfprintf(verbose_out, fmt, args);
|
||||
fprintf(verbose_out, "\n");
|
||||
fflush(verbose_out);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
#endif /* NEVER */
|
||||
275
Argyll_V3.5.0/rspl/trnd.c
Normal file
275
Argyll_V3.5.0/rspl/trnd.c
Normal file
@@ -0,0 +1,275 @@
|
||||
|
||||
/************************************************/
|
||||
/* Test RSPL reverse lookup in 3/4D */
|
||||
/************************************************/
|
||||
|
||||
/* Author: Graeme Gill
|
||||
* Date: 31/10/96
|
||||
* Derived from tnd.c
|
||||
* Copyright 1999 - 2000 Graeme W. Gill
|
||||
*
|
||||
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
|
||||
* see the License.txt file for licencing details.
|
||||
*/
|
||||
|
||||
|
||||
#undef DEBUG
|
||||
#undef DETAILED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "rspl.h"
|
||||
#include "numlib.h"
|
||||
|
||||
#ifdef NEVER
|
||||
FILE *verbose_out = stdout;
|
||||
int verbose_level = 6; /* Current verbosity level */
|
||||
/* 0 = none */
|
||||
/* !0 = diagnostics */
|
||||
#endif /* NEVER */
|
||||
|
||||
#define GRES 10 /* Grid resolution */
|
||||
#define DI 4 /* Dimensions in */
|
||||
#define FDI 3 /* Function (out) Dimensions */
|
||||
#define DOLIMIT
|
||||
#define LIMITV 1.50
|
||||
|
||||
/* Fwd function approximated by rspl */
|
||||
void func(
|
||||
void *cbctx,
|
||||
double *out,
|
||||
double *in) {
|
||||
double tt[4];
|
||||
|
||||
#ifdef NEVER
|
||||
printf(" Got input %f %f\n",in[0],in[1]);
|
||||
if (in[1] < 0.5 && in[0] < 0.5) { /* 0,0 */
|
||||
out[0] = 0.1;
|
||||
out[1] = 0.5;
|
||||
}
|
||||
if (in[1] < 0.5 && in[0] > 0.5) { /* 0,1 */
|
||||
out[0] = 0.5;
|
||||
out[1] = 0.0;
|
||||
}
|
||||
if (in[1] > 0.5 && in[0] < 0.5) { /* 0,1 */
|
||||
out[0] = 0.9;
|
||||
out[1] = 0.8;
|
||||
}
|
||||
if (in[1] > 0.5 && in[0] > 0.5) { /* 0,1 */
|
||||
out[0] = 0.9;
|
||||
out[1] = 0.2;
|
||||
}
|
||||
#endif /* NEVER */
|
||||
|
||||
#if DI >= 3
|
||||
tt[0] = 0.7 * in[0] + 0.2 * in[1] + 0.1 * in[2];
|
||||
tt[0] = tt[0] * tt[0];
|
||||
tt[1] = 0.2 * in[0] + 0.8 * in[1] - 0.1 * in[2];
|
||||
tt[1] = tt[1] * tt[1];
|
||||
tt[2] = 0.3 * in[0] - 0.2 * in[1] + 0.9 * in[2];
|
||||
tt[2] = tt[2] * tt[2];
|
||||
#endif
|
||||
|
||||
#if DI == 4
|
||||
tt[0] *= in[3];
|
||||
tt[1] *= in[3];
|
||||
tt[2] *= in[3];
|
||||
#endif
|
||||
|
||||
tt[3] = 0.3 * in[0] + 0.4 * in[1] + 0.3 * in[2];
|
||||
|
||||
#if FDI > 0
|
||||
out[0] = tt[0];
|
||||
#endif
|
||||
#if FDI > 1
|
||||
out[1] = tt[1];
|
||||
#endif
|
||||
#if FDI > 2
|
||||
out[2] = tt[2];
|
||||
#endif
|
||||
#if FDI > 3
|
||||
out[3] = tt[3];
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Simplex ink limit function */
|
||||
double limitf(
|
||||
void *lcntx,
|
||||
double *in
|
||||
) {
|
||||
int i;
|
||||
double ov;
|
||||
|
||||
for (ov = 0.0, i = 0; i < DI; i++) {
|
||||
ov += in[i];
|
||||
}
|
||||
return ov;
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
int e;
|
||||
rspl *rss; /* Multi-resolution regularized spline structure */
|
||||
int gres[MXDI];
|
||||
|
||||
for (e = 0; e < DI; e++)
|
||||
gres[e] = GRES;
|
||||
|
||||
printf("Started test\n");
|
||||
/* Create the object */
|
||||
rss = new_rspl(RSPL_NOFLAGS, DI, FDI);
|
||||
|
||||
printf("Rspl allocated\n");
|
||||
rss->set_rspl(rss, 0, (void *)NULL, func, NULL, NULL, gres, NULL, NULL);
|
||||
// rss->set_rspl(rss, RSPL_SET_APXLS, (void *)NULL, func, NULL, NULL, gres, NULL, NULL);
|
||||
|
||||
printf("Rspl set\n");
|
||||
|
||||
{
|
||||
#define NIP 10 /* Number of solutions allowed */
|
||||
int i, r, cl;
|
||||
double v[MXDO]; /* Target output value */
|
||||
co tp[NIP], chp; /* Test point, check point */
|
||||
double cvec[4]; /* Text clip vector */
|
||||
int auxm[4]; /* Auxiliary target value valid flag */
|
||||
double lmin[4], lmax[4]; /* Locus min/max values */
|
||||
|
||||
/* Output value being looked for */
|
||||
/*
|
||||
tp[0].v[0] = v[0] = 1.5;
|
||||
tp[0].v[1] = v[1] = 0.9;
|
||||
tp[0].v[2] = v[2] = 1.2;
|
||||
tp[0].v[3] = v[3] = 0.0;
|
||||
*/
|
||||
tp[0].v[0] = v[0] = 0.3;
|
||||
tp[0].v[1] = v[1] = 0.4;
|
||||
tp[0].v[2] = v[2] = 0.26;
|
||||
tp[0].v[3] = v[3] = 0.0;
|
||||
|
||||
/* Set auxiliary target */
|
||||
auxm[0] = 0;
|
||||
auxm[1] = 0;
|
||||
auxm[2] = 0;
|
||||
auxm[3] = 1;
|
||||
tp[0].p[0] = 0;
|
||||
tp[0].p[1] = 0;
|
||||
tp[0].p[2] = 0.0;
|
||||
tp[0].p[3] = 0.87;
|
||||
|
||||
for (i = 1; i < NIP; i++) { /* Make sure we can see changes */
|
||||
tp[i].p[0] = -1.0;
|
||||
tp[i].p[1] = -1.0;
|
||||
tp[i].p[2] = -1.0;
|
||||
tp[i].p[3] = -1.0;
|
||||
}
|
||||
|
||||
/* Clip center */
|
||||
cvec[0] = 0.1 - tp[0].v[0];
|
||||
cvec[1] = 0.1 - tp[0].v[1];
|
||||
cvec[2] = 0.1 - tp[0].v[2];
|
||||
cvec[3] = 0.1 - tp[0].v[3];
|
||||
|
||||
#ifdef DOLIMIT
|
||||
/* Setup limit */
|
||||
rss->rev_set_limit(rss,
|
||||
limitf, /* limit function */
|
||||
NULL, /* Function context */
|
||||
LIMITV /* limit maximum value */
|
||||
);
|
||||
#endif /* DOLIMIT */
|
||||
|
||||
#if DI > FDI
|
||||
/* Check out the locus size */
|
||||
if ((r = rss->rev_locus(rss,
|
||||
auxm, /* auxm Auxiliary mask flags */
|
||||
tp, /* Input and auxiliary values */
|
||||
lmin, /* Locus min/max return values */
|
||||
lmax
|
||||
)) > 0) {
|
||||
|
||||
printf("Total of %d Results\n",r);
|
||||
for (i = 0; i < FDI; i++) {
|
||||
if (auxm[i] == 0)
|
||||
continue;
|
||||
printf("Auxiliary %d min = %f, max = %f\n",i, lmin[i], lmax[i]);
|
||||
}
|
||||
} else {
|
||||
printf("Failed to find gamut range\n");
|
||||
}
|
||||
printf("\n\n");
|
||||
#endif
|
||||
|
||||
/* Do reverse interpolation ~~~1 */
|
||||
if ((r = rss->rev_interp(rss,
|
||||
0 /* RSPL_EXACTAUX */, /* Hint flags */
|
||||
NIP, /* Number of solutions allowed */
|
||||
auxm, /* auxm Auxiliary mask flags */
|
||||
cvec, /* cvec Clip vector direction & length */
|
||||
tp) /* Input and output values */
|
||||
) > 0) {
|
||||
|
||||
printf("Total of %d Results\n", r &= RSPL_NOSOLNS);
|
||||
|
||||
printf("Target output %f, %f, %f, %f\n", v[0], v[1], v[2], v[3]);
|
||||
|
||||
cl = r & RSPL_DIDCLIP; /* clipped flag */
|
||||
r &= RSPL_NOSOLNS; /* Get number of solutions */
|
||||
|
||||
/* Check test result */
|
||||
for (i = 0; i < r; i++) {
|
||||
chp.p[0] = tp[i].p[0];
|
||||
chp.p[1] = tp[i].p[1];
|
||||
chp.p[2] = tp[i].p[2];
|
||||
chp.p[3] = tp[i].p[3];
|
||||
chp.v[0] = -1.0;
|
||||
chp.v[1] = -1.0;
|
||||
chp.v[2] = -1.0;
|
||||
chp.v[3] = -1.0;
|
||||
printf("Result %d = inp: %f, %f, %f, %f\n",i, tp[i].p[0],tp[i].p[1],tp[i].p[2],tp[i].p[3]);
|
||||
printf(" out: %f, %f, %f, %f\n",tp[i].v[0],tp[i].v[1],tp[i].v[2],tp[i].v[3]);
|
||||
|
||||
if (rss->interp(rss, &chp))
|
||||
printf("Fwd check %d failed!\n",i);
|
||||
else {
|
||||
int p;
|
||||
double er = 0.0;
|
||||
for (p = 0; p < FDI; p++)
|
||||
er += (v[p] - chp.v[p]) * (v[p] - chp.v[p]);
|
||||
er = sqrt(er);
|
||||
printf("Fwd check error %d = %f\n",i,er);
|
||||
|
||||
if (cl != 0) {
|
||||
/* Check if clipped result us reasonable */
|
||||
/* ~~~ */
|
||||
}
|
||||
}
|
||||
{
|
||||
printf("Output limit = %f\n",limitf(NULL, tp[i].p));
|
||||
}
|
||||
}
|
||||
} else
|
||||
printf("Rev lookup result returned none\n");
|
||||
}
|
||||
rss->del(rss);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef NEVER
|
||||
/* Standard interface for powell function */
|
||||
/* return err on sucess, -1.0 on failure */
|
||||
/* Result will be in cp */
|
||||
double powell(
|
||||
int di, /* Dimensionality */
|
||||
double cp[], /* Initial starting point */
|
||||
double s[], /* Size of initial search area */
|
||||
double ftol, /* Tollerance of error change to stop on */
|
||||
int maxit, /* Maximum iterations allowed */
|
||||
double (*func)(void *fdata, double tp[]), /* Error function to evaluate */
|
||||
void *fdata /* Opaque data needed by function */
|
||||
) {
|
||||
#endif
|
||||
Reference in New Issue
Block a user