├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── examples ├── ex101_creating_a_plot.cc ├── ex102_mouse_and_keyboard_events.cc ├── ex103_multiple_plots.cc ├── ex104_style_and_color.cc ├── ex105_axes.cc ├── ex106_surface_and_contour.cc ├── ex107_3d_line_and_surface.cc └── ex108_animation.cc ├── include └── matplotpp │ ├── gl2ps.h │ └── matplotpp.h └── src ├── gl2ps.c └── matplotpp.cc /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | build/ 31 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required ( VERSION 2.8.12.2 ) 2 | project ( matplotpp ) 3 | 4 | list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules ) 5 | find_package ( OpenGL REQUIRED ) 6 | find_package ( GLEW REQUIRED ) 7 | find_package ( GLUT REQUIRED ) 8 | 9 | set ( COMMON_INCLUDES ${PROJECT_SOURCE_DIR}/include ) 10 | 11 | include_directories ( 12 | ${COMMON_INCLUDES} 13 | ${OPENGL_INCLUDE_DIRS} 14 | ${GLEW_INCLUDE_DIRS} 15 | ${GLUT_INCLUDE_DIRS} 16 | ) 17 | 18 | # Library 19 | 20 | set ( LINK_LIBS ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ) 21 | 22 | file ( GLOB SRCS ${PROJECT_SOURCE_DIR}/src/*.* ) 23 | 24 | add_library ( matplotpp STATIC ${SRCS} ) 25 | 26 | target_include_directories ( matplotpp PUBLIC ${COMMON_INCLUDES} ) 27 | 28 | target_link_libraries ( matplotpp LINK_PUBLIC ${LINK_LIBS} ) 29 | 30 | install ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include ) 31 | install ( TARGETS matplotpp DESTINATION lib ) 32 | 33 | # Examples 34 | 35 | function ( add_example EX_PATH ) 36 | get_filename_component ( EX_NAME ${EX_PATH} NAME_WE ) 37 | add_executable ( ${EX_NAME} ${EX_PATH} ) 38 | target_link_libraries ( ${EX_NAME} matplotpp ) 39 | endfunction ( add_example ) 40 | 41 | file ( GLOB EXAMPLES ${PROJECT_SOURCE_DIR}/examples/*.cc ) 42 | 43 | foreach ( EXAMPLE ${EXAMPLES} ) 44 | add_example ( ${EXAMPLE} ) 45 | endforeach ( EXAMPLE ) 46 | -------------------------------------------------------------------------------- /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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # matplotpp 2 | **MATPLOT++** is a Matlab like simple plotting framework in C++. In cases where you need to make plots of data generated in C/C++, `matplotpp` enables you to generate 2D/3D plots, histograms, scatterplots, etc, just by adding a few lines of code, without any external plotting tool such as MATLAB or Gnuplot. 3 | 4 | ![logo](https://github.com/yuichikatori/matplotpp/wiki/images/logo.png) 5 | 6 | MATPLOT++ features are the following: 7 | * MATLAB like command set. 8 | * Cross platform compatibility on Linux, MacOS, and Windows. `matplotpp` is based on **OpenGL/GLUT** which is a simple cross-platform windowing **API**. 9 | * High quality vector output: PS, EPS, PDF, and SVG. 10 | 11 | # Note 12 | This repository is a fork of the [matplotpp](https://code.google.com/p/matplotpp/) library by **Yuichi Katori**. The repository is not maintained. It is merely a modified version of the project that uses `cmake`. 13 | 14 | # Dependencies 15 | To install the required dependencies on Linux/Ubuntu, run 16 | ```bash 17 | sudo apt-get install freeglut3-dev libglew-dev 18 | ``` 19 | 20 | # Compilation 21 | 22 | ```bash 23 | git clone https://github.com/nlamprian/matplotpp.git 24 | cd matplotpp 25 | 26 | mkdir build 27 | cd build 28 | 29 | # to configure and compile 30 | cmake .. 31 | make 32 | 33 | # to run the examples (e.g.) 34 | ./ex101_creating_a_plot 35 | 36 | # to install the library 37 | sudo make install 38 | ``` 39 | -------------------------------------------------------------------------------- /examples/ex101_creating_a_plot.cc: -------------------------------------------------------------------------------- 1 | //Copyright (c) 2011 Yuichi Katori All Rights Reserved 2 | //Author: Yuichi Katori (yuichi.katori@gmail.com) 3 | using namespace std; 4 | #include 5 | class MP :public MatPlot{ 6 | void DISPLAY(){ 7 | vector x(100),y(100); 8 | for(int i=0;i<100;++i){ 9 | x[i]=0.1*i; 10 | y[i]=sin(x[i]); 11 | } 12 | plot(x,y); 13 | } 14 | }mp; 15 | void display(){ mp.display(); } 16 | void reshape(int w,int h){ mp.reshape(w,h); } 17 | int main(int argc,char* argv[]){ 18 | glutInit(&argc, argv); 19 | glutCreateWindow(100,100,400,300); 20 | glutDisplayFunc( display ); 21 | glutReshapeFunc( reshape ); 22 | glutMainLoop(); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /examples/ex102_mouse_and_keyboard_events.cc: -------------------------------------------------------------------------------- 1 | //Copyright (c) 2011 Yuichi Katori (yuichi.katori@gmail.com) All Rights Reserved 2 | using namespace std; 3 | #include 4 | class MP :public MatPlot{ 5 | void DISPLAY(){ 6 | vector x(100),y(100); 7 | for(int i=0;i<100;++i){ 8 | x[i]=0.1*i; 9 | y[i]=sin(x[i]); 10 | } 11 | plot(x,y); 12 | } 13 | }mp; 14 | void display(){mp.display(); } 15 | void reshape(int w,int h){ mp.reshape(w,h); } 16 | void idle( void ){glutPostRedisplay(); usleep(10000);} 17 | void mouse(int button, int state, int x, int y ){ mp.mouse(button,state,x,y); } 18 | void motion(int x, int y ){mp.motion(x,y); } 19 | void passive(int x, int y ){mp.passivemotion(x,y); } 20 | void keyboard(unsigned char key, int x, int y){mp.keyboard(key, x, y); } 21 | int main(int argc, char* argv[]){ 22 | glutInit(&argc, argv); 23 | glutCreateWindow(100,100,400,300); 24 | glutDisplayFunc( display ); 25 | glutReshapeFunc( reshape ); 26 | glutIdleFunc( idle ); 27 | glutMotionFunc( motion ); 28 | glutMouseFunc( mouse ); 29 | glutPassiveMotionFunc(passive); 30 | glutKeyboardFunc( keyboard ); 31 | glutMainLoop(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/ex103_multiple_plots.cc: -------------------------------------------------------------------------------- 1 | //Copyright (c) 2011 Yuichi Katori (yuichi.katori@gmail.com) All Rights Reserved 2 | using namespace std; 3 | #include 4 | class MP :public MatPlot{ 5 | void DISPLAY(){ 6 | int n=100; 7 | vector x(n),y1(n),y2(n),y3(n),y4(n); 8 | 9 | // Create test data 10 | for(int i=0;i 4 | class MP :public MatPlot{ 5 | void DISPLAY(){ 6 | 7 | // Create test data 8 | int n=100,m=10; 9 | vector x(n),y(n); 10 | x=linspace(0,10,n); 11 | vector > Y(m,vector(n)); 12 | for(int j=0;j 4 | class MP :public MatPlot{ 5 | void DISPLAY(){ 6 | 7 | // create test data 8 | int n=100; 9 | float d=0.4; 10 | vector x(n),y1(n),y2(n),y3(n),y4(n); 11 | for(int i=0;i 4 | class MP :public MatPlot{ 5 | void DISPLAY(){ 6 | // Prepare test data 7 | int n=100; 8 | vector x,y,z; 9 | x=linspace(-2,2,n); 10 | y=linspace(-2,2,n); 11 | vector< vector< double > > Z(n,vector(n)),C(n,vector(n)); 12 | for(int i=0;i 4 | class MP :public MatPlot{ 5 | void DISPLAY(){ 6 | 7 | // Prepare test data 8 | int n=50; 9 | vector x,y,z; 10 | x=linspace(-2,2,n); 11 | y=linspace(-2,2,n); 12 | vector< vector< double > > Z(n,vector(n)),C(n,vector(n)); 13 | for(int i=0;i 4 | 5 | int is_run=1; 6 | double t=0;// time 7 | 8 | class MP :public MatPlot{ 9 | void DISPLAY(){ 10 | // Create test data 11 | int n=40; 12 | dvec x,y,z; 13 | x=linspace(-2,2,n); 14 | y=linspace(-2,2,n); 15 | dmat Z(n,dvec(n)); 16 | double r2; 17 | for(int i=0;i. 34 | */ 35 | 36 | #ifndef __GL2PS_H__ 37 | #define __GL2PS_H__ 38 | 39 | #include 40 | #include 41 | 42 | /* Define GL2PSDLL at compile time to build a Windows DLL */ 43 | 44 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) 45 | # if defined(_MSC_VER) 46 | # pragma warning(disable:4115) 47 | # pragma warning(disable:4996) 48 | # endif 49 | # include 50 | # if defined(GL2PSDLL) 51 | # if defined(GL2PSDLL_EXPORTS) 52 | # define GL2PSDLL_API __declspec(dllexport) 53 | # else 54 | # define GL2PSDLL_API __declspec(dllimport) 55 | # endif 56 | # else 57 | # define GL2PSDLL_API 58 | # endif 59 | #else 60 | # define GL2PSDLL_API 61 | #endif 62 | 63 | #if defined(__APPLE__) || defined(HAVE_OPENGL_GL_H) 64 | # include 65 | #else 66 | # include 67 | #endif 68 | 69 | /* Support for compressed PostScript/PDF/SVG and for embedded PNG 70 | images in SVG */ 71 | 72 | #if defined(HAVE_ZLIB) || defined(HAVE_LIBZ) 73 | # define GL2PS_HAVE_ZLIB 74 | # if defined(HAVE_LIBPNG) || defined(HAVE_PNG) 75 | # define GL2PS_HAVE_LIBPNG 76 | # endif 77 | #endif 78 | 79 | /* Version number */ 80 | 81 | #define GL2PS_MAJOR_VERSION 1 82 | #define GL2PS_MINOR_VERSION 3 83 | #define GL2PS_PATCH_VERSION 5 84 | #define GL2PS_EXTRA_VERSION "" 85 | 86 | #define GL2PS_VERSION (GL2PS_MAJOR_VERSION + \ 87 | 0.01 * GL2PS_MINOR_VERSION + \ 88 | 0.0001 * GL2PS_PATCH_VERSION) 89 | 90 | #define GL2PS_COPYRIGHT "(C) 1999-2009 C. Geuzaine" 91 | 92 | /* Output file formats (the values and the ordering are important!) */ 93 | 94 | #define GL2PS_PS 0 95 | #define GL2PS_EPS 1 96 | #define GL2PS_TEX 2 97 | #define GL2PS_PDF 3 98 | #define GL2PS_SVG 4 99 | #define GL2PS_PGF 5 100 | 101 | /* Sorting algorithms */ 102 | 103 | #define GL2PS_NO_SORT 1 104 | #define GL2PS_SIMPLE_SORT 2 105 | #define GL2PS_BSP_SORT 3 106 | 107 | /* Message levels and error codes */ 108 | 109 | #define GL2PS_SUCCESS 0 110 | #define GL2PS_INFO 1 111 | #define GL2PS_WARNING 2 112 | #define GL2PS_ERROR 3 113 | #define GL2PS_NO_FEEDBACK 4 114 | #define GL2PS_OVERFLOW 5 115 | #define GL2PS_UNINITIALIZED 6 116 | 117 | /* Options for gl2psBeginPage */ 118 | 119 | #define GL2PS_NONE 0 120 | #define GL2PS_DRAW_BACKGROUND (1<<0) 121 | #define GL2PS_SIMPLE_LINE_OFFSET (1<<1) 122 | #define GL2PS_SILENT (1<<2) 123 | #define GL2PS_BEST_ROOT (1<<3) 124 | #define GL2PS_OCCLUSION_CULL (1<<4) 125 | #define GL2PS_NO_TEXT (1<<5) 126 | #define GL2PS_LANDSCAPE (1<<6) 127 | #define GL2PS_NO_PS3_SHADING (1<<7) 128 | #define GL2PS_NO_PIXMAP (1<<8) 129 | #define GL2PS_USE_CURRENT_VIEWPORT (1<<9) 130 | #define GL2PS_COMPRESS (1<<10) 131 | #define GL2PS_NO_BLENDING (1<<11) 132 | #define GL2PS_TIGHT_BOUNDING_BOX (1<<12) 133 | 134 | /* Arguments for gl2psEnable/gl2psDisable */ 135 | 136 | #define GL2PS_POLYGON_OFFSET_FILL 1 137 | #define GL2PS_POLYGON_BOUNDARY 2 138 | #define GL2PS_LINE_STIPPLE 3 139 | #define GL2PS_BLEND 4 140 | 141 | /* Text alignment (o=raster position; default mode is BL): 142 | +---+ +---+ +---+ +---+ +---+ +---+ +-o-+ o---+ +---o 143 | | o | o | | o | | | | | | | | | | | | 144 | +---+ +---+ +---+ +-o-+ o---+ +---o +---+ +---+ +---+ 145 | C CL CR B BL BR T TL TR */ 146 | 147 | #define GL2PS_TEXT_C 1 148 | #define GL2PS_TEXT_CL 2 149 | #define GL2PS_TEXT_CR 3 150 | #define GL2PS_TEXT_B 4 151 | #define GL2PS_TEXT_BL 5 152 | #define GL2PS_TEXT_BR 6 153 | #define GL2PS_TEXT_T 7 154 | #define GL2PS_TEXT_TL 8 155 | #define GL2PS_TEXT_TR 9 156 | 157 | typedef GLfloat GL2PSrgba[4]; 158 | 159 | #if defined(__cplusplus) 160 | extern "C" { 161 | #endif 162 | 163 | GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, 164 | GLint viewport[4], GLint format, GLint sort, 165 | GLint options, GLint colormode, 166 | GLint colorsize, GL2PSrgba *colormap, 167 | GLint nr, GLint ng, GLint nb, GLint buffersize, 168 | FILE *stream, const char *filename); 169 | GL2PSDLL_API GLint gl2psEndPage(void); 170 | GL2PSDLL_API GLint gl2psSetOptions(GLint options); 171 | GL2PSDLL_API GLint gl2psGetOptions(GLint *options); 172 | GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4]); 173 | GL2PSDLL_API GLint gl2psEndViewport(void); 174 | GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, 175 | GLshort fontsize); 176 | GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, 177 | GLshort fontsize, GLint align, GLfloat angle); 178 | GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str); 179 | GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, 180 | GLint xorig, GLint yorig, 181 | GLenum format, GLenum type, const void *pixels); 182 | GL2PSDLL_API GLint gl2psEnable(GLint mode); 183 | GL2PSDLL_API GLint gl2psDisable(GLint mode); 184 | GL2PSDLL_API GLint gl2psPointSize(GLfloat value); 185 | GL2PSDLL_API GLint gl2psLineWidth(GLfloat value); 186 | GL2PSDLL_API GLint gl2psBlendFunc(GLenum sfactor, GLenum dfactor); 187 | 188 | /* undocumented */ 189 | GL2PSDLL_API GLint gl2psDrawImageMap(GLsizei width, GLsizei height, 190 | const GLfloat position[3], 191 | const unsigned char *imagemap); 192 | GL2PSDLL_API const char *gl2psGetFileExtension(GLint format); 193 | GL2PSDLL_API const char *gl2psGetFormatDescription(GLint format); 194 | 195 | #if defined(__cplusplus) 196 | } 197 | #endif 198 | 199 | #endif /* __GL2PS_H__ */ 200 | -------------------------------------------------------------------------------- /include/matplotpp/matplotpp.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2011 Yuichi Katori All Rights Reserved 3 | License: Gnu Public license (GPL) v3 4 | Author: Yuichi Katori (yuichi.katori@gmail.com) 5 | Project:MATPLOT++ (MATLAB-like plotting tool in C++). 6 | Version:0.3.13 7 | ****************************************************************************/ 8 | 9 | #ifndef __MATPLOTPP_H__ 10 | #define __MATPLOTPP_H__ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define PI 3.14159265358979323846264 25 | 26 | typedef vector dvec; 27 | typedef vector< vector > dmat; 28 | typedef vector< vector > tcvec; 29 | typedef vector< vector< vector > > tcmat; 30 | 31 | inline vector linspace(double min,double max,int n){ 32 | vector a; 33 | if(n<1){n=1;} 34 | a.resize(n); 35 | for(int i=0;i valinspace(double min,double max,int n){ 40 | valarray a; 41 | a.resize(n); 42 | for(int i=0;i Children; 65 | 66 | void add_child(int i); 67 | Figure(int id_){ 68 | id=id_; 69 | //Status=1; 70 | //Position[0]=100; 71 | //Position[1]=100; 72 | //Position[2]=800; 73 | //Position[3]=800; 74 | Visible=1; 75 | }; 76 | }; 77 | 78 | 79 | class Layer{/// 80 | public: 81 | int id; 82 | int Visible; 83 | string layername; 84 | vector Children; 85 | Layer(int id_); 86 | void add_child(int i); 87 | }; 88 | 89 | class Axes{/// 90 | private: 91 | 92 | protected: 93 | 94 | public: 95 | int id; 96 | 97 | float cta,phi; // controled by mouse 98 | float cta0,phi0;// default value or specified by command line 99 | // Mouse 100 | double XMouse,YMouse; 101 | int Mouse; 102 | 103 | double xmin,xmax,ymin,ymax,zmin,zmax; 104 | int num_child; 105 | 106 | void reset(); 107 | void config(); 108 | int ID(); 109 | int selected(); 110 | void selected(int i); 111 | void add_child(int i); 112 | dvec make_tick(double min,double max); 113 | 114 | int View;// 0:2D, 1:3D 115 | 116 | vector > ColorMap;// for colorbar 117 | 118 | // Matlab variables // 119 | // styles 120 | int Box;//0:Off, 1:On 121 | string GridLineStyle; 122 | float LineWidth; 123 | string TickDir;// {in} | out 124 | //string TickDirMode; 125 | //TickLength 126 | int Visible;//0:Off, 1:On 127 | int XGrid,YGrid,ZGrid;// {0:Off}, 1:On 128 | 129 | // General Information 130 | int Parent; 131 | vector Children; 132 | int Selected; 133 | float Position[4];//left bottom width height 134 | float Viewport3d[4];//left bottom width height 135 | 136 | //Scale 137 | string XAxisLocation; 138 | string YAxisLocation; 139 | 140 | //string XDir,YDir,ZDir; 141 | 142 | double XLim[2],YLim[2],ZLim[2];//plot range 143 | int XLimMode,YLimMode,ZLimMode;//0:Auto 1:Manual 144 | 145 | int XScale,YScale,ZScale;// linear | log 146 | 147 | dvec XTick,YTick,ZTick; 148 | string XTickMode,YTickMode,ZTickMode; 149 | int TickLabel;// 0:Off, {1:On} 150 | //View 151 | float CameraPosition[3]; 152 | float CameraTarget[3]; 153 | float CameraUpVector[3]; 154 | 155 | // Label 156 | string Title; 157 | string XLabel,YLabel,ZLabel; 158 | 159 | double CLim[2]; 160 | 161 | Axes(int id_){ 162 | id=id_; 163 | Selected=0; 164 | Position[0]=0.13; 165 | Position[1]=0.11; 166 | Position[2]=0.775; 167 | Position[3]=0.815; 168 | 169 | Viewport3d[0]=0.0; 170 | Viewport3d[1]=0.0; 171 | Viewport3d[2]=1.0; 172 | Viewport3d[3]=1.0; 173 | 174 | Mouse=1; 175 | View=0; 176 | Visible=1; 177 | Box=1; 178 | Children.clear(); 179 | 180 | cta0=30; 181 | phi0=30; 182 | cta=cta0; 183 | phi=cta0; 184 | 185 | CameraPosition[0]=1; CameraPosition[1]=1; CameraPosition[2]=1; 186 | CameraTarget[0]=0.; CameraTarget[1]=0; CameraTarget[2]=0; 187 | CameraUpVector[0]=0; CameraUpVector[1]=0; CameraUpVector[2]=1; 188 | 189 | LineWidth=1; 190 | 191 | GridLineStyle=":"; 192 | XGrid=0; 193 | YGrid=0; 194 | ZGrid=0; 195 | 196 | XLim[0]=0; XLim[1]=10; 197 | YLim[0]=0; YLim[1]=10; 198 | ZLim[0]=0; ZLim[1]=10; 199 | 200 | XLimMode=0; YLimMode=0; ZLimMode=0; 201 | XAxisLocation="bottom";//top | bottom 202 | YAxisLocation="left";// left | right 203 | XScale=0;// {0:linear} | 1:log 204 | YScale=0; 205 | ZScale=0; 206 | 207 | TickLabel=1; 208 | TickDir="in"; 209 | 210 | xmin= 1e99; xmax=-1e99; 211 | ymin= 1e99; ymax=-1e99; 212 | zmin= 1e99; zmax=-1e99; 213 | 214 | CLim[0]=0;CLim[1]=0; 215 | 216 | num_child=0; 217 | //MakeTick(); 218 | //Parent=i_figure; 219 | }; 220 | }; 221 | 222 | 223 | class Line{/// 224 | public: 225 | int id; 226 | int Errorbar; 227 | 228 | void reset(); 229 | void color(float r,float g,float b); 230 | 231 | // Matlab oriented variables // 232 | 233 | dvec XData,YData,ZData; 234 | dvec YPData,YMData; 235 | //dmat XData,YData,ZData; 236 | //dmat EData,UData,LData; 237 | //dmat VData,WData; 238 | 239 | string Color; 240 | string LineStyle;// {-} | - - | : | -. | none 241 | float LineWidth; 242 | string Marker;// {none} 243 | float MarkerSize; 244 | string MarkerEdgeColor; 245 | string MarkerFaceColor; 246 | 247 | int Clipping; 248 | //string EraseMode; 249 | int SelectionHighlight; 250 | int Visible; 251 | 252 | // General Information 253 | int Parent; 254 | int Selected; 255 | 256 | Line(int id_){ 257 | id=id_; 258 | 259 | Color="b"; 260 | LineStyle="-"; 261 | LineWidth=0.5; 262 | 263 | Marker="none"; 264 | MarkerSize=6; 265 | MarkerEdgeColor="k"; 266 | MarkerFaceColor="w"; 267 | 268 | Errorbar=0; 269 | //PlotStyle=0; 270 | } 271 | }; 272 | class Surface{/// 273 | public: 274 | int type; 275 | int id; 276 | string ColorMap; 277 | 278 | //dvec XData,YData; 279 | dmat XData,YData,ZData,CDataIndex; 280 | dvec V,UserData; 281 | tcmat CData; 282 | 283 | string FaceColor;//ColorSpec | none | {flat} 284 | string EdgeColor;//ColorSpec{k} | none | flat 285 | 286 | string LineStyle;// {-} | - - | : | -. | none 287 | float LineWidth; 288 | string Marker;// {none} 289 | float MarkerSize; 290 | string MarkerEdgeColor; 291 | string MarkerFaceColor; 292 | 293 | int Parent; 294 | 295 | int NContour; 296 | 297 | Surface(int id_){ 298 | id=id_; 299 | 300 | ColorMap="Gray"; 301 | //Shading="faceted"; 302 | FaceColor="flat"; 303 | EdgeColor="b"; 304 | LineStyle="-"; 305 | LineWidth=0.5; 306 | NContour=10; 307 | V.clear(); 308 | 309 | } 310 | void get(){ 311 | cout <<"FaceColor: "<< FaceColor < > Faces; 325 | dmat Vertices; 326 | dmat FaceVertexCData; 327 | dmat XData,YData,ZData; 328 | 329 | //dvec ICVec; 330 | //dmat ICMat; 331 | //tcmat CData; 332 | tcvec CData; 333 | 334 | string EdgeColor,FaceColor;//{ColorSpec}|none|flat|interp 335 | 336 | string LineStyle; // {-} | - - | : | -. | none 337 | float LineWidth; 338 | 339 | Patch(int id_){ 340 | id=id_; 341 | type=0; 342 | LineWidth=1; 343 | FaceColor="r"; 344 | EdgeColor="k"; 345 | LineStyle="-"; 346 | } 347 | }; 348 | //Note: XData[iv][if] 349 | 350 | class Text{/// 351 | public: 352 | int id; 353 | string String; 354 | float Position[3]; 355 | int Parent; 356 | int type;//0:axis 1:figure 357 | Text(int id_); 358 | }; 359 | 360 | 361 | 362 | const int tFigure=1; 363 | const int tAxes=2; 364 | const int tLine=3; 365 | const int tSurface=4; 366 | const int tText=5; 367 | const int tLayer=6; 368 | const int tPatch=7; 369 | 370 | /// contour 371 | struct ContourPoint{ 372 | double x,y; 373 | int xj,yi; 374 | int xy; 375 | int done; 376 | }; 377 | dmat contourc(dvec x, dvec y, dmat Z, dvec v); 378 | 379 | 380 | class MatPlot{/// 381 | private: 382 | int is_debug1; 383 | int is_debug2; 384 | 385 | vector > cmap;//TODO move to class Figure 386 | 387 | int mode;//0:initialization 1:configuration 388 | int init_level;// initialization level of objects 389 | int hObj;// handle number of current object 390 | 391 | int time_layer_clicked,time_layer_clicked_last; 392 | 393 | // Events // 394 | int window_w,window_h; 395 | float xButtonDown,yButtonDown;// last clicked mouse position 396 | float ctaButtonDown,phiButtonDown; 397 | int xPassive,yPassive; 398 | 399 | // pointer to current objects // 400 | Figure *cf; 401 | Layer *cfr; 402 | Axes *ca; 403 | Line *cl; 404 | Surface *cs; 405 | Patch *cp; 406 | Text *ct; 407 | 408 | // objects containers // 409 | vector< Figure > vFigure; 410 | vector< Layer > vLayer; 411 | vector< Axes > vAxes; 412 | vector< Line > vLine; 413 | vector< Surface > vSurface; 414 | vector< Patch > vPatch; 415 | vector< Text > vText; 416 | 417 | // objects counter // 418 | int iFigure; 419 | int iLayer; 420 | int iAxes; 421 | int iLine; 422 | int iSurface; 423 | int iPatch; 424 | int iText; 425 | 426 | // Selected object // 427 | int iAxesSelected; 428 | 429 | // coordinate transform // 430 | // figure coordination 431 | float ctx2(double x); 432 | float cty2(double y); 433 | // axes coordination 434 | float ctx(double x); 435 | float cty(double y); 436 | float ct3x(double x); 437 | float ct3y(double y); 438 | float ct3z(double z); 439 | 440 | int figure(); 441 | 442 | // display // 443 | void display_figure(); 444 | void display_layer(); 445 | void display_layer2(); 446 | 447 | void display_axes(); 448 | void display_axes_2d(); 449 | void display_axes_3d(); 450 | void display_axes_colorbar(); 451 | 452 | void display_line(); 453 | 454 | void display_surface(); 455 | void display_surface_2d(); 456 | void display_surface_3d(); 457 | void display_pcolor(); 458 | void display_contour(); 459 | 460 | void display_patch(); 461 | void display_patch_2d(); 462 | void display_patch_3d(); 463 | 464 | 465 | void display_bar(); 466 | 467 | void display_text(); 468 | 469 | // mouse // 470 | void Layer_mouse(int button, int state, int x, int y ); 471 | void Axes_mouse(int button, int state, int x, int y ); 472 | void Axes_motion(int x, int y ); 473 | 474 | 475 | void surface_config(); 476 | void line_config(); 477 | void patch_config(); 478 | tcvec Index2TrueColor(dvec IC); 479 | 480 | public: 481 | 482 | MatPlot(); 483 | ~MatPlot(); 484 | 485 | void virtual DISPLAY(){}; 486 | 487 | void inline debug1(){is_debug1=1;} 488 | void inline debug2(){is_debug2=1;} 489 | 490 | // GLUT Callback Functions /// 491 | void display(); 492 | void reshape(int w, int h); 493 | void mouse(int button, int state, int x, int y ); 494 | void motion(int x, int y ); 495 | void passivemotion(int x,int y); 496 | void keyboard(unsigned char key, int x, int y); 497 | 498 | // Layer /// 499 | int layer(); 500 | //int layer(string s); 501 | int layer(string s,int Visible); 502 | int frame(string s,int Visible);// do not use 503 | 504 | // Axes /// 505 | 506 | int axes(); 507 | int gca(); 508 | int subplot(int m,int n,int p); 509 | 510 | int colorbar(); 511 | 512 | void axis(double xMin,double xMax,double yMin,double yMax); 513 | void axis(double xMin,double xMax,double yMin,double yMax,double zMin,double zMax); 514 | 515 | void axis(string s); 516 | void axis(int s); 517 | 518 | void grid(string s); 519 | void grid(int s); 520 | 521 | void ticklabel(string s); 522 | void ticklabel(int s); 523 | 524 | void title(string s); 525 | void xlabel(string s); 526 | void ylabel(string s); 527 | void zlabel(string s); 528 | 529 | //void xlim(double min,double max); 530 | //void xlim(string s); 531 | 532 | //void legend(string s,int N); 533 | 534 | //int plotyy 535 | 536 | void mouse_capture(double *xmouse,double *ymouse); 537 | 538 | // set, General Object Handling /// 539 | void set(string v); 540 | void set(float v); 541 | void set(string p,float v); 542 | void set(string p,string v); 543 | void set(int h,string p,string v); 544 | void set(int h,string p,float v); 545 | int gco(); 546 | 547 | // Line /// 548 | 549 | int begin();//do not use 550 | void end();//do not use 551 | void vertex(double x,double y); 552 | void vertex(double x,double y,double z); 553 | 554 | int line(); 555 | int line(dvec x,dvec y); 556 | int line(dvec x,dvec y,dvec z); 557 | //line(X,Y) 558 | //line(X,Y,Z) 559 | 560 | int plot(dvec y); 561 | int plot(dvec x,dvec y); 562 | //int plot(dmat Y); 563 | //int plot(dvec x,dmat Y); 564 | //int plot(dmat X,dmat Y); 565 | int plot(valarray x,valarray y); 566 | 567 | int plot3(dvec x,dvec y,dvec z); 568 | //int plot3(dvec X,dvec Y,dvec Z); 569 | 570 | int semilogx(dvec x,dvec y); 571 | int semilogy(dvec x,dvec y); 572 | //int loglog(dvec y); 573 | int loglog(dvec x,dvec y); 574 | 575 | //int polar(dvec theta,dvec rho); 576 | 577 | void vertex(double x,double y,double ep,double em); 578 | int errorbar(dvec x,dvec y,dvec e); 579 | int errorbar(dvec x,dvec y,dvec ep,dvec em); 580 | 581 | //int quiver(U,V); 582 | //int quiver(X,Y,U,V); 583 | 584 | //int scatter(X,Y,S,C) 585 | //int scatter(X,Y,S) 586 | //int scatter(X,Y) 587 | 588 | // Surface, Contour /// 589 | dmat peaks(int n); 590 | //dmat peaks(int m,int n); 591 | //dmat peaks(int m,int n,string type); 592 | 593 | int surface(); 594 | int surface(dmat Z); 595 | int surface(dmat Z,dmat C); 596 | int surface(dmat Z,tcmat C); //!! 597 | int surface(dvec x,dvec y,dmat Z); 598 | int surface(dvec x,dvec y,dmat Z,dmat C); 599 | int surface(dvec x,dvec y,dmat Z,tcmat C);//!! 600 | int surface(dmat X,dmat Y,dmat Z); 601 | int surface(dmat X,dmat Y,dmat Z,dmat C); 602 | int surface(dmat X,dmat Y,dmat Z,tcmat C);//!! 603 | 604 | int pcolor(dmat C); 605 | int pcolor(tcmat C); 606 | int pcolor(dvec x,dvec y,dmat C); 607 | int pcolor(dvec x,dvec y,tcmat C); 608 | int pcolor(dmat X,dmat Y,dmat C); 609 | int pcolor(dmat X,dmat Y,tcmat C); 610 | 611 | int contour(dmat Z); 612 | int contour(dmat Z,int n); 613 | int contour(dmat Z,dvec v); 614 | int contour(dvec x, dvec y, dmat Z); 615 | int contour(dvec x, dvec y, dmat Z,int n); 616 | int contour(dvec x, dvec y, dmat Z,dvec v); 617 | //int contour(dmat X, dmat Y, dmat Z); 618 | //int contour(dmat X, dmat Y, dmat Z,int n); 619 | //int contour(dmat X, dmat Y, dmat Z,dvec v); 620 | 621 | //int mesh(dmat Z); 622 | //int mesh(dmat Z,dmat C); 623 | //int mesh(dmat Z,tcmat C); 624 | int mesh(dvec x, dvec y, dmat Z); 625 | //int mesh(dvec x, dvec y, dmat Z,dmat C); 626 | //int mesh(dvec x, dvec y, dmat Z,tcmat C); 627 | //int mesh(dmat X,dmat Y,dmat Z); 628 | //int mesh(dmat X,dmat Y,dmat Z,dmat C); 629 | //int mesh(dmat X,dmat Y,dmat Z,tcmat C); 630 | // meshc() 631 | // meshz() 632 | 633 | int surf(dvec x, dvec y, dmat Z); 634 | 635 | // Patch /// 636 | 637 | int patch(); 638 | int patch(dmat X,dmat Y); 639 | int patch(dmat X,dmat Y,dvec C); 640 | int patch(dmat X,dmat Y,tcvec C); 641 | int patch(dmat X,dmat Y,dmat Z);//!! 642 | int patch(dmat X,dmat Y,dmat Z,dvec C);//!! 643 | int patch(dmat X,dmat Y,dmat Z,tcvec C);//!! 644 | //int patch(dmat X,dmat Y,tcmat C); 645 | //int patch(dmat X,dmat Y,dmat Z,tcmat C); 646 | 647 | int bar(dvec y); 648 | int bar(dvec y,float width); 649 | int bar(dvec x,dvec y); 650 | int bar(dvec x,dvec y,float width); 651 | 652 | //int bar(Y) 653 | //int bar(Y,float width); 654 | //int bar(Y,string style); 655 | //int bar(Y,float width,string style); 656 | 657 | //int bar(x,Y) 658 | //int bar(x,Y,float width); 659 | //int bar(x,Y,string style); 660 | //int bar(x,Y,float width,string style); 661 | 662 | //int hist(y); 663 | //int hist(y,x); 664 | //int hist(y,nbins); 665 | 666 | //int pie(dvec x); 667 | //int pie(dvec x, vector Explode); 668 | 669 | // Text /// 670 | //TODO: more fonts 671 | int text(); 672 | int text(double x,double y,string s); 673 | void set_font(char font_[],int size); 674 | void ptext(float x,float y,string s); 675 | void ptext3(float x,float y,float z,string s); 676 | void ptext3c(float x,float y,float z,string s); 677 | 678 | // Colors /// 679 | void color(float r,float g,float b); 680 | vector colormap(string c,float t); 681 | void colormap(string c); 682 | void colormap(vector > c); 683 | 684 | void gray(); 685 | void jet(); 686 | void hsv(); 687 | void hot(); 688 | void cool(); 689 | void spring(); 690 | void summer(); 691 | void autumn(); 692 | void winter(); 693 | 694 | vector map2color(double x,double xmin,double xmax); 695 | 696 | void Shading(string c); 697 | void shading(string c); 698 | vector ColorSpec2RGB(string c); 699 | string rgb2colorspec(vector rgb); 700 | 701 | // print /// 702 | void print(); 703 | 704 | }; 705 | 706 | #endif /* __MATPLOTPP_H__ */ 707 | -------------------------------------------------------------------------------- /src/matplotpp.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2011 Yuichi Katori All Rights Reserved 3 | License: Gnu Public license (GPL) v3 4 | Author: Yuichi Katori (yuichi.katori@gmail.com) 5 | Project:MATPLOT++ (MATLAB-like plotting tool in C++). 6 | Version:0.3.13 7 | ****************************************************************************/ 8 | 9 | using namespace std; 10 | #include 11 | 12 | /// Figure 13 | void Figure::add_child(int i){Children.push_back(i);} 14 | /// Axes 15 | void Axes::reset(){ 16 | num_child=0; 17 | xmin=1e99; xmax=-1e99; 18 | ymin=1e99; ymax=-1e99; 19 | zmin=1e99; zmax=-1e99; 20 | } 21 | void Axes::config(){ 22 | float extent=0,extent_linear=0.03; 23 | if((XLimMode==0)&&(xmax>xmin)){ 24 | if(XScale==0){extent=extent_linear;} 25 | if(XScale==1){extent=0;} 26 | XLim[0]=xmin-extent*(xmax-xmin); 27 | XLim[1]=xmax+extent*(xmax-xmin); 28 | } 29 | if((YLimMode==0)&&(ymax>ymin)){ 30 | if(YScale==0){extent=extent_linear;} 31 | if(YScale==1){extent=0;} 32 | YLim[0]=ymin-extent*(ymax-ymin); 33 | YLim[1]=ymax+extent*(ymax-ymin); 34 | } 35 | if((ZLimMode==0)&&(zmax>zmin)){ 36 | ZLim[0]=zmin-extent*(zmax-zmin); 37 | ZLim[1]=zmax+extent*(zmax-zmin); 38 | } 39 | //printf("Z: %d,%f,%f\n",ZLimMode,ZLim[0],ZLim[1]); 40 | //if(num_child){Visible=1;}else{Visible=0;} 41 | 42 | XTick=make_tick(XLim[0],XLim[1]); 43 | YTick=make_tick(YLim[0],YLim[1]); 44 | ZTick=make_tick(ZLim[0],ZLim[1]); 45 | } 46 | 47 | int Axes::ID(){return id;} 48 | int Axes::selected(){return Selected;} 49 | void Axes::selected(int i){Selected=i;} 50 | void Axes::add_child(int i){Children.push_back(i);} 51 | 52 | dvec Axes::make_tick(double min,double max){ 53 | int i,j; 54 | double dg; 55 | double x,y; 56 | int z; 57 | x=fabs(max-min); 58 | z=(int)log10(x); 59 | y=x/pow((double)10,(double)z); 60 | dg=1*pow((double)10,(double)z); 61 | if(y<5){dg=0.5*pow((double)10,(double)z);} 62 | if(y<2){dg=0.2*pow((double)10,(double)z);} 63 | 64 | double min0; 65 | min0=min-fmod(min,dg);j=0; 66 | 67 | dvec tick; 68 | tick.clear(); 69 | if(max>min){ i=-2; while(max>=min0+dg*i){ if(min<=min0+dg*i){ tick.push_back(min0+dg*i); j++; } i+=1;} } 70 | if(max=min0-dg*i){ tick.push_back(min0-dg*i); j++; } i+=1;} } 71 | return tick; 72 | } 73 | 74 | 75 | /// Line 76 | 77 | void Line::reset(){ 78 | XData.clear(); 79 | YData.clear(); 80 | ZData.clear(); 81 | YPData.clear(); 82 | YMData.clear(); 83 | } 84 | void Line::color(float r,float g,float b){ 85 | //Color[0]=r; 86 | //Color[1]=g; 87 | //Color[2]=b; 88 | } 89 | /// Surface 90 | 91 | /// Text 92 | Text::Text(int id_){ 93 | id=id_; 94 | type=0; 95 | } 96 | 97 | 98 | /// Layer 99 | Layer::Layer(int id_){ 100 | id=id_; 101 | Children.clear(); 102 | } 103 | /// Patch 104 | 105 | void Layer::add_child(int i){Children.push_back(i);} 106 | 107 | //// MatPlot // 108 | MatPlot::MatPlot(){ 109 | is_debug1=0; 110 | is_debug2=0; 111 | 112 | if(is_debug1){cout<<"init()..."<Color[0]=r; 221 | //cl->Color[1]=g; 222 | //cl->Color[2]=b; 223 | } 224 | } 225 | // coordinate transform /// 226 | 227 | // figure coordination 228 | float MatPlot::ctx2(double x){ 229 | double t; 230 | if(ca->XScale==0){//linear 231 | return ca->Position[0] +ca->Position[2]*( (x-ca->XLim[0])/(ca->XLim[1]-ca->XLim[0]) ); 232 | } 233 | if(ca->XScale==1){//log 234 | t=( log10(x) - log10(ca->XLim[0]) )/( log10(ca->XLim[1])-log10(ca->XLim[0]) ); 235 | if(x<=0){t=-1;} 236 | return ca->Position[0] +ca->Position[2]*t; 237 | } 238 | 239 | } 240 | float MatPlot::cty2(double y){ 241 | if(ca->YScale==0){//linear 242 | return ca->Position[1] +ca->Position[3]*( (y-ca->YLim[0])/(ca->YLim[1]-ca->YLim[0]) ); 243 | } 244 | if(ca->YScale==1){//log 245 | return ca->Position[1] +ca->Position[3]*( log10(y) - log10(ca->YLim[0]) )/( log10(ca->YLim[1])-log10(ca->YLim[0]) ); 246 | } 247 | } 248 | // axes coordination 249 | float MatPlot::ctx(double x){ 250 | if(ca->XScale==0){//linear 251 | return (x-ca->XLim[0])/(ca->XLim[1]-ca->XLim[0]); 252 | } 253 | if(ca->XScale==1){//log 254 | return ( log10(x) - log10(ca->XLim[0]) )/( log10(ca->XLim[1])-log10(ca->XLim[0]) ); 255 | } 256 | } 257 | float MatPlot::cty(double y){ 258 | if(ca->YScale==0){//linear 259 | return (y-ca->YLim[0])/(ca->YLim[1]-ca->YLim[0]); 260 | } 261 | if(ca->YScale==1){//log 262 | return ( log10(y) - log10(ca->YLim[0]) )/( log10(ca->YLim[1])-log10(ca->YLim[0]) ); 263 | } 264 | } 265 | float MatPlot::ct3x(double x){ 266 | return -1+2*(x-ca->XLim[0])/(ca->XLim[1]-ca->XLim[0]); 267 | } 268 | float MatPlot::ct3y(double y){ 269 | return -1+2*(y-ca->YLim[0])/(ca->YLim[1]-ca->YLim[0]); 270 | } 271 | float MatPlot::ct3z(double z){ 272 | return -1+2*(z-ca->ZLim[0])/(ca->ZLim[1]-ca->ZLim[0]); 273 | } 274 | // set /// 275 | /// set(v) 276 | void MatPlot::set(string v){ 277 | int h=gco(); 278 | int tObj=h%100; 279 | int iObj=h/100; 280 | //if( (tObj==tLine) && (iObj" ){ set(h,"Marker",">"); set(h,"LineStyle","none"); } 329 | if( v=="<" ){ set(h,"Marker","<"); set(h,"LineStyle","none"); } 330 | if( v=="p" ){ set(h,"Marker","p"); set(h,"LineStyle","none"); } 331 | if( v=="h" ){ set(h,"Marker","h"); set(h,"LineStyle","none"); } 332 | 333 | //} 334 | 335 | } 336 | void MatPlot::set(float v){ 337 | int h=gco(); 338 | int tObj=h%100; 339 | int iObj=h/100; 340 | if( (tObj==tLine) && (iObjLineWidth=linewidth; 418 | //} 419 | 420 | // Events /// 421 | void MatPlot::reshape(int w, int h){ 422 | window_w=w; 423 | window_h=h; 424 | if(mode==2){ 425 | glViewport(0,0,w,h); 426 | } 427 | //cout <<"window size: "<< w <<" "<id);} 492 | 493 | int tObj;// type of child object 494 | int iObj;// index of child object 495 | if(cf->Visible){ 496 | glEnable(GL_DEPTH_TEST); 497 | //glDepthFunc(GL_NEVER); 498 | 499 | glClearColor(1, 1, 1, 0.); 500 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 501 | 502 | glViewport(0,0, (int)(window_w),(int)(window_h)); 503 | glLoadIdentity(); 504 | //gluOrtho2D( 0.0, 1.0, 0.0, 1.0 ); 505 | glOrtho(0, 1, 0, 1, -1, 3); 506 | 507 | for(int i=0;iChildren.size();++i){ 508 | tObj=cf->Children[i]%100; 509 | iObj=cf->Children[i]/100; 510 | //printf("Obj t:%3d i:%3d \n",tObj,iObj); 511 | 512 | if(tObj==tLayer){ 513 | cfr=&vLayer[iObj]; 514 | if(cfr->Visible){ display_layer();} 515 | } 516 | } 517 | /* 518 | for(int i1=0;i1Children.size();++i1){ 519 | tObj1=cf->Children[i1]%100; 520 | iObj1=cf->Children[i1]/100; 521 | if(tObj1==tLayer){ 522 | cfr=&vLayer[iObj1]; 523 | if(cfr->Visible){ display_layer();} 524 | 525 | for(int i2=0;i2Children.size();++i2){ 526 | tObj2=cfr->Children[i2]%100; 527 | iObj2=cfr->Children[i2]/100; 528 | if(tObj2==tAxes){ 529 | ca=&vAxes[iObj2]; 530 | if(ca->Children.size()){display_axes();} 531 | } 532 | } 533 | } 534 | } 535 | */ 536 | 537 | //Visible(1); 538 | 539 | display_layer2(); 540 | 541 | glFlush(); 542 | glViewport(0,0,window_w,window_h); 543 | 544 | } 545 | glutSwapBuffers(); 546 | } 547 | 548 | 549 | // Layer /// 550 | int MatPlot::layer(){ 551 | int h=iLayer*100 + tLayer;hObj=h; 552 | if(is_debug1){printf("mode: %d handle: %4d Layer\n",mode,h);} 553 | 554 | if(mode==0){ 555 | vLayer.push_back(Layer(h)); 556 | cf->add_child(h); 557 | } 558 | if(mode==1){ 559 | 560 | } 561 | if(iLayerid,cfr->layername.c_str());} 572 | 573 | int tObj;// type of child object 574 | int iObj;// index of child object 575 | for(int i=0;iChildren.size();++i){ 576 | tObj=cfr->Children[i]%100; 577 | iObj=cfr->Children[i]/100; 578 | if(tObj==tAxes){ 579 | ca=&vAxes[iObj]; 580 | display_axes(); 581 | } 582 | }//i 583 | } 584 | void MatPlot::display_layer2(){ 585 | int l,t,w,h,r; 586 | string s; 587 | l=1; 588 | t=1; 589 | w=20;//button_width; 590 | h=20;//button_height; 591 | r=3; 592 | 593 | if(xPassive<25){ 594 | 595 | 596 | glViewport(0,0, (int)(window_w),(int)(window_h)); 597 | glLoadIdentity(); 598 | gluOrtho2D( 0.0, (int)(window_w), (int)(window_h),0 ); 599 | 600 | glDisable(GL_LINE_STIPPLE); 601 | gl2psDisable(GL2PS_LINE_STIPPLE); 602 | 603 | glLineWidth(2); 604 | glColor3d(0,0,1); 605 | 606 | for(int j=0;jVisible=Visible; 695 | cfr->layername=s; 696 | } 697 | return h; 698 | } 699 | int MatPlot::frame(string s,int Visible){ 700 | int h=layer(); 701 | if(mode==0){ 702 | cfr->Visible=Visible; 703 | cfr->layername=s; 704 | } 705 | return h; 706 | } 707 | 708 | // Axes /// 709 | int MatPlot::gca(){ 710 | return ca->id; 711 | } 712 | int MatPlot::axes(){ 713 | int h=iAxes*100 + tAxes; hObj=h; 714 | //int h=handle(iAxes,tAxes); 715 | if(is_debug1){printf("mode: %d handle: %4d Axes \n",mode,h);} 716 | 717 | if(mode==0){ 718 | cfr->add_child(h); 719 | vAxes.push_back(Axes(h)); 720 | } 721 | if(mode==1){ 722 | if(iAxesVisible=cfr->Visible; 726 | iAxes++; 727 | return h; 728 | } 729 | void MatPlot::display_axes(){ 730 | if(is_debug1){printf("mode: %d handle: %4d Axes #Children %lu\n", 731 | mode,ca->id,ca->Children.size());} 732 | 733 | if(ca->Children.size()){ 734 | if(ca->View==0){//2D 735 | display_axes_2d(); 736 | } 737 | if(ca->View==1){//2D 738 | display_axes_3d(); 739 | } 740 | } 741 | if(ca->View==2){//colorbar 742 | display_axes_colorbar(); 743 | } 744 | 745 | // childlen // 746 | int tObj;// type of child object 747 | int iObj;// index of child object 748 | for(int i=0;iChildren.size();++i){ 749 | tObj=ca->Children[i]%100; 750 | iObj=ca->Children[i]/100; 751 | if(tObj==tLine){ 752 | cl=&vLine[iObj]; 753 | display_line(); 754 | } 755 | if(tObj==tSurface){ 756 | cs=&vSurface[iObj]; 757 | display_surface(); 758 | } 759 | if(tObj==tText){ 760 | ct=&vText[iObj]; 761 | display_text(); 762 | } 763 | if(tObj==tPatch){ 764 | cp=&vPatch[iObj]; 765 | display_patch(); 766 | } 767 | }//i 768 | } 769 | /// display 770 | void MatPlot::display_axes_2d(){ 771 | 772 | 773 | char ctmp[100]; 774 | float l,b,w,h;//left,bottom,width,height 775 | float r=0.01; 776 | 777 | l=ca->Position[0]; 778 | b=ca->Position[1]; 779 | w=ca->Position[2]; 780 | h=ca->Position[3]; 781 | 782 | // Viewport Figure (VpF) for drawing axes 783 | glViewport(0,0, (int)(window_w),(int)(window_h)); 784 | glLoadIdentity(); 785 | gluOrtho2D( 0.0, 1.0, 0.0, 1.0 ); 786 | 787 | glDisable(GL_LINE_STIPPLE); 788 | gl2psDisable(GL2PS_LINE_STIPPLE); 789 | 790 | float x_axis_location=1,y_axis_location=1; 791 | if(ca->XAxisLocation=="top" ){x_axis_location=1;}else{x_axis_location=-1;} 792 | if(ca->YAxisLocation=="right"){y_axis_location=1;}else{y_axis_location=-1;} 793 | 794 | int char_w=6,char_h=12; 795 | float offset=0.01; 796 | int num_char=4; 797 | 798 | int gridlinestyle; 799 | 800 | int tickdir=1;//1:in, -1:out 801 | 802 | if(ca->Box){ 803 | // box // 804 | glLineWidth(ca->LineWidth); 805 | gl2psLineWidth(ca->LineWidth); 806 | if(ca->Selected){ 807 | glLineWidth( 2* ca->LineWidth); 808 | gl2psLineWidth(ca->LineWidth); 809 | } 810 | glColor3f(0,0,0); 811 | glBegin(GL_LINE_LOOP); 812 | glVertex2d(l, b); 813 | glVertex2d(l+w,b); 814 | glVertex2d(l+w,b+h); 815 | glVertex2d(l, b+h); 816 | glEnd(); 817 | 818 | // mouse capture // 819 | if(ca->Selected){ 820 | sprintf(ctmp,"Mouse:(%f,%f)",ca->XMouse,ca->YMouse); 821 | ptext( l,b+h+r,ctmp ); 822 | } 823 | 824 | // Grid // 825 | gridlinestyle=3; 826 | if(ca->GridLineStyle=="-" ){gridlinestyle=1;} 827 | if(ca->GridLineStyle=="- -"){gridlinestyle=2;} 828 | if(ca->GridLineStyle==":" ){gridlinestyle=3;} 829 | if(ca->GridLineStyle=="-." ){gridlinestyle=4;} 830 | 831 | if(ca->XGrid){ 832 | glLineWidth(ca->LineWidth); 833 | gl2psLineWidth(ca->LineWidth); 834 | for(int i=0;iXTick.size();++i){ 835 | 836 | //cout <<"grid "<XTick[i]<XTick[i]),b ); 859 | glVertex2d( ctx2(ca->XTick[i]),b+h );//!! TODO 860 | glEnd(); 861 | } 862 | } 863 | if(ca->YGrid){ 864 | for(int i=0;iXTick.size();++i){ 865 | if(gridlinestyle==1){// - 866 | glDisable(GL_LINE_STIPPLE); 867 | gl2psDisable(GL2PS_LINE_STIPPLE); 868 | } 869 | if(gridlinestyle==2){//- - 870 | glEnable(GL_LINE_STIPPLE); 871 | glLineStipple(1, 0xF0F0); 872 | gl2psEnable(GL2PS_LINE_STIPPLE); 873 | } 874 | if(gridlinestyle==3){//: 875 | glEnable(GL_LINE_STIPPLE); 876 | glLineStipple(1, 0xCCCC); 877 | gl2psEnable(GL2PS_LINE_STIPPLE); 878 | } 879 | if(gridlinestyle==4){//-. 880 | glEnable(GL_LINE_STIPPLE); 881 | glLineStipple(1, 0x087F); 882 | gl2psEnable(GL2PS_LINE_STIPPLE); 883 | } 884 | glBegin(GL_LINE_STRIP); 885 | glVertex2d( l, cty2(ca->YTick[i]) ); 886 | glVertex2d( l+w,cty2(ca->YTick[i]) ); 887 | glEnd(); 888 | } 889 | } 890 | 891 | // Ticks // 892 | if(ca->TickDir=="in"){tickdir=1;} 893 | if(ca->TickDir=="out"){tickdir=-1;} 894 | 895 | glDisable(GL_LINE_STIPPLE); 896 | gl2psDisable(GL2PS_LINE_STIPPLE); 897 | //TODO precise adjustment of tick location 898 | // x tick 899 | for(int i=0;iXTick.size();++i){ 900 | glBegin(GL_LINE_STRIP); 901 | glVertex2d( ctx2(ca->XTick[i]),b ); 902 | glVertex2d( ctx2(ca->XTick[i]),b+tickdir*0.01 );//b-0.02*h 903 | glEnd(); 904 | } 905 | // x tick label 906 | if(ca->TickLabel){ 907 | for(int i=0;iXTick.size();++i){ 908 | sprintf(ctmp,"%4.1f",ca->XTick[i]); 909 | //ptext( ctx2(ca->XTick[i])-0.02, b-0.025,ctmp );//b-0.05*h 910 | ptext( ctx2(ca->XTick[i])-(float)num_char*char_w/window_w/2.0, 911 | b-offset-1.0*char_h/window_h,ctmp );//b-0.05*h 912 | } 913 | } 914 | // y tick 915 | for(int i=0;iYTick.size();++i){ 916 | glBegin(GL_LINE_STRIP); 917 | glVertex2d( l, cty2(ca->YTick[i]) ); 918 | glVertex2d( l+tickdir*0.01,cty2(ca->YTick[i]) ); 919 | glEnd(); 920 | } 921 | // y tick label 922 | if(ca->TickLabel){ 923 | for(int i=0;iYTick.size();++i){ 924 | sprintf(ctmp,"%4.1f",ca->YTick[i]); 925 | //ptext( l-0.05,cty2(ca->YTick[i])-0.0,ctmp ); 926 | ptext( l-(float)num_char*char_w/window_w-offset, 927 | cty2(ca->YTick[i])-0.5*char_h/window_h,ctmp ); 928 | } 929 | } 930 | }//Box 931 | 932 | //Title 933 | num_char=ca->Title.length(); 934 | ptext( l+w/2.0-(float)num_char*char_w/window_w/2.0, 935 | b+h+offset, 936 | ca->Title ); 937 | 938 | //XLabel 939 | num_char=ca->XLabel.length(); 940 | ptext( l+w/2.0-(float)num_char*char_w/window_w/2.0, 941 | b-offset-2.0*char_h/window_h, 942 | ca->XLabel ); 943 | 944 | //YLabel 945 | num_char=ca->YLabel.length(); 946 | ptext( l, b+h+offset, 947 | ca->YLabel ); 948 | 949 | // Viewport Axes (VpA) for drawing lines and surfaces 950 | glViewport((int)(ca->Position[0]*window_w ), 951 | (int)(ca->Position[1]*window_h ), 952 | (int)(ca->Position[2]*window_w ), 953 | (int)(ca->Position[3]*window_h )); 954 | glLoadIdentity(); 955 | gluOrtho2D( 0.0, 1.0, 0.0, 1.0 ); 956 | } 957 | void MatPlot::display_axes_3d(){ 958 | 959 | char ctmp[100]; 960 | float l,b,w,h;//left,bottom,width,height 961 | float r=0.01; 962 | 963 | l=ca->Position[0]; 964 | b=ca->Position[1]; 965 | w=ca->Position[2]; 966 | h=ca->Position[3]; 967 | 968 | // Viewport Axes 969 | /* 970 | glViewport((int)(ca->Position[0]*window_w ), 971 | (int)(ca->Position[1]*window_h ), 972 | (int)(ca->Position[2]*window_w ), 973 | (int)(ca->Position[3]*window_h )); 974 | */ 975 | 976 | glViewport((int)(ca->Viewport3d[0]*window_w ), 977 | (int)(ca->Viewport3d[1]*window_h ), 978 | (int)(ca->Viewport3d[2]*window_w ), 979 | (int)(ca->Viewport3d[3]*window_h )); 980 | 981 | glLoadIdentity(); 982 | //glOrtho(-1.7, 1.7, -1.7, 1.7, -1.5, 3); 983 | glOrtho(-1.8, 1.8, -1.8, 1.8, -1.5, 3); 984 | 985 | gluLookAt(cos(ca->cta*PI/180)*cos(ca->phi*PI/180), 986 | sin(ca->cta*PI/180)*cos(ca->phi*PI/180), 987 | sin(ca->phi*PI/180), 988 | //gluLookAt(CameraPosition[0],CameraPosition[1],CameraPosition[2], 989 | ca->CameraTarget[0], ca->CameraTarget[1], ca->CameraTarget[2], 990 | ca->CameraUpVector[0],ca->CameraUpVector[1],ca->CameraUpVector[2]); 991 | 992 | /* 993 | // x,y,z axes for test 994 | glColor3f(1,0,0); 995 | glBegin(GL_LINE_STRIP); 996 | glVertex3d(0,0,0); glVertex3d(1,0,0); 997 | glEnd(); 998 | 999 | glColor3f(0,1,0); 1000 | glBegin(GL_LINE_STRIP); 1001 | glVertex3d(0,0,0); glVertex3d(0,1,0); 1002 | glEnd(); 1003 | 1004 | glColor3f(0,0,1); 1005 | glBegin(GL_LINE_STRIP); 1006 | glVertex3d(0,0,0); glVertex3d(0,0,1); 1007 | glEnd(); 1008 | 1009 | glColor3f(0,0,0); 1010 | glBegin(GL_LINE_LOOP); 1011 | glVertex3d(-1,-1,0); glVertex3d(1,-1,0); glVertex3d(1,1,0); glVertex3d(-1,1,0); 1012 | glEnd(); 1013 | */ 1014 | 1015 | int char_w=6,char_h=12; 1016 | float offset=0.01; 1017 | int num_char=4; 1018 | 1019 | if(ca->Box){ 1020 | // tick 1021 | float cta0; 1022 | float r1=1.05;//tick width 1023 | float r2=1.2; 1024 | float r3=1.4; 1025 | int signx,signy; 1026 | cta0=ca->cta;cta0=fmod(ca->cta,360); 1027 | if(( 0<=cta0)&&(cta0< 90)){signx= 1;signy= 1;} 1028 | if(( 90<=cta0)&&(cta0<190)){signx=-1;signy= 1;} 1029 | if((180<=cta0)&&(cta0<270)){signx=-1;signy=-1;} 1030 | if((270<=cta0)&&(cta0<360)){signx= 1;signy=-1;} 1031 | 1032 | glColor3f(0,0,0); 1033 | 1034 | // axes // 1035 | // x 1036 | glBegin(GL_LINE_STRIP); 1037 | glVertex3d(-1,signy,-1); 1038 | glVertex3d( 1,signy,-1); 1039 | glEnd(); 1040 | // y 1041 | glBegin(GL_LINE_STRIP); 1042 | glVertex3d(signx,-1,-1); 1043 | glVertex3d(signx, 1,-1); 1044 | glEnd(); 1045 | // z 1046 | glBegin(GL_LINE_STRIP); 1047 | glVertex3d(signy,-signx,-1); 1048 | glVertex3d(signy,-signx, 1); 1049 | glEnd(); 1050 | 1051 | // Tick // 1052 | //x 1053 | for(int i=0;iXTick.size();++i){ 1054 | glBegin(GL_LINE_STRIP); 1055 | glVertex3d( ct3x(ca->XTick[i]),signy ,-1 ); 1056 | glVertex3d( ct3x(ca->XTick[i]),signy*r1,-1 ); 1057 | glEnd(); 1058 | } 1059 | // y 1060 | for(int i=0;iYTick.size();++i){ 1061 | glBegin(GL_LINE_STRIP); 1062 | glVertex3d( signx ,ct3y(ca->YTick[i]),-1 ); 1063 | glVertex3d( signx*r1,ct3y(ca->YTick[i]),-1 ); 1064 | glEnd(); 1065 | } 1066 | // z 1067 | for(int i=0;iYTick.size();++i){ 1068 | glBegin(GL_LINE_STRIP); 1069 | glVertex3d( signy ,-signx ,ct3z(ca->ZTick[i]) ); 1070 | glVertex3d( signy*r1,-signx,ct3z(ca->ZTick[i]) ); 1071 | glEnd(); 1072 | } 1073 | // Tick Label // 1074 | if(ca->TickLabel){ 1075 | //x 1076 | for(int i=0;iXTick.size();++i){ 1077 | sprintf(ctmp,"%4.1f",ca->XTick[i]); 1078 | ptext3c( ct3x(ca->XTick[i]),signy*r2 ,-1,ctmp ); 1079 | } 1080 | // y 1081 | for(int i=0;iYTick.size();++i){ 1082 | sprintf(ctmp,"%4.1f",ca->YTick[i]); 1083 | ptext3c( signx*r2,ct3y(ca->YTick[i]),-1,ctmp ); 1084 | } 1085 | // z 1086 | for(int i=0;iZTick.size();++i){ 1087 | sprintf(ctmp,"%4.1f",ca->ZTick[i]); 1088 | ptext3c( signy*r2,-signx,ct3z(ca->ZTick[i]),ctmp ); 1089 | } 1090 | } 1091 | // xyz Label // 1092 | ptext3c(0,signy*r3,-1,"x"); 1093 | ptext3c(signx*r3,0,-1,"y"); 1094 | ptext3c(signy*r3,-signx,0,"z"); 1095 | 1096 | }//box 1097 | } 1098 | 1099 | /// colorbar 1100 | void MatPlot::display_axes_colorbar(){ 1101 | char ctmp[100]; 1102 | float l,b,w,h;//left,bottom,width,height 1103 | float r=0.01; 1104 | 1105 | l=ca->Position[0]; 1106 | b=ca->Position[1]; 1107 | w=ca->Position[2]; 1108 | h=ca->Position[3]; 1109 | 1110 | // Viewport Figure (VpF) for drawing axes 1111 | glViewport(0,0, (int)(window_w),(int)(window_h)); 1112 | glLoadIdentity(); 1113 | gluOrtho2D( 0.0, 1.0, 0.0, 1.0 ); 1114 | 1115 | glDisable(GL_LINE_STIPPLE); 1116 | gl2psDisable(GL2PS_LINE_STIPPLE); 1117 | 1118 | if(ca->Box){ 1119 | // box 1120 | glLineWidth(ca->LineWidth); 1121 | gl2psLineWidth(ca->LineWidth); 1122 | glColor3f(0,0,0); 1123 | glBegin(GL_LINE_LOOP); 1124 | glVertex2d(l, b); 1125 | glVertex2d(l+w,b); 1126 | glVertex2d(l+w,b+h); 1127 | glVertex2d(l, b+h); 1128 | glEnd(); 1129 | 1130 | // z tick 1131 | for(int i=0;iZTick.size();++i){ 1132 | glBegin(GL_LINE_STRIP); 1133 | glVertex2d( l+w, cty2(ca->ZTick[i]) ); 1134 | glVertex2d( l+w+0.01, cty2(ca->ZTick[i]) ); 1135 | glEnd(); 1136 | } 1137 | // z tick number 1138 | for(int i=0;iZTick.size();++i){ 1139 | sprintf(ctmp,"%4.1f",ca->ZTick[i]); 1140 | ptext( l+w+0.01,cty2(ca->ZTick[i]),ctmp ); 1141 | } 1142 | }//Box 1143 | 1144 | vector rgb; 1145 | int n=cmap.size(); 1146 | for(int i=0;iColorMap[i]; 1148 | glColor3f(rgb[0],rgb[1],rgb[2]); 1149 | 1150 | glBegin(GL_QUADS); 1151 | glVertex2d(l ,b+h*i/n); 1152 | glVertex2d(l+w,b+h*i/n); 1153 | glVertex2d(l+w,b+h*(i+1)/n); 1154 | glVertex2d(l ,b+h*(i+1)/n); 1155 | glEnd(); 1156 | } 1157 | 1158 | } 1159 | /// events (mouse, motion) 1160 | void MatPlot::Axes_mouse(int button, int state, int x, int y ){ 1161 | 1162 | float X,Y; 1163 | double rx,ry,mx,my;//mouse 1164 | X=(float) x /window_w; 1165 | Y=(float)(window_h-y)/window_h; 1166 | float l,b,w,h; 1167 | 1168 | if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {// Left Click 1169 | xButtonDown=x; 1170 | yButtonDown=y; 1171 | 1172 | //cout <<"window w h"<=0){ 1177 | 1178 | ca=&vAxes[iAxesSelected]; 1179 | if(ca->Visible){ 1180 | l=ca->Position[0]; 1181 | b=ca->Position[1]; 1182 | w=ca->Position[2]; 1183 | h=ca->Position[3]; 1184 | 1185 | if( (l<=X)&&(X<=l+w)&&(b<=Y)&&(Y<=b+h)&&(ca->Mouse==1) ){ 1186 | rx=(X-l)/w; 1187 | ry=(Y-b)/h; 1188 | mx=rx*(ca->XLim[1]-ca->XLim[0])+ca->XLim[0]; 1189 | my=ry*(ca->YLim[1]-ca->YLim[0])+ca->YLim[0]; 1190 | ca->XMouse = mx; 1191 | ca->YMouse = my; 1192 | if(is_debug2){cout <<"mouse capture: "<< mx <<" "<< my <Selected=0; 1203 | if(ca->Visible){ 1204 | l=ca->Position[0]; 1205 | b=ca->Position[1]; 1206 | w=ca->Position[2]; 1207 | h=ca->Position[3]; 1208 | 1209 | if( (l<=X)&&(X<=l+w)&&(b<=Y)&&(Y<=b+h) ){ 1210 | iAxesSelected=i; 1211 | ca->Selected=1; 1212 | if(ca->View==1){//3D 1213 | ctaButtonDown = ca->cta; 1214 | phiButtonDown = ca->phi; 1215 | } 1216 | //cout << "axes "<< i << " is selected "<< vAxes[i].selected() << endl; 1217 | //cout <<"(cta,phi) = "<< ctaButtonDown <<" "<< phiButtonDown << endl; 1218 | } 1219 | } 1220 | } 1221 | 1222 | if(is_debug2){ cout <<"selected axes"<< iAxesSelected<Selected)&&(ca->View==1)){ 1232 | cta = ctaButtonDown - (float) (x - xButtonDown)*1; 1233 | phi = phiButtonDown + (float) (y - yButtonDown)*1; 1234 | if(phi>= 90){phi= 90;} 1235 | if(phi<=-90){phi=-90;} 1236 | if(cta>360){cta+=-360;} 1237 | if(cta< 0){cta+= 360;} 1238 | 1239 | ca->phi = phi; 1240 | ca->cta = cta; 1241 | //cout <<"( phi,cta ) = ( "<< vAxes[i].phi <<","<< vAxes[i].cta <<" )"<Position[0]=(ix+0.13)/n; 1262 | ca->Position[1]=(iy+0.11)/m; 1263 | ca->Position[2]=0.775/n; 1264 | ca->Position[3]=0.815/m; 1265 | 1266 | ca->Viewport3d[0]=1.0*ix/n; 1267 | ca->Viewport3d[1]=1.0*iy/m; 1268 | ca->Viewport3d[2]=1.0/n; 1269 | ca->Viewport3d[3]=1.0/m; 1270 | 1271 | return h; 1272 | } 1273 | /// colorbar 1274 | int MatPlot::colorbar(){ 1275 | float l,b,w,h; 1276 | l=ca->Position[0]; 1277 | b=ca->Position[1]; 1278 | w=ca->Position[2]; 1279 | h=ca->Position[3]; 1280 | float zmin,zmax; 1281 | zmin=ca->ZLim[0]; 1282 | zmax=ca->ZLim[1]; 1283 | 1284 | // TODO use in 3D 1285 | 1286 | int hh=axes(); 1287 | ca->ColorMap=cmap; 1288 | ca->View=2; 1289 | ca->Position[0]=l+w+w*0.01; 1290 | ca->Position[1]=b; 1291 | ca->Position[2]=w*0.05; 1292 | ca->Position[3]=h; 1293 | ca->ZLim[0]=zmin; 1294 | ca->ZLim[1]=zmax; 1295 | ca->YLim[0]=zmin; 1296 | ca->YLim[1]=zmax; 1297 | return hh; 1298 | } 1299 | /// axis 1300 | void MatPlot::axis(double xMin,double xMax,double yMin,double yMax){ 1301 | if(xMin!=xMax){ 1302 | ca->XLim[0]=xMin; 1303 | ca->XLim[1]=xMax; 1304 | ca->XLimMode=1; 1305 | } 1306 | if(yMin!=yMax){ 1307 | ca->YLim[0]=yMin; 1308 | ca->YLim[1]=yMax; 1309 | ca->YLimMode=1; 1310 | } 1311 | ca->View=0;//2D 1312 | } 1313 | 1314 | void MatPlot::axis(double xMin,double xMax,double yMin,double yMax,double zMin,double zMax){ 1315 | ca->XLim[0]=xMin; ca->XLim[1]=xMax; 1316 | ca->YLim[0]=yMin; ca->YLim[1]=yMax; 1317 | ca->ZLim[0]=zMin; ca->ZLim[1]=zMax; 1318 | ca->XLimMode=1; 1319 | ca->YLimMode=1; 1320 | ca->ZLimMode=1; 1321 | ca->View=1;//3D 1322 | } 1323 | void MatPlot::axis(string s){ 1324 | if( s=="on" ){ca->Box=1;} 1325 | if( s=="off" ){ca->Box=0;} 1326 | } 1327 | void MatPlot::axis(int s){ 1328 | if(s){ca->Box=1;} 1329 | else{ ca->Box=0;} 1330 | } 1331 | void MatPlot::grid(string s){ 1332 | if( s=="on" ){ca->XGrid=1; ca->YGrid=1; ca->ZGrid=1;} 1333 | if( s=="off"){ca->XGrid=0; ca->YGrid=0; ca->ZGrid=0;} 1334 | } 1335 | void MatPlot::grid(int s){ 1336 | if(s){ca->XGrid=1; ca->YGrid=1; ca->ZGrid=1;} 1337 | else{ca->XGrid=0; ca->YGrid=0; ca->ZGrid=0;} 1338 | } 1339 | void MatPlot::ticklabel(int s){ 1340 | if(s){ca->TickLabel=1;} 1341 | else{ ca->TickLabel=0;} 1342 | } 1343 | void MatPlot::title(string s){ 1344 | ca->Title=s; 1345 | } 1346 | void MatPlot::xlabel(string s){ 1347 | ca->XLabel=s; 1348 | } 1349 | void MatPlot::ylabel(string s){ 1350 | ca->YLabel=s; 1351 | } 1352 | void MatPlot::mouse_capture(double *xmouse,double *ymouse){ 1353 | ca->Mouse=1; 1354 | //ca->XMouse = xmouse; 1355 | //ca->YMouse = ymouse; 1356 | } 1357 | /// Fmax Fmin 1358 | double Fmax(dvec x){ 1359 | double max=-1e99; 1360 | for(int i=0;imax){max=x[i];} 1362 | } 1363 | return max; 1364 | } 1365 | double Fmin(dvec x){ 1366 | double min=1e99; 1367 | for(int i=0;i max){max=x[i][j];} 1377 | } 1378 | } 1379 | return max; 1380 | } 1381 | double Fmin(dmat x){ 1382 | double min=1e99; 1383 | for(int i=0;iadd_child(h); 1398 | vLine.push_back(Line(h)); 1399 | //al.Parent=gca(); 1400 | } 1401 | if(mode==1){ 1402 | if(iLineXData.size(); 1412 | if(ca->XScale==0){//linear 1413 | for(int i=0;iXData[i]; 1415 | if(ca->xmin>t){ca->xmin=t;} 1416 | if(ca->xmaxxmax=t;} 1417 | } 1418 | } 1419 | if(ca->XScale==1){//log 1420 | for(int i=0;iXData[i]; 1422 | if((ca->xmin>t)&&(t>0)){ca->xmin=t;} 1423 | if(ca->xmaxxmax=t;} 1424 | } 1425 | } 1426 | double y; 1427 | n=cl->YData.size(); 1428 | for(int i=0;iYData[i]; 1430 | if(ca->ymin>y){ca->ymin=y;} 1431 | if(ca->ymaxymax=y;} 1432 | } 1433 | double z; 1434 | n=cl->ZData.size(); 1435 | for(int i=0;iZData[i]; 1437 | if(ca->zmin>z){ca->zmin=z;} 1438 | if(ca->zmaxzmax=z;} 1439 | } 1440 | } 1441 | int MatPlot::line(dvec x,dvec y){ 1442 | int h=line(); 1443 | if(cfr->Visible){ 1444 | cl->XData=x; 1445 | cl->YData=y; 1446 | line_config(); 1447 | } 1448 | return h; 1449 | } 1450 | int MatPlot::line(dvec x,dvec y,dvec z){ 1451 | int h=line(); 1452 | if(cfr->Visible){ 1453 | cl->XData=x; 1454 | cl->YData=y; 1455 | cl->ZData=z; 1456 | line_config(); 1457 | } 1458 | return h; 1459 | } 1460 | /// vertex 1461 | int MatPlot::begin(){ return line(); } 1462 | void MatPlot::end(){} 1463 | void MatPlot::vertex(double x,double y){ 1464 | if(cfr->Visible){ 1465 | if(ca->xmin>x){ca->xmin=x;} 1466 | if(ca->xmaxxmax=x;} 1467 | if(ca->ymin>y){ca->ymin=y;} 1468 | if(ca->ymaxymax=y;} 1469 | cl->XData.push_back(x); 1470 | cl->YData.push_back(y); 1471 | } 1472 | } 1473 | /// plot, semilogx, semilogy, loglog 1474 | int MatPlot::plot(dvec y){ 1475 | int n=y.size(); 1476 | dvec x; 1477 | x.resize(n); 1478 | for(int i=0;i x,valarray y){ 1485 | dvec xx,yy; 1486 | for(int i=0;iXScale=1; 1492 | int h=line(); 1493 | if(cfr->Visible){ 1494 | cl->XData=x; 1495 | cl->YData=y; 1496 | line_config(); 1497 | } 1498 | return h; 1499 | } 1500 | int MatPlot::semilogy(dvec x,dvec y){ 1501 | ca->YScale=1; 1502 | int h=line(); 1503 | if(cfr->Visible){ 1504 | cl->XData=x; 1505 | cl->YData=y; 1506 | line_config(); 1507 | } 1508 | return h; 1509 | } 1510 | int MatPlot::loglog(dvec x,dvec y){ 1511 | ca->XScale=1; 1512 | ca->YScale=1; 1513 | int h=line(); 1514 | if(cfr->Visible){ 1515 | cl->XData=x; 1516 | cl->YData=y; 1517 | line_config(); 1518 | } 1519 | return h; 1520 | } 1521 | /// errorbar 1522 | void MatPlot::vertex(double x,double y,double ep,double em){//for errorbar 1523 | if(ca->xmin>x){ca->xmin=x;} 1524 | if(ca->xmaxxmax=x;} 1525 | if(ca->ymin>y+ep){ca->ymin=y+ep;} 1526 | if(ca->ymaxymax=y-em;} 1527 | cl->XData.push_back(x); 1528 | cl->YData.push_back(y); 1529 | cl->YPData.push_back(ep); 1530 | cl->YMData.push_back(em); 1531 | } 1532 | int MatPlot::errorbar(dvec x,dvec y,dvec e){ 1533 | begin(); 1534 | for(int i=0;iErrorbar=1; 1537 | return 0; 1538 | } 1539 | int MatPlot::errorbar(dvec x,dvec y,dvec ep,dvec em){ 1540 | begin(); 1541 | for(int i=0;iErrorbar=1; 1544 | return 0; 1545 | } 1546 | /// 3D line 1547 | void MatPlot::vertex(double x,double y,double z){ 1548 | if(cfr->Visible){ 1549 | if(ca->xmin>x){ca->xmin=x;} 1550 | if(ca->xmaxxmax=x;} 1551 | if(ca->ymin>y){ca->ymin=y;} 1552 | if(ca->ymaxymax=y;} 1553 | if(ca->zmin>z){ca->zmin=z;} 1554 | if(ca->zmaxzmax=z;} 1555 | cl->XData.push_back(x); 1556 | cl->YData.push_back(y); 1557 | cl->ZData.push_back(z); 1558 | } 1559 | //if(cl->LineStyle){//Line 1560 | //glVertex3d(ct3x(x),ct3y(y),ct3z(z)); 1561 | //} 1562 | } 1563 | int MatPlot::plot3(dvec x,dvec y,dvec z){ 1564 | ca->View=1; 1565 | begin(); 1566 | for(int i=0;iid);} 1576 | 1577 | float xx,yy;// transformed coordination 1578 | float r;//marker size 1579 | float rx,ry; 1580 | vector rgb=ColorSpec2RGB(cl->Color); 1581 | glColor3f(rgb[0],rgb[1],rgb[2]); 1582 | 1583 | glLineWidth(cl->LineWidth); 1584 | glPointSize(cl->LineWidth); 1585 | gl2psLineWidth(cl->LineWidth); 1586 | gl2psPointSize(cl->LineWidth); 1587 | // 2D // 1588 | if(ca->View==0){ 1589 | if(cl->LineStyle !="none" ){// Line // 1590 | 1591 | if(cl->LineStyle=="-"){ 1592 | glDisable(GL_LINE_STIPPLE); 1593 | gl2psDisable(GL2PS_LINE_STIPPLE); 1594 | } 1595 | if(cl->LineStyle=="- -"){ 1596 | glEnable(GL_LINE_STIPPLE); 1597 | glLineStipple(1, 0xF0F0); 1598 | gl2psEnable(GL2PS_LINE_STIPPLE); 1599 | } 1600 | if(cl->LineStyle==":"){ 1601 | glEnable(GL_LINE_STIPPLE); 1602 | glLineStipple(1, 0xCCCC); 1603 | gl2psEnable(GL2PS_LINE_STIPPLE); 1604 | } 1605 | if(cl->LineStyle=="-."){ 1606 | glEnable(GL_LINE_STIPPLE); 1607 | glLineStipple(1, 0x087F); 1608 | gl2psEnable(GL2PS_LINE_STIPPLE); 1609 | } 1610 | if(cl->XData.size()){ 1611 | glBegin(GL_LINE_STRIP); 1612 | for(int i=0;iXData.size();++i){ 1613 | //printf("i:%d %f %f\n",i,xx,yy); 1614 | xx=ctx(cl->XData[i]); 1615 | yy=cty(cl->YData[i]); 1616 | glVertex2d(xx,yy); 1617 | } 1618 | glEnd(); 1619 | } 1620 | } 1621 | 1622 | if(cl->Marker != "none"){// Marker // 1623 | 1624 | r=cl->MarkerSize/500.0; 1625 | rx=cl->MarkerSize/window_w; 1626 | ry=cl->MarkerSize/window_h; 1627 | 1628 | 1629 | glDisable(GL_LINE_STIPPLE); 1630 | gl2psDisable(GL2PS_LINE_STIPPLE); 1631 | 1632 | for(int i=0;iXData.size();++i){ 1633 | xx=ctx(cl->XData[i]); 1634 | yy=cty(cl->YData[i]); 1635 | 1636 | if(cl->Marker=="."){//. 1637 | glPointSize(cl->LineWidth); 1638 | glBegin(GL_POINTS); 1639 | glVertex2d(xx,yy); 1640 | glEnd(); 1641 | } 1642 | if(cl->Marker=="+"){//+ 1643 | glBegin(GL_LINE_STRIP); 1644 | glVertex2d(xx-rx,yy); 1645 | glVertex2d(xx+rx,yy); 1646 | glEnd(); 1647 | glBegin(GL_LINE_STRIP); 1648 | glVertex2d(xx,yy-ry); 1649 | glVertex2d(xx,yy+ry); 1650 | glEnd(); 1651 | } 1652 | if(cl->Marker=="x"){//x 1653 | glBegin(GL_LINE_STRIP); 1654 | glVertex2d(xx-rx,yy-ry); 1655 | glVertex2d(xx+rx,yy+ry); 1656 | glEnd(); 1657 | glBegin(GL_LINE_STRIP); 1658 | glVertex2d(xx+rx,yy-ry); 1659 | glVertex2d(xx-rx,yy+ry); 1660 | glEnd(); 1661 | } 1662 | if(cl->Marker=="d"){//d diamond 1663 | glBegin(GL_LINE_LOOP); 1664 | glVertex2d(xx, yy+ry); 1665 | glVertex2d(xx+rx,yy); 1666 | glVertex2d(xx, yy-ry); 1667 | glVertex2d(xx-rx,yy); 1668 | glEnd(); 1669 | } 1670 | if(cl->Marker=="^"){//^ 1671 | glBegin(GL_LINE_LOOP); 1672 | glVertex2d(xx, yy+ry); 1673 | glVertex2d(xx+rx,yy-ry); 1674 | glVertex2d(xx-rx,yy-ry); 1675 | glEnd(); 1676 | } 1677 | if(cl->Marker=="v"){//v 1678 | glBegin(GL_LINE_LOOP); 1679 | glVertex2d(xx, yy-ry); 1680 | glVertex2d(xx+rx,yy+ry); 1681 | glVertex2d(xx-rx,yy+ry); 1682 | glEnd(); 1683 | } 1684 | if(cl->Marker=="o"){//o 1685 | glBegin(GL_LINE_LOOP); 1686 | for(int i=0;i<20;i++){ 1687 | glVertex2d(xx+rx*cos(2*PI*(double)i/(double)(20)), 1688 | yy+ry*sin(2*PI*(double)i/(double)(20))); 1689 | } 1690 | glEnd(); 1691 | } 1692 | if(cl->Marker=="*"){//* 1693 | glBegin(GL_LINE_STRIP); 1694 | glVertex2d(xx-rx,yy); 1695 | glVertex2d(xx+rx,yy); 1696 | glEnd(); 1697 | glBegin(GL_LINE_STRIP); 1698 | glVertex2d(xx,yy-ry); 1699 | glVertex2d(xx,yy+ry); 1700 | glEnd(); 1701 | glBegin(GL_LINE_STRIP); 1702 | glVertex2d(xx-rx,yy-ry); 1703 | glVertex2d(xx+rx,yy+ry); 1704 | glEnd(); 1705 | glBegin(GL_LINE_STRIP); 1706 | glVertex2d(xx+rx,yy-ry); 1707 | glVertex2d(xx-rx,yy+ry); 1708 | glEnd(); 1709 | 1710 | } 1711 | if(cl->Marker=="s"){//s :squire 1712 | glBegin(GL_LINE_LOOP); 1713 | glVertex2d(xx-rx,yy-ry); 1714 | glVertex2d(xx-rx,yy+ry); 1715 | glVertex2d(xx+rx,yy+ry); 1716 | glVertex2d(xx+rx,yy-ry); 1717 | glEnd(); 1718 | } 1719 | //TODO use switch 1720 | }//i 1721 | }// Marker 1722 | 1723 | 1724 | if(cl->Errorbar){// Errorbar // 1725 | float xx,yy,yyp,yym;// transformed coordination 1726 | 1727 | glDisable(GL_LINE_STIPPLE); 1728 | gl2psDisable(GL2PS_LINE_STIPPLE); 1729 | //r=cl->MarkerSize/500; 1730 | 1731 | for(int i=0;iXData.size();++i){ 1732 | xx=ctx(cl->XData[i]); 1733 | yy=cty(cl->YData[i]); 1734 | yyp=cty(cl->YData[i] + cl->YPData[i]); 1735 | yym=cty(cl->YData[i] - cl->YMData[i]); 1736 | 1737 | glBegin(GL_LINE_STRIP); 1738 | glVertex2d(xx,yyp); 1739 | glVertex2d(xx,yym); 1740 | glEnd(); 1741 | glBegin(GL_LINE_STRIP); 1742 | glVertex2d(xx-rx,yy); 1743 | glVertex2d(xx+rx,yy); 1744 | glEnd(); 1745 | glBegin(GL_LINE_STRIP); 1746 | glVertex2d(xx-rx,yyp); 1747 | glVertex2d(xx+rx,yyp); 1748 | glEnd(); 1749 | glBegin(GL_LINE_STRIP); 1750 | glVertex2d(xx-rx,yym); 1751 | glVertex2d(xx+rx,yym); 1752 | glEnd(); 1753 | }//i 1754 | }//Errorbar 1755 | //TODO:selection of error bar type 1756 | }//2D 1757 | 1758 | // 3D // 1759 | if(ca->View==1){ 1760 | glBegin(GL_LINE_STRIP); 1761 | for(int i=0;iXData.size();++i){ 1762 | glVertex3d(ct3x(cl->XData[i]), 1763 | ct3y(cl->YData[i]), 1764 | ct3z(cl->ZData[i])); 1765 | } 1766 | glEnd(); 1767 | } 1768 | } 1769 | 1770 | // Surface /// 1771 | int MatPlot::surface(){ 1772 | int h=iSurface*100 + tSurface; hObj=h; 1773 | if(is_debug1){printf("mode: %d handle: %4d Surface\n",mode,h);} 1774 | 1775 | if(mode==0){ 1776 | ca->add_child(h); 1777 | vSurface.push_back(Surface(h)); 1778 | //as.Parent=gca(); 1779 | } 1780 | if(mode==1){ 1781 | 1782 | } 1783 | if(iSurfaceZData.size(); 1793 | if(nzi){nzj=cs->ZData[0].size(); } 1794 | 1795 | int nci,ncj; 1796 | nci=cs->CDataIndex.size(); 1797 | if(nci){ncj=cs->CDataIndex[0].size();} 1798 | 1799 | // generate x and y data 1800 | int nx=0,ny=0; 1801 | if(nzi){ny=nzi; nx=nzj;} 1802 | if(nci){ny=nci; nx=ncj;} 1803 | 1804 | //printf("%s %s:%d: %d %d %d %d \n", __func__, __FILE__, __LINE__,nzi,nci,nx,ny); 1805 | if(cs->XData.size()==0){ 1806 | cs->XData.resize(1); 1807 | cs->XData[0]=linspace(1.0,(double)nx,nx); 1808 | } 1809 | if(cs->YData.size()==0){ 1810 | cs->YData.resize(1); 1811 | cs->YData[0]=linspace(1.0,(double)ny,ny); 1812 | } 1813 | 1814 | // config data range 1815 | ca->xmax=fmax(Fmax(cs->XData),ca->xmax); 1816 | ca->xmin=fmin(Fmin(cs->XData),ca->xmin); 1817 | ca->ymax=fmax(Fmax(cs->YData),ca->ymax); 1818 | ca->ymin=fmin(Fmin(cs->YData),ca->ymin); 1819 | ca->zmax=fmax(Fmax(cs->ZData),ca->zmax ); 1820 | ca->zmin=fmin(Fmin(cs->ZData),ca->zmin ); 1821 | 1822 | // set CLim 1823 | //note: first called surface effects CLim 1824 | if(ca->CLim[0]==ca->CLim[1]){ 1825 | ca->CLim[0]=Fmin(cs->CDataIndex); 1826 | ca->CLim[1]=Fmax(cs->CDataIndex); 1827 | } 1828 | 1829 | // CData !!! 1830 | if( (cs->CData.size()==0) && (cs->CDataIndex.size()) ){ 1831 | vector rgb; 1832 | //tcmat cdata(ny,nx); 1833 | tcmat cdata(ny); 1834 | 1835 | for(int i=0;iCDataIndex[i][j],ca->CLim[0],ca->CLim[1]); 1839 | cdata[i][j]=rgb; 1840 | } 1841 | } 1842 | cs->CData=cdata; 1843 | } 1844 | 1845 | // contour plot 1846 | if(cs->V.size()==0){ 1847 | if(cs->NContour<1){ 1848 | cs->NContour=10; 1849 | } 1850 | cs->V=linspace(Fmin(cs->ZData),Fmax(cs->ZData),cs->NContour); 1851 | } 1852 | } 1853 | 1854 | /// create surface 1855 | int MatPlot::surface(dmat Z){ 1856 | int h=surface(); 1857 | ca->View=1; 1858 | cs->type=1; 1859 | cs->ZData=Z; 1860 | cs->CDataIndex=Z; 1861 | cs->CData.clear(); 1862 | surface_config(); 1863 | return h; 1864 | } 1865 | int MatPlot::surface(dmat Z,dmat C){ 1866 | int h=surface(); 1867 | ca->View=1; 1868 | cs->type=1; 1869 | cs->ZData=Z; 1870 | cs->CDataIndex=C; 1871 | cs->CData.clear(); 1872 | surface_config(); 1873 | return h; 1874 | } 1875 | int MatPlot::surface(dmat Z,tcmat C){ 1876 | int h=surface(); 1877 | ca->View=1; 1878 | cs->type=1; 1879 | cs->ZData=Z; 1880 | cs->CDataIndex.clear(); 1881 | cs->CData=C; 1882 | surface_config(); 1883 | return h; 1884 | } 1885 | int MatPlot::surface(dvec x,dvec y,dmat Z){ 1886 | int h=surface(); 1887 | ca->View=1; 1888 | cs->type=1; 1889 | cs->XData.resize(1); cs->XData[0]=x; 1890 | cs->YData.resize(1); cs->YData[0]=y; 1891 | cs->ZData=Z; 1892 | cs->CDataIndex=Z; 1893 | cs->CData.clear(); 1894 | surface_config(); 1895 | return h; 1896 | } 1897 | int MatPlot::surface(dvec x,dvec y,dmat Z,dmat C){ 1898 | int h=surface(); 1899 | ca->View=1; 1900 | cs->type=1; 1901 | cs->XData.resize(1); cs->XData[0]=x; 1902 | cs->YData.resize(1); cs->YData[0]=y; 1903 | cs->ZData=Z; 1904 | cs->CDataIndex=C; 1905 | cs->CData.clear(); 1906 | surface_config(); 1907 | return h; 1908 | } 1909 | int MatPlot::surface(dvec x,dvec y,dmat Z,tcmat C){ 1910 | int h=surface(); 1911 | ca->View=1; 1912 | cs->type=1; 1913 | cs->XData.resize(1); cs->XData[0]=x; 1914 | cs->YData.resize(1); cs->YData[0]=y; 1915 | cs->ZData=Z; 1916 | cs->CDataIndex.clear(); 1917 | cs->CData=C; 1918 | surface_config(); 1919 | return h; 1920 | } 1921 | 1922 | int MatPlot::surface(dmat X,dmat Y,dmat Z){ 1923 | int h=surface(); 1924 | ca->View=1; 1925 | cs->type=1; 1926 | cs->XData=X; 1927 | cs->YData=Y; 1928 | cs->ZData=Z; 1929 | cs->CDataIndex=Z; 1930 | cs->CData.clear(); 1931 | surface_config(); 1932 | return h; 1933 | } 1934 | int MatPlot::surface(dmat X,dmat Y,dmat Z,dmat C){ 1935 | int h=surface(); 1936 | ca->View=1; 1937 | cs->type=1; 1938 | cs->XData=X; 1939 | cs->YData=Y; 1940 | cs->ZData=Z; 1941 | cs->CDataIndex=C; 1942 | cs->CData.clear(); 1943 | 1944 | surface_config(); 1945 | return h; 1946 | } 1947 | int MatPlot::surface(dmat X,dmat Y,dmat Z,tcmat C){ 1948 | int h=surface(); 1949 | ca->View=1; 1950 | cs->type=1; 1951 | cs->XData=X; 1952 | cs->YData=Y; 1953 | cs->ZData=Z; 1954 | cs->CDataIndex.clear(); 1955 | cs->CData=C; 1956 | 1957 | surface_config(); 1958 | return h; 1959 | } 1960 | /// surf 1961 | int MatPlot::surf(dvec x, dvec y, dmat Z){ 1962 | int h=surface(); 1963 | ca->View=1; 1964 | cs->type=1; 1965 | cs->XData.resize(1); cs->XData[0]=x; 1966 | cs->YData.resize(1); cs->YData[0]=y; 1967 | cs->ZData=Z; 1968 | cs->CDataIndex=Z; 1969 | cs->CData.clear(); 1970 | cs->EdgeColor="k"; 1971 | cs->FaceColor="flat"; 1972 | surface_config(); 1973 | return h; 1974 | } 1975 | /// create pcolor 1976 | int MatPlot::pcolor(dmat C){ 1977 | 1978 | int h; h=surface(); 1979 | 1980 | cs->type=0; 1981 | cs->XData.clear(); 1982 | cs->YData.clear(); 1983 | cs->ZData.clear(); 1984 | cs->CDataIndex=C; 1985 | cs->CData.clear(); 1986 | 1987 | surface_config(); 1988 | 1989 | return h; 1990 | } 1991 | int MatPlot::pcolor(tcmat C){ 1992 | int h=surface(); 1993 | cs->type=0; 1994 | cs->XData.clear(); 1995 | cs->YData.clear(); 1996 | cs->ZData.clear(); 1997 | cs->CDataIndex.clear(); 1998 | cs->CData=C; 1999 | surface_config(); 2000 | return h; 2001 | } 2002 | int MatPlot::pcolor(dvec x, dvec y, dmat C){ 2003 | int h=surface(); 2004 | cs->type=0; 2005 | cs->XData.resize(1); cs->XData[0]=x; 2006 | cs->YData.resize(1); cs->YData[0]=y; 2007 | cs->ZData.clear(); 2008 | cs->CDataIndex=C; 2009 | cs->CData.clear(); 2010 | surface_config(); 2011 | return h; 2012 | } 2013 | int MatPlot::pcolor(dvec x, dvec y, tcmat C){ 2014 | int h=surface(); 2015 | cs->type=0; 2016 | cs->XData.resize(1); cs->XData[0]=x; 2017 | cs->YData.resize(1); cs->YData[0]=y; 2018 | cs->ZData.clear(); 2019 | cs->CDataIndex.clear(); 2020 | cs->CData=C; 2021 | surface_config(); 2022 | return h; 2023 | } 2024 | int MatPlot::pcolor(dmat X,dmat Y,dmat C){ 2025 | int h=surface(); 2026 | cs->type=0; 2027 | cs->XData=X; 2028 | cs->YData=Y; 2029 | cs->ZData.clear(); 2030 | cs->CDataIndex=C; 2031 | cs->CData.clear(); 2032 | surface_config(); 2033 | return h; 2034 | } 2035 | int MatPlot::pcolor(dmat X,dmat Y,tcmat C){ 2036 | int h=surface(); 2037 | cs->type=0; 2038 | cs->XData=X; 2039 | cs->YData=Y; 2040 | cs->ZData.clear(); 2041 | cs->CDataIndex.clear(); 2042 | cs->CData=C; 2043 | surface_config(); 2044 | return h; 2045 | } 2046 | 2047 | /// mesh 2048 | int MatPlot::mesh(dvec x, dvec y, dmat Z){ 2049 | int h=surface(); 2050 | ca->View=1; 2051 | cs->type=1; 2052 | cs->XData.resize(1); cs->XData[0]=x; 2053 | cs->YData.resize(1); cs->YData[0]=y; 2054 | cs->ZData=Z; 2055 | cs->CDataIndex=Z; 2056 | cs->CData.clear(); 2057 | cs->EdgeColor="k"; 2058 | cs->FaceColor="w"; 2059 | surface_config(); 2060 | return h; 2061 | } 2062 | 2063 | /// contour 2064 | int MatPlot::contour(dmat Z){ 2065 | int h=surface(); 2066 | cs->type=3; 2067 | cs->XData.clear(); 2068 | cs->YData.clear(); 2069 | cs->ZData=Z; 2070 | cs->NContour=0; 2071 | cs->V.clear(); 2072 | 2073 | surface_config(); 2074 | return h; 2075 | } 2076 | int MatPlot::contour(dmat Z,int n){ 2077 | int h=surface(); 2078 | cs->type=3; 2079 | cs->XData.clear(); 2080 | cs->YData.clear(); 2081 | cs->ZData=Z; 2082 | cs->NContour=n; 2083 | cs->V.clear(); 2084 | 2085 | surface_config(); 2086 | return h; 2087 | } 2088 | int MatPlot::contour(dmat Z, dvec v){ 2089 | int h=surface(); 2090 | cs->type=3; 2091 | cs->XData.clear(); 2092 | cs->YData.clear(); 2093 | cs->ZData=Z; 2094 | cs->NContour=v.size(); 2095 | cs->V=v; 2096 | 2097 | surface_config(); 2098 | return h; 2099 | } 2100 | int MatPlot::contour(dvec x,dvec y,dmat Z){ 2101 | int h=surface(); 2102 | cs->type=3; 2103 | cs->XData.resize(1); cs->XData[0]=x; 2104 | cs->YData.resize(1); cs->YData[0]=y; 2105 | cs->ZData=Z; 2106 | cs->NContour=0; 2107 | cs->V.clear(); 2108 | 2109 | surface_config(); 2110 | return h; 2111 | } 2112 | int MatPlot::contour(dvec x,dvec y,dmat Z,int n){ 2113 | int h=surface(); 2114 | cs->type=3; 2115 | cs->XData.resize(1); cs->XData[0]=x; 2116 | cs->YData.resize(1); cs->YData[0]=y; 2117 | cs->ZData=Z; 2118 | cs->NContour=n; 2119 | cs->V.clear(); 2120 | 2121 | surface_config(); 2122 | return h; 2123 | } 2124 | int MatPlot::contour(dvec x, dvec y, dmat Z, dvec v){ 2125 | int h=surface(); 2126 | cs->type=3; 2127 | cs->XData.resize(1); cs->XData[0]=x; 2128 | cs->YData.resize(1); cs->YData[0]=y; 2129 | cs->ZData=Z; 2130 | cs->NContour=v.size(); 2131 | cs->V=v; 2132 | 2133 | surface_config(); 2134 | return h; 2135 | } 2136 | /// display 2137 | void MatPlot::display_surface(){ 2138 | if(is_debug1){printf("mode: %d handle: %4d Surface type %d, Z.size %lu\n", 2139 | mode,cs->id,cs->type,cs->ZData.size());} 2140 | 2141 | //if(cs->type==0){ display_pcolor(); } 2142 | if(cs->type==0){ display_surface_2d(); } 2143 | if(cs->type==1){ display_surface_3d(); } 2144 | if(cs->type==2){ display_surface_3d(); } 2145 | if(cs->type==3){ display_contour(); } 2146 | 2147 | } 2148 | void MatPlot::display_surface_2d(){ 2149 | int nxi,nxj,nyi,nyj,nzi,nzj; 2150 | vector rgb; 2151 | nzi=cs->ZData.size(); if(nzi){nzj=cs->ZData[0].size();} 2152 | nxi=cs->XData.size(); if(nxi){nxj=cs->XData[0].size();} 2153 | nyi=cs->YData.size(); if(nyi){nyj=cs->YData[0].size();} 2154 | 2155 | //printf("%s %s:%d (%d %d) (%d %d) (%d %d) \n", __func__, __FILE__, __LINE__,nxi,nxj,nyi,nyj,nzi,nzj); 2156 | 2157 | // (Z) // do not use 2158 | if(nxi==0){ 2159 | printf("%s %s:%d\n", __func__, __FILE__, __LINE__); 2160 | // Edge 2161 | if(cs->EdgeColor != "none"){ 2162 | glLineWidth(cs->LineWidth); 2163 | rgb=ColorSpec2RGB(cs->EdgeColor); 2164 | glColor3d(rgb[0],rgb[1],rgb[2]); 2165 | 2166 | for(int i=0;iXLim[0]+(ca->XLim[1]-ca->XLim[0])*(float)(j)/(nzj-1)), 2170 | cty(ca->YLim[0]+(ca->YLim[1]-ca->YLim[0])*(float)(i)/(nzi-1))); 2171 | } 2172 | glEnd(); 2173 | } 2174 | /* 2175 | for(int j=0;jXLim[0]+(ca->XLim[1]-ca->XLim[0])*(float)(j)/(nzj-1)), 2179 | cty(ca->YLim[0]+(ca->YLim[1]-ca->YLim[0])*(float)(i)/(nzi-1))); 2180 | } 2181 | glEnd(); 2182 | } 2183 | */ 2184 | } 2185 | // Face 2186 | if(cs->FaceColor != "none"){ 2187 | for(int i=0;iFaceColor); 2191 | if(cs->FaceColor=="flat"){ rgb=cs->CData[i][j]; } 2192 | glColor3f(rgb[0],rgb[1],rgb[2]); 2193 | 2194 | glBegin(GL_QUADS); 2195 | glVertex2d(ctx(ca->XLim[0]+(ca->XLim[1]-ca->XLim[0])*(float)(j )/(float)(nzj-1)), 2196 | cty(ca->YLim[0]+(ca->YLim[1]-ca->YLim[0])*(float)(i )/(float)(nzi-1))); 2197 | glVertex2d(ctx(ca->XLim[0]+(ca->XLim[1]-ca->XLim[0])*(float)(j+1)/(float)(nzj-1)), 2198 | cty(ca->YLim[0]+(ca->YLim[1]-ca->YLim[0])*(float)(i )/(float)(nzi-1))); 2199 | glVertex2d(ctx(ca->XLim[0]+(ca->XLim[1]-ca->XLim[0])*(float)(j+1)/(float)(nzj-1)), 2200 | cty(ca->YLim[0]+(ca->YLim[1]-ca->YLim[0])*(float)(i+1)/(float)(nzi-1))); 2201 | glVertex2d(ctx(ca->XLim[0]+(ca->XLim[1]-ca->XLim[0])*(float)(j )/(float)(nzj-1)), 2202 | cty(ca->YLim[0]+(ca->YLim[1]-ca->YLim[0])*(float)(i+1)/(float)(nzi-1))); 2203 | glEnd(); 2204 | } 2205 | } 2206 | }//Face 2207 | } 2208 | 2209 | // (x,y,Z) // 2210 | if(nxi==1){ 2211 | //printf("%s %s:%d %d %d \n", __func__, __FILE__, __LINE__,nxj,nyj); 2212 | // Edge 2213 | if(cs->EdgeColor != "none"){ 2214 | 2215 | glLineWidth(cs->LineWidth); 2216 | rgb=ColorSpec2RGB(cs->EdgeColor); 2217 | glColor3d(rgb[0],rgb[1],rgb[2]); 2218 | 2219 | for(int i=0;iXData[0][j]),cty(cs->YData[0][i])); 2223 | //} 2224 | glVertex2d( ctx(cs->XData[0][ 0]),cty(cs->YData[0][i]) ); 2225 | glVertex2d( ctx(cs->XData[0][nxj-1]),cty(cs->YData[0][i]) ); 2226 | 2227 | glEnd(); 2228 | } 2229 | for(int j=0;jXData[0][j]), cty(cs->YData[0][i])); 2233 | //} 2234 | glVertex2d(ctx(cs->XData[0][j]),cty(cs->YData[0][0])); 2235 | glVertex2d(ctx(cs->XData[0][j]),cty(cs->YData[0][nyj-1])); 2236 | glEnd(); 2237 | } 2238 | } 2239 | // Face 2240 | if(cs->FaceColor != "none"){ 2241 | for(int i=0;iFaceColor); 2245 | if(cs->FaceColor=="flat"){ rgb=cs->CData[i][j]; } 2246 | glColor3f(rgb[0],rgb[1],rgb[2]); 2247 | 2248 | glBegin(GL_QUADS); 2249 | glVertex2d(ctx(cs->XData[0][j]), 2250 | cty(cs->YData[0][i]) ); 2251 | glVertex2d(ctx(cs->XData[0][j]), 2252 | cty(cs->YData[0][i+1]) ); 2253 | glVertex2d(ctx(cs->XData[0][j+1]), 2254 | cty(cs->YData[0][i+1]) ); 2255 | glVertex2d(ctx(cs->XData[0][j+1]), 2256 | cty(cs->YData[0][i]) ); 2257 | glEnd(); 2258 | } 2259 | } 2260 | } 2261 | }//nxi==1 2262 | 2263 | // (X,Y,C) // 2264 | if(nxi>1){ 2265 | // Edge 2266 | //printf("%s %s:%d\n", __func__, __FILE__, __LINE__); 2267 | if(cs->EdgeColor != "none"){ 2268 | glLineWidth(cs->LineWidth); 2269 | rgb=ColorSpec2RGB(cs->EdgeColor); 2270 | glColor3d(rgb[0],rgb[1],rgb[2]); 2271 | 2272 | for(int i=0;iXData[i][j]), 2276 | cty(cs->YData[i][j])); 2277 | } 2278 | glEnd(); 2279 | } 2280 | for(int j=0;jXData[i][j]), 2284 | cty(cs->YData[i][j])); 2285 | } 2286 | glEnd(); 2287 | } 2288 | } 2289 | // Face 2290 | if(cs->FaceColor != "none"){ 2291 | for(int i=0;iFaceColor); 2295 | if(cs->FaceColor=="flat"){rgb=cs->CData[i][j]; } 2296 | glColor3f(rgb[0],rgb[1],rgb[2]); 2297 | 2298 | glBegin(GL_QUADS); 2299 | glVertex2d(ctx(cs->XData[i ][j]), 2300 | cty(cs->YData[i ][j]) ); 2301 | glVertex2d(ctx(cs->XData[i ][j+1]), 2302 | cty(cs->YData[i ][j+1]) ); 2303 | glVertex2d(ctx(cs->XData[i+1][j+1]), 2304 | cty(cs->YData[i+1][j+1]) ); 2305 | glVertex2d(ctx(cs->XData[i+1][j]), 2306 | cty(cs->YData[i+1][j]) ); 2307 | glEnd(); 2308 | } 2309 | } 2310 | } 2311 | } 2312 | } 2313 | 2314 | /// display 3d 2315 | void MatPlot::display_surface_3d(){ 2316 | vector rgb; 2317 | int ny=cs->ZData.size(); 2318 | int nx=cs->ZData[0].size(); 2319 | 2320 | if(cs->XData.size()==1){ 2321 | //(x,y,Z); 2322 | //Face 2323 | if(cs->FaceColor != "none"){ 2324 | for(int i=0;iFaceColor); 2327 | glColor3d(rgb[0], rgb[1], rgb[2]); 2328 | if(cs->FaceColor=="flat"){ 2329 | rgb=cs->CData[i][j]; 2330 | glColor3f(rgb[0],rgb[1],rgb[2]); 2331 | } 2332 | glBegin(GL_TRIANGLES); 2333 | glVertex3d(ct3x(cs->XData[0][j]), 2334 | ct3y(cs->YData[0][i]), 2335 | ct3z(cs->ZData[i][j]) ); 2336 | glVertex3d(ct3x(cs->XData[0][j]), 2337 | ct3y(cs->YData[0][i+1]), 2338 | ct3z(cs->ZData[i+1][j]) ); 2339 | glVertex3d(ct3x(cs->XData[0][j+1]), 2340 | ct3y(cs->YData[0][i+1]), 2341 | ct3z(cs->ZData[i+1][j+1]) ); 2342 | glEnd(); 2343 | glBegin(GL_TRIANGLES); 2344 | glVertex3d(ct3x(cs->XData[0][j]), 2345 | ct3y(cs->YData[0][i]), 2346 | ct3z(cs->ZData[i][j]) ); 2347 | glVertex3d(ct3x(cs->XData[0][j+1]), 2348 | ct3y(cs->YData[0][i]), 2349 | ct3z(cs->ZData[i][j+1]) ); 2350 | glVertex3d(ct3x(cs->XData[0][j+1]), 2351 | ct3y(cs->YData[0][i+1]), 2352 | ct3z(cs->ZData[i+1][j+1]) ); 2353 | glEnd(); 2354 | } 2355 | } 2356 | } 2357 | // Edge 2358 | if(cs->EdgeColor != "none"){ 2359 | glLineWidth(cs->LineWidth); 2360 | rgb=ColorSpec2RGB(cs->EdgeColor); 2361 | glColor3d(rgb[0], rgb[1], rgb[2]); 2362 | 2363 | for(int i=0;iXData[0][j]), 2367 | ct3y(cs->YData[0][i]), 2368 | ct3z(cs->ZData[i][j]) ); 2369 | } 2370 | glEnd(); 2371 | } 2372 | for(int j=0;jXData[0][j]), 2376 | ct3y(cs->YData[0][i]), 2377 | ct3z(cs->ZData[i][j]) ); 2378 | } 2379 | glEnd(); 2380 | } 2381 | } 2382 | }// (x,y,Z) 2383 | // (X,Y,Z) // 2384 | if(cs->XData.size()>1){ 2385 | 2386 | //Face 2387 | if(cs->FaceColor != "none"){ 2388 | for(int i=0;iFaceColor); 2391 | glColor3d(rgb[0], rgb[1], rgb[2]); 2392 | if(cs->FaceColor=="flat"){ 2393 | rgb=cs->CData[i][j]; 2394 | glColor3f(rgb[0],rgb[1],rgb[2]); 2395 | } 2396 | 2397 | glBegin(GL_TRIANGLES); 2398 | glVertex3d(ct3x(cs->XData[i][j]), 2399 | ct3y(cs->YData[i][j]), 2400 | ct3z(cs->ZData[i][j]) ); 2401 | glVertex3d(ct3x(cs->XData[i][j+1]), 2402 | ct3y(cs->YData[i][j+1]), 2403 | ct3z(cs->ZData[i][j+1]) ); 2404 | glVertex3d(ct3x(cs->XData[i+1][j+1]), 2405 | ct3y(cs->YData[i+1][j+1]), 2406 | ct3z(cs->ZData[i+1][j+1]) ); 2407 | glEnd(); 2408 | 2409 | glBegin(GL_TRIANGLES); 2410 | glVertex3d(ct3x(cs->XData[i][j]), 2411 | ct3y(cs->YData[i][j]), 2412 | ct3z(cs->ZData[i][j]) ); 2413 | glVertex3d(ct3x(cs->XData[i+1][j]), 2414 | ct3y(cs->YData[i+1][j]), 2415 | ct3z(cs->ZData[i+1][j]) ); 2416 | glVertex3d(ct3x(cs->XData[i+1][j+1]), 2417 | ct3y(cs->YData[i+1][j+1]), 2418 | ct3z(cs->ZData[i+1][j+1]) ); 2419 | glEnd(); 2420 | } 2421 | } 2422 | } 2423 | // Edge 2424 | if(cs->EdgeColor != "none"){ 2425 | glLineWidth(cs->LineWidth); 2426 | rgb=ColorSpec2RGB(cs->EdgeColor); 2427 | glColor3d(rgb[0], rgb[1], rgb[2]); 2428 | 2429 | for(int i=0;iXData[i][j]), 2433 | ct3y(cs->YData[i][j]), 2434 | ct3z(cs->ZData[i][j]) ); 2435 | } 2436 | glEnd(); 2437 | } 2438 | for(int j=0;jXData[i][j]), 2442 | ct3y(cs->YData[i][j]), 2443 | ct3z(cs->ZData[i][j]) ); 2444 | } 2445 | glEnd(); 2446 | } 2447 | } 2448 | }//(X,Y,Z) 2449 | } 2450 | /// dispaly contour 2451 | dmat contourc(dvec x, dvec y, dmat Z, dvec v){ 2452 | //Z(i,j), x(j),y(i) 2453 | double x0,y0,z0; 2454 | int ny=Z.size(); 2455 | int nx=Z[0].size(); 2456 | dmat C; 2457 | ContourPoint c; 2458 | vector vc; 2459 | deque ac; 2460 | C.resize(2); 2461 | //z0=0.1; 2462 | //v.clear();v.push_back(0.2);v.push_back(0.1); 2463 | int is_print=0; 2464 | 2465 | 2466 | 2467 | for(int iv=0;iv2)) ){ 2526 | if( (c.xy==0) && (vc[m].xy==0) && (vc[m].xj==c.xj ) && (vc[m].yi==c.yi-1) ){ is=1; } 2527 | if( (c.xy==0) && (vc[m].xy==0) && (vc[m].xj==c.xj ) && (vc[m].yi==c.yi+1) ){ is=2; } 2528 | if( (c.xy==0) && (vc[m].xy==1) && (vc[m].xj==c.xj ) && (vc[m].yi==c.yi ) ){ is=3; } 2529 | if( (c.xy==0) && (vc[m].xy==1) && (vc[m].xj==c.xj+1) && (vc[m].yi==c.yi ) ){ is=4; } 2530 | if( (c.xy==0) && (vc[m].xy==1) && (vc[m].xj==c.xj ) && (vc[m].yi==c.yi-1) ){ is=5; } 2531 | if( (c.xy==0) && (vc[m].xy==1) && (vc[m].xj==c.xj+1) && (vc[m].yi==c.yi-1) ){ is=6; } 2532 | if( (c.xy==1) && (vc[m].xy==1) && (vc[m].xj==c.xj+1) && (vc[m].yi==c.yi ) ){ is=7; } 2533 | if( (c.xy==1) && (vc[m].xy==1) && (vc[m].xj==c.xj-1) && (vc[m].yi==c.yi ) ){ is=8; } 2534 | if( (c.xy==1) && (vc[m].xy==0) && (vc[m].xj==c.xj ) && (vc[m].yi==c.yi ) ){ is=9; } 2535 | if( (c.xy==1) && (vc[m].xy==0) && (vc[m].xj==c.xj ) && (vc[m].yi==c.yi+1) ){ is=10; } 2536 | if( (c.xy==1) && (vc[m].xy==0) && (vc[m].xj==c.xj-1) && (vc[m].yi==c.yi ) ){ is=11; } 2537 | if( (c.xy==1) && (vc[m].xy==0) && (vc[m].xj==c.xj-1) && (vc[m].yi==c.yi+1) ){ is=12; } 2538 | } 2539 | if(is){kk=m;} 2540 | m++; 2541 | } 2542 | if(is){ 2543 | vc[kk].done=1; 2544 | c=vc[kk]; 2545 | } 2546 | if(mode==1){ 2547 | if(is){ 2548 | ac.push_back(vc[kk]); 2549 | mode_next=1; 2550 | }else{ 2551 | mode_next=2; 2552 | } 2553 | } 2554 | if(mode==3){ 2555 | if(is){ 2556 | ac.push_front(vc[kk]); 2557 | mode_next=3; 2558 | }else{ 2559 | mode_next=4; 2560 | } 2561 | } 2562 | } 2563 | if(mode==2){// set first terminal 2564 | c=ac[0]; 2565 | mode_next=3; 2566 | } 2567 | if(mode==4){// move the accumlated points 2568 | if(ac.size()){ 2569 | C[0].push_back(z0); 2570 | C[1].push_back(ac.size()); 2571 | for(int i=0;i rgb; 2596 | //int ny=cs->ZData.size(); 2597 | //int nx=cs->ZData[0].size(); 2598 | vector< vector< double > > C; 2599 | double xx,yy; 2600 | 2601 | C=contourc(cs->XData[0],cs->YData[0],cs->ZData,cs->V); 2602 | 2603 | glDisable(GL_LINE_STIPPLE); 2604 | gl2psDisable(GL2PS_LINE_STIPPLE); 2605 | 2606 | //glLineWidth(cl->LineWidth); 2607 | glLineWidth(2); 2608 | gl2psLineWidth(2); 2609 | 2610 | //rgb=cs->CData[i][j]; 2611 | //glColor3f(rgb[0],rgb[1],rgb[2]); 2612 | glColor3f(0,0,0); 2613 | 2614 | //TODO: adjust line color and properties 2615 | int k=0,nk; 2616 | for(int i=0;ink){ 2629 | k=0; 2630 | glEnd(); 2631 | } 2632 | } 2633 | } 2634 | 2635 | dmat MatPlot::peaks(int n){ 2636 | 2637 | float x1=1,y1=0; 2638 | float x2=-1,y2=1; 2639 | float x3=-0.5,y3=-1; 2640 | float sr1,sr2,sr3; 2641 | float sigma=0.4; 2642 | float a1=1,a2=0.5,a3=0.3; 2643 | double x,y; 2644 | //vector< vector< double > > Z(n,n); 2645 | dmat Z(n,dvec(n)); 2646 | for(int i=0;iadd_child(h); 2667 | vPatch.push_back(Patch(h)); 2668 | //as.Parent=gca(); 2669 | } 2670 | if(mode==1){ 2671 | 2672 | } 2673 | if(iPatchxmax=fmax( Fmax(cp->XData), ca->xmax); 2679 | ca->xmin=fmin( Fmin(cp->XData), ca->xmin); 2680 | ca->ymax=fmax( Fmax(cp->YData), ca->ymax); 2681 | ca->ymin=fmin( Fmin(cp->YData), ca->ymin); 2682 | ca->zmax=fmax( Fmax(cp->ZData), ca->zmax ); 2683 | ca->zmin=fmin( Fmin(cp->ZData), ca->zmin ); 2684 | } 2685 | tcvec MatPlot::Index2TrueColor(dvec IC){ 2686 | if(ca->CLim[0]==ca->CLim[1]){ 2687 | ca->CLim[0]=fmin( Fmin(IC), Fmin(IC) ); 2688 | ca->CLim[1]=fmax( Fmax(IC), Fmax(IC) ); 2689 | } 2690 | vector rgb; 2691 | tcvec tc; 2692 | for(int j=0;jCLim[0],ca->CLim[1]); 2694 | tc.push_back(rgb); 2695 | } 2696 | return tc; 2697 | } 2698 | /// patch 2699 | int MatPlot::patch(dmat X,dmat Y){ 2700 | // Single color 2701 | int h=patch(); 2702 | cp->type=0; 2703 | 2704 | cp->XData=X; 2705 | cp->YData=Y; 2706 | cp->ZData.clear(); 2707 | cp->CData.clear(); 2708 | 2709 | patch_config(); 2710 | return h; 2711 | } 2712 | int MatPlot::patch(dmat X,dmat Y,dvec C){ 2713 | // One color per face with index color 2714 | int h=patch(); 2715 | cp->type=0; 2716 | cp->XData=X; 2717 | cp->YData=Y; 2718 | cp->ZData.clear(); 2719 | cp->CData=Index2TrueColor(C); 2720 | 2721 | patch_config(); 2722 | return h; 2723 | } 2724 | int MatPlot::patch(dmat X,dmat Y,tcvec C){ 2725 | // One color per face with true color 2726 | int h=patch(); 2727 | cp->type=0; 2728 | cp->XData=X; 2729 | cp->YData=Y; 2730 | cp->ZData.clear(); 2731 | cp->CData=C; 2732 | 2733 | patch_config(); 2734 | return h; 2735 | } 2736 | int MatPlot::patch(dmat X,dmat Y,dmat Z){ 2737 | // Single color 2738 | int h=patch(); 2739 | ca->View=1; 2740 | cp->type=1; 2741 | cp->XData=X; 2742 | cp->YData=Y; 2743 | cp->ZData=Z; 2744 | cp->CData.clear(); 2745 | 2746 | patch_config(); 2747 | return h; 2748 | } 2749 | int MatPlot::patch(dmat X,dmat Y,dmat Z,dvec C){ 2750 | // One color per face 2751 | int h=patch(); 2752 | ca->View=1; 2753 | cp->type=1; 2754 | 2755 | cp->XData=X; 2756 | cp->YData=Y; 2757 | cp->ZData=Z; 2758 | cp->CData=Index2TrueColor(C); 2759 | 2760 | patch_config(); 2761 | return h; 2762 | } 2763 | int MatPlot::patch(dmat X,dmat Y,dmat Z,tcvec C){ 2764 | // One color per face 2765 | int h=patch(); 2766 | ca->View=1; 2767 | cp->type=1; 2768 | 2769 | cp->XData=X; 2770 | cp->YData=Y; 2771 | cp->ZData=Z; 2772 | cp->CData=C; 2773 | 2774 | patch_config(); 2775 | return h; 2776 | } 2777 | /// bar 2778 | 2779 | int MatPlot::bar(dvec y){ 2780 | dvec x; 2781 | x.resize(y.size()); 2782 | for(int i=0;itype=0; 2801 | cp->XData.clear(); 2802 | cp->YData.clear(); 2803 | cp->ZData.clear(); 2804 | //cp->CData.clear(); 2805 | 2806 | double wx=width*(Fmax(x)-Fmin(x))/x.size(); 2807 | 2808 | dvec X(4),Y(4); 2809 | for(int i=0;iXData.push_back(X); 2815 | cp->YData.push_back(Y); 2816 | } 2817 | patch_config(); 2818 | return h; 2819 | } 2820 | 2821 | /// display 2822 | 2823 | void MatPlot::display_patch(){ 2824 | if(is_debug1){printf("display:%4d Patch :type %d, Faces.size %lu\n", 2825 | cp->id,cp->type,cp->Faces.size());} 2826 | 2827 | if(cp->type==0){ display_patch_2d(); } 2828 | if(cp->type==1){ display_patch_3d(); } 2829 | } 2830 | 2831 | void MatPlot::display_patch_2d(){ 2832 | // FaceVertex & CData // 2833 | 2834 | vector v(3); 2835 | vector f(3); 2836 | float x,y; 2837 | for(int i=0;iFaces.size();++i){ 2838 | f=cp->Faces[i]; 2839 | glBegin(GL_TRIANGLES); 2840 | x=ctx(cp->Vertices[f[0]][0]); 2841 | y=cty(cp->Vertices[f[0]][1]); 2842 | glVertex2d(x,y); 2843 | x=ctx(cp->Vertices[f[1]][0]); 2844 | y=cty(cp->Vertices[f[1]][1]); 2845 | glVertex2d(x,y); 2846 | x=ctx(cp->Vertices[f[2]][0]); 2847 | y=cty(cp->Vertices[f[2]][1]); 2848 | glVertex2d(x,y); 2849 | glEnd(); 2850 | } 2851 | 2852 | 2853 | // XYZ Data // 2854 | int nf,nv;//number of faces and vertex 2855 | nf=cp->XData.size(); 2856 | vector rgb; 2857 | 2858 | for(int i=0;iXData[i].size(); 2860 | 2861 | // Edge 2862 | if(cp->EdgeColor!="none"){ 2863 | 2864 | glLineWidth(cp->LineWidth); 2865 | gl2psLineWidth(cp->LineWidth); 2866 | 2867 | rgb=ColorSpec2RGB(cp->EdgeColor); 2868 | glColor3f(rgb[0],rgb[1],rgb[2]); 2869 | 2870 | glBegin(GL_LINE_LOOP); 2871 | for(int iv=0;ivXData[i][iv]), 2873 | cty(cp->YData[i][iv]) ); 2874 | } 2875 | glEnd(); 2876 | 2877 | } 2878 | // Face 2879 | if(cp->FaceColor!="none"){ 2880 | 2881 | rgb=ColorSpec2RGB(cp->FaceColor); 2882 | glColor3f(rgb[0],rgb[1],rgb[2]); 2883 | 2884 | if(cp->CData.size()){ 2885 | rgb=cp->CData[i]; 2886 | glColor3d(rgb[0],rgb[1],rgb[2]); 2887 | } 2888 | 2889 | glBegin(GL_POLYGON); 2890 | for(int iv=0;ivXData[i][iv]), 2892 | cty(cp->YData[i][iv]) ); 2893 | } 2894 | glEnd(); 2895 | 2896 | } 2897 | } 2898 | 2899 | 2900 | } 2901 | void MatPlot::display_patch_3d(){ 2902 | // FaceVertex & CData // 2903 | // XYZ Data // 2904 | int nf,nv;//number of faces and vertex 2905 | nf=cp->XData.size(); 2906 | vector rgb; 2907 | 2908 | for(int i=0;iXData[i].size(); 2910 | 2911 | // Edge 2912 | if(cp->EdgeColor!="none"){ 2913 | 2914 | glLineWidth(cp->LineWidth); 2915 | gl2psLineWidth(cp->LineWidth); 2916 | 2917 | rgb=ColorSpec2RGB(cp->EdgeColor); 2918 | glColor3f(rgb[0],rgb[1],rgb[2]); 2919 | 2920 | glBegin(GL_LINE_LOOP); 2921 | for(int iv=0;ivXData[i][iv]), 2923 | ct3y(cp->YData[i][iv]), 2924 | ct3z(cp->ZData[i][iv]) ); 2925 | } 2926 | glEnd(); 2927 | 2928 | } 2929 | // Face 2930 | if(cp->FaceColor!="none"){ 2931 | 2932 | rgb=ColorSpec2RGB(cp->FaceColor); 2933 | glColor3f(rgb[0],rgb[1],rgb[2]); 2934 | 2935 | if(cp->CData.size()){ 2936 | rgb=cp->CData[i]; 2937 | glColor3d(rgb[0],rgb[1],rgb[2]); 2938 | } 2939 | 2940 | glBegin(GL_POLYGON); 2941 | for(int iv=0;ivXData[i][iv]), 2943 | ct3y(cp->YData[i][iv]), 2944 | ct3z(cp->ZData[i][iv]) 2945 | ); 2946 | } 2947 | glEnd(); 2948 | 2949 | } 2950 | } 2951 | } 2952 | // Text /// 2953 | //TODO more fonts 2954 | /// text 2955 | int MatPlot::text(){ 2956 | int h=iText*100 + tText; hObj=h; 2957 | if(is_debug1){printf("mode: %d handle: %4d Text\n",mode,h);} 2958 | 2959 | if(mode==0){ 2960 | vText.push_back(Text(h)); 2961 | ca->add_child(h); 2962 | //at.Parent=gca(); 2963 | } 2964 | if(mode==1){ 2965 | } 2966 | if(iTextid);} 2972 | glColor3f(0,0,0); 2973 | glRasterPos2f( ctx(ct->Position[0]), cty(ct->Position[1]) ); 2974 | gl2psText(ct->String.c_str(), "Arial", 12); 2975 | for(int i=0; i<(int)ct->String.size(); ++i ){ 2976 | glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, ct->String[i] ); 2977 | } 2978 | } 2979 | int MatPlot::text(double x,double y,string s){ 2980 | // text on current axes 2981 | //if(is_debug1){cout<<"mode:"<Position[0]=x; 2984 | ct->Position[1]=y; 2985 | ct->String=s; 2986 | return h; 2987 | } 2988 | void MatPlot::set_font(char font_[],int size){ 2989 | //font=font_; 2990 | //font_size=size; 2991 | } 2992 | /// ptext 2993 | void MatPlot::ptext(float x,float y,string s){ 2994 | // Viewport Figure 2995 | glViewport(0,0, (int)(window_w),(int)(window_h)); 2996 | glLoadIdentity(); 2997 | gluOrtho2D( 0.0, 1.0, 0.0, 1.0 ); 2998 | 2999 | glColor3f(0,0,0); 3000 | glRasterPos2f( x, y ); 3001 | gl2psText(s.c_str(), "Arial", 12); 3002 | //gl2psText(test, "Times-Roman", 24); 3003 | 3004 | for(int i=0; i<(int)s.size(); i++ ){ 3005 | glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, s[i] ); 3006 | } 3007 | } 3008 | void MatPlot::ptext3(float x,float y,float z,string s){ 3009 | glColor3f(0,0,0); 3010 | glRasterPos3d(x,y,z); 3011 | gl2psText(s.c_str(), "Arial", 12); 3012 | for(int i=0; i<(int)s.size(); i++ ){ 3013 | glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, s[i] ); 3014 | } 3015 | } 3016 | void MatPlot::ptext3c(float x,float y,float z,string s){ 3017 | int char_w=6,char_h=12; 3018 | int num_char=s.length(); 3019 | glColor3f(0,0,0); 3020 | glRasterPos3d(x,y,z); 3021 | glBitmap(0,0,0,0,-char_w*num_char/2,-char_h/2,NULL); 3022 | gl2psText(s.c_str(), "Arial", 12); 3023 | 3024 | for(int i=0; i<(int)s.size(); i++ ){ 3025 | glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, s[i] ); 3026 | } 3027 | } 3028 | 3029 | 3030 | /// Color /// 3031 | 3032 | void MatPlot::Shading(string c){ 3033 | shading(c); 3034 | } 3035 | void MatPlot::shading(string c){ 3036 | 3037 | int tObj=hObj%100; 3038 | int iObj=hObj/100; 3039 | if( (tObj==tSurface) && (iObj MatPlot::colormap(string c,float t){ 3052 | 3053 | vector rgb(3); 3054 | if(t>1){t=1;} 3055 | if(t<0){t=0;} 3056 | 3057 | if( c=="Gray" ){ 3058 | rgb[0]=t; 3059 | rgb[1]=t; 3060 | rgb[2]=t; 3061 | return rgb; 3062 | } 3063 | if( c=="HSV" ){ 3064 | t*=6; 3065 | if( 0<=t && t<=1.0){rgb[0] = 1; rgb[1] = t; rgb[2] = 0;} 3066 | if(1.0<=t && t<=2.0){rgb[0] = 1-(t-1); rgb[1] = 1; rgb[2] = 0;} 3067 | if(2.0<=t && t<=3.0){rgb[0] = 0; rgb[1] = 1; rgb[2] = t-2;} 3068 | if(3.0<=t && t<=4.0){rgb[0] = 0; rgb[1] = 1-(t-3); rgb[2] = 1;} 3069 | if(4.0<=t && t<=5.0){rgb[0] = t-4; rgb[1] = 0; rgb[2] = 1;} 3070 | if(5.0<=t && t<=6.0){rgb[0] = 1; rgb[1] = 0; rgb[2] = 1-(t-5);} 3071 | 3072 | return rgb; 3073 | } 3074 | if( c=="Jet" ){ 3075 | t*=8; 3076 | if( 0<=t && t<=1.0){rgb[0] = 0; rgb[1] = 0; rgb[2] = 0.5+0.5*t;} 3077 | if(1.0<=t && t<=3.0){rgb[0] = 0; rgb[1] = 0.5*(t-1); rgb[2] = 1;} 3078 | if(3.0<=t && t<=5.0){rgb[0] = 0.5*(t-3);rgb[1] = 1; rgb[2] = 1-0.5*(t-3);} 3079 | if(5.0<=t && t<=7.0){rgb[0] = 1; rgb[1] = 1-0.5*(t-5);rgb[2] = 0;} 3080 | if(7.0<=t && t<=8.0){rgb[0] = 1-0.5*(t-7);rgb[1] = 0; rgb[2] = 0;} 3081 | return rgb; 3082 | } 3083 | if( c=="Hot" ){ 3084 | t*=3; 3085 | if( 0<=t && t<=1.0){rgb[0] = t; rgb[1] = 0; rgb[2] = 0;} 3086 | if(1.0<=t && t<=2.0){rgb[0] = 1; rgb[1] = t-1; rgb[2] = 0;} 3087 | if(2.0<=t && t<=3.0){rgb[0] = 1; rgb[1] = 1; rgb[2] = t-2;} 3088 | return rgb; 3089 | } 3090 | 3091 | if( c=="Cool" ){ 3092 | rgb[0]=t; 3093 | rgb[1]=1-t; 3094 | rgb[2]=1; 3095 | return rgb; 3096 | } 3097 | if( c=="Spring" ){// Magenta - Yellow 3098 | rgb[0]=1; 3099 | rgb[1]=t; 3100 | rgb[2]=1-t; 3101 | return rgb; 3102 | } 3103 | if( c=="Summer" ){// Green Yellow 3104 | rgb[0]=t; 3105 | rgb[1]=1; 3106 | rgb[2]=0; 3107 | return rgb; 3108 | } 3109 | if( c=="Autumn" ){ 3110 | rgb[0]=1; 3111 | rgb[1]=t; 3112 | rgb[2]=0; 3113 | return rgb; 3114 | } 3115 | if( c=="Winter" ){ 3116 | rgb[0]=0; 3117 | rgb[1]=t; 3118 | rgb[2]=1-t; 3119 | return rgb; 3120 | } 3121 | if( c=="Bone" ){ 3122 | rgb[0]=t; 3123 | //rgb[1]=t;if(t<0.8){rgb[1]=t;} 3124 | rgb[2]=t; 3125 | return rgb; 3126 | } 3127 | } 3128 | void MatPlot::colormap(string c){ 3129 | //if(is_debug1){printf("colormap %s \n",c.c_str());} 3130 | int n; 3131 | float t; 3132 | vector rgb(3); 3133 | 3134 | cmap.clear(); 3135 | n=64; 3136 | for(int i=0;iiColorMap=iColorMap; 3142 | cs->ColorMap=c; 3143 | } 3144 | } 3145 | void MatPlot::colormap(vector > c){ 3146 | cmap=c; 3147 | } 3148 | void MatPlot::gray(){colormap("Gray");}; 3149 | void MatPlot::jet(){ colormap("Jet"); } 3150 | void MatPlot::hsv(){ colormap("HSV"); } 3151 | void MatPlot::hot(){ colormap("Hot"); } 3152 | void MatPlot::cool(){colormap("Cool");} 3153 | void MatPlot::spring(){colormap("Spring");} 3154 | void MatPlot::summer(){colormap("Summer");} 3155 | void MatPlot::autumn(){colormap("Autumn");} 3156 | void MatPlot::winter(){colormap("Winter");} 3157 | 3158 | vector MatPlot::map2color(double x,double xmin,double xmax){ 3159 | int n=cmap.size(); 3160 | float normx; 3161 | vector rgb(3); 3162 | 3163 | normx=(x-xmin)/(xmax-xmin); 3164 | if(x>xmax){normx=1;} 3165 | if(x MatPlot::ColorSpec2RGB(string c){ 3173 | float r,g,b; 3174 | //line 3175 | if( c=="k" ){r=0;g=0;b=0;}// black 3176 | if( c=="r" ){r=1;g=0;b=0;}// red 3177 | if( c=="b" ){r=0;g=0;b=1;}// blue 3178 | if( c=="g" ){r=0;g=1;b=0;}// green 3179 | if( c=="c" ){r=0;g=1;b=1;}// cyan 3180 | if( c=="m" ){r=1;g=0;b=1;}// magenta 3181 | if( c=="y" ){r=1;g=1;b=0;}// yellow 3182 | if( c=="w" ){r=1;g=1;b=1;}// white 3183 | 3184 | //dark color 3185 | float h=0.6; 3186 | if( c=="dr" ){r=h;g=0;b=0;}// red 3187 | if( c=="db" ){r=0;g=0;b=h;}// blue 3188 | if( c=="dg" ){r=0;g=h;b=0;}// green 3189 | if( c=="dc" ){r=0;g=h;b=h;}// cyan 3190 | if( c=="dm" ){r=h;g=0;b=h;}// magenta 3191 | if( c=="dy" ){r=h;g=h;b=0;}// yellow 3192 | 3193 | //light color 3194 | h=0.5; 3195 | if( c=="lr" ){r=1;g=h;b=h;}// red 3196 | if( c=="lb" ){r=h;g=h;b=1;}// blue 3197 | if( c=="lg" ){r=h;g=1;b=h;}// green 3198 | if( c=="lc" ){r=h;g=1;b=1;}// cyan 3199 | if( c=="lm" ){r=1;g=h;b=1;}// magenta 3200 | if( c=="ly" ){r=1;g=1;b=h;}// yellow 3201 | 3202 | //universal color 3203 | if( c=="ur" ){r=1; g=0.2; b=0; }//red 3204 | if( c=="ub" ){r=0; g=0.25;b=1; }//blue 3205 | if( c=="ug" ){r=0.2; g=0.6; b=0.4;}//green 3206 | if( c=="uy" ){r=1; g=1; b=1; }//yellow 3207 | if( c=="uc" ){r=0.4; g=0.8; b=1; }//sky blue 3208 | if( c=="up" ){r=1; g=0.6; b=0.6;}//pink 3209 | if( c=="uo" ){r=1; g=0.6; b=0; }//orange 3210 | if( c=="um" ){r=0.6; g=0; b=0.4;}//perple 3211 | if( c=="ubr"){r=0.4; g=0.2; b=0; }//brown 3212 | 3213 | char line[1000],*tp; 3214 | char d[]=" ,:\t\n[]";//delimiter 3215 | /* 3216 | if(c.size()){ 3217 | if( (c[0]=='[') && (c[c.size()-1]==']') ){ 3218 | sprintf(line,c.c_str()); 3219 | tp=strtok(line,d); if(tp){r=atof(tp);} 3220 | tp=strtok(NULL,d); if(tp){g=atof(tp);} 3221 | tp=strtok(NULL,d); if(tp){b=atof(tp);} 3222 | } 3223 | } 3224 | */ 3225 | //cout <<"c,r,g,b: "<< c <<" "< out(3); 3227 | out[0]=r; 3228 | out[1]=g; 3229 | out[2]=b; 3230 | return out; 3231 | 3232 | } 3233 | string MatPlot::rgb2colorspec(vector rgb){ 3234 | char c[100]; 3235 | sprintf(c,"[%f %f %f]",rgb[0],rgb[1],rgb[2]); 3236 | string s=c; 3237 | return s; 3238 | } 3239 | 3240 | 3241 | --------------------------------------------------------------------------------