initial upload
This commit is contained in:
commit
f4bfeb6cf8
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build/
|
||||
.DS_Store
|
12
CMakeLists.txt
Normal file
12
CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.15.2)
|
||||
# 设置工程名称
|
||||
project(stt VERSION 1.2 LANGUAGES CXX)
|
||||
|
||||
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||
# CMake默认的安装路径 Windows下为C:/Program\ Files/${Project_Name} Linux/Unix下为/usr/local
|
||||
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||
# CMake默认的变异类型为空
|
||||
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
|
||||
# 添加源文件地址
|
||||
add_subdirectory(src/)
|
665
LICENSE
Normal file
665
LICENSE
Normal file
@ -0,0 +1,665 @@
|
||||
stt License
|
||||
--------------
|
||||
|
||||
stt is distributed under a dual licensing scheme. 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. A copy of the GNU Affero General Public License is reproduced
|
||||
below.
|
||||
|
||||
If the terms and conditions of the AGPL v.3. would prevent you from
|
||||
using stt, please consider the option to obtain a commercial
|
||||
license for a fee. These licenses are offered by the Author. As a rule,
|
||||
licenses are provided "as-is", unlimited in time for a one time
|
||||
fee. Please send corresponding requests to:
|
||||
zhangyiss@icloud.com. Please do not forget to include some
|
||||
description of your company and the realm of its activities.
|
||||
|
||||
=====================================================================
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright © 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/>.
|
139
README.md
Normal file
139
README.md
Normal file
@ -0,0 +1,139 @@
|
||||
## Spherical Triangular Tessellation (STT) Generator
|
||||
|
||||
### Introduction
|
||||
|
||||
The spherical triangular tessellation is a kind of partition of the spherical surface composed by only triangular cells. This program could generate the STT based on an icosahedron. The STT generated by the program could be refined around given points, lines, polygons and circles on the spherical surface. The exterior and interior outlines of the STT could also be customized.
|
||||
|
||||
### Files and folders
|
||||
|
||||
1. **CMakeLists.txt** CMake project file;
|
||||
2. **\*.h and \*.cpp** Source files;
|
||||
3. **README.md** This file;
|
||||
4. **stt-example.png** Screen short of an example output;
|
||||
5. **archived** Old source files;
|
||||
6. **doc** Example files.
|
||||
|
||||
#### Source file lists
|
||||
|
||||
```shell
|
||||
head_functions.cc
|
||||
head_functions.h
|
||||
main.cc
|
||||
progress_bar.cc
|
||||
progress_bar.h
|
||||
struct_functions.cc
|
||||
struct_functions.h
|
||||
stt_class.h
|
||||
stt_close_surface.cc
|
||||
stt_create_branch.cc
|
||||
stt_create_tree.cc
|
||||
stt_cut_hole.cc
|
||||
stt_cut_outline.cc
|
||||
stt_delete_tree.cc
|
||||
stt_get_control_circle.cc
|
||||
stt_get_control_line.cc
|
||||
stt_get_control_point.cc
|
||||
stt_in_poly_outline.cc
|
||||
stt_in_triangle_circle.cc
|
||||
stt_in_triangle_line.cc
|
||||
stt_in_triangle_point.cc
|
||||
stt_in_triangle_polygon.cc
|
||||
stt_initial_icosahedron.cc
|
||||
stt_out_poly_outline.cc
|
||||
stt_output_msh_file.cc
|
||||
stt_output_neighbor.cc
|
||||
stt_output_triangle_center_location.cc
|
||||
stt_output_vertex_location.cc
|
||||
stt_return_branch_depth.cc
|
||||
stt_return_depth.cc
|
||||
stt_return_leaf.cc
|
||||
stt_routine.cc
|
||||
stt_set_command_record.cc
|
||||
stt_set_icosahedron_orient.cc
|
||||
stt_set_pole_equator_radius.cc
|
||||
stt_set_tree_depth.cc
|
||||
stt_sort_neighbor.cc
|
||||
```
|
||||
|
||||
### Installation
|
||||
|
||||
This program is a toolkit that is developed and maintained by Dr. Yi Zhang (zhangyiss@icloud.com) , which could be compiled and installed using the [CMake](https://cmake.org) software. Follow the instructions bellow to compile this program:
|
||||
|
||||
```shell
|
||||
mkdir build
|
||||
cd build
|
||||
make install
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
Usage: stt -d<minimal-depth>/<maximal-depth> [-r'WGS84'|'Earth'|'Moon'|<equator-radius>/<pole-radius>|<equator_radius>,<flat-rate>] [-o<orient-longitude>/<orient-latitude>] [-m<output-msh-filename>] [-v<output-vert-loc-filename>] [-t<output-tri-cen-filename>] [-n<output-tri-neg-filename>] [-p<control-point-filename>] [-l<control-line-filename>] [-g<control-poly-filename>] [-c<control-circle-filename>] [-s<outline-shape-filename>] [-k<hole-shape-filename>] [-h]
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
+ __-d__: Minimal and maximal depths of the quad-tree structures used to construct the STT.
|
||||
+ __-r__: Coordinate reference system of the output files.
|
||||
+ __-o__: Orientation of the top vertex of the base icosahedron.
|
||||
+ __-m__: Output filename of the Gmsh(.msh) file.
|
||||
+ __-v__: Output filename of the vertices' location.
|
||||
+ __-t__: Output filename of the triangles' center location.
|
||||
+ __-n__: Output filename of the triangles' neighbor.
|
||||
+ __-p__: Input filename of control points' location.
|
||||
+ __-l__: Input filename of control lines' location.
|
||||
+ __-g__: Input filename of control polygons' location.
|
||||
+ __-c__: Input filename of control circles' location.
|
||||
+ __-s__: Input filename of outline shapes' location.
|
||||
+ __-k__: Input filename of hole shapes' location.
|
||||
+ __-h__: show help information.
|
||||
|
||||
#### Input File Formats
|
||||
|
||||
##### Point format
|
||||
|
||||
The format of the control points' location is a plain text file. Each line of the file has the information of one control point which contains the spherical coordinates, maximal quad-tree depth, minimal resolution and physical group of the point. The program takes both the tree depth and resolution to control the fineness of the refined STT. The refinement of the STT will stop which ever the two conditions has been reached. Note that any line that starts with '#' or any empty line will be skipped. An example file:
|
||||
|
||||
```bash
|
||||
# <longitude> <latitude> <maximal-depth> <minimal-resolution> <physical-group>
|
||||
-45 -45 5 1.0 7
|
||||
45 -45 5 1.0 7
|
||||
45 45 5 1.0 7
|
||||
-45 45 5 1.0 7
|
||||
```
|
||||
|
||||
##### Circle format
|
||||
|
||||
The format of the control circles' location is a plain text file. Each line of the file has the information of one control circle which contains the spherical coordinates, spherical cap degree, maximal quad-tree depth, minimal resolution and physical group of the circle. The program takes both the tree depth and resolution to control the fineness of the refined STT. The refinement of the STT will stop which ever the two conditions has been reached. Note that any line that starts with '#' or any empty line will be skipped. An example file:
|
||||
|
||||
```bash
|
||||
# <longitude> <latitude> <spherical-cap-degree> <maximal-depth> <minimal-resolution> <physical-group>
|
||||
45 60 30 5 0.1 12
|
||||
-20 -45 20 6 0.1 13
|
||||
```
|
||||
|
||||
##### Line format
|
||||
|
||||
The format of the control lines', polygons', outlines', and holes' location is a plain text file. Blocks separated by empty lines contain information of control units. For each block, the first line has the number of the spherical locations, maximal quad-tree depth, minimal resolution and physical group of the unit. Followed by spherical coordinates of the unit.The program takes both the tree depth and resolution to control the fineness of the refined STT. The refinement of the STT will stop which ever the two conditions has been reached. Note that any line that starts with '#' or any empty line will be skipped. An example file:
|
||||
|
||||
```bash
|
||||
# <number-of-points> <maximal-depth> <minimal-resolution> <physical-group>
|
||||
# <longitude> <latitude>
|
||||
# <longitude> <latitude>
|
||||
# ... ...
|
||||
4 6 0.1 5
|
||||
-10 10
|
||||
50 15
|
||||
60 55
|
||||
-15 50
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
An example of multi-resolution STT:
|
||||
|
||||
```bash
|
||||
stt -d 3/7 -m example.msh -l doc/control_lines.txt -g doc/control_poly.txt -c doc/control_circle.txt
|
||||
```
|
||||
|
||||

|
2196
archived/QdTree_Icosa.h
Normal file
2196
archived/QdTree_Icosa.h
Normal file
File diff suppressed because it is too large
Load Diff
476
archived/dataStruct.h
Normal file
476
archived/dataStruct.h
Normal file
@ -0,0 +1,476 @@
|
||||
#ifndef _DATASTRUCT_H
|
||||
#define _DATASTRUCT_H
|
||||
#include "sysDefine.h"
|
||||
|
||||
//直角坐标系下的一个点
|
||||
struct cpoint
|
||||
{
|
||||
double x,y,z;
|
||||
cpoint() //初始化坐标值
|
||||
{
|
||||
x = y = z = MAX_DBL;
|
||||
}
|
||||
};
|
||||
typedef vector<cpoint> cpointArray;
|
||||
|
||||
//直角坐标点的一些数学运算
|
||||
cpoint operator -(cpoint a, cpoint b)
|
||||
{
|
||||
cpoint m;
|
||||
m.x=a.x-b.x;
|
||||
m.y=a.y-b.y;
|
||||
m.z=a.z-b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
cpoint operator +(cpoint a, cpoint b) //矢量加法
|
||||
{
|
||||
cpoint m;
|
||||
m.x=a.x+b.x;
|
||||
m.y=a.y+b.y;
|
||||
m.z=a.z+b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
cpoint operator *(double sign,cpoint b) //矢量乘法
|
||||
{
|
||||
cpoint m;
|
||||
m.x=sign*b.x;
|
||||
m.y=sign*b.y;
|
||||
m.z=sign*b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
//重载逻辑等操作符作用于矢量,判断两个直角点是否相等
|
||||
bool operator ==(cpoint a, cpoint b)
|
||||
{
|
||||
if(fabs(a.x-b.x)<ZERO&&fabs(a.y-b.y)<ZERO&&fabs(a.z-b.z)<ZERO)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
double dot(cpoint a, cpoint b) //矢量点乘
|
||||
{
|
||||
return a.x*b.x+a.y*b.y+a.z*b.z;
|
||||
}
|
||||
|
||||
cpoint cross(cpoint a,cpoint b) //矢量叉乘
|
||||
{
|
||||
cpoint v;
|
||||
v.x = a.y*b.z-a.z*b.y;
|
||||
v.y = a.z*b.x-a.x*b.z;
|
||||
v.z = a.x*b.y-a.y*b.x;
|
||||
return v;
|
||||
}
|
||||
|
||||
//返回两个直角坐标点的中点位置
|
||||
cpoint middle_cpoint(cpoint a,cpoint b)
|
||||
{
|
||||
cpoint c;
|
||||
c.x = 0.5*(a.x + b.x);
|
||||
c.y = 0.5*(a.y + b.y);
|
||||
c.z = 0.5*(a.z + b.z);
|
||||
return c;
|
||||
}
|
||||
|
||||
//返回两点之间的一个点 以第一个点为参考点 第三个参数为相对于原线段的比例
|
||||
cpoint scale_cpoint(cpoint a,cpoint b,double scale)
|
||||
{
|
||||
cpoint c;
|
||||
c.x = a.x + (b.x - a.x)*scale;
|
||||
c.y = a.y + (b.y - a.y)*scale;
|
||||
c.z = a.z + (b.z - a.z)*scale;
|
||||
return c;
|
||||
}
|
||||
|
||||
cpoint rescale_cpoint(cpoint a,double refr)
|
||||
{
|
||||
cpoint c;
|
||||
double m = sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
|
||||
c.x = a.x*refr/m;
|
||||
c.y = a.y*refr/m;
|
||||
c.z = a.z*refr/m;
|
||||
return c;
|
||||
}
|
||||
|
||||
double length_cpoint(cpoint v) //矢量模
|
||||
{
|
||||
return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
|
||||
}
|
||||
|
||||
double distance_cpoint(cpoint a, cpoint b)
|
||||
{
|
||||
cpoint m;
|
||||
double d;
|
||||
m.x=a.x-b.x;
|
||||
m.y=a.y-b.y;
|
||||
m.z=a.z-b.z;
|
||||
d = sqrt(m.x*m.x + m.y*m.y + m.z*m.z);
|
||||
return d;
|
||||
}
|
||||
|
||||
//计算两个向量的夹角
|
||||
double cpoint_angle(cpoint a,cpoint b)
|
||||
{
|
||||
return acos((a.x*b.x+a.y*b.y+a.z*b.z)/(sqrt(a.x*a.x+a.y*a.y+a.z*a.z)*sqrt(b.x*b.x+b.y*b.y+b.z*b.z)))*180.0/pi;
|
||||
}
|
||||
|
||||
//求三角形中心坐标
|
||||
cpoint Tri_center(cpoint vec1,cpoint vec2,cpoint vec3)
|
||||
{
|
||||
cpoint c;
|
||||
c.x = (vec1.x+vec2.x+vec3.x)/3.0;
|
||||
c.y = (vec1.y+vec2.y+vec3.y)/3.0;
|
||||
c.z = (vec1.z+vec2.z+vec3.z)/3.0;
|
||||
return c;
|
||||
}
|
||||
|
||||
//球坐标系下的一个点
|
||||
struct spoint
|
||||
{
|
||||
double lon,lat,rad;
|
||||
spoint() //初始化坐标值
|
||||
{
|
||||
lon = lat = rad = MAX_DBL;
|
||||
}
|
||||
};
|
||||
typedef vector<spoint> spointArray;
|
||||
|
||||
/*直角坐标与球坐标相互转换函数 注意这里使用的球坐标是地理坐标范围 即经度为-180~180 纬度为-90~90*/
|
||||
cpoint s2c(spoint s)
|
||||
{
|
||||
cpoint c;
|
||||
c.x = s.rad*sin((0.5 - s.lat/180.0)*pi)*cos((2.0 + s.lon/180.0)*pi);
|
||||
c.y = s.rad*sin((0.5 - s.lat/180.0)*pi)*sin((2.0 + s.lon/180.0)*pi);
|
||||
c.z = s.rad*cos((0.5 - s.lat/180.0)*pi);
|
||||
return c;
|
||||
}
|
||||
|
||||
spoint c2s(cpoint c)
|
||||
{
|
||||
spoint s;
|
||||
s.rad = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
|
||||
if (fabs(s.rad)<ZERO) //点距离原点极近 将点置于原点
|
||||
{
|
||||
s.lat = s.lon = s.rad = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.lat = 90.0 - acos(c.z/s.rad)*180.0/pi;
|
||||
s.lon = atan2(c.y,c.x)*180.0/pi;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
//顶点
|
||||
struct vertex
|
||||
{
|
||||
int id; //索引
|
||||
cpoint posic; //直角坐标系位置
|
||||
spoint posis; //球坐标系位置
|
||||
vertex()
|
||||
{
|
||||
id = -1; //初始化顶点索引值为-1 这里不需要初始化坐标位置 因为已经由相应的初始化函数完成了初始化
|
||||
}
|
||||
void set(int i) //设置索引值
|
||||
{
|
||||
id = i;
|
||||
}
|
||||
void set(cpoint c) //从直角坐标位置初始化
|
||||
{
|
||||
posic.x = c.x; posic.y = c.y; posic.z = c.z;
|
||||
posis = c2s(posic);
|
||||
}
|
||||
void set(spoint s) //从球坐标位置初始化
|
||||
{
|
||||
posis.lon = s.lon; posis.lat = s.lat; posis.rad = s.rad;
|
||||
posic = s2c(posis);
|
||||
}
|
||||
void info() //显示顶点信息
|
||||
{
|
||||
cout << id << " " << setprecision(16) << posic.x << " " << posic.y << " " << posic.z << " " << posis.lon << " " << posis.lat << " " << posis.rad << endl;
|
||||
}
|
||||
};
|
||||
typedef vector<vertex> vertexArray;
|
||||
typedef map<int,vertex> idMap; //顶点索引值映射 用于通过索引值寻找相应顶点
|
||||
typedef map<string,vertex> strMap; //顶点位置映射 用于通过顶点位置寻找相应顶点
|
||||
typedef map<int,int> outIdMap; //输出msh文件时重新索引三角形顶点集
|
||||
|
||||
//计算一个顶点向量的中点
|
||||
cpoint middle_vertex(vertexArray vert)
|
||||
{
|
||||
cpoint c;
|
||||
c.x = 0; c.y = 0; c.z = 0;
|
||||
if (!vert.empty())
|
||||
{
|
||||
for (int i = 0; i < vert.size(); i++)
|
||||
{
|
||||
c.x += vert.at(i).posic.x;
|
||||
c.y += vert.at(i).posic.y;
|
||||
c.z += vert.at(i).posic.z;
|
||||
}
|
||||
c.x /= vert.size();
|
||||
c.y /= vert.size();
|
||||
c.z /= vert.size();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/*旋转顶点的方位
|
||||
旋转的方式为首先绕着x轴旋转 然后绕着z轴旋转
|
||||
给出参考点的原位置olda与新位置newa以获取旋转参数 然后求取输入点oldb做相同旋转后的新坐标newb
|
||||
*/
|
||||
|
||||
vertex rotate_vertex(vertex olda,vertex newa,vertex oldb)
|
||||
{
|
||||
vertex newb;
|
||||
vertex temp_ref,temp_b;
|
||||
double yz_angle = (newa.posis.lat - olda.posis.lat)*pi/180.0;
|
||||
//首先绕olda.lon即x轴旋转oldb
|
||||
temp_b.posic.x = oldb.posic.x;
|
||||
temp_b.posic.y = oldb.posic.y*cos(-1.0*yz_angle)+oldb.posic.z*sin(-1.0*yz_angle);
|
||||
temp_b.posic.z = oldb.posic.z*cos(-1.0*yz_angle)-oldb.posic.y*sin(-1.0*yz_angle);
|
||||
temp_b.set(temp_b.posic);
|
||||
//计算绕x轴旋转后olda的位置 这是后一步旋转需要的参考值
|
||||
temp_ref.posic.x = olda.posic.x;
|
||||
temp_ref.posic.y = olda.posic.y*cos(-1.0*yz_angle)+olda.posic.z*sin(-1.0*yz_angle);
|
||||
temp_ref.posic.z = olda.posic.z*cos(-1.0*yz_angle)-olda.posic.y*sin(-1.0*yz_angle);
|
||||
temp_ref.set(temp_ref.posic);
|
||||
//注意绕z轴旋转的经度参考位置为olda绕x轴旋转后的经度值
|
||||
double xy_angle = (newa.posis.lon - temp_ref.posis.lon)*pi/180.0;
|
||||
//绕z轴旋转temp_b z值不变
|
||||
newb.id = oldb.id;
|
||||
newb.posic.x = temp_b.posic.x*cos(-1.0*xy_angle)+temp_b.posic.y*sin(-1.0*xy_angle);
|
||||
newb.posic.y = temp_b.posic.y*cos(-1.0*xy_angle)-temp_b.posic.x*sin(-1.0*xy_angle);
|
||||
newb.posic.z = temp_b.posic.z;
|
||||
newb.set(newb.posic);
|
||||
return newb;
|
||||
}
|
||||
|
||||
//点 点包含索引和一个顶点
|
||||
struct point
|
||||
{
|
||||
int id;
|
||||
int maxDepth;
|
||||
double minDeg;
|
||||
int physic;
|
||||
vertex vert;
|
||||
point()
|
||||
{
|
||||
id = -1;
|
||||
maxDepth = -1;
|
||||
minDeg = -1.0;
|
||||
}
|
||||
void info()
|
||||
{
|
||||
cout << id << " " << maxDepth << " " << minDeg << endl;
|
||||
vert.info();
|
||||
}
|
||||
};
|
||||
typedef vector<point> pointArray;
|
||||
|
||||
//折线 折线包含索引和一个顶点向量 顶点从前向后连成折线
|
||||
struct line
|
||||
{
|
||||
int id;
|
||||
int maxDepth;
|
||||
double minDeg;
|
||||
int physic;
|
||||
vertexArray vert;
|
||||
line()
|
||||
{
|
||||
id = -1;
|
||||
maxDepth = -1;
|
||||
minDeg = -1.0;
|
||||
}
|
||||
void info()
|
||||
{
|
||||
cout << id << " " << maxDepth << " " << minDeg << endl;
|
||||
for (int i = 0; i < vert.size(); i++)
|
||||
{
|
||||
vert.at(i).info();
|
||||
}
|
||||
}
|
||||
void clear_vert()
|
||||
{
|
||||
if (!vert.empty()) vert.clear();
|
||||
}
|
||||
};
|
||||
typedef vector<line> lineArray;
|
||||
|
||||
//多边形 多边形包含索引和一个顶点向量 顶点逆时针连成多边形 注意多边形第一个点和最后一个点应该一致
|
||||
struct polygon
|
||||
{
|
||||
int id;
|
||||
int maxDepth;
|
||||
double minDeg;
|
||||
int physic;
|
||||
vertexArray vert;
|
||||
polygon()
|
||||
{
|
||||
id = -1;
|
||||
maxDepth = -1;
|
||||
minDeg = -1.0;
|
||||
}
|
||||
void info()
|
||||
{
|
||||
cout << id << " " << maxDepth << " " << minDeg << endl;
|
||||
for (int i = 0; i < vert.size(); i++)
|
||||
{
|
||||
vert.at(i).info();
|
||||
}
|
||||
}
|
||||
void clear_vert()
|
||||
{
|
||||
if (!vert.empty()) vert.clear();
|
||||
}
|
||||
};
|
||||
typedef vector<polygon> polygonArray;
|
||||
|
||||
//圆形
|
||||
struct circle
|
||||
{
|
||||
int id;
|
||||
int maxDepth;
|
||||
double minDeg;
|
||||
double radDeg;
|
||||
int physic;
|
||||
vertex cen;
|
||||
};
|
||||
typedef vector<circle> circleArray;
|
||||
|
||||
//三角形信息结构体,包含三角形的三个顶点索引,逆时针排序
|
||||
struct triangle
|
||||
{
|
||||
int ids[3];//三角形顶点
|
||||
int physic; //三角形的物理属性组
|
||||
triangle() //初始化顶点索引
|
||||
{
|
||||
physic = 0; //默认的物理属性组为0
|
||||
ids[0] = ids[1] = ids[2] = -1;
|
||||
}
|
||||
};
|
||||
typedef vector<triangle> triangleArray;
|
||||
|
||||
//平面参数结构体
|
||||
struct planePara
|
||||
{
|
||||
double A,B,C,D;
|
||||
planePara()
|
||||
{
|
||||
A = B = C = D = MAX_DBL;
|
||||
}
|
||||
};
|
||||
|
||||
//矢量与平面的交点
|
||||
cpoint lineOnPlane(cpoint c,cpoint normal,cpoint p)
|
||||
{
|
||||
cpoint m;
|
||||
m.x = 0; m.y = 0; m.z = 0;
|
||||
double t;
|
||||
if (dot(normal,p) != 0) //平面与矢量平行
|
||||
{
|
||||
t = dot(normal,c)/dot(normal,p);
|
||||
m.x += p.x*t;
|
||||
m.y += p.y*t;
|
||||
m.z += p.z*t;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
//正二十面体结构体,包含正二十面体的十二个顶点和二十个面的顶点索引,三角面索引按逆时针排序
|
||||
struct Icosa
|
||||
{
|
||||
vertex vert[12];
|
||||
triangle tri[20];
|
||||
};
|
||||
|
||||
//四叉树节点结构体,这是整个算法中最重要的结构体,包含一个指向triangle的指针和指向四个子节点的指针
|
||||
struct Qdtree_node
|
||||
{
|
||||
int id;//节点的编号
|
||||
int outId;//节点在文件输出时候的id 这个id会在return_leaf函数中确定
|
||||
int depth;//节点深度
|
||||
bool outOK; //节点是否可以被输出
|
||||
triangle* tri;//节点三角形顶点索引 逆时针
|
||||
Qdtree_node* children[4];//四个子节点指针
|
||||
Qdtree_node() //初始化变量值
|
||||
{
|
||||
id = -1;
|
||||
depth = -1;
|
||||
outOK = true;
|
||||
children[0] = children[1] = children[2] = children[3] = NULL;
|
||||
tri = new triangle;
|
||||
}
|
||||
void info()
|
||||
{
|
||||
cout << id << endl;
|
||||
cout << depth << endl;
|
||||
cout << outOK << endl;
|
||||
cout << tri->ids[0] << " " << tri->ids[1] << " " << tri->ids[2] << endl;
|
||||
}
|
||||
};
|
||||
|
||||
//四叉树结构
|
||||
struct Qdtree
|
||||
{
|
||||
Qdtree_node *root;//根节点
|
||||
};
|
||||
|
||||
/*
|
||||
// 在现行的代码中 我们不再使用平面投影算法 因此不再需要使用以下的数据类型与函数
|
||||
struct point2d
|
||||
{
|
||||
double x,y;
|
||||
point2d()
|
||||
{
|
||||
x = y = MAX_DBL;
|
||||
}
|
||||
};
|
||||
|
||||
//由三个顶点计算平面参数
|
||||
planePara get_planePara(cpoint v1,cpoint v2,cpoint v3)
|
||||
{
|
||||
planePara pl;
|
||||
pl.A = (v2.y - v1.y)*(v3.z - v1.z) - (v3.y - v1.y)*(v2.z - v1.z);
|
||||
pl.B = (v2.z - v1.z)*(v3.x - v1.x) - (v3.z - v1.z)*(v2.x - v1.x);
|
||||
pl.C = (v2.x - v1.x)*(v3.y - v1.y) - (v3.x - v1.x)*(v2.y - v1.y);
|
||||
pl.D = -1.0*(pl.A*v1.x + pl.B*v1.y + pl.C*v1.z);
|
||||
return pl;
|
||||
}
|
||||
|
||||
//点在平面上的投影
|
||||
vertex dotOnPlane(planePara pl,vertex v)
|
||||
{
|
||||
vertex m;
|
||||
double t = (pl.A*v.posic.x + pl.B*v.posic.y + pl.C*v.posic.z + pl.D)/(pl.A*pl.A + pl.B*pl.B + pl.C*pl.C);
|
||||
m.posic.x = v.posic.x - pl.A*t;
|
||||
m.posic.y = v.posic.y - pl.B*t;
|
||||
m.posic.z = v.posic.z - pl.C*t;
|
||||
m.set(m.posic);
|
||||
return m;
|
||||
}
|
||||
|
||||
//以平面内一条直线为x轴 起点为原点 计算另一个点到新的坐标系内的坐标值
|
||||
point2d newXY(vertex v1,vertex v2,vertex v3,vertex p)
|
||||
{
|
||||
point2d p2d;
|
||||
vertex m,ap;
|
||||
cpoint dir_map,dir_v123;
|
||||
m.posic = v2.posic - v1.posic;
|
||||
ap.posic = p.posic - v1.posic;
|
||||
//因为cos函数在这种情况下自动可以区分正负情况 所以x值的计算比较简单
|
||||
p2d.x = dot(ap.posic,m.posic)/length_cpoint(m.posic);
|
||||
//下面我们来计算y值 相对比较麻烦 首先计算一下距离
|
||||
p2d.y = sqrt(pow(length_cpoint(ap.posic),2) - p2d.x*p2d.x);
|
||||
//计算一下三角形的外向法矢量 m与ap的法矢量
|
||||
dir_v123 = cross(v2.posic-v1.posic,v3.posic-v1.posic);
|
||||
dir_map = cross(v2.posic-v1.posic,ap.posic);
|
||||
//如果两个向量同向则y值为正 否则为负
|
||||
if (dot(dir_v123,dir_map) < 0) p2d.y *= -1.0;
|
||||
return p2d;
|
||||
}
|
||||
*/
|
||||
#endif
|
21
archived/main.cpp
Normal file
21
archived/main.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "QdTree_Icosa.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char para[1024];
|
||||
QdTree_Icosa q;
|
||||
if (argc == 1)
|
||||
{
|
||||
strcpy(para,"NULL");
|
||||
q.runtine(para);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
strcpy(para,argv[i]);
|
||||
q.runtine(para);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
154
archived/progressBar_imp.h
Normal file
154
archived/progressBar_imp.h
Normal file
@ -0,0 +1,154 @@
|
||||
#ifndef _PROGRESS_BAR_
|
||||
#define _PROGRESS_BAR_
|
||||
|
||||
//#ifdef _WINDOWS
|
||||
//#include <windows.h>
|
||||
//#else
|
||||
//#include <sys/ioctl.h>
|
||||
//#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#define TOTAL_PERCENTAGE 100.0
|
||||
#define CHARACTER_WIDTH_PERCENTAGE 4
|
||||
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
|
||||
ProgressBar();
|
||||
ProgressBar(unsigned long n_, const char *description_="", std::ostream& out_=std::cerr);
|
||||
|
||||
void SetFrequencyUpdate(unsigned long frequency_update_);
|
||||
void SetStyle(const char* unit_bar_, const char* unit_space_);
|
||||
|
||||
void Progressed(unsigned long idx_);
|
||||
|
||||
private:
|
||||
|
||||
unsigned long n;
|
||||
unsigned int desc_width;
|
||||
unsigned long frequency_update;
|
||||
std::ostream* out;
|
||||
|
||||
const char *description;
|
||||
const char *unit_bar;
|
||||
const char *unit_space;
|
||||
|
||||
void ClearBarField();
|
||||
int GetConsoleWidth();
|
||||
int GetBarLength();
|
||||
|
||||
};
|
||||
|
||||
ProgressBar::ProgressBar() {}
|
||||
|
||||
ProgressBar::ProgressBar(unsigned long n_, const char* description_, std::ostream& out_){
|
||||
|
||||
n = n_;
|
||||
frequency_update = n_;
|
||||
description = description_;
|
||||
out = &out_;
|
||||
|
||||
unit_bar = "\u2588";
|
||||
unit_space = "-";
|
||||
desc_width = std::strlen(description); // character width of description field
|
||||
|
||||
}
|
||||
|
||||
void ProgressBar::SetFrequencyUpdate(unsigned long frequency_update_){
|
||||
|
||||
if(frequency_update_ > n){
|
||||
frequency_update = n; // prevents crash if freq_updates_ > n_
|
||||
}
|
||||
else{
|
||||
frequency_update = frequency_update_;
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressBar::SetStyle(const char* unit_bar_, const char* unit_space_){
|
||||
|
||||
unit_bar = unit_bar_;
|
||||
unit_space = unit_space_;
|
||||
}
|
||||
|
||||
int ProgressBar::GetConsoleWidth(){
|
||||
|
||||
int width;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
width = csbi.srWindow.Right - csbi.srWindow.Left;
|
||||
#else
|
||||
struct winsize win;
|
||||
ioctl(0, TIOCGWINSZ, &win);
|
||||
width = win.ws_col;
|
||||
#endif
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
int ProgressBar::GetBarLength(){
|
||||
|
||||
// get console width and according adjust the length of the progress bar
|
||||
|
||||
int bar_length = static_cast<int>((GetConsoleWidth() - desc_width - CHARACTER_WIDTH_PERCENTAGE) / 2.);
|
||||
|
||||
return bar_length;
|
||||
}
|
||||
|
||||
void ProgressBar::ClearBarField(){
|
||||
|
||||
for(int i=0;i<GetConsoleWidth();++i){
|
||||
*out << " ";
|
||||
}
|
||||
*out << "\r" << std::flush;
|
||||
}
|
||||
|
||||
void ProgressBar::Progressed(unsigned long idx_)
|
||||
{
|
||||
try{
|
||||
if(idx_ > n) throw idx_;
|
||||
|
||||
// determines whether to update the progress bar from frequency_update
|
||||
if ((idx_ != n-1) && ((idx_+1) % (n/frequency_update) != 0)) return;
|
||||
|
||||
// calculate the size of the progress bar
|
||||
int bar_size = GetBarLength();
|
||||
|
||||
// calculate percentage of progress
|
||||
double progress_percent = idx_* TOTAL_PERCENTAGE/(n-1);
|
||||
|
||||
// calculate the percentage value of a unit bar
|
||||
double percent_per_unit_bar = TOTAL_PERCENTAGE/bar_size;
|
||||
|
||||
// display progress bar
|
||||
*out << " " << description << " |";
|
||||
|
||||
for(int bar_length=0;bar_length<=bar_size-1;++bar_length){
|
||||
if(bar_length*percent_per_unit_bar<progress_percent){
|
||||
*out << unit_bar;
|
||||
}
|
||||
else{
|
||||
*out << unit_space;
|
||||
}
|
||||
}
|
||||
|
||||
if(idx_ == n-1)
|
||||
*out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush << std::endl;
|
||||
else *out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush;
|
||||
}
|
||||
catch(unsigned long e){
|
||||
ClearBarField();
|
||||
std::cerr << "PROGRESS_BAR_EXCEPTION: _idx (" << e << ") went out of bounds, greater than n (" << n << ")." << std::endl << std::flush;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
96
archived/sysDefine.h
Normal file
96
archived/sysDefine.h
Normal file
@ -0,0 +1,96 @@
|
||||
#ifndef _SYSDEFINE_H
|
||||
#define _SYSDEFINE_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "string"
|
||||
#include "cmath"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "vector"
|
||||
#include "map"
|
||||
#include "algorithm"
|
||||
#include "ctime"
|
||||
|
||||
#define MAX_DBL 1.0e+30
|
||||
#define MIN_BDL -1.0e+30
|
||||
#define ZERO 1.0e-20
|
||||
|
||||
#define pole_radius 6351251.669//WGS84椭球极半径
|
||||
#define equator_radius 6378137//WGS84椭球长半径
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define golden_mean (sqrt(5.0)+1)/2//黄金比例
|
||||
#define defaultR 1e+5
|
||||
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<int> _1iArray;
|
||||
typedef vector<vector<int> > _2iArray;
|
||||
|
||||
//操作计时
|
||||
clock_t start,finish;
|
||||
|
||||
//以度计算的正弦函数
|
||||
inline double sind(double degree)
|
||||
{
|
||||
return sin(degree*pi/180.0);
|
||||
}
|
||||
|
||||
//以度计算的余弦函数
|
||||
inline double cosd(double degree)
|
||||
{
|
||||
return cos(degree*pi/180.0);
|
||||
}
|
||||
|
||||
//全局函数
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//计算WGS84椭球半径
|
||||
double WGS84_r(double lati)
|
||||
{
|
||||
return pole_radius*equator_radius/sqrt(pow(pole_radius,2)*pow(cos((double) lati*pi/180.0),2)+pow(equator_radius,2)*pow(sin((double) lati*pi/180.0),2));
|
||||
}
|
||||
|
||||
//计算一个参考椭球或者参考球在纬度位置的半径
|
||||
double REF_r(double lati,double refr,double refR)
|
||||
{
|
||||
return refr*refR/sqrt(pow(refr,2)*pow(cos((double) lati*pi/180.0),2)+pow(refR,2)*pow(sin((double) lati*pi/180.0),2));
|
||||
}
|
||||
|
||||
// 球面双线性插值函数 以度为单位的版本
|
||||
double SphBiInterp_deg(double CoLat1,double CoLat2,double Lon1,double Lon2,double CoLat0,double Lon0,double h11,double h12,double h21,double h22)
|
||||
{
|
||||
double Delta=(Lon2-Lon1)*(cosd(CoLat2)-cosd(CoLat1));
|
||||
double A=(Lon1*(h12-h22)+Lon2*(h21-h11))/Delta;
|
||||
double B=(cosd(CoLat1)*(h21-h22)+cosd(CoLat2)*(h12-h11))/Delta;
|
||||
double C=(h11+h22-h21-h12)/Delta;
|
||||
double D=(Lon2*cosd(CoLat2)*h11-Lon2*cosd(CoLat1)*h21+Lon1*cosd(CoLat1)*h22-Lon1*cosd(CoLat2)*h12)/Delta;
|
||||
double h0=A*cosd(CoLat0)+B*Lon0+C*Lon0*cosd(CoLat0)+D;
|
||||
return h0;
|
||||
}
|
||||
#endif
|
59
archived/template.sh
Normal file
59
archived/template.sh
Normal file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
# 从命令行获取块名称
|
||||
blocknames=$1
|
||||
# 声明常量
|
||||
execfile=./bin/Qdtree_icosa.ex
|
||||
parafile=log.txt
|
||||
# 正演参数块 名称为forward
|
||||
if [[ $blocknames == "moho" ]]; then
|
||||
# 声明程序参数文件内容并通过cat保存在parafile
|
||||
cat <<- EOF > $parafile
|
||||
basic-depth=5
|
||||
max-depth=10
|
||||
orientation=NULL
|
||||
extra-points=NULL
|
||||
extra-lines=NULL
|
||||
extra-polys=NULL
|
||||
extra-circles=NULL
|
||||
outline-polys=NULL
|
||||
msh-save=d5-globe.msh
|
||||
sph-save=NULL
|
||||
EOF
|
||||
# 运行程序
|
||||
$execfile $parafile
|
||||
|
||||
elif [[ $blocknames == "USA" ]]; then
|
||||
# 声明程序参数文件内容并通过cat保存在parafile
|
||||
cat <<- EOF > $parafile
|
||||
basic-depth=3
|
||||
max-depth=7
|
||||
orientation=NULL
|
||||
extra-points=NULL
|
||||
extra-lines=NULL
|
||||
extra-polys=doc/test/china-border.txt
|
||||
extra-circles=NULL
|
||||
outline-polys=NULL
|
||||
msh-save=china.msh
|
||||
sph-save=NULL
|
||||
EOF
|
||||
# 运行程序
|
||||
$execfile $parafile
|
||||
|
||||
elif [[ $blocknames == "test" ]]; then
|
||||
# 声明程序参数文件内容并通过cat保存在parafile
|
||||
cat <<- EOF > $parafile
|
||||
basic-depth=6
|
||||
max-depth=10
|
||||
orientation=NULL
|
||||
extra-points=NULL
|
||||
extra-lines=NULL
|
||||
extra-polys=NULL
|
||||
extra-circles=NULL
|
||||
outline-polys=doc/test/test-outline.txt
|
||||
msh-save=test-d6.msh
|
||||
sph-save=NULL
|
||||
EOF
|
||||
# 运行程序
|
||||
$execfile $parafile
|
||||
|
||||
fi
|
17
config.sh
Executable file
17
config.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
cmd=${1}
|
||||
package=stt
|
||||
stow_dir=/opt/stow
|
||||
target_dir=/usr/local
|
||||
|
||||
if [[ ${cmd} == "configure" && ! -d "build/" ]]; then
|
||||
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=${stow_dir}/${package} -DCMAKE_BUILD_TYPE=Release
|
||||
elif [[ ${cmd} == "configure" ]]; then
|
||||
cd build && rm -rf * && cmake .. -DCMAKE_INSTALL_PREFIX=${stow_dir}/${package} -DCMAKE_BUILD_TYPE=Release
|
||||
elif [[ ${cmd} == "build" ]]; then
|
||||
cd build && make
|
||||
elif [[ ${cmd} == "install" ]]; then
|
||||
cd build && sudo make install
|
||||
sudo stow --dir=${stow_dir} --target=${target_dir} ${package}
|
||||
fi
|
2
doc/control_circle.txt
Normal file
2
doc/control_circle.txt
Normal file
@ -0,0 +1,2 @@
|
||||
45 60 30 5 0.1 12
|
||||
-20 -45 20 6 0.1 13
|
5
doc/control_lines.txt
Normal file
5
doc/control_lines.txt
Normal file
@ -0,0 +1,5 @@
|
||||
4 7 0.1 4
|
||||
20 15
|
||||
66 45
|
||||
126 14
|
||||
156 -20
|
4
doc/control_points.txt
Normal file
4
doc/control_points.txt
Normal file
@ -0,0 +1,4 @@
|
||||
-45 -45 5 1.0 7
|
||||
45 -45 5 1.0 7
|
||||
45 45 5 1.0 7
|
||||
-45 45 5 1.0 7
|
5
doc/control_poly.txt
Normal file
5
doc/control_poly.txt
Normal file
@ -0,0 +1,5 @@
|
||||
4 6 -1 5
|
||||
-10 10
|
||||
50 15
|
||||
60 55
|
||||
-15 50
|
42966
doc/example.msh
Normal file
42966
doc/example.msh
Normal file
File diff suppressed because it is too large
Load Diff
5
doc/outline.txt
Normal file
5
doc/outline.txt
Normal file
@ -0,0 +1,5 @@
|
||||
4 0 0 0
|
||||
-10 10
|
||||
50 15
|
||||
60 55
|
||||
-15 50
|
BIN
doc/stt-example.png
Normal file
BIN
doc/stt-example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 267 KiB |
8
src/CMakeLists.txt
Normal file
8
src/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
aux_source_directory(. STT_SRC)
|
||||
|
||||
add_executable(stt ${STT_SRC})
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set_target_properties(stt PROPERTIES CXX_STANDARD 11)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
install(TARGETS stt RUNTIME DESTINATION sbin)
|
65
src/head_functions.cc
Normal file
65
src/head_functions.cc
Normal file
@ -0,0 +1,65 @@
|
||||
#include "head_functions.h"
|
||||
|
||||
// degree version of sin() and cos()
|
||||
inline double sind(double degree){
|
||||
return sin(degree*Pi/180.0);
|
||||
}
|
||||
|
||||
inline double cosd(double degree){
|
||||
return cos(degree*Pi/180.0);
|
||||
}
|
||||
// calculate the semi-radius at a given latitude given the pole and equator radius of the reference system
|
||||
double EllipsoidRadius(double latitude,double pole_radius,double equator_radius){
|
||||
return pole_radius*equator_radius/sqrt(pow(pole_radius,2)*pow(cosd(latitude),2)+pow(equator_radius,2)*pow(sind(latitude),2));
|
||||
}
|
||||
// Bilinear interpolation on the sphere
|
||||
/*
|
||||
latitude
|
||||
|
|
||||
|
|
||||
value21-------value22
|
||||
| |
|
||||
| |
|
||||
| 0 |
|
||||
| |
|
||||
| |
|
||||
value11-------value12----> longitude
|
||||
*/
|
||||
double SphBilinearInterpolation(
|
||||
double latitude1,double latitude2,double longitude1,double longitude2,
|
||||
double latitude0,double longitude0,
|
||||
double value11,double value12,double value21,double value22){
|
||||
double colatitude1 = 90.0 - latitude1;
|
||||
double colatitude2 = 90.0 - latitude2;
|
||||
double colatitude0 = 90.0 - latitude0;
|
||||
double delta=(longitude2-longitude1)*(cosd(colatitude2)-cosd(colatitude1));
|
||||
double A=(longitude1*(value12-value22)+longitude2*(value21-value11))/delta;
|
||||
double B=(cosd(colatitude1)*(value21-value22)+cosd(colatitude2)*(value12-value11))/delta;
|
||||
double C=(value11+value22-value21-value12)/delta;
|
||||
double D=(longitude2*cosd(colatitude2)*value11-longitude2*cosd(colatitude1)*value21+longitude1*cosd(colatitude1)*value22-longitude1*cosd(colatitude2)*value12)/delta;
|
||||
return A*cosd(colatitude0)+B*longitude0+C*longitude0*cosd(colatitude0)+D;
|
||||
}
|
||||
// Convert a string to stringstream
|
||||
stringstream Str2Ss(string input_string){
|
||||
stringstream sstr;
|
||||
sstr.str(""); sstr.clear(); sstr.str(input_string);
|
||||
return sstr;
|
||||
}
|
||||
// Check the existence of a input file and return the running status
|
||||
int OpenInfile(ifstream &input_file,char* filename){
|
||||
input_file.open(filename);
|
||||
if (!input_file){
|
||||
cerr << BOLDRED << "Error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// Check the existence of a output file and return the running status
|
||||
int OpenOutfile(ofstream &output_file,char* filename){
|
||||
output_file.open(filename);
|
||||
if (!output_file){
|
||||
cerr << BOLDRED << "Error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
71
src/head_functions.h
Normal file
71
src/head_functions.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef _HEAD_FUNCTIONS_H
|
||||
#define _HEAD_FUNCTIONS_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "vector"
|
||||
#include "map"
|
||||
#include "algorithm"
|
||||
#include "ctime"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// terminal controls
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define BOLDGREEN "\033[1m\033[32m"
|
||||
#define BOLDBLUE "\033[1m\033[34m"
|
||||
#define UNDERLINE "\033[1m\033[4m"
|
||||
#define RESET "\033[0m"
|
||||
#define MOVEUP(x) printf("\033[%dA", (x))
|
||||
#define MOVEDOWN(x) printf("\033[%dB", (x))
|
||||
#define MOVELEFT(x) printf("\033[%dD", (x))
|
||||
#define MOVERIGHT(x) printf("\033[%dC", (x))
|
||||
#define MOVETO(y,x) printf("\033[%d;%dH", (y), (x))
|
||||
#define CLEARLINE "\033[K"
|
||||
#define CLEARALL "\033[2J"
|
||||
|
||||
// define some mathematic constants
|
||||
#define DBL_MAX 1.0e+30
|
||||
#define DBL_MIN -1.0e+30
|
||||
#define ZERO 1.0e-20
|
||||
#define DefaultR 1e+5
|
||||
|
||||
// define some physical constants
|
||||
// semi-radius (pole and equator) of the WGS84 reference system
|
||||
#define WGS84_r 6356752.314245179
|
||||
#define WGS84_R 6378137.0
|
||||
// mean radius of the Earth and Moon
|
||||
#define Earth_r 6371008.8
|
||||
#define Moon_r 1738000
|
||||
// Pi and the golden ratio
|
||||
#define Pi (4.0*atan(1.0))
|
||||
#define GoldenMean ((sqrt(5.0)+1)/2)
|
||||
// Universal gravitational constant
|
||||
#define G0 6.67408e-11
|
||||
|
||||
// Macro functions
|
||||
#define MAX(a,b) (a>b?a:b)
|
||||
#define MIN(a,b) (a<b?a:b)
|
||||
#define SetToBox(low,high,input) (MAX(low,MIN(high,input)))
|
||||
|
||||
// Define global functions
|
||||
// degree version of sin() and cos()
|
||||
inline double sind(double);
|
||||
inline double cosd(double);
|
||||
// calculate the semi-radius at a given latitude given the pole and equator radius of the reference system
|
||||
double EllipsoidRadius(double,double,double);
|
||||
// Bilinear interpolation on the spherical sphere
|
||||
double SphBilinearInterpolation(double,double,double,double,double,double,double,double,double,double);
|
||||
// Convert a string to stringstream
|
||||
stringstream Str2Ss(string);
|
||||
// Check the existence of a input file and return the running status
|
||||
int OpenInfile(ifstream&,char*);
|
||||
// Check the existence of a output file and return the running status
|
||||
int OpenOutfile(ofstream&,char*);
|
||||
#endif
|
128
src/main.cc
Normal file
128
src/main.cc
Normal file
@ -0,0 +1,128 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void disp_help(char* proname){
|
||||
string exe_name = proname;
|
||||
exe_name = " " + exe_name +
|
||||
" -d<minimal-depth>/<maximal-depth> \
|
||||
[-r'WGS84'|'Earth'|'Moon'|<equator-radius>/<pole-radius>|<equator_radius>,<flat-rate>] \
|
||||
[-o<orient-longitude>/<orient-latitude>] \
|
||||
[-m<output-msh-filename>] \
|
||||
[-v<output-vert-loc-filename>] \
|
||||
[-t<output-tri-cen-filename>] \
|
||||
[-n<output-tri-neg-filename>] \
|
||||
[-p<control-point-filename>] \
|
||||
[-l<control-line-filename>] \
|
||||
[-g<control-poly-filename>] \
|
||||
[-c<control-circle-filename>] \
|
||||
[-s<outline-shape-filename>] \
|
||||
[-k<hole-shape-filename>] \
|
||||
[-h]";
|
||||
clog << proname << " - v1.3 A generator of the Spherical Triangular Tessellation (STT)." << endl;
|
||||
clog << "Usage: " << exe_name << endl;
|
||||
clog << "Options:" << endl;
|
||||
clog << "\t-d\tMinimal and maximal quad-tree depths of the output STT." << endl;
|
||||
clog << "\t-r\tCoordinate reference system of the output STT, the default is 1e+5/1e+5." << endl;
|
||||
clog << "\t-o\tOrientation of the top vertex of the base icosahedron, the default is 0/90." << endl;
|
||||
clog << "\t-m\tOutput Gmsh(.msh) filename." << endl;
|
||||
clog << "\t-v\tOutput vertex location(.txt) filename." << endl;
|
||||
clog << "\t-t\tOutput triangle center location(.txt) filename." << endl;
|
||||
clog << "\t-n\tOutput triangle neighbor(.txt) filename." << endl;
|
||||
clog << "\t-p\tInput control point location(.txt) filename." << endl;
|
||||
clog << "\t-l\tInput control line location(.txt) filename." << endl;
|
||||
clog << "\t-g\tInput control polygon location(.txt) filename." << endl;
|
||||
clog << "\t-c\tInput control circle location(.txt) filename." << endl;
|
||||
clog << "\t-s\tInput outline polygon location(.txt) filename." << endl;
|
||||
clog << "\t-k\tInput hole polygon location(.txt) filename." << endl;
|
||||
clog << "\t-h\tShow help information." << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
/*map of input options
|
||||
0 -> tree depths
|
||||
1 -> coordinate reference system
|
||||
2 -> orientation of the base icosahedron
|
||||
3 -> output filename for the constructed model (Gmsh .msh file)
|
||||
4 -> output filename for vertex locations
|
||||
5 -> output filename for triangle's center locations
|
||||
6 -> output filename for triangle's neighboring index
|
||||
7 -> input filename for point constraints
|
||||
8 -> input filename for line constraints
|
||||
9 -> input filename for polygon constraints
|
||||
10-> input filename for circle constraints
|
||||
11-> input filename for outline shape constraints
|
||||
12-> input filename for hole shape constraints*/
|
||||
char input_options[13][1024];
|
||||
for (int i = 0; i < 13; i++){
|
||||
strcpy(input_options[i],"NULL");
|
||||
}
|
||||
|
||||
// show help information is no options is read
|
||||
if (argc == 1){
|
||||
disp_help(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int curr, option_number;
|
||||
while((curr = getopt(argc,argv,"hd:r:o:m:v:t:n:p:l:g:c:s:k:")) != -1){
|
||||
// get option number
|
||||
switch (curr){
|
||||
case 'h': // show help information
|
||||
disp_help(argv[0]); return 0;
|
||||
case 'd':
|
||||
option_number = 0; break;
|
||||
case 'r':
|
||||
option_number = 1; break;
|
||||
case 'o':
|
||||
option_number = 2; break;
|
||||
case 'm':
|
||||
option_number = 3; break;
|
||||
case 'v':
|
||||
option_number = 4; break;
|
||||
case 't':
|
||||
option_number = 5; break;
|
||||
case 'n':
|
||||
option_number = 6; break;
|
||||
case 'p':
|
||||
option_number = 7; break;
|
||||
case 'l':
|
||||
option_number = 8; break;
|
||||
case 'g':
|
||||
option_number = 9; break;
|
||||
case 'c':
|
||||
option_number =10; break;
|
||||
case 's':
|
||||
option_number =11; break;
|
||||
case 'k':
|
||||
option_number =12; break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'd' || optopt == 'r' || optopt == 'o' || optopt == 'm' || optopt == 'n'
|
||||
|| optopt == 'v' || optopt == 't' || optopt == 'p' || optopt == 'l'
|
||||
|| optopt == 'g' || optopt == 'c' || optopt == 's' || optopt == 'k'){
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
return 0;
|
||||
}
|
||||
else if (isprint(optopt)){
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
return 0;
|
||||
} break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (1!=sscanf(optarg,"%s",input_options[option_number])){
|
||||
cerr<<BOLDRED<<"Error ==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
SttGenerator instance;
|
||||
// record commands
|
||||
instance.set_command_record(argc,argv);
|
||||
// generate stt model
|
||||
instance.Routine(input_options);
|
||||
return 0;
|
||||
}
|
114
src/progress_bar.cc
Normal file
114
src/progress_bar.cc
Normal file
@ -0,0 +1,114 @@
|
||||
//#ifdef _WINDOWS
|
||||
//#include <windows.h>
|
||||
//#else
|
||||
//#include <sys/ioctl.h>
|
||||
//#endif
|
||||
|
||||
#include "progress_bar.h"
|
||||
|
||||
ProgressBar::ProgressBar() {}
|
||||
|
||||
ProgressBar::ProgressBar(unsigned long n_, const char* description_, std::ostream& out_){
|
||||
|
||||
n = n_;
|
||||
frequency_update = n_;
|
||||
description = description_;
|
||||
out = &out_;
|
||||
|
||||
unit_bar = "\u2588";
|
||||
unit_space = "-";
|
||||
desc_width = std::strlen(description); // character width of description field
|
||||
|
||||
}
|
||||
|
||||
void ProgressBar::SetFrequencyUpdate(unsigned long frequency_update_){
|
||||
|
||||
if(frequency_update_ > n){
|
||||
frequency_update = n; // prevents crash if freq_updates_ > n_
|
||||
}
|
||||
else{
|
||||
frequency_update = frequency_update_;
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressBar::SetStyle(const char* unit_bar_, const char* unit_space_){
|
||||
|
||||
unit_bar = unit_bar_;
|
||||
unit_space = unit_space_;
|
||||
}
|
||||
|
||||
int ProgressBar::GetConsoleWidth(){
|
||||
|
||||
int width;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
width = csbi.srWindow.Right - csbi.srWindow.Left;
|
||||
#else
|
||||
struct winsize win;
|
||||
//注意!当我们使用pipe here-doc等通道获取程序参数时无法正确的获取窗口大小 此时我们将使用预定值
|
||||
if (ioctl(0, TIOCGWINSZ, &win) != -1)
|
||||
width = win.ws_col;
|
||||
else width = 100;
|
||||
#endif
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
int ProgressBar::GetBarLength(){
|
||||
|
||||
// get console width and according adjust the length of the progress bar
|
||||
|
||||
int bar_length = static_cast<int>((GetConsoleWidth() - desc_width - CHARACTER_WIDTH_PERCENTAGE) / 2.);
|
||||
|
||||
return bar_length;
|
||||
}
|
||||
|
||||
void ProgressBar::ClearBarField(){
|
||||
|
||||
for(int i=0;i<GetConsoleWidth();++i){
|
||||
*out << " ";
|
||||
}
|
||||
*out << "\r" << std::flush;
|
||||
}
|
||||
|
||||
void ProgressBar::Progressed(unsigned long idx_)
|
||||
{
|
||||
try{
|
||||
if(idx_ > n) throw idx_;
|
||||
|
||||
// determines whether to update the progress bar from frequency_update
|
||||
if ((idx_ != n-1) && ((idx_+1) % (n/frequency_update) != 0)) return;
|
||||
|
||||
// calculate the size of the progress bar
|
||||
int bar_size = GetBarLength();
|
||||
|
||||
// calculate percentage of progress
|
||||
double progress_percent = idx_* TOTAL_PERCENTAGE/(n-1);
|
||||
|
||||
// calculate the percentage value of a unit bar
|
||||
double percent_per_unit_bar = TOTAL_PERCENTAGE/bar_size;
|
||||
|
||||
// display progress bar
|
||||
*out << " " << description << " |";
|
||||
|
||||
for(int bar_length=0;bar_length<=bar_size-1;++bar_length){
|
||||
if(bar_length*percent_per_unit_bar<progress_percent){
|
||||
*out << unit_bar;
|
||||
}
|
||||
else{
|
||||
*out << unit_space;
|
||||
}
|
||||
}
|
||||
|
||||
if(idx_ == n-1)
|
||||
*out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush << std::endl;
|
||||
else *out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush;
|
||||
}
|
||||
catch(unsigned long e){
|
||||
ClearBarField();
|
||||
std::cerr << "PROGRESS_BAR_EXCEPTION: _idx (" << e << ") went out of bounds, greater than n (" << n << ")." << std::endl << std::flush;
|
||||
}
|
||||
|
||||
}
|
41
src/progress_bar.h
Normal file
41
src/progress_bar.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef _PROGRESS_BAR_
|
||||
#define _PROGRESS_BAR_
|
||||
#include <sys/ioctl.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#define TOTAL_PERCENTAGE 100.0
|
||||
#define CHARACTER_WIDTH_PERCENTAGE 4
|
||||
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
|
||||
ProgressBar();
|
||||
ProgressBar(unsigned long n_, const char *description_="", std::ostream& out_=std::cerr);
|
||||
|
||||
void SetFrequencyUpdate(unsigned long frequency_update_);
|
||||
void SetStyle(const char* unit_bar_, const char* unit_space_);
|
||||
|
||||
void Progressed(unsigned long idx_);
|
||||
|
||||
private:
|
||||
|
||||
unsigned long n;
|
||||
unsigned int desc_width;
|
||||
unsigned long frequency_update;
|
||||
std::ostream* out;
|
||||
|
||||
const char *description;
|
||||
const char *unit_bar;
|
||||
const char *unit_space;
|
||||
|
||||
void ClearBarField();
|
||||
int GetConsoleWidth();
|
||||
int GetBarLength();
|
||||
|
||||
};
|
||||
#endif
|
157
src/struct_functions.cc
Normal file
157
src/struct_functions.cc
Normal file
@ -0,0 +1,157 @@
|
||||
#include "struct_functions.h"
|
||||
|
||||
// mathematic functions regarding declared structures
|
||||
bool operator ==(Cpoint a,Cpoint b){
|
||||
if(fabs(a.x-b.x)<ZERO&&fabs(a.y-b.y)<ZERO&&fabs(a.z-b.z)<ZERO){
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
bool operator !=(Cpoint a,Cpoint b){
|
||||
if(fabs(a.x-b.x)>=ZERO || fabs(a.y-b.y)>=ZERO || fabs(a.z-b.z)>=ZERO){
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
Cpoint operator +(Cpoint a,Cpoint b){
|
||||
Cpoint m;
|
||||
m.x=a.x+b.x; m.y=a.y+b.y; m.z=a.z+b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
Cpoint operator -(Cpoint a,Cpoint b){
|
||||
Cpoint m;
|
||||
m.x=a.x-b.x; m.y=a.y-b.y; m.z=a.z-b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
Cpoint operator *(double sign,Cpoint b){
|
||||
Cpoint m;
|
||||
m.x=sign*b.x; m.y=sign*b.y; m.z=sign*b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
double DotProduct(Cpoint a,Cpoint b){
|
||||
return a.x*b.x+a.y*b.y+a.z*b.z;
|
||||
}
|
||||
|
||||
Cpoint CrossProduct(Cpoint a,Cpoint b){
|
||||
Cpoint v;
|
||||
v.x = a.y*b.z-a.z*b.y;
|
||||
v.y = a.z*b.x-a.x*b.z;
|
||||
v.z = a.x*b.y-a.y*b.x;
|
||||
return v;
|
||||
}
|
||||
|
||||
Cpoint CloudCenter(VertexArray input_verts){
|
||||
Cpoint c;
|
||||
c.x = 0; c.y = 0; c.z = 0;
|
||||
if (!input_verts.empty()){
|
||||
for (int i = 0; i < input_verts.size(); i++){
|
||||
c.x += input_verts[i].posic.x;
|
||||
c.y += input_verts[i].posic.y;
|
||||
c.z += input_verts[i].posic.z;
|
||||
}
|
||||
c.x /= input_verts.size();
|
||||
c.y /= input_verts.size();
|
||||
c.z /= input_verts.size();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
double ModuleLength(Cpoint v){
|
||||
return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
|
||||
}
|
||||
|
||||
double ProjectAngle(Cpoint a,Cpoint b){
|
||||
return acos((a.x*b.x+a.y*b.y+a.z*b.z)/(sqrt(a.x*a.x+a.y*a.y+a.z*a.z)*sqrt(b.x*b.x+b.y*b.y+b.z*b.z)))*180.0/Pi;
|
||||
}
|
||||
|
||||
Cpoint Sphere2Cartesian(Spoint s){
|
||||
Cpoint c;
|
||||
c.x = s.rad*sin((0.5 - s.lat/180.0)*Pi)*cos((2.0 + s.lon/180.0)*Pi);
|
||||
c.y = s.rad*sin((0.5 - s.lat/180.0)*Pi)*sin((2.0 + s.lon/180.0)*Pi);
|
||||
c.z = s.rad*cos((0.5 - s.lat/180.0)*Pi);
|
||||
return c;
|
||||
}
|
||||
|
||||
Spoint Cartesian2Sphere(Cpoint c){
|
||||
Spoint s;
|
||||
s.rad = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
|
||||
//点距离原点极近 将点置于原点
|
||||
if (fabs(s.rad)<ZERO){
|
||||
s.lat = s.lon = s.rad = 0.0;
|
||||
}
|
||||
else{
|
||||
s.lat = 90.0 - acos(c.z/s.rad)*180.0/Pi;
|
||||
s.lon = atan2(c.y,c.x)*180.0/Pi;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Vertex RotateVertex(Vertex olda,Vertex newa,Vertex oldb){
|
||||
Vertex newb;
|
||||
Vertex temp_ref,temp_b;
|
||||
double yz_angle = (newa.posis.lat - olda.posis.lat)*Pi/180.0;
|
||||
//首先绕olda.lon即x轴旋转oldb
|
||||
temp_b.posic.x = oldb.posic.x;
|
||||
temp_b.posic.y = oldb.posic.y*cos(-1.0*yz_angle)+oldb.posic.z*sin(-1.0*yz_angle);
|
||||
temp_b.posic.z = oldb.posic.z*cos(-1.0*yz_angle)-oldb.posic.y*sin(-1.0*yz_angle);
|
||||
temp_b.posis = Cartesian2Sphere(temp_b.posic);
|
||||
//计算绕x轴旋转后olda的位置 这是后一步旋转需要的参考值
|
||||
temp_ref.posic.x = olda.posic.x;
|
||||
temp_ref.posic.y = olda.posic.y*cos(-1.0*yz_angle)+olda.posic.z*sin(-1.0*yz_angle);
|
||||
temp_ref.posic.z = olda.posic.z*cos(-1.0*yz_angle)-olda.posic.y*sin(-1.0*yz_angle);
|
||||
temp_ref.posis = Cartesian2Sphere(temp_ref.posic);
|
||||
//注意绕z轴旋转的经度参考位置为olda绕x轴旋转后的经度值
|
||||
double xy_angle = (newa.posis.lon - temp_ref.posis.lon)*Pi/180.0;
|
||||
//绕z轴旋转temp_b z值不变
|
||||
newb.id = oldb.id;
|
||||
newb.posic.x = temp_b.posic.x*cos(-1.0*xy_angle)+temp_b.posic.y*sin(-1.0*xy_angle);
|
||||
newb.posic.y = temp_b.posic.y*cos(-1.0*xy_angle)-temp_b.posic.x*sin(-1.0*xy_angle);
|
||||
newb.posic.z = temp_b.posic.z;
|
||||
newb.posis = Cartesian2Sphere(newb.posic);
|
||||
return newb;
|
||||
}
|
||||
|
||||
Cpoint LineCrossPlane(Cpoint c,Cpoint normal,Cpoint p){
|
||||
Cpoint m;
|
||||
m.x = 0; m.y = 0; m.z = 0;
|
||||
double t;
|
||||
if (DotProduct(normal,p) != 0) //平面与矢量平行
|
||||
{
|
||||
t = DotProduct(normal,c)/DotProduct(normal,p);
|
||||
m.x += p.x*t;
|
||||
m.y += p.y*t;
|
||||
m.z += p.z*t;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
string GetStringIndex(Vertex input_vertex)
|
||||
{
|
||||
stringstream sstemp;
|
||||
string vert_id,mid_id;
|
||||
|
||||
sstemp.str(""); sstemp.clear();
|
||||
sstemp << setprecision(16) << input_vertex.posic.x;
|
||||
sstemp >> vert_id;
|
||||
sstemp.str(""); sstemp.clear();
|
||||
sstemp << setprecision(16) << input_vertex.posic.y;
|
||||
sstemp >> mid_id;
|
||||
vert_id = vert_id + " " + mid_id;
|
||||
sstemp.str(""); sstemp.clear();
|
||||
sstemp << setprecision(16) << input_vertex.posic.z;
|
||||
sstemp >> mid_id;
|
||||
vert_id = vert_id + " " + mid_id;
|
||||
return vert_id;
|
||||
}
|
||||
|
||||
int LocalIndex(int id, Triangle t)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
if (id == t.ids[i]) return i;
|
||||
return -1;
|
||||
}
|
92
src/struct_functions.h
Normal file
92
src/struct_functions.h
Normal file
@ -0,0 +1,92 @@
|
||||
#ifndef _STRUCT_FUNCTIONS_H
|
||||
#define _STRUCT_FUNCTIONS_H
|
||||
#include "head_functions.h"
|
||||
|
||||
// array structures
|
||||
typedef vector<int> IntArray1D; //1D int array
|
||||
typedef vector<vector<int> > IntArray2D; // 2D int array
|
||||
typedef vector<double> DoubleArray1D; // 1D double array
|
||||
// map structures
|
||||
typedef map<int,int> Int2IntMap; // int to int map
|
||||
// point structures in the Cartesian and spherical coordinates
|
||||
struct Cpoint{
|
||||
double x = DBL_MAX, y = DBL_MAX, z = DBL_MAX;
|
||||
};
|
||||
typedef vector<Cpoint> CpointArray;
|
||||
// lon for longitude, lat for latitude and rad for radius
|
||||
struct Spoint{
|
||||
double lon = DBL_MAX, lat = DBL_MAX, rad = DBL_MAX;
|
||||
};
|
||||
typedef vector<Spoint> SpointArray;
|
||||
// vertex structure
|
||||
struct Vertex{
|
||||
int id = -1;
|
||||
Cpoint posic; //position under the Cartesian coordinates
|
||||
Spoint posis; //position under the sphere coordinates
|
||||
};
|
||||
typedef vector<Vertex> VertexArray;
|
||||
typedef map<int,Vertex> Int2VertexMap;
|
||||
typedef map<string,Vertex> String2VertexMap;
|
||||
// triangle structure
|
||||
struct Triangle{
|
||||
int ids[3] = {-1,-1,-1}; // index s
|
||||
int physic_group = 0;
|
||||
};
|
||||
typedef vector<Triangle> TriangleArray;
|
||||
// icosahedron structure
|
||||
struct Icosahedron{
|
||||
Vertex vert[12]; // vert for vertex
|
||||
Triangle tri[20]; // tir for triangle
|
||||
};
|
||||
// Quad-tree node structure
|
||||
struct QuadTreeNode{
|
||||
int id = -1, depth = -1;
|
||||
bool out_ok = true;
|
||||
Triangle tri;
|
||||
QuadTreeNode *children[4] = {nullptr,nullptr,nullptr,nullptr};
|
||||
QuadTreeNode *neighbor[3] = {nullptr,nullptr,nullptr};
|
||||
};
|
||||
typedef vector<QuadTreeNode*> QuadTreeNodePointerArray;
|
||||
// quad-tree structure
|
||||
struct QuadTree{
|
||||
QuadTreeNode *root = nullptr;
|
||||
};
|
||||
// control points, lines(polygons) and circles
|
||||
struct ControlPoint{
|
||||
int id = -1, max_depth = -1, physic_group = 0;
|
||||
double minimal_resolution = DBL_MAX;
|
||||
Vertex vert; // vert for vertex
|
||||
};
|
||||
typedef vector<ControlPoint> ControlPointArray;
|
||||
|
||||
struct ControlLine{
|
||||
int id = -1, max_depth = -1, physic_group = 0;
|
||||
double minimal_resolution = -1.0;
|
||||
VertexArray vert; // verts for vertices
|
||||
};
|
||||
typedef vector<ControlLine> ControlLineArray;
|
||||
|
||||
struct ControlCircle{
|
||||
int id = -1, max_depth = -1, physic_group = 0;
|
||||
double minimal_resolution = -1.0, circle_cap_degree = -1.0;
|
||||
Vertex circle_center;
|
||||
};
|
||||
typedef vector<ControlCircle> ControlCircleArray;
|
||||
// mathematic functions regarding declared structures
|
||||
bool operator ==(Cpoint,Cpoint);
|
||||
bool operator !=(Cpoint,Cpoint);
|
||||
Cpoint operator +(Cpoint,Cpoint);
|
||||
Cpoint operator -(Cpoint,Cpoint);
|
||||
Cpoint operator *(double,Cpoint);
|
||||
double DotProduct(Cpoint,Cpoint);
|
||||
Cpoint CrossProduct(Cpoint,Cpoint);
|
||||
Cpoint CloudCenter(VertexArray);
|
||||
double ModuleLength(Cpoint);
|
||||
double ProjectAngle(Cpoint,Cpoint);
|
||||
Cpoint Sphere2Cartesian(Spoint);
|
||||
Spoint Cartesian2Sphere(Cpoint);
|
||||
Vertex RotateVertex(Vertex,Vertex,Vertex);
|
||||
Cpoint LineCrossPlane(Cpoint,Cpoint,Cpoint);
|
||||
string GetStringIndex(Vertex);
|
||||
int LocalIndex(int,Triangle);
|
||||
#endif
|
77
src/stt_class.h
Normal file
77
src/stt_class.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef _STT_CLASS_H
|
||||
#define _STT_CLASS_H
|
||||
#include "head_functions.h"
|
||||
#include "struct_functions.h"
|
||||
|
||||
class SttGenerator
|
||||
{
|
||||
public:
|
||||
SttGenerator()
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
forest_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
~SttGenerator(){}
|
||||
int set_command_record(int,char**);
|
||||
int set_tree_depth(char*);
|
||||
int set_pole_equator_radius(char*);
|
||||
int set_icosahedron_orient(char*);
|
||||
int Routine(char [][1024]); // for a 2D array. you must specify enough dimensional information to make it unique
|
||||
void InitialIcosahedron(double,Vertex); //初始化一个二十面体实例 需要给定一个默认半径值 二十面体顶点的经纬坐标 在init_para函数中调用
|
||||
void CreateBranch(int,int,int,int,int,int,int,QuadTreeNode**); //创建分枝
|
||||
void CreateTree(int,int,int,int,QuadTree*);//创建树
|
||||
void DeleteTree(QuadTreeNode**);//清空整颗树
|
||||
void ReturnLeaf(QuadTreeNode**);//返回叶子
|
||||
void ReturnDepth(QuadTreeNode**,int);
|
||||
void SortNeighbor(QuadTreeNodePointerArray); // sort neighboring relationship for input triangles
|
||||
void CutOutline(QuadTreeNode**);//切割模型范围 为了保证后续处理中树形结构的完整性 我们只添加node的属性值来控制是否输出该节点
|
||||
void CutHole(QuadTreeNode**); //cut holes in the created STT
|
||||
void CloseSurface(QuadTree**);
|
||||
int ReturnBranchDepth(QuadTreeNode**); //返回当前枝桠的最大深度
|
||||
int InTrianglePoint(QuadTreeNode*);//在球面上判断点和三角形关系的一种方法 直接使用矢量运算确定包含关系 更直接更简单
|
||||
int InTriangleLine(QuadTreeNode*);//判断插入线是否穿过节点三角形 使用的是球面下的方法 直接矢量计算 注意因为球面上的特殊关系 两个点之间的夹角不能大于等于180度 因为球面上总是沿着最短路径走 而且通常我们指的也是最短路径
|
||||
int InTrianglePolygon(QuadTreeNode*);//判断多边形与三角形的关系
|
||||
int InTriangleCircle(QuadTreeNode*);//判断圆与三角形的关系
|
||||
int OutPolyOutline(QuadTreeNode*);//判断多边形与三角形的关系 用于切割模型边界
|
||||
int InPolyOutline(QuadTreeNode*);//判断多边形与三角形的关系 用于切割模型边界 挖洞
|
||||
int OutputMshFile(char*,double,double);
|
||||
int OutputVertexLocation(char*,double,double);
|
||||
int OutputTriangleCenterLocation(char*,double,double);
|
||||
int OutputNeighbor(char*);
|
||||
int GetControlPoint(char*); //读取额外的点
|
||||
int GetControlCircle(char*); //读取额外的圆
|
||||
int GetControlLine(char*,ControlLineArray&); // Get control line arrays
|
||||
private:
|
||||
// record input command line options for output records
|
||||
string command_record_;
|
||||
// minimal and maximal depths of quad-tree
|
||||
int tree_depth_, max_depth_;
|
||||
// pole and equator radius of the coordinate reference system
|
||||
double pole_radius_, equator_radius_;
|
||||
// orientation of the top vertex of the icosahedron
|
||||
Vertex icosahedron_orient_;
|
||||
// vertex array of the STT. This array defines the actual shape of the STT
|
||||
VertexArray array_stt_vert_;
|
||||
// map from the vertex's index to vertex. This map is used to find vertex by its index
|
||||
Int2VertexMap map_id_vertex_;
|
||||
Int2VertexMap::iterator ivd_;
|
||||
// map from the vertex's position to vertex. This map is used to find vertex by its position
|
||||
String2VertexMap map_str_vertex_;
|
||||
String2VertexMap::iterator ivm_;
|
||||
// base icosahedron used to construct the STT
|
||||
Icosahedron base_icosahedron_;
|
||||
// 20 quad-trees in which each of them represents the partition of one facet of the base icosahedron
|
||||
QuadTree *forest_[20];
|
||||
// pointer array of the extracted quad-tree nodes returned according to conditions
|
||||
QuadTreeNodePointerArray array_out_tri_pointer_;
|
||||
// external constraint information (point, line, polygons, circles, outline polygons and hole polygons)
|
||||
ControlPointArray array_control_point_;
|
||||
ControlCircleArray array_control_circle_;
|
||||
ControlLineArray array_control_line_;
|
||||
ControlLineArray array_control_polygon_;
|
||||
ControlLineArray array_outline_polygon_;
|
||||
ControlLineArray array_hole_polygon_;
|
||||
};
|
||||
#endif
|
221
src/stt_close_surface.cc
Normal file
221
src/stt_close_surface.cc
Normal file
@ -0,0 +1,221 @@
|
||||
#include "stt_class.h"
|
||||
#include "progress_bar.h"
|
||||
|
||||
void SttGenerator::CloseSurface(QuadTree** forest){
|
||||
int breaked,local_id,new_count;
|
||||
int newids[4][3] = {{0,3,5},{1,4,3},{2,5,4},{3,4,5}};
|
||||
Vertex temp_vert;
|
||||
Vertex local_vert[6];
|
||||
Triangle temp_tri,temp_tri2;
|
||||
QuadTree* current_tree;
|
||||
|
||||
ProgressBar *bar = new ProgressBar(max_depth_,"Close surface");
|
||||
//首先我们返回三角形列表再确定当前层的相邻关系
|
||||
for (int d = 0; d < max_depth_; d++){
|
||||
bar->Progressed(d);
|
||||
if (!array_out_tri_pointer_.empty()) array_out_tri_pointer_.clear();
|
||||
for (int t = 0; t < 20; t++){
|
||||
current_tree = *(forest+t);
|
||||
ReturnDepth(&(current_tree->root),d);
|
||||
}
|
||||
SortNeighbor(array_out_tri_pointer_);
|
||||
|
||||
//遍历所有三角形询问
|
||||
for (int t = 0; t < array_out_tri_pointer_.size(); t++){
|
||||
if (array_out_tri_pointer_[t]->children[0] != nullptr) continue; //如果节点三角形已经存在子节点则跳过
|
||||
else{
|
||||
//询问节点三角形的邻居
|
||||
for (int n = 0; n < 3; n++){
|
||||
//邻居必须存在
|
||||
if (array_out_tri_pointer_[t]->neighbor[n] != nullptr){
|
||||
//如果邻居最大深度大于等于三层当前节点的深度 则直接在所有邻居新建三个顶点 完成后跳出邻居循环
|
||||
//这样做的主要原因是如果相邻节点深度差距太大的话无法保证在表面闭合的过程中三角形的质量 同时可以增加缝合带的宽度 有利于后续的建模使用
|
||||
breaked = 0;
|
||||
if (ReturnBranchDepth(&(array_out_tri_pointer_[t]->neighbor[n])) - array_out_tri_pointer_[t]->depth >= 3){
|
||||
for (int q = 0; q < 3; q++){
|
||||
if (array_out_tri_pointer_[t]->neighbor[(n+q)%3] != nullptr){
|
||||
for (int l = 0; l < 3; l++)
|
||||
temp_tri2.ids[l] = array_out_tri_pointer_[t]->neighbor[(n+q)%3]->tri.ids[l];
|
||||
for (int h = 0; h < 3; h++){
|
||||
//计算新顶点坐标
|
||||
temp_vert.posic = 0.5*(array_stt_vert_[temp_tri2.ids[h]].posic + array_stt_vert_[temp_tri2.ids[(h+1)%3]].posic);
|
||||
// map vertex to the reference sphere/ellipsoid
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
temp_vert.posis.rad = EllipsoidRadius(temp_vert.posis.lat, pole_radius_, equator_radius_);
|
||||
temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
|
||||
ivm_ = map_str_vertex_.find(GetStringIndex(temp_vert));
|
||||
//若为新的顶点则将其增加到两个映射和一个链表中
|
||||
if(ivm_ == map_str_vertex_.end()){
|
||||
temp_vert.id = array_stt_vert_.size();//新的顶点索引等于顶点集的数量
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
array_stt_vert_.push_back(temp_vert);//将新产生的顶点保存到顶点链表中
|
||||
map_id_vertex_[temp_vert.id] = temp_vert;//将新产生的顶点保存到顶点索引映射中
|
||||
map_str_vertex_[GetStringIndex(temp_vert)] = temp_vert;//将新产生的顶点保存到顶点位置映射中
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
breaked = 1;
|
||||
}
|
||||
if(breaked) break;
|
||||
//如果邻居节点存在与该节点相邻的孙节点 则可能需要增加新的顶点 如果只存在子节点则不需要增加新的顶点 所以此时我们不考虑子节点的情况
|
||||
//遍历邻居的所有子节点
|
||||
for (int m = 0; m < 4; m++){
|
||||
//要存在可能相邻的孙节点则必须存在子节点
|
||||
if (array_out_tri_pointer_[t]->neighbor[n]->children[m] != nullptr){
|
||||
//如果邻居的一个子节点存在子节点则需要判断这个子节点是否与当前的节点三角形相邻 相邻的条件是邻居的这个存疑的子节点应该与当前节点三角形共顶点
|
||||
if (array_out_tri_pointer_[t]->neighbor[n]->children[m]->children[0] != nullptr){
|
||||
//循环匹配当前节点三角形的三个顶点与存疑的子节点的三个顶点 如果共顶点则寻找当前节点三角形中唯一不与邻居三角形连接的顶点(外点)
|
||||
//并在公共顶点与外顶点的中点尝试新建一个顶点 如果新的顶点不存在则添加 否则继续
|
||||
for (int l = 0; l < 3; l++)
|
||||
temp_tri.ids[l] = array_out_tri_pointer_[t]->neighbor[n]->children[m]->tri.ids[l];
|
||||
for (int l = 0; l < 3; l++)
|
||||
temp_tri2.ids[l] = array_out_tri_pointer_[t]->neighbor[n]->tri.ids[l];
|
||||
breaked = 0;
|
||||
for (int h = 0; h < 3; h++){
|
||||
for (int f = 0; f < 3; f++){
|
||||
//检验顶点索引 找到公共点
|
||||
if (array_out_tri_pointer_[t]->tri.ids[h] == temp_tri.ids[f]){
|
||||
//找到外点
|
||||
local_id = LocalIndex(temp_tri.ids[f],temp_tri2);
|
||||
if (array_out_tri_pointer_[t]->tri.ids[(h+1)%3] != temp_tri2.ids[(local_id+1)%3] &&
|
||||
array_out_tri_pointer_[t]->tri.ids[(h+1)%3] != temp_tri2.ids[(local_id+2)%3]){
|
||||
//外点是array_out_tri_pointer_[t]->tri->ids[(h+1)%3]
|
||||
temp_vert.posic = 0.5*(array_stt_vert_[array_out_tri_pointer_[t]->tri.ids[h]].posic
|
||||
+ array_stt_vert_[array_out_tri_pointer_[t]->tri.ids[(h+1)%3]].posic);//计算新顶点坐标
|
||||
// map vertex to the reference sphere/ellipsoid
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
temp_vert.posis.rad = EllipsoidRadius(temp_vert.posis.lat, pole_radius_, equator_radius_);
|
||||
temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
|
||||
ivm_ = map_str_vertex_.find(GetStringIndex(temp_vert));
|
||||
//若为新的顶点则将其增加到两个映射和一个链表中
|
||||
if(ivm_ == map_str_vertex_.end()){
|
||||
temp_vert.id = array_stt_vert_.size();//新的顶点索引等于顶点集的数量
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
array_stt_vert_.push_back(temp_vert);//将新产生的顶点保存到顶点链表中
|
||||
map_id_vertex_[temp_vert.id] = temp_vert;//将新产生的顶点保存到顶点索引映射中
|
||||
map_str_vertex_[GetStringIndex(temp_vert)] = temp_vert;//将新产生的顶点保存到顶点位置映射中
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//外点是array_out_tri_pointer_[t]->tri->ids[(h+2)%3]
|
||||
temp_vert.posic = 0.5*(array_stt_vert_[array_out_tri_pointer_[t]->tri.ids[h]].posic
|
||||
+ array_stt_vert_[array_out_tri_pointer_[t]->tri.ids[(h+2)%3]].posic);//计算新顶点坐标
|
||||
// map vertex to the reference sphere/ellipsoid
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
temp_vert.posis.rad = EllipsoidRadius(temp_vert.posis.lat, pole_radius_, equator_radius_);
|
||||
temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
|
||||
ivm_ = map_str_vertex_.find(GetStringIndex(temp_vert));
|
||||
//若为新的顶点则将其增加到两个映射和一个链表中
|
||||
if(ivm_ == map_str_vertex_.end()){
|
||||
temp_vert.id = array_stt_vert_.size();//新的顶点索引等于顶点集的数量
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
array_stt_vert_.push_back(temp_vert);//将新产生的顶点保存到顶点链表中
|
||||
map_id_vertex_[temp_vert.id] = temp_vert;//将新产生的顶点保存到顶点索引映射中
|
||||
map_str_vertex_[GetStringIndex(temp_vert)] = temp_vert;//将新产生的顶点保存到顶点位置映射中
|
||||
}
|
||||
}
|
||||
breaked = 1; break; //跳出循环 并触发二次跳出
|
||||
}
|
||||
}
|
||||
if(breaked) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//第二次遍历所有三角形 按照未连接顶点个数补全下一层的三角形
|
||||
for (int t = 0; t < array_out_tri_pointer_.size(); t++){
|
||||
if (array_out_tri_pointer_[t]->children[0] != nullptr) continue; //如果节点三角形已经存在子节点则跳过
|
||||
else{
|
||||
for (int i = 0; i < 3; i++)
|
||||
local_vert[i] = array_stt_vert_[array_out_tri_pointer_[t]->tri.ids[i]];
|
||||
//查询当前节点三角形的各边是否有未连接的顶点并记录
|
||||
new_count = 0;
|
||||
for (int i = 0; i < 3; i++){
|
||||
local_vert[i+3].posic = 0.5*(local_vert[i].posic + local_vert[(i+1)%3].posic);//计算新顶点坐标
|
||||
// map vertex to the reference sphere/ellipsoid
|
||||
local_vert[i+3].posis= Cartesian2Sphere(local_vert[i+3].posic);
|
||||
local_vert[i+3].posis.rad = EllipsoidRadius(local_vert[i+3].posis.lat, pole_radius_, equator_radius_);
|
||||
local_vert[i+3].posic = Sphere2Cartesian(local_vert[i+3].posis);
|
||||
|
||||
ivm_ = map_str_vertex_.find(GetStringIndex(local_vert[i+3]));
|
||||
//若为新的顶点则将其增加到两个映射和一个链表中
|
||||
if(ivm_!=map_str_vertex_.end()){
|
||||
local_vert[i+3].id = ivm_->second.id;
|
||||
new_count++;
|
||||
}
|
||||
else local_vert[i+3].id = -1;
|
||||
}
|
||||
//如果存在三个未连接的顶点则新建四个三角形
|
||||
if (new_count == 3){
|
||||
for (int i = 0; i < 4; i++){
|
||||
array_out_tri_pointer_[t]->children[i] = new QuadTreeNode;
|
||||
array_out_tri_pointer_[t]->children[i]->id = 10*(array_out_tri_pointer_[t]->id) + 1 + i;
|
||||
array_out_tri_pointer_[t]->children[i]->depth = array_out_tri_pointer_[t]->depth + 1;
|
||||
array_out_tri_pointer_[t]->children[i]->tri.ids[0] = local_vert[newids[i][0]].id;
|
||||
array_out_tri_pointer_[t]->children[i]->tri.ids[1] = local_vert[newids[i][1]].id;
|
||||
array_out_tri_pointer_[t]->children[i]->tri.ids[2] = local_vert[newids[i][2]].id;
|
||||
}
|
||||
}
|
||||
else if (new_count == 2){
|
||||
for (int i = 0; i < 3; i++){
|
||||
if (local_vert[i+3].id == -1){
|
||||
array_out_tri_pointer_[t]->children[0] = new QuadTreeNode;
|
||||
array_out_tri_pointer_[t]->children[0]->id = 10*(array_out_tri_pointer_[t]->id) + 1;
|
||||
array_out_tri_pointer_[t]->children[0]->depth = array_out_tri_pointer_[t]->depth + 1;
|
||||
array_out_tri_pointer_[t]->children[0]->tri.ids[0] = local_vert[i].id;
|
||||
array_out_tri_pointer_[t]->children[0]->tri.ids[1] = local_vert[(i+1)%3].id;
|
||||
array_out_tri_pointer_[t]->children[0]->tri.ids[2] = local_vert[(i+1)%3+3].id;
|
||||
|
||||
array_out_tri_pointer_[t]->children[1] = new QuadTreeNode;
|
||||
array_out_tri_pointer_[t]->children[1]->id = 10*(array_out_tri_pointer_[t]->id) + 2;
|
||||
array_out_tri_pointer_[t]->children[1]->depth = array_out_tri_pointer_[t]->depth + 1;
|
||||
array_out_tri_pointer_[t]->children[1]->tri.ids[0] = local_vert[i].id;
|
||||
array_out_tri_pointer_[t]->children[1]->tri.ids[1] = local_vert[(i+1)%3+3].id;
|
||||
array_out_tri_pointer_[t]->children[1]->tri.ids[2] = local_vert[(i+2)%3+3].id;
|
||||
|
||||
array_out_tri_pointer_[t]->children[2] = new QuadTreeNode;
|
||||
array_out_tri_pointer_[t]->children[2]->id = 10*(array_out_tri_pointer_[t]->id) + 3;
|
||||
array_out_tri_pointer_[t]->children[2]->depth = array_out_tri_pointer_[t]->depth + 1;
|
||||
array_out_tri_pointer_[t]->children[2]->tri.ids[0] = local_vert[(i+2)%3].id;
|
||||
array_out_tri_pointer_[t]->children[2]->tri.ids[1] = local_vert[(i+2)%3+3].id;
|
||||
array_out_tri_pointer_[t]->children[2]->tri.ids[2] = local_vert[(i+1)%3+3].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (new_count == 1){
|
||||
for (int i = 0; i < 3; i++){
|
||||
if (local_vert[i+3].id != -1){
|
||||
array_out_tri_pointer_[t]->children[0] = new QuadTreeNode;
|
||||
array_out_tri_pointer_[t]->children[0]->id = 10*(array_out_tri_pointer_[t]->id) + 1;
|
||||
array_out_tri_pointer_[t]->children[0]->depth = array_out_tri_pointer_[t]->depth + 1;
|
||||
array_out_tri_pointer_[t]->children[0]->tri.ids[0] = local_vert[i].id;
|
||||
array_out_tri_pointer_[t]->children[0]->tri.ids[1] = local_vert[i+3].id;
|
||||
array_out_tri_pointer_[t]->children[0]->tri.ids[2] = local_vert[(i+2)%3].id;
|
||||
|
||||
array_out_tri_pointer_[t]->children[1] = new QuadTreeNode;
|
||||
array_out_tri_pointer_[t]->children[1]->id = 10*(array_out_tri_pointer_[t]->id) + 2;
|
||||
array_out_tri_pointer_[t]->children[1]->depth = array_out_tri_pointer_[t]->depth + 1;
|
||||
array_out_tri_pointer_[t]->children[1]->tri.ids[0] = local_vert[(i+2)%3].id;
|
||||
array_out_tri_pointer_[t]->children[1]->tri.ids[1] = local_vert[i+3].id;
|
||||
array_out_tri_pointer_[t]->children[1]->tri.ids[2] = local_vert[(i+1)%3].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete bar;
|
||||
return;
|
||||
}
|
61
src/stt_create_branch.cc
Normal file
61
src/stt_create_branch.cc
Normal file
@ -0,0 +1,61 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::CreateBranch(int upper_id,int order_id,int depth,int t_ids0,int t_ids1,int t_ids2,int phy_group,QuadTreeNode** node)
|
||||
{
|
||||
Vertex local_vert[6];
|
||||
QuadTreeNode* current_node;
|
||||
|
||||
*node = new QuadTreeNode; //初始化一个新的四叉树节点
|
||||
current_node = *node;
|
||||
current_node->tri.ids[0] = t_ids0;//将上一节点的三角形顶点索引赋值给current_node内的triangle.ids,因此每一层节点实际上都保存了其本身的三角形顶点索引
|
||||
current_node->tri.ids[1] = t_ids1;
|
||||
current_node->tri.ids[2] = t_ids2;
|
||||
current_node->tri.physic_group = phy_group; //继承上层的物理组
|
||||
current_node->id = upper_id*10+order_id;//写入四叉树节点编号
|
||||
current_node->depth = depth;//记录四叉树深度
|
||||
|
||||
//额外生长条件 满足其一即可生长 在局部加密模型的过程中 不同物理组的赋值顺序前后顺序为圈 多边形 线 点
|
||||
if ((depth < tree_depth_ //基本生长条件 所有节点都能达到的深度
|
||||
|| InTriangleCircle(current_node)
|
||||
|| InTrianglePolygon(current_node)
|
||||
|| InTriangleLine(current_node)
|
||||
|| InTrianglePoint(current_node))
|
||||
&& depth < max_depth_) //最大深度限制 所有节点不能超过的深度
|
||||
{
|
||||
ivd_ = map_id_vertex_.find(t_ids0);//利用map_ID映射找到四叉树节点的前三个点,这三个节点是上一层四叉树产生的,必然存在
|
||||
local_vert[0] = ivd_->second;
|
||||
ivd_ = map_id_vertex_.find(t_ids1);
|
||||
local_vert[1] = ivd_->second;
|
||||
ivd_ = map_id_vertex_.find(t_ids2);
|
||||
local_vert[2] = ivd_->second;
|
||||
|
||||
for(int i = 0; i < 3; i++)//循环产生三个新的顶点,位于节点三角形的三条边的中点,给每一个新产生的节点赋索引值与坐标,并保存到顶点链表中
|
||||
{
|
||||
local_vert[i+3].posic = 0.5*(local_vert[i%3].posic+local_vert[(i+1)%3].posic);//计算新顶点坐标,这里需要注意,如果顶点已经存在则需要将顶点索引重置,不增加顶点计数
|
||||
// map vertex to the reference sphere/ellipsoid
|
||||
local_vert[i+3].posis = Cartesian2Sphere(local_vert[i+3].posic);
|
||||
local_vert[i+3].posis.rad = EllipsoidRadius(local_vert[i+3].posis.lat, pole_radius_, equator_radius_);
|
||||
local_vert[i+3].posic = Sphere2Cartesian(local_vert[i+3].posis);
|
||||
|
||||
ivm_ = map_str_vertex_.find(GetStringIndex(local_vert[i+3]));
|
||||
if(ivm_ != map_str_vertex_.end())//利用map_vert查到当前顶点是否存在,这里需要注意,如果顶点已经存在则只需要将顶点索引置为已存在顶点的索引,不增加顶点计数
|
||||
{
|
||||
local_vert[i+3].id = ivm_->second.id;
|
||||
}
|
||||
else//若为新的顶点则将其增加到两个映射和一个链表中
|
||||
{
|
||||
local_vert[i+3].id = array_stt_vert_.size();//新的顶点索引等于顶点集的数量
|
||||
local_vert[i+3].posis = Cartesian2Sphere(local_vert[i+3].posic);
|
||||
array_stt_vert_.push_back(local_vert[i+3]);//将新产生的顶点保存到顶点链表中
|
||||
map_id_vertex_[local_vert[i+3].id] = local_vert[i+3];//将新产生的顶点保存到顶点索引映射中
|
||||
map_str_vertex_[GetStringIndex(local_vert[i+3])] = local_vert[i+3];//将新产生的顶点保存到顶点位置映射中
|
||||
}
|
||||
}
|
||||
|
||||
CreateBranch(current_node->id,1,depth+1,local_vert[0].id,local_vert[3].id,local_vert[5].id,current_node->tri.physic_group,&(current_node->children[0]));
|
||||
CreateBranch(current_node->id,2,depth+1,local_vert[1].id,local_vert[4].id,local_vert[3].id,current_node->tri.physic_group,&(current_node->children[1]));
|
||||
CreateBranch(current_node->id,3,depth+1,local_vert[2].id,local_vert[5].id,local_vert[4].id,current_node->tri.physic_group,&(current_node->children[2]));
|
||||
CreateBranch(current_node->id,4,depth+1,local_vert[3].id,local_vert[4].id,local_vert[5].id,current_node->tri.physic_group,&(current_node->children[3]));
|
||||
}
|
||||
return;
|
||||
}
|
19
src/stt_create_tree.cc
Normal file
19
src/stt_create_tree.cc
Normal file
@ -0,0 +1,19 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::CreateTree(int tree_id,int t_ids0,int t_ids1,int t_ids2,QuadTree* p_tree){
|
||||
if (max_depth_ == 0){
|
||||
p_tree->root->id = 0;
|
||||
p_tree->root->depth = 0;
|
||||
p_tree->root->tri.ids[0] = t_ids0;//将上一节点的三角形顶点索引赋值给currNode内的triangle.ids,因此每一层节点实际上都保存了其本身的三角形顶点索引
|
||||
p_tree->root->tri.ids[1] = t_ids1;
|
||||
p_tree->root->tri.ids[2] = t_ids2;
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
p_tree->root->children[i] = nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateBranch(0,tree_id,0,t_ids0,t_ids1,t_ids2,0,&(p_tree->root));//以根节点开始创建四叉树
|
||||
}
|
||||
}
|
26
src/stt_cut_hole.cc
Normal file
26
src/stt_cut_hole.cc
Normal file
@ -0,0 +1,26 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::CutHole(QuadTreeNode** p_tree){
|
||||
//切割范围多边形之外的四叉树节点 从深到浅执行
|
||||
QuadTreeNode* current_node = *p_tree;
|
||||
//当前节点是叶子节点 进行判断
|
||||
if (current_node->children[0]==nullptr && current_node->children[1]==nullptr &&
|
||||
current_node->children[2]==nullptr && current_node->children[3]==nullptr){
|
||||
//如果节点三角形在范围多边形之外 删除节点三角形 同时初始化指针
|
||||
if (InPolyOutline(current_node)){
|
||||
current_node->out_ok = false;
|
||||
return;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++){
|
||||
//顺序访问当前节点的四个子节点 先处理子节点的情况 当然前提是节点存在
|
||||
if (current_node->children[i] != nullptr){
|
||||
CutHole(&(current_node->children[i]));
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
26
src/stt_cut_outline.cc
Normal file
26
src/stt_cut_outline.cc
Normal file
@ -0,0 +1,26 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::CutOutline(QuadTreeNode** p_tree){
|
||||
//切割范围多边形之外的四叉树节点 从深到浅执行
|
||||
QuadTreeNode* current_node = *p_tree;
|
||||
//当前节点是叶子节点 进行判断
|
||||
if (current_node->children[0]==nullptr && current_node->children[1]==nullptr &&
|
||||
current_node->children[2]==nullptr && current_node->children[3]==nullptr){
|
||||
//如果节点三角形在范围多边形之外 删除节点三角形 同时初始化指针
|
||||
if (OutPolyOutline(current_node)){
|
||||
current_node->out_ok = false;
|
||||
return;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++){
|
||||
//顺序访问当前节点的四个子节点 先处理子节点的情况 当然前提是节点存在
|
||||
if (current_node->children[i] != nullptr){
|
||||
CutOutline(&(current_node->children[i]));
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
18
src/stt_delete_tree.cc
Normal file
18
src/stt_delete_tree.cc
Normal file
@ -0,0 +1,18 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::DeleteTree(QuadTreeNode **p_tree)
|
||||
{
|
||||
QuadTreeNode *current_node = *p_tree;
|
||||
|
||||
if (current_node != nullptr)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
DeleteTree(&(current_node->children[i]));
|
||||
}
|
||||
|
||||
delete current_node; current_node = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
36
src/stt_get_control_circle.cc
Normal file
36
src/stt_get_control_circle.cc
Normal file
@ -0,0 +1,36 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::GetControlCircle(char* filename)
|
||||
{
|
||||
double node_eleva;
|
||||
stringstream temp_ss;
|
||||
string temp_str;
|
||||
ControlCircle temp_circle;
|
||||
ifstream infile;
|
||||
|
||||
if (!strcmp(filename,"NULL")){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (OpenInfile(infile,filename)) return -1;
|
||||
else{
|
||||
while (getline(infile,temp_str)){
|
||||
if (*(temp_str.begin()) == '#' || temp_str == "") continue;
|
||||
else{
|
||||
temp_ss = Str2Ss(temp_str);
|
||||
if (temp_ss >> temp_circle.circle_center.posis.lon >> temp_circle.circle_center.posis.lat >> temp_circle.circle_cap_degree
|
||||
>> temp_circle.max_depth >> temp_circle.minimal_resolution >> temp_circle.physic_group)
|
||||
{
|
||||
if (temp_circle.max_depth < 0) temp_circle.max_depth = 1e+3; //这里直接给一个很大的深度值 节点深度一定小于这个值
|
||||
if (temp_circle.minimal_resolution < 0) temp_circle.minimal_resolution = -1.0; //这里直接给成-1
|
||||
temp_circle.circle_center.posis.rad = DefaultR;
|
||||
temp_circle.circle_center.id = array_control_circle_.size();
|
||||
temp_circle.circle_center.posic = Sphere2Cartesian(temp_circle.circle_center.posis);
|
||||
array_control_circle_.push_back(temp_circle);
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
51
src/stt_get_control_line.cc
Normal file
51
src/stt_get_control_line.cc
Normal file
@ -0,0 +1,51 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::GetControlLine(char* filename,ControlLineArray& return_line_array)
|
||||
{
|
||||
int count;
|
||||
stringstream temp_ss;
|
||||
string temp_str;
|
||||
Vertex temp_vert;
|
||||
ControlLine temp_line;
|
||||
ifstream infile;
|
||||
|
||||
if (!strcmp(filename,"NULL")){
|
||||
return 0;
|
||||
}
|
||||
|
||||
//clear return array
|
||||
if (!return_line_array.empty()){
|
||||
for (int i = 0; i < return_line_array.size(); i++){
|
||||
if (!return_line_array[i].vert.empty()) return_line_array[i].vert.clear();
|
||||
}
|
||||
return_line_array.clear();
|
||||
}
|
||||
|
||||
if (OpenInfile(infile,filename)) return -1;
|
||||
else{
|
||||
while (getline(infile,temp_str)){
|
||||
if (*(temp_str.begin()) == '#' || temp_str == "") continue;
|
||||
else{
|
||||
if (!temp_line.vert.empty()) temp_line.vert.clear();
|
||||
temp_ss = Str2Ss(temp_str);
|
||||
temp_ss >> count >> temp_line.max_depth >> temp_line.minimal_resolution >> temp_line.physic_group;
|
||||
if (temp_line.max_depth <= 0) temp_line.max_depth = 1e+3; //这里直接给一个很大的深度值 节点深度一定小于这个值
|
||||
if (temp_line.minimal_resolution <= 0) temp_line.minimal_resolution = -1.0; //这里直接给成-1
|
||||
for (int i = 0; i < count; i++){
|
||||
getline(infile,temp_str);
|
||||
temp_ss = Str2Ss(temp_str);
|
||||
if (temp_ss >> temp_vert.posis.lon >> temp_vert.posis.lat){
|
||||
temp_vert.posis.rad = DefaultR;
|
||||
temp_vert.id = temp_line.vert.size();
|
||||
temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
temp_line.vert.push_back(temp_vert);
|
||||
}
|
||||
}
|
||||
temp_line.id = return_line_array.size();
|
||||
return_line_array.push_back(temp_line);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
39
src/stt_get_control_point.cc
Normal file
39
src/stt_get_control_point.cc
Normal file
@ -0,0 +1,39 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::GetControlPoint(char* filename)
|
||||
{
|
||||
stringstream temp_ss;
|
||||
string temp_str;
|
||||
ControlPoint one_point;
|
||||
ifstream infile;
|
||||
|
||||
if (!strcmp(filename,"NULL")) return 0;
|
||||
|
||||
if (OpenInfile(infile,filename)) return -1;
|
||||
else
|
||||
{
|
||||
while (getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#' || temp_str == "") continue;
|
||||
else
|
||||
{
|
||||
temp_ss = Str2Ss(temp_str);
|
||||
if (temp_ss >> one_point.vert.posis.lon
|
||||
>> one_point.vert.posis.lat
|
||||
>> one_point.max_depth
|
||||
>> one_point.minimal_resolution
|
||||
>> one_point.physic_group)
|
||||
{
|
||||
if (one_point.max_depth < 0) one_point.max_depth = 1e+3; //这里直接给一个很大的深度值 节点深度一定小于这个值
|
||||
if (one_point.minimal_resolution < 0) one_point.minimal_resolution = -1.0; //这里直接给成-1
|
||||
one_point.vert.posis.rad = DefaultR;
|
||||
one_point.vert.id = array_control_point_.size();
|
||||
one_point.vert.posic = Sphere2Cartesian(one_point.vert.posis);
|
||||
array_control_point_.push_back(one_point);
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
114
src/stt_in_poly_outline.cc
Normal file
114
src/stt_in_poly_outline.cc
Normal file
@ -0,0 +1,114 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::InPolyOutline(QuadTreeNode* node)
|
||||
{
|
||||
//没有范围多边形 直接返回否
|
||||
if (array_hole_polygon_.empty()){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int count, pnum;
|
||||
Cpoint tri_nor;
|
||||
Cpoint lineface_nor, edgeface_nor;
|
||||
Cpoint intersect[2];
|
||||
Cpoint angle_mid;
|
||||
Cpoint polygon_mid;
|
||||
Cpoint cross_point;
|
||||
Triangle temp_tri;
|
||||
for (int j = 0; j < 3; j++){
|
||||
temp_tri.ids[j] = node->tri.ids[j];
|
||||
}
|
||||
|
||||
//计算三角面元外法线矢量
|
||||
tri_nor = CrossProduct(array_stt_vert_[temp_tri.ids[1]].posic-array_stt_vert_[temp_tri.ids[0]].posic,
|
||||
array_stt_vert_[temp_tri.ids[2]].posic-array_stt_vert_[temp_tri.ids[0]].posic);
|
||||
//首先判断多边形的顶点是否在当前节点三角形内 或者多边形的边是否与当前节点三角形相交 这些条件可以判断多边形边上的三角形
|
||||
for (int i = 0; i < array_hole_polygon_.size(); i++){
|
||||
pnum = array_hole_polygon_[i].vert.size();
|
||||
for (int j = 0; j < array_hole_polygon_[i].vert.size(); j++){
|
||||
//排除球形背面的点
|
||||
if (DotProduct(tri_nor,array_hole_polygon_[i].vert[j].posic) > 0){
|
||||
//多边形节点在当前节点三角形内
|
||||
count = 0;
|
||||
for (int k = 0; k < 3; k++){
|
||||
cross_point = LineCrossPlane(array_stt_vert_[temp_tri.ids[k%3]].posic,tri_nor,array_hole_polygon_[i].vert[j].posic);
|
||||
//依次判断前后两条边与待检测点的外法线是否同向 注意排除从球体背面穿射的情况 全为真则返回真
|
||||
if (DotProduct(tri_nor,
|
||||
CrossProduct(array_stt_vert_[temp_tri.ids[(k+1)%3]].posic-array_stt_vert_[temp_tri.ids[k%3]].posic,
|
||||
cross_point-array_stt_vert_[temp_tri.ids[k%3]].posic)) > 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
//全部在左侧 多边形顶点至少有一个在节点三角形内 即节点三角形至少有一个顶点在多边形内 返回真
|
||||
if (count == 3) return 1;
|
||||
}
|
||||
//多边形边与当前节点三角形相交
|
||||
lineface_nor = CrossProduct(array_hole_polygon_[i].vert[j%pnum].posic,array_hole_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
angle_mid = 0.5*(array_hole_polygon_[i].vert[j%pnum].posic + array_hole_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
for (int n = 0; n < 3; n++){
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[temp_tri.ids[n%3]].posic,array_stt_vert_[temp_tri.ids[(n+1)%3]].posic);
|
||||
//排除两个扇面在同一个平面的情况
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor)*ModuleLength(edgeface_nor)) != 1.0){
|
||||
//两个扇面可能的交点矢量垂直于两个扇面的外法线矢量 正反两个矢量
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int k = 0; k < 2; k++){
|
||||
//交点矢量在两个线段端点矢量之间 注意端点先后顺序决定了大圆弧在球面上的范围 注意这里同样有从背面穿透的可能 因为我们不确定intersect中哪一个是我们想要的
|
||||
//注意计算叉乘的时候 我们总是会走一个角度小于180的方向
|
||||
//排除与angle_mid相反的半球上所有的三角形
|
||||
if (DotProduct(CrossProduct(intersect[k],array_stt_vert_[temp_tri.ids[n%3]].posic),CrossProduct(intersect[k],array_stt_vert_[temp_tri.ids[(n+1)%3]].posic)) < 0
|
||||
&& DotProduct(CrossProduct(intersect[k],array_hole_polygon_[i].vert[j%pnum].posic),CrossProduct(intersect[k],array_hole_polygon_[i].vert[(j+1)%pnum].posic)) < 0
|
||||
&& DotProduct(angle_mid,tri_nor) > 0)
|
||||
{
|
||||
//多边形边与节点三角形相交 即节点三角形至少有一个顶点在多边形内 返回真
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//多边形的顶点和边与当前节点三角形不相交或者包含 判断三角形是否在多边形内
|
||||
for (int i = 0; i < array_hole_polygon_.size(); i++){
|
||||
pnum = array_hole_polygon_[i].vert.size();
|
||||
polygon_mid = CloudCenter(array_hole_polygon_[i].vert);
|
||||
//依次判断节点三角形的三条边与多边形边的交点个数
|
||||
for (int k = 0; k < 3; k++){
|
||||
count = 0;
|
||||
//计算三角形边与球心的平面的法线矢量 只要任意一条边在多边形内 则三角形在多边形内
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[temp_tri.ids[(k)%3]].posic,array_stt_vert_[temp_tri.ids[(k+1)%3]].posic);
|
||||
for (int j = 0; j < array_hole_polygon_[i].vert.size(); j++){
|
||||
//多边形边与当前节点三角形相交
|
||||
lineface_nor = CrossProduct(array_hole_polygon_[i].vert[j%pnum].posic,array_hole_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
angle_mid = 0.5*(array_hole_polygon_[i].vert[j%pnum].posic + array_hole_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
//排除两个扇面在同一个平面的情况
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor)*ModuleLength(edgeface_nor)) != 1.0){
|
||||
//两个扇面可能的交点矢量垂直于两个扇面的外法线矢量 正反两个矢量
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int n = 0; n < 2; n++){
|
||||
/*注意 这里我们只判断交点是否在线段之间 或者一个点上 这里选择第一个点也可以选择第二点 但只能包含一个 不判断是不是在边之间
|
||||
注意我们只统计从当前三角形顶点向左或者向右旋转180度中遇到的交点*/
|
||||
//交点矢量在两个线段端点矢量之间 注意端点先后顺序决定了大圆弧在球面上的范围 注意这里同样有从背面穿透的可能 因为我们不确定intersect中哪一个是我们想要的
|
||||
//注意计算叉乘的时候 我们总是会走一个角度小于180的方向
|
||||
//排除与angle_mid相反的半球上所有的三角形
|
||||
if (DotProduct(polygon_mid,tri_nor) > 0 //排除位于球背面的三角形
|
||||
&& (DotProduct(CrossProduct(intersect[k],array_hole_polygon_[i].vert[j%pnum].posic),CrossProduct(intersect[k],array_hole_polygon_[i].vert[(j+1)%pnum].posic)) < 0
|
||||
|| array_hole_polygon_[i].vert[j].posic == intersect[n]) //排除与多边形的边不相交的三角形边的延长线 这里包含了一个等于条件 即交点刚好在多边形的顶点上
|
||||
&& DotProduct(angle_mid,intersect[n]) > 0 //排除位于球背面的多边形边与三角形边延长线的交点
|
||||
&& DotProduct(edgeface_nor,CrossProduct(array_stt_vert_[temp_tri.ids[k%3]].posic,intersect[n])) > 0) //只取三角形边其中一则的延长线
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//交点个数为奇数 边在多边形内 返回真
|
||||
if (pow(-1,count) < 0) return 1;
|
||||
}
|
||||
}
|
||||
//全不为真 返回假
|
||||
return 0;
|
||||
}
|
||||
}
|
41
src/stt_in_triangle_circle.cc
Normal file
41
src/stt_in_triangle_circle.cc
Normal file
@ -0,0 +1,41 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::InTriangleCircle(QuadTreeNode* node){
|
||||
// If no constraint circle, return false
|
||||
if (array_control_circle_.empty()){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int node_depth;
|
||||
double node_resolution, center_degree;
|
||||
|
||||
Triangle temp_tri;
|
||||
for (int j = 0; j < 3; j++){
|
||||
temp_tri.ids[j] = node->tri.ids[j];
|
||||
}
|
||||
|
||||
node_depth = node->depth;
|
||||
|
||||
node_resolution = 0;
|
||||
for (int i = 0; i < 3; i++){
|
||||
node_resolution += acos(DotProduct(array_stt_vert_[temp_tri.ids[i]].posic,array_stt_vert_[temp_tri.ids[(i+1)%3]].posic)
|
||||
/(ModuleLength(array_stt_vert_[temp_tri.ids[i]].posic)*ModuleLength(array_stt_vert_[temp_tri.ids[(i+1)%3]].posic)));
|
||||
}
|
||||
node_resolution = node_resolution*60/Pi;
|
||||
|
||||
for (int i = 0; i < array_control_circle_.size(); i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
// calculate the geocentric angle between a vertex of the triangle and the center of the circle
|
||||
center_degree = acos(DotProduct(array_control_circle_[i].circle_center.posic,array_stt_vert_[temp_tri.ids[j]].posic)
|
||||
/(ModuleLength(array_control_circle_[i].circle_center.posic)*ModuleLength(array_stt_vert_[temp_tri.ids[j]].posic)))*180.0/Pi;
|
||||
|
||||
if (center_degree <= array_control_circle_[i].circle_cap_degree
|
||||
&& array_control_circle_[i].max_depth >= node_depth && node_resolution >= array_control_circle_[i].minimal_resolution){
|
||||
node->tri.physic_group = array_control_circle_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
85
src/stt_in_triangle_line.cc
Normal file
85
src/stt_in_triangle_line.cc
Normal file
@ -0,0 +1,85 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::InTriangleLine(QuadTreeNode* node){
|
||||
// If no constraint line, return false
|
||||
if (array_control_line_.empty()){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int count, node_depth;
|
||||
double node_resolution;
|
||||
Cpoint tri_nor;
|
||||
Cpoint lineface_nor, edgeface_nor;
|
||||
Cpoint intersect[2];
|
||||
Cpoint angle_mid;
|
||||
Cpoint edge_mid;
|
||||
Cpoint cross_point;
|
||||
|
||||
Triangle temp_tri;
|
||||
for (int i = 0; i < 3; i++){
|
||||
temp_tri.ids[i] = node->tri.ids[i];
|
||||
}
|
||||
|
||||
node_depth = node->depth;
|
||||
|
||||
node_resolution = 0;
|
||||
for (int i = 0; i < 3; i++){
|
||||
node_resolution += acos(DotProduct(array_stt_vert_[temp_tri.ids[i]].posic, array_stt_vert_[temp_tri.ids[(i+1)%3]].posic)
|
||||
/(ModuleLength(array_stt_vert_[temp_tri.ids[i]].posic) * ModuleLength(array_stt_vert_[temp_tri.ids[(i+1)%3]].posic)));
|
||||
}
|
||||
node_resolution = node_resolution*60/Pi;
|
||||
|
||||
tri_nor = CrossProduct(array_stt_vert_[temp_tri.ids[1]].posic - array_stt_vert_[temp_tri.ids[0]].posic,
|
||||
array_stt_vert_[temp_tri.ids[2]].posic - array_stt_vert_[temp_tri.ids[0]].posic);
|
||||
|
||||
for (int i = 0; i < array_control_line_.size(); i++){
|
||||
for (int j = 0; j < array_control_line_[i].vert.size(); j++){
|
||||
if (DotProduct(tri_nor,array_control_line_[i].vert[j].posic) > 0){
|
||||
count = 0;
|
||||
for (int k = 0; k < 3; k++){
|
||||
cross_point = LineCrossPlane(array_stt_vert_[temp_tri.ids[k]].posic, tri_nor, array_control_line_[i].vert[j].posic);
|
||||
if (DotProduct(tri_nor,
|
||||
CrossProduct(array_stt_vert_[temp_tri.ids[(k+1)%3]].posic - array_stt_vert_[temp_tri.ids[k]].posic,
|
||||
cross_point - array_stt_vert_[temp_tri.ids[k]].posic)) > 0){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 3 && array_control_line_[i].max_depth >= node_depth && node_resolution >= array_control_line_[i].minimal_resolution){
|
||||
node->tri.physic_group = array_control_line_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < array_control_line_.size(); i++){
|
||||
for (int j = 0; j < array_control_line_[i].vert.size()-1; j++){
|
||||
lineface_nor = CrossProduct(array_control_line_[i].vert[j].posic, array_control_line_[i].vert[j+1].posic);
|
||||
angle_mid = 0.5*(array_control_line_[i].vert[j].posic + array_control_line_[i].vert[j+1].posic);
|
||||
for (int n = 0; n < 3; n++){
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[temp_tri.ids[n]].posic, array_stt_vert_[temp_tri.ids[(n+1)%3]].posic);
|
||||
edge_mid = 0.5*(array_stt_vert_[temp_tri.ids[n]].posic + array_stt_vert_[temp_tri.ids[(n+1)%3]].posic);
|
||||
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor) * ModuleLength(edgeface_nor)) != 1.0){
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int k = 0; k < 2; k++){
|
||||
if (DotProduct(angle_mid,tri_nor) > 0
|
||||
&& DotProduct(CrossProduct(intersect[k],array_stt_vert_[temp_tri.ids[n]].posic),CrossProduct(intersect[k],array_stt_vert_[temp_tri.ids[(n+1)%3]].posic)) < 0
|
||||
&& DotProduct(CrossProduct(intersect[k],array_control_line_[i].vert[j].posic),CrossProduct(intersect[k],array_control_line_[i].vert[j+1].posic)) < 0
|
||||
&& DotProduct(intersect[k],angle_mid) > 0
|
||||
&& DotProduct(intersect[k],edge_mid) > 0
|
||||
&& array_control_line_[i].max_depth >= node_depth
|
||||
&& node_resolution >= array_control_line_[i].minimal_resolution){
|
||||
node->tri.physic_group = array_control_line_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
50
src/stt_in_triangle_point.cc
Normal file
50
src/stt_in_triangle_point.cc
Normal file
@ -0,0 +1,50 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::InTrianglePoint(QuadTreeNode* node){
|
||||
//没有插入的点位 直接返回否
|
||||
if (array_control_point_.empty()){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int count, node_depth;
|
||||
double node_resolution;
|
||||
Cpoint tri_nor;
|
||||
Cpoint cross_point;
|
||||
|
||||
Triangle temp_tri;
|
||||
for (int j = 0; j < 3; j++){
|
||||
temp_tri.ids[j] = node->tri.ids[j];
|
||||
}
|
||||
|
||||
node_depth = node->depth;
|
||||
|
||||
node_resolution = 0;
|
||||
for (int i = 0; i < 3; i++){
|
||||
node_resolution += acos(DotProduct(array_stt_vert_[temp_tri.ids[i]].posic,array_stt_vert_[temp_tri.ids[(i+1)%3]].posic)
|
||||
/(ModuleLength(array_stt_vert_[temp_tri.ids[i]].posic)*ModuleLength(array_stt_vert_[temp_tri.ids[(i+1)%3]].posic)));
|
||||
}
|
||||
node_resolution = node_resolution*60/Pi;
|
||||
|
||||
tri_nor = CrossProduct(array_stt_vert_[temp_tri.ids[1]].posic - array_stt_vert_[temp_tri.ids[0]].posic,
|
||||
array_stt_vert_[temp_tri.ids[2]].posic - array_stt_vert_[temp_tri.ids[0]].posic);
|
||||
for (int i = 0; i < array_control_point_.size(); i++){
|
||||
if (DotProduct(tri_nor, array_control_point_[i].vert.posic) > 0){
|
||||
count = 0;
|
||||
for (int j = 0; j < 3; j++){
|
||||
cross_point = LineCrossPlane(array_stt_vert_[temp_tri.ids[j]].posic, tri_nor, array_control_point_[i].vert.posic);
|
||||
if (DotProduct(tri_nor,
|
||||
CrossProduct(array_stt_vert_[temp_tri.ids[(j+1)%3]].posic - array_stt_vert_[temp_tri.ids[j]].posic,
|
||||
cross_point - array_stt_vert_[temp_tri.ids[j]].posic)) > 0){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 3 && array_control_point_[i].max_depth >= node_depth && node_resolution >= array_control_point_[i].minimal_resolution){
|
||||
node->tri.physic_group = array_control_point_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
159
src/stt_in_triangle_polygon.cc
Normal file
159
src/stt_in_triangle_polygon.cc
Normal file
@ -0,0 +1,159 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::InTrianglePolygon(QuadTreeNode* node){
|
||||
// If no polygon, return false
|
||||
if (array_control_polygon_.empty()){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int count, point_num, node_depth;
|
||||
double node_resolution;
|
||||
Cpoint tri_nor;
|
||||
Cpoint lineface_nor, edgeface_nor;
|
||||
Cpoint intersect[2];
|
||||
Cpoint angle_mid;
|
||||
Cpoint edge_mid;
|
||||
Cpoint polygon_mid;
|
||||
Cpoint cross_point;
|
||||
|
||||
// copy node triangle index to a local variable triangle
|
||||
Triangle node_tri;
|
||||
for (int j = 0; j < 3; j++){
|
||||
node_tri.ids[j] = node->tri.ids[j];
|
||||
}
|
||||
// copy node depth to a local variable node_depth
|
||||
node_depth = node->depth;
|
||||
// calculate the spatial resolution of current node's triangle, which equals to the averaged geocentric angle of the triangle's edges.
|
||||
// Note that using the minimal_resolution constraint may introduce uneven constrains at different parts of the spherical polygon. Use it
|
||||
// with caution.
|
||||
node_resolution = 0;
|
||||
for (int i = 0; i < 3; i++){
|
||||
node_resolution += acos(DotProduct(array_stt_vert_[node_tri.ids[i]].posic,array_stt_vert_[node_tri.ids[(i+1)%3]].posic)
|
||||
/(ModuleLength(array_stt_vert_[node_tri.ids[i]].posic)*ModuleLength(array_stt_vert_[node_tri.ids[(i+1)%3]].posic)));
|
||||
}
|
||||
node_resolution = node_resolution*60/Pi;
|
||||
// calculate the outside normal vector of current node's triangle. The vector does not need to be normalized.
|
||||
tri_nor = CrossProduct(array_stt_vert_[node_tri.ids[1]].posic-array_stt_vert_[node_tri.ids[0]].posic,
|
||||
array_stt_vert_[node_tri.ids[2]].posic-array_stt_vert_[node_tri.ids[0]].posic);
|
||||
// To begin with, we deal with triangles that might be located on the edge of a polygon.
|
||||
// loop all polygons
|
||||
for (int i = 0; i < array_control_polygon_.size(); i++)
|
||||
{
|
||||
// vertex number of current polygon
|
||||
point_num = array_control_polygon_[i].vert.size();
|
||||
for (int j = 0; j < point_num; j++)
|
||||
{
|
||||
// Firstly, we determine if any vertex of a polygon locates inside of the node's triangle.
|
||||
// The vertex must face the side as the same as the node's triangle. This condition rule out all vertexes that are located on the back of the sphere
|
||||
if (DotProduct(tri_nor,array_control_polygon_[i].vert[j].posic) > 0)
|
||||
{
|
||||
count = 0;
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
cross_point = LineCrossPlane(array_stt_vert_[node_tri.ids[k]].posic, tri_nor, array_control_polygon_[i].vert[j].posic);
|
||||
// See if the intersection point is on the left side of the triangle's edges
|
||||
if (DotProduct(tri_nor,
|
||||
CrossProduct(array_stt_vert_[node_tri.ids[(k+1)%3]].posic-array_stt_vert_[node_tri.ids[k]].posic,
|
||||
cross_point-array_stt_vert_[node_tri.ids[k]].posic)) > 0){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// if the intersection point is on the left side of all three edges of the triangle, then the point is located inside the triangle
|
||||
// Meanwhile, the node depth must be small than or equal to the maximal constraint depth of the polygon,
|
||||
// or the node triangle's resolution must be bigger than or equal to the minimal constraint resolution of the polygon.
|
||||
if (count == 3 && array_control_polygon_[i].max_depth >= node_depth && node_resolution >= array_control_polygon_[i].minimal_resolution)
|
||||
{
|
||||
// assign the polygon's physical group to the node's triangle as it is a part of the refined STT
|
||||
node->tri.physic_group = array_control_polygon_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Secondly, we see if and edges of a polygon is intersected with the node's triangle
|
||||
// calculate the outside normal vector of a triangle composed by two endpoints of a polygon's edge and the origin.
|
||||
lineface_nor = CrossProduct(array_control_polygon_[i].vert[j].posic, array_control_polygon_[i].vert[(j+1)%point_num].posic);
|
||||
// calculate the middle vector of two endpoints of a polygon's edge.
|
||||
angle_mid = 0.5*(array_control_polygon_[i].vert[j].posic + array_control_polygon_[i].vert[(j+1)%point_num].posic);
|
||||
// for edges of the node's triangle
|
||||
for (int n = 0; n < 3; n++)
|
||||
{
|
||||
// calculate the outside normal vector of a triangle composed by two endpoints of a triangle's edge and the origin.
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[node_tri.ids[n]].posic,array_stt_vert_[node_tri.ids[(n+1)%3]].posic);
|
||||
edge_mid = 0.5*(array_stt_vert_[node_tri.ids[n]].posic + array_stt_vert_[node_tri.ids[(n+1)%3]].posic);
|
||||
// exclude the situation that the two edges are parallel to each other.
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor)*ModuleLength(edgeface_nor)) != 1.0)
|
||||
{
|
||||
// two intersection points of the edges are found using the cross product.
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int k = 0; k < 2; k++)
|
||||
{
|
||||
// The two edges are intersected with each other if one intersection point is located between the polygon's edge and the triangle's edge.
|
||||
// Note that the two edges should be facing the same hemisphere.
|
||||
if (DotProduct(angle_mid, tri_nor) > 0
|
||||
&& DotProduct(CrossProduct(intersect[k],array_stt_vert_[node_tri.ids[n]].posic),CrossProduct(intersect[k],array_stt_vert_[node_tri.ids[(n+1)%3]].posic)) < 0
|
||||
&& DotProduct(CrossProduct(intersect[k],array_control_polygon_[i].vert[j].posic),CrossProduct(intersect[k],array_control_polygon_[i].vert[(j+1)%point_num].posic)) < 0
|
||||
&& DotProduct(intersect[k], angle_mid) > 0
|
||||
&& DotProduct(intersect[k], edge_mid) > 0
|
||||
&& array_control_polygon_[i].max_depth >= node_depth
|
||||
&& node_resolution >= array_control_polygon_[i].minimal_resolution)
|
||||
{
|
||||
node->tri.physic_group = array_control_polygon_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now we found triangles that are inside the polygon.
|
||||
for (int i = 0; i < array_control_polygon_.size(); i++)
|
||||
{
|
||||
point_num = array_control_polygon_[i].vert.size();
|
||||
// find the center direction of the polygon
|
||||
polygon_mid = CloudCenter(array_control_polygon_[i].vert);
|
||||
// calculate number of intersection points for each edge of the triangle against the polygon.
|
||||
// If any edge of the triangle is inside the polygon, then the triangle is inside the polygon.
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
count = 0;
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[node_tri.ids[k]].posic,array_stt_vert_[node_tri.ids[(k+1)%3]].posic);
|
||||
for (int j = 0; j < point_num; j++)
|
||||
{
|
||||
lineface_nor = CrossProduct(array_control_polygon_[i].vert[j].posic, array_control_polygon_[i].vert[(j+1)%point_num].posic);
|
||||
angle_mid = 0.5*(array_control_polygon_[i].vert[j].posic + array_control_polygon_[i].vert[(j+1)%point_num].posic);
|
||||
// exclude the situation that the two edges are parallel to each other.
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor)*ModuleLength(edgeface_nor)) != 1.0){
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
// The two edges are intersected with each other if one intersection point is located between the polygon's edge and the triangle's edge.
|
||||
// The two edges should be facing the same hemisphere.
|
||||
// The intersection point is located between an edge of the polygon.
|
||||
// Or the beginning point of an polygon's edge is the intersection point (you can choose to use the ending point too, but you should only use one of them).
|
||||
// The intersection should be facing the same hemisphere as the polygon's edge.
|
||||
// Only one side of the extended trajectory of the triangle's edge should be used.
|
||||
if (DotProduct(polygon_mid,tri_nor) > 0
|
||||
// Fixed an indexing error at the following line (change k to n) on 2021-10-13 by Yi Zhang
|
||||
&& (DotProduct(CrossProduct(intersect[n],array_control_polygon_[i].vert[j].posic),CrossProduct(intersect[n],array_control_polygon_[i].vert[(j+1)%point_num].posic)) < 0
|
||||
|| array_control_polygon_[i].vert[j].posic == intersect[n])
|
||||
&& DotProduct(angle_mid,intersect[n]) > 0
|
||||
&& DotProduct(edgeface_nor,CrossProduct(array_stt_vert_[node_tri.ids[k]].posic,intersect[n])) > 0){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the number of intersection is odd. The triangle is inside the polygon.
|
||||
if (pow(-1,count) < 0 && array_control_polygon_[i].max_depth >= node_depth && node_resolution >= array_control_polygon_[i].minimal_resolution){
|
||||
node->tri.physic_group = array_control_polygon_[i].physic_group;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// All fails, the triangle is outside the polygon.
|
||||
return 0;
|
||||
}
|
||||
}
|
70
src/stt_initial_icosahedron.cc
Normal file
70
src/stt_initial_icosahedron.cc
Normal file
@ -0,0 +1,70 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
/**
|
||||
* 初始化二十面实例ICOSA
|
||||
* @param radius 二十面的顶点半径
|
||||
* @param orient 二十面最高点顶点方位
|
||||
*/
|
||||
void SttGenerator::InitialIcosahedron(double radius,Vertex orient)
|
||||
{
|
||||
double constL, constZ;
|
||||
//计算二十面的十二个顶点位置 首先将顶点位置固定在地理北极点
|
||||
base_icosahedron_.vert[0].id = 0;
|
||||
base_icosahedron_.vert[0].posic.x = 0.0;
|
||||
base_icosahedron_.vert[0].posic.y = 0.0;
|
||||
base_icosahedron_.vert[0].posic.z = radius;
|
||||
base_icosahedron_.vert[0].posis = Cartesian2Sphere(base_icosahedron_.vert[0].posic);
|
||||
base_icosahedron_.vert[11].id = 11;
|
||||
base_icosahedron_.vert[11].posic.x = 0.0;
|
||||
base_icosahedron_.vert[11].posic.y = 0.0;
|
||||
base_icosahedron_.vert[11].posic.z = -1.0*radius;
|
||||
base_icosahedron_.vert[11].posis = Cartesian2Sphere(base_icosahedron_.vert[11].posic);
|
||||
|
||||
constZ = radius*(GoldenMean*GoldenMean - 1.0)/(GoldenMean*GoldenMean + 1.0);
|
||||
constL = radius*sqrt(1.0 - pow((GoldenMean*GoldenMean - 1.0)/(GoldenMean*GoldenMean + 1.0),2));
|
||||
|
||||
for(int i = 1; i <= 5; i++)
|
||||
{
|
||||
base_icosahedron_.vert[i].id = i;
|
||||
base_icosahedron_.vert[i].posic.x = cos(72.0*(i-1)*Pi/180.0)*constL;
|
||||
base_icosahedron_.vert[i].posic.y = sin(72.0*(i-1)*Pi/180.0)*constL;
|
||||
base_icosahedron_.vert[i].posic.z = constZ;
|
||||
base_icosahedron_.vert[i].posis = Cartesian2Sphere(base_icosahedron_.vert[i].posic);
|
||||
|
||||
base_icosahedron_.vert[i+5].id = i+5;
|
||||
base_icosahedron_.vert[i+5].posic.x = cos((72.0*(i-1)+36.0)*Pi/180.0)*constL;
|
||||
base_icosahedron_.vert[i+5].posic.y = sin((72.0*(i-1)+36.0)*Pi/180.0)*constL;
|
||||
base_icosahedron_.vert[i+5].posic.z = -constZ;
|
||||
base_icosahedron_.vert[i+5].posis = Cartesian2Sphere(base_icosahedron_.vert[i+5].posic);
|
||||
}
|
||||
|
||||
//给定二十面的面顶点索引,各个三角面顶点索引按逆时针排序
|
||||
base_icosahedron_.tri[0].ids[0] = 0; base_icosahedron_.tri[0].ids[1] = 1; base_icosahedron_.tri[0].ids[2] = 2;
|
||||
base_icosahedron_.tri[1].ids[0] = 0; base_icosahedron_.tri[1].ids[1] = 2; base_icosahedron_.tri[1].ids[2] = 3;
|
||||
base_icosahedron_.tri[2].ids[0] = 0; base_icosahedron_.tri[2].ids[1] = 3; base_icosahedron_.tri[2].ids[2] = 4;
|
||||
base_icosahedron_.tri[3].ids[0] = 0; base_icosahedron_.tri[3].ids[1] = 4; base_icosahedron_.tri[3].ids[2] = 5;
|
||||
base_icosahedron_.tri[4].ids[0] = 0; base_icosahedron_.tri[4].ids[1] = 5; base_icosahedron_.tri[4].ids[2] = 1;
|
||||
base_icosahedron_.tri[5].ids[0] = 1; base_icosahedron_.tri[5].ids[1] = 6; base_icosahedron_.tri[5].ids[2] = 2;
|
||||
base_icosahedron_.tri[6].ids[0] = 2; base_icosahedron_.tri[6].ids[1] = 6; base_icosahedron_.tri[6].ids[2] = 7;
|
||||
base_icosahedron_.tri[7].ids[0] = 2; base_icosahedron_.tri[7].ids[1] = 7; base_icosahedron_.tri[7].ids[2] = 3;
|
||||
base_icosahedron_.tri[8].ids[0] = 3; base_icosahedron_.tri[8].ids[1] = 7; base_icosahedron_.tri[8].ids[2] = 8;
|
||||
base_icosahedron_.tri[9].ids[0] = 3; base_icosahedron_.tri[9].ids[1] = 8; base_icosahedron_.tri[9].ids[2] = 4;
|
||||
base_icosahedron_.tri[10].ids[0] = 4; base_icosahedron_.tri[10].ids[1] = 8; base_icosahedron_.tri[10].ids[2] = 9;
|
||||
base_icosahedron_.tri[11].ids[0] = 4; base_icosahedron_.tri[11].ids[1] = 9; base_icosahedron_.tri[11].ids[2] = 5;
|
||||
base_icosahedron_.tri[12].ids[0] = 5; base_icosahedron_.tri[12].ids[1] = 9; base_icosahedron_.tri[12].ids[2] = 10;
|
||||
base_icosahedron_.tri[13].ids[0] = 5; base_icosahedron_.tri[13].ids[1] = 10; base_icosahedron_.tri[13].ids[2] = 1;
|
||||
base_icosahedron_.tri[14].ids[0] = 1; base_icosahedron_.tri[14].ids[1] = 10; base_icosahedron_.tri[14].ids[2] = 6;
|
||||
base_icosahedron_.tri[15].ids[0] = 6; base_icosahedron_.tri[15].ids[1] = 11; base_icosahedron_.tri[15].ids[2] = 7;
|
||||
base_icosahedron_.tri[16].ids[0] = 7; base_icosahedron_.tri[16].ids[1] = 11; base_icosahedron_.tri[16].ids[2] = 8;
|
||||
base_icosahedron_.tri[17].ids[0] = 8; base_icosahedron_.tri[17].ids[1] = 11; base_icosahedron_.tri[17].ids[2] = 9;
|
||||
base_icosahedron_.tri[18].ids[0] = 9; base_icosahedron_.tri[18].ids[1] = 11; base_icosahedron_.tri[18].ids[2] = 10;
|
||||
base_icosahedron_.tri[19].ids[0] = 10; base_icosahedron_.tri[19].ids[1] = 11; base_icosahedron_.tri[19].ids[2] = 6;
|
||||
|
||||
//旋转二十面顶点的位置
|
||||
Vertex ref_vert = base_icosahedron_.vert[0]; //注意我们选取的参考点为z轴正方向
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
base_icosahedron_.vert[i] = RotateVertex(ref_vert,orient,base_icosahedron_.vert[i]);
|
||||
}
|
||||
return;
|
||||
}
|
112
src/stt_out_poly_outline.cc
Normal file
112
src/stt_out_poly_outline.cc
Normal file
@ -0,0 +1,112 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::OutPolyOutline(QuadTreeNode* node)
|
||||
{
|
||||
//没有范围多边形 直接返回否
|
||||
if (array_outline_polygon_.empty()){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int count, pnum;
|
||||
Cpoint tri_nor;
|
||||
Cpoint lineface_nor, edgeface_nor;
|
||||
Cpoint intersect[2];
|
||||
Cpoint angle_mid;
|
||||
Cpoint polygon_mid;
|
||||
Cpoint cross_point;
|
||||
Triangle temp_tri;
|
||||
for (int j = 0; j < 3; j++){
|
||||
temp_tri.ids[j] = node->tri.ids[j];
|
||||
}
|
||||
|
||||
//计算三角面元外法线矢量
|
||||
tri_nor = CrossProduct(array_stt_vert_[temp_tri.ids[1]].posic-array_stt_vert_[temp_tri.ids[0]].posic,
|
||||
array_stt_vert_[temp_tri.ids[2]].posic-array_stt_vert_[temp_tri.ids[0]].posic);
|
||||
//首先判断多边形的顶点是否在当前节点三角形内 或者多边形的边是否与当前节点三角形相交 这些条件可以判断多边形边上的三角形
|
||||
for (int i = 0; i < array_outline_polygon_.size(); i++){
|
||||
pnum = array_outline_polygon_[i].vert.size();
|
||||
for (int j = 0; j < array_outline_polygon_[i].vert.size(); j++){
|
||||
//排除球形背面的点
|
||||
if (DotProduct(tri_nor,array_outline_polygon_[i].vert[j].posic) > 0){
|
||||
//多边形节点在当前节点三角形内
|
||||
count = 0;
|
||||
for (int k = 0; k < 3; k++){
|
||||
cross_point = LineCrossPlane(array_stt_vert_[temp_tri.ids[k%3]].posic,tri_nor,array_outline_polygon_[i].vert[j].posic);
|
||||
//依次判断前后两条边与待检测点的外法线是否同向 注意排除从球体背面穿射的情况 全为真则返回真
|
||||
if (DotProduct(tri_nor,
|
||||
CrossProduct(array_stt_vert_[temp_tri.ids[(k+1)%3]].posic-array_stt_vert_[temp_tri.ids[k%3]].posic,
|
||||
cross_point-array_stt_vert_[temp_tri.ids[k%3]].posic)) > 0){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
//全部在左侧 多边形顶点至少有一个在节点三角形内 即节点三角形至少有一个顶点在多边形内 返回假
|
||||
if (count == 3) return 0;
|
||||
}
|
||||
//多边形边与当前节点三角形相交
|
||||
lineface_nor = CrossProduct(array_outline_polygon_[i].vert[j%pnum].posic,array_outline_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
angle_mid = 0.5*(array_outline_polygon_[i].vert[j%pnum].posic + array_outline_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
for (int n = 0; n < 3; n++){
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[temp_tri.ids[n%3]].posic,array_stt_vert_[temp_tri.ids[(n+1)%3]].posic);
|
||||
//排除两个扇面在同一个平面的情况
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor)*ModuleLength(edgeface_nor)) != 1.0){
|
||||
//两个扇面可能的交点矢量垂直于两个扇面的外法线矢量 正反两个矢量
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int k = 0; k < 2; k++){
|
||||
//交点矢量在两个线段端点矢量之间 注意端点先后顺序决定了大圆弧在球面上的范围 注意这里同样有从背面穿透的可能 因为我们不确定intersect中哪一个是我们想要的
|
||||
//注意计算叉乘的时候 我们总是会走一个角度小于180的方向
|
||||
//排除与angle_mid相反的半球上所有的三角形
|
||||
if (DotProduct(CrossProduct(intersect[k],array_stt_vert_[temp_tri.ids[n%3]].posic),CrossProduct(intersect[k],array_stt_vert_[temp_tri.ids[(n+1)%3]].posic)) < 0
|
||||
&& DotProduct(CrossProduct(intersect[k],array_outline_polygon_[i].vert[j%pnum].posic),CrossProduct(intersect[k],array_outline_polygon_[i].vert[(j+1)%pnum].posic)) < 0
|
||||
&& DotProduct(angle_mid,tri_nor) > 0){
|
||||
//多边形边与节点三角形相交 即节点三角形至少有一个顶点在多边形内 返回假
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//多边形的顶点和边与当前节点三角形不相交或者包含 判断三角形是否在多边形内
|
||||
for (int i = 0; i < array_outline_polygon_.size(); i++){
|
||||
pnum = array_outline_polygon_[i].vert.size();
|
||||
polygon_mid = CloudCenter(array_outline_polygon_[i].vert);
|
||||
//依次判断节点三角形的三条边与多边形边的交点个数
|
||||
for (int k = 0; k < 3; k++){
|
||||
count = 0;
|
||||
//计算三角形边与球心的平面的法线矢量 只要任意一条边在多边形内 则三角形在多边形内
|
||||
edgeface_nor = CrossProduct(array_stt_vert_[temp_tri.ids[(k)%3]].posic,array_stt_vert_[temp_tri.ids[(k+1)%3]].posic);
|
||||
for (int j = 0; j < array_outline_polygon_[i].vert.size(); j++){
|
||||
//多边形边与当前节点三角形相交
|
||||
lineface_nor = CrossProduct(array_outline_polygon_[i].vert[j%pnum].posic,array_outline_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
angle_mid = 0.5*(array_outline_polygon_[i].vert[j%pnum].posic + array_outline_polygon_[i].vert[(j+1)%pnum].posic);
|
||||
//排除两个扇面在同一个平面的情况
|
||||
if (fabs(DotProduct(lineface_nor,edgeface_nor))/(ModuleLength(lineface_nor)*ModuleLength(edgeface_nor)) != 1.0){
|
||||
//两个扇面可能的交点矢量垂直于两个扇面的外法线矢量 正反两个矢量
|
||||
intersect[0] = CrossProduct(lineface_nor,edgeface_nor);
|
||||
intersect[1] = CrossProduct(edgeface_nor,lineface_nor);
|
||||
for (int n = 0; n < 2; n++){
|
||||
/*注意 这里我们只判断交点是否在线段之间 或者一个点上 这里选择第一个点也可以选择第二点 但只能包含一个 不判断是不是在边之间
|
||||
注意我们只统计从当前三角形顶点向左或者向右旋转180度中遇到的交点*/
|
||||
//交点矢量在两个线段端点矢量之间 注意端点先后顺序决定了大圆弧在球面上的范围 注意这里同样有从背面穿透的可能 因为我们不确定intersect中哪一个是我们想要的
|
||||
//注意计算叉乘的时候 我们总是会走一个角度小于180的方向
|
||||
//排除与angle_mid相反的半球上所有的三角形
|
||||
if (DotProduct(polygon_mid,tri_nor) > 0 //排除位于球背面的三角形
|
||||
&& (DotProduct(CrossProduct(intersect[k],array_outline_polygon_[i].vert[j%pnum].posic),CrossProduct(intersect[k],array_outline_polygon_[i].vert[(j+1)%pnum].posic)) < 0
|
||||
|| array_outline_polygon_[i].vert[j].posic == intersect[n]) //排除与多边形的边不相交的三角形边的延长线 这里包含了一个等于条件 即交点刚好在多边形的顶点上
|
||||
&& DotProduct(angle_mid,intersect[n]) > 0 //排除位于球背面的多边形边与三角形边延长线的交点
|
||||
&& DotProduct(edgeface_nor,CrossProduct(array_stt_vert_[temp_tri.ids[k%3]].posic,intersect[n])) > 0) //只取三角形边其中一则的延长线
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//交点个数为奇数 边在多边形内 返回假
|
||||
if (pow(-1,count) < 0) return 0;
|
||||
}
|
||||
}
|
||||
//全不为假 返回真
|
||||
return 1;
|
||||
}
|
||||
}
|
58
src/stt_output_msh_file.cc
Normal file
58
src/stt_output_msh_file.cc
Normal file
@ -0,0 +1,58 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::OutputMshFile(char* filename,double pole_radius,double equator_radius)
|
||||
{
|
||||
time_t now = time(0);
|
||||
char* dt = ctime(&now);
|
||||
IntArray1D array_vert_id;
|
||||
Int2IntMap map_id_out_id;
|
||||
|
||||
if (!strcmp(filename,"NULL") || !strcmp(filename,""))
|
||||
return -1;
|
||||
|
||||
ofstream outfile;
|
||||
if(OpenOutfile(outfile,filename)) return -1;
|
||||
|
||||
vector<int>::iterator pos;
|
||||
for (int i = 0; i < array_out_tri_pointer_.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array_vert_id.push_back(array_out_tri_pointer_[i]->tri.ids[j]);
|
||||
}
|
||||
}
|
||||
sort(array_vert_id.begin(), array_vert_id.end()); //对顶点序列由小到大排序
|
||||
pos = unique(array_vert_id.begin(), array_vert_id.end()); //获取重复序列开始的位置
|
||||
array_vert_id.erase(pos, array_vert_id.end()); //删除重复顶点序列
|
||||
//初始化mapOutId;
|
||||
for (int i = 0; i < array_vert_id.size(); i++)
|
||||
{
|
||||
map_id_out_id[array_vert_id[i]] = i;
|
||||
}
|
||||
|
||||
Vertex temp_vert;
|
||||
outfile << "$Comments" << endl << "This file is created by stt-generator.ex on " << dt;
|
||||
outfile << "Commands: " << command_record_ << endl;
|
||||
outfile << "$EndComments" << endl;
|
||||
outfile << "$MeshFormat" << endl << "2.2 0 8" << endl << "$EndMeshFormat" << endl;
|
||||
outfile << "$Nodes"<< endl << array_vert_id.size() << endl;
|
||||
for (int i = 0; i < array_vert_id.size(); i++)
|
||||
{
|
||||
temp_vert = array_stt_vert_[array_vert_id[i]];
|
||||
//temp_vert.posis.rad = EllipsoidRadius(temp_vert.posis.lat,pole_radius,equator_radius);
|
||||
//temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
outfile << i << " " << setprecision(16) << temp_vert.posic.x << " " << temp_vert.posic.y << " " << temp_vert.posic.z << endl;
|
||||
}
|
||||
outfile << "$EndNodes" << endl;
|
||||
outfile << "$Elements" << endl << array_out_tri_pointer_.size() << endl;
|
||||
for (int i = 0; i < array_out_tri_pointer_.size(); i++)
|
||||
{
|
||||
outfile<< i <<" 2 1 " << array_out_tri_pointer_[i]->tri.physic_group << " "
|
||||
<< map_id_out_id[array_out_tri_pointer_[i]->tri.ids[0]] << " "
|
||||
<< map_id_out_id[array_out_tri_pointer_[i]->tri.ids[1]] << " "
|
||||
<< map_id_out_id[array_out_tri_pointer_[i]->tri.ids[2]] << endl;
|
||||
}
|
||||
outfile<<"$EndElements"<<endl;
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
34
src/stt_output_neighbor.cc
Normal file
34
src/stt_output_neighbor.cc
Normal file
@ -0,0 +1,34 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::OutputNeighbor(char* filename)
|
||||
{
|
||||
time_t now = time(0);
|
||||
char* dt = ctime(&now);
|
||||
ofstream outfile;
|
||||
Int2IntMap map_out_triangle_id_;
|
||||
|
||||
if (!strcmp(filename,"NULL")) return 0;
|
||||
if (OpenOutfile(outfile,filename)) return -1;
|
||||
|
||||
for (int i = 0; i < array_out_tri_pointer_.size(); i++){
|
||||
map_out_triangle_id_[array_out_tri_pointer_[i]->id] = i;
|
||||
}
|
||||
|
||||
outfile << "# This file is created by stt-generator.ex on " << dt;
|
||||
outfile << "# Commands: " << command_record_ << endl;
|
||||
outfile << "# Triangle number: "<< array_out_tri_pointer_.size() << endl;
|
||||
outfile << "# Invalid number: -1" << endl;
|
||||
outfile << "# triangle_id neighbor_id1 neighbor_id2 neighbor_id3" << endl;
|
||||
for (int i = 0; i < array_out_tri_pointer_.size(); i++){
|
||||
outfile << i;
|
||||
for (int j = 0; j < 3; j++){
|
||||
if (array_out_tri_pointer_[i]->neighbor[j] != nullptr){
|
||||
outfile << " " << map_out_triangle_id_[array_out_tri_pointer_[i]->neighbor[j]->id];
|
||||
}
|
||||
else outfile << " -1";
|
||||
}
|
||||
outfile << endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
32
src/stt_output_triangle_center_location.cc
Normal file
32
src/stt_output_triangle_center_location.cc
Normal file
@ -0,0 +1,32 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::OutputTriangleCenterLocation(char* filename,double pole_radius,double equator_radius)
|
||||
{
|
||||
time_t now = time(0);
|
||||
char* dt = ctime(&now);
|
||||
|
||||
if (!strcmp(filename,"NULL") || !strcmp(filename,""))
|
||||
return -1;
|
||||
|
||||
ofstream outfile;
|
||||
if(OpenOutfile(outfile,filename)) return -1;
|
||||
|
||||
Vertex temp_vert;
|
||||
outfile << "# This file is created by stt-generator.ex on " << dt;
|
||||
outfile << "# Commands: " << command_record_ << endl;
|
||||
outfile << "# Vertex number: "<< array_out_tri_pointer_.size() << endl;
|
||||
outfile << "# x y z longitude latitude radius (meter)" << endl;
|
||||
for (int i = 0; i < array_out_tri_pointer_.size(); i++)
|
||||
{
|
||||
temp_vert.posic = 1.0/3.0*(array_stt_vert_[array_out_tri_pointer_[i]->tri.ids[0]].posic
|
||||
+ array_stt_vert_[array_out_tri_pointer_[i]->tri.ids[1]].posic
|
||||
+ array_stt_vert_[array_out_tri_pointer_[i]->tri.ids[2]].posic);
|
||||
temp_vert.posis = Cartesian2Sphere(temp_vert.posic);
|
||||
temp_vert.posis.rad = EllipsoidRadius(temp_vert.posis.lat,pole_radius,equator_radius);
|
||||
temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
outfile << setprecision(16) << temp_vert.posic.x << " " << temp_vert.posic.y << " " << temp_vert.posic.z
|
||||
<< " " << temp_vert.posis.lon << " " << temp_vert.posis.lat << " " << temp_vert.posis.rad << endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
42
src/stt_output_vertex_location.cc
Normal file
42
src/stt_output_vertex_location.cc
Normal file
@ -0,0 +1,42 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::OutputVertexLocation(char* filename,double pole_radius,double equator_radius)
|
||||
{
|
||||
time_t now = time(0);
|
||||
char* dt = ctime(&now);
|
||||
IntArray1D array_vert_id;
|
||||
|
||||
if (!strcmp(filename,"NULL") || !strcmp(filename,""))
|
||||
return -1;
|
||||
|
||||
ofstream outfile;
|
||||
if(OpenOutfile(outfile,filename)) return -1;
|
||||
|
||||
vector<int>::iterator pos;
|
||||
for (int i = 0; i < array_out_tri_pointer_.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array_vert_id.push_back(array_out_tri_pointer_[i]->tri.ids[j]);
|
||||
}
|
||||
}
|
||||
sort(array_vert_id.begin(), array_vert_id.end()); //对顶点序列由小到大排序
|
||||
pos = unique(array_vert_id.begin(), array_vert_id.end()); //获取重复序列开始的位置
|
||||
array_vert_id.erase(pos, array_vert_id.end()); //删除重复顶点序列
|
||||
|
||||
Vertex temp_vert;
|
||||
outfile << "# This file is created by stt-generator.ex on " << dt;
|
||||
outfile << "# Commands: " << command_record_ << endl;
|
||||
outfile << "# Vertex number: "<< array_vert_id.size() << endl;
|
||||
outfile << "# x y z longitude latitude radius (meter)" << endl;
|
||||
for (int i = 0; i < array_vert_id.size(); i++)
|
||||
{
|
||||
temp_vert = array_stt_vert_[array_vert_id[i]];
|
||||
//temp_vert.posis.rad = EllipsoidRadius(temp_vert.posis.lat,pole_radius,equator_radius);
|
||||
//temp_vert.posic = Sphere2Cartesian(temp_vert.posis);
|
||||
outfile << setprecision(16) << temp_vert.posic.x << " " << temp_vert.posic.y << " " << temp_vert.posic.z
|
||||
<< " " << temp_vert.posis.lon << " " << temp_vert.posis.lat << " " << temp_vert.posis.rad << endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
19
src/stt_return_branch_depth.cc
Normal file
19
src/stt_return_branch_depth.cc
Normal file
@ -0,0 +1,19 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::ReturnBranchDepth(QuadTreeNode** p_tree){
|
||||
int node_depth, max_depth = 0;
|
||||
QuadTreeNode* current_node = *p_tree;
|
||||
if (current_node->children[0]==nullptr && current_node->children[1]==nullptr &&
|
||||
current_node->children[2]==nullptr && current_node->children[3]==nullptr){
|
||||
return current_node->depth;
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++){
|
||||
if (current_node->children[i] != nullptr){
|
||||
node_depth = ReturnBranchDepth(&(current_node->children[i]));
|
||||
if(node_depth > max_depth) max_depth = node_depth;
|
||||
}
|
||||
}
|
||||
return max_depth;
|
||||
}
|
||||
}
|
16
src/stt_return_depth.cc
Normal file
16
src/stt_return_depth.cc
Normal file
@ -0,0 +1,16 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::ReturnDepth(QuadTreeNode** p_tree,int back_depth){
|
||||
QuadTreeNode* current_node = *p_tree;
|
||||
if (current_node->depth == back_depth && back_depth <= max_depth_){
|
||||
array_out_tri_pointer_.push_back(current_node);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++){
|
||||
if (current_node->children[i] != nullptr)
|
||||
ReturnDepth(&(current_node->children[i]),back_depth);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
24
src/stt_return_leaf.cc
Normal file
24
src/stt_return_leaf.cc
Normal file
@ -0,0 +1,24 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
void SttGenerator::ReturnLeaf(QuadTreeNode** p_tree){
|
||||
QuadTreeNode* current_node = *p_tree;
|
||||
if (current_node->children[0]==nullptr && current_node->children[1]==nullptr &&
|
||||
current_node->children[2]==nullptr && current_node->children[3]==nullptr &&
|
||||
current_node->out_ok==true){
|
||||
// bug fix 这里将输出的节点的邻居重置为nullptr 否则在输出局部stt的邻居列表时将产生一个bug 即边缘位置的三角形会默认与0号三角形相邻
|
||||
// 这是因为在之前的闭合三角面过程中我们已全部对邻居列表赋值,所以所有节点三角形的邻居列表全不为空,因此一定会输出三个邻居,但对局部
|
||||
// stt而言,因为在输出环节的邻居排序中并不能找到对应的三角形索引,所以会输出一个默认值,即0。
|
||||
current_node->neighbor[0] = nullptr;
|
||||
current_node->neighbor[1] = nullptr;
|
||||
current_node->neighbor[2] = nullptr;
|
||||
array_out_tri_pointer_.push_back(current_node);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++){
|
||||
if (current_node->children[i]!=nullptr)
|
||||
ReturnLeaf(&(current_node->children[i]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
101
src/stt_routine.cc
Normal file
101
src/stt_routine.cc
Normal file
@ -0,0 +1,101 @@
|
||||
#include "stt_class.h"
|
||||
#include "progress_bar.h"
|
||||
|
||||
int SttGenerator::Routine(char input_options[][1024]){
|
||||
// set values of tree depths, terminate the program if failed
|
||||
if (set_tree_depth(input_options[0])) return -1;
|
||||
// set values of pole_radius_ and equator_radius_, terminate the program if failed
|
||||
if (set_pole_equator_radius(input_options[1])) return -1;
|
||||
// set orientation of the base icosahedron, terminate the program if failed
|
||||
if (set_icosahedron_orient(input_options[2])) return -1;
|
||||
// get extra-control information for control points, lines, polygons and circles. Terminate the program if failed
|
||||
// get outline and hole polygons
|
||||
if (GetControlPoint(input_options[7])) return -1;
|
||||
if (GetControlCircle(input_options[10])) return -1;
|
||||
if (GetControlLine(input_options[8],array_control_line_)) return -1;
|
||||
if (GetControlLine(input_options[9],array_control_polygon_)) return -1;
|
||||
if (GetControlLine(input_options[11],array_outline_polygon_)) return -1;
|
||||
if (GetControlLine(input_options[12],array_hole_polygon_)) return -1;
|
||||
|
||||
// initial spaces for tree root
|
||||
for (int i = 0; i < 20; i++){
|
||||
forest_[i] = new QuadTree;
|
||||
forest_[i]->root = new QuadTreeNode;
|
||||
}
|
||||
// initial the base icosahedron
|
||||
// the radius of the base icosahedron is set to DefaultR
|
||||
InitialIcosahedron(DefaultR,icosahedron_orient_);
|
||||
// map vertex to the reference sphere/ellipsoid
|
||||
for (int i = 0; i < 12; i++){
|
||||
base_icosahedron_.vert[i].posis = Cartesian2Sphere(base_icosahedron_.vert[i].posic);
|
||||
base_icosahedron_.vert[i].posis.rad = EllipsoidRadius(base_icosahedron_.vert[i].posis.lat, pole_radius_, equator_radius_);
|
||||
base_icosahedron_.vert[i].posic = Sphere2Cartesian(base_icosahedron_.vert[i].posis);
|
||||
}
|
||||
// add vertices of the base icosahedron to array_stt_vert_, map_id_vertex_ and map_str_vertex_
|
||||
for (int i = 0; i < 12; i++){
|
||||
array_stt_vert_.push_back(base_icosahedron_.vert[i]);
|
||||
map_id_vertex_[base_icosahedron_.vert[i].id] = base_icosahedron_.vert[i];
|
||||
map_str_vertex_[GetStringIndex(base_icosahedron_.vert[i])] = base_icosahedron_.vert[i];
|
||||
}
|
||||
|
||||
ProgressBar *bar = new ProgressBar(20,"Initialize STT");
|
||||
for (int i = 0; i < 20; i++){
|
||||
bar->Progressed(i);
|
||||
// initialize the tree index starts from 50 to avoid possible repetition of vertex's index
|
||||
CreateTree(i+50,base_icosahedron_.tri[i].ids[0],base_icosahedron_.tri[i].ids[1],base_icosahedron_.tri[i].ids[2], forest_[i]);
|
||||
}
|
||||
|
||||
delete bar;
|
||||
|
||||
// close surface after construction
|
||||
CloseSurface(&forest_[0]);
|
||||
|
||||
// if outline polygon exists
|
||||
if (!array_outline_polygon_.empty()){
|
||||
ProgressBar *bar3 = new ProgressBar(20,"Cut outline");
|
||||
for (int i = 0; i < 20; i++){
|
||||
bar3->Progressed(i);
|
||||
CutOutline(&(forest_[i]->root));
|
||||
}
|
||||
delete bar3;
|
||||
}
|
||||
|
||||
// if hole polygon exists
|
||||
if (!array_hole_polygon_.empty())
|
||||
{
|
||||
ProgressBar *bar4 = new ProgressBar(20,"Cut holes");
|
||||
for (int i = 0; i < 20; i++){
|
||||
bar4->Progressed(i);
|
||||
CutHole(&(forest_[i]->root));
|
||||
}
|
||||
delete bar4;
|
||||
}
|
||||
|
||||
// return leafs and prepare for outputs
|
||||
if (!array_out_tri_pointer_.empty()) array_out_tri_pointer_.clear();
|
||||
for (int i = 0; i < 20; i++)
|
||||
ReturnLeaf(&(forest_[i]->root));
|
||||
|
||||
if (!OutputMshFile(input_options[3],pole_radius_,equator_radius_))
|
||||
clog << "file saved: " << input_options[3] << endl;
|
||||
if (!OutputVertexLocation(input_options[4],pole_radius_,equator_radius_))
|
||||
clog << "file saved: " << input_options[4] << endl;
|
||||
if (!OutputTriangleCenterLocation(input_options[5],pole_radius_,equator_radius_))
|
||||
clog << "file saved: " << input_options[5] << endl;
|
||||
if (strcmp(input_options[6],"NULL")){
|
||||
SortNeighbor(array_out_tri_pointer_);
|
||||
if (!OutputNeighbor(input_options[6]))
|
||||
clog << "file saved: " << input_options[6] << endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
DeleteTree(&(forest_[i]->root));
|
||||
if (forest_[i] != nullptr)
|
||||
{
|
||||
delete forest_[i];
|
||||
forest_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
12
src/stt_set_command_record.cc
Normal file
12
src/stt_set_command_record.cc
Normal file
@ -0,0 +1,12 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::set_command_record(int argv_num,char** argvs)
|
||||
{
|
||||
command_record_ = argvs[0];
|
||||
for (int i = 1; i < argv_num; i++)
|
||||
{
|
||||
command_record_ += " ";
|
||||
command_record_ += argvs[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
19
src/stt_set_icosahedron_orient.cc
Normal file
19
src/stt_set_icosahedron_orient.cc
Normal file
@ -0,0 +1,19 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::set_icosahedron_orient(char* input_parameter){
|
||||
// if input_parameter is NULL or empty, set icosahedron_orient_ to the positive direction of z-axis
|
||||
if (!strcmp(input_parameter,"NULL") || !strcmp(input_parameter,"")){
|
||||
icosahedron_orient_.posis.lon = 0.0; icosahedron_orient_.posis.lat = 90.0;
|
||||
}
|
||||
// try to read the input parameter as icosahedron_orient_.posis.lon/icosahedron_orient_.posis.lat along with some boundary checks
|
||||
else if (2!=sscanf(input_parameter,"%lf/%lf",&icosahedron_orient_.posis.lon,&icosahedron_orient_.posis.lat)
|
||||
|| icosahedron_orient_.posis.lon < -180.0 || icosahedron_orient_.posis.lon > 180.0
|
||||
|| icosahedron_orient_.posis.lat < -90.0 || icosahedron_orient_.posis.lat > 90.0){
|
||||
cerr << BOLDRED << "Error ==> " << RESET << "fail to initialize the orient of the base icosahedron: " << input_parameter << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
icosahedron_orient_.posis.rad = DefaultR;
|
||||
icosahedron_orient_.posic = Sphere2Cartesian(icosahedron_orient_.posis);
|
||||
return 0;
|
||||
}
|
37
src/stt_set_pole_equator_radius.cc
Normal file
37
src/stt_set_pole_equator_radius.cc
Normal file
@ -0,0 +1,37 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::set_pole_equator_radius(char* input_parameter){
|
||||
double ratio;
|
||||
// if input_parameter is NULL or empty, set pole_radius_ and equator_radius_ to DefaultR
|
||||
if (!strcmp(input_parameter,"NULL") || !strcmp(input_parameter,"")){
|
||||
pole_radius_ = equator_radius_ = DefaultR;
|
||||
}
|
||||
// use predefined values
|
||||
else if (!strcmp(input_parameter,"WGS84")){
|
||||
pole_radius_ = WGS84_r; equator_radius_ = WGS84_R;
|
||||
}
|
||||
else if (!strcmp(input_parameter,"Earth")){
|
||||
pole_radius_ = equator_radius_ = Earth_r;
|
||||
}
|
||||
else if (!strcmp(input_parameter,"Moon")){
|
||||
pole_radius_ = equator_radius_ = Moon_r;
|
||||
}
|
||||
// first try to read the input parameter as equator_radius_/pole_radius_
|
||||
// note that equator_radius_ and pole_radius_ must be bigger than zero
|
||||
else if (2 != sscanf(input_parameter,"%lf/%lf",&equator_radius_,&pole_radius_) || pole_radius_ <= 0.0 || equator_radius_ <= 0.0){
|
||||
// then try to read it as equator_radius_,ratio in which ratio = pole_radius_/equator_radius_
|
||||
// note the ratio must be bigger than zero but not necessarily smaller than or equal to one
|
||||
// However, for reality account, we set the limit of the ratio as 2.0
|
||||
if (2 == sscanf(input_parameter,"%lf,%lf",&equator_radius_,&ratio) && equator_radius_ > 0.0 && ratio > 0.0 && ratio <= 2.0){
|
||||
pole_radius_ = ratio * equator_radius_;
|
||||
}
|
||||
// all attempts fail, return -1
|
||||
else{
|
||||
cerr << BOLDRED << "Error ==> " << RESET << "fail to initialize the coordinate reference system: " << input_parameter << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// test output
|
||||
//clog << equator_radius_ << " " << pole_radius_ << endl;
|
||||
return 0;
|
||||
}
|
15
src/stt_set_tree_depth.cc
Normal file
15
src/stt_set_tree_depth.cc
Normal file
@ -0,0 +1,15 @@
|
||||
#include "stt_class.h"
|
||||
|
||||
int SttGenerator::set_tree_depth(char* input_parameter){
|
||||
// if input_parameter is NULL or empty, set tree_depth_ and max_depth_ to zero
|
||||
if (!strcmp(input_parameter,"NULL") || !strcmp(input_parameter,"")){
|
||||
tree_depth_ = max_depth_ = 0;
|
||||
}
|
||||
// try to read the input parameter as tree_depth_/max_depth_ along with some boundary checks
|
||||
else if (2!=sscanf(input_parameter,"%d/%d",&tree_depth_,&max_depth_)
|
||||
|| tree_depth_ > max_depth_ || max_depth_ < 0){
|
||||
cerr << BOLDRED << "Error ==> " << RESET << "fail to initialize the minimal and maximal quad-tree depths: " << input_parameter << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
78
src/stt_sort_neighbor.cc
Normal file
78
src/stt_sort_neighbor.cc
Normal file
@ -0,0 +1,78 @@
|
||||
#include "stt_class.h"
|
||||
#include "progress_bar.h"
|
||||
|
||||
void SttGenerator::SortNeighbor(QuadTreeNodePointerArray input_pointers)
|
||||
{
|
||||
int local_id1,local_id2;
|
||||
IntArray1D vert_index; //当前层的顶点索引列表
|
||||
vector<int>::iterator pos; //整型向量的迭代器
|
||||
IntArray2D vert_neighbor; //对应于当前层顶点索引的相邻三角形索引列表
|
||||
IntArray2D neighbor_index; //三角形的相邻索引
|
||||
Int2IntMap map_vert_id;
|
||||
|
||||
//确定当前层的所有顶点索引列表
|
||||
if (!vert_index.empty()) vert_index.clear();
|
||||
for (int i = 0; i < input_pointers.size(); i++){
|
||||
for (int t = 0; t < 3; t++){
|
||||
vert_index.push_back(input_pointers[i]->tri.ids[t]);
|
||||
}
|
||||
}
|
||||
//去除所有重复点
|
||||
sort(vert_index.begin(),vert_index.end()); //对顶点序列由小到大排序
|
||||
pos = unique(vert_index.begin(),vert_index.end()); //获取重复序列开始的位置
|
||||
vert_index.erase(pos,vert_index.end()); //删除重复点
|
||||
//初始化map_vert_id
|
||||
if (!map_vert_id.empty()) map_vert_id.clear();
|
||||
for (int i = 0; i < vert_index.size(); i++){
|
||||
map_vert_id[vert_index[i]] = i;
|
||||
}
|
||||
//确定与顶点相连的三角形索引列表
|
||||
if (!vert_neighbor.empty()){
|
||||
for (int i = 0; i < vert_neighbor.size(); i++){
|
||||
if (!vert_neighbor[i].empty()) vert_neighbor[i].clear();
|
||||
}
|
||||
}
|
||||
vert_neighbor.resize(vert_index.size());
|
||||
for (int i = 0; i < input_pointers.size(); i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
vert_neighbor[map_vert_id[input_pointers[i]->tri.ids[j]]].push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!neighbor_index.empty()){
|
||||
for (int i = 0; i < neighbor_index.size(); i++){
|
||||
if (!neighbor_index[i].empty()) neighbor_index[i].clear();
|
||||
}
|
||||
}
|
||||
neighbor_index.resize(input_pointers.size());
|
||||
for (int i = 0; i < neighbor_index.size(); i++)
|
||||
neighbor_index[i].reserve(3);
|
||||
|
||||
//确定相邻的三角形
|
||||
for (int i = 0; i < vert_neighbor.size(); i++){
|
||||
//顺序取其中两个三角形 size为1时循环直接跳过
|
||||
for (int m = 0; m < vert_neighbor[i].size()-1; m++){
|
||||
local_id1 = LocalIndex(vert_index[i], input_pointers[vert_neighbor[i][m]]->tri);
|
||||
for (int n = m+1; n < vert_neighbor[i].size(); n++){
|
||||
local_id2 = LocalIndex(vert_index[i], input_pointers[vert_neighbor[i][n]]->tri);
|
||||
//使用单边相邻进行判定 避免重复添加
|
||||
if (input_pointers[vert_neighbor[i][m]]->tri.ids[(local_id1+1)%3] == input_pointers[vert_neighbor[i][n]]->tri.ids[(local_id2+2)%3]){
|
||||
//相互添加
|
||||
neighbor_index[vert_neighbor[i][m]].push_back(vert_neighbor[i][n]);
|
||||
neighbor_index[vert_neighbor[i][n]].push_back(vert_neighbor[i][m]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//最后为对应的节点添加neighbor
|
||||
for (int i = 0; i < neighbor_index.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < neighbor_index[i].size(); j++)
|
||||
{
|
||||
input_pointers[i]->neighbor[j] = input_pointers[neighbor_index[i][j]];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
Loading…
Reference in New Issue
Block a user