├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── dataset ├── GT │ ├── Freiburg101_scan.png │ ├── Freiburg101_scan_furnitures_trashbins.png │ ├── Freiburg79_scan_furnitures_trashbins.png │ ├── freiburg_building101.png │ ├── freiburg_building52.png │ ├── freiburg_building79.png │ ├── intel_map.png │ ├── lab_a.png │ ├── lab_b.png │ ├── lab_c.png │ ├── lab_c_scan_furnitures_trashbins.png │ ├── lab_d.png │ ├── lab_d_scan_furnitures.png │ ├── lab_e.png │ ├── lab_ipa_furnitures.png │ └── sistD.png ├── data_setting ├── input │ ├── Freiburg101_scan.png │ ├── Freiburg101_scan_furnitures_trashbins.png │ ├── Freiburg79_scan_furnitures_trashbins.png │ ├── freiburg_building101.png │ ├── freiburg_building52.png │ ├── freiburg_building79.png │ ├── intel_map.png │ ├── lab_a.png │ ├── lab_b.png │ ├── lab_c.png │ ├── lab_c_scan_furnitures_trashbins.png │ ├── lab_d.png │ ├── lab_d_scan_furnitures.png │ ├── lab_e.png │ ├── lab_ipa_furnitures.png │ └── sistD.png ├── input_afterRemoval │ ├── Freiburg101_scan.png │ ├── Freiburg101_scan_furnitures_trashbins.png │ ├── Freiburg79_scan_furnitures_trashbins.png │ ├── freiburg_building101.png │ ├── freiburg_building52.png │ ├── freiburg_building79.png │ ├── intel_map.png │ ├── lab_a.png │ ├── lab_b.png │ ├── lab_c.png │ ├── lab_c_scan_furnitures_trashbins.png │ ├── lab_d.png │ ├── lab_d_scan_furnitures.png │ ├── lab_e.png │ ├── lab_ipa_furnitures.png │ └── sistD.png ├── mazes │ ├── maze.jpg │ ├── maze4000.png │ ├── maze_ipa.png │ ├── maze_maoris.png │ ├── maze_my.png │ ├── singa.png │ ├── singa_ipa.png │ ├── singa_maoris.png │ └── singa_my.png ├── strategy_w │ ├── Freiburg101_scan.png │ ├── Freiburg101_scan_furnitures_trashbins.png │ ├── Freiburg79_scan_furnitures_trashbins.png │ ├── freiburg_building101.png │ ├── freiburg_building52.png │ ├── freiburg_building79.png │ ├── intel_map.png │ ├── lab_a.png │ ├── lab_b.png │ ├── lab_c.png │ ├── lab_c_scan_furnitures_trashbins.png │ ├── lab_d.png │ ├── lab_d_scan_furnitures.png │ ├── lab_e.png │ ├── lab_ipa_furnitures.png │ └── sistD.png └── w=1_25 │ ├── Freiburg101_scan.png │ ├── Freiburg101_scan_furnitures_trashbins.png │ ├── Freiburg79_scan_furnitures_trashbins.png │ ├── freiburg_building101.png │ ├── freiburg_building52.png │ ├── freiburg_building79.png │ ├── intel_map.png │ ├── lab_a.png │ ├── lab_b.png │ ├── lab_c.png │ ├── lab_c_scan_furnitures_trashbins.png │ ├── lab_d.png │ ├── lab_d_scan_furnitures.png │ ├── lab_e.png │ ├── lab_ipa_furnitures.png │ └── sistD.png ├── include ├── AreaGenerate.h ├── Denoise.h ├── RoomDect.h ├── TopoGeometry.h ├── TopoGraph.h ├── VoriConfig.h ├── VoriGraph.h ├── cgal │ ├── AlphaShape.h │ ├── AlphaShapeRemoval.h │ └── CgalVoronoi.h ├── passageSearch.h ├── qt │ └── QImageVoronoi.h └── roomGraph.h ├── src ├── AreaGenerate.cpp ├── Denoise.cpp ├── RoomDect.cpp ├── TopoGraph.cpp ├── VoriConfig.cpp ├── VoriGraph.cpp ├── cgal │ ├── AlphaShape.cpp │ ├── AlphaShapeRemoval.cpp │ └── CgalVoronoi.cpp ├── passageSearch.cpp ├── qt │ └── QImageVoronoi.cpp └── roomGraph.cpp └── test └── example.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | *~ 35 | build/ 36 | bin/ 37 | .idea/ 38 | cmake-build-debug/ 39 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | 3 | project (TOPO_GRAPH_2D) 4 | 5 | find_package( Boost REQUIRED ) 6 | if ( NOT Boost_FOUND ) 7 | message(STATUS "This project requires the Boost library, and will not be compiled.") 8 | return() 9 | endif() 10 | 11 | find_package(CGAL COMPONENTS Core Boost) 12 | FIND_PACKAGE(Qt4 REQUIRED) 13 | 14 | 15 | if ( CGAL_FOUND ) 16 | 17 | include( ${CGAL_USE_FILE} ) 18 | 19 | include( CGAL_CreateSingleSourceCGALProgram ) 20 | 21 | else() 22 | 23 | message(STATUS "This program requires the CGAL library, and will not be compiled.") 24 | 25 | endif() 26 | 27 | INCLUDE(${QT_USE_FILE}) 28 | ADD_DEFINITIONS(${QT_DEFINITIONS}) 29 | 30 | #add_subdirectory (dir) 31 | 32 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 33 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 34 | 35 | add_library (topo_graph_2d STATIC / 36 | src/VoriConfig.cpp / 37 | src/VoriGraph.cpp / 38 | src/TopoGraph.cpp / 39 | src/RoomDect.cpp / 40 | src/roomGraph.cpp / 41 | src/Denoise.cpp / 42 | src/passageSearch.cpp / 43 | src/cgal/CgalVoronoi.cpp / 44 | src/cgal/AlphaShape.cpp / 45 | src/qt/QImageVoronoi.cpp / 46 | src/cgal/AlphaShapeRemoval.cpp) 47 | 48 | include_directories (${TOPO_GRAPH_2D_SOURCE_DIR}/include) 49 | 50 | include_directories(${CGAL_INCLUDE_DIR} ${QT_INCLUDE_DIR}) 51 | 52 | add_executable(example_segmentation test/example.cpp) 53 | include_directories (${TOPO_GRAPH_2D_SOURCE_DIR}/include) 54 | 55 | message(STATUS " cgal: ${CGAL_LIBRARIES} ") 56 | 57 | TARGET_LINK_LIBRARIES(example_segmentation topo_graph_2d ${QT_LIBRARIES} ${CGAL_LIBRARIES} -lboost_unit_test_framework -lboost_filesystem -lboost_system) 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Area graph 2 | 3 | ## Paper 4 | The paper describing the method was accepted for publication at ICAR2019. The preprint version is [available on Arxiv](https://arxiv.org/abs/1910.01019). 5 | 6 | Hou, J., Y. Yuan, and S. Schwertfeger, "Area Graph: Generation of Topological Maps using the Voronoi Diagram", 19th International Conference on Advanced Robotics (ICAR): IEEE Press, 2019. 7 | 8 | ``` 9 | @conference {hou2019area, 10 | title = {Area Graph: Generation of Topological Maps using the Voronoi Diagram}, 11 | booktitle = {19th International Conference on Advanced Robotics (ICAR)}, 12 | year = {2019}, 13 | publisher = {IEEE Press}, 14 | organization = {IEEE Press}, 15 | author = {Hou, Jiawei and Yuan, Yijun and Schwertfeger, S{\"o}ren} 16 | } 17 | ``` 18 | 19 | 20 | 21 | 22 | ## How to compile 23 | ### Dependencies 24 | Before running the code, make sure you have installed: cmake, g++, Eigen3, Qt4, CGAL 25 | They can be installed by (Ubuntu): 26 | ``` 27 | sudo apt-get install g++ 28 | sudo apt-get install cmake 29 | sudo apt-get install qt4-default 30 | sudo apt-get install libcgal-dev 31 | ``` 32 | The code has been test on Ubuntu 14.04 and 16.04. 33 | 34 | ### How to use 35 | Now, we can build our Area Graph generation code: 36 | ``` 37 | cd /path/to/map-matching/code/ 38 | mkdir build 39 | cd build 40 | cmake .. 41 | make example_segmentation 42 | ./bin/test_areaMatch Map.png resolution door_width corridor_width noise_percentage 43 | ``` 44 | where the meanings of the arguments are shown belows. 45 | * Map.png: The map you are going to generate the Area Graph for it. Please don't use the maps whose background color is lighter than the sites (obstacle points). 46 | * resolution: resolution of the map (the default resolution is set as 0.05) 47 | * door_width: the widest door's width in the environment 48 | * corridor_width: the narrowest corridor's width in the environment 49 | if you don't know the door width and corridor width of the environment, set it as -1 and we use the fix W = 1.25 to run the Alpha Shape algorithm to detect rooms 50 | * noise_percentage: You can rely on intuition to estimate how much noise is in the map. If you use the map in the directory "afterAlphaRemoval" as input, you can set this argument as 0. 51 | 52 | example: 53 | ``` 54 | ./bin/example_segmentation ../dataset/input/Freiburg79_scan_furnitures_trashbins.png 0.05 -1 -1 1.5 55 | ``` 56 | or 57 | ``` 58 | ./bin/example_segmentation ../dataset/input/Freiburg79_scan_furnitures_trashbins.png 0.05 0.85 2.7 1.5 59 | ``` 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /dataset/GT/Freiburg101_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/Freiburg101_scan.png -------------------------------------------------------------------------------- /dataset/GT/Freiburg101_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/Freiburg101_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/GT/Freiburg79_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/Freiburg79_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/GT/freiburg_building101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/freiburg_building101.png -------------------------------------------------------------------------------- /dataset/GT/freiburg_building52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/freiburg_building52.png -------------------------------------------------------------------------------- /dataset/GT/freiburg_building79.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/freiburg_building79.png -------------------------------------------------------------------------------- /dataset/GT/intel_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/intel_map.png -------------------------------------------------------------------------------- /dataset/GT/lab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_a.png -------------------------------------------------------------------------------- /dataset/GT/lab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_b.png -------------------------------------------------------------------------------- /dataset/GT/lab_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_c.png -------------------------------------------------------------------------------- /dataset/GT/lab_c_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_c_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/GT/lab_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_d.png -------------------------------------------------------------------------------- /dataset/GT/lab_d_scan_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_d_scan_furnitures.png -------------------------------------------------------------------------------- /dataset/GT/lab_e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_e.png -------------------------------------------------------------------------------- /dataset/GT/lab_ipa_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/lab_ipa_furnitures.png -------------------------------------------------------------------------------- /dataset/GT/sistD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/GT/sistD.png -------------------------------------------------------------------------------- /dataset/data_setting: -------------------------------------------------------------------------------- 1 | resolution (m/pixel) (Bormann did not tell the resolution of the data so we just guess their resolution): 2 | Freiburg79_scan_furnitures_trashbins.png 0.05 3 | Freiburg101_scan.png 0.05 4 | Freiburg101_scan_furnitures_trashbins.png 0.05 5 | freiburg_building79.png 0.05 6 | freiburg_building52.png 0.05 7 | freiburg_building101.png 0.05 8 | intel_map.png 0.05 9 | lab_a.png 0.05 10 | lab_b.png 0.05 11 | lab_c.png 0.05 12 | lab_d_scan_furnitures.png 0.05 13 | lab_ipa_furnitures.png 0.05 14 | sistD.png 0.05 15 | lab_c_scan_furnitures_trashbins.png 0.05 16 | 17 | widest door width (m) and narrowest corridor width (m) (roughly measure with GIMP): 18 | Freiburg79_scan_furnitures_trashbins.png 0.85 2.7 19 | Freiburg101_scan.png 1.15 6 20 | Freiburg101_scan_furnitures_trashbins.png 1.15 6 21 | freiburg_building79.png 1.3 2.05 22 | freiburg_building52.png 0.85 1.65 23 | freiburg_building101.png 1.0 2.7 24 | intel_map.png 2.7 1.4 25 | lab_a.png 0.85 1.15 26 | lab_b.png 1.8 1.2 27 | lab_c.png 2.05 2.3 28 | lab_d_scan_furnitures.png 0.95 0.95 29 | lab_ipa_furnitures.png 1.3 1.6 30 | sistD.png 1.5 2.35 31 | lab_c_scan_furnitures_trashbins.png 2.2 2.05 32 | 33 | w (m) according to strategy: 34 | Freiburg79_scan_furnitures_trashbins.png 0.95 35 | Freiburg101_scan.png 1.25 36 | Freiburg101_scan_furnitures_trashbins.png 1.25 37 | freiburg_building79.png 1.4 38 | freiburg_building52.png 0.95 39 | freiburg_building101.png 1.1 40 | intel_map.png 1.3 41 | lab_a.png 0.95 42 | lab_b.png 1.1 43 | lab_c.png 2.15 44 | lab_d_scan_furnitures.png 1.05 45 | lab_ipa_furnitures.png 1.4 46 | sistD.png 1.6 47 | lab_c_scan_furnitures_trashbins.png 1.95 48 | 49 | noise percentage: 50 | Freiburg79_scan_furnitures_trashbins.png 1.5 51 | Freiburg101_scan.png 0 52 | Freiburg101_scan_furnitures_trashbins.png 0 53 | freiburg_building79.png 3.5 54 | freiburg_building52.png 3.5 55 | freiburg_building101.png 3.5 (please also set MAX_PLEN_REMOVAL as 380 in AlphaShapeRemoval.h for this map, because there is a big obstacle in the map) 56 | intel_map.png 3 57 | lab_a.png 0.2 58 | lab_b.png 3.5 59 | lab_c.png 0 60 | lab_d_scan_furnitures.png 1 61 | lab_ipa_furnitures.png 2.5 62 | sistD.png 0.5 63 | lab_c_scan_furnitures_trashbins.png 2 64 | -------------------------------------------------------------------------------- /dataset/input/Freiburg101_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/Freiburg101_scan.png -------------------------------------------------------------------------------- /dataset/input/Freiburg101_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/Freiburg101_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/input/Freiburg79_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/Freiburg79_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/input/freiburg_building101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/freiburg_building101.png -------------------------------------------------------------------------------- /dataset/input/freiburg_building52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/freiburg_building52.png -------------------------------------------------------------------------------- /dataset/input/freiburg_building79.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/freiburg_building79.png -------------------------------------------------------------------------------- /dataset/input/intel_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/intel_map.png -------------------------------------------------------------------------------- /dataset/input/lab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_a.png -------------------------------------------------------------------------------- /dataset/input/lab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_b.png -------------------------------------------------------------------------------- /dataset/input/lab_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_c.png -------------------------------------------------------------------------------- /dataset/input/lab_c_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_c_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/input/lab_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_d.png -------------------------------------------------------------------------------- /dataset/input/lab_d_scan_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_d_scan_furnitures.png -------------------------------------------------------------------------------- /dataset/input/lab_e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_e.png -------------------------------------------------------------------------------- /dataset/input/lab_ipa_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/lab_ipa_furnitures.png -------------------------------------------------------------------------------- /dataset/input/sistD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input/sistD.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/Freiburg101_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/Freiburg101_scan.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/Freiburg101_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/Freiburg101_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/Freiburg79_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/Freiburg79_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/freiburg_building101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/freiburg_building101.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/freiburg_building52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/freiburg_building52.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/freiburg_building79.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/freiburg_building79.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/intel_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/intel_map.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_a.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_b.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_c.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_c_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_c_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_d.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_d_scan_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_d_scan_furnitures.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_e.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/lab_ipa_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/lab_ipa_furnitures.png -------------------------------------------------------------------------------- /dataset/input_afterRemoval/sistD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/input_afterRemoval/sistD.png -------------------------------------------------------------------------------- /dataset/mazes/maze.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/maze.jpg -------------------------------------------------------------------------------- /dataset/mazes/maze4000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/maze4000.png -------------------------------------------------------------------------------- /dataset/mazes/maze_ipa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/maze_ipa.png -------------------------------------------------------------------------------- /dataset/mazes/maze_maoris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/maze_maoris.png -------------------------------------------------------------------------------- /dataset/mazes/maze_my.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/maze_my.png -------------------------------------------------------------------------------- /dataset/mazes/singa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/singa.png -------------------------------------------------------------------------------- /dataset/mazes/singa_ipa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/singa_ipa.png -------------------------------------------------------------------------------- /dataset/mazes/singa_maoris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/singa_maoris.png -------------------------------------------------------------------------------- /dataset/mazes/singa_my.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/mazes/singa_my.png -------------------------------------------------------------------------------- /dataset/strategy_w/Freiburg101_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/Freiburg101_scan.png -------------------------------------------------------------------------------- /dataset/strategy_w/Freiburg101_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/Freiburg101_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/strategy_w/Freiburg79_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/Freiburg79_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/strategy_w/freiburg_building101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/freiburg_building101.png -------------------------------------------------------------------------------- /dataset/strategy_w/freiburg_building52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/freiburg_building52.png -------------------------------------------------------------------------------- /dataset/strategy_w/freiburg_building79.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/freiburg_building79.png -------------------------------------------------------------------------------- /dataset/strategy_w/intel_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/intel_map.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_a.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_b.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_c.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_c_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_c_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_d.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_d_scan_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_d_scan_furnitures.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_e.png -------------------------------------------------------------------------------- /dataset/strategy_w/lab_ipa_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/lab_ipa_furnitures.png -------------------------------------------------------------------------------- /dataset/strategy_w/sistD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/strategy_w/sistD.png -------------------------------------------------------------------------------- /dataset/w=1_25/Freiburg101_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/Freiburg101_scan.png -------------------------------------------------------------------------------- /dataset/w=1_25/Freiburg101_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/Freiburg101_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/w=1_25/Freiburg79_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/Freiburg79_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/w=1_25/freiburg_building101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/freiburg_building101.png -------------------------------------------------------------------------------- /dataset/w=1_25/freiburg_building52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/freiburg_building52.png -------------------------------------------------------------------------------- /dataset/w=1_25/freiburg_building79.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/freiburg_building79.png -------------------------------------------------------------------------------- /dataset/w=1_25/intel_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/intel_map.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_a.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_b.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_c.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_c_scan_furnitures_trashbins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_c_scan_furnitures_trashbins.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_d.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_d_scan_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_d_scan_furnitures.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_e.png -------------------------------------------------------------------------------- /dataset/w=1_25/lab_ipa_furnitures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/lab_ipa_furnitures.png -------------------------------------------------------------------------------- /dataset/w=1_25/sistD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-Center/areaGraph/97148680326fb44c524c499cfe8116121308a5ad/dataset/w=1_25/sistD.png -------------------------------------------------------------------------------- /include/AreaGenerate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by houjiawei on 18-1-24. 3 | // 4 | 5 | #ifndef TOPO_GRAPH_2D_AREAGENERATE_H 6 | #define TOPO_GRAPH_2D_AREAGENERATE_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "VoriGraph.h" 17 | #include "TopoGraph.h" 18 | #include "cgal/CgalVoronoi.h" 19 | #include "cgal/AlphaShape.h" 20 | #include "qt/QImageVoronoi.h" 21 | 22 | 23 | //#include "TopoPathMatcher.h" 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include "RoomDect.h" 30 | 31 | #include "roomGraph.h" 32 | #include "Denoise.h" 33 | 34 | void generateAreas(const char *input_name, const char *output_name, VoriConfig *sConfig, VoriGraph &voriGraph); 35 | 36 | 37 | void generateRMG(RMG::AreaGraph &RMGraph); 38 | //bool generateAreas(QImage input_name, QImage output_name){} 39 | #endif //TOPO_GRAPH_2D_AREAGENERATE_H -------------------------------------------------------------------------------- /include/Denoise.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by houjiawei on 18-1-23. 3 | // 4 | 5 | #ifndef TOPO_GRAPH_2D_DENOISE_H 6 | #define TOPO_GRAPH_2D_DENOISE_H 7 | 8 | #endif //TOPO_GRAPH_2D_DENOISE_H 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; 18 | typedef Kernel::Point_3 Point; 19 | 20 | 21 | using namespace std; 22 | 23 | QImage paintPoints(const char* file_name, const vector &points, int width, int height); 24 | bool isBlack(uchar* pixel, int black_threshold); 25 | void getPoints(QImage &img, int &black_threshold, vector &points); 26 | void usage(); 27 | bool DenoiseImg(const char* input_name, const char* output_name, int &black_threshold, int neighbors, double percentage); -------------------------------------------------------------------------------- /include/RoomDect.h: -------------------------------------------------------------------------------- 1 | #ifndef ROOM_DECT_H 2 | #define ROOM_DECT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // includes for defining the Voronoi diagram adaptor 9 | //#include 10 | //#include 11 | //#include 12 | //#include 13 | //#include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "cgal/AlphaShape.h" 26 | 27 | typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 28 | 29 | typedef CGAL::Alpha_shape_vertex_base_2 Avb; 30 | typedef CGAL::Triangulation_hierarchy_vertex_base_2 Av; 31 | typedef CGAL::Triangulation_face_base_2 Tf; 32 | typedef CGAL::Alpha_shape_face_base_2 Af; 33 | 34 | typedef CGAL::Triangulation_default_data_structure_2 Tds; 35 | typedef CGAL::Delaunay_triangulation_2 Dt; 36 | typedef CGAL::Triangulation_hierarchy_2
Ht; 37 | typedef CGAL::Alpha_shape_2 Alpha_shape_2; 38 | 39 | typedef Alpha_shape_2::Alpha_shape_edges_iterator Edge_iterator; 40 | 41 | typedef CGAL::Polygon_2 Polygon_2; 42 | typedef K::Segment_2 Segment; 43 | 44 | //add 45 | typedef Polygon_2::Vertex_iterator Vertex_iterator; 46 | 47 | #include "VoriGraph.h" 48 | 49 | class RoomDect { 50 | public: 51 | // containing roomid of all polygons (except the biggest one) 52 | std::list roomidList; 53 | 54 | //record map room's id to room's vorigraph 55 | std::map voriRooms; 56 | 57 | //map of border vertices in voriroom to the ones in vorigraph 58 | std::map > roomMap; 59 | 60 | //void drawRoom(std::string prefix); 61 | //cut at intersections 62 | void cutEdgeCrossingPolygons(AlphaShapePolygon &alphaSP, VoriGraph &voriGraph, Polygon_2 *poly); 63 | void forRoomDect(AlphaShapePolygon &alphaSP, VoriGraph &voriGraph, AlphaShapePolygon::Polygon_2 *poly); 64 | 65 | void drawPolygon(AlphaShapePolygon &alphaSP, QImage &pImg); 66 | 67 | private: 68 | //return true if edge intersects with polygon and put the cut distances from source to the vector 69 | bool cutDist(VoriGraphHalfEdge *edge, Polygon_2 *polygon, std::vector &distance); 70 | 71 | //used during cutEdgeCrossingPolygons 72 | void setRoomIDForNonRoomVertex(VoriGraphHalfEdge *edge, Polygon_2 *polygon, int index = -1); 73 | 74 | void setRoomIDForPath(VoriGraph &voriGraph, AlphaShapePolygon &alphaSP); 75 | 76 | void mergeDeadEndInRoom_polygon(VoriGraph &voriGraph); 77 | void mergeDeadEndInRoom(VoriGraph &voriGraph); 78 | 79 | void labelpassages(VoriGraph &voriGraph); 80 | 81 | void saveRooms(AlphaShapePolygon &alphaSP, VoriGraph &voriGraph, Polygon_2 *poly); 82 | 83 | void roomCenterCalc(AlphaShapePolygon &alphaSP, int roomIndex, double ¢erX, double ¢erY); 84 | 85 | void generateNewRoom(AlphaShapePolygon &alphaSP, VoriGraph &voriGraph); 86 | 87 | void removeDeadEndRoomVertex(VoriGraph &voriGraph); 88 | 89 | }; 90 | 91 | #endif -------------------------------------------------------------------------------- /include/TopoGeometry.h: -------------------------------------------------------------------------------- 1 | #ifndef TOPO_GEOMETRY_H 2 | #define TOPO_GEOMETRY_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #define EPSINON 0.00000001 10 | BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) 11 | 12 | namespace topo_geometry{ 13 | 14 | typedef boost::geometry::model::d2::point_xy point; 15 | 16 | static double getX(const point &p){ 17 | return boost::geometry::get<0>(p); 18 | } 19 | static double getY(const point &p){ 20 | return boost::geometry::get<1>(p); 21 | } 22 | 23 | // boost::geometry::distance 24 | 25 | 26 | /* Jiawei: crate a polygon DS */ 27 | 28 | struct polygon{ 29 | std::list points; 30 | }; 31 | 32 | static std::string print(const point &p){ 33 | std::stringstream str; 34 | str<(one) == boost::geometry::get<0>(two)) return boost::geometry::get<1>(one) < boost::geometry::get<1>(two); 42 | return boost::geometry::get<0>(one) < boost::geometry::get<0>(two); 43 | } 44 | }; 45 | 46 | class Vertex{ 47 | public: 48 | 49 | point p; 50 | 51 | }; 52 | //add from yutianyan 53 | // comparison for 2D coordinates - in order to judge whether the path is cut from source or target 54 | // set as static to avoid multiple definition 55 | static bool operator==(const point &one, const point &two) { 56 | return (boost::geometry::get<0>( one ) == boost::geometry::get<0>( two )) && 57 | (boost::geometry::get<1>( one ) == boost::geometry::get<1>( two )); 58 | } 59 | /** Jiawei **/ 60 | // static bool operator==(const point &one, const point &two) { 61 | // return (fabs(boost::geometry::get<0>( one ) - boost::geometry::get<0>( two ))( one ) - boost::geometry::get<1>( two )) cutHalfedge(point cutfrom, double cutlength) { 85 | //list to save the cut halfedge 86 | std::list edgeCutted; 87 | if ((cutlength - EPSINON > length_) || (cutlength + EPSINON < 0)) { 88 | //0. can not cut at the point out of the halfedge 89 | return edgeCutted; 90 | } else { 91 | //1. normal cutting (2 Halfedges in result) 92 | if ((cutlength - EPSINON > 0) && (cutlength + EPSINON < length_)) { 93 | double rate = 0; 94 | if (cutfrom == s_) { 95 | rate = cutlength / length_; 96 | } else { 97 | if (cutfrom == t_) { 98 | rate = 1 - cutlength / length_; 99 | } else { 100 | //point must be start or target vertex of the halfedge 101 | return edgeCutted; 102 | } 103 | } 104 | 105 | point cutposition( rate * getX( t_ ) + (1 - rate) * getX( s_ ), 106 | rate * getY( t_ ) + (1 - rate) * getY( s_ )); 107 | Halfedge edgeCut_first( s_, cutposition, o_, dist_, isRay_ ); 108 | Halfedge edgeCut_second( cutposition, t_, o_, dist_, isRay_ ); 109 | 110 | edgeCutted.push_back( edgeCut_first ); 111 | edgeCutted.push_back( edgeCut_second ); 112 | } else { 113 | //2. cutting at source/target 114 | Halfedge edgeCut( s_, t_, o_, dist_, isRay_ ); 115 | edgeCutted.push_back( edgeCut ); 116 | } 117 | return edgeCutted; 118 | } 119 | } 120 | 121 | protected: 122 | 123 | double calcLength(){ 124 | length_ = boost::geometry::distance(s_, t_); 125 | return length_; 126 | } 127 | 128 | /* Jiawei: create polygon face in here */ 129 | 130 | polygon pol; 131 | 132 | point s_, t_, o_; 133 | double dist_, length_; 134 | bool isRay_; 135 | }; 136 | 137 | } 138 | 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /include/TopoGraph.h: -------------------------------------------------------------------------------- 1 | #ifndef TOPO_GRAPH_H 2 | #define TOPO_GRAPH_H 3 | 4 | #include "VoriGraph.h" 5 | 6 | // #include 7 | 8 | class TopoExit; 9 | 10 | class TopoVertex; 11 | 12 | class TopoHalfEdge; 13 | 14 | class TopoGraph; 15 | 16 | class VoriGraphHalfEdge; 17 | 18 | extern VoriConfig *sConfig; 19 | 20 | 21 | /** 22 | * Saves distance values: distance along the path and hops in the graph and hops only over major vertices 23 | * 记录path的长度(distance)和其上的hope(段数) 24 | */ 25 | struct DistanceCalcHelper { 26 | DistanceCalcHelper() : distance( -1. ), hops( 0 ), majorHops( 0 ) {} 27 | 28 | double distance; 29 | unsigned int hops; 30 | unsigned int majorHops; // only those that not only have feature edges 31 | 32 | void clear(); 33 | }; 34 | 35 | 36 | /** 37 | * A vertex in the topology graph 38 | * 39 | */ 40 | class TopoVertex { 41 | public: 42 | TopoVertex() : distanceOfJoinedVertices( 0. ), isFeatureVertex( false ) {} 43 | 44 | 45 | void calculateAngles(); 46 | 47 | TopoExit *findDirectExitTo(TopoVertex *vertex); 48 | 49 | TopoExit *findExitTo(TopoVertex *vertex, bool *wasMajor = 0); 50 | 51 | std::list aVoriVertices; 52 | 53 | std::list aExits; 54 | double biggestExitAngleRad, smallestExitAngleRad; 55 | 56 | topo_geometry::point point; 57 | double distanceOfJoinedVertices; 58 | 59 | double averageDistanceToObstacles; 60 | 61 | DistanceCalcHelper distanceCalcHelper; 62 | // is true if there are exactly two non-feature adjacent vertices (== this vertex would vanish if the feature edges are removed) 63 | // the opposite is called major Vertex 64 | bool isFeatureVertex; 65 | 66 | // loops that this vertex is part of 67 | // the lower pointer exit has to be first 68 | // experimental for matching.... 69 | std::map, DistanceCalcHelper> loops; 70 | 71 | // for the similairty matching... 72 | bool inconsistent; 73 | 74 | bool isIsomorph; 75 | 76 | unsigned int id; 77 | 78 | friend class TopoGraph; 79 | }; 80 | 81 | /** 82 | * 83 | * A Half edge in the TopoGraph 84 | * 85 | * 86 | */ 87 | class TopoHalfEdge { 88 | public: 89 | TopoHalfEdge() : sourceExit( 0 ), targetExit( 0 ), sourceVertex( 0 ), targetVertex( 0 ), twin( 0 ), 90 | edgeFlags( 0 ) {} 91 | 92 | enum EdgeFlags { 93 | UNKNOWN = 0, 94 | DEAD_END = 0x01, // In this direction a dead end is reached (shorter distance than the rest of the graph) 95 | FEATURE_END = 0x02, // this dead end is even so small that it is just a feature 96 | OUTSIDE = 0x04, // In this direction a ray to the outside is reached 97 | DEAD_ENDISH = 0x08, // There is at least one DEAD_END in this direction 98 | OUTSIDEISH = 0x10, // There is at least one OUTSIDE end in this direction 99 | LOOP = 0x20, // In this direction at least one loop is present 100 | LOOP_BACK = 0x40 101 | }; // Going this direction there is a way to come back to this source (not using this twin!) 102 | 103 | TopoExit *sourceExit; 104 | TopoExit *targetExit; 105 | 106 | TopoVertex *sourceVertex; 107 | TopoVertex *targetVertex; 108 | 109 | TopoHalfEdge *twin; 110 | 111 | // the flas show what to expect if you follow this edge 112 | // so a dead end will have the dead_end flag on the edge that leads to the end vertex 113 | unsigned int edgeFlags; 114 | 115 | bool isRay() { return !(sourceVertex && targetVertex); } 116 | 117 | bool getPointForDistance(double distance, topo_geometry::point &); 118 | 119 | VoriGraphHalfEdge *getFirst() { return *voriHalfEdges.begin(); } 120 | 121 | std::list voriHalfEdges; 122 | double distance; 123 | 124 | }; 125 | 126 | /** 127 | * Handles one edge connected to a (source) vertex (leading from this vertex) 128 | * 129 | */ 130 | class TopoExit { 131 | public: 132 | 133 | TopoHalfEdge *exitEdge; // the edge whose source is topoVertex 134 | TopoHalfEdge *twinEdge() { return exitEdge->twin; } 135 | 136 | TopoVertex *source() { return exitEdge->sourceVertex; } 137 | 138 | TopoVertex *target() { return exitEdge->targetVertex; } 139 | 140 | TopoExit *nextTopoExit; 141 | double angleToNextTopoExitRad; // between 0. and 2 M_PI 142 | 143 | double vertexEdgeDistance; // The distance between the (possibly joined) vertex and the beginning of the actual edge 144 | double totalDistance; // The edge distance plus both vertexEdgeDistances 145 | 146 | double distance() { return totalDistance; } 147 | 148 | // already includes both vertexEdgeDistance 149 | double distanceToNextMajorVertex; 150 | TopoVertex *nextMajorVertex; 151 | 152 | std::map distances; 153 | }; 154 | 155 | 156 | class TopoGraph { 157 | public: 158 | TopoGraph(VoriGraph &pVoriGraph); 159 | 160 | // void paintPaths(QImage &image); 161 | // void paintNumbers(QImage &image); 162 | void printInfo(); 163 | 164 | void assignVertexIds(); 165 | 166 | // private: 167 | void createFromVoriGraph(); 168 | // void paintVoriEdge(QPainter &painter, VoriGraphHalfEdge *edge, bool isFeature); 169 | 170 | void markGraph(); 171 | 172 | void checkFirstVertexInList(std::map &workList); 173 | 174 | void removeDistanceMarks(); 175 | 176 | void setInconsistencyMarks(bool set); 177 | 178 | void calcAllDistances(); 179 | 180 | void calcDistancesFor(TopoExit *startExit); 181 | 182 | void addTargetToWorkList(TopoExit *currExit, std::set &workList, TopoVertex *startVertex); 183 | 184 | 185 | // lists of ALL exits, vertices and half edges in the topo graph... 186 | std::list aExits; 187 | std::list aVertices; 188 | std::list aHalfEdges; 189 | 190 | VoriGraph &aVoriGraph; // the graph all voriGraph pointers refer to 191 | }; 192 | 193 | 194 | #endif 195 | -------------------------------------------------------------------------------- /include/VoriConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef VORI_CONFIG_H 2 | #define VORI_CONFIG_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | struct VoriConfig{ 9 | 10 | 11 | double voronoiMinimumDistanceToObstacle(); 12 | 13 | double topoGraphDistanceToJoinVertices(); 14 | 15 | double topoGraphAngleCalcStartDistance(); 16 | double topoGraphAngleCalcEndDistance(); 17 | double topoGraphAngleCalcStepSize(); 18 | 19 | double topoGraphMarkAsFeatureEdgeLength(); 20 | 21 | double alphaShapeRemovalSquaredSize(); 22 | 23 | // for Vertices 24 | double simiVerNumberOfExitsOffset(); 25 | double simiVerNumberOfExitsMax(); 26 | 27 | double simiVerExitAngleRadOffset(); 28 | double simiVerExitAngleRadMax(); 29 | 30 | double simiVerDistanceToObstaclesOffset(); 31 | double simiVerDistanceToObstaclesMax(); 32 | 33 | double simiVerDistanceBetweenJoinedVerticesOffset(); 34 | double simiVerDistanceBetweenJoinedVerticesMax(); 35 | 36 | double simiExitVertexDistanceOffset(); 37 | double simiExitVertexDistanceMax(); 38 | 39 | double simiExitDistanceToObstaclesOffset(); 40 | double simiExitDistanceToObstaclesMax(); 41 | 42 | double simiConsistencyEdgeDistanceFactor(); 43 | double simiConsistencyEdgeDistanceMinAllowance(); 44 | 45 | double simiIsomorphismMinNumberOfVertices(); 46 | 47 | double simiNeighbourDistanceOffset(); 48 | double simiNeighbourDistanceFactor(); 49 | 50 | double simiNeighbourMaxHopDifference(); 51 | double simiNeighbourMaxMajorHopDifference(); 52 | 53 | double simiNeighbourMinProb(); 54 | double simiNeighbourGoodProb(); 55 | 56 | double firstDeadEndRemovalDistance(); 57 | double secondDeadEndRemovalDistance(); 58 | 59 | double thirdDeadEndRemovalDistance(); 60 | double fourthDeadEndRemovalDistance(); 61 | 62 | 63 | std::map doubleConfigVars; 64 | 65 | }; 66 | 67 | 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /include/VoriGraph.h: -------------------------------------------------------------------------------- 1 | #ifndef VORI_GRAPH_H 2 | #define VORI_GRAPH_H 3 | 4 | //#include "cgal/CgalVoronoi.h" 5 | #include "VoriConfig.h" 6 | 7 | #include "TopoGeometry.h" 8 | 9 | #include 10 | #include 11 | #define thresholdForCut 0.001 12 | #define EPSINON 0.00000001 13 | 14 | class VoriGraphVertex; 15 | 16 | class VoriGraphHalfEdge; 17 | 18 | 19 | 20 | /** 21 | * A polygon (jointed faces) in the vori graph 22 | * 23 | */ 24 | struct VoriGraphPolygon { 25 | VoriGraphPolygon() : isRay( false ) {} 26 | 27 | bool operator==(const VoriGraphPolygon &other) { 28 | return this == &other; 29 | } 30 | 31 | bool isRay; 32 | std::list belongpaths; 33 | // 各个face中的site => list of points (for the sites) 34 | std::list sites; 35 | VoriGraphPolygon *twin; 36 | std::list polygonpoints; //多边形端点 37 | 38 | }; 39 | 40 | /** 41 | * A half edge in the vori graph 42 | * 43 | */ 44 | struct VoriGraphHalfEdge { //path 45 | VoriGraphHalfEdge() : source( 0 ), target( 0 ), twin( 0 ), distance( 0 ), deadEnd( false ), groupId( 0 ), 46 | roomId( -1 ), obstacleAverage( 0. ), obstacleMinimum( 0. ), pathFace( NULL ), 47 | roomPath( false ) {} 48 | 49 | bool operator==(const VoriGraphHalfEdge &other) { 50 | return this == &other; 51 | } 52 | 53 | /// the list of path edges - those are simple coordinates forming the path from the voronoi diagram 54 | std::list pathEdges; 55 | 56 | VoriGraphVertex *source; 57 | VoriGraphVertex *target; 58 | VoriGraphPolygon *pathFace; 59 | VoriGraphHalfEdge *twin; // a pointer point to another VoriGraphHalfEdge 60 | 61 | std::list joinPolygon(VoriGraphHalfEdge *, VoriGraphHalfEdge *); 62 | 63 | /// The length along the path of this edge 64 | double distance; //length of this path 65 | /// if this is a ray the ray coordinates are saved in here 66 | topo_geometry::Halfedge topo_ray; 67 | 68 | /// true if this is a dead end 69 | bool deadEnd; 70 | /// a group id assigned to this vertex - after keepBiggestGroup only one group should exist 71 | unsigned int groupId; 72 | 73 | /// average distance to the obstacles along the path 74 | double obstacleAverage; 75 | /// minimum distance to an obstacle along the path 76 | double obstacleMinimum; 77 | 78 | // added from yutianyan 79 | int roomId; // a room id assigned to this halfedge : -1 means not in any room 80 | // set and get function of roomId 81 | void setRoomId(unsigned int i) { roomId = i; }; 82 | int getRoomId() { return roomId; }; 83 | bool roomPath; // artificial path from room border to center 84 | bool markRoomPath() { roomPath = true; }; 85 | bool isRoomPath() { return roomPath; }; 86 | 87 | /// returns if this a ray or not. 88 | bool isRay() const { return (bool) (source) ^ (bool) (target); } 89 | 90 | /// samples one point along the path in a certain distance. 91 | bool getPointForDistance(double distance, topo_geometry::point &); //获取路径上距离始节点特定距离的某个点的坐标(该点可能在某个Halfedge上) 92 | 93 | // added from yutianyan 94 | std::list cutVoriGraphHalfEdge_Polygon(double cutlength, VoriGraphVertex &, 95 | std::list &); 96 | std::list cutVoriGraphHalfEdge_Polygon_accruay(double cutlength, VoriGraphVertex &, 97 | std::list &); 98 | std::list cutVoriGraphHalfEdge(double cutlength, VoriGraphVertex &); 99 | //if size is 0, fail to cut. 100 | }; 101 | 102 | 103 | /** 104 | * A vertex in the voronoi graph 105 | * 106 | */ 107 | struct VoriGraphVertex { 108 | VoriGraphVertex() : groupId( 0 ), roomId( -1 ), obstacleDist( 0. ), roomVertex( false ), borderVertex( false ), 109 | roomCenter( false ),passageVertex(false) {} 110 | 111 | bool operator==(const VoriGraphVertex &other) { 112 | return this == &other; 113 | } 114 | 115 | /// the coordinate of this vertex 116 | topo_geometry::point point; //the position of this vertex 117 | 118 | std::list edgesConnected; // the VoriGraphHalfEdge list connected to this vertex 119 | unsigned int groupId; 120 | 121 | double obstacleDist; // distance to the closes obstacle 122 | // added from yutianyan 123 | //bool for room vertex(at the cut) 124 | bool roomVertex; 125 | // added from yutianyan 126 | //bool for border (deadend and the cut) 127 | bool borderVertex; 128 | // added from yutianyan 129 | //bool for room center 130 | bool roomCenter; 131 | // added from yutianyan 132 | // a room id assigned to this vertex - -1 means not in any polygons 133 | int roomId; 134 | //added by jiawei: label the passage vertex 135 | bool passageVertex; 136 | 137 | // added from yutianyan 138 | //set and get function of roomId 139 | void setRoomId(unsigned int i) { roomId = i; }; 140 | // added from yutianyan 141 | int getRoomId() { return roomId; }; 142 | 143 | bool removeHalfEdge(VoriGraphHalfEdge *edge); //remove a VoriGraphHalfEdge from the list edgesConnected 144 | void markTwins(); //find the twin for each VoriGraphHalfEdge 145 | // added from yutianyan 146 | //mark room vertex (at the cut) 147 | void markRoomVertex() { 148 | roomVertex = true; 149 | borderVertex = true; 150 | }; 151 | // added from yutianyan 152 | //mark border vertex (at the cut and dead end within a room) 153 | void markBorderVertex() { borderVertex = true; }; 154 | // added from yutianyan 155 | //mark room center 156 | void markRoomCenter() { roomCenter = true; }; 157 | // added from yutianyan 158 | bool isRoomVertex() { return roomVertex; }; 159 | // added from yutianyan 160 | bool isBorderVertex() { return borderVertex; }; 161 | // added from yutianyan 162 | bool isRoomCenter() { return roomCenter; }; 163 | // added from yutianyan 164 | bool isPassageVertex() { return passageVertex; }; 165 | }; 166 | 167 | /** 168 | * A group of connected elements (vertices and edges) in the graph 169 | */ 170 | 171 | 172 | 173 | struct VoriGroup { 174 | /// pointer to some edge in the group 175 | VoriGraphHalfEdge *edge; 176 | /// the id of this group 177 | unsigned int groupId; 178 | /// the total sum of distances (length) of the paths of the edges in this group 179 | double distance; 180 | }; 181 | //add by jiawei 2017.10.31 182 | struct VoriGraphArea { 183 | VoriGraphArea() : roomId( -1 ){} 184 | bool operator==(const VoriGraphArea &other) { 185 | return this == &other; 186 | } 187 | 188 | int roomId; 189 | std::map connecttedAreas; 190 | std::map includedPolygons; 191 | std::list polygonPoints; 192 | }; 193 | 194 | /** 195 | * A vori graph is the first, basic, topological structure (generated from a voronoi diagram) 196 | * 197 | */ 198 | struct VoriGraph { 199 | 200 | typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 201 | typedef CGAL::Point_2 Point; 202 | typedef CGAL::Polygon_2 Polygon_2; 203 | VoriGraph() {}; 204 | 205 | typedef std::map VertexMap; //按照节点位置排序(x小在前,y小在前),由节点坐标索引VoriGraphVertex 206 | VertexMap vertices; //包含所有节点的哈希表 207 | std::list halfEdges; 208 | std::list pathFaces; 209 | std::list groups; 210 | std::list areas; 211 | 212 | 213 | std::list::iterator removeHalfEdge(std::list::iterator &remove); 214 | 215 | // added from yutianyan 216 | std::list::iterator removeHalfEdge_tianyan(std::list::iterator &remove, 217 | bool deleteEmpty = true, bool deleteRoomBorder = true); 218 | //从VoriGraphHalfEdge列表里删掉 remove这条 VoriGraphHalfEdge 219 | std::list::iterator removeHalfEdge_jiawei(std::list::iterator &remove); 220 | 221 | std::list::iterator removeHalfEdge_roomPolygon(std::list::iterator &remove, 222 | bool deleteEmpty = true, bool deleteRoomBorder = true); 223 | void removeHalfEdge_roomPolygon(VoriGraphHalfEdge *remove, bool deleteEmpty = true, bool deleteRoomBorder = true); 224 | void joinHalfEdges(); 225 | void joinHalfEdges_jiawei(); 226 | void joinHalfEdges_tianyan(); 227 | 228 | void joinHalfEdges(VoriGraphHalfEdge *, VoriGraphHalfEdge *); 229 | void joinHalfEdges_jiawei(VoriGraphHalfEdge *, VoriGraphHalfEdge *, bool = false); //把pFirst和pSecond两条路径连接起来 230 | //add from yutianyan 231 | void joinHalfEdges_tianyan(VoriGraphHalfEdge *, VoriGraphHalfEdge *, bool = false);// added from yutianyan 232 | 233 | void markDeadEnds_isRoomVertex(); 234 | void markDeadEnds(); 235 | 236 | // added from yutianyan 237 | bool cutHalfEdgeAtDistance_Polygon(double cutlength, VoriGraphHalfEdge *pHalfEdge, VoriGraphVertex &pPoint, unsigned int = 0); 238 | bool cutHalfEdgeAtDistance_Polygonbk(double cutlength, VoriGraphHalfEdge *pHalfEdge, VoriGraphVertex &pPoint, unsigned int = 0); 239 | bool cutHalfEdgeAtDistance(double cutlength, VoriGraphHalfEdge *pHalfEdge, VoriGraphVertex &pPoint, unsigned int = 0); 240 | }; 241 | 242 | 243 | void coutpoint(topo_geometry::point p); 244 | 245 | void printGraphStatistics(VoriGraph &voriGraph, std::string= ""); 246 | 247 | 248 | void gernerateGroupId(VoriGraph &voriGraph); 249 | 250 | void removeGroupId(VoriGraph &voriGraph); 251 | 252 | void keepBiggestGroup(VoriGraph &voriGraph); 253 | 254 | 255 | void removeRays(VoriGraph &voriGraph); 256 | 257 | 258 | void removeDeadEnds_addFacetoPolygon(VoriGraph &voriGraph, double maxDist); 259 | 260 | void removeDeadEnds(VoriGraph &voriGraph, double maxDist); 261 | 262 | /// for debugging... 263 | void checkConnectedEdgesForError(VoriGraph &voriGraph); 264 | 265 | VoriGraphHalfEdge * 266 | pathToEdge(VoriGraph &voriGraph, double x, double y, double &Pmindist, topo_geometry::point &closestP); 267 | 268 | #endif 269 | -------------------------------------------------------------------------------- /include/cgal/AlphaShape.h: -------------------------------------------------------------------------------- 1 | #ifndef ALPHA_SHAPE_MAPTOOL_H 2 | #define ALPHA_SHAPE_MAPTOOL_H 3 | 4 | #include 5 | 6 | 7 | #include 8 | 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | 25 | class QImage; 26 | 27 | 28 | class AlphaShapePolygon{ 29 | public: 30 | 31 | typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 32 | 33 | typedef CGAL::Alpha_shape_vertex_base_2 Avb; 34 | typedef CGAL::Triangulation_hierarchy_vertex_base_2 Av; 35 | 36 | typedef CGAL::Triangulation_face_base_2 Tf; 37 | typedef CGAL::Alpha_shape_face_base_2 Af; 38 | 39 | typedef CGAL::Triangulation_default_data_structure_2 Tds; 40 | typedef CGAL::Delaunay_triangulation_2 Dt; 41 | typedef CGAL::Triangulation_hierarchy_2
Ht; 42 | typedef CGAL::Alpha_shape_2 Alpha_shape_2; 43 | 44 | typedef Alpha_shape_2::Alpha_shape_edges_iterator Edge_iterator; 45 | 46 | typedef CGAL::Polygon_2 Polygon_2; 47 | typedef CGAL::Point_2 Point; 48 | typedef Polygon_2::Vertex_iterator VertexIterator; 49 | typedef Polygon_2::Edge_const_iterator EdgeIterator; 50 | typedef K::Segment_2 Segment; 51 | 52 | 53 | class SegmentSearchy{ 54 | public: 55 | SegmentSearchy(std::list > &pSegments); 56 | 57 | typedef std::list >::iterator CellEntry; 58 | typedef std::list CellEntries; 59 | CellEntries findSegments(AlphaShapePolygon::K::Point_2 &p); 60 | protected: 61 | void fill(); 62 | 63 | std::list > & aSegments; 64 | std::map > segmentSourceMap; 65 | }; 66 | 67 | Polygon_2 *performAlpha(QImage &pImg, double squared_size_is_alpha, bool deleteSmallPolygon = true); 68 | Polygon_2 *performAlpha_biggestArea(QImage &pImg, double squared_size_is_alpha, bool deleteSmallPolygon = true); 69 | 70 | void getPoints(QImage &pImg, std::vector &points); 71 | 72 | void generatePolygons(std::vector &points, double squared_size_is_alpha, std::list &polygons); 73 | void generateBBoxesForPolygons(std::list &polygons, std::list &bboxes); 74 | 75 | static bool isOutside(const K::Point_2 &p, Polygon_2 &poly, CGAL::Bbox_2 &box); 76 | 77 | static double calculatePolygonLength(Polygon_2 &polygon); 78 | 79 | //add 80 | Polygon_2 & getPolygon(unsigned int i); 81 | 82 | unsigned int sizeOfPolygons(); 83 | 84 | void drawPolygonByIndex(QImage &pImg, unsigned int index); 85 | 86 | void drawPolygon(QImage &pImg, Polygon_2 * poly); 87 | 88 | protected: 89 | std::list polygons; 90 | 91 | // void growPolygon(std::list &segments, Polygon_2 &polygon, K::Point_2 front, K::Point_2 back); 92 | void growPolygon(SegmentSearchy &searchy, Polygon_2 &polygon, K::Point_2 front, K::Point_2 back); 93 | }; 94 | 95 | #endif 96 | 97 | -------------------------------------------------------------------------------- /include/cgal/AlphaShapeRemoval.h: -------------------------------------------------------------------------------- 1 | #ifndef ALPHA_SHAPE_REMOVAL_H 2 | #define ALPHA_SHAPE_REMOVAL_H 3 | 4 | #define MAX_PLEN_REMOVAL 80 //380 for f101 5 | class QImage; 6 | // class AlphaShapeRemoval: public AlphaShapePolygon{ 7 | void performAlphaRemoval(QImage &pImg, double pAlphaShapeSquaredDist, double pMaxPolygonLength); 8 | // }; 9 | #endif 10 | -------------------------------------------------------------------------------- /include/cgal/CgalVoronoi.h: -------------------------------------------------------------------------------- 1 | #ifndef _CGAL_VORONOI_H 2 | #define _CGAL_VORONOI_H 3 | 4 | 5 | 6 | #include 7 | 8 | 9 | 10 | #include 11 | 12 | // includes for defining the Voronoi diagram adaptor 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace CgalVoronoi{ 20 | 21 | // typedefs for defining the adaptor 22 | typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 23 | typedef CGAL::Delaunay_triangulation_2 DT; 24 | typedef CGAL::Delaunay_triangulation_adaptation_traits_2
AT; 25 | typedef CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2
AP; 26 | typedef CGAL::Voronoi_diagram_2 VD; 27 | 28 | // typedef for the result type of the point location 29 | typedef AT::Site_2 Site_2; 30 | typedef AT::Point_2 Point_2; 31 | 32 | typedef VD::Locate_result Locate_result; 33 | typedef VD::Vertex_handle Vertex_handle; 34 | typedef VD::Face_handle Face_handle; 35 | typedef VD::Halfedge_handle Halfedge_handle; 36 | typedef VD::Ccb_halfedge_circulator Ccb_halfedge_circulator; 37 | 38 | } 39 | 40 | #include "VoriGraph.h" 41 | 42 | /// create a vori graph using a number of occupied points 43 | bool createVoriGraph(const std::vector &sites, VoriGraph &voriGraph, VoriConfig *sConfig); 44 | 45 | 46 | /// remove all vertices and edges outsite a given polygon. Edges cut by the polygon are turned into rays. Typically used with a polygon generated by an alpha shape algorithm. 47 | void removeOutsidePolygon(VoriGraph &voriGraph, CGAL::Polygon_2 &polygon); 48 | 49 | void paintVoronoi(QImage &image, CgalVoronoi::VD & vd); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/passageSearch.h: -------------------------------------------------------------------------------- 1 | /*passageSearch: 2 | * 3 | * Author: Yijun Yuan 4 | * date: Jan.21.2018 5 | * 6 | * Here the passageSearch will attempt to build passage to passage graph 7 | * on top of previous roomGraph. 8 | */ 9 | 10 | #ifndef PASSAGESEARCH_H__ 11 | #define PASSAGESEARCH_h__ 12 | 13 | #include "VoriGraph.h" 14 | #include "TopoGeometry.h" 15 | 16 | namespace PS{ 17 | //1. struct PPEdge(passage1, passage2, cost, path) 18 | struct Vertex{ 19 | Vertex(VoriGraphVertex* VoriVptr, double h, double g):VoriVptr(VoriVptr),h(h){this->g=1000000;this->f=0;}; 20 | VoriGraphVertex* VoriVptr; 21 | double h; 22 | double g; 23 | double f; 24 | }; 25 | //2. general unit to form a flexible graph 26 | class PPEdge{ 27 | public: 28 | VoriGraphVertex* psg1;//from psg1 to psg2 29 | VoriGraphVertex* psg2; 30 | double cost; 31 | std::list* path; 32 | public: 33 | PPEdge(VoriGraphVertex* psg1, VoriGraphVertex* psg2, double cost, std::list* path); 34 | }; 35 | 36 | 37 | 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /include/qt/QImageVoronoi.h: -------------------------------------------------------------------------------- 1 | #ifndef QIMAGE_VORONOI_H 2 | #define QIMAGE_VORONOI_H 3 | 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | //#include "TopoGeometry.h" 12 | #include "TopoGraph.h" 13 | 14 | 15 | 16 | enum TripleValue{OCCUPIED=0, UNKNOWN=127, FREE=255}; 17 | 18 | void analyseImage(QImage &pImg, bool &pIsTriple); 19 | 20 | bool getSites(QImage &pImg, std::vector &sites); 21 | 22 | void paintVori(QImage &image, VoriGraph &voriGraph); 23 | void paintVori_Area(QImage &image, VoriGraph &voriGraph); 24 | void paintVori_vertex(QImage &image, VoriGraph &voriGraph); 25 | void paintVori_AreaRoom(QImage &image, VoriGraph &voriGraph); 26 | 27 | void qRGB2Gray(QImage &image); 28 | void paintVori_onlyArea(QImage &image, VoriGraph &voriGraph); 29 | void paintVori_randomcolor(QImage &image, VoriGraph &voriGraph); 30 | 31 | void paintVori_pathFace(QImage &image, VoriGraph &voriGraph); 32 | void paintVori_pathFace_withsites(QImage &image, VoriGraph &voriGraph); 33 | 34 | 35 | void paintTopoPaths(TopoGraph &graph, QImage &image); 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/roomGraph.h: -------------------------------------------------------------------------------- 1 | /*roomGraph: 2 | * 3 | * Author: Yijun Yuan 4 | * date: Nov.2.2017 5 | * 6 | * The main task of this roomGraph is to build a line graph 7 | * and then merge those edges with same roomId into one 8 | * roomVertex 9 | */ 10 | 11 | #ifndef ROOMGRAPH_H__ 12 | #define ROOMGRAPH_H__ 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include "VoriGraph.h" 25 | #include "TopoGeometry.h" 26 | #include "passageSearch.h" 27 | 28 | 29 | #include "CGAL/Polygon_2.h" 30 | #include "cgal/CgalVoronoi.h" 31 | 32 | 33 | namespace RMG{ 34 | class roomVertex; 35 | class passageEdge; 36 | 37 | class AreaGraph { 38 | public: 39 | //TODO: try to change originSet from vector to list, because we need to delete roomVertex in mergeRoomCell 40 | std::vector originSet;//here we use vector not set because it only insert while new a node. 41 | // std::vector graph; 42 | 43 | std::set passageV_set; 44 | // std::vector passageEList; //mainly used in buildAreaGraph_bk() 45 | std::list passageEList; 46 | public: 47 | // roomGraph(VoriGraph &voriGraph); //by Yijun 48 | void mergeRoomCell(); 49 | void prunning(); 50 | void arrangeRoomId(); 51 | void show(); 52 | void draw(QImage& image); 53 | void mergeRoomPolygons(); 54 | 55 | //Jiawei: For using passages as edges 56 | AreaGraph(VoriGraph &voriGraph); 57 | void buildAreaGraph(VoriGraph &voriGraph); 58 | void mergeAreas(); 59 | public: 60 | /* 61 | * created at 1/22/2018 for passage based search 62 | */ 63 | //0. generate_areaInnerPPGraph for each roomVertex 64 | // void roomV_generate_areaInnerPPGraph(VoriGraph &voriGraph); 65 | 66 | //1. for a random point provide the path in its room 67 | 68 | //2. integrate the whole graph by collect all the PPEdges 69 | 70 | //3. visualize 71 | //4. visualize the high level graph 72 | }; 73 | 74 | class roomVertex{ 75 | public: 76 | int roomId; 77 | topo_geometry::point center; 78 | topo_geometry::point st;//edge start (only used at roomGraph init, because at very beginning, each roomVertex is a half edge 79 | topo_geometry::point ed;//edge end (only used at roomGraph init 80 | std::vector polygons; 81 | std::set neighbours; 82 | 83 | roomVertex* parentV;//if not null, it is a sub-cell 84 | 85 | std::vector passages; 86 | public: 87 | roomVertex(int roomId, topo_geometry::point loc, topo_geometry::point st, topo_geometry::point ed); 88 | 89 | //merge polygon 90 | std::list polygon; 91 | void mergePolygons(); 92 | 93 | 94 | public: 95 | /* 96 | * created at 1/21/2018 for passage based search 97 | */ 98 | //local passage stuff 99 | std::list areaInnerPathes;//record the path () 100 | std::list areaInnerPPGraph;//the vertex to vertex graph in this room 101 | std::list areaInnerP2PGraph;//the passage to passage graph 102 | std::set voriV_set; 103 | //transform from areaInnerPathes to areaInnerPPGraph 104 | void init_areaInnerPPGraph(); 105 | //from areaInnerPPGraph to areaInnerP2PGraph(Passage to Passage graph) 106 | 107 | }; 108 | 109 | class passageLine{ 110 | public: 111 | std::list cwline; //line in clockwise 112 | std::list ccwline; //line in counterclockwise 113 | double length; 114 | 115 | public: 116 | double get_len(){ 117 | std::list::iterator last_pit=cwline.begin(); 118 | std::list::iterator pit=last_pit; 119 | double len=0; 120 | for(pit++;pit!=cwline.end();pit++){ 121 | len+=boost::geometry::distance(*last_pit,*pit); 122 | last_pit=pit; 123 | } 124 | length=len; 125 | return len; 126 | } 127 | }; 128 | class passageEdge{ 129 | public: 130 | topo_geometry::point position; 131 | std::vector connectedAreas; 132 | bool junction; 133 | passageLine line; 134 | 135 | passageEdge(topo_geometry::point p, bool j):position(p), junction(j){}; 136 | }; 137 | 138 | 139 | void connectRoomVertexes(std::vector &originSet); 140 | 141 | } 142 | #endif 143 | -------------------------------------------------------------------------------- /src/AreaGenerate.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by houjiawei on 18-1-24. 3 | // 4 | 5 | // #include 6 | #include "AreaGenerate.h" 7 | 8 | #define occupied_thresh 0.75 9 | #define neighbors 8 10 | #define percentage 0 11 | 12 | void generateAreas(const char *input_name, const char *output_name, VoriConfig *sConfig, VoriGraph &voriGraph) { 13 | 14 | int black_threshold; 15 | black_threshold = round(255 * occupied_thresh); 16 | bool de = DenoiseImg(input_name, "clean.png", black_threshold, neighbors, percentage); 17 | if (de) 18 | cout << "Denoise run successed!!" << endl; 19 | 20 | QImage test; 21 | test.load("clean.png"); 22 | bool isTriple; 23 | analyseImage(test, isTriple); 24 | cout << " is triple?: " << isTriple << endl; 25 | 26 | 27 | std::vector sites; 28 | bool ret = getSites(test, sites); 29 | 30 | // create the voronoi graph and vori graph 31 | ret = createVoriGraph(sites, voriGraph, sConfig); 32 | // printGraphStatistics(voriGraph); 33 | 34 | QImage alpha = test; 35 | AlphaShapePolygon alphaSP; 36 | AlphaShapePolygon::Polygon_2 *poly = alphaSP.performAlpha(alpha, sConfig->alphaShapeRemovalSquaredSize(), false); 37 | 38 | cout << "size of Polygons: " << alphaSP.sizeOfPolygons() << endl; 39 | if (poly) { 40 | cout << "Removing vertices outside of polygon" << endl; 41 | removeOutsidePolygon(voriGraph, *poly); //Remove vertices outside of polygon 42 | // paintVori(alpha, voriGraph); 43 | } 44 | voriGraph.joinHalfEdges_jiawei(); 45 | // alpha.save("alpha.png"); 46 | 47 | std::list::iterator> zeroHalfEdge; 48 | 49 | for (std::list::iterator pathEdgeItr = voriGraph.halfEdges.begin(); 50 | pathEdgeItr != voriGraph.halfEdges.end(); pathEdgeItr++) { 51 | if (pathEdgeItr->distance <= EPSINON) { 52 | zeroHalfEdge.push_back(pathEdgeItr); 53 | } 54 | } 55 | for (std::list::iterator>::iterator zeroHalfEdgeItr = zeroHalfEdge.begin(); 56 | zeroHalfEdgeItr != zeroHalfEdge.end(); zeroHalfEdgeItr++) { 57 | voriGraph.removeHalfEdge_jiawei(*zeroHalfEdgeItr); 58 | } 59 | 60 | if (sConfig->firstDeadEndRemovalDistance() > 0.) { 61 | voriGraph.markDeadEnds(); 62 | removeDeadEnds_addFacetoPolygon(voriGraph, sConfig->firstDeadEndRemovalDistance()); 63 | voriGraph.joinHalfEdges_jiawei(); 64 | // printGraphStatistics(voriGraph, "First dead ends"); 65 | } 66 | // QImage filter = test; 67 | // paintVori_Area(filter, voriGraph); 68 | // filter.save("filter.png"); 69 | 70 | if (sConfig->secondDeadEndRemovalDistance() > 0.) { 71 | voriGraph.markDeadEnds(); 72 | removeDeadEnds_addFacetoPolygon(voriGraph, sConfig->secondDeadEndRemovalDistance()); 73 | voriGraph.joinHalfEdges_jiawei(); 74 | } 75 | // QImage filter2 = test; 76 | // paintVori_Area(filter2, voriGraph); 77 | // filter.save("filter2.png"); 78 | 79 | gernerateGroupId(voriGraph); 80 | keepBiggestGroup(voriGraph); 81 | 82 | removeRays(voriGraph); 83 | voriGraph.joinHalfEdges_jiawei(); 84 | 85 | if (sConfig->thirdDeadEndRemovalDistance() > 0.) { 86 | voriGraph.markDeadEnds(); 87 | removeDeadEnds_addFacetoPolygon(voriGraph, sConfig->thirdDeadEndRemovalDistance()); 88 | voriGraph.joinHalfEdges_jiawei(); 89 | } 90 | if (sConfig->fourthDeadEndRemovalDistance() > 0.) { 91 | voriGraph.markDeadEnds(); 92 | removeDeadEnds_addFacetoPolygon(voriGraph, sConfig->fourthDeadEndRemovalDistance()); 93 | voriGraph.joinHalfEdges_jiawei(); 94 | } 95 | 96 | // QImage lastVori = test; 97 | // paintVori_Area(lastVori, voriGraph); 98 | // lastVori.save("lastVori.png"); 99 | 100 | 101 | RoomDect roomtest; 102 | roomtest.forRoomDect(alphaSP, voriGraph, poly); 103 | 104 | // QImage after = test; 105 | // paintVori_pathFace(after, voriGraph); 106 | // after.save("after.png"); 107 | 108 | QImage dectRoom = test; 109 | paintVori_AreaRoom(dectRoom, voriGraph); 110 | dectRoom.save(output_name); 111 | 112 | std::cout << "end generateAreas..." << std::endl; 113 | } 114 | 115 | 116 | void generateRMG(RMG::AreaGraph &RMGraph) { 117 | std::cout << "enter generateRMG" << std::endl; 118 | 119 | RMGraph.mergeAreas(); 120 | RMGraph.arrangeRoomId(); 121 | // RMGraph.show(); 122 | 123 | RMGraph.mergeRoomPolygons(); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /src/Denoise.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by houjiawei on 18-1-23. 3 | // 4 | 5 | #include "Denoise.h" 6 | 7 | QImage paintPoints(const char *file_name, const vector &points, int width, int height) { 8 | 9 | QImage img(width, height, QImage::Format_RGB888); 10 | img.fill(QColor(255, 255, 255)); 11 | for (vector::const_iterator itr = points.begin(); itr != points.end(); ++itr) { 12 | img.setPixel(itr->x(), itr->y(), 0); 13 | } 14 | img.save(QString::fromStdString(file_name)); 15 | return img; 16 | } 17 | 18 | bool isBlack(uchar *pixel, int black_threshold) { 19 | return *pixel + *(pixel + 1) + *(pixel + 2) <= black_threshold; 20 | } 21 | 22 | int pixel_value(uchar* pixel){ 23 | return *pixel + *(pixel+1) + *(pixel+2); 24 | } 25 | 26 | void getPoints_bk(QImage &img, int &black_threshold, vector &points) { 27 | for (unsigned int y = 0; y < img.height(); y++) { 28 | uchar *pointer = img.scanLine(y); 29 | uchar *endP = pointer + img.width() * 3; 30 | for (unsigned int x = 0; pointer < endP; pointer += 3, x++) { 31 | if (isBlack(pointer, black_threshold)) { 32 | points.push_back(Point(x, y, 0.)); 33 | } 34 | } 35 | } 36 | } 37 | void getPoints(QImage &img, int &black_threshold, vector &points) { 38 | unsigned int iy=9; 39 | uchar* pointer = img.scanLine(iy); 40 | unsigned int ix=9*3; 41 | pointer+=ix; 42 | black_threshold=pixel_value(pointer)-1; 43 | cout<<"black_threshold = "<0.3*img.height()*img.width()){ 57 | black_threshold=black_ave/(points.size()+1); 58 | points.clear(); 59 | for (unsigned int y = 0; y < img.height(); y++) { 60 | uchar *pointer = img.scanLine(y); 61 | uchar *endP = pointer + img.width() * 3; 62 | for (unsigned int x = 0; pointer < endP; pointer += 3, x++) { 63 | int tem_v=pixel_value(pointer); 64 | if (tem_v<= black_threshold) { 65 | points.push_back(Point(x, y, 0.)); 66 | } 67 | } 68 | } 69 | } 70 | } 71 | 72 | void usage() { 73 | cout << "Denoises a map by removing a percentage of black pixels " << endl; 74 | } 75 | 76 | 77 | bool 78 | DenoiseImg(const char *input_name, const char *output_name, int &black_threshold, int neighbors, double percentage) { 79 | QImage img; 80 | img.load(input_name); 81 | if (img.isNull()) { 82 | cerr << "Error loading image " << input_name << endl; 83 | return false; 84 | } 85 | black_threshold *= 3; 86 | QImage rgb = img.convertToFormat(QImage::Format_RGB888); 87 | if (rgb.isNull()) { 88 | cerr << "Error convertig image to RGB" << endl; 89 | return false; 90 | } 91 | 92 | vector points; 93 | getPoints(rgb, black_threshold, points); 94 | 95 | // Removes outliers using erase-remove idiom. 96 | // The Dereference_property_map property map can be omitted here as it is the default value. 97 | int sec_percent=percentage>=1?1:0; 98 | 99 | // We have to use Identity_property_map for CGAL 4.7 (ubuntu 16) 100 | #if CGAL_VERSION_NR > 1040201000 101 | points.erase(CGAL::remove_outliers(points.begin(), points.end(), 102 | CGAL::Identity_property_map(), 103 | neighbors, percentage), 104 | points.end()); 105 | points.erase(CGAL::remove_outliers(points.begin(), points.end(), 106 | CGAL::Identity_property_map(), 107 | neighbors, sec_percent), 108 | points.end()); 109 | #else 110 | points.erase(CGAL::remove_outliers(points.begin(), points.end(), 111 | CGAL::Dereference_property_map(), 112 | neighbors, percentage), 113 | points.end()); 114 | points.erase(CGAL::remove_outliers(points.begin(), points.end(), 115 | CGAL::Dereference_property_map(), 116 | neighbors, sec_percent), 117 | points.end()); 118 | #endif 119 | // points.erase(CGAL::remove_outliers(points.begin(), points.end(), 120 | // CGAL::Dereference_property_map(), 121 | // neighbors, percentage), 122 | // points.end()); 123 | 124 | // Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity 125 | std::vector(points).swap(points); 126 | 127 | paintPoints(output_name, points, rgb.width(), rgb.height()); 128 | return true; 129 | } -------------------------------------------------------------------------------- /src/TopoGraph.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "TopoGraph.h" 3 | 4 | // #include "VoronoiPlugin.h" 5 | 6 | // #include 7 | 8 | using namespace std; 9 | 10 | 11 | TopoGraph::TopoGraph(VoriGraph &pVoriGraph) : aVoriGraph(pVoriGraph) { 12 | } 13 | 14 | 15 | void findCloseVertices(VoriGraphVertex *start, map &add) { 16 | // if this is an end point of a dead end we are not interested in joining... 17 | if (start->edgesConnected.size() < 3) return; 18 | std::list::iterator itrConnectedEdges; 19 | for (itrConnectedEdges = start->edgesConnected.begin(); 20 | itrConnectedEdges != start->edgesConnected.end(); ++itrConnectedEdges) { 21 | cout.flush(); 22 | if ((*itrConnectedEdges)->isRay()) continue; 23 | // we are only interested in those edges which have this vertex as source... (e.g. ignore the twins) 24 | if ((*itrConnectedEdges)->source != start) continue; 25 | // cout<<&(*itrConnectedEdges)<<" dist: "<<(*itrConnectedEdges)->distance<<" twin dist "<<(*itrConnectedEdges)->twin->distance<distance <= sConfig->topoGraphDistanceToJoinVertices()) { 27 | //first check if the vertex has already been taken care of (should not happen!?) 28 | if ((*itrConnectedEdges)->target->groupId != 0) { 29 | cout << "Vertex to be joined but already taken care of :( " << (*itrConnectedEdges)->target; 30 | continue; 31 | } 32 | // ok we found a short one - first check if this one is already in the list! 33 | map::iterator found = add.find((*itrConnectedEdges)->target); 34 | if (found == add.end()) { 35 | // if this is an end point of a dead end we are not interested in joining... 36 | if ((*itrConnectedEdges)->target->edgesConnected.size() < 3) continue; 37 | 38 | //this is a new one - mark to be joined! 39 | add[(*itrConnectedEdges)->target] = (*itrConnectedEdges)->distance; 40 | // also mark the joined away edges... 41 | (*itrConnectedEdges)->groupId = 1; 42 | (*itrConnectedEdges)->twin->groupId = 1; 43 | // and recursively also check this one 44 | findCloseVertices((*itrConnectedEdges)->target, add); 45 | } 46 | } 47 | } 48 | 49 | } 50 | 51 | void TopoGraph::createFromVoriGraph() { 52 | aExits.clear(); 53 | aVertices.clear(); 54 | aHalfEdges.clear(); 55 | 56 | // groupId 1 will be set for all entries which has been taken care of 57 | removeGroupId(aVoriGraph); //遍历voriGraph.halfEdges和voriGraph.vertices把它们的groupId置为0 58 | 59 | // create a translation entry from voriVertices to TopoVertices 60 | map mapVoriTopoVertex; 61 | 62 | VoriGraph::VertexMap::iterator itrVertices; 63 | for (itrVertices = aVoriGraph.vertices.begin(); itrVertices != aVoriGraph.vertices.end(); ++itrVertices) { 64 | cout.flush(); 65 | // check if this vertex was already taken care of (due to joining) 66 | if (itrVertices->second.groupId != 0) { 67 | continue; 68 | } 69 | // the second double is the distance of said vertice 70 | map verticesToJoin; 71 | // add this one of course: 72 | verticesToJoin[&itrVertices->second] = 0.; 73 | // first check the distances 74 | findCloseVertices(&itrVertices->second, verticesToJoin); 75 | // now we know which VoriGraph vertices to used to create the TopoVertex - do it (most often its just one vertex) 76 | 77 | //add the vertex 78 | { 79 | TopoVertex newVertex; 80 | aVertices.push_back(newVertex); 81 | } 82 | TopoVertex &vertex = *aVertices.rbegin(); 83 | 84 | vertex.averageDistanceToObstacles = 0.; 85 | double averageX = 0.; 86 | double averageY = 0.; 87 | vertex.distanceOfJoinedVertices = 0.; 88 | map::iterator itrToJoin; 89 | for (itrToJoin = verticesToJoin.begin(); itrToJoin != verticesToJoin.end(); ++itrToJoin) { 90 | vertex.averageDistanceToObstacles += itrToJoin->first->obstacleDist; 91 | averageX += topo_geometry::getX(itrToJoin->first->point); 92 | // averageY += itrToJoin->first->vertex->point().y(); 93 | averageY += topo_geometry::getY(itrToJoin->first->point); 94 | vertex.aVoriVertices.push_back(itrToJoin->first); 95 | vertex.distanceOfJoinedVertices += itrToJoin->second; 96 | // mark as already taken care of 97 | itrToJoin->first->groupId = 1; 98 | mapVoriTopoVertex[itrToJoin->first] = &vertex; 99 | } 100 | vertex.averageDistanceToObstacles /= verticesToJoin.size(); 101 | averageX /= verticesToJoin.size(); 102 | averageY /= verticesToJoin.size(); 103 | vertex.point = topo_geometry::point(averageX, averageY); 104 | } 105 | 106 | // now we have all the vertices - next create the HalfEdges 107 | 108 | list::iterator itrHalfEdges; 109 | for (itrHalfEdges = aVoriGraph.halfEdges.begin(); itrHalfEdges != aVoriGraph.halfEdges.end(); ++itrHalfEdges) { 110 | // if this edge was joined away ignore it... 111 | if (itrHalfEdges->groupId != 0) continue; 112 | aHalfEdges.push_back(TopoHalfEdge()); 113 | TopoHalfEdge &edge = *aHalfEdges.rbegin(); 114 | if (itrHalfEdges->source) edge.sourceVertex = mapVoriTopoVertex[itrHalfEdges->source]; 115 | if (itrHalfEdges->target) edge.targetVertex = mapVoriTopoVertex[itrHalfEdges->target]; 116 | // for now there is only one half edge... 117 | edge.distance = itrHalfEdges->distance; 118 | edge.voriHalfEdges.push_back(&*itrHalfEdges); 119 | } 120 | 121 | // now create the exits (could theoretically be done in the above step - but this way it is cleaner) 122 | list::iterator itrTopoHalfEdges; 123 | for (itrTopoHalfEdges = aHalfEdges.begin(); itrTopoHalfEdges != aHalfEdges.end(); ++itrTopoHalfEdges) { 124 | // take care of rays ;) 125 | if (itrTopoHalfEdges->sourceVertex == 0) continue; 126 | aExits.push_back(TopoExit()); 127 | TopoExit &exit = *aExits.rbegin(); 128 | exit.exitEdge = &*itrTopoHalfEdges; 129 | itrTopoHalfEdges->sourceVertex->aExits.push_back(&exit); 130 | // calculate the distance... 131 | //TODO: get the distance boost::geometry::distance 132 | // exit.vertexEdgeDistance = sqrt(squared_distance( exit.exitEdge->getFirst()->source->vertex->point(), exit.source()->point )); 133 | exit.vertexEdgeDistance = boost::geometry::distance(exit.exitEdge->getFirst()->source->point, 134 | exit.source()->point); 135 | 136 | } 137 | // now that all exits have proper vertex distances we can calculate the new edge distances (with vertex distances on both ends!) 138 | for (list::iterator itrExits = aExits.begin(); itrExits != aExits.end(); ++itrExits) { 139 | itrExits->totalDistance = itrExits->vertexEdgeDistance + itrExits->exitEdge->distance; 140 | if (itrExits->exitEdge->sourceExit) itrExits->totalDistance += itrExits->exitEdge->sourceExit->vertexEdgeDistance; 141 | } 142 | 143 | 144 | // now that all exits are there we can create the twin entries in the halfEdges 145 | for (itrTopoHalfEdges = aHalfEdges.begin(); itrTopoHalfEdges != aHalfEdges.end(); ++itrTopoHalfEdges) { 146 | // take care of rays... 147 | if (itrTopoHalfEdges->targetVertex == 0) continue; 148 | // search for the exit in the target which has the source as source 149 | list::iterator itrExits; 150 | for (itrExits = itrTopoHalfEdges->targetVertex->aExits.begin(); 151 | itrExits != itrTopoHalfEdges->targetVertex->aExits.end(); ++itrExits) { 152 | if ((*itrExits)->target() == itrTopoHalfEdges->sourceVertex) { 153 | // this is the correct one... 154 | (*itrExits)->exitEdge->twin = &*itrTopoHalfEdges; 155 | // also other way around - make most of them double but otherwise we would miss some of the rays! 156 | itrTopoHalfEdges->twin = (*itrExits)->exitEdge; 157 | // we can also mark our twin 158 | break; 159 | } 160 | } 161 | } 162 | cout << "now we have " << aVertices.size() << " vertices, " << aHalfEdges.size() << " halfEdges and " 163 | << aExits.size() << " exits." << endl; 164 | 165 | // remove strange empty vertices from rays and calculate the angles... 166 | list::iterator itrTopoVertices; 167 | for (itrTopoVertices = aVertices.begin(); itrTopoVertices != aVertices.end();) { 168 | if (itrTopoVertices->aExits.empty()) { 169 | itrTopoVertices = aVertices.erase(itrTopoVertices); 170 | } else { 171 | itrTopoVertices->calculateAngles(); 172 | ++itrTopoVertices; 173 | } 174 | } 175 | 176 | calcAllDistances(); 177 | 178 | } 179 | 180 | 181 | bool compareVertexPositions(const TopoVertex *first, const TopoVertex *second) { 182 | if (first->point.x() == second->point.x()) return first->point.y() < second->point.y(); 183 | return first->point.x() < second->point.x(); 184 | } 185 | 186 | void TopoGraph::assignVertexIds() { 187 | 188 | list vertices; 189 | for (list::iterator itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 190 | vertices.push_back(&*itrVertices); 191 | } 192 | vertices.sort(compareVertexPositions); 193 | unsigned int counter = 1; 194 | for (list::iterator itr = vertices.begin(); itr != vertices.end(); ++itr) { 195 | (*itr)->id = counter++; 196 | } 197 | } 198 | 199 | 200 | double clockWiseAngleRad(double start, double end) { 201 | if (start < 0.) start += 2 * M_PI; 202 | if (start >= 2 * M_PI) start -= 2 * M_PI; 203 | if (end < 0.) end += 2 * M_PI; 204 | if (end >= 2 * M_PI) end -= 2 * M_PI; 205 | if (start < end) { 206 | return 2 * M_PI - end + start; 207 | } else { 208 | return start - end; 209 | } 210 | } 211 | 212 | bool smallerThan(pair &first, pair &second) { 213 | return first.first < second.first; 214 | } 215 | 216 | void TopoVertex::calculateAngles() { 217 | // special case with just one exits first... 218 | if (aExits.size() < 2) { 219 | biggestExitAngleRad = 2 * M_PI; 220 | smallestExitAngleRad = 2 * M_PI; 221 | (*aExits.begin())->nextTopoExit = *aExits.begin(); 222 | return; 223 | } 224 | // calculate the global angles ... 225 | list > globalAnglesRad; 226 | for (list::iterator itrExits = aExits.begin(); itrExits != aExits.end(); ++itrExits) { 227 | topo_geometry::point otherPoint; 228 | double startDistance = sConfig->topoGraphAngleCalcStartDistance() - (*itrExits)->vertexEdgeDistance; 229 | if (startDistance < 0.) startDistance = 0.; 230 | double endDistance = sConfig->topoGraphAngleCalcEndDistance() - (*itrExits)->vertexEdgeDistance; 231 | if (endDistance < 0.) endDistance = 0.; 232 | list angles; // between 0 and 2*M_PI 233 | for (double di = endDistance; di >= startDistance; di -= sConfig->topoGraphAngleCalcStepSize()) { 234 | if ((*itrExits)->exitEdge->getPointForDistance(di, otherPoint)) { 235 | double ang = atan2(point.y() - topo_geometry::getY(otherPoint), 236 | point.x() - topo_geometry::getX(otherPoint)); 237 | if (ang < 0.) ang += 2 * M_PI; 238 | angles.push_back(ang); 239 | } 240 | } 241 | if (angles.empty()) { 242 | cerr << "Cannot calculate angle of edge - check your configuration!!" << endl; 243 | return; 244 | } 245 | list::iterator itrAngles = angles.begin(); 246 | double startAngle = *itrAngles; 247 | ++itrAngles; 248 | double error = 0.; 249 | unsigned int count = 1; 250 | for (; itrAngles != angles.end(); ++itrAngles, ++count) { 251 | error += min((2 * M_PI) - fabs(*itrAngles - startAngle), fabs(*itrAngles - startAngle)); 252 | } 253 | startAngle = startAngle + error / count; 254 | if (startAngle < 0.) startAngle += 2 * M_PI; 255 | if (startAngle >= 2 * M_PI) startAngle -= 2 * M_PI; 256 | globalAnglesRad.push_back(pair(startAngle, *itrExits)); 257 | } 258 | // now we have the global angles - sort and put in... 259 | globalAnglesRad.sort(smallerThan); 260 | list >::iterator itrAngles = globalAnglesRad.begin(); 261 | TopoExit *currentExit = itrAngles->second; 262 | double currentAngle = itrAngles->first; 263 | ++itrAngles; 264 | 265 | for (; itrAngles != globalAnglesRad.end(); ++itrAngles) { 266 | currentExit->nextTopoExit = itrAngles->second; 267 | currentExit->angleToNextTopoExitRad = clockWiseAngleRad(itrAngles->first, currentAngle); 268 | if (currentExit->angleToNextTopoExitRad < 0.) currentExit->angleToNextTopoExitRad += 2 * M_PI; 269 | if (currentExit->angleToNextTopoExitRad >= 2 * M_PI) currentExit->angleToNextTopoExitRad -= 2 * M_PI; 270 | currentExit = itrAngles->second; 271 | currentAngle = itrAngles->first; 272 | } 273 | // the last one has to point to the first one... 274 | currentExit->nextTopoExit = globalAnglesRad.begin()->second; 275 | currentExit->angleToNextTopoExitRad = clockWiseAngleRad(globalAnglesRad.begin()->first, currentAngle); 276 | if (currentExit->angleToNextTopoExitRad < 0.) currentExit->angleToNextTopoExitRad += 2 * M_PI; 277 | if (currentExit->angleToNextTopoExitRad >= 2 * M_PI) currentExit->angleToNextTopoExitRad -= 2 * M_PI; 278 | 279 | // now mark the biggest and the smallest angles in the vertex 280 | biggestExitAngleRad = 0.; 281 | smallestExitAngleRad = 2 * M_PI; 282 | for (list::iterator itrExits = aExits.begin(); itrExits != aExits.end(); ++itrExits) { 283 | if ((*itrExits)->angleToNextTopoExitRad > biggestExitAngleRad) 284 | biggestExitAngleRad = (*itrExits)->angleToNextTopoExitRad; 285 | if ((*itrExits)->angleToNextTopoExitRad < smallestExitAngleRad) 286 | smallestExitAngleRad = (*itrExits)->angleToNextTopoExitRad; 287 | } 288 | } 289 | 290 | bool TopoHalfEdge::getPointForDistance(double distance, topo_geometry::point &pPoint) { 291 | if (voriHalfEdges.size() != 1) { 292 | cerr << "not yet implemented!" << endl; 293 | assert(0); 294 | } 295 | return (*voriHalfEdges.begin())->getPointForDistance(distance, pPoint); 296 | } 297 | 298 | 299 | // 300 | // checks everything that exits from the first vertex 301 | void TopoGraph::checkFirstVertexInList(map &workList) { 302 | if (workList.empty()) return; // should never happen 303 | TopoVertex *curr = workList.begin()->first; 304 | // remove this one from the list 305 | workList.erase(workList.begin()); 306 | // first the easy case - this is the end of a dead end: 307 | if (curr->aExits.size() == 1) { 308 | unsigned int flags = TopoHalfEdge::DEAD_END | TopoHalfEdge::DEAD_ENDISH; 309 | // check the length 310 | if ((*curr->aExits.begin())->exitEdge->distance <= sConfig->topoGraphMarkAsFeatureEdgeLength()) { 311 | flags = flags | TopoHalfEdge::FEATURE_END; 312 | } 313 | // now set the properties and add the target to the work list 314 | (*curr->aExits.begin())->twinEdge()->edgeFlags = flags; 315 | // in the very unlikely event that this is a ray... 316 | if ((*curr->aExits.begin())->exitEdge->targetVertex) { 317 | workList[(*curr->aExits.begin())->exitEdge->targetVertex] = true; 318 | } 319 | } else { 320 | // more complicated case of multiple exits - first check what is coming in 321 | // find out what is coming on on all the exits 322 | unsigned int numIncomingDeadEndish = 0; 323 | unsigned int numIncomingOutsideisch = 0; 324 | unsigned int numIncomingEmpties = 0; 325 | // check every exit 326 | for (list::iterator itrExits = curr->aExits.begin(); itrExits != curr->aExits.end(); ++itrExits) { 327 | TopoExit *topoExit = *itrExits; 328 | // first check if this is a ray 329 | if (topoExit->exitEdge->isRay()) { 330 | ++numIncomingOutsideisch; 331 | // set the ray properties 332 | topoExit->exitEdge->edgeFlags = TopoHalfEdge::OUTSIDE | TopoHalfEdge::OUTSIDEISH; 333 | continue; 334 | } 335 | if (topoExit->exitEdge->edgeFlags & TopoHalfEdge::DEAD_ENDISH) ++numIncomingDeadEndish; 336 | if (topoExit->exitEdge->edgeFlags & TopoHalfEdge::OUTSIDEISH) ++numIncomingOutsideisch; 337 | if ((topoExit->exitEdge->edgeFlags & TopoHalfEdge::OUTSIDEISH) == 0 && 338 | (topoExit->exitEdge->edgeFlags & TopoHalfEdge::DEAD_ENDISH) == 0) { 339 | ++numIncomingEmpties; 340 | } 341 | } 342 | // now lets see if we can do stuff 343 | if (numIncomingEmpties < 2) { 344 | // we have one or no empty exits - "send" the information to all exits 345 | for (list::iterator itrExits = curr->aExits.begin(); 346 | itrExits != curr->aExits.end(); ++itrExits) { 347 | TopoExit *topoExit = *itrExits; 348 | if (topoExit->exitEdge->isRay()) continue; 349 | unsigned int flags = 0; 350 | unsigned int isDeadEndish = topoExit->twinEdge()->edgeFlags & TopoHalfEdge::DEAD_ENDISH; 351 | unsigned int isOutsideish = topoExit->twinEdge()->edgeFlags & TopoHalfEdge::OUTSIDEISH; 352 | if (numIncomingDeadEndish - isDeadEndish) { 353 | flags = flags | TopoHalfEdge::DEAD_ENDISH; 354 | } 355 | if (numIncomingOutsideisch - isOutsideish) { 356 | flags = flags | TopoHalfEdge::OUTSIDEISH; 357 | } 358 | // check if the flag we want to set differs! 359 | if ((topoExit->twinEdge()->edgeFlags & flags) != flags) { 360 | // we have to set and add to work list 361 | topoExit->twinEdge()->edgeFlags = topoExit->twinEdge()->edgeFlags | flags; 362 | workList[topoExit->target()] = true; 363 | } 364 | } 365 | } 366 | } 367 | } 368 | 369 | void TopoGraph::markGraph() { 370 | map workList; 371 | // fill the work list with all dead ends 372 | list::iterator itrVertices; 373 | for (itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 374 | if (itrVertices->aExits.size() < 2) { 375 | // this is a dead end - add to the list 376 | workList[&*itrVertices] = true; 377 | } 378 | } 379 | // now work on the list.... 380 | while (!workList.empty()) { 381 | checkFirstVertexInList(workList); 382 | } 383 | // mark the vertices, too 384 | for (itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 385 | unsigned int countNonFeatureExits = 0; 386 | for (list::iterator itrExits = itrVertices->aExits.begin(); 387 | itrExits != itrVertices->aExits.end(); ++itrExits) { 388 | if (!((*itrExits)->exitEdge->edgeFlags & TopoHalfEdge::FEATURE_END)) ++countNonFeatureExits; 389 | } 390 | itrVertices->isFeatureVertex = (countNonFeatureExits == 2); 391 | } 392 | } 393 | 394 | 395 | void TopoGraph::printInfo() { 396 | for (list::iterator itrTopoHalfEdges = aHalfEdges.begin(); 397 | itrTopoHalfEdges != aHalfEdges.end(); ++itrTopoHalfEdges) { 398 | cout << " edge: "; 399 | if (itrTopoHalfEdges->sourceVertex) cout << topo_geometry::print(itrTopoHalfEdges->sourceVertex->point); 400 | else 401 | cout << "INF"; 402 | cout << " to "; 403 | if (itrTopoHalfEdges->targetVertex) cout << topo_geometry::print(itrTopoHalfEdges->targetVertex->point); 404 | else 405 | cout << "INF"; 406 | cout << " : "; 407 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::DEAD_END) cout << "deadEnd "; 408 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::DEAD_ENDISH) cout << "deadEndish "; 409 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::FEATURE_END) cout << "feature "; 410 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::OUTSIDE) cout << "outside "; 411 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::OUTSIDEISH) cout << "outsideish "; 412 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::LOOP) cout << "loop "; 413 | if (itrTopoHalfEdges->edgeFlags & TopoHalfEdge::LOOP_BACK) cout << "loopBack "; 414 | cout << endl; 415 | } 416 | } 417 | 418 | void DistanceCalcHelper::clear() { 419 | distance = -1.; 420 | hops = 0; 421 | majorHops = 0; 422 | } 423 | 424 | 425 | void TopoGraph::removeDistanceMarks() { 426 | for (list::iterator itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 427 | itrVertices->distanceCalcHelper.clear(); 428 | } 429 | } 430 | 431 | void TopoGraph::calcAllDistances() { 432 | markGraph(); 433 | for (list::iterator itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 434 | for (list::iterator itrExits = itrVertices->aExits.begin(); 435 | itrExits != itrVertices->aExits.end(); ++itrExits) { 436 | calcDistancesFor(*itrExits); 437 | } 438 | } 439 | } 440 | 441 | void TopoGraph::setInconsistencyMarks(bool set) { 442 | for (list::iterator itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 443 | itrVertices->inconsistent = set; 444 | } 445 | } 446 | 447 | void TopoGraph::addTargetToWorkList(TopoExit *currExit, set &workList, TopoVertex *startVertex) { 448 | //first check if the target is not the start vertex 449 | if (currExit->target() == startVertex) return; 450 | // add all exits on the target to the work list - except the twin of currExit... 451 | for (list::iterator itrExits = currExit->target()->aExits.begin(); 452 | itrExits != currExit->target()->aExits.end(); ++itrExits) { 453 | if ((*itrExits)->target() == currExit->source()) continue; 454 | workList.insert(*itrExits); 455 | } 456 | } 457 | 458 | TopoExit *TopoVertex::findDirectExitTo(TopoVertex *vertex) { 459 | for (list::iterator itr = aExits.begin(); itr != aExits.end(); ++itr) { 460 | if ((*itr)->target() == vertex) return *itr; 461 | } 462 | return 0; 463 | } 464 | 465 | TopoExit *TopoVertex::findExitTo(TopoVertex *vertex, bool *wasMajor) { 466 | for (list::iterator itr = aExits.begin(); itr != aExits.end(); ++itr) { 467 | if ((*itr)->target() == vertex) { 468 | if (wasMajor) *wasMajor = false; 469 | return *itr; 470 | } 471 | if ((*itr)->nextMajorVertex == vertex) { 472 | if (wasMajor) *wasMajor = true; 473 | return *itr; 474 | } 475 | } 476 | return 0; 477 | } 478 | 479 | void TopoGraph::calcDistancesFor(TopoExit *startExit) { 480 | 481 | removeDistanceMarks(); 482 | 483 | TopoVertex *startVertex = startExit->source(); 484 | bool thereIsALoop = false; 485 | 486 | map loopingInVia; 487 | 488 | startVertex->distanceCalcHelper.distance = 0.; 489 | 490 | set workList; 491 | workList.insert(startExit); 492 | 493 | while (!workList.empty()) { 494 | TopoExit *currExit = *workList.begin(); 495 | workList.erase(workList.begin()); 496 | 497 | if (currExit->exitEdge->isRay()) continue; 498 | 499 | DistanceCalcHelper distCalc = currExit->source()->distanceCalcHelper; 500 | distCalc.distance += currExit->distance(); 501 | distCalc.hops++; 502 | //check if this is a major hop 503 | if (!startVertex->isFeatureVertex) ++distCalc.majorHops; 504 | 505 | // check if a loop occured 506 | if (currExit->target()->distanceCalcHelper.distance != -1) thereIsALoop = true; 507 | 508 | // check if the goal is unset or has a longer distance... 509 | if (currExit->target()->distanceCalcHelper.distance == -1 || 510 | currExit->target()->distanceCalcHelper.distance > distCalc.distance) { 511 | // we update the target and add the exits there to the work list 512 | currExit->target()->distanceCalcHelper = distCalc; 513 | addTargetToWorkList(currExit, workList, startVertex); 514 | } 515 | // if this is the startVertex again we want to save from where we came: 516 | if (currExit->target() == startVertex) { 517 | if (loopingInVia[currExit->source()].distance == -1 || 518 | loopingInVia[currExit->source()].distance > distCalc.distance) { 519 | loopingInVia[currExit->source()] = distCalc; 520 | } 521 | } 522 | } // while 523 | // add the loop info we gathered to the edge 524 | if (thereIsALoop) { 525 | startExit->exitEdge->edgeFlags = startExit->exitEdge->edgeFlags | TopoHalfEdge::LOOP; 526 | } 527 | if (!loopingInVia.empty()) { 528 | startExit->exitEdge->edgeFlags = startExit->exitEdge->edgeFlags | TopoHalfEdge::LOOP_BACK; 529 | } 530 | // add the loop info to the vertex 531 | if (!loopingInVia.empty()) { 532 | for (map::iterator itr = loopingInVia.begin(); 533 | itr != loopingInVia.end(); ++itr) { 534 | // find the exit in that direction: 535 | TopoExit *first = startVertex->findDirectExitTo(itr->first); 536 | TopoExit *second = startExit; 537 | if (second < first) { 538 | second = first; 539 | first = startExit; 540 | } 541 | if (first == second) { 542 | // cout<<"Grosse schweinerei! "<second.distance<<" "<second.hops<loops[pair(first, second)] = itr->second; 546 | } 547 | } 548 | } 549 | 550 | double nextMajorVertexDist = -1.; 551 | TopoVertex *nextMajorVertex = 0; 552 | //add the distnace info to the exit 553 | for (list::iterator itrVertices = aVertices.begin(); itrVertices != aVertices.end(); ++itrVertices) { 554 | if ((itrVertices->distanceCalcHelper.distance != -1.) && (&*itrVertices != startVertex)) { 555 | startExit->distances[&*itrVertices] = itrVertices->distanceCalcHelper; 556 | // also find the shortest distance to the next major node... 557 | if (!itrVertices->isFeatureVertex && itrVertices->aExits.size() > 1) { 558 | // this is a major node 559 | if (nextMajorVertexDist == -1. || itrVertices->distanceCalcHelper.distance < nextMajorVertexDist) { 560 | nextMajorVertexDist = itrVertices->distanceCalcHelper.distance; 561 | nextMajorVertex = &*itrVertices; 562 | } 563 | } 564 | } 565 | } 566 | if (nextMajorVertexDist > 0.) { 567 | startExit->distanceToNextMajorVertex = nextMajorVertexDist; 568 | startExit->nextMajorVertex = nextMajorVertex; 569 | } 570 | } 571 | 572 | 573 | -------------------------------------------------------------------------------- /src/VoriConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "VoriConfig.h" 2 | 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | 10 | #define DOUBLE_VAR_METHOD(name) \ 11 | double VoriConfig::name(){ \ 12 | map::iterator found = doubleConfigVars.find(#name); \ 13 | if(found == doubleConfigVars.end()){ \ 14 | cerr<<"Did not find config var "<<#name<<"!"<second; \ 18 | } 19 | 20 | DOUBLE_VAR_METHOD(voronoiMinimumDistanceToObstacle); 21 | 22 | DOUBLE_VAR_METHOD(topoGraphDistanceToJoinVertices); 23 | DOUBLE_VAR_METHOD(topoGraphAngleCalcStartDistance); 24 | DOUBLE_VAR_METHOD(topoGraphAngleCalcEndDistance); 25 | DOUBLE_VAR_METHOD(topoGraphAngleCalcStepSize); 26 | DOUBLE_VAR_METHOD(topoGraphMarkAsFeatureEdgeLength); 27 | 28 | DOUBLE_VAR_METHOD(alphaShapeRemovalSquaredSize); 29 | 30 | DOUBLE_VAR_METHOD(simiVerNumberOfExitsOffset); 31 | DOUBLE_VAR_METHOD(simiVerNumberOfExitsMax); 32 | DOUBLE_VAR_METHOD(simiVerExitAngleRadOffset); 33 | DOUBLE_VAR_METHOD(simiVerExitAngleRadMax); 34 | 35 | DOUBLE_VAR_METHOD(simiVerDistanceToObstaclesOffset); 36 | DOUBLE_VAR_METHOD(simiVerDistanceToObstaclesMax); 37 | 38 | DOUBLE_VAR_METHOD(simiVerDistanceBetweenJoinedVerticesOffset); 39 | DOUBLE_VAR_METHOD(simiVerDistanceBetweenJoinedVerticesMax); 40 | 41 | DOUBLE_VAR_METHOD(simiExitVertexDistanceOffset); 42 | DOUBLE_VAR_METHOD(simiExitVertexDistanceMax); 43 | 44 | DOUBLE_VAR_METHOD(simiExitDistanceToObstaclesOffset); 45 | DOUBLE_VAR_METHOD(simiExitDistanceToObstaclesMax); 46 | 47 | DOUBLE_VAR_METHOD(simiConsistencyEdgeDistanceFactor); 48 | DOUBLE_VAR_METHOD(simiConsistencyEdgeDistanceMinAllowance); 49 | 50 | DOUBLE_VAR_METHOD(simiIsomorphismMinNumberOfVertices); 51 | 52 | DOUBLE_VAR_METHOD(simiNeighbourDistanceOffset); 53 | DOUBLE_VAR_METHOD(simiNeighbourDistanceFactor); 54 | DOUBLE_VAR_METHOD(simiNeighbourMaxHopDifference); 55 | DOUBLE_VAR_METHOD(simiNeighbourMaxMajorHopDifference); 56 | 57 | DOUBLE_VAR_METHOD(simiNeighbourMinProb); 58 | DOUBLE_VAR_METHOD(simiNeighbourGoodProb); 59 | 60 | DOUBLE_VAR_METHOD(firstDeadEndRemovalDistance); 61 | DOUBLE_VAR_METHOD(secondDeadEndRemovalDistance); 62 | DOUBLE_VAR_METHOD(thirdDeadEndRemovalDistance); 63 | DOUBLE_VAR_METHOD(fourthDeadEndRemovalDistance); 64 | 65 | -------------------------------------------------------------------------------- /src/cgal/AlphaShape.cpp: -------------------------------------------------------------------------------- 1 | #include "cgal/AlphaShape.h" 2 | 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | 13 | void AlphaShapePolygon::getPoints(QImage &pImg, std::vector &points) { 14 | 15 | unsigned int height = pImg.height(); 16 | if (pImg.format() == QImage::Format_RGB32 || pImg.format() == QImage::Format_ARGB32) { 17 | qDebug() << "32 bit change color"; 18 | // mark color here 19 | for (unsigned int y = 0; y < height; y++) { 20 | QRgb *pointer = (QRgb *) pImg.scanLine( y ); 21 | QRgb *endP = pointer + pImg.width(); 22 | for (unsigned int x = 0; pointer < endP; ++pointer, ++x) { 23 | if (qRed( *pointer ) < 2) { 24 | points.push_back( K::Point_2( x + 0.25, y + 0.25 )); 25 | points.push_back( K::Point_2( x + 0.25, y - 0.25 )); 26 | points.push_back( K::Point_2( x - 0.25, y + 0.25 )); 27 | points.push_back( K::Point_2( x - 0.25, y - 0.25 )); 28 | } 29 | } 30 | } 31 | } else if (pImg.format() == QImage::Format_RGB888) { 32 | qDebug() << "24 bit change color"; 33 | for (unsigned int y = 0; y < height; y++) { 34 | // do the stuff... 35 | uchar *pointer = pImg.scanLine( y ); 36 | uchar *endP = pointer + (pImg.width() * 3); 37 | for (unsigned int x = 0; pointer < endP; pointer += 3, x++) { 38 | if ((*pointer) < 2) { 39 | points.push_back( K::Point_2( x + 0.25, y + 0.25 )); 40 | points.push_back( K::Point_2( x + 0.25, y - 0.25 )); 41 | points.push_back( K::Point_2( x - 0.25, y + 0.25 )); 42 | points.push_back( K::Point_2( x - 0.25, y - 0.25 )); 43 | 44 | } 45 | } 46 | } 47 | } 48 | } 49 | 50 | AlphaShapePolygon::SegmentSearchy::SegmentSearchy(std::list > &pSegments) 51 | : aSegments( pSegments ) { 52 | fill(); 53 | } 54 | 55 | void AlphaShapePolygon::SegmentSearchy::fill() { 56 | segmentSourceMap.clear(); 57 | for (list >::iterator itr = aSegments.begin(); 58 | itr != aSegments.end(); ++itr) { 59 | itr->second = true; 60 | segmentSourceMap[static_cast(itr->first.source().x())][static_cast(itr->first.source().y())].push_back( 61 | itr ); 62 | } 63 | } 64 | 65 | AlphaShapePolygon::SegmentSearchy::CellEntries 66 | AlphaShapePolygon::SegmentSearchy::findSegments(AlphaShapePolygon::K::Point_2 &p) { 67 | CellEntries rtn; 68 | map >::iterator found1 = segmentSourceMap.find( static_cast(p.x())); 69 | if (found1 == segmentSourceMap.end()) return rtn; 70 | map::iterator found2 = found1->second.find( static_cast(p.y())); 71 | if (found2 == found1->second.end()) return rtn; 72 | for (CellEntries::iterator itr = found2->second.begin(); itr != found2->second.end(); ++itr) { 73 | if ((*itr)->second && (*itr)->first.source() == p) rtn.push_back( *itr ); 74 | } 75 | return rtn; 76 | } 77 | 78 | 79 | void AlphaShapePolygon::growPolygon(SegmentSearchy &searchy, Polygon_2 &polygon, K::Point_2 front, K::Point_2 back) { 80 | while (front != back) { 81 | SegmentSearchy::CellEntries found = searchy.findSegments( back ); 82 | Segment currSegment; 83 | if (found.empty()) { 84 | cerr << "did not find contiuation for polygon!" << endl; 85 | return; 86 | } 87 | if (found.size() > 1) { 88 | cerr << "found " << found.size() << " continuations for polygon - randomly choosing..." << endl; 89 | } 90 | currSegment = (*found.begin())->first; 91 | // remove this segement... 92 | (*found.begin())->second = false; 93 | 94 | if (currSegment.source() == back) { 95 | back = currSegment.target(); 96 | if (back != front) { ; 97 | polygon.push_back( currSegment.target()); 98 | } 99 | } else { 100 | cerr << "not successfull :(" << endl; 101 | } 102 | } 103 | } 104 | 105 | // void AlphaShapePolygon::growPolygon(std::list &segments, Polygon_2 &polygon, K::Point_2 front, K::Point_2 back){ 106 | // list::iterator itr = segments.begin(); 107 | // while(front != back){ 108 | // Segment &currSegment = *itr; 109 | // if(currSegment.target() == front){ 110 | // front = currSegment.source(); 111 | // if(back != front){ 112 | // polygon.insert(polygon.vertices_begin(), currSegment.source()); 113 | // } 114 | // list::iterator del = itr; 115 | // ++itr; 116 | // segments.erase(del); 117 | // }else if(currSegment.source() == back){ 118 | // back = currSegment.target(); 119 | // if(back != front) {; 120 | // polygon.push_back(currSegment.target()); 121 | // } 122 | // list::iterator del = itr; 123 | // ++itr; 124 | // segments.erase(del); 125 | // }else{ 126 | // ++itr; 127 | // } 128 | // // continue search 129 | // if(itr == segments.end()) itr = segments.begin(); 130 | // } 131 | // } 132 | 133 | bool AlphaShapePolygon::isOutside(const K::Point_2 &p, Polygon_2 &poly, CGAL::Bbox_2 &box) { 134 | return p.x() >= box.xmin() && p.x() <= box.xmax() && p.y() >= box.ymin() && p.y() <= box.ymax() && 135 | poly.is_simple() && !poly.has_on_unbounded_side( p ); 136 | } 137 | 138 | void AlphaShapePolygon::generateBBoxesForPolygons(list &polygons, list &bboxes) { 139 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 140 | bboxes.push_back( itr->bbox()); 141 | } 142 | } 143 | 144 | double AlphaShapePolygon::calculatePolygonLength(Polygon_2 &polygon) { 145 | double length = 0.; 146 | for (Polygon_2::Edge_const_iterator edgeItr = polygon.edges_begin(); edgeItr != polygon.edges_end(); ++edgeItr) { 147 | length += sqrt( edgeItr->squared_length()); 148 | } 149 | return length; 150 | } 151 | 152 | void AlphaShapePolygon::generatePolygons(std::vector &points, double squared_size_is_alpha, 153 | list &polygons) { 154 | 155 | Alpha_shape_2 alpha( points.begin(), points.end()); 156 | alpha.set_alpha( squared_size_is_alpha ); 157 | alpha.set_mode( Alpha_shape_2::REGULARIZED ); 158 | cout << "calculated alpha - number " << alpha.number_of_solid_components() << endl; 159 | 160 | if (alpha.alpha_shape_edges_begin() == alpha.alpha_shape_edges_end()) return; 161 | 162 | std::list > segments; 163 | 164 | for (Edge_iterator itr = alpha.alpha_shape_edges_begin(); itr != alpha.alpha_shape_edges_end(); ++itr) { 165 | segments.push_back( pair( alpha.segment( *itr ), true )); 166 | // cout<<"segment added"<first< >::iterator itr = segments.begin(); itr != segments.end(); ++itr) { 175 | if (itr->second) { 176 | itr->second = false; 177 | // search for all connected parts 178 | polygons.push_back( Polygon_2()); 179 | Polygon_2 &currPoly = *polygons.rbegin(); 180 | currPoly.push_back( itr->first.source()); 181 | currPoly.push_back( itr->first.target()); 182 | growPolygon( segmentSearchy, currPoly, itr->first.source(), itr->first.target()); 183 | } 184 | } 185 | } 186 | 187 | // AlphaShapePolygon::Polygon_2 * 188 | // AlphaShapePolygon::performAlpha(QImage &pImg, double squared_size_is_alpha, bool deleteSmallPolygon) { 189 | // 190 | // std::vector points; 191 | // getPoints( pImg, points ); 192 | // 193 | // generatePolygons( points, squared_size_is_alpha, polygons ); 194 | // 195 | // pImg = pImg.convertToFormat( QImage::Format_ARGB32 ); 196 | // // pImg.fill(qRgba(255, 255, 255, 0)); 197 | // 198 | // QPainter painty( &pImg ); 199 | // painty.setPen( Qt::red ); 200 | // 201 | // cout << "number of polygons: " << polygons.size() << endl; 202 | // for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 203 | // for (Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr) { 204 | // Segment s = *edgeItr; 205 | // painty.drawLine( round( s.source().x()), round( s.source().y()), round( s.target().x()), 206 | // round( s.target().y())); 207 | // } 208 | // } 209 | // 210 | // list bboxes; 211 | // generateBBoxesForPolygons( polygons, bboxes ); 212 | // 213 | // if (deleteSmallPolygon) { 214 | // for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 215 | // // delete polygons inside this one: 216 | // list::iterator itrBBox = bboxes.begin(); 217 | // for (list::iterator itr2 = polygons.begin(); itr2 != polygons.end();) { 218 | // 219 | // if (itr != itr2 && isOutside( itr2->edges_begin()->source(), *itr, *itrBBox )) { 220 | // // this is an inside polygon 221 | // itr2 = polygons.erase( itr2 ); 222 | // itrBBox = bboxes.erase( itrBBox ); 223 | // } else { 224 | // ++itr2; 225 | // ++itrBBox; 226 | // } 227 | // } 228 | // } 229 | // 230 | // cout << "After inside removal: number of polygons: " << polygons.size() << endl; 231 | // 232 | // for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 233 | // for (Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr) { 234 | // Segment s = *edgeItr; 235 | // painty.drawLine( round( s.source().x()), round( s.source().y()), round( s.target().x()), 236 | // round( s.target().y())); 237 | // } 238 | // } 239 | // } 240 | // 241 | // // Polygon_2 &biggest = *polygons.begin(); 242 | // // double maxLength = -1.; 243 | // // for(list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr){ 244 | // // double length = calculatePolygonLength(*itr); 245 | // // if(length > maxLength){ 246 | // // maxLength = length; 247 | // // biggest = *itr; 248 | // // } 249 | // // } 250 | // 251 | // 252 | // int biggest = 0; 253 | // int counter = 0; 254 | // double maxLength = -1.; 255 | // for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr, ++counter) { 256 | // double length = calculatePolygonLength( *itr ); 257 | // cout << " test " << counter << " length " << length << endl; 258 | // if (length > maxLength) { 259 | // maxLength = length; 260 | // biggest = counter; 261 | // cout << " biggest " << biggest << " length " << length << endl; 262 | // } 263 | // } 264 | // 265 | // painty.setPen( qRgb(255,200,0) ); 266 | // cout << "Length of biggest polygon: " << maxLength << endl; 267 | // for (Polygon_2::Edge_const_iterator edgeItr = getPolygon( biggest ).edges_begin(); 268 | // edgeItr != getPolygon( biggest ).edges_end(); ++edgeItr) { 269 | // Segment s = *edgeItr; 270 | // painty.drawLine( round( s.source().x()), round( s.source().y()), 271 | // round( s.target().x()), round( s.target().y())); 272 | // } 273 | // 274 | // return &getPolygon( biggest ); 275 | // 276 | // } 277 | 278 | AlphaShapePolygon::Polygon_2 * 279 | AlphaShapePolygon::performAlpha(QImage &pImg, double squared_size_is_alpha, bool deleteSmallPolygon) { 280 | //biggest alpha shape: longest length 281 | std::vector points; 282 | getPoints( pImg, points ); 283 | 284 | generatePolygons( points, squared_size_is_alpha, polygons ); 285 | 286 | pImg = pImg.convertToFormat( QImage::Format_ARGB32 ); 287 | // pImg.fill(qRgba(255, 255, 255, 0)); 288 | 289 | QPainter painty( &pImg ); 290 | painty.setPen( Qt::red ); 291 | 292 | 293 | QBrush brush; 294 | QColor color = QColor( qRgba(250,0,0,80) ); 295 | brush.setColor( color ); 296 | brush.setStyle( Qt::Dense7Pattern ); 297 | QPainter painter(&pImg); 298 | painty.setBrush( brush ); 299 | painty.setPen( color ); 300 | cout << "number of polygons: " << polygons.size() << endl; 301 | int cnt=0; 302 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 303 | QPolygon poly; 304 | for (Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr) { 305 | Segment s = *edgeItr; 306 | painty.drawLine( round( s.source().x()), round( s.source().y()), round( s.target().x()), 307 | round( s.target().y())); 308 | poly << QPoint( round( s.target().x()), round( s.target().y())); 309 | } 310 | if (cnt!=0) 311 | painty.drawPolygon( poly ); 312 | cnt++; 313 | } 314 | 315 | list bboxes; 316 | generateBBoxesForPolygons( polygons, bboxes ); 317 | 318 | if (deleteSmallPolygon) { 319 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 320 | // delete polygons inside this one: 321 | list::iterator itrBBox = bboxes.begin(); 322 | for (list::iterator itr2 = polygons.begin(); itr2 != polygons.end();) { 323 | 324 | if (itr != itr2 && isOutside( itr2->edges_begin()->source(), *itr, *itrBBox )) { 325 | // this is an inside polygon 326 | itr2 = polygons.erase( itr2 ); 327 | itrBBox = bboxes.erase( itrBBox ); 328 | } else { 329 | ++itr2; 330 | ++itrBBox; 331 | } 332 | } 333 | } 334 | 335 | // cout << "After inside removal: number of polygons: " << polygons.size() << endl; 336 | 337 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 338 | for (Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr) { 339 | Segment s = *edgeItr; 340 | painty.drawLine( round( s.source().x()), round( s.source().y()), round( s.target().x()), 341 | round( s.target().y())); 342 | } 343 | } 344 | } 345 | 346 | // Polygon_2 &biggest = *polygons.begin(); 347 | // double maxLength = -1.; 348 | // for(list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr){ 349 | // double length = calculatePolygonLength(*itr); 350 | // if(length > maxLength){ 351 | // maxLength = length; 352 | // biggest = *itr; 353 | // } 354 | // } 355 | 356 | 357 | int biggest = 0; 358 | int counter = 0; 359 | double maxLength = -1.; 360 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr, ++counter) { 361 | double length = calculatePolygonLength( *itr ); 362 | // cout << " test " << counter << " length " << length << endl; 363 | if (length > maxLength) { 364 | maxLength = length; 365 | biggest = counter; 366 | // cout << " biggest " << biggest << " length " << length << endl; 367 | } 368 | } 369 | 370 | painty.setPen( qRgb(0,250,0) ); 371 | cout << "Length of biggest polygon: " << maxLength << endl; 372 | for (Polygon_2::Edge_const_iterator edgeItr = getPolygon( biggest ).edges_begin(); 373 | edgeItr != getPolygon( biggest ).edges_end(); ++edgeItr) { 374 | Segment s = *edgeItr; 375 | painty.drawLine( round( s.source().x()), round( s.source().y()), 376 | round( s.target().x()), round( s.target().y())); 377 | } 378 | 379 | return &getPolygon( biggest ); 380 | 381 | } 382 | AlphaShapePolygon::Polygon_2 * 383 | AlphaShapePolygon::performAlpha_biggestArea(QImage &pImg, double squared_size_is_alpha, bool deleteSmallPolygon) { 384 | // function: returen biggest alpha polygon, and save all generated alpha polygons in this->polygons (protected member) 385 | 386 | std::vector points; 387 | getPoints( pImg, points ); 388 | 389 | // polygons: a list of alpha shape polygons 390 | generatePolygons( points, squared_size_is_alpha, polygons ); 391 | 392 | pImg = pImg.convertToFormat( QImage::Format_ARGB32 ); 393 | 394 | QPainter painty( &pImg ); 395 | painty.setPen( Qt::red ); 396 | 397 | 398 | QBrush brush; 399 | QColor color = QColor( qRgba(250,0,0,80) ); 400 | brush.setColor( color ); 401 | brush.setStyle( Qt::Dense7Pattern ); 402 | // QPainter painter(&pImg); 403 | painty.setBrush( brush ); 404 | painty.setPen( color ); 405 | cout << "number of polygons: " << polygons.size() << endl; 406 | if(!deleteSmallPolygon) { 407 | int cnt = 0; 408 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 409 | QPolygon poly; 410 | for (Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr) { 411 | Segment s = *edgeItr; 412 | painty.drawLine( round( s.source().x()), round( s.source().y()), round( s.target().x()), 413 | round( s.target().y())); 414 | poly << QPoint( round( s.target().x()), round( s.target().y())); 415 | } 416 | if (cnt != 0) 417 | painty.drawPolygon( poly ); 418 | cnt++; 419 | } 420 | } 421 | 422 | list bboxes; 423 | generateBBoxesForPolygons( polygons, bboxes ); 424 | 425 | if (deleteSmallPolygon) { 426 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 427 | // delete polygons inside this one: 428 | list::iterator itrBBox = bboxes.begin(); 429 | for (list::iterator itr2 = polygons.begin(); itr2 != polygons.end();) { 430 | 431 | if (itr != itr2 && isOutside( itr2->edges_begin()->source(), *itr, *itrBBox )) { 432 | // this is an inside polygon 433 | itr2 = polygons.erase( itr2 ); 434 | itrBBox = bboxes.erase( itrBBox ); 435 | } else { 436 | ++itr2; 437 | ++itrBBox; 438 | } 439 | } 440 | } 441 | 442 | if(!deleteSmallPolygon) { 443 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr) { 444 | for (Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); 445 | edgeItr != itr->edges_end(); ++edgeItr) { 446 | Segment s = *edgeItr; 447 | painty.drawLine( round( s.source().x()), round( s.source().y()), round( s.target().x()), 448 | round( s.target().y())); 449 | } 450 | } 451 | } 452 | } 453 | int biggest = 0; 454 | int counter = 0; 455 | double maxArea = -1.; 456 | for (list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr, ++counter) { 457 | double tem_area= fabs(itr->area()); 458 | // cout << " test " << counter << " area " << tem_area << endl; 459 | if (tem_area > maxArea) { 460 | maxArea = tem_area; 461 | biggest = counter; 462 | } 463 | } 464 | 465 | painty.setPen( qRgb(0,0,0) ); 466 | if(!deleteSmallPolygon) 467 | painty.setPen( qRgb(0,0,250) ); 468 | cout << "Area of biggest polygon: " << maxArea << endl; 469 | for (Polygon_2::Edge_const_iterator edgeItr = getPolygon( biggest ).edges_begin(); 470 | edgeItr != getPolygon( biggest ).edges_end(); ++edgeItr) { 471 | Segment s = *edgeItr; 472 | painty.drawLine( round( s.source().x()), round( s.source().y()), 473 | round( s.target().x()), round( s.target().y())); 474 | } 475 | 476 | return &getPolygon( biggest ); 477 | 478 | } 479 | 480 | //add 481 | AlphaShapePolygon::Polygon_2 &AlphaShapePolygon::getPolygon(unsigned int i) { 482 | std::list::iterator itr = polygons.begin(); 483 | unsigned int index; 484 | for (index = 0; index < i && itr != polygons.end(); index++, itr++); 485 | if (index == i) { 486 | return *itr; 487 | } else { 488 | return polygons.back(); 489 | } 490 | } 491 | 492 | unsigned int AlphaShapePolygon::sizeOfPolygons() { 493 | return polygons.size(); 494 | } 495 | 496 | void AlphaShapePolygon::drawPolygonByIndex(QImage &pImg, unsigned int index) { 497 | QPainter painty( &pImg ); 498 | unsigned int i = 0; 499 | QPainterPath polygonPath; 500 | 501 | for (Polygon_2::Edge_const_iterator edgeItr = getPolygon( index ).edges_begin(); 502 | edgeItr != getPolygon( index ).edges_end(); ++edgeItr) { 503 | Segment s = *edgeItr; 504 | if (i == 0) { 505 | polygonPath.moveTo( round( s.source().x()), round( s.source().y())); 506 | } else { 507 | polygonPath.lineTo( round( s.source().x()), round( s.source().y())); 508 | } 509 | i++; 510 | //painty.drawLine(round(s.source().x()), round(s.source().y()), round( s.target().x()), round(s.target().y())); 511 | } 512 | polygonPath.closeSubpath(); 513 | 514 | painty.setPen( Qt::red ); 515 | painty.fillPath( polygonPath, QBrush( QColor( 255, 255, (255 / (sizeOfPolygons())) * index ), Qt::SolidPattern )); 516 | painty.drawPath( polygonPath ); 517 | 518 | /*painty.setPen(Qt::red); 519 | if(index < sizeOfPolygons()) 520 | { 521 | for(Polygon_2::Edge_const_iterator edgeItr = getPolygon(index).edges_begin(); edgeItr != getPolygon(index).edges_end(); ++edgeItr){ 522 | Segment s = *edgeItr; 523 | painty.drawLine(round(s.source().x()), round(s.source().y()), round( s.target().x()), round(s.target().y())); 524 | } 525 | }*/ 526 | } 527 | 528 | void AlphaShapePolygon::drawPolygon(QImage &pImg, Polygon_2 *poly) { 529 | QPainter painty( &pImg ); 530 | for (int index = 0; index < sizeOfPolygons(); index++) { 531 | unsigned int i = 0; 532 | QPainterPath polygonPath; 533 | 534 | for (Polygon_2::Edge_const_iterator edgeItr = getPolygon( index ).edges_begin(); 535 | edgeItr != getPolygon( index ).edges_end(); ++edgeItr) { 536 | Segment s = *edgeItr; 537 | if (i == 0) { 538 | polygonPath.moveTo( round( s.source().x()), round( s.source().y())); 539 | } else { 540 | polygonPath.lineTo( round( s.source().x()), round( s.source().y())); 541 | } 542 | i++; 543 | } 544 | polygonPath.closeSubpath(); 545 | 546 | if (getPolygon( index ) != *poly) { 547 | painty.setPen( Qt::red ); 548 | painty.fillPath( polygonPath, 549 | QBrush( QColor( 255, 255, (255 / (sizeOfPolygons())) * index ), Qt::SolidPattern )); 550 | } else { 551 | painty.setPen( Qt::blue ); 552 | } 553 | 554 | painty.drawPath( polygonPath ); 555 | } 556 | } -------------------------------------------------------------------------------- /src/cgal/AlphaShapeRemoval.cpp: -------------------------------------------------------------------------------- 1 | #include "cgal/AlphaShapeRemoval.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "cgal/AlphaShape.h" 8 | 9 | using namespace std; 10 | 11 | void performAlphaRemoval(QImage &pImg, double pAlphaShapeSquaredDist, double pMaxPolygonLength){ 12 | AlphaShapePolygon alphaShapePolygon; 13 | 14 | vector points; 15 | alphaShapePolygon.getPoints(pImg, points); 16 | 17 | list polygons; 18 | alphaShapePolygon.generatePolygons(points, pAlphaShapeSquaredDist, polygons); 19 | 20 | QImage image = pImg.convertToFormat(QImage::Format_ARGB32); 21 | image.fill(qRgba(255, 255, 255, 0)); 22 | QPainter painty(&image); 23 | painty.setPen(Qt::blue); 24 | for(list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr){ 25 | for(AlphaShapePolygon::Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr){ 26 | AlphaShapePolygon::Segment s = *edgeItr; 27 | painty.drawLine(round(s.source().x()), round(s.source().y()), round( s.target().x()), round(s.target().y())); 28 | } 29 | } 30 | 31 | 32 | for(list::iterator itr = polygons.begin(); itr != polygons.end();){ 33 | if(alphaShapePolygon.calculatePolygonLength(*itr) > pMaxPolygonLength){ 34 | itr = polygons.erase(itr); 35 | }else{ 36 | ++itr; 37 | } 38 | } 39 | 40 | painty.setPen(Qt::red); 41 | for(list::iterator itr = polygons.begin(); itr != polygons.end(); ++itr){ 42 | for(AlphaShapePolygon::Polygon_2::Edge_const_iterator edgeItr = itr->edges_begin(); edgeItr != itr->edges_end(); ++edgeItr){ 43 | AlphaShapePolygon::Segment s = *edgeItr; 44 | painty.drawLine(round(s.source().x()), round(s.source().y()), round( s.target().x()), round(s.target().y())); 45 | } 46 | } 47 | painty.end(); 48 | // image.save("detectAlphaRemoval.png"); 49 | 50 | list bboxes; 51 | alphaShapePolygon.generateBBoxesForPolygons(polygons, bboxes); 52 | 53 | cout<<"Removing the points for "<::iterator itrPoints = points.begin(); itrPoints != points.end(); ++itrPoints){ 55 | bool remove = false; 56 | list::iterator itrBBoxes= bboxes.begin(); 57 | for(list::iterator itrPolygons = polygons.begin(); itrPolygons != polygons.end(); ++itrPolygons, ++itrBBoxes){ 58 | if(AlphaShapePolygon::isOutside(*itrPoints, *itrPolygons, *itrBBoxes) ){ 59 | remove = true; 60 | break; 61 | } 62 | } 63 | if(remove){ 64 | pImg.setPixel(round(itrPoints->x()), round(itrPoints->y()), qRgba(255, 255, 255, 255) ); 65 | } 66 | } 67 | 68 | } 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/passageSearch.cpp: -------------------------------------------------------------------------------- 1 | #include "passageSearch.h" 2 | 3 | PS::Vertex *removeMiniF(std::list &alst); 4 | 5 | /* 6 | * feature function 7 | * 8 | */ 9 | PS::PPEdge::PPEdge(VoriGraphVertex *psg1, VoriGraphVertex *psg2, double cost, std::list *path) 10 | : psg1(psg1), psg2(psg2), cost(cost), path(path) {}; 11 | 12 | 13 | 14 | /* 15 | *tools for this cpp only 16 | */ 17 | PS::Vertex *removeMiniF(std::list &alst) { 18 | std::list::iterator mini_it = alst.begin(); 19 | for (std::list::iterator it = ++(alst.begin()); it != alst.end(); it++) { 20 | if ((*it)->f < (*mini_it)->f) { 21 | mini_it = it; 22 | } 23 | } 24 | PS::Vertex *mini_ptr = (*mini_it); 25 | alst.erase(mini_it); 26 | return mini_ptr; 27 | } 28 | -------------------------------------------------------------------------------- /src/roomGraph.cpp: -------------------------------------------------------------------------------- 1 | #include "roomGraph.h" 2 | #include "RoomDect.h" 3 | // 4 | //void coutpoint(topo_geometry::point p) { 5 | // double x, y; 6 | // x = topo_geometry::getX(p); 7 | // y = topo_geometry::getY(p); 8 | // std::cout << "(" << x << ", " << y << ") "; 9 | //} 10 | 11 | /* 12 | * class init 13 | */ 14 | RMG::AreaGraph::AreaGraph(VoriGraph &voriGraph) { 15 | //1. achieve those roomVertexes 16 | this->buildAreaGraph(voriGraph); 17 | //2. build a lineGraph 18 | // RMG::connectRoomVertexes(originSet); 19 | } 20 | 21 | /* 22 | * By Yijun 23 | * 24 | RMG::roomGraph::roomGraph(VoriGraph &voriGraph){ 25 | //1. achieve those roomVertexes 26 | RMG::build_oriSet(voriGraph, originSet); 27 | //2. build a lineGraph 28 | RMG::connectRoomVertexes(originSet); 29 | }*/ 30 | 31 | RMG::roomVertex::roomVertex(int roomId, topo_geometry::point loc, topo_geometry::point st, topo_geometry::point ed) 32 | : roomId(roomId), center(loc), st(st), ed(ed) { 33 | parentV = NULL; 34 | } 35 | 36 | /* 37 | * roomVertex class function 38 | */ 39 | void RMG::roomVertex::init_areaInnerPPGraph() { 40 | for (std::list::iterator it = this->areaInnerPathes.begin(); 41 | it != this->areaInnerPathes.end(); it++) { 42 | PS::PPEdge *tmp_ppe = new PS::PPEdge((*it)->source, (*it)->target, 43 | (*it)->distance, &((*it)->pathEdges)); 44 | this->areaInnerPPGraph.push_back(tmp_ppe); 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | void RMG::AreaGraph::mergeAreas() { 52 | //1. traverse each roomVertex, find other points with the same roomId to put into roomToMerge, 53 | // where build a new roomVertex as merged room to put at begin of roomToMerge 54 | // 55 | //Attention: the merged points will have roomId = -2 to indicate they are removed 56 | // And also the new node don't have a in degree, will be build in the 57 | // prunning step 58 | std::vector newNodeSet;//temporally store the new node 59 | std::map > roomToMerge; 60 | 61 | for (std::vector::iterator it = originSet.begin(); it != originSet.end(); it++) { 62 | 63 | int groupRoomId = (*it)->roomId; 64 | //1.1 check 65 | if (groupRoomId == -1 or groupRoomId == -2) 66 | continue; //because it is not belong to a roomCell or has already been chosed. 67 | 68 | // (*it)->roomId = -2; 69 | roomVertex *biggerRoom; 70 | std::map >::iterator rM = roomToMerge.find(groupRoomId); 71 | if (rM == roomToMerge.end()) { //a new roomId, we need to create a new roomVertex for a new big room 72 | roomVertex *tmp_bigroom(new roomVertex(groupRoomId, (*it)->center, (*it)->st, (*it)->ed)); 73 | biggerRoom = tmp_bigroom; 74 | std::vector tmpVec; // store the vertexes with the same roomId 75 | tmpVec.push_back(biggerRoom); 76 | roomToMerge[groupRoomId] = tmpVec; 77 | } else { 78 | biggerRoom = *roomToMerge[groupRoomId].begin(); 79 | } 80 | roomToMerge[groupRoomId].push_back(*it); 81 | for (std::list::iterator inrm_ps_it = (*it)->areaInnerPathes.begin(); 82 | inrm_ps_it != (*it)->areaInnerPathes.end(); inrm_ps_it++) { 83 | biggerRoom->areaInnerPathes.push_back(*inrm_ps_it); 84 | // to instead "biggerRoom->init_areaInnerPPGraph()": convert the halfedge into PPEdge 85 | PS::PPEdge *tmp_ppe(new PS::PPEdge((*inrm_ps_it)->source, (*inrm_ps_it)->target, 86 | (*inrm_ps_it)->distance, &((*inrm_ps_it)->pathEdges))); 87 | biggerRoom->areaInnerPPGraph.push_back(tmp_ppe); 88 | } 89 | // (*it)->parentV = biggerRoom; 90 | 91 | biggerRoom->polygons.insert(biggerRoom->polygons.end(), (*it)->polygons.begin(), (*it)->polygons.end()); 92 | 93 | //2. check: if the passage is inside the big room, then it is not a passage of the big room, and delete the passage from roomGraph.passageEList; 94 | // otherwise, delete the small area from passage.connectedAreas and add big room instead 95 | for (std::vector::iterator sitr = (*it)->passages.begin(); 96 | sitr != (*it)->passages.end(); sitr++) { 97 | 98 | std::vector::iterator ritr; 99 | int rcnt = 0; 100 | bool innerpassage = true; 101 | for (std::vector::iterator vitr = (*sitr)->connectedAreas.begin(); 102 | vitr != (*sitr)->connectedAreas.end(); vitr++) { 103 | if (groupRoomId != (*vitr)->roomId) { 104 | innerpassage = false; 105 | } 106 | rcnt++; 107 | ritr = vitr; 108 | } 109 | if (innerpassage == false) { //not an inner passage 110 | if (rcnt > 1) { 111 | bool first = true; 112 | for (std::vector::iterator vitr = (*sitr)->connectedAreas.begin(); 113 | vitr != (*sitr)->connectedAreas.end();) { 114 | if (groupRoomId == (*vitr)->roomId) { 115 | if (first) { 116 | first = false; 117 | (*vitr) = biggerRoom; 118 | vitr++; 119 | } else { 120 | (*sitr)->connectedAreas.erase(vitr); 121 | } 122 | } else { 123 | vitr++; 124 | } 125 | } 126 | } else { //Replace the original room with the bigger room 127 | (*ritr) = biggerRoom; 128 | } 129 | biggerRoom->passages.push_back((*sitr)); 130 | } else { //a inner passage 131 | passageEList.remove(*sitr); 132 | } 133 | } 134 | 135 | } 136 | for (std::map >::iterator mitr = roomToMerge.begin(); 137 | mitr != roomToMerge.end(); mitr++) { 138 | std::vector tmpVec = mitr->second; 139 | 140 | //merge neigbhbours and polygons, point origin node to new node 141 | std::vector::iterator itr = tmpVec.begin(); 142 | roomVertex *biggerRoom = *itr; 143 | itr++; 144 | for (; itr != tmpVec.end(); itr++) { 145 | roomVertex *rp = *itr; 146 | originSet.erase(std::remove(originSet.begin(), originSet.end(), (*itr))); 147 | delete rp; 148 | } 149 | originSet.push_back(biggerRoom); 150 | } 151 | } 152 | 153 | 154 | /* 155 | *roomGraph class function 156 | * 157 | */ 158 | void RMG::AreaGraph::mergeRoomCell() { 159 | //1. traverse each point, find other points with the same roomId 160 | //2. build a new roomGraph and build neighbours and polygons 161 | //Attention: the merged points will have roomId = -2 to indicate they are removed 162 | // And also the new node don't have a in degree, will be build in the 163 | // prunning step 164 | std::vector newNodeSet;//temporally store the new node 165 | 166 | for (std::vector::iterator it = originSet.begin(); 167 | it != originSet.end(); it++) { 168 | 169 | int groupRoomId = (*it)->roomId; 170 | //1.1 check 171 | if (groupRoomId == -1 or groupRoomId == -2) 172 | continue;//because it is not belong to a roomCell or has already been chosed. 173 | 174 | 175 | //1.2 store the same roomId point 176 | std::vector tmpVec; // store the vertexes with the same roomId 177 | tmpVec.push_back((*it)); 178 | (*it)->roomId = -2; 179 | 180 | 181 | std::vector::iterator itj = it; 182 | for (itj++; itj != originSet.end(); itj++) { 183 | //check 184 | if ((*itj)->roomId == -1 or (*itj)->roomId == -2) 185 | continue;//because it is not belong to a roomCell or has already been chosed. 186 | 187 | if ((*itj)->roomId == groupRoomId) { 188 | tmpVec.push_back((*itj)); 189 | (*itj)->roomId = -2; 190 | } 191 | } 192 | 193 | //2 build a new roomV 194 | roomVertex *biggerRoom = new roomVertex(groupRoomId, (*(tmpVec.begin()))->center, (*(tmpVec.begin()))->st, 195 | (*(tmpVec.begin()))->ed); 196 | //append innerpathes into the new innerpathes list then transform to PPEdge list 197 | for (std::vector::iterator inrm_it = tmpVec.begin(); inrm_it != tmpVec.end(); inrm_it++) { 198 | for (std::list::iterator inrm_ps_it = (*inrm_it)->areaInnerPathes.begin(); 199 | inrm_ps_it != (*inrm_it)->areaInnerPathes.end(); inrm_ps_it++) { 200 | biggerRoom->areaInnerPathes.push_back(*inrm_ps_it); 201 | biggerRoom->areaInnerPathes.push_back((*inrm_ps_it)->twin); 202 | } 203 | } 204 | biggerRoom->init_areaInnerPPGraph(); 205 | 206 | //merge neigbhbours and polygons, point origin node to new node 207 | for (std::vector::iterator itr = tmpVec.begin(); itr != tmpVec.end(); itr++) { 208 | //biggerRoom->neighbours.merge((*itr)->neighbours); 209 | //biggerRoom->polygons.merge((*itr)->polygons); 210 | biggerRoom->neighbours.insert((*itr)->neighbours.begin(), (*itr)->neighbours.end()); 211 | biggerRoom->polygons.insert(biggerRoom->polygons.begin(), (*itr)->polygons.begin(), (*itr)->polygons.end()); 212 | (*itr)->parentV = biggerRoom; 213 | } 214 | newNodeSet.push_back(biggerRoom); 215 | } 216 | //merge new node into originSet 217 | originSet.insert(originSet.end(), newNodeSet.begin(), newNodeSet.end()); 218 | } 219 | 220 | void RMG::AreaGraph::prunning() { 221 | //1. search each point to find if its neighbour have -2 roomId, 222 | // if a neighbour is, rm this neighbour and point to its parent 223 | // (the new node) 224 | //2. delete those point with -2 roomId 225 | // (traverse through the originSet and build a delete vector in step one) 226 | std::set removeOriginSet; 227 | //1. 228 | for (std::vector::iterator it = originSet.begin(); it != originSet.end(); it++) { 229 | std::set removeNeibourSet; 230 | std::set insertNeibourSet; 231 | for (std::set::iterator its = (*it)->neighbours.begin(); 232 | its != (*it)->neighbours.end(); its++) { 233 | if ((*its)->roomId == -2) { 234 | insertNeibourSet.insert((*its)->parentV); 235 | removeNeibourSet.insert((*its)); 236 | removeOriginSet.insert((*its)); 237 | } 238 | } 239 | //remove neighbour node 240 | for (std::set::iterator itr = removeNeibourSet.begin(); itr != removeNeibourSet.end(); itr++) { 241 | //(*it)->neighbours.extract((*itr)); 242 | (*it)->neighbours.erase((*itr)); 243 | } 244 | //insert neighbour node 245 | //(*it)->neighbours.merge(insertNeibourSet); 246 | (*it)->neighbours.insert(insertNeibourSet.begin(), insertNeibourSet.end()); 247 | //clean the temporary set 248 | removeNeibourSet.clear(); 249 | insertNeibourSet.clear(); 250 | } 251 | 252 | //2. remove -2 node from originSet 253 | for (std::set::iterator itrmo = removeOriginSet.begin(); itrmo != removeOriginSet.end(); itrmo++) { 254 | originSet.erase(std::remove(originSet.begin(), originSet.end(), (*itrmo)), originSet.end()); 255 | } 256 | } 257 | 258 | void RMG::AreaGraph::arrangeRoomId() { 259 | int roomId = 0; 260 | for (std::vector::iterator it = this->originSet.begin(); it != this->originSet.end(); it++) { 261 | (*it)->roomId = roomId++; 262 | } 263 | } 264 | 265 | 266 | void RMG::AreaGraph::show() { 267 | std::cout << "area number = " << (*this->originSet.rbegin())->roomId + 1 << std::endl; 268 | // for(std::vector::iterator it = this->originSet.begin(); it!=this->originSet.end(); it++){ 269 | // std::cout << (*it)->roomId << " "; 270 | // if((*it)->parentV) 271 | // std::cout << "there is one room should be erased during prunning "; 272 | // std::cout << std::endl; 273 | // } 274 | } 275 | 276 | void RMG::AreaGraph::draw(QImage &image) { 277 | QPainter painter(&image); 278 | for (std::vector::iterator it = this->originSet.begin(); it != this->originSet.end(); it++) { 279 | 280 | //draw current polygons 281 | QBrush brush; 282 | QColor color = QColor(rand() % 255, rand() % 255, rand() % 255); 283 | brush.setColor(color); 284 | brush.setStyle(Qt::SolidPattern); 285 | painter.setBrush(brush); 286 | painter.setPen(color); 287 | 288 | QPolygon poly; 289 | for (std::list::iterator pointitr = (*it)->polygon.begin(); 290 | pointitr != (*it)->polygon.end(); pointitr++) { 291 | int x = round(topo_geometry::getX(*pointitr)); 292 | int y = round(topo_geometry::getY(*pointitr)); 293 | // cout<<" point: "<::iterator itj = (*it)->neighbours.begin(); itj != (*it)->neighbours.end(); itj++) { 299 | painter.setPen(qRgb(rand(), rand(), rand())); 300 | 301 | int x1 = (round(topo_geometry::getX((*itj)->center))); //坐标都取整(四舍五入)再画 302 | int y1 = (round(topo_geometry::getY((*itj)->center))); 303 | int x2 = (round(topo_geometry::getX((*it)->center))); 304 | int y2 = (round(topo_geometry::getY((*it)->center))); 305 | // painter.drawLine(x1, y1, x2, y2); 306 | } 307 | } 308 | } 309 | 310 | //passage searching stuff 311 | 312 | 313 | 314 | 315 | /* 316 | * AreaGraph namespace functions 317 | */ 318 | static bool equalLineVertex(const topo_geometry::point &a, const topo_geometry::point &b); 319 | 320 | void RMG::connectRoomVertexes(std::vector &originSet) { 321 | for (std::vector::iterator it = originSet.begin(); 322 | it != originSet.end(); it++) { 323 | topo_geometry::point st = (*it)->st; 324 | topo_geometry::point ed = (*it)->ed; 325 | std::vector::iterator tmpIt = it;//shoud double check (it should be a copy of it) 326 | for (std::vector::iterator itj = tmpIt; 327 | itj != originSet.end(); itj++) { 328 | if (equalLineVertex(st, (*itj)->st) || 329 | equalLineVertex(st, (*itj)->ed) || 330 | equalLineVertex(ed, (*itj)->st) || 331 | equalLineVertex(ed, (*itj)->ed)) { 332 | 333 | (*it)->neighbours.insert((*itj)); 334 | (*itj)->neighbours.insert((*it)); 335 | } 336 | 337 | } 338 | 339 | 340 | } 341 | } 342 | 343 | 344 | //void RMG::build_oriSet(VoriGraph &voriGraph, std::vector &originSet) { 345 | // //build a line graph 346 | // std::set halfEdgeSet; 347 | // for (std::list::iterator voriHalfEdgeItr = voriGraph.halfEdges.begin(); 348 | // voriHalfEdgeItr != voriGraph.halfEdges.end(); ++voriHalfEdgeItr) { 349 | // if (voriHalfEdgeItr->isRay()) { 350 | // continue; 351 | // } else if (halfEdgeSet.find(&*voriHalfEdgeItr) == halfEdgeSet.end()) { 352 | // halfEdgeSet.insert(&*voriHalfEdgeItr); 353 | // 354 | // VoriGraphPolygon *polygonPtr = voriHalfEdgeItr->pathFace; 355 | // int sumX = 0, sumY = 0; 356 | // if (polygonPtr != 0 /*&& polygonPtr->isRay*/) { 357 | // for (std::list::iterator pointitr = polygonPtr->polygonpoints.begin(); 358 | // pointitr != polygonPtr->polygonpoints.end(); 359 | // pointitr++) { 360 | // sumX += round(topo_geometry::getX(*pointitr)); 361 | // sumY += round(topo_geometry::getY(*pointitr)); 362 | // } 363 | // 364 | // VoriGraphHalfEdge *twinHalfedge = voriHalfEdgeItr->twin; 365 | // if (twinHalfedge) { 366 | // halfEdgeSet.insert(twinHalfedge); 367 | // VoriGraphPolygon *twinpolygonPtr = twinHalfedge->pathFace; 368 | // if (twinpolygonPtr != 0) { 369 | // QPolygon twin_poly; 370 | // for (std::list::iterator pointitr = twinpolygonPtr->polygonpoints.begin(); 371 | // pointitr != twinpolygonPtr->polygonpoints.end(); 372 | // pointitr++) { 373 | // sumX += round(topo_geometry::getX(*pointitr)); 374 | // sumY += round(topo_geometry::getY(*pointitr)); 375 | // } 376 | // } 377 | // } 378 | // sumX /= (polygonPtr->polygonpoints.size() + twinHalfedge->pathFace->polygonpoints.size()); 379 | // sumY /= (polygonPtr->polygonpoints.size() + twinHalfedge->pathFace->polygonpoints.size()); 380 | // }//if(polygonPtr != 0) 381 | // if ((sumX) * (sumY) < 0.00000001) { 382 | // std::cout << "This shouldn't happen, right"; 383 | // } 384 | // 385 | // 386 | // 387 | // //build a roomVertex for each edge 388 | // roomVertex *tmp_rv = new roomVertex(voriHalfEdgeItr->roomId, topo_geometry::point(sumX, sumY), 389 | // voriHalfEdgeItr->source->point, voriHalfEdgeItr->target->point); 390 | // //append edge into pathes list then transform to PPEdge 391 | // tmp_rv->areaInnerPathes.push_back(&*voriHalfEdgeItr); 392 | // tmp_rv->areaInnerPathes.push_back(voriHalfEdgeItr->twin); 393 | // tmp_rv->init_areaInnerPPGraph(); 394 | // 395 | // 396 | // if (polygonPtr) 397 | // tmp_rv->polygons.push_back(polygonPtr); 398 | // if (voriHalfEdgeItr->twin->pathFace) 399 | // tmp_rv->polygons.push_back(voriHalfEdgeItr->twin->pathFace); 400 | // //insert roomVertex into the originSet 401 | // originSet.push_back(tmp_rv); 402 | // 403 | // }//end else 404 | // }//end for 405 | //} 406 | 407 | 408 | void RMG::AreaGraph::buildAreaGraph(VoriGraph &voriGraph) { 409 | VoriGraph::VertexMap::iterator vertexItr; 410 | 411 | std::set halfEdgeSet; 412 | std::map hE2rV; 413 | for (vertexItr = voriGraph.vertices.begin(); vertexItr != voriGraph.vertices.end(); vertexItr++) { 414 | int conCnt = vertexItr->second.edgesConnected.size(); 415 | passageEdge *curr_passage; 416 | if (conCnt >= 4) { 417 | if (conCnt == 4) { 418 | // curr_passage = new passageEdge(vertexItr->first, false); 419 | passageEdge *tmp_passage(new passageEdge(vertexItr->first, false)); 420 | curr_passage = tmp_passage; 421 | } else if (conCnt > 4) { 422 | // curr_passage = new passageEdge(vertexItr->first, true); 423 | passageEdge *tmp_passage(new passageEdge(vertexItr->first, true)); 424 | curr_passage = tmp_passage; 425 | } 426 | passageEList.push_back(curr_passage); 427 | } else { // if the vertex is a dead end or zero degree 428 | // std::cout<<"conCnt="<first.x()<<" , "<first.y()<<" ) "<::iterator hitr = vertexItr->second.edgesConnected.begin(); 433 | hitr != vertexItr->second.edgesConnected.end(); hitr++) { 434 | if ((*hitr)->isRay()) { 435 | conCnt--; 436 | continue; 437 | } 438 | 439 | std::set::iterator hfound = halfEdgeSet.find( 440 | *hitr); //WARNING: This check may cause the vertex not being recorded as a passage of this roomVertex 441 | if (hfound == halfEdgeSet.end()) { 442 | halfEdgeSet.insert(*hitr); 443 | VoriGraphPolygon *polygonPtr = (*hitr)->pathFace; 444 | if (polygonPtr) { 445 | VoriGraphHalfEdge *twinHalfedge = (*hitr)->twin; 446 | if (twinHalfedge) { 447 | halfEdgeSet.insert(twinHalfedge); 448 | VoriGraphPolygon *twpolygonPtr = twinHalfedge->pathFace; 449 | if (twpolygonPtr) { 450 | // CHANGE: just create this halfedge as a roomVertex when both its twin(must has) and it have and path face 451 | double cx = (*hitr)->source->point.x() + (*hitr)->target->point.x(); 452 | cx /= 2.0; 453 | double cy = (*hitr)->source->point.y() + (*hitr)->target->point.y(); 454 | cy /= 2.0; 455 | topo_geometry::point c(cx, cy); 456 | // std::cout<<"creating roomVertex: roomId="<<(*hitr)->roomId<<", center="; 457 | // coutpoint(c); std::cout<roomId, c, 459 | (*hitr)->source->point, (*hitr)->target->point)); 460 | curr_rv->areaInnerPathes.push_back(*hitr); 461 | curr_rv->areaInnerPathes.push_back(twinHalfedge); 462 | curr_rv->init_areaInnerPPGraph(); 463 | curr_rv->polygons.push_back(polygonPtr); 464 | curr_rv->polygons.push_back(twpolygonPtr); 465 | originSet.push_back(curr_rv); 466 | 467 | hE2rV[*hitr] = curr_rv; 468 | hE2rV[twinHalfedge] = curr_rv; 469 | 470 | 471 | //push the new roomVertex as the passage's connected areas 472 | curr_passage->connectedAreas.push_back(curr_rv); 473 | // curr_rv->passages.push_back(curr_passage); 474 | curr_rv->passages.push_back(curr_passage); 475 | 476 | } else { 477 | coutpoint(twinHalfedge->source->point); 478 | std::cout << "->"; 479 | coutpoint(twinHalfedge->target->point); 480 | std::cout << "has no path face!" << std::endl; 481 | } 482 | } else { 483 | coutpoint((*hitr)->source->point); 484 | std::cout << "->"; 485 | coutpoint((*hitr)->target->point); 486 | std::cout << "has no twin halfedge!" << std::endl; 487 | } 488 | 489 | } else { 490 | coutpoint((*hitr)->source->point); 491 | std::cout << "->"; 492 | coutpoint((*hitr)->target->point); 493 | std::cout << "has no path face!" << std::endl; 494 | } 495 | 496 | } else { 497 | if (hE2rV.find(*hitr) != hE2rV.end()) { 498 | roomVertex *f_rv = hE2rV[*hitr]; 499 | 500 | std::vector::iterator it = f_rv->passages.begin(); 501 | for (; it != f_rv->passages.end(); it++) { 502 | if (*it == curr_passage) 503 | break; 504 | } 505 | if (it == f_rv->passages.end()) { 506 | curr_passage->connectedAreas.push_back(f_rv); 507 | f_rv->passages.push_back(curr_passage); 508 | } 509 | } 510 | // if ((*hitr)->pathFace && (*hitr)->twin->pathFace) { 511 | // curr_passage->connectedAreas.push_back(hE2rV[*hitr]); 512 | // hE2rV[*hitr]->passages.push_back(curr_passage); 513 | // } 514 | } 515 | } 516 | } 517 | } 518 | 519 | 520 | void RMG::AreaGraph::mergeRoomPolygons() { 521 | for (std::vector::iterator it = this->originSet.begin(); 522 | it != this->originSet.end(); it++) 523 | (*it)->mergePolygons(); 524 | } 525 | 526 | 527 | static void check_redun_pair(std::vector > &edges, 528 | std::pair new_pair); 529 | 530 | static double calc_poly_area(std::list &polygon); 531 | 532 | void RMG::roomVertex::mergePolygons() { 533 | //1. traverse all of the pairs(edge) and insert it into vector, 534 | //if there is a redundent, delete this edge 535 | //(Because considering the redun count can only be 0 or 1) 536 | //2. store those outer vertex in order 537 | if (this->polygons.size() < 2) { 538 | this->polygon = (*(this->polygons.begin()))->polygonpoints; 539 | return; 540 | } 541 | //1. 542 | std::vector > edges;//store all of those vertices 543 | //each polygon 544 | for (std::vector::iterator it = this->polygons.begin(); it != this->polygons.end(); it++) { 545 | if ((*it)->polygonpoints.size() < 2) 546 | continue; 547 | topo_geometry::point firstGeoP = *((*it)->polygonpoints.begin()); 548 | //each polygon vertex 549 | std::list::iterator itj = (*it)->polygonpoints.begin(); 550 | std::list::iterator itj_next = itj; 551 | 552 | for (itj_next++; itj_next != (*it)->polygonpoints.end();) { 553 | 554 | 555 | std::pair new_pair(*itj, *itj_next); 556 | //check redundent 557 | check_redun_pair(edges, new_pair); 558 | itj_next = ++itj; 559 | itj_next++; 560 | } 561 | check_redun_pair(edges, std::pair(firstGeoP, *itj)); 562 | } 563 | //2. 564 | std::pair first_pair = *(edges.rbegin()); 565 | 566 | std::list tmp_polygon; 567 | tmp_polygon.push_back(first_pair.first); 568 | 569 | topo_geometry::point pair_tail = first_pair.second; 570 | double area_max = 0; 571 | while (!edges.empty()) { 572 | std::vector >::iterator itp = edges.begin(); 573 | 574 | for (; itp != edges.end(); itp++) { 575 | if (equalLineVertex(pair_tail, itp->first)) { 576 | tmp_polygon.push_back(pair_tail); 577 | 578 | pair_tail = itp->second; 579 | // this->polygon.push_back(pair_tail); 580 | break; 581 | } 582 | if (equalLineVertex(pair_tail, itp->second)) { 583 | tmp_polygon.push_back(pair_tail); 584 | 585 | pair_tail = itp->first; 586 | // this->polygon.push_back(pair_tail); 587 | break; 588 | } 589 | } 590 | 591 | if (itp != edges.end()) { 592 | 593 | edges.erase(itp); 594 | } else { 595 | tmp_polygon.push_back(pair_tail); 596 | 597 | double tmp_area = calc_poly_area(tmp_polygon); 598 | //std::cout << tmp_area< area_max) { 600 | area_max = tmp_area; 601 | this->polygon = tmp_polygon; 602 | } 603 | tmp_polygon.clear(); 604 | //inner poly or outter poly, new poly 605 | first_pair = *(edges.rbegin()); 606 | //edges.pop_back(); 607 | tmp_polygon.push_back(first_pair.first); 608 | pair_tail = first_pair.second; 609 | } 610 | } 611 | double tmp_area = calc_poly_area(tmp_polygon); 612 | //std::cout << tmp_area< area_max) { 614 | area_max = tmp_area; 615 | this->polygon = tmp_polygon; 616 | } 617 | 618 | } 619 | 620 | /* 621 | *Tools only for this cpp 622 | */ 623 | static double calc_poly_area(std::list &polygon) { 624 | double area = 0; 625 | std::list::iterator itj = polygon.end(); 626 | itj--; 627 | for (std::list::iterator it = polygon.begin(); it != polygon.end(); it++) { 628 | area += ((topo_geometry::getX(*itj) * topo_geometry::getX(*it)) * 629 | (topo_geometry::getY(*itj) - topo_geometry::getY(*it))); 630 | itj = it; 631 | } 632 | return std::abs(area / 2.0); 633 | } 634 | 635 | static void check_redun_pair(std::vector > &edges, 636 | std::pair new_pair) { 637 | //check redundent 638 | std::vector >::iterator itk = edges.begin(); 639 | for (; itk != edges.end(); itk++) { 640 | if ((equalLineVertex(itk->first, new_pair.first) && equalLineVertex(itk->second, new_pair.second)) || 641 | (equalLineVertex(itk->first, new_pair.second) && equalLineVertex(itk->second, new_pair.first))) 642 | break; 643 | } 644 | //if fund redun, erase 645 | if (itk != edges.end()) { 646 | edges.erase(itk); 647 | } 648 | //if not found redun, insert 649 | else { 650 | //check self.connect edge 651 | if (!equalLineVertex(new_pair.first, new_pair.second)) 652 | edges.push_back(new_pair); 653 | } 654 | } 655 | 656 | static bool equalLineVertex(const topo_geometry::point &a, const topo_geometry::point &b) { 657 | if ((topo_geometry::getX(a)) == (topo_geometry::getX(b)) 658 | && 659 | (topo_geometry::getY(a)) == (topo_geometry::getY(b))) { 660 | if ((topo_geometry::getX(a)) == 0 && (topo_geometry::getY(a)) == 0) 661 | /* 662 | if((round(topo_geometry::getX(a))) == (round(topo_geometry::getX(b))) 663 | && 664 | (round(topo_geometry::getY(a))) == (round(topo_geometry::getY(b))) ){ 665 | if((round(topo_geometry::getX(a))) ==0 && (round(topo_geometry::getY(a))) == 0 ) 666 | */ 667 | return false; 668 | //std::cout << "True match: " << round(topo_geometry::getX(a))<<" " < 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "VoriGraph.h" 17 | #include "TopoGraph.h" 18 | #include "cgal/CgalVoronoi.h" 19 | #include "cgal/AlphaShape.h" 20 | #include "qt/QImageVoronoi.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | 30 | #include "RoomDect.h" 31 | 32 | #include "roomGraph.h" 33 | #include "Denoise.h" 34 | #include 35 | #include 36 | 37 | #include "cgal/AlphaShapeRemoval.h" 38 | 39 | using namespace std; 40 | 41 | #include 42 | 43 | template 44 | std::string NumberToString(T Number) { 45 | std::ostringstream ss; 46 | ss << Number; 47 | return ss.str(); 48 | } 49 | 50 | int nearint(double a) { 51 | return ceil( a ) - a < 0.5 ? ceil( a ) : floor( a ); 52 | } 53 | 54 | VoriConfig *sConfig; 55 | 56 | int main(int argc, char *argv[]) { 57 | if (argc < 2) { 58 | cout << "Usage " << argv[0] 59 | << " RGBimage.png " 60 | << endl; 61 | return 255; 62 | } 63 | double door_wide = 1.15, corridor_wide = 2, res = 0.05; 64 | double noise_percent = 1.5; 65 | bool record_time = false; 66 | if (argc > 2) { 67 | res = atof( argv[2] ); 68 | if (argc > 4) { 69 | door_wide = atof( argv[3] ) == -1 ? 1.15 : atof( argv[3] ); 70 | corridor_wide = atof( argv[4] ) == -1 ? 1.35 : atof( argv[4] ); 71 | 72 | if (argc > 5) { 73 | noise_percent = atof( argv[5] ); 74 | if (argc > 6) 75 | record_time = true; 76 | } 77 | } 78 | } 79 | 80 | sConfig = new VoriConfig(); 81 | sConfig->doubleConfigVars["alphaShapeRemovalSquaredSize"] = 625; 82 | sConfig->doubleConfigVars["firstDeadEndRemovalDistance"] = 100000; 83 | sConfig->doubleConfigVars["secondDeadEndRemovalDistance"] = -100000; 84 | sConfig->doubleConfigVars["thirdDeadEndRemovalDistance"] = 0.25 / res; 85 | sConfig->doubleConfigVars["fourthDeadEndRemovalDistance"] = 8; 86 | sConfig->doubleConfigVars["topoGraphAngleCalcEndDistance"] = 10; 87 | sConfig->doubleConfigVars["topoGraphAngleCalcStartDistance"] = 3; 88 | sConfig->doubleConfigVars["topoGraphAngleCalcStepSize"] = 0.1; 89 | sConfig->doubleConfigVars["topoGraphDistanceToJoinVertices"] = 10; 90 | sConfig->doubleConfigVars["topoGraphMarkAsFeatureEdgeLength"] = 16; 91 | sConfig->doubleConfigVars["voronoiMinimumDistanceToObstacle"] = 0.25 / res; 92 | sConfig->doubleConfigVars["topoGraphDistanceToJoinVertices"] = 4; 93 | 94 | 95 | clock_t start; 96 | start = clock(); 97 | 98 | int black_threshold = 210; 99 | bool de = DenoiseImg( argv[1], "clean.png", black_threshold, 18, noise_percent ); 100 | if (de) 101 | cout << "Denoise run successed!!" << endl; 102 | 103 | clock_t afterDenoise = clock(); 104 | QImage test; 105 | test.load( "clean.png" ); 106 | 107 | bool isTriple; 108 | analyseImage( test, isTriple ); 109 | 110 | double AlphaShapeSquaredDist = 111 | (sConfig->voronoiMinimumDistanceToObstacle()) * (sConfig->voronoiMinimumDistanceToObstacle()); 112 | performAlphaRemoval( test, AlphaShapeSquaredDist, MAX_PLEN_REMOVAL ); 113 | test.save( "afterAlphaRemoval.png" ); 114 | 115 | clock_t afterAlphaRemoval = clock(); 116 | std::vector sites; 117 | bool ret = getSites( test, sites ); 118 | 119 | int remove_alpha_value = 3600; 120 | double a = door_wide < corridor_wide ? door_wide + 0.1 : corridor_wide - 0.1; 121 | int alpha_value = ceil( a * a * 0.25 / (res * res)); 122 | sConfig->doubleConfigVars["alphaShapeRemovalSquaredSize"] = alpha_value; 123 | std::cout << "a = " << a << ", where alpha = " << alpha_value << std::endl; 124 | clock_t loop_start = clock(); 125 | // create the voronoi graph and vori graph 126 | VoriGraph voriGraph; 127 | ret = createVoriGraph( sites, voriGraph, sConfig ); 128 | printGraphStatistics( voriGraph ); 129 | 130 | clock_t generatedVG = clock(); 131 | QImage alpha = test; 132 | AlphaShapePolygon alphaSP, tem_alphaSP; 133 | AlphaShapePolygon::Polygon_2 *poly = alphaSP.performAlpha_biggestArea( alpha, remove_alpha_value, true ); 134 | if (poly) { 135 | cout << "Removing vertices outside of polygon" << endl; 136 | removeOutsidePolygon( voriGraph, *poly ); 137 | } 138 | AlphaShapePolygon::Polygon_2 *tem_poly = tem_alphaSP.performAlpha_biggestArea( alpha, 139 | sConfig->alphaShapeRemovalSquaredSize(), 140 | false ); 141 | voriGraph.joinHalfEdges_jiawei(); 142 | cout << "size of Polygons: " << tem_alphaSP.sizeOfPolygons() << endl; 143 | 144 | clock_t rmOut = clock(); 145 | std::list::iterator> zeroHalfEdge; 146 | for (std::list::iterator pathEdgeItr = voriGraph.halfEdges.begin(); 147 | pathEdgeItr != voriGraph.halfEdges.end(); pathEdgeItr++) { 148 | if (pathEdgeItr->distance <= EPSINON) { 149 | zeroHalfEdge.push_back( pathEdgeItr ); 150 | } 151 | } 152 | for (std::list::iterator>::iterator zeroHalfEdgeItr = zeroHalfEdge.begin(); 153 | zeroHalfEdgeItr != zeroHalfEdge.end(); zeroHalfEdgeItr++) { 154 | voriGraph.removeHalfEdge_jiawei( *zeroHalfEdgeItr ); 155 | } 156 | 157 | clock_t zeroHf = clock(); 158 | if (sConfig->firstDeadEndRemovalDistance() > 0.) { 159 | voriGraph.markDeadEnds(); 160 | removeDeadEnds_addFacetoPolygon( voriGraph, 161 | sConfig->firstDeadEndRemovalDistance()); 162 | voriGraph.joinHalfEdges_jiawei(); 163 | } 164 | if (sConfig->secondDeadEndRemovalDistance() > 0.) { 165 | voriGraph.markDeadEnds(); 166 | removeDeadEnds_addFacetoPolygon( voriGraph, sConfig->secondDeadEndRemovalDistance()); 167 | voriGraph.joinHalfEdges_jiawei(); 168 | } 169 | 170 | gernerateGroupId( voriGraph ); 171 | keepBiggestGroup( voriGraph ); 172 | 173 | removeRays( voriGraph ); 174 | voriGraph.joinHalfEdges_jiawei(); 175 | 176 | if (sConfig->thirdDeadEndRemovalDistance() > 0.) { 177 | voriGraph.markDeadEnds(); 178 | removeDeadEnds_addFacetoPolygon( voriGraph, sConfig->thirdDeadEndRemovalDistance()); 179 | voriGraph.joinHalfEdges_jiawei(); 180 | // printGraphStatistics(voriGraph, "Third dead ends"); 181 | } 182 | if (sConfig->fourthDeadEndRemovalDistance() > 0.) { 183 | voriGraph.markDeadEnds(); 184 | removeDeadEnds_addFacetoPolygon( voriGraph, sConfig->fourthDeadEndRemovalDistance()); 185 | voriGraph.joinHalfEdges_jiawei(); 186 | // printGraphStatistics(voriGraph, "Fourth dead ends"); 187 | } 188 | 189 | clock_t DeadEndRemoval = clock(); 190 | 191 | RoomDect roomtest; 192 | roomtest.forRoomDect( tem_alphaSP, voriGraph, tem_poly ); 193 | 194 | clock_t roomDetect = clock(); 195 | 196 | QImage dectRoom = test; 197 | paintVori_onlyArea( dectRoom, voriGraph ); 198 | string tem_s = NumberToString( nearint( a * 100 )) + ".png"; 199 | dectRoom.save( tem_s.c_str()); 200 | 201 | clock_t beforeMerge = clock(); 202 | 203 | RMG::AreaGraph RMGraph( voriGraph ); 204 | RMGraph.mergeAreas(); 205 | RMGraph.mergeRoomCell(); 206 | RMGraph.prunning(); 207 | RMGraph.arrangeRoomId(); 208 | RMGraph.show(); 209 | 210 | clock_t geneAG = clock(); 211 | double t_wholeloop = geneAG - start; 212 | 213 | RMGraph.mergeRoomPolygons(); 214 | std::cout << "Area Graph generation use time (including denoising pre-processiong): " << t_wholeloop / CLOCKS_PER_SEC << std::endl; 215 | std::cout << "Area Graph generation use time: " << (double)(geneAG-afterAlphaRemoval) / CLOCKS_PER_SEC << std::endl; 216 | 217 | // QImage RMGIm = test; 218 | // RMGraph.draw( RMGIm ); 219 | // RMGIm.save( "roomGraph.png" ); 220 | return 0; 221 | } 222 | --------------------------------------------------------------------------------