├── .gitignore
├── .qmake.conf
├── .travis.yml
├── LICENSE
├── Muview.DS_Store
├── README.md
├── deploy
├── MakefileInstall
├── appveyor.yml
├── background-dmg.png
├── deployLinux.sh
├── deployLinux_travis.sh
├── deployMacOSX.sh
├── deployWin32.bat
└── deployWindows.sh
├── example.omf
├── muview.pro
├── pretty_dmg.applescript
└── source
├── OMFEndian.h
├── OMFImport.cpp
├── OMFImport.h
├── aboutdialog.cpp
├── aboutdialog.h
├── aboutdialog.ui
├── glwidget.cpp
├── glwidget.h
├── glwidget_assets.cpp
├── glwidget_input.cpp
├── main.cpp
├── matrix.cpp
├── matrix.h
├── preferences.cpp
├── preferences.h
├── preferences.ui
├── qxtspanslider.cpp
├── qxtspanslider.h
├── qxtspanslider_p.h
├── resources.qrc
├── resources
├── 128x128
│ └── muview.png
├── 16x16
│ └── muview.png
├── 256x256
│ └── muview.png
├── 32x32
│ └── muview.png
├── 512x512
│ └── muview.png
├── 64x64
│ └── muview.png
├── muview.desktop
├── muview.icns
├── splash.png
└── splash2.png
├── shaders
├── cube.frag
├── cube.vert
├── standard.frag
└── standard.vert
├── source.pro
├── window.cpp
├── window.h
└── window.ui
/.gitignore:
--------------------------------------------------------------------------------
1 | moc_*.cpp
2 | muview
3 | install
4 | test
5 | *.o
6 | *.a
7 | ui_*
8 | Makefile
9 | muview.pro.user*
10 | qrc_*
11 | .qmake.stash
12 | .DS_Store
13 | *.dmg
14 | *.app
15 |
--------------------------------------------------------------------------------
/.qmake.conf:
--------------------------------------------------------------------------------
1 | top_srcdir=$$PWD
2 | top_builddir=$$shadowed($$PWD)
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 | cache:
3 | ccache: true
4 | directories:
5 | - /var/cache/apt/archives
6 |
7 | matrix:
8 | include:
9 | - os: linux
10 | dist: xenial
11 | sudo: required
12 | compiler: clang
13 | - os: osx
14 | osx_image: xcode10.2
15 | sudo: required
16 | compiler: clang
17 |
18 | before_install:
19 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
20 | brew update;
21 | brew install qt5;
22 | brew upgrade qt5;
23 | echo "Adding brewed Qt5 to path";
24 | export PATH=/usr/local/opt/qt5/bin:$PATH;
25 | qmake -v;
26 | fi
27 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
28 | sudo apt-get -y install libgl1-mesa-dev
29 |
30 | echo "Installing Qt 5.12.3";
31 | sudo add-apt-repository --yes ppa:beineri/opt-qt-5.12.3-xenial;
32 | sudo apt-get update -qq;
33 | sudo apt-get -y install qt512base qt5123d qt512tools qt512x11extras;
34 | source /opt/qt512/bin/qt512-env.sh;
35 | which qmake;
36 | qmake -v;
37 |
38 | echo "Installing Fuse";
39 | sudo apt-get install -qq pkg-config fuse;
40 | sudo modprobe fuse;
41 | sudo chmod 666 /dev/fuse;
42 | sudo chown root:$USER /etc/fuse.conf;
43 |
44 | cd /home/travis/build;
45 | mkdir linuxdeployqt && cd linuxdeployqt;
46 | wget https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage -O linuxdeployqt;
47 | chmod a+x linuxdeployqt;
48 | export PATH=$PATH:/home/travis/build/linuxdeployqt;
49 |
50 | cd /home/travis/build;
51 | ( wget https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2 && tar xf patchelf-0.9.tar.bz2);
52 | ( cd patchelf-0.9/ && ./configure --prefix=$HOME/patchelf && make && make install && cd ..);
53 | export PATH=$PATH:$HOME/patchelf/bin;
54 |
55 | cd /home/travis/build;
56 | mkdir appimagetool && cd appimagetool;
57 | wget https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool;
58 | chmod a+x appimagetool;
59 | export PATH=$PATH:/home/travis/build/appimagetool;
60 |
61 | fi
62 | script:
63 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
64 | echo "Preparing to deploy Muview2";
65 | bash deploy/deployMacOSX.sh;
66 | fi
67 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
68 | cd /home/travis/build/grahamrow/Muview2;
69 | bash deploy/deployLinux_travis.sh;
70 | fi
71 | - echo "Files in deploy/articfacts"
72 | - ls deploy/artifacts
73 | deploy:
74 | provider: releases
75 | draft: true
76 | api_key:
77 | secure: d2MC+YJVRE4Fk2vgIEB+6i6b7w304DMoHMA/ILIATfQPJXYBUslAT5jgEYrPX/2kFG2swKx20gmQobhwvuV1qbKkGCjWxwh/DDZGtDaHE23Lc9buOV6T8j81+/dbKXBDMd++8WuK7inxjbiIU33K3XlZQ8rWhoVGwmUi7iRNySwM+3ehUyELvDFUl0ry6J1VgTYMEipPWQyXDun5kn2pChm0HLrwR3bqywigAsVzpZRedVhKSDbuaXvi1DXB5ASXLEA8qgSjmso+ZywqSNlJx3sd8QPMBm+pi77ViFk0dqMEcm+AhU6fUyFNnxXgcIwt6+3j2D8mys6GY2l72KnkqIVqfJMpuQxAwtvkOZrSL/NwMSZAauzz3E93AcOmSRaafrLlMdkhvOCGJ6hq7YmeE4YZF7AfYZ9WRUiYWCt8O2HX1ls0LLBYvrWnZqKNdcksWLSY83Sf21R6J7STJje/s7IC5d76GTq4E+3HrvVIphk5akPL6N5Ke4cuaTK333DxdCU/taQW7jM13hhnFy1byY3Vu48UVSbFuU+zsl9TBiHoYcjY5kwOGs41Bu5hKjXlPYw36EKpXqMdl4J3vWHHx9aRY5z5rMOsEe87gPAkCjpt3vGx2VkBJ0aiIZ1Bs6mYHwSSAlkaWINQ6cC/Fn6Uc6GL47VvA0jFwrX9+okoe/Y=
78 | file_glob: true
79 | file: deploy/artifacts/*
80 | skip_cleanup: true
81 | on:
82 | repo: grahamrow/Muview2
83 | tags: true
84 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
--------------------------------------------------------------------------------
/Muview.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/Muview.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Muview2
2 | [](https://travis-ci.org/grahamrow/Muview2) [](https://ci.appveyor.com/project/grahamrow/muview2)
3 |
4 | MuView2 is an OVF (version 1 and 2) compatible viewer intended to function with Mumax and OOMMF. The viewer provides a fast QT/OpenGL interface that enables users to scrub through loaded files with an animation timeline, eliminating the need for manually generating image sequences and rendering animations using several third party software packages.
5 |
6 | ### New Features
7 | - Moved to instanced drawing scheme for drastically increased performance.
8 | - Offload glyph orientation/coloring computation on GLSL shaders for huge performance gains.
9 | - Updated to build with Qt 5.12.3.
10 |
11 | ### Current Features
12 | - Interactive 3D view of vector and scalar inputs (of arbitrary type)
13 | - Slicing for viewing cross-sections of the geometry
14 | - Easy scrubbing (with automatic caching) through loaded files
15 | - Watch folders such that Muview displays new files when they are created
16 | - Save image sequences directly from the loaded set of files
17 |
18 | Files may be loaded from command line using standard globbing
19 | ```
20 | muview SpinTorqueOscillator.out/m*.ovf
21 | muview OOMMF-Data/Oxs*.omf
22 | ```
23 | Otherwise, groups of files or entire directories can be loaded from the GUI.
24 |
25 | ### Installation
26 | All builds are available for Linux, macOS, and Window at the [releases](https://github.com/grahamrow/Muview2/releases) page.
27 |
28 | **Linux**
29 | An [AppImage](https://appimage.org/) bundle is now available for Linux, which is recommended for all Linux users given it's portability and distribution agnosticism. This may be executed directly, possibly requiring the execution flag is set with`chmod +x Muview2-x86_64.AppImage`. Otherwise a self-contained `Muview.tar.gz` bundle is available with all of the necessary Qt libraries included.
30 |
31 | **Windows**
32 | The self-contained Windows distribution `Muview.7z` required 7zip for expansion. The required MSVC redistributable is bundled in the same archive as `vcredist_x64.exe`.
33 |
34 | **macOS**
35 | Just mount `Muview.dmg` image and drag Muview to the applications folder. Qt libraries are embedded in the .app bundle.
36 |
--------------------------------------------------------------------------------
/deploy/MakefileInstall:
--------------------------------------------------------------------------------
1 | MAKEFILE = Makefile
2 | CURRENT_DIR = $(shell pwd)
3 | INSTALL_FILE = install -m 644 -p
4 | INSTALL_DIR = $(COPY_DIR)
5 | INSTALL_PROGRAM = install -m 755 -p
6 | LINK_PROGRAM = ln -sf
7 | STRIP = strip
8 | TARGET = muview
9 | DEL_FILE = rm
10 | # INSTALL ROOT may be set to the desired prefix
11 |
12 | install_target:
13 | @test -d $(INSTALL_ROOT)/usr/local/bin || mkdir -p $(INSTALL_ROOT)/usr/local/bin
14 | -$(LINK_PROGRAM) $(CURRENT_DIR)/$(TARGET) $(INSTALL_ROOT)/usr/local/bin/$(TARGET)
15 |
16 | uninstall_target:
17 | -$(DEL_FILE) "$(INSTALL_ROOT)/usr/local/bin/$(TARGET)"
18 |
19 | install_desktopfile:
20 | @test -d $(INSTALL_ROOT)/usr/share/applications || mkdir -p $(INSTALL_ROOT)/usr/share/applications
21 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/muview.desktop $(INSTALL_ROOT)/usr/share/applications/
22 |
23 | uninstall_desktopfile:
24 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/applications/muview.desktop
25 |
26 |
27 | install_iconfile512:
28 | @test -d $(INSTALL_ROOT)/usr/share/icons/hicolor/512x512/apps || mkdir -p $(INSTALL_ROOT)/usr/share/icons/hicolor/512x512/apps
29 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/512x512/muview.png $(INSTALL_ROOT)/usr/share/icons/hicolor/512x512/apps/
30 |
31 | uninstall_iconfile512:
32 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/512x512/apps/muview.png
33 |
34 | install_iconfile256:
35 | @test -d $(INSTALL_ROOT)/usr/share/icons/hicolor/256x256/apps || mkdir -p $(INSTALL_ROOT)/usr/share/icons/hicolor/256x256/apps
36 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/256x256/muview.png $(INSTALL_ROOT)/usr/share/icons/hicolor/256x256/apps/
37 |
38 | uninstall_iconfile256:
39 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/256x256/apps/muview.png
40 |
41 | install_iconfile128:
42 | @test -d $(INSTALL_ROOT)/usr/share/icons/hicolor/128x128/apps || mkdir -p $(INSTALL_ROOT)/usr/share/icons/hicolor/128x128/apps
43 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/128x128/muview.png $(INSTALL_ROOT)/usr/share/icons/hicolor/128x128/apps/
44 |
45 | uninstall_iconfile128:
46 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/128x128/apps/muview.png
47 |
48 | install_iconfile64:
49 | @test -d $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps || mkdir -p $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps
50 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/64x64/muview.png $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/
51 |
52 | uninstall_iconfile64:
53 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/muview.png
54 |
55 | install_iconfile32:
56 | @test -d $(INSTALL_ROOT)/usr/share/icons/hicolor/32x32/apps || mkdir -p $(INSTALL_ROOT)/usr/share/icons/hicolor/32x32/apps
57 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/32x32/muview.png $(INSTALL_ROOT)/usr/share/icons/hicolor/32x32/apps/
58 |
59 | uninstall_iconfile32:
60 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/32x32/apps/muview.png
61 |
62 | install_iconfile16:
63 | @test -d $(INSTALL_ROOT)/usr/share/icons/hicolor/16x16/apps || mkdir -p $(INSTALL_ROOT)/usr/share/icons/hicolor/16x16/apps
64 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/16x16/muview.png $(INSTALL_ROOT)/usr/share/icons/hicolor/16x16/apps/
65 |
66 | uninstall_iconfile16:
67 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/16x16/apps/muview.png
68 |
69 | install_pixmap:
70 | @test -d $(INSTALL_ROOT)/usr/share/pixmaps || mkdir -p $(INSTALL_ROOT)/usr/share/pixmaps
71 | -$(INSTALL_FILE) $(CURRENT_DIR)/resources/256x256/muview.png $(INSTALL_ROOT)/usr/share/pixmaps/
72 |
73 | uninstall_pixmap:
74 | -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/pixmaps/muview.png
75 |
76 | install: install_desktopfile install_iconfile512 install_iconfile256 install_iconfile128 install_iconfile64 install_iconfile32 install_iconfile16 install_target install_pixmap
77 |
78 | uninstall: uninstall_desktopfile uninstall_iconfile512 uninstall_iconfile256 uninstall_iconfile128 uninstall_iconfile64 uninstall_iconfile32 uninstall_iconfile16 uninstall_target uninstall_pixmap
79 |
--------------------------------------------------------------------------------
/deploy/appveyor.yml:
--------------------------------------------------------------------------------
1 | #---------------------------------#
2 | # general configuration #
3 | #---------------------------------#
4 |
5 | version: 1.0.{build}
6 |
7 | # Maximum number of concurrent jobs for the project
8 | max_jobs: 1
9 |
10 | #---------------------------------#
11 | # environment configuration #
12 | #---------------------------------#
13 |
14 | # Build worker image (VM template)
15 | image: Visual Studio 2017
16 |
17 | environment:
18 | QT5: C:\Qt\5.12.2\msvc2017_64
19 |
20 | # scripts that are called at very beginning, before repo cloning
21 | init:
22 | - git config --global core.autocrlf input
23 | - set PATH=%QT5%\bin;%PATH%
24 | - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
25 |
26 | # clone directory
27 | clone_folder: C:\dev\Muview2
28 |
29 | #---------------------------------#
30 | # build configuration #
31 | #---------------------------------#
32 |
33 | # build platform, i.e. x86, x64, Any CPU. This setting is optional.
34 | platform: x64
35 |
36 | # scripts to run before build
37 | before_build:
38 | - cd C:\dev\Muview2
39 | - mkdir Muview
40 |
41 | # to run your custom scripts instead of automatic MSBuild
42 | build_script:
43 | - qmake.exe -r -config release
44 | - nmake.exe
45 | - move source\muview.exe Muview\Muview.exe
46 | - windeployqt.exe Muview\Muview.exe
47 |
48 | # scripts to run after build
49 | after_build:
50 | - 7z a Muview.7z Muview
51 |
52 | #---------------------------------#
53 | # artifacts configuration #
54 | #---------------------------------#
55 |
56 | artifacts:
57 | - path: 'Muview.7z'
58 |
59 | #---------------------------------#
60 | # deployment configuration #
61 | #---------------------------------#
62 |
63 | deploy:
64 | provider: GitHub
65 | auth_token:
66 | secure: yPVqUihO3aoFTJhmY1TN30sWL6XIFXuAx22BGxMViPRBnsgV1MMLXxdTizwNwb4g
67 | artifact: Muview.7z
68 | draft: true
69 | prerelease: false
70 | on:
71 | appveyor_repo_tag: true # deploy on tag push only
72 |
--------------------------------------------------------------------------------
/deploy/background-dmg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/deploy/background-dmg.png
--------------------------------------------------------------------------------
/deploy/deployLinux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Make sure libxkbcommon-dev, libxcb-dev, libgtk-dev are installed
4 | # Static build of Qt5.2.1 done with the following commands
5 | # ./configure -release -opensource -static -opengl desktop -fontconfig -qt-xkbcommon -qt-xcb -qt-libjpeg -qt-libpng
6 | # make -j10 sub-src
7 |
8 | # Static compilation of Qt5.4.0 source distribution
9 | # cd into qtbase subdir
10 | # ./configure -release -opensource -static -opengl desktop -fontconfig -no-dbus \
11 | # -qt-xkbcommon -qt-xcb -qt-libjpeg -qt-libpng -nomake examples -nomake tests
12 | # make -j10 sub-src
13 |
14 | VERSION="2.2"
15 | NAME="Muview${VERSION}-Linux"
16 | # buildDir="../build-muview-Desktop-Release"
17 |
18 | if [ -e muview ]
19 | then
20 | rm muview
21 | fi
22 | if [ -e "${NAME}.tar.gz" ]
23 | then
24 | rm "${NAME}.tar.gz"
25 | fi
26 | # Kill old product
27 | if [ -d $NAME ]
28 | then
29 | echo "Removing $applicationName"
30 | rm -r $NAME
31 | fi
32 |
33 | cd source
34 | make clean
35 | rm Makefile
36 | qmake -r -spec linux-g++ -config release
37 | cd ..
38 | make clean
39 | rm Makefile
40 | qmake -r -spec linux-g++ -config release
41 | make -j20
42 |
43 | FILES="muview README.md LICENSE"
44 |
45 | mkdir $NAME
46 | # Copy the install-only makefile to deploy directory
47 | cp deploy/MakefileInstall $NAME/Makefile
48 | # Copy the necessary resources, delete extraneous ones
49 | cp -R source/resources $NAME
50 | rm $NAME/resources/muview.icns $NAME/resources/splash*.png
51 | # Copy the rest of the files
52 | cp $FILES $NAME
53 |
54 | tar -czvf "${NAME}.tar.gz" $NAME
55 | echo "Done deploying!"
56 |
--------------------------------------------------------------------------------
/deploy/deployLinux_travis.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | NAME="Muview"
4 |
5 | # Fix version numbers
6 | if [ "$TRAVIS" == true ]
7 | then
8 | echo "Updating version numbers"
9 | for name in source/aboutdialog.ui source/source.pro source/window.cpp
10 | do
11 | sed "s|2.2|${TRAVIS_BRANCH}|" $name > $name.temp
12 | mv $name.temp $name
13 | done
14 | fi
15 |
16 | qmake -r -spec linux-g++ -config release
17 | make -j4
18 |
19 | FILES="muview README.md LICENSE"
20 |
21 | mkdir $NAME
22 | mkdir deploy/artifacts
23 | # Copy the install-only makefile to deploy directory
24 | cp deploy/MakefileInstall Muview/Makefile
25 | # Copy the necessary resources, delete extraneous ones
26 | cp -R source/resources $NAME
27 | rm $NAME/resources/muview.icns $NAME/resources/splash*.png
28 | # Copy the rest of the files
29 | cp $FILES $NAME
30 |
31 | # Package using linuxdeployqt
32 | # echo "Creating AppImage bundle at $PWD/Muview.AppImage"
33 | echo "using qmake from $(which qmake)"
34 | echo "using linuxdeployqt from $(which linuxdeployqt)"
35 |
36 | cd $NAME
37 | linuxdeployqt muview -bundle-non-qt-libs -verbose=1
38 | linuxdeployqt resources/muview.desktop -appimage -verbose=1
39 | mv Muview_Viewer*x86_64.AppImage ../deploy/artifacts/Muview2-x86_64.AppImage
40 | rm AppRun
41 | cd ..
42 |
43 | tar -czvf "Muview.tar.gz" $NAME
44 | mv Muview.tar.gz deploy/artifacts
45 | echo "Done deploying on Linux!"
46 |
--------------------------------------------------------------------------------
/deploy/deployMacOSX.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | buildDir='./'
4 | applicationName="Muview.app"
5 | finalDMGName="Muview.dmg"
6 | title="Muview"
7 |
8 | # Kill old product
9 | if [ -d $applicationName ]
10 | then
11 | echo "Removing $applicationName"
12 | rm -r $applicationName
13 | fi
14 | if [ -d $buildDir/$applicationName ]
15 | then
16 | echo "Removing $buildDir/$applicationName"
17 | rm -r $buildDir/$applicationName
18 | fi
19 |
20 | # Fix version numbers
21 | if [ "$TRAVIS" == true ]
22 | then
23 | echo "Updating version numbers"
24 | for name in source/aboutdialog.ui source/source.pro source/window.cpp
25 | do
26 | sed "s|2.2|${TRAVIS_BRANCH}|" $name > $name.temp
27 | mv $name.temp $name
28 | done
29 | fi
30 |
31 | # qmake version
32 | qmake_vers=$(qmake -v | tail -n1 | sed -n 's|.*\(/usr/.*\)/lib|\1|p')
33 |
34 | # This produces Muview
35 | cd source
36 | qmake -config release
37 | make clean
38 | cd ..
39 | qmake -config release
40 | make clean
41 | make -j4
42 |
43 | echo "Creating Bundle at $PWD/Muview.app"
44 | echo "using qmake from $(which qmake)"
45 | echo "using macdeployqt from $(which macdeployqt)"
46 |
47 | # Macdeployqt has known problems for brewed qt
48 | macdeployqt $buildDir/$applicationName -verbose=1 -always-overwrite
49 | curl -o fix_temp.py https://raw.githubusercontent.com/aurelien-rainone/macdeployqtfix/master/macdeployqtfix.py
50 | sed "s/deps = \[s.strip/deps = \[s.decode\(\).strip/" fix_temp.py > fix.py
51 | python fix.py Muview.app/Contents/MacOS/Muview $qmake_vers
52 | rm fix_temp.py fix.py
53 |
54 | if [ -e tmp.dmg ]
55 | then
56 | rm tmp.dmg
57 | fi
58 |
59 | if [ -e $finalDMGName ]
60 | then
61 | rm $finalDMGName
62 | fi
63 |
64 | echo "Creating Staging Directory"
65 | rm -rf staging
66 | mkdir -p staging/.background
67 | cp deploy/background-dmg.png staging/.background
68 | cp Muview.DS_Store staging/.DS_Store
69 | cp -R $applicationName staging
70 |
71 | echo "Creating DMG"
72 | hdiutil makehybrid -hfs -hfs-volume-name $title -hfs-openfolder staging staging -o tmp.dmg
73 | hdiutil convert -format UDZO tmp.dmg -o $finalDMGName
74 | mkdir deploy/artifacts
75 | mv $finalDMGName deploy/artifacts
76 |
--------------------------------------------------------------------------------
/deploy/deployWin32.bat:
--------------------------------------------------------------------------------
1 | set PATH=C:\Qt\5.7\msvc2015_64\bin;%PATH%
2 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
3 |
4 | qmake.exe -r -config release
5 | nmake.exe
6 | mkdir Muview
7 | move source\muview.exe Muview\Muview.exe
8 | windeployqt.exe Muview\Muview.exe
9 | 7z a Muview.7z Muview
10 | rmdir Muview
11 |
--------------------------------------------------------------------------------
/deploy/deployWindows.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Do this through a MINGW terminal to preserve sanity...
3 | # Compile in QtCreator first...
4 |
5 | VERSION="2.2"
6 | NAME="Muview${VERSION}"
7 | TARGET="muview.exe"
8 | MANIFEST="muview.exe.embed.manifest"
9 | BUILD_DIR="../build-muview-Desktop_Qt_5_3_0_MSVC2013_OpenGL_64bit-Release/source"
10 | SOURCE_DIR="/C/Qt/Qt5.3.0/5.3/msvc2013_64_opengl/bin"
11 | QTDLLS="Qt5Core Qt5Gui Qt5Widgets Qt5OpenGL icuin52 icuuc52 icudt52"
12 | # WINDLL_DIR="/C/Windows/System32"
13 | # WINDLLS="msvcp110 msvcr110"
14 | PLATFORMDLLS="qwindows qminimal"
15 | PLUGIN_DIR="C:\Qt\Qt5.3.0\5.3\msvc2013_64_opengl\plugins"
16 | FILES="README.md LICENSE"
17 |
18 | # Kill old product
19 | if [ -d $NAME ]
20 | then
21 | echo "Removing $NAME"
22 | rm -r $NAME
23 | fi
24 |
25 | mkdir -p $NAME/platforms
26 |
27 | for DLL in $QTDLLS
28 | do
29 | echo "Copying ${DLL}.dll"
30 | cp "${SOURCE_DIR}/${DLL}.dll" ${NAME}
31 | done
32 |
33 | # for DLL in $WINDLLS
34 | # do
35 | # echo "Copying ${DLL}.dll"
36 | # cp "${WINDLL_DIR}/${DLL}.dll" ${NAME}
37 | # done
38 |
39 | for DLL in $PLATFORMDLLS
40 | do
41 | echo "Copying ${DLL}.dll"
42 | cp "${PLUGIN_DIR}/platforms/${DLL}.dll" ${NAME}/platforms
43 | done
44 |
45 | cp "${BUILD_DIR}/${TARGET}" "${BUILD_DIR}/${MANIFEST}" $NAME
46 | echo "Done deploying!"
47 |
--------------------------------------------------------------------------------
/example.omf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/example.omf
--------------------------------------------------------------------------------
/muview.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = subdirs
2 | SUBDIRS = source
3 |
--------------------------------------------------------------------------------
/pretty_dmg.applescript:
--------------------------------------------------------------------------------
1 |
2 | tell application "Finder"
3 | tell disk "mnt"
4 | open
5 | set current view of container window to icon view
6 | set toolbar visible of container window to false
7 | set statusbar visible of container window to false
8 | set the bounds of container window to {400, 100, 1071, 632}
9 | set theViewOptions to the icon view options of container window
10 | set arrangement of theViewOptions to not arranged
11 | set icon size of theViewOptions to 350
12 | set background picture of theViewOptions to file ".background:background-dmg.png"
13 | set position of item "Muview.app" of container window to {212, 282}
14 | update without registering applications
15 | delay 5
16 | end tell
17 | end tell
18 |
19 |
--------------------------------------------------------------------------------
/source/OMFEndian.h:
--------------------------------------------------------------------------------
1 | // This part is originally created and released into the public
2 | // domain by Gunnar Selke .
3 |
4 | #ifndef ENDIAN_H
5 | #define ENDIAN_H
6 |
7 | #include
8 | #include
9 |
10 | /** @file
11 | * Miscellanous functions as well as the RESTRICT macro.
12 | */
13 |
14 | /**
15 | * Swaps the endianness (byte order) of a value.
16 | */
17 | template
18 | T swapEndianness(T value)
19 | {
20 | T result;
21 |
22 | char *src = (char*)&value;
23 | char *dst = (char*)&result;
24 |
25 | for (size_t i=0; i
56 | T toBigEndian(T value)
57 | {
58 | if (isBigEndian()) return value;
59 | return swapEndianness(value);
60 | }
61 |
62 | /**
63 | * Converts a value in big-endian byte order to host-byte-order.
64 | */
65 | template
66 | T fromBigEndian(T value)
67 | {
68 | if (isBigEndian()) return value;
69 | return swapEndianness(value);
70 | }
71 |
72 | /**
73 | * Converts a value in little-endian byte order to host-byte-order.
74 | */
75 | template
76 | T fromLittleEndian(T value)
77 | {
78 | if (!isBigEndian()) return value;
79 | return swapEndianness(value);
80 | }
81 |
82 | #endif
83 |
84 |
--------------------------------------------------------------------------------
/source/OMFImport.cpp:
--------------------------------------------------------------------------------
1 | // This part is originally created and released into the public
2 | // domain by Gunnar Selke .
3 | // Converted to Qt libs and custom QVector based matrix class
4 | // by Graham Rowlands
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | #include "matrix.h"
21 | #include "OMFImport.h"
22 | #include "OMFEndian.h"
23 |
24 | QSharedPointer readOMF(QString &path)
25 | {
26 | bool success;
27 | QFile file(path);
28 | OMFReader *reader = new OMFReader(file);
29 | success = reader->read();
30 | if (!success) {
31 | return QSharedPointer();
32 | } else {
33 | return QSharedPointer(reader);
34 | }
35 | return QSharedPointer();
36 | }
37 |
38 | OMFReader::OMFReader(QFile &fileref) :
39 | file(fileref),
40 | Title(""),
41 | meshunit(""),
42 | valueunit(""),
43 | valuemultiplier(0.0),
44 | xmin(0.0), ymin(0.0), zmin(0.0),
45 | xmax(0.0), ymax(0.0), zmax(0.0),
46 | ValueRangeMaxMag(0.0), ValueRangeMinMag(0.0),
47 | meshtype("rectangular"),
48 | xbase(0.0), ybase(0.0), zbase(0.0),
49 | xstepsize(0.0), ystepsize(0.0), zstepsize(0.0),
50 | xnodes(0), ynodes(0), znodes(0)
51 | {
52 |
53 | }
54 |
55 | bool OMFReader::read()
56 | {
57 | bool ok;
58 | QString key, value;
59 |
60 | if (!file.open(QIODevice::ReadOnly))
61 | {
62 | return QSharedPointer();
63 | }
64 | // Read first line
65 | acceptLine();
66 | ok = parseFirstLine(key, value, version);
67 | if (ok && key == "oommf") {
68 | acceptLine();
69 | } else {
70 | qDebug() << "Expected valid 'OOMMF' header at line 1";
71 | return false;
72 | }
73 |
74 | ok = parseCommentLine(key, value);
75 | if (ok && key == "segment count") {
76 | acceptLine();
77 | } else {
78 | qDebug() << "Expected 'Segment count' at line 2";
79 | return false;
80 | }
81 |
82 | ok = parseCommentLine(key, value);
83 | if (ok && key == "begin" && value == "segment") {
84 | parseSegment();
85 | } else {
86 | qDebug() << "Expected begin of segment";
87 | return false;
88 | }
89 |
90 | return true;
91 | }
92 |
93 | bool OMFReader::parseFirstLine(QString &key, QString &value, int &version)
94 | {
95 | if (line=="# OOMMF: OVF 2.0") {
96 | key="oommf";
97 | value="ovf 2.0";
98 | version=2;
99 | return true;
100 | } else if (line=="# OOMMF: rectangular mesh v1.0") {
101 | key="oommf";
102 | value="rectangular mesh v1.0";
103 | version=1;
104 | return true;
105 | } else if (line=="# OOMMF OVF 2.0") {
106 | key="oommf";
107 | value="ovf 2.0";
108 | version=2;
109 | return true;
110 | } else {
111 | return false;
112 | }
113 | return false;
114 | }
115 |
116 | bool OMFReader::parseCommentLine(QString &key, QString &value)
117 | {
118 | if (line.at(0) == '#') {
119 | int sep = line.indexOf(':');
120 | key = line.mid(2,sep-2).toLower().simplified();
121 | value = line.mid(sep+1).toLower().simplified();
122 | return true;
123 | } else {
124 | return false;
125 | }
126 | }
127 |
128 | void OMFReader::acceptLine()
129 | {
130 | bool reallydone = false;
131 | while(!reallydone && !file.atEnd())
132 | {
133 | line = file.readLine();
134 | if( line.endsWith("\n") ) line.truncate( line.length() - 1 );
135 | if (line=="#") {
136 | reallydone=false;
137 | } else if (line=="") {
138 | reallydone=true;
139 | } else if (line.isNull()) {
140 | reallydone=true;
141 | } else {
142 | reallydone=true;
143 | }
144 | }
145 | }
146 |
147 | bool OMFReader::parseSegment()
148 | {
149 | bool ok;
150 | QString key, value;
151 |
152 | ok = parseCommentLine(key, value);
153 | if (!ok || key != "begin" || value != "segment") {
154 | qDebug() << "Parse error. Expected 'Begin Segment'";
155 | return false;
156 | }
157 | acceptLine();
158 |
159 | parseHeader();
160 | ok = parseCommentLine(key, value);
161 | if (!ok || key != "begin") {
162 | qDebug() << "Parse error. Expected 'Begin Data '";
163 | return false;
164 | }
165 | if (value == "data text") {
166 | ok = parseDataAscii();
167 | } else if (value == "data binary 4") {
168 | ok = parseDataBinary4();
169 | } else if (value == "data binary 8") {
170 | ok = parseDataBinary8();
171 | } else {
172 | qDebug() << "Expected either 'Text', 'Binary 4' or 'Binary 8' chunk type";
173 | return false;
174 | }
175 |
176 | if (!ok) {
177 | qDebug() << "Parsing failed. May load anyway!";
178 | return false;
179 | }
180 |
181 | return true;
182 | }
183 |
184 | bool OMFReader::parseHeader()
185 | {
186 | bool ok;
187 | QString key, value;
188 |
189 | ok = parseCommentLine(key, value);
190 | if (!ok || key != "begin" || value != "header") {
191 | qDebug() << "Expected 'Begin Header'";
192 | }
193 | acceptLine();
194 |
195 | bool done = false;
196 | while (!done) {
197 | ok = parseCommentLine(key, value);
198 | if (!ok) {
199 | qDebug() << "Skipped erroneous line in header.";
200 | continue;
201 | }
202 |
203 | if (key == "end" && value == "header") {
204 | done = true;
205 | break;
206 | } else if (key == "title") {
207 | Title = value;
208 | } else if (key == "desc") {
209 | Desc.push_back(value);
210 | } else if (key == "meshunit") {
211 | meshunit = value;
212 | } else if (key == "valueunit") {
213 | valueunit = value;
214 | } else if (key == "valuemultiplier") {
215 | valuemultiplier = value.toDouble();
216 | } else if (key == "xmin") {
217 | xmin = value.toDouble();
218 | } else if (key == "ymin") {
219 | ymin = value.toDouble();
220 | } else if (key == "zmin") {
221 | zmin = value.toDouble();
222 | } else if (key == "xmax") {
223 | xmax = value.toDouble();
224 | } else if (key == "ymax") {
225 | ymax = value.toDouble();
226 | } else if (key == "zmax") {
227 | zmax = value.toDouble();
228 | } else if (key == "valuedim") { // OVF 2.0
229 | valuedim = value.toInt();
230 | } else if (key == "valueunits") { // OVF 2.0
231 | valueunits.push_back(value);
232 | } else if (key == "valuelabels") { // OVF 2.0
233 | valuelabels.push_back(value);
234 | } else if (key == "valuerangeminmag") {
235 | ValueRangeMinMag = value.toDouble();
236 | } else if (key == "valuerangemaxmag") {
237 | ValueRangeMaxMag = value.toDouble();
238 | } else if (key == "meshtype") {
239 | meshtype = value;
240 | } else if (key == "xbase") {
241 | xbase = value.toDouble();
242 | } else if (key == "ybase") {
243 | ybase = value.toDouble();
244 | } else if (key == "zbase") {
245 | zbase = value.toDouble();
246 | } else if (key == "xstepsize") {
247 | xstepsize = value.toDouble();
248 | } else if (key == "ystepsize") {
249 | ystepsize = value.toDouble();
250 | } else if (key == "zstepsize") {
251 | zstepsize = value.toDouble();
252 | } else if (key == "xnodes") {
253 | xnodes = value.toInt();
254 | } else if (key == "ynodes") {
255 | ynodes = value.toInt();
256 | } else if (key == "znodes") {
257 | znodes = value.toInt();
258 | } else {
259 | qDebug() << "OMFReader::parseHeader: Unknown key: " << key << "---" << value;
260 | }
261 | acceptLine();
262 | }
263 |
264 | if (version == 1) {
265 | valuedim = 3;
266 | }
267 |
268 | ok = parseCommentLine( key, value);
269 | if (!ok || key != "end" || value != "header") {
270 | qDebug() << "Expected 'End Header'";
271 | return false;
272 | }
273 | acceptLine();
274 | return true;
275 | }
276 |
277 | bool OMFReader::parseDataAscii()
278 | {
279 | bool ok;
280 | QString key, value;
281 |
282 | ok = parseCommentLine(key, value);
283 | if (!ok || key != "begin" || value != "data text") {
284 | qDebug() << "Expected 'Begin DataText'";
285 | return false;
286 | }
287 | acceptLine();
288 |
289 | // Create field matrix object
290 | field = QSharedPointer(new matrix(xnodes, ynodes, znodes));
291 |
292 | for (int z=0; z> v1;
301 | val = QVector3D(v1,v1,v1);
302 | } else {
303 | ss >> v1 >> v2 >> v3;
304 | val = QVector3D(v1,v2,v3);
305 | }
306 |
307 | if (version==1) {
308 | val = val*valuemultiplier;
309 | }
310 |
311 | field->set(x,y,z,val);
312 |
313 | acceptLine();
314 | }
315 |
316 | return true;
317 | }
318 |
319 | bool OMFReader::parseDataBinary4()
320 | {
321 | Q_ASSERT(sizeof(float) == 4);
322 |
323 | bool ok;
324 | QString key, value;
325 |
326 | // Parse "Begin: Data Binary 4"
327 | ok = parseCommentLine(key, value);
328 | if (!ok || key != "begin" || value != "data binary 4") {
329 | qDebug() << "Expected 'Begin Binary 4'";
330 | return false;
331 | }
332 |
333 | // Create field matrix object
334 | field = QSharedPointer(new matrix(xnodes, ynodes, znodes));
335 | const int num_cells = field->num_elements();
336 |
337 | // Read magic value and field contents from file
338 | double magic;
339 | QByteArray magicArray = file.read(sizeof(float));
340 | QDataStream magicStream(magicArray);
341 | magicStream.setFloatingPointPrecision(QDataStream::SinglePrecision);
342 | if (version==1) {
343 | magicStream.setByteOrder(QDataStream::BigEndian);
344 | magicStream >> magic;
345 | } else if (version==2) {
346 | magicStream.setByteOrder(QDataStream::LittleEndian);
347 | magicStream >> magic;
348 | } else {
349 | qDebug() << "Wrong version number detected.";
350 | return false;
351 | }
352 |
353 | if (magic != 1234567.0) qDebug() << "Wrong magic number (binary 4 format)";
354 |
355 | QByteArray dataArray;
356 | if (valuedim == 1) {
357 | dataArray = file.read(num_cells*sizeof(float));
358 | } else {
359 | dataArray = file.read(3*num_cells*sizeof(float));
360 | }
361 | QDataStream dataStream(dataArray);
362 | dataStream.setFloatingPointPrecision(QDataStream::SinglePrecision);
363 | if (version==1) {
364 | dataStream.setByteOrder(QDataStream::BigEndian);
365 | } else {
366 | dataStream.setByteOrder(QDataStream::LittleEndian);
367 | }
368 |
369 | QVector3D val;
370 | double v1, v2, v3;
371 | for (int i=0; i> v1;
374 | if (version==1) {
375 | v1 = v1 * valuemultiplier;
376 | }
377 | val = QVector3D(v1,v1,v1);
378 | } else {
379 | dataStream >> v1 >> v2 >> v3;
380 | val = QVector3D(v1, v2, v3);
381 | if (version==1) {
382 | val = val * valuemultiplier;
383 | }
384 | }
385 | field->set(i,val);
386 | }
387 | return true;
388 | }
389 |
390 | bool OMFReader::parseDataBinary8()
391 | {
392 | Q_ASSERT(sizeof(double) == 8);
393 |
394 | bool ok;
395 | QString key, value;
396 |
397 | // Parse "Begin: Data Binary 8"
398 | ok = parseCommentLine(key, value);
399 | if (!ok || key != "begin" || value != "data binary 8") {
400 | qDebug() << "Expected 'Begin Binary 8'";
401 | return false;
402 | }
403 |
404 | // Create field matrix object
405 | field = QSharedPointer(new matrix(xnodes, ynodes, znodes));
406 | const int num_cells = field->num_elements();
407 |
408 | // Read magic value and field contents from file
409 | double magic;
410 | QByteArray magicArray = file.read(sizeof(double));
411 | QDataStream magicStream(magicArray);
412 | magicStream.setFloatingPointPrecision(QDataStream::DoublePrecision);
413 | if (version==1) {
414 | magicStream.setByteOrder(QDataStream::BigEndian);
415 | magicStream >> magic;
416 | } else {
417 | magicStream.setByteOrder(QDataStream::LittleEndian);
418 | magicStream >> magic;
419 | }
420 |
421 | if (magic != 123456789012345.0) qDebug() << "Wrong magic number (binary 8 format)";
422 |
423 | QByteArray dataArray;
424 | if (valuedim == 1) {
425 | dataArray = file.read(num_cells*sizeof(double));
426 | } else {
427 | dataArray = file.read(3*num_cells*sizeof(double));
428 | }
429 | QDataStream dataStream(dataArray);
430 | dataStream.setFloatingPointPrecision(QDataStream::DoublePrecision);
431 | if (version==1) {
432 | dataStream.setByteOrder(QDataStream::BigEndian);
433 | } else {
434 | dataStream.setByteOrder(QDataStream::LittleEndian);
435 | }
436 |
437 | QVector3D val;
438 | double v1, v2, v3;
439 | for (int i=0; i> v1;
442 | if (version==1) {
443 | v1 = v1 * valuemultiplier;
444 | }
445 | val = QVector3D(v1,v1,v1);
446 | } else {
447 | dataStream >> v1 >> v2 >> v3;
448 | val = QVector3D(v1, v2, v3);
449 | if (version==1) {
450 | val = val * valuemultiplier;
451 | }
452 | }
453 | field->set(i,val);
454 | }
455 | return true;
456 | }
457 |
458 |
--------------------------------------------------------------------------------
/source/OMFImport.h:
--------------------------------------------------------------------------------
1 | // This part is originally created and released into the public
2 | // domain by Gunnar Selke .
3 | // Modified by Graham Rowlands
4 |
5 | #ifndef OMF_IMPORT_H
6 | #define OMF_IMPORT_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include "matrix.h"
13 |
14 | // Always using QSharedPointers to data arrays
15 | // since they will be automatically deleted when
16 | // going out of scope. This way the cache doesn't
17 | // spiral out of control w.r.t memory usage
18 |
19 | enum OMFFormat
20 | {
21 | OMF_FORMAT_ASCII,
22 | OMF_FORMAT_BINARY_4,
23 | OMF_FORMAT_BINARY_8
24 | };
25 |
26 | class OMFReader : public QObject
27 | {
28 | Q_OBJECT
29 | public:
30 | OMFReader(QFile &fileref);
31 | bool read();
32 | QSharedPointer field;
33 |
34 | // Header related
35 | QString Title;
36 | QStringList Desc;
37 | QStringList valueunits; // OVF 2.0
38 | QStringList valuelabels; // OVF 2.0
39 | QString meshunit; // e.g. "m"
40 | QString valueunit; // e.g. "A/m"
41 | double valuemultiplier;
42 | double xmin, ymin, zmin;
43 | double xmax, ymax, zmax;
44 | double ValueRangeMaxMag, ValueRangeMinMag;
45 | QString meshtype; // "rectangular"
46 | double xbase, ybase, zbase;
47 | double xstepsize, ystepsize, zstepsize;
48 | int xnodes, ynodes, znodes;
49 | int valuedim; // OVF 2.0 only
50 | int version;
51 |
52 | private:
53 | // Parsing related
54 | bool parse();
55 | bool parseFirstLine(QString &key, QString &value, int &version);
56 | bool parseSegment();
57 | bool parseHeader();
58 | bool parseCommentLine(QString &key, QString &value);
59 | bool parseDataAscii();
60 | bool parseDataBinary4();
61 | bool parseDataBinary8();
62 | void acceptLine();
63 |
64 | // OMFHeader header;
65 | QTextStream in;
66 | QString line;
67 | QString filename;
68 | QFile &file;
69 | int lineno;
70 | };
71 |
72 | QSharedPointer readOMF(QString &path);
73 |
74 | #endif
75 |
76 |
--------------------------------------------------------------------------------
/source/aboutdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "aboutdialog.h"
2 | #include "ui_aboutdialog.h"
3 |
4 | AboutDialog::AboutDialog(QWidget *parent) :
5 | QDialog(parent),
6 | ui(new Ui::AboutDialog)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | AboutDialog::~AboutDialog()
12 | {
13 | delete ui;
14 | }
15 |
--------------------------------------------------------------------------------
/source/aboutdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef ABOUTDIALOG_H
2 | #define ABOUTDIALOG_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class AboutDialog;
8 | }
9 |
10 | class AboutDialog : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit AboutDialog(QWidget *parent = 0);
16 | ~AboutDialog();
17 |
18 | private:
19 | Ui::AboutDialog *ui;
20 | };
21 |
22 | #endif // ABOUTDIALOG_H
23 |
--------------------------------------------------------------------------------
/source/aboutdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | AboutDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 500
10 | 280
11 |
12 |
13 |
14 | UpArrowCursor
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | 320
23 | 250
24 | 176
25 | 27
26 |
27 |
28 |
29 | Qt::Horizontal
30 |
31 |
32 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok
33 |
34 |
35 |
36 |
37 |
38 | 140
39 | 10
40 | 351
41 | 91
42 |
43 |
44 |
45 | <html><head/><body><p align="right"><a href="http://grahamrow.github.io/Muview2"><span style=" text-decoration: underline; color:#0c3d5e;">Muview2</span></a><span style=" color:#ffffff;"> is written in C++ using OpenGL and Qt 5<br/>Graham Rowlands<br/></span><span style=" font-style:italic; color:#ffffff;">Version 2.2 - May 2019</span></p><p align="right"><span style=" color:#ffffff;"><br/></span></p></body></html>
46 |
47 |
48 | true
49 |
50 |
51 | true
52 |
53 |
54 |
55 |
56 |
57 | 0
58 | 0
59 | 500
60 | 280
61 |
62 |
63 |
64 |
65 |
66 |
67 | :/resources/splash.png
68 |
69 |
70 | label_2
71 | buttonBox
72 | label
73 |
74 |
75 |
76 |
77 |
78 |
79 | buttonBox
80 | accepted()
81 | AboutDialog
82 | accept()
83 |
84 |
85 | 248
86 | 254
87 |
88 |
89 | 157
90 | 274
91 |
92 |
93 |
94 |
95 | buttonBox
96 | rejected()
97 | AboutDialog
98 | reject()
99 |
100 |
101 | 316
102 | 260
103 |
104 |
105 | 286
106 | 274
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/source/glwidget.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "glwidget.h"
6 |
7 | GLWidget::GLWidget( const QGLFormat& glformat, QWidget* parent )
8 | : QGLWidget( glformat, parent )
9 | {
10 | // Defaults
11 | displayOn = false;
12 | toggleDisplay(0); // Start with cubes
13 | brightness = 1.0;
14 | xRot = yRot = zRot = 0;
15 | xLoc = yLoc = 0;
16 | zoom = -300.0;
17 | slices = 16;
18 | subsampling = 0;
19 | vectorLength = 1.0f;
20 | vectorRadius = 0.5f;
21 | vectorTipLengthRatio = 0.4f;
22 | vectorShaftRadiusRatio = 0.4f;
23 |
24 | // Slicing and Thresholding
25 | xSliceLow=ySliceLow=zSliceLow=thresholdLow=0;
26 | xSliceHigh=ySliceHigh=zSliceHigh=thresholdHigh=16*100;
27 |
28 | // Map from display type to int
29 |
30 | display_type_map["Full Orientation"] = 1;
31 | display_type_map["In-Plane Angle"] = 2;
32 | display_type_map["X Coordinate"] = 3;
33 | display_type_map["Y Coordinate"] = 4;
34 | display_type_map["Z Coordinate"] = 5;
35 |
36 | // Load shader programs, lights, models, etc.
37 | context()->makeCurrent();
38 |
39 | // Draw at a fixed framerate (if updates are needed)
40 | QTimer *timer = new QTimer(this);
41 | connect(timer, SIGNAL(timeout()), this, SLOT(update()));
42 | timer->start(16);
43 | }
44 |
45 | QColor GLWidget::customSpriteColor(float value) {
46 | // Number of colors in the list
47 | int numColors = customColors.length();
48 |
49 | // Part of the mapping that value takes given this number of colors
50 | float interval = 1.0f / (static_cast(numColors) - 1.0f);
51 |
52 | // Find which colors in the list we're in between
53 | int firstColorIndex = static_cast(0.999f*value/interval);
54 | if (firstColorIndex > (numColors-2)) {
55 | firstColorIndex = numColors-2;
56 | }
57 | QColor firstColor = customColors.at(firstColorIndex);
58 | QColor secondColor = customColors.at(firstColorIndex + 1);
59 |
60 | // Rescale the value to within 0:1
61 | value = (value - firstColorIndex*interval)/interval;
62 |
63 | // Linear interpolation between the chosen colors
64 | qreal r = firstColor.redF() + value * (secondColor.redF() - firstColor.redF());
65 | qreal g = firstColor.greenF() + value * (secondColor.greenF() - firstColor.greenF());
66 | qreal b = firstColor.blueF() + value * (secondColor.blueF() - firstColor.blueF());
67 |
68 | return QColor::fromRgbF(r,g,b);
69 |
70 | }
71 |
72 | void GLWidget::setCustomColorScale(QList colors)
73 | {
74 | // Set the private color variables to the inputs
75 | customColors = colors;
76 | }
77 |
78 | void GLWidget::updateData(QSharedPointer data)
79 | {
80 | if (data.isNull()) {
81 | displayOn = false;
82 | } else {
83 | valuedim = data->valuedim;
84 | // Nothing set for the extents...
85 | if (valuedim == 3) {
86 | data->field->minmaxMagnitude(minmag, maxmag);
87 | } else if (valuedim == 1) {
88 | data->field->minmaxScalar(minmag, maxmag);
89 | }
90 | dataPtr = data;
91 | displayOn = true;
92 | // Update the display
93 | updateCOM();
94 | updateExtent();
95 | needsUpdate = true;
96 |
97 | pushBuffers();
98 | }
99 | }
100 |
101 | void GLWidget::pushLUT() {
102 | if (colorScale != "HSL") {
103 | QVector4D lut[256];
104 | for (int i=0; i<256; i++) {
105 | float h = ((float)i)/255.0;
106 | if (colorScale == ("Grayscale")) {
107 | spriteColor = QColor::fromHslF(0.0, 0.0, h);
108 | } else if (colorScale == ("Blue to Red")) {
109 | if (h <= 0.5) {
110 | spriteColor = QColor::fromHsvF(0.0,1.0-2.0*h,1.0);
111 | } else {
112 | spriteColor = QColor::fromHsvF(0.5,(h-0.5)*2.0,1.0);
113 | }
114 | } else if (colorScale == ("Green to White")) {
115 | spriteColor = QColor::fromHsvF(0.3,1.0-h,0.25+0.75*h);
116 |
117 | } else if (colorScale == ("Custom")) {
118 | spriteColor = customSpriteColor(h);
119 | }
120 |
121 | lut[i] = QVector4D(spriteColor.redF(), spriteColor.greenF(), spriteColor.blueF(), 0.0);
122 | }
123 | currentShader->setUniformValueArray("color_lut", lut, 256);
124 | }
125 | }
126 |
127 | void GLWidget::pushBuffers()
128 | {
129 | if (displayOn) {
130 | QVector size = dataPtr->field->shape();
131 | // int numNodes = dataPtr->field->num_elements();
132 | int incr_x = ((1 << subsampling) > size[0]) ? size[0] : (1 << subsampling);
133 | int incr_y = ((1 << subsampling) > size[1]) ? size[1] : (1 << subsampling);
134 | int incr_z = ((1 << subsampling) > size[2]) ? size[2] : (1 << subsampling);
135 |
136 | // numNodes = size[0]/incr_x;
137 | // numNodes *= size[1]/incr_y;
138 | // numNodes *= size[2]/incr_z;
139 | numNodes = 0;
140 |
141 | // Push new data
142 | for(int i=0; ifield->at(i,j,k), 0.0);
147 | numNodes++;
148 | }
149 | }
150 | }
151 |
152 | if ( numNodes <= 1) {
153 | subsampling --;
154 | }
155 |
156 | currentShader->bind();
157 | displayObject->vao->bind();
158 |
159 | // Buffers for coordinates and colors
160 | displayObject->pos_vbo.bind();
161 | displayObject->pos_vbo.allocate( numNodes * sizeof(QVector4D) );
162 | displayObject->pos_vbo.write(0, instPositions.constData(), numNodes * sizeof(QVector4D));
163 |
164 | displayObject->mag_vbo.bind();
165 | displayObject->mag_vbo.allocate( numNodes * sizeof(QVector4D) );
166 | displayObject->mag_vbo.write(0, instMagnetizations.constData(), numNodes * sizeof(QVector4D));
167 |
168 | // Release buffers
169 | displayObject->pos_vbo.release();
170 | displayObject->mag_vbo.release();
171 | displayObject->vao->release();
172 |
173 | // Clear Qt containers
174 | instPositions.clear();
175 | instMagnetizations.clear();
176 | }
177 | }
178 |
179 | void GLWidget::updateExtent()
180 | {
181 | QVector size = dataPtr->field->shape();
182 | xmax = size[0];
183 | ymax = size[1];
184 | zmax = size[2];
185 | xmin = 0.0;
186 | ymin = 0.0;
187 | zmin = 0.0;
188 | }
189 |
190 | void GLWidget::update() {
191 | if (needsUpdate) {
192 | pushBuffers();
193 | updateGL();
194 | needsUpdate = false;
195 | emit doneRenderingFrame(filename);
196 | }
197 | }
198 |
199 | void GLWidget::renderFrame(QString file)
200 | {
201 | filename = file;
202 | needsUpdate = true;
203 | update();
204 | }
205 |
206 | void GLWidget::initializeGL()
207 | {
208 | qDebug() << "Widget OpenGl: " << format().majorVersion() << "." << format().minorVersion();
209 | qDebug() << "Context valid: " << context()->isValid();
210 | qDebug() << "Really used OpenGl: " << context()->format().majorVersion() << "." << context()->format().minorVersion();
211 | qDebug() << "OpenGl information: VENDOR: " << (const char*)glGetString(GL_VENDOR);
212 | qDebug() << " RENDERDER: " << (const char*)glGetString(GL_RENDERER);
213 | qDebug() << " VERSION: " << (const char*)glGetString(GL_VERSION);
214 | qDebug() << " GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
215 |
216 | // gl330Funcs = 0;
217 | // gl330Funcs = context()->versionFunctions();
218 | gl330Funcs = new QOpenGLFunctions_3_3_Core;
219 | if (gl330Funcs)
220 | gl330Funcs->initializeOpenGLFunctions();
221 | else
222 | {
223 | qWarning() << "Could not obtain required OpenGL context version";
224 | exit(1);
225 | }
226 |
227 | initializeAssets();
228 |
229 | QGLFormat glFormat = QGLWidget::format();
230 | if ( !glFormat.sampleBuffers() )
231 | qWarning() << "Could not enable sample buffers";
232 |
233 | // Set the clear color to black
234 | backgroundColor = QColor::fromRgbF(0.9, 0.8, 1.0).dark();
235 | qglClearColor( backgroundColor );
236 |
237 | glEnable( GL_MULTISAMPLE );
238 | glEnable( GL_DEPTH_TEST );
239 | glEnable( GL_CULL_FACE );
240 | glEnable( GL_SMOOTH );
241 | glDepthFunc( GL_LEQUAL );
242 | }
243 |
244 | void GLWidget::resizeGL( int w, int h )
245 | {
246 | // Set the viewport to window dimensions
247 | glViewport( 0, 0, w, qMax( h, 1 ) );
248 | qreal aspect = qreal(w) / qreal(h ? h : 1);
249 | projection.setToIdentity();
250 | projection.perspective(45.0f,aspect,0.1f,10000.0f);
251 |
252 | needsUpdate = true;
253 | }
254 |
255 | void GLWidget::paintGL()
256 | {
257 | // Clear the buffer with the current clearing color
258 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
259 |
260 | if (displayOn) {
261 |
262 | QVector size = dataPtr->field->shape();
263 | // int numNodes = dataPtr->field->num_elements();
264 | sprite *tempSprite;
265 | QOpenGLShaderProgram *tempShader;
266 |
267 | GLfloat thrLo = ((GLfloat)thresholdLow)/1600.0;
268 | GLfloat thrHi = ((GLfloat)thresholdHigh)/1600.0;
269 | GLfloat xSlLo = (xmax-xmin)*(GLfloat)xSliceLow/1600.0;
270 | GLfloat xSlHi = (xmax-xmin)*(GLfloat)xSliceHigh/1600.0;
271 | GLfloat ySlLo = (ymax-ymin)*(GLfloat)ySliceLow/1600.0;
272 | GLfloat ySlHi = (ymax-ymin)*(GLfloat)ySliceHigh/1600.0;
273 | GLfloat zSlLo = (zmax-zmin)*(GLfloat)zSliceLow/1600.0;
274 | GLfloat zSlHi = (zmax-zmin)*(GLfloat)zSliceHigh/1600.0;
275 | GLfloat sc = (GLfloat)(1 << subsampling);
276 | view.setToIdentity();
277 | view.translate(xLoc, yLoc, zoom);
278 | view.rotate(xRot / 1600.0, 1.0, 0.0, 0.0);
279 | view.rotate(yRot / 1600.0, 0.0, 1.0, 0.0);
280 | view.rotate(zRot / 1600.0, 0.0, 0.0, 1.0);
281 |
282 | if (valuedim == 1 ) {
283 | tempSprite = &cube;
284 | tempShader = &cubeShader;
285 | } else {
286 | tempSprite = displayObject;
287 | tempShader = currentShader;
288 | }
289 |
290 | tempShader->bind();
291 | tempShader->setUniformValue("view", view);
292 | tempShader->setUniformValue("projection", projection);
293 | tempShader->setUniformValue("brightness", brightness);
294 | tempShader->setUniformValue("light.position", lightPosition);
295 | tempShader->setUniformValue("light.intensities", lightIntensity);
296 | tempShader->setUniformValue("ambient", lightAmbient);
297 | tempShader->setUniformValue("brightness", brightness);
298 | tempShader->setUniformValue("maxmag", maxmag);
299 | tempShader->setUniformValue("thresholdLow", thrLo);
300 | tempShader->setUniformValue("thresholdHigh", thrHi);
301 | tempShader->setUniformValue("xSliceLow", xSlLo);
302 | tempShader->setUniformValue("xSliceHigh", xSlHi);
303 | tempShader->setUniformValue("ySliceLow", ySlLo);
304 | tempShader->setUniformValue("ySliceHigh", ySlHi);
305 | tempShader->setUniformValue("zSliceLow", zSlLo);
306 | tempShader->setUniformValue("zSliceHigh", zSlHi);
307 | tempShader->setUniformValue("display_type", display_type_map[coloredQuantity]);
308 | tempShader->setUniformValue("use_color_lut", (colorScale != "HSL") ? 1 : 0);
309 | tempShader->setUniformValue("com", QVector3D(xcom, ycom, zcom));
310 | tempShader->setUniformValue("do_rotate", (displayObject == &cube) ? 0 : 1);
311 | tempShader->setUniformValue("valuedim", valuedim);
312 | tempShader->setUniformValue("scale", sc);
313 |
314 | // Vertex Array
315 | tempSprite->vao->bind();
316 |
317 | // Buffers for coordinates and colors
318 | tempSprite->pos_vbo.bind();
319 | tempSprite->mag_vbo.bind();
320 |
321 | // Draw everything in one call
322 | gl330Funcs->glDrawArraysInstanced( GL_TRIANGLES, 0, tempSprite->count, numNodes);
323 |
324 | // Release buffers
325 | tempSprite->pos_vbo.release();
326 | tempSprite->mag_vbo.release();
327 | tempSprite->vao->release();
328 | }
329 | }
330 |
331 | void GLWidget::toggleDisplay(int type)
332 | {
333 | displayType = type;
334 | if (displayType == 0) {
335 | displayObject = &cube;
336 | currentShader = &cubeShader;
337 | } else if (displayType == 1) {
338 | displayObject = &cone;
339 | currentShader = &standardShader;
340 | } else {
341 | displayObject = &vect;
342 | currentShader = &standardShader;
343 | }
344 | needsUpdate = true;
345 | }
346 |
347 | void GLWidget::setBackgroundColor(QColor color) {
348 | backgroundColor = color;
349 | qglClearColor(backgroundColor);
350 | needsUpdate = true;
351 | }
352 |
353 | void GLWidget::setSpriteDimensions(int newslices, float length, float radius, float tipLengthRatio, float shaftRadiusRatio, QString origin)
354 | {
355 | if ( (slices != newslices) || (vectorLength != length) || (vectorRadius != radius) ||
356 | (vectorTipLengthRatio != tipLengthRatio) || (vectorShaftRadiusRatio != shaftRadiusRatio) ||
357 | (vectorOrigin != origin) )
358 | {
359 | slices = newslices;
360 | vectorLength = length;
361 | vectorRadius = radius;
362 | vectorTipLengthRatio = tipLengthRatio;
363 | vectorShaftRadiusRatio = shaftRadiusRatio;
364 | vectorOrigin = origin;
365 | initializeVect(slices, 5.0f*vectorLength, 1.0f*vectorRadius, vectorTipLengthRatio, vectorShaftRadiusRatio);
366 | initializeCone(slices, 1.0*vectorRadius, 2.0*vectorLength);
367 | needsUpdate = true;
368 | }
369 | }
370 |
371 | void GLWidget::setBrightness(float bright)
372 | {
373 | brightness = bright;
374 | needsUpdate = true;
375 | }
376 |
377 | void GLWidget::setColoredQuantity(QString value)
378 | {
379 | coloredQuantity = value;
380 | }
381 |
382 | void GLWidget::setColorScale(QString value)
383 | {
384 | colorScale = value;
385 | pushLUT();
386 | }
387 |
388 | void GLWidget::setSpriteScale(QString value)
389 | {
390 | spriteScale = value;
391 | }
392 |
--------------------------------------------------------------------------------
/source/glwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef GLWIDGET_H
2 | #define GLWIDGET_H
3 | #define PI 3.1415926535897932384626433832795
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "matrix.h"
12 | #include "OMFImport.h"
13 |
14 | struct sprite
15 | {
16 | QOpenGLBuffer vbo;
17 | QOpenGLBuffer pos_vbo;
18 | QOpenGLBuffer mag_vbo;
19 | QOpenGLVertexArrayObject *vao;
20 | GLuint count;
21 | };
22 |
23 | class GLWidget : public QGLWidget
24 | {
25 | Q_OBJECT
26 | public:
27 | GLWidget( const QGLFormat& format, QWidget* parent = 0 );
28 |
29 | // Data and Drawing
30 | void updateData(QSharedPointer data);
31 | // void updateHeader(QSharedPointer header, QSharedPointer data);
32 | void isDoneRendering();
33 | virtual void renderFrame(QString file);
34 |
35 | // View Preferences
36 | virtual void toggleDisplay(int type);
37 | virtual void setBackgroundColor(QColor color);
38 | virtual void setSpriteDimensions(int newslices, float length, float radius, float tipLengthRatio, float shaftRadiusRatio, QString origin);
39 | virtual void setBrightness(float bright);
40 | void setColorScale(QString value);
41 | void setSpriteScale(QString value);
42 | void setColoredQuantity(QString value);
43 | void setCustomColorScale(QList colors);
44 |
45 | public slots:
46 | virtual void update();
47 |
48 | // Movement and slicing
49 | void setXRotation(int angle);
50 | void setYRotation(int angle);
51 | void setZRotation(int angle);
52 | void setXSliceLow(int low);
53 | void setYSliceLow(int low);
54 | void setZSliceLow(int low);
55 | void setThresholdLow(int low);
56 | void setXSliceHigh(int high);
57 | void setYSliceHigh(int high);
58 | void setZSliceHigh(int high);
59 | void setThresholdHigh(int high);
60 | void setXCom(float val);
61 | void setYCom(float val);
62 | void setZCom(float val);
63 | void setXLoc(float val);
64 | void setYLoc(float val);
65 | void setZLoc(float val);
66 |
67 | // Subsampling
68 | void increaseSubsampling();
69 | void decreaseSubsampling();
70 |
71 | signals:
72 | void xRotationChanged(int angle);
73 | void yRotationChanged(int angle);
74 | void zRotationChanged(int angle);
75 | void COMChanged(float val);
76 | void doneRenderingFrame(QString filename);
77 |
78 | protected:
79 | virtual void updateCOM();
80 | virtual void updateExtent();
81 |
82 | virtual void initializeGL();
83 | virtual void resizeGL( int w, int h );
84 | virtual void paintGL();
85 | virtual void pushBuffers();
86 | virtual void pushLUT();
87 |
88 | virtual void keyPressEvent( QKeyEvent* e );
89 | virtual void mousePressEvent(QMouseEvent *e);
90 | virtual void mouseMoveEvent(QMouseEvent *e);
91 | virtual void mouseReleaseEvent(QMouseEvent *e);
92 | virtual void wheelEvent(QWheelEvent *e);
93 |
94 | private:
95 | // Shaders
96 | QOpenGLShaderProgram standardShader, cubeShader;
97 | QOpenGLShaderProgram *currentShader;
98 | QOpenGLFunctions_3_3_Core* gl330Funcs;
99 |
100 | // Init functions
101 | void initializeAssets();
102 | bool initializeShaders();
103 | bool initializeLights();
104 | bool initializeCube();
105 | bool initializeCone(int slices, float radius, float height);
106 | bool initializeVect(int slices, float height, float radius, float fractionTip, float fractionInner);
107 |
108 | QVector instPositions;
109 | QVector instMagnetizations;
110 |
111 | // Sprites and Data
112 | sprite cube, cone, vect;
113 | sprite *displayObject;
114 | int numNodes; // Number of nodes being displayed with current subsampling
115 | int displayType; // Cube 0, Cone 1, Vector 2
116 | int valuedim; // scalar or vector
117 | int subsampling; // display each 2^n'th cell according to this variable
118 | QSharedPointer dataPtr;
119 | float maxmag, minmag;
120 | QColor spriteColor;
121 | int slices; // Resolution for cones/vects
122 | float vectorLength, vectorRadius, vectorTipLengthRatio, vectorShaftRadiusRatio;
123 |
124 | // Lighting
125 | GLfloat lightAmbient;
126 | QVector4D lightIntensity;
127 | QVector4D lightPosition;
128 | float brightness;
129 |
130 | // View Related
131 | QSize mandatedSize;
132 | QColor backgroundColor;
133 | QMatrix4x4 projection, view, model;
134 | bool displayOn;
135 | QVector3D com, location, maxExtent, minExtent;
136 | float xcom, ycom, zcom;
137 | float xmax, ymax, zmax;
138 | float xmin, ymin, zmin;
139 | int xRot, yRot, zRot;
140 | float xLoc, yLoc, zLoc, zoom;
141 | // slice variables
142 | int xSliceLow, xSliceHigh;
143 | int ySliceLow, ySliceHigh;
144 | int zSliceLow, zSliceHigh;
145 | int thresholdLow, thresholdHigh;
146 |
147 | // Coloring
148 | QString colorScale;
149 | QString coloredQuantity;
150 | QString vectorOrigin;
151 | QString spriteScale;
152 | QColor customSpriteColor(float val); // val goes from 0 to 1.0
153 | QList customColors;
154 | QMap display_type_map;
155 |
156 | // Mouse control
157 | QVector2D previousMousePosition;
158 | bool leftMousePressed;
159 | bool middleMousePressed;
160 | bool rightMousePressed;
161 |
162 | // Render control
163 | bool needsUpdate;
164 | QString filename; // for rendering image sequences...
165 |
166 | };
167 |
168 | #endif // GLWIDGET_H
169 |
170 |
--------------------------------------------------------------------------------
/source/glwidget_assets.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "glwidget.h"
4 | #include
5 |
6 | void GLWidget::initializeAssets()
7 | {
8 | // Prepare a complete shader program...
9 | initializeShaders();
10 | initializeCube();
11 | initializeCone(16, 1.0, 2.0);
12 | initializeVect(16, 5.0f*vectorLength, vectorRadius, vectorTipLengthRatio, vectorShaftRadiusRatio);
13 | initializeLights();
14 | }
15 |
16 | bool GLWidget::initializeLights()
17 | {
18 | lightIntensity = QVector4D(1.0,1.0,1.0,1.0);
19 | lightPosition = QVector4D(10,10,150,1.0);
20 | lightAmbient = 0.4f;
21 | return true;
22 | }
23 |
24 | bool GLWidget::initializeShaders()
25 | {
26 | bool result = true;
27 |
28 | result = result && cubeShader.addShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/cube.vert" );
29 | result = result && cubeShader.addShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/cube.frag" );
30 |
31 | result = result && standardShader.addShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/standard.vert" );
32 | result = result && standardShader.addShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/standard.frag" );
33 |
34 | if ( !result ) {
35 | qWarning() << "Shaders could not be loaded (flat)" << cubeShader.log();
36 | qWarning() << "Shaders could not be loaded (diffuse)" << standardShader.log();
37 | }
38 | return result;
39 | }
40 |
41 | bool GLWidget::initializeCube()
42 | {
43 | cube.vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
44 | cube.pos_vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
45 | cube.mag_vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
46 |
47 | cube.vao = new QOpenGLVertexArrayObject(this);
48 | cube.vao->create();
49 | cube.vao->bind();
50 | cube.count = 6*3*2;
51 |
52 | // Generate the coordinates, normals
53 | GLfloat vertexNormData[] = {
54 | // X Y Z Normal
55 | // bottom
56 | -1.0f,-1.0f,-1.0f, 0.0f, -1.0f, 0.0f,
57 | 1.0f,-1.0f,-1.0f, 0.0f, -1.0f, 0.0f,
58 | -1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
59 | 1.0f,-1.0f,-1.0f, 0.0f, -1.0f, 0.0f,
60 | 1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
61 | -1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
62 | // top
63 | -1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f,
64 | -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
65 | 1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f,
66 | 1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f,
67 | -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
68 | 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
69 | // front
70 | -1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
71 | 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
72 | -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
73 | 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
74 | 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
75 | -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
76 | // back
77 | -1.0f,-1.0f,-1.0f, 0.0f, 0.0f, -1.0f,
78 | -1.0f, 1.0f,-1.0f, 0.0f, 0.0f, -1.0f,
79 | 1.0f,-1.0f,-1.0f, 0.0f, 0.0f, -1.0f,
80 | 1.0f,-1.0f,-1.0f, 0.0f, 0.0f, -1.0f,
81 | -1.0f, 1.0f,-1.0f, 0.0f, 0.0f, -1.0f,
82 | 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, -1.0f,
83 | // left
84 | -1.0f,-1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
85 | -1.0f, 1.0f,-1.0f, -1.0f, 0.0f, 0.0f,
86 | -1.0f,-1.0f,-1.0f, -1.0f, 0.0f, 0.0f,
87 | -1.0f,-1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
88 | -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
89 | -1.0f, 1.0f,-1.0f, -1.0f, 0.0f, 0.0f,
90 | // right
91 | 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
92 | 1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f,
93 | 1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f,
94 | 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
95 | 1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f,
96 | 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f
97 | };
98 |
99 | if (cube.vbo.isCreated()) {
100 | cube.vbo.destroy();
101 | cube.pos_vbo.destroy();
102 | cube.mag_vbo.destroy();
103 | }
104 | cube.vbo.create();
105 | cube.pos_vbo.create();
106 | cube.mag_vbo.create();
107 |
108 | // Bind the shader program so that we can associate variables from
109 | // our application to the shaders
110 | if ( !cubeShader.bind() )
111 | {
112 | qWarning() << "Could not bind shader program to context (flat)" << cubeShader.log();
113 | return false;
114 | }
115 |
116 | // Set usage. Vertices are static, positions and orientations are dynamic
117 | cube.vbo.setUsagePattern( QOpenGLBuffer::StaticDraw );
118 | cube.pos_vbo.setUsagePattern( QOpenGLBuffer::DynamicDraw );
119 | cube.mag_vbo.setUsagePattern( QOpenGLBuffer::DynamicDraw );
120 |
121 | if ( !cube.vbo.bind() )
122 | {
123 | qWarning() << "Could not bind vertex buffer to the context";
124 | return false;
125 | }
126 | cube.vbo.allocate( vertexNormData, 6*6*3*2 * sizeof( float ) );
127 | cubeShader.setAttributeBuffer( "vertex", GL_FLOAT, 0, 3, 6*sizeof(GLfloat) );
128 | cubeShader.setAttributeBuffer( "vertexNormal", GL_FLOAT, 3*sizeof(GLfloat), 3, 6*sizeof(GLfloat) );
129 | cubeShader.enableAttributeArray( "vertex" );
130 | cubeShader.enableAttributeArray( "vertexNormal" );
131 | cube.vbo.release();
132 |
133 | if ( !cube.pos_vbo.bind() )
134 | {
135 | qWarning() << "Could not bind position buffer to the context";
136 | return false;
137 | }
138 | cube.pos_vbo.allocate( 1 * sizeof(QVector4D) );
139 | cubeShader.setAttributeBuffer( "translation", GL_FLOAT, 0, 4, 4*sizeof(GLfloat) );
140 | cubeShader.enableAttributeArray( "translation" );
141 | gl330Funcs->glVertexAttribDivisor(3, 1); // "translation" vbo
142 | cube.pos_vbo.release();
143 |
144 | if ( !cube.mag_vbo.bind() )
145 | {
146 | qWarning() << "Could not bind magnetization buffer to the context";
147 | return false;
148 | }
149 | cube.mag_vbo.allocate( 1 * sizeof(QVector4D) );
150 | cubeShader.setAttributeBuffer( "magnetization", GL_FLOAT, 0, 4, 4*sizeof(GLfloat) );
151 | cubeShader.enableAttributeArray( "magnetization" );
152 | gl330Funcs->glVertexAttribDivisor(2, 1); // "magnetization" vbo
153 | cube.mag_vbo.release();
154 |
155 | cube.vao->release();
156 | return true;
157 | }
158 |
159 | bool GLWidget::initializeCone(int slices, float radius, float height)
160 | {
161 |
162 | if (!cone.vbo.isCreated()) {
163 | cone.vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
164 | cone.pos_vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
165 | cone.mag_vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
166 | cone.vbo.create();
167 | cone.pos_vbo.create();
168 | cone.mag_vbo.create();
169 |
170 | cone.vao = new QOpenGLVertexArrayObject(this);
171 | cone.vao->create();
172 | } else {
173 | cone.vbo.destroy();
174 | cone.pos_vbo.destroy();
175 | cone.mag_vbo.destroy();
176 | cone.vbo.create();
177 | cone.pos_vbo.create();
178 | cone.mag_vbo.create();
179 | cone.vao->destroy();
180 | cone.vao->create();
181 | }
182 |
183 | cone.vao->bind();
184 | cone.count = 2*slices*3;
185 |
186 | float normScale = 1.0/sqrt(height*height + radius*radius);
187 |
188 | std::vector vertices;
189 | // Top (Pointy part)
190 | for (int i = 0; iglVertexAttribDivisor(3, 1); // "translation" vbo
278 | cone.pos_vbo.release();
279 |
280 | if ( !cone.mag_vbo.bind() )
281 | {
282 | qWarning() << "Could not bind magnetization buffer to the context";
283 | return false;
284 | }
285 | cone.mag_vbo.allocate( 1 * sizeof(QVector4D) );
286 | standardShader.setAttributeBuffer( "magnetization", GL_FLOAT, 0, 4, 4*sizeof(GLfloat) );
287 | standardShader.enableAttributeArray( "magnetization" );
288 | gl330Funcs->glVertexAttribDivisor(2, 1); // "magnetization" vbo
289 | cone.mag_vbo.release();
290 |
291 | cone.vao->release();
292 | standardShader.release();
293 | return true;
294 | }
295 |
296 | bool GLWidget::initializeVect(int slices, float height, float radius, float fractionTip, float fractionInner)
297 | {
298 | if (!vect.vbo.isCreated()) {
299 | vect.vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
300 | vect.pos_vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
301 | vect.mag_vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
302 | vect.vbo.create();
303 | vect.pos_vbo.create();
304 | vect.mag_vbo.create();
305 |
306 | vect.vao = new QOpenGLVertexArrayObject(this);
307 | vect.vao->create();
308 | } else {
309 | vect.vbo.destroy();
310 | vect.pos_vbo.destroy();
311 | vect.mag_vbo.destroy();
312 | vect.vbo.create();
313 | vect.pos_vbo.create();
314 | vect.mag_vbo.create();
315 | vect.vao->destroy();
316 | vect.vao->create();
317 | }
318 |
319 | vect.vao->bind();
320 | float normScale = 1.0/sqrt(height*height + radius*radius);
321 | float headOffset, tailOffset;
322 | if (vectorOrigin == "Tail") {
323 | tailOffset = 0.0f;
324 | headOffset = height;
325 | } else { // Center origin
326 | tailOffset = -height/2.0f;
327 | headOffset = height/2.0f;
328 | }
329 | float centerOffset = tailOffset + height*(1.0f-fractionTip);
330 |
331 | float tipHeight = height*fractionTip;
332 |
333 | std::vector vertices;
334 | // Top (Pointy part)
335 | for (int i = 0; iglVertexAttribDivisor(3, 1); // "translation" vbo
504 | vect.pos_vbo.release();
505 |
506 | if ( !vect.mag_vbo.bind() )
507 | {
508 | qWarning() << "Could not bind magnetization buffer to the context";
509 | return false;
510 | }
511 | vect.mag_vbo.allocate( 1 * sizeof(QVector4D) );
512 | standardShader.setAttributeBuffer( "magnetization", GL_FLOAT, 0, 4, 4*sizeof(GLfloat) );
513 | standardShader.enableAttributeArray( "magnetization" );
514 | gl330Funcs->glVertexAttribDivisor(2, 1); // "magnetization" vbo
515 | vect.mag_vbo.release();
516 |
517 | vect.vao->release();
518 | standardShader.release();
519 | return true;
520 | // vect.vbo.setUsagePattern( QOpenGLBuffer::StaticDraw );
521 | // if ( !vect.vbo.bind() )
522 | // {
523 | // qWarning() << "Could not bind vertex buffer to the context";
524 | // return false;
525 | // }
526 |
527 | // vect.vbo.allocate( &vertices.front(), vertices.size() * sizeof(vertices[0]) );
528 | // vect.count = vertices.size();
529 |
530 | // // Bind the shader program so that we can associate variables from
531 | // // our application to the shaders
532 | // if ( !standardShader.bind() )
533 | // {
534 | // qWarning() << "Could not bind shader program to context (vector)" << standardShader.log();
535 | // return false;
536 | // }
537 |
538 | // standardShader.setAttributeBuffer( "vertex", GL_FLOAT, 0, 3, 6*sizeof(GLfloat) );
539 | // standardShader.enableAttributeArray( "vertex" );
540 | // standardShader.setAttributeBuffer( "vertexNormal", GL_FLOAT, 3*sizeof(GLfloat), 3, 6*sizeof(GLfloat) );
541 | // standardShader.enableAttributeArray( "vertexNormal" );
542 |
543 | // vect.vao->release();
544 | // standardShader.release();
545 | // return true;
546 | }
547 |
548 |
--------------------------------------------------------------------------------
/source/glwidget_input.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "glwidget.h"
3 |
4 | void GLWidget::updateCOM()
5 | {
6 | QVector size = dataPtr->field->shape();
7 | xcom = (float)size[0]*0.5;
8 | ycom = (float)size[1]*0.5;
9 | zcom = (float)size[2]*0.5;
10 | }
11 |
12 | void GLWidget::keyPressEvent( QKeyEvent* e )
13 | {
14 | switch ( e->key() )
15 | {
16 | case Qt::Key_Escape:
17 | QCoreApplication::instance()->quit();
18 | break;
19 | default:
20 | QGLWidget::keyPressEvent( e );
21 | }
22 | }
23 | void GLWidget::mousePressEvent(QMouseEvent *e)
24 | {
25 | previousMousePosition = QVector2D(e->localPos());
26 | if (e->buttons() & Qt::LeftButton) {
27 | leftMousePressed = true;
28 | } else if (e->buttons() & Qt::MidButton) {
29 | middleMousePressed = true;
30 | } else if (e->buttons() & Qt::RightButton) {
31 | rightMousePressed = true;
32 | }
33 | }
34 |
35 | void GLWidget::mouseReleaseEvent(QMouseEvent *e)
36 | {
37 | (void) e;
38 | leftMousePressed = false;
39 | middleMousePressed = false;
40 | rightMousePressed = false;
41 | needsUpdate=true;
42 | }
43 |
44 | void GLWidget::mouseMoveEvent(QMouseEvent *e)
45 | {
46 | QVector2D diff = QVector2D(e->localPos()) - previousMousePosition;
47 |
48 | if (e->buttons() & Qt::RightButton) {
49 | setXRotation(xRot + 800 * diff.y());
50 | setYRotation(yRot + 800 * diff.x());
51 | } else if (e->buttons() & Qt::LeftButton) {
52 | setXRotation(xRot + 800 * diff.y());
53 | setZRotation(zRot + 800 * diff.x());
54 | } else if (e->buttons() & Qt::MidButton) {
55 | setXLoc(xLoc + 0.2*diff.x());
56 | setYLoc(yLoc - 0.2*diff.y());
57 | }
58 |
59 | previousMousePosition = QVector2D(e->localPos());
60 |
61 | }
62 |
63 | void GLWidget::wheelEvent(QWheelEvent *e)
64 | {
65 | if(e->orientation() == Qt::Vertical)
66 | {
67 | zoom += (float)(e->delta()) / 50;
68 | }
69 | needsUpdate = true;
70 | }
71 |
72 | void GLWidget::setXSliceLow(int low)
73 | {
74 | if (xSliceLow != low) {
75 | xSliceLow = low;
76 | needsUpdate = true;
77 | }
78 | }
79 |
80 | void GLWidget::setXSliceHigh(int high)
81 | {
82 | if (xSliceLow != high) {
83 | xSliceHigh = high;
84 | needsUpdate = true;
85 | }
86 | }
87 |
88 | void GLWidget::setYSliceLow(int low)
89 | {
90 | if (ySliceLow != low) {
91 | ySliceLow = low;
92 | needsUpdate = true;
93 | }
94 | }
95 |
96 | void GLWidget::setYSliceHigh(int high)
97 | {
98 | if (ySliceLow != high) {
99 | ySliceHigh = high;
100 | needsUpdate = true;
101 | }
102 | }
103 |
104 | void GLWidget::setZSliceLow(int low)
105 | {
106 | if (zSliceLow != low) {
107 | zSliceLow = low;
108 | needsUpdate = true;
109 | }
110 | }
111 |
112 | void GLWidget::setZSliceHigh(int high)
113 | {
114 | if (zSliceLow != high) {
115 | zSliceHigh = high;
116 | needsUpdate = true;
117 | }
118 | }
119 |
120 | void GLWidget::setThresholdLow(int low)
121 | {
122 | if (thresholdLow != low) {
123 | thresholdLow = low;
124 | needsUpdate = true;
125 | }
126 | }
127 |
128 | void GLWidget::setThresholdHigh(int high)
129 | {
130 | if (thresholdLow != high) {
131 | thresholdHigh = high;
132 | needsUpdate = true;
133 | }
134 | }
135 |
136 | static void qNormalizeAngle(int &angle)
137 | {
138 | while (angle < 0)
139 | angle += 360 * 1600;
140 | while (angle > 360 * 1600)
141 | angle -= 360 * 1600;
142 | }
143 |
144 | void GLWidget::setXRotation(int angle)
145 | {
146 | qNormalizeAngle(angle);
147 | if (angle != xRot) {
148 | xRot = angle;
149 | emit xRotationChanged(angle);
150 | needsUpdate = true;
151 | }
152 | }
153 |
154 | void GLWidget::setYRotation(int angle)
155 | {
156 | qNormalizeAngle(angle);
157 | if (angle != yRot) {
158 | yRot = angle;
159 | emit yRotationChanged(angle);
160 | needsUpdate = true;
161 | }
162 | }
163 |
164 | void GLWidget::setZRotation(int angle)
165 | {
166 | qNormalizeAngle(angle);
167 | if (angle != zRot) {
168 | zRot = angle;
169 | emit zRotationChanged(angle);
170 | needsUpdate = true;
171 | }
172 | }
173 |
174 | void GLWidget::setXLoc(float val)
175 | {
176 | if (xLoc != val) {
177 | xLoc = val;
178 | emit COMChanged(val);
179 | needsUpdate = true;
180 | }
181 | }
182 |
183 | void GLWidget::setYLoc(float val)
184 | {
185 | if (yLoc != val) {
186 | yLoc = val;
187 | emit COMChanged(val);
188 | needsUpdate = true;
189 | }
190 | }
191 |
192 | void GLWidget::setZLoc(float val)
193 | {
194 | if (zLoc != val) {
195 | zLoc = val;
196 | emit COMChanged(val);
197 | needsUpdate = true;
198 | }
199 | }
200 |
201 | void GLWidget::increaseSubsampling()
202 | {
203 | subsampling++;
204 | needsUpdate = true;
205 | pushBuffers();
206 | }
207 |
208 | void GLWidget::decreaseSubsampling()
209 | {
210 | if (subsampling > 0) {
211 | subsampling--;
212 | needsUpdate = true;
213 | pushBuffers();
214 | }
215 | }
216 |
217 | void GLWidget::setXCom(float val)
218 | {
219 | if (xcom != val) {
220 | xcom = val;
221 | emit COMChanged(val);
222 | needsUpdate = true;
223 | }
224 | }
225 |
226 | void GLWidget::setYCom(float val)
227 | {
228 | if (ycom != val) {
229 | ycom = val;
230 | emit COMChanged(val);
231 | needsUpdate = true;
232 | }
233 | }
234 |
235 | void GLWidget::setZCom(float val)
236 | {
237 | if (zcom != val) {
238 | zcom = val;
239 | emit COMChanged(val);
240 | needsUpdate = true;
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/source/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "window.h"
5 |
6 | int main( int argc, char* argv[] )
7 | {
8 | QApplication app( argc, argv );
9 |
10 | // Parse command line arguments
11 | QApplication::setApplicationName("Muview");
12 | QApplication::setApplicationVersion("2.2");
13 | app.setStyle(QStyleFactory::create("GTK+"));
14 |
15 | Window w( app.arguments() );
16 | w.show();
17 |
18 | return app.exec();
19 | }
20 |
--------------------------------------------------------------------------------
/source/matrix.cpp:
--------------------------------------------------------------------------------
1 | #include "matrix.h"
2 |
3 | matrix::matrix(int sizeX, int sizeY, int sizeZ)
4 | {
5 | sizes << sizeX << sizeY << sizeZ;
6 | numElements = sizeX*sizeY*sizeZ;
7 | strides << 1 << sizeX << sizeY*sizeX;
8 | data = QSharedPointer >(new QVector(numElements));
9 | }
10 |
11 | void matrix::clear()
12 | {
13 | data->fill(QVector3D(0,0,0));
14 | }
15 |
16 | void matrix::set(int x, int y, int z, QVector3D vector)
17 | {
18 | data->replace(index(x,y,z), vector);
19 | }
20 |
21 | void matrix::set(int ind, QVector3D vector)
22 | {
23 | data->replace(ind, vector);
24 | }
25 |
26 | QVector3D matrix::at(int x, int y, int z)
27 | {
28 | return data->at(index(x,y,z));
29 | }
30 |
31 | QVector3D matrix::get(int i)
32 | {
33 | return data->at(i);
34 | }
35 |
36 | QVector matrix::shape()
37 | {
38 | return sizes;
39 | }
40 |
41 | void matrix::minmaxScalar(float &min, float &max)
42 | {
43 | float minSearch = (data->at(0)).x();
44 | float maxSearch = (data->at(0)).x();
45 | float val;
46 |
47 | for(int k=0; kat(0)).x();
50 | if (val < minSearch) {
51 | minSearch = val;
52 | }
53 | if (val > maxSearch) {
54 | maxSearch = val;
55 | }
56 | }
57 |
58 | max = maxSearch;
59 | min = minSearch;
60 | }
61 |
62 | void matrix::minmaxMagnitude(float &min, float &max)
63 | {
64 | float minSearch = data->at(0).length();
65 | float maxSearch = data->at(0).length();
66 | float length;
67 |
68 | for(int k=0; kat(k).length();
71 | if (length < minSearch) {
72 | minSearch = length;
73 | }
74 | if (length > maxSearch) {
75 | maxSearch = length;
76 | }
77 | }
78 |
79 | max = maxSearch;
80 | min = minSearch;
81 | }
82 |
83 | int matrix::num_elements()
84 | {
85 | return numElements;
86 | }
87 |
88 | int matrix::index(int x, int y, int z)
89 | {
90 | return x*strides[0] + y*strides[1] + z*strides[2];
91 | }
92 |
--------------------------------------------------------------------------------
/source/matrix.h:
--------------------------------------------------------------------------------
1 | #ifndef MATRIX_H
2 | #define MATRIX_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class matrix : public QObject
10 | {
11 | Q_OBJECT
12 | public:
13 | matrix(int sizeX, int sizeY, int sizeZ);
14 | void clear();
15 | void set(int x, int y, int z, QVector3D vector);
16 | void set(int ind, QVector3D vector);
17 | QVector3D at(int x, int y, int z);
18 | QVector3D get(int i);
19 | QVector shape();
20 | void minmaxScalar(float &min, float &max);
21 | void minmaxMagnitude(float &min, float &max);
22 | int num_elements();
23 |
24 | private:
25 | int index(int x, int y, int z);
26 | // x, y, z ordering
27 | QVector sizes;
28 | QVector strides;
29 | int numElements;
30 | QSharedPointer > data;
31 | };
32 |
33 | #endif // MATRIX_H
34 |
--------------------------------------------------------------------------------
/source/preferences.cpp:
--------------------------------------------------------------------------------
1 | #include "preferences.h"
2 | #include "ui_preferences.h"
3 | #include
4 | #include
5 | #include
6 |
7 | Preferences::Preferences(QWidget *parent) :
8 | QDialog(parent),
9 | ui(new Ui::Preferences)
10 | {
11 | ui->setupUi(this);
12 |
13 | backgroundColor = QColor::fromRgbF(0.9, 0.8, 1.0).dark();
14 | customColor1 = QColor::fromRgb(240,115,20);
15 | customColor2 = QColor::fromRgb(175,175,175);
16 | customColor3 = QColor::fromRgb(55,195,225);
17 |
18 | ui->colorBox->setPalette(QPalette(backgroundColor));
19 | ui->customColorBox1->setPalette(QPalette(customColor1));
20 | ui->customColorBox2->setPalette(QPalette(customColor2));
21 | ui->customColorBox3->setPalette(QPalette(customColor3));
22 |
23 | connect(ui->setBackgroundColor, SIGNAL(clicked()), this, SLOT(setColor()));
24 | connect(ui->setCustomColor1, SIGNAL(clicked()), this, SLOT(setCustomColor1()));
25 | connect(ui->setCustomColor2, SIGNAL(clicked()), this, SLOT(setCustomColor2()));
26 | connect(ui->setCustomColor3, SIGNAL(clicked()), this, SLOT(setCustomColor3()));
27 | }
28 |
29 | void Preferences::setColor()
30 | {
31 | QColor color = QColorDialog::getColor(backgroundColor, this);
32 | if (color.isValid())
33 | {
34 | ui->colorBox->setPalette(QPalette(color));
35 | ui->colorBox->setAutoFillBackground(true);
36 | backgroundColor = color;
37 | }
38 | }
39 |
40 | void Preferences::setCustomColor1()
41 | {
42 | QColor color = QColorDialog::getColor(customColor1, this);
43 | if (color.isValid())
44 | {
45 | ui->customColorBox1->setPalette(QPalette(color));
46 | ui->customColorBox1->setAutoFillBackground(true);
47 | customColor1 = color;
48 | }
49 | }
50 |
51 | void Preferences::setCustomColor2()
52 | {
53 | QColor color = QColorDialog::getColor(customColor2, this);
54 | if (color.isValid())
55 | {
56 | ui->customColorBox2->setPalette(QPalette(color));
57 | ui->customColorBox2->setAutoFillBackground(true);
58 | customColor2 = color;
59 | }
60 | }
61 |
62 | void Preferences::setCustomColor3()
63 | {
64 | QColor color = QColorDialog::getColor(customColor3, this);
65 | if (color.isValid())
66 | {
67 | ui->customColorBox3->setPalette(QPalette(color));
68 | ui->customColorBox3->setAutoFillBackground(true);
69 | customColor3 = color;
70 | }
71 | }
72 |
73 | QColor Preferences::getBackgroundColor() {
74 | return backgroundColor;
75 | }
76 |
77 | Preferences::~Preferences()
78 | {
79 | delete ui;
80 | }
81 |
82 | int Preferences::getSpriteResolution()
83 | {
84 | return ui->spriteResolution->value();
85 | }
86 |
87 | float Preferences::getVectorLength()
88 | {
89 | return ((float)ui->vectorLength->value())/100.f;
90 | }
91 |
92 | float Preferences::getVectorRadius()
93 | {
94 | return ((float)ui->vectorRadius->value())/100.f;
95 | }
96 |
97 | float Preferences::getVectorTipToTail()
98 | {
99 | return ((float)ui->tipPercent->value())/100.f;
100 | }
101 |
102 | float Preferences::getVectorInnerToOuter()
103 | {
104 | return ((float)ui->shaftRadiusPercent->value())/100.f;
105 | }
106 |
107 | float Preferences::getBrightness()
108 | {
109 | return ((float)ui->brightnessSlider->value())/50.0;
110 | }
111 |
112 | QString Preferences::getFormat()
113 | {
114 | return ui->imageFormat->currentText();
115 | }
116 |
117 | QSize Preferences::getImageDimensions()
118 | {
119 | if (ui->fixedSize->isChecked()) {
120 | return QSize(ui->imageWidth->value(), ui->imageHeight->value());
121 | } else {
122 | return QSize(-1,-1);
123 | }
124 | }
125 |
126 | QString Preferences::getColorScale()
127 | {
128 | return ui->colorScaleGroup->checkedButton()->text();
129 | }
130 |
131 | QString Preferences::getColorQuantity()
132 | {
133 | return ui->coloredQuantityGroup->checkedButton()->text();
134 | }
135 |
136 | QString Preferences::getVectorOrigin()
137 | {
138 | return ui->vectorOriginGroup->checkedButton()->text();
139 | }
140 |
141 | QString Preferences::getSpriteScale()
142 | {
143 | return ui->spriteScaleGroup->checkedButton()->text();
144 | }
145 |
146 | QList Preferences::getCustomColorScale()
147 | {
148 | QList colors;
149 | colors << customColor1 << customColor2 << customColor3;
150 | return colors;
151 | }
152 |
--------------------------------------------------------------------------------
/source/preferences.h:
--------------------------------------------------------------------------------
1 | #ifndef PREFERENCES_H
2 | #define PREFERENCES_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class Preferences;
9 | }
10 |
11 | class Preferences : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit Preferences(QWidget *parent = 0);
17 | QColor getBackgroundColor();
18 | int getSpriteResolution();
19 | float getVectorLength();
20 | float getVectorRadius();
21 | float getVectorTipToTail();
22 | float getVectorInnerToOuter();
23 | float getBrightness();
24 | QString getFormat();
25 | QSize getImageDimensions();
26 | QString getColorScale();
27 | QString getColorQuantity();
28 | QString getVectorOrigin();
29 | QString getSpriteScale();
30 | QList getCustomColorScale();
31 | ~Preferences();
32 |
33 | private:
34 | Ui::Preferences *ui;
35 | QColor backgroundColor;
36 | QColor customColor1;
37 | QColor customColor2;
38 | QColor customColor3;
39 | private slots:
40 | void setColor();
41 | void setCustomColor1();
42 | void setCustomColor2();
43 | void setCustomColor3();
44 | };
45 |
46 | #endif // PREFERENCES_H
47 |
--------------------------------------------------------------------------------
/source/qxtspanslider.cpp:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) Qxt Foundation. Some rights reserved.
4 | **
5 | ** This file is part of the QxtGui module of the Qxt library.
6 | **
7 | ** This library is free software; you can redistribute it and/or modify it
8 | ** under the terms of the Common Public License, version 1.0, as published
9 | ** by IBM, and/or under the terms of the GNU Lesser General Public License,
10 | ** version 2.1, as published by the Free Software Foundation.
11 | **
12 | ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
13 | ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
14 | ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
15 | ** FITNESS FOR A PARTICULAR PURPOSE.
16 | **
17 | ** You should have received a copy of the CPL and the LGPL along with this
18 | ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
19 | ** included with the source distribution for more information.
20 | ** If you did not receive a copy of the licenses, contact the Qxt Foundation.
21 | **
22 | **
23 | **
24 | ****************************************************************************/
25 | // Modified by Graham Rowlands
26 |
27 | #include "qxtspanslider.h"
28 | #include "qxtspanslider_p.h"
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | QxtSpanSliderPrivate::QxtSpanSliderPrivate() :
37 | lower(0),
38 | upper(0),
39 | lowerPos(0),
40 | upperPos(0),
41 | offset(0),
42 | position(0),
43 | lastPressed(NoHandle),
44 | mainControl(LowerHandle),
45 | lowerPressed(QStyle::SC_None),
46 | upperPressed(QStyle::SC_None),
47 | movement(QxtSpanSlider::FreeMovement),
48 | firstMovement(false),
49 | blockTracking(false),
50 | fixedInterval(false)
51 | {
52 | }
53 |
54 | // TODO: get rid of this in Qt 4.3
55 | void QxtSpanSliderPrivate::initStyleOption(QStyleOptionSlider* option, SpanHandle handle) const
56 | {
57 | if (!option)
58 | return;
59 |
60 | const QSlider* p = &qxt_p();
61 | option->initFrom(p);
62 | option->subControls = QStyle::SC_None;
63 | option->activeSubControls = QStyle::SC_None;
64 | option->orientation = p->orientation();
65 | option->maximum = p->maximum();
66 | option->minimum = p->minimum();
67 | option->tickPosition = p->tickPosition();
68 | option->tickInterval = p->tickInterval();
69 | option->upsideDown = (p->orientation() == Qt::Horizontal) ?
70 | (p->invertedAppearance() != (option->direction == Qt::RightToLeft)) : (!p->invertedAppearance());
71 | option->direction = Qt::LeftToRight; // we use the upsideDown option instead
72 | option->sliderPosition = (handle == LowerHandle ? lowerPos : upperPos);
73 | option->sliderValue = (handle == LowerHandle ? lower : upper);
74 | option->singleStep = p->singleStep();
75 | option->pageStep = p->pageStep();
76 | if (p->orientation() == Qt::Horizontal)
77 | option->state |= QStyle::State_Horizontal;
78 | }
79 |
80 | int QxtSpanSliderPrivate::pixelPosToRangeValue(int pos) const
81 | {
82 | QStyleOptionSlider opt;
83 | initStyleOption(&opt);
84 |
85 | int sliderMin = 0;
86 | int sliderMax = 0;
87 | int sliderLength = 0;
88 | const QSlider* p = &qxt_p();
89 | const QRect gr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p);
90 | const QRect sr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, p);
91 | if (p->orientation() == Qt::Horizontal)
92 | {
93 | sliderLength = sr.width();
94 | sliderMin = gr.x();
95 | sliderMax = gr.right() - sliderLength + 1;
96 | }
97 | else
98 | {
99 | sliderLength = sr.height();
100 | sliderMin = gr.y();
101 | sliderMax = gr.bottom() - sliderLength + 1;
102 | }
103 | return QStyle::sliderValueFromPosition(p->minimum(), p->maximum(), pos - sliderMin,
104 | sliderMax - sliderMin, opt.upsideDown);
105 | }
106 |
107 | void QxtSpanSliderPrivate::handleMousePress(const QPoint& pos, QStyle::SubControl& control, int value, SpanHandle handle)
108 | {
109 | QStyleOptionSlider opt;
110 | initStyleOption(&opt, handle);
111 | QSlider* p = &qxt_p();
112 | const QStyle::SubControl oldControl = control;
113 | control = p->style()->hitTestComplexControl(QStyle::CC_Slider, &opt, pos, p);
114 | const QRect sr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, p);
115 | if (control == QStyle::SC_SliderHandle)
116 | {
117 | position = value;
118 | offset = pick(pos - sr.topLeft());
119 | lastPressed = handle;
120 | p->setSliderDown(true);
121 | }
122 | if (control != oldControl)
123 | p->update(sr);
124 | }
125 |
126 | void QxtSpanSliderPrivate::setupPainter(QPainter* painter, Qt::Orientation orientation, qreal x1, qreal y1, qreal x2, qreal y2) const
127 | {
128 | QColor highlight = qxt_p().palette().color(QPalette::Highlight);
129 | QLinearGradient gradient(x1, y1, x2, y2);
130 | gradient.setColorAt(0, highlight.dark(120));
131 | gradient.setColorAt(1, highlight.light(108));
132 | painter->setBrush(gradient);
133 |
134 | if (orientation == Qt::Horizontal)
135 | painter->setPen(QPen(highlight.dark(130), 0));
136 | else
137 | painter->setPen(QPen(highlight.dark(150), 0));
138 | }
139 |
140 | void QxtSpanSliderPrivate::drawSpan(QStylePainter* painter, const QRect& rect) const
141 | {
142 | QStyleOptionSlider opt;
143 | initStyleOption(&opt);
144 | const QSlider* p = &qxt_p();
145 |
146 | // area
147 | QRect groove = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p);
148 | if (opt.orientation == Qt::Horizontal)
149 | groove.adjust(0, 0, -1, 0);
150 | else
151 | groove.adjust(0, 0, 0, -1);
152 |
153 | // pen & brush
154 | painter->setPen(QPen(p->palette().color(QPalette::Dark).light(110), 0));
155 | if (opt.orientation == Qt::Horizontal)
156 | setupPainter(painter, opt.orientation, groove.center().x(), groove.top(), groove.center().x(), groove.bottom());
157 | else
158 | setupPainter(painter, opt.orientation, groove.left(), groove.center().y(), groove.right(), groove.center().y());
159 |
160 | // draw groove
161 | painter->drawRect(rect.intersected(groove));
162 | }
163 |
164 | void QxtSpanSliderPrivate::drawHandle(QStylePainter* painter, SpanHandle handle) const
165 | {
166 | QStyleOptionSlider opt;
167 | initStyleOption(&opt, handle);
168 | opt.subControls = QStyle::SC_SliderHandle;
169 | QStyle::SubControl pressed = (handle == LowerHandle ? lowerPressed : upperPressed);
170 | if (pressed == QStyle::SC_SliderHandle)
171 | {
172 | opt.activeSubControls = pressed;
173 | opt.state |= QStyle::State_Sunken;
174 | }
175 | painter->drawComplexControl(QStyle::CC_Slider, opt);
176 | }
177 |
178 | void QxtSpanSliderPrivate::triggerAction(QAbstractSlider::SliderAction action, bool main)
179 | {
180 | int value = 0;
181 | bool no = false;
182 | bool up = false;
183 | const int min = qxt_p().minimum();
184 | const int max = qxt_p().maximum();
185 | const SpanHandle altControl = (mainControl == LowerHandle ? UpperHandle : LowerHandle);
186 |
187 | blockTracking = true;
188 |
189 | switch (action)
190 | {
191 | case QAbstractSlider::SliderSingleStepAdd:
192 | if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
193 | {
194 | value = qBound(min, upper + qxt_p().singleStep(), max);
195 | up = true;
196 | break;
197 | }
198 | value = qBound(min, lower + qxt_p().singleStep(), max);
199 | break;
200 | case QAbstractSlider::SliderSingleStepSub:
201 | if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
202 | {
203 | value = qBound(min, upper - qxt_p().singleStep(), max);
204 | up = true;
205 | break;
206 | }
207 | value = qBound(min, lower - qxt_p().singleStep(), max);
208 | break;
209 | case QAbstractSlider::SliderToMinimum:
210 | value = min;
211 | if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
212 | up = true;
213 | break;
214 | case QAbstractSlider::SliderToMaximum:
215 | value = max;
216 | if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
217 | up = true;
218 | break;
219 | case QAbstractSlider::SliderMove:
220 | if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
221 | up = true;
222 | case QAbstractSlider::SliderNoAction:
223 | no = true;
224 | break;
225 | default:
226 | qWarning("QxtSpanSliderPrivate::triggerAction: Unknown action");
227 | break;
228 | }
229 |
230 | if (!no && !up)
231 | {
232 | if (movement == QxtSpanSlider::NoCrossing)
233 | value = qMin(value, upper);
234 | else if (movement == QxtSpanSlider::NoOverlapping)
235 | value = qMin(value, upper - 1);
236 |
237 | if (movement == QxtSpanSlider::FreeMovement && value > upper)
238 | {
239 | swapControls();
240 | qxt_p().setUpperPosition(value);
241 | }
242 | else
243 | {
244 | qxt_p().setLowerPosition(value);
245 | }
246 | }
247 | else if (!no)
248 | {
249 | if (movement == QxtSpanSlider::NoCrossing)
250 | value = qMax(value, lower);
251 | else if (movement == QxtSpanSlider::NoOverlapping)
252 | value = qMax(value, lower + 1);
253 |
254 | if (movement == QxtSpanSlider::FreeMovement && value < lower)
255 | {
256 | swapControls();
257 | qxt_p().setLowerPosition(value);
258 | }
259 | else
260 | {
261 | qxt_p().setUpperPosition(value);
262 | }
263 | }
264 |
265 | blockTracking = false;
266 | qxt_p().setLowerValue(lowerPos);
267 | qxt_p().setUpperValue(upperPos);
268 | }
269 |
270 | void QxtSpanSliderPrivate::swapControls()
271 | {
272 | qSwap(lower, upper);
273 | qSwap(lowerPressed, upperPressed);
274 | lastPressed = (lastPressed == LowerHandle ? UpperHandle : LowerHandle);
275 | mainControl = (mainControl == LowerHandle ? UpperHandle : LowerHandle);
276 | }
277 |
278 | void QxtSpanSliderPrivate::updateRange(int min, int max)
279 | {
280 | Q_UNUSED(min);
281 | Q_UNUSED(max);
282 | // setSpan() takes care of keeping span in range
283 | qxt_p().setSpan(lower, upper);
284 | }
285 |
286 | void QxtSpanSliderPrivate::movePressedHandle()
287 | {
288 | switch (lastPressed)
289 | {
290 | case QxtSpanSliderPrivate::LowerHandle:
291 | if (lowerPos != lower)
292 | {
293 | bool main = (mainControl == QxtSpanSliderPrivate::LowerHandle);
294 | triggerAction(QAbstractSlider::SliderMove, main);
295 | }
296 | break;
297 | case QxtSpanSliderPrivate::UpperHandle:
298 | if (upperPos != upper)
299 | {
300 | bool main = (mainControl == QxtSpanSliderPrivate::UpperHandle);
301 | triggerAction(QAbstractSlider::SliderMove, main);
302 | }
303 | break;
304 | default:
305 | break;
306 | }
307 | }
308 |
309 | /*!
310 | \class QxtSpanSlider
311 | \inmodule QxtGui
312 | \brief The QxtSpanSlider widget is a QSlider with two handles.
313 |
314 | QxtSpanSlider is a slider with two handles. QxtSpanSlider is
315 | handy for letting user to choose an span between min/max.
316 |
317 | The span color is calculated based on QPalette::Highlight.
318 |
319 | The keys are bound according to the following table:
320 | \table
321 | \header \o Orientation \o Key \o Handle
322 | \row \o Qt::Horizontal \o Qt::Key_Left \o lower
323 | \row \o Qt::Horizontal \o Qt::Key_Right \o lower
324 | \row \o Qt::Horizontal \o Qt::Key_Up \o upper
325 | \row \o Qt::Horizontal \o Qt::Key_Down \o upper
326 | \row \o Qt::Vertical \o Qt::Key_Up \o lower
327 | \row \o Qt::Vertical \o Qt::Key_Down \o lower
328 | \row \o Qt::Vertical \o Qt::Key_Left \o upper
329 | \row \o Qt::Vertical \o Qt::Key_Right \o upper
330 | \endtable
331 |
332 | Keys are bound by the time the slider is created. A key is bound
333 | to same handle for the lifetime of the slider. So even if the handle
334 | representation might change from lower to upper, the same key binding
335 | remains.
336 |
337 | \image qxtspanslider.png "QxtSpanSlider in Plastique style."
338 |
339 | \bold {Note:} QxtSpanSlider inherits QSlider for implementation specific
340 | reasons. Adjusting any single handle specific properties like
341 | \list
342 | \o QAbstractSlider::sliderPosition
343 | \o QAbstractSlider::value
344 | \endlist
345 | has no effect. However, all slider specific properties like
346 | \list
347 | \o QAbstractSlider::invertedAppearance
348 | \o QAbstractSlider::invertedControls
349 | \o QAbstractSlider::minimum
350 | \o QAbstractSlider::maximum
351 | \o QAbstractSlider::orientation
352 | \o QAbstractSlider::pageStep
353 | \o QAbstractSlider::singleStep
354 | \o QSlider::tickInterval
355 | \o QSlider::tickPosition
356 | \endlist
357 | are taken into consideration.
358 | */
359 |
360 | /*!
361 | \enum QxtSpanSlider::HandleMovementMode
362 |
363 | This enum describes the available handle movement modes.
364 |
365 | \value FreeMovement The handles can be moved freely.
366 | \value NoCrossing The handles cannot cross, but they can still overlap each other. The lower and upper values can be the same.
367 | \value NoOverlapping The handles cannot overlap each other. The lower and upper values cannot be the same.
368 | */
369 |
370 | /*!
371 | \fn QxtSpanSlider::lowerValueChanged(int lower)
372 |
373 | This signal is emitted whenever the \a lower value has changed.
374 | */
375 |
376 | /*!
377 | \fn QxtSpanSlider::upperValueChanged(int upper)
378 |
379 | This signal is emitted whenever the \a upper value has changed.
380 | */
381 |
382 | /*!
383 | \fn QxtSpanSlider::spanChanged(int lower, int upper)
384 |
385 | This signal is emitted whenever both the \a lower and the \a upper
386 | values have changed ie. the span has changed.
387 | */
388 |
389 | /*!
390 | \fn QxtSpanSlider::lowerPositionChanged(int lower)
391 |
392 | This signal is emitted whenever the \a lower position has changed.
393 | */
394 |
395 | /*!
396 | \fn QxtSpanSlider::upperPositionChanged(int upper)
397 |
398 | This signal is emitted whenever the \a upper position has changed.
399 | */
400 |
401 | /*!
402 | Constructs a new QxtSpanSlider with \a parent.
403 | */
404 | QxtSpanSlider::QxtSpanSlider(QWidget* parent) : QSlider(parent)
405 | {
406 | QXT_INIT_PRIVATE(QxtSpanSlider);
407 | connect(this, SIGNAL(rangeChanged(int, int)), &qxt_d(), SLOT(updateRange(int, int)));
408 | connect(this, SIGNAL(sliderReleased()), &qxt_d(), SLOT(movePressedHandle()));
409 | }
410 |
411 | /*!
412 | Constructs a new QxtSpanSlider with \a orientation and \a parent.
413 | */
414 | QxtSpanSlider::QxtSpanSlider(Qt::Orientation orientation, QWidget* parent) : QSlider(orientation, parent)
415 | {
416 | QXT_INIT_PRIVATE(QxtSpanSlider);
417 | connect(this, SIGNAL(rangeChanged(int, int)), &qxt_d(), SLOT(updateRange(int, int)));
418 | connect(this, SIGNAL(sliderReleased()), &qxt_d(), SLOT(movePressedHandle()));
419 | }
420 |
421 | /*!
422 | Destructs the span slider.
423 | */
424 | QxtSpanSlider::~QxtSpanSlider()
425 | {
426 | }
427 |
428 | /*!
429 | \property QxtSpanSlider::handleMovementMode
430 | \brief the handle movement mode
431 | */
432 | QxtSpanSlider::HandleMovementMode QxtSpanSlider::handleMovementMode() const
433 | {
434 | return qxt_d().movement;
435 | }
436 |
437 | void QxtSpanSlider::setHandleMovementMode(QxtSpanSlider::HandleMovementMode mode)
438 | {
439 | qxt_d().movement = mode;
440 | }
441 |
442 | /*!
443 | \property QxtSpanSlider::lowerValue
444 | \brief the lower value of the span
445 | */
446 | int QxtSpanSlider::lowerValue() const
447 | {
448 | return qMin(qxt_d().lower, qxt_d().upper);
449 | }
450 |
451 | void QxtSpanSlider::setLowerValue(int lower)
452 | {
453 | setSpan(lower, qxt_d().upper);
454 | }
455 |
456 | /*!
457 | \property QxtSpanSlider::upperValue
458 | \brief the upper value of the span
459 | */
460 | int QxtSpanSlider::upperValue() const
461 | {
462 | return qMax(qxt_d().lower, qxt_d().upper);
463 | }
464 |
465 | void QxtSpanSlider::setUpperValue(int upper)
466 | {
467 | setSpan(qxt_d().lower, upper);
468 | }
469 |
470 | /*!
471 | Sets the span from \a lower to \a upper.
472 | */
473 | void QxtSpanSlider::setSpan(int lower, int upper)
474 | {
475 | const int low = qBound(minimum(), qMin(lower, upper), maximum());
476 | const int upp = qBound(minimum(), qMax(lower, upper), maximum());
477 | if (low != qxt_d().lower || upp != qxt_d().upper)
478 | {
479 | if (low != qxt_d().lower)
480 | {
481 | qxt_d().lower = low;
482 | qxt_d().lowerPos = low;
483 | emit lowerValueChanged(low);
484 | }
485 | if (upp != qxt_d().upper)
486 | {
487 | qxt_d().upper = upp;
488 | qxt_d().upperPos = upp;
489 | emit upperValueChanged(upp);
490 | }
491 | emit spanChanged(qxt_d().lower, qxt_d().upper);
492 | update();
493 | }
494 | }
495 |
496 | /*!
497 | \property QxtSpanSlider::lowerPosition
498 | \brief the lower position of the span
499 | */
500 | int QxtSpanSlider::lowerPosition() const
501 | {
502 | return qxt_d().lowerPos;
503 | }
504 |
505 | void QxtSpanSlider::setLowerPosition(int lower)
506 | {
507 | if (qxt_d().lowerPos != lower)
508 | {
509 | qxt_d().lowerPos = lower;
510 | if (!hasTracking())
511 | update();
512 | if (isSliderDown())
513 | emit lowerPositionChanged(lower);
514 | if (hasTracking() && !qxt_d().blockTracking)
515 | {
516 | bool main = (qxt_d().mainControl == QxtSpanSliderPrivate::LowerHandle);
517 | qxt_d().triggerAction(SliderMove, main);
518 | }
519 | }
520 | }
521 |
522 | /*!
523 | \property QxtSpanSlider::upperPosition
524 | \brief the upper position of the span
525 | */
526 | int QxtSpanSlider::upperPosition() const
527 | {
528 | return qxt_d().upperPos;
529 | }
530 |
531 | void QxtSpanSlider::setUpperPosition(int upper)
532 | {
533 | if (qxt_d().upperPos != upper)
534 | {
535 | qxt_d().upperPos = upper;
536 | if (!hasTracking())
537 | update();
538 | if (isSliderDown())
539 | emit upperPositionChanged(upper);
540 | if (hasTracking() && !qxt_d().blockTracking)
541 | {
542 | bool main = (qxt_d().mainControl == QxtSpanSliderPrivate::UpperHandle);
543 | qxt_d().triggerAction(SliderMove, main);
544 | }
545 | }
546 | }
547 |
548 | /*!
549 | \reimp
550 | */
551 | void QxtSpanSlider::keyPressEvent(QKeyEvent* event)
552 | {
553 | QSlider::keyPressEvent(event);
554 |
555 | bool main = true;
556 | SliderAction action = SliderNoAction;
557 | switch (event->key())
558 | {
559 | case Qt::Key_Left:
560 | main = (orientation() == Qt::Horizontal);
561 | action = !invertedAppearance() ? SliderSingleStepSub : SliderSingleStepAdd;
562 | break;
563 | case Qt::Key_Right:
564 | main = (orientation() == Qt::Horizontal);
565 | action = !invertedAppearance() ? SliderSingleStepAdd : SliderSingleStepSub;
566 | break;
567 | case Qt::Key_Up:
568 | main = (orientation() == Qt::Vertical);
569 | action = invertedControls() ? SliderSingleStepSub : SliderSingleStepAdd;
570 | break;
571 | case Qt::Key_Down:
572 | main = (orientation() == Qt::Vertical);
573 | action = invertedControls() ? SliderSingleStepAdd : SliderSingleStepSub;
574 | break;
575 | case Qt::Key_Home:
576 | main = (qxt_d().mainControl == QxtSpanSliderPrivate::LowerHandle);
577 | action = SliderToMinimum;
578 | break;
579 | case Qt::Key_End:
580 | main = (qxt_d().mainControl == QxtSpanSliderPrivate::UpperHandle);
581 | action = SliderToMaximum;
582 | break;
583 | default:
584 | event->ignore();
585 | break;
586 | }
587 |
588 | if (action)
589 | qxt_d().triggerAction(action, main);
590 | }
591 |
592 | /*!
593 | \reimp
594 | */
595 | void QxtSpanSlider::mousePressEvent(QMouseEvent* event)
596 | {
597 | if (minimum() == maximum() || (event->buttons() ^ event->button()))
598 | {
599 | event->ignore();
600 | return;
601 | }
602 |
603 | if (event->modifiers() & Qt::ShiftModifier) {
604 | qxt_d().fixedInterval = true;
605 | }
606 |
607 | qxt_d().handleMousePress(event->pos(), qxt_d().upperPressed, qxt_d().upper, QxtSpanSliderPrivate::UpperHandle);
608 | if (qxt_d().upperPressed != QStyle::SC_SliderHandle)
609 | qxt_d().handleMousePress(event->pos(), qxt_d().lowerPressed, qxt_d().lower, QxtSpanSliderPrivate::LowerHandle);
610 |
611 | qxt_d().firstMovement = true;
612 | event->accept();
613 | }
614 |
615 | /*!
616 | \reimp
617 | */
618 | void QxtSpanSlider::mouseMoveEvent(QMouseEvent* event)
619 | {
620 | if (qxt_d().lowerPressed != QStyle::SC_SliderHandle && qxt_d().upperPressed != QStyle::SC_SliderHandle)
621 | {
622 | event->ignore();
623 | return;
624 | }
625 |
626 | QStyleOptionSlider opt;
627 | qxt_d().initStyleOption(&opt);
628 | const int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this);
629 | int newPosition = qxt_d().pixelPosToRangeValue(qxt_d().pick(event->pos()) - qxt_d().offset);
630 | if (m >= 0)
631 | {
632 | const QRect r = rect().adjusted(-m, -m, m, m);
633 | if (!r.contains(event->pos()))
634 | {
635 | newPosition = qxt_d().position;
636 | }
637 | }
638 |
639 | // pick the preferred handle on the first movement
640 | if (qxt_d().firstMovement)
641 | {
642 | if (qxt_d().lower == qxt_d().upper)
643 | {
644 | if (newPosition < lowerValue())
645 | {
646 | qxt_d().swapControls();
647 | qxt_d().firstMovement = false;
648 | }
649 | }
650 | else
651 | {
652 | qxt_d().firstMovement = false;
653 | }
654 | }
655 |
656 | if (qxt_d().lowerPressed == QStyle::SC_SliderHandle)
657 | {
658 | if (qxt_d().movement == NoCrossing)
659 | {
660 | newPosition = qMin(newPosition, upperValue());
661 | }
662 | else if (qxt_d().movement == NoOverlapping)
663 | {
664 | if (qxt_d().fixedInterval)
665 | {
666 | int span = qxt_d().upperPos - qxt_d().lowerPos;
667 | newPosition = qMin(newPosition, upperValue() - 1);
668 | newPosition = qMin(newPosition, maximum() - span);
669 | setUpperPosition(newPosition + span);
670 | }
671 | else
672 | {
673 | newPosition = qMin(newPosition, upperValue() - 1);
674 | }
675 | }
676 |
677 | if (qxt_d().movement == FreeMovement && newPosition > qxt_d().upper)
678 | {
679 | qxt_d().swapControls();
680 | setUpperPosition(newPosition);
681 | }
682 | else
683 | {
684 | setLowerPosition(newPosition);
685 | }
686 | }
687 | else if (qxt_d().upperPressed == QStyle::SC_SliderHandle)
688 | {
689 | if (qxt_d().movement == NoCrossing)
690 | newPosition = qMax(newPosition, lowerValue());
691 | else if (qxt_d().movement == NoOverlapping)
692 | {
693 | if (qxt_d().fixedInterval)
694 | {
695 | int span = qxt_d().upperPos - qxt_d().lowerPos;
696 | newPosition = qMax(newPosition, lowerValue() + 1);
697 | newPosition = qMax(newPosition, span);
698 | setLowerPosition(newPosition - span);
699 | }
700 | else
701 | {
702 | newPosition = qMax(newPosition, lowerValue() + 1);
703 | }
704 | }
705 | if (qxt_d().movement == FreeMovement && newPosition < qxt_d().lower)
706 | {
707 | qxt_d().swapControls();
708 | setLowerPosition(newPosition);
709 | }
710 | else
711 | {
712 | setUpperPosition(newPosition);
713 | }
714 | }
715 | event->accept();
716 | }
717 |
718 | /*!
719 | \reimp
720 | */
721 | void QxtSpanSlider::mouseReleaseEvent(QMouseEvent* event)
722 | {
723 | qxt_d().fixedInterval = false;
724 | QSlider::mouseReleaseEvent(event);
725 | setSliderDown(false);
726 | qxt_d().lowerPressed = QStyle::SC_None;
727 | qxt_d().upperPressed = QStyle::SC_None;
728 | update();
729 | }
730 |
731 | /*!
732 | \reimp
733 | */
734 | void QxtSpanSlider::paintEvent(QPaintEvent* event)
735 | {
736 | Q_UNUSED(event);
737 | QStylePainter painter(this);
738 |
739 | // groove & ticks
740 | QStyleOptionSlider opt;
741 | qxt_d().initStyleOption(&opt);
742 | opt.sliderValue = 0;
743 | opt.sliderPosition = 0;
744 | opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderTickmarks;
745 | painter.drawComplexControl(QStyle::CC_Slider, opt);
746 |
747 | // handle rects
748 | opt.sliderPosition = qxt_d().lowerPos;
749 | const QRect lr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
750 | const int lrv = qxt_d().pick(lr.center());
751 | opt.sliderPosition = qxt_d().upperPos;
752 | const QRect ur = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
753 | const int urv = qxt_d().pick(ur.center());
754 |
755 | // span
756 | const int minv = qMin(lrv, urv);
757 | const int maxv = qMax(lrv, urv);
758 | const QPoint c = QRect(lr.center(), ur.center()).center();
759 | QRect spanRect;
760 | if (orientation() == Qt::Horizontal)
761 | spanRect = QRect(QPoint(minv, c.y() - 2), QPoint(maxv, c.y() + 1));
762 | else
763 | spanRect = QRect(QPoint(c.x() - 2, minv), QPoint(c.x() + 1, maxv));
764 | qxt_d().drawSpan(&painter, spanRect);
765 |
766 | // handles
767 | switch (qxt_d().lastPressed)
768 | {
769 | case QxtSpanSliderPrivate::LowerHandle:
770 | qxt_d().drawHandle(&painter, QxtSpanSliderPrivate::UpperHandle);
771 | qxt_d().drawHandle(&painter, QxtSpanSliderPrivate::LowerHandle);
772 | break;
773 | case QxtSpanSliderPrivate::UpperHandle:
774 | default:
775 | qxt_d().drawHandle(&painter, QxtSpanSliderPrivate::LowerHandle);
776 | qxt_d().drawHandle(&painter, QxtSpanSliderPrivate::UpperHandle);
777 | break;
778 | }
779 | }
780 |
--------------------------------------------------------------------------------
/source/qxtspanslider.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) Qxt Foundation. Some rights reserved.
4 | **
5 | ** This file is part of the QxtGui module of the Qxt library.
6 | **
7 | ** This library is free software; you can redistribute it and/or modify it
8 | ** under the terms of the Common Public License, version 1.0, as published
9 | ** by IBM, and/or under the terms of the GNU Lesser General Public License,
10 | ** version 2.1, as published by the Free Software Foundation.
11 | **
12 | ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
13 | ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
14 | ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
15 | ** FITNESS FOR A PARTICULAR PURPOSE.
16 | **
17 | ** You should have received a copy of the CPL and the LGPL along with this
18 | ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
19 | ** included with the source distribution for more information.
20 | ** If you did not receive a copy of the licenses, contact the Qxt Foundation.
21 | **
22 | **
23 | **
24 | ****************************************************************************/
25 | // Modified by Graham Rowlands
26 |
27 | #ifndef QXTSPANSLIDER_H
28 | #define QXTSPANSLIDER_H
29 |
30 | #define QXT_GUI_EXPORT Q_DECL_IMPORT
31 | #define QXT_CORE_EXPORT Q_DECL_IMPORT
32 | #define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface qxt_d;
33 | #define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
34 | #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
35 | #define QXT_D(PUB) PUB##Private& d = qxt_d()
36 | #define QXT_P(PUB) PUB& p = qxt_p()
37 |
38 | #include
39 |
40 | template
41 | class QxtPrivate
42 | {
43 | public:
44 | virtual ~QxtPrivate()
45 | {}
46 | inline void QXT_setPublic(PUB* pub)
47 | {
48 | qxt_p_ptr = pub;
49 | }
50 |
51 | protected:
52 | inline PUB& qxt_p()
53 | {
54 | return *qxt_p_ptr;
55 | }
56 | inline const PUB& qxt_p() const
57 | {
58 | return *qxt_p_ptr;
59 | }
60 |
61 | private:
62 | PUB* qxt_p_ptr;
63 | };
64 |
65 | template
66 | class QxtPrivateInterface
67 | {
68 | friend class QxtPrivate;
69 | public:
70 | QxtPrivateInterface()
71 | {
72 | pvt = new PVT;
73 | }
74 | ~QxtPrivateInterface()
75 | {
76 | delete pvt;
77 | }
78 |
79 | inline void setPublic(PUB* pub)
80 | {
81 | pvt->QXT_setPublic(pub);
82 | }
83 | inline PVT& operator()()
84 | {
85 | return *static_cast(pvt);
86 | }
87 | inline const PVT& operator()() const
88 | {
89 | return *static_cast(pvt);
90 | }
91 | private:
92 | QxtPrivateInterface(const QxtPrivateInterface&) { }
93 | QxtPrivateInterface& operator=(const QxtPrivateInterface&) { }
94 | QxtPrivate* pvt;
95 | };
96 |
97 | class QxtSpanSliderPrivate;
98 |
99 | class QxtSpanSlider : public QSlider
100 | {
101 | Q_OBJECT
102 | QXT_DECLARE_PRIVATE(QxtSpanSlider)
103 | Q_PROPERTY(int lowerValue READ lowerValue WRITE setLowerValue)
104 | Q_PROPERTY(int upperValue READ upperValue WRITE setUpperValue)
105 | Q_PROPERTY(int lowerPosition READ lowerPosition WRITE setLowerPosition)
106 | Q_PROPERTY(int upperPosition READ upperPosition WRITE setUpperPosition)
107 | Q_PROPERTY(HandleMovementMode handleMovementMode READ handleMovementMode WRITE setHandleMovementMode)
108 | Q_ENUMS(HandleMovementMode)
109 |
110 | public:
111 | explicit QxtSpanSlider(QWidget* parent = 0);
112 | explicit QxtSpanSlider(Qt::Orientation orientation, QWidget* parent = 0);
113 | virtual ~QxtSpanSlider();
114 |
115 | enum HandleMovementMode
116 | {
117 | FreeMovement,
118 | NoCrossing,
119 | NoOverlapping
120 | };
121 |
122 | HandleMovementMode handleMovementMode() const;
123 | void setHandleMovementMode(HandleMovementMode mode);
124 |
125 | int lowerValue() const;
126 | int upperValue() const;
127 |
128 | int lowerPosition() const;
129 | int upperPosition() const;
130 |
131 | public Q_SLOTS:
132 | void setLowerValue(int lower);
133 | void setUpperValue(int upper);
134 | void setSpan(int lower, int upper);
135 |
136 | void setLowerPosition(int lower);
137 | void setUpperPosition(int upper);
138 |
139 | Q_SIGNALS:
140 | void spanChanged(int lower, int upper);
141 | void lowerValueChanged(int lower);
142 | void upperValueChanged(int upper);
143 |
144 | void lowerPositionChanged(int lower);
145 | void upperPositionChanged(int upper);
146 |
147 | protected:
148 | virtual void keyPressEvent(QKeyEvent* event);
149 | virtual void mousePressEvent(QMouseEvent* event);
150 | virtual void mouseMoveEvent(QMouseEvent* event);
151 | virtual void mouseReleaseEvent(QMouseEvent* event);
152 | virtual void paintEvent(QPaintEvent* event);
153 | };
154 |
155 | #endif // QXTSPANSLIDER_H
156 |
--------------------------------------------------------------------------------
/source/qxtspanslider_p.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) Qxt Foundation. Some rights reserved.
4 | **
5 | ** This file is part of the QxtGui module of the Qxt library.
6 | **
7 | ** This library is free software; you can redistribute it and/or modify it
8 | ** under the terms of the Common Public License, version 1.0, as published
9 | ** by IBM, and/or under the terms of the GNU Lesser General Public License,
10 | ** version 2.1, as published by the Free Software Foundation.
11 | **
12 | ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
13 | ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
14 | ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
15 | ** FITNESS FOR A PARTICULAR PURPOSE.
16 | **
17 | ** You should have received a copy of the CPL and the LGPL along with this
18 | ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
19 | ** included with the source distribution for more information.
20 | ** If you did not receive a copy of the licenses, contact the Qxt Foundation.
21 | **
22 | **
23 | **
24 | ****************************************************************************/
25 | // Modified by Graham Rowlands
26 | #ifndef QXTSPANSLIDER_P_H
27 | #define QXTSPANSLIDER_P_H
28 |
29 | #include
30 | #include
31 | #include "qxtspanslider.h"
32 |
33 | class QStylePainter;
34 | class QStyleOptionSlider;
35 |
36 | class QxtSpanSliderPrivate : public QObject, public QxtPrivate
37 | {
38 | Q_OBJECT
39 |
40 | public:
41 | QXT_DECLARE_PUBLIC(QxtSpanSlider)
42 |
43 | enum SpanHandle
44 | {
45 | NoHandle,
46 | LowerHandle,
47 | UpperHandle
48 | };
49 |
50 | QxtSpanSliderPrivate();
51 | void initStyleOption(QStyleOptionSlider* option, SpanHandle handle = UpperHandle) const;
52 | int pick(const QPoint& pt) const
53 | {
54 | return qxt_p().orientation() == Qt::Horizontal ? pt.x() : pt.y();
55 | }
56 | int pixelPosToRangeValue(int pos) const;
57 | void handleMousePress(const QPoint& pos, QStyle::SubControl& control, int value, SpanHandle handle);
58 | void drawHandle(QStylePainter* painter, SpanHandle handle) const;
59 | void setupPainter(QPainter* painter, Qt::Orientation orientation, qreal x1, qreal y1, qreal x2, qreal y2) const;
60 | void drawSpan(QStylePainter* painter, const QRect& rect) const;
61 | void triggerAction(QAbstractSlider::SliderAction action, bool main);
62 | void swapControls();
63 |
64 | int lower;
65 | int upper;
66 | int lowerPos;
67 | int upperPos;
68 | int offset;
69 | int position;
70 | SpanHandle lastPressed;
71 | SpanHandle mainControl;
72 | QStyle::SubControl lowerPressed;
73 | QStyle::SubControl upperPressed;
74 | QxtSpanSlider::HandleMovementMode movement;
75 | bool firstMovement;
76 | bool blockTracking;
77 | bool fixedInterval;
78 |
79 | public slots:
80 | void updateRange(int min, int max);
81 | void movePressedHandle();
82 | };
83 |
84 | #endif // QXTSPANSLIDER_P_H
85 |
--------------------------------------------------------------------------------
/source/resources.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | shaders/cube.frag
4 | shaders/cube.vert
5 | shaders/standard.frag
6 | shaders/standard.vert
7 | resources/splash.png
8 | resources/splash2.png
9 | resources/32x32/muview.png
10 | resources/64x64/muview.png
11 | resources/128x128/muview.png
12 | resources/256x256/muview.png
13 | resources/512x512/muview.png
14 | resources/16x16/muview.png
15 |
16 |
17 |
--------------------------------------------------------------------------------
/source/resources/128x128/muview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/128x128/muview.png
--------------------------------------------------------------------------------
/source/resources/16x16/muview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/16x16/muview.png
--------------------------------------------------------------------------------
/source/resources/256x256/muview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/256x256/muview.png
--------------------------------------------------------------------------------
/source/resources/32x32/muview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/32x32/muview.png
--------------------------------------------------------------------------------
/source/resources/512x512/muview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/512x512/muview.png
--------------------------------------------------------------------------------
/source/resources/64x64/muview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/64x64/muview.png
--------------------------------------------------------------------------------
/source/resources/muview.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=Muview Viewer
3 | Comment=Open OVF/OMF files
4 | TryExec=muview
5 | Icon=muview
6 | Exec=muview %U
7 | StartupNotify=true
8 | Terminal=false
9 | Type=Application
10 | Categories=Science;Qt;3DGraphics;Viewer;
11 |
--------------------------------------------------------------------------------
/source/resources/muview.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/muview.icns
--------------------------------------------------------------------------------
/source/resources/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/splash.png
--------------------------------------------------------------------------------
/source/resources/splash2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grahamrow/Muview2/f4a86ea2744bf95471a2a1cae626a3af94eb011e/source/resources/splash2.png
--------------------------------------------------------------------------------
/source/shaders/cube.frag:
--------------------------------------------------------------------------------
1 | #version 330
2 |
3 | in vec4 fragNormal;
4 | in vec4 fragVertex;
5 | in vec4 col;
6 | in vec4 trans;
7 | in mat4 mv;
8 | in vec3 nrm;
9 | out vec4 fragColor;
10 |
11 | mat4 model;
12 |
13 | uniform mat4 view;
14 | uniform float ambient;
15 | uniform struct Light {
16 | vec4 position;
17 | vec4 intensities; //a.k.a the color of the light
18 | } light;
19 |
20 | void main( void )
21 | {
22 | // Drop thresholded or clipped values as dictated by vertex shader
23 | if (col.w > 0.5)
24 | discard;
25 |
26 | //calculate the location of this fragment (pixel) in world coordinates
27 | vec3 fragPosition = mat3(mv) * vec3(fragVertex);
28 |
29 | //calculate the vector from this pixels surface to the light source
30 | vec3 surfaceToLight = vec3(light.position) - vec3(fragPosition);
31 |
32 | //calculate the cosine of the angle of incidence
33 | float brightness = dot(nrm, surfaceToLight) / (length(surfaceToLight) * length(nrm));
34 | brightness = clamp(brightness, 0, 1);
35 |
36 | // calculate final color of the pixel, based on:
37 | // 1. The angle of incidence: brightness
38 | // 2. The color/intensities of the light: light.intensities
39 | // 3. The texture and texture coord: texture(tex, fragTexCoord)
40 | fragColor = (ambient + brightness * light.intensities) * col;
41 | }
42 |
--------------------------------------------------------------------------------
/source/shaders/cube.vert:
--------------------------------------------------------------------------------
1 | #version 330
2 |
3 | const float PI = 3.1415926535897932384626433832795;
4 |
5 | layout(location = 0) in vec4 vertex;
6 | layout(location = 1) in vec4 vertexNormal;
7 | layout(location = 2) in vec4 magnetization;
8 | layout(location = 3) in vec4 translation;
9 |
10 | out vec4 fragVertex;
11 | out vec4 fragNormal;
12 | out vec4 col;
13 | out vec4 trans;
14 | out mat4 mv;
15 | out vec3 nrm;
16 |
17 | float mag, relmag, phi, theta;
18 |
19 | // Which quantity to use for coloration
20 | // 1 = Full Orientation, 2 = In-Plane Angle, 3 = X-component,
21 | // 4 = Y-Component, 5 = Z-Component
22 | uniform int display_type;
23 |
24 | // Color lookup table
25 | uniform int use_color_lut;
26 | uniform vec4 color_lut[256];
27 |
28 | // Dimensionality
29 | uniform int valuedim;
30 | uniform float scale;
31 |
32 | uniform mat4 view, projection;
33 | uniform vec3 com; // Center of mass
34 | uniform float maxmag, thresholdLow, thresholdHigh;
35 | uniform float xSliceLow, xSliceHigh, ySliceLow, ySliceHigh, zSliceLow, zSliceHigh;
36 |
37 | float atan2(in float y, in float x)
38 | {
39 | bool s = (abs(x) > abs(y));
40 | return mix(PI/2.0 - atan(x,y), atan(y,x), s);
41 | }
42 |
43 | float hue2rgb(float f1, float f2, float hue) {
44 | if (hue < 0.0)
45 | hue += 1.0;
46 | else if (hue > 1.0)
47 | hue -= 1.0;
48 | float res;
49 | if ((6.0 * hue) < 1.0)
50 | res = f1 + (f2 - f1) * 6.0 * hue;
51 | else if ((2.0 * hue) < 1.0)
52 | res = f2;
53 | else if ((3.0 * hue) < 2.0)
54 | res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
55 | else
56 | res = f1;
57 | return res;
58 | }
59 |
60 | vec3 hsl2rgb(vec3 hsl) {
61 | vec3 rgb;
62 |
63 | if (hsl.y == 0.0) {
64 | rgb = vec3(hsl.z); // Luminance
65 | } else {
66 | float f2;
67 |
68 | if (hsl.z < 0.5)
69 | f2 = hsl.z * (1.0 + hsl.y);
70 | else
71 | f2 = hsl.z + hsl.y - hsl.y * hsl.z;
72 |
73 | float f1 = 2.0 * hsl.z - f2;
74 |
75 | rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0));
76 | rgb.g = hue2rgb(f1, f2, hsl.x);
77 | rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0));
78 | }
79 | return rgb;
80 | }
81 |
82 |
83 | void main( void )
84 | {
85 | trans = translation;
86 |
87 | // mod_model = model;
88 | mat4 model = mat4(1.0);
89 | model[3][0] += 2.0*(translation.x-com.x);
90 | model[3][1] += 2.0*(translation.y-com.y);
91 | model[3][2] += 2.0*(translation.z-com.z);
92 |
93 | fragNormal = vertexNormal;
94 | fragVertex = vertex; // + translation;
95 |
96 | mag = length(magnetization);
97 | relmag = mag/maxmag;
98 | col = vec4(magnetization.x/mag, 0.0,0.0,0.0);
99 | theta = acos(magnetization.z/mag);
100 | phi = atan2(magnetization.y, magnetization.x);
101 |
102 | mat4 sc = mat4(mat3(scale));
103 | model = model * sc;
104 | mv = view * model;
105 |
106 | mat3 normalMatrix = transpose(inverse(mat3(mv)));
107 | nrm = normalize(normalMatrix * vec3(fragNormal));
108 |
109 | // In-plane angle coloring
110 | float hue = phi/(2.0*PI);
111 | float lum = 0.5;
112 |
113 | if (display_type == 1)
114 | lum = 0.5 + 0.5*magnetization.z/mag;
115 | if (display_type >= 3) // by component
116 | hue = 0.5 + 0.5*magnetization[display_type-3]/mag;
117 | if (use_color_lut == 0)
118 | col = vec4(hsl2rgb(vec3(hue, 1.0, lum)), 0.0);
119 | if (use_color_lut == 1)
120 | col = color_lut[int(255.0*hue)];
121 |
122 | // Discarded because of thresholding
123 | if (relmag < thresholdLow - 0.01)
124 | col.w = 1.0;
125 | if (relmag > thresholdHigh + 0.01)
126 | col.w = 1.0;
127 |
128 | // Discarded because of clipping
129 | if (translation.x < xSliceLow)
130 | col.w = 1.0;
131 | if (translation.x > xSliceHigh)
132 | col.w = 1.0;
133 | if (translation.y < ySliceLow)
134 | col.w = 1.0;
135 | if (translation.y > ySliceHigh)
136 | col.w = 1.0;
137 | if (translation.z < zSliceLow)
138 | col.w = 1.0;
139 | if (translation.z > zSliceHigh)
140 | col.w = 1.0;
141 |
142 | gl_Position = projection * view * model * vertex;
143 | }
144 |
--------------------------------------------------------------------------------
/source/shaders/standard.frag:
--------------------------------------------------------------------------------
1 | #version 330
2 |
3 | smooth in vec4 fragNormal;
4 | smooth in vec4 fragVertex;
5 | in vec4 col;
6 | in vec4 trans;
7 | in mat4 mv;
8 | smooth in vec3 nrm;
9 | out vec4 fragColor;
10 |
11 | mat4 model;
12 |
13 | uniform mat4 view;
14 | uniform float ambient;
15 | uniform struct Light {
16 | vec4 position;
17 | vec4 intensities; //a.k.a the color of the light
18 | } light;
19 |
20 | void main( void )
21 | {
22 | // Drop thresholded or clipped values as dictated by vertex shader
23 | if (col.w > 0.5)
24 | discard;
25 |
26 | //calculate the location of this fragment (pixel) in world coordinates
27 | vec3 fragPosition = mat3(mv) * vec3(fragVertex);
28 |
29 | //calculate the vector from this pixels surface to the light source
30 | vec3 surfaceToLight = vec3(light.position) - vec3(fragPosition);
31 |
32 | //calculate the cosine of the angle of incidence
33 | float brightness = dot(nrm, surfaceToLight) / (length(surfaceToLight) * length(nrm));
34 | brightness = clamp(brightness, 0, 1);
35 |
36 | // calculate final color of the pixel, based on:
37 | // 1. The angle of incidence: brightness
38 | // 2. The color/intensities of the light: light.intensities
39 | // 3. The texture and texture coord: texture(tex, fragTexCoord)
40 | fragColor = (ambient + brightness * light.intensities) * col;
41 | }
42 |
--------------------------------------------------------------------------------
/source/shaders/standard.vert:
--------------------------------------------------------------------------------
1 | #version 330
2 |
3 | const float PI = 3.1415926535897932384626433832795;
4 |
5 | layout(location = 0) in vec4 vertex;
6 | layout(location = 1) in vec4 vertexNormal;
7 | layout(location = 2) in vec4 magnetization;
8 | layout(location = 3) in vec4 translation;
9 |
10 | smooth out vec4 fragVertex;
11 | smooth out vec4 fragNormal;
12 | smooth out vec4 col;
13 | out vec4 trans;
14 | out mat4 mv;
15 | smooth out vec3 nrm;
16 |
17 | float mag, relmag, phi, theta;
18 |
19 | // Which quantity to use for coloration
20 | // 1 = Full Orientation, 2 = In-Plane Angle, 3 = X-component,
21 | // 4 = Y-Component, 5 = Z-Component
22 | uniform int display_type;
23 |
24 | // Color lookup table
25 | uniform int use_color_lut;
26 | uniform vec4 color_lut[256];
27 |
28 | // Dimensionality
29 | uniform int valuedim;
30 | uniform float scale;
31 |
32 | uniform mat4 view, projection;
33 | uniform vec3 com; // Center of mass
34 | uniform float maxmag, thresholdLow, thresholdHigh;
35 | uniform float xSliceLow, xSliceHigh, ySliceLow, ySliceHigh, zSliceLow, zSliceHigh;
36 |
37 | float atan2(in float y, in float x)
38 | {
39 | bool s = (abs(x) > abs(y));
40 | return mix(PI/2.0 - atan(x,y), atan(y,x), s);
41 | }
42 |
43 | float hue2rgb(float f1, float f2, float hue) {
44 | if (hue < 0.0)
45 | hue += 1.0;
46 | else if (hue > 1.0)
47 | hue -= 1.0;
48 | float res;
49 | if ((6.0 * hue) < 1.0)
50 | res = f1 + (f2 - f1) * 6.0 * hue;
51 | else if ((2.0 * hue) < 1.0)
52 | res = f2;
53 | else if ((3.0 * hue) < 2.0)
54 | res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
55 | else
56 | res = f1;
57 | return res;
58 | }
59 |
60 | vec3 hsl2rgb(vec3 hsl) {
61 | vec3 rgb;
62 |
63 | if (hsl.y == 0.0) {
64 | rgb = vec3(hsl.z); // Luminance
65 | } else {
66 | float f2;
67 |
68 | if (hsl.z < 0.5)
69 | f2 = hsl.z * (1.0 + hsl.y);
70 | else
71 | f2 = hsl.z + hsl.y - hsl.y * hsl.z;
72 |
73 | float f1 = 2.0 * hsl.z - f2;
74 |
75 | rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0));
76 | rgb.g = hue2rgb(f1, f2, hsl.x);
77 | rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0));
78 | }
79 | return rgb;
80 | }
81 |
82 |
83 | void main( void )
84 | {
85 | trans = translation;
86 |
87 | // mod_model = model;
88 | mat4 model = mat4(1.0);
89 | model[3][0] += 2.0*(translation.x-com.x);
90 | model[3][1] += 2.0*(translation.y-com.y);
91 | model[3][2] += 2.0*(translation.z-com.z);
92 |
93 | fragNormal = vertexNormal;
94 | fragVertex = vertex; // + translation;
95 |
96 | mag = length(magnetization);
97 | relmag = mag/maxmag;
98 | col = vec4(magnetization.x/mag, 0.0,0.0,0.0);
99 | theta = acos(magnetization.z/mag);
100 | phi = atan2(magnetization.y, magnetization.x);
101 |
102 | mat4 sc = mat4(mat3(scale));
103 |
104 | mat4 rot_theta = mat4(1.0);
105 | rot_theta[1][1] = rot_theta[2][2] = cos(theta);
106 | rot_theta[1][2] = rot_theta[2][1] = sin(theta);
107 | rot_theta[2][1] *= -1;
108 |
109 | mat4 rot_phi = mat4(1.0);
110 | rot_phi[0][0] = rot_phi[1][1] = cos(phi+0.5*PI);
111 | rot_phi[0][1] = rot_phi[1][0] = sin(phi+0.5*PI);
112 | rot_phi[1][0] *= -1;
113 |
114 | model = model * rot_phi * rot_theta * sc;
115 | mv = view * model;
116 |
117 | mat3 normalMatrix = transpose(inverse(mat3(mv)));
118 | nrm = normalize(normalMatrix * vec3(fragNormal));
119 |
120 | // In-plane angle coloring
121 | float hue = phi/(2.0*PI);
122 | float lum = 0.5;
123 |
124 | if (display_type == 1)
125 | lum = 0.5 + 0.5*magnetization.z/mag;
126 | if (display_type >= 3) // by component
127 | hue = 0.5 + 0.5*magnetization[display_type-3]/mag;
128 | if (use_color_lut == 0)
129 | col = vec4(hsl2rgb(vec3(hue, 1.0, lum)), 0.0);
130 | if (use_color_lut == 1)
131 | col = color_lut[int(255.0*hue)];
132 |
133 | // Discarded because of thresholding
134 | if (relmag < thresholdLow - 0.01)
135 | col.w = 1.0;
136 | if (relmag > thresholdHigh + 0.01)
137 | col.w = 1.0;
138 |
139 | // Discarded because of clipping
140 | if (translation.x < xSliceLow)
141 | col.w = 1.0;
142 | if (translation.x > xSliceHigh)
143 | col.w = 1.0;
144 | if (translation.y < ySliceLow)
145 | col.w = 1.0;
146 | if (translation.y > ySliceHigh)
147 | col.w = 1.0;
148 | if (translation.z < zSliceLow)
149 | col.w = 1.0;
150 | if (translation.z > zSliceHigh)
151 | col.w = 1.0;
152 |
153 | gl_Position = projection * view * model * vertex;
154 | }
155 |
--------------------------------------------------------------------------------
/source/source.pro:
--------------------------------------------------------------------------------
1 | QT += core gui widgets opengl
2 | TEMPLATE = app
3 | TARGET = ../muview
4 | INCLUDEPATH += $$top_srcdir
5 | UI_DIR = uics
6 | MOC_DIR = mocs
7 | OBJECTS_DIR = objs
8 | VERSION = 2.2
9 |
10 | CONFIG += release
11 |
12 | linux {
13 | #CONFIG += static
14 | message(Building in Linux Environment)
15 | message(" will install muview (binary) to /usr/local/bin")
16 | target.path = /usr/local/bin
17 |
18 | UNAME = $$system(uname -a)
19 |
20 | contains(UNAME, .*Ubuntu): UBUNTU = 1
21 |
22 | contains(UBUNTU, 1): {
23 | message("Ubuntu type distribution found:")
24 | message(" will install muview.desktop to /usr/share/applications")
25 | message(" will install icons to /usr/share/icons/hicolor/")
26 | desktopfile.path = /usr/share/applications
27 | desktopfile.files += resources/muview.desktop
28 | iconfile512.path = /usr/share/icons/hicolor/512x512/apps
29 | iconfile512.files = resources/512x512/muview.png
30 | iconfile256.path = /usr/share/icons/hicolor/256x256/apps
31 | iconfile256.files = resources/256x256/muview.png
32 | iconfile128.path = /usr/share/icons/hicolor/128x128/apps
33 | iconfile128.files = resources/128x128/muview.png
34 | iconfile64.path = /usr/share/icons/hicolor/64x64/apps
35 | iconfile64.files = resources/64x64/muview.png
36 | iconfile32.path = /usr/share/icons/hicolor/32x32/apps
37 | iconfile32.files = resources/32x32/muview.png
38 | iconfile16.path = /usr/share/icons/hicolor/16x16/apps
39 | iconfile16.files = resources/16x16/muview.png
40 |
41 | INSTALLS += desktopfile \
42 | iconfile512 iconfile256 iconfile128 \
43 | iconfile64 iconfile32 iconfile16
44 | }
45 |
46 | pixmap.path = /usr/share/pixmaps
47 | pixmap.files = resources/256x256/muview.png
48 |
49 | INSTALLS += target pixmap
50 | }
51 |
52 | macx {
53 | message(Building in Mac OSX Environment)
54 | message(" will install muview (app) to /Applications")
55 | QMAKE_MAC_SDK = macosx10.14
56 | QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14
57 | target.path = /Applications
58 |
59 |
60 | TARGET = ../Muview
61 | ICON = resources/muview.icns
62 | CONFIG += dead-strip
63 | INSTALLS += target
64 | }
65 |
66 | win32 {
67 | message(Building in Windows Environment)
68 | message(" will install muview (binary) to C:\\Program Files")
69 | target.path = "C:\\Program Files"
70 | LIBS += opengl32.lib
71 | INSTALLS += target
72 | }
73 |
74 | SOURCES += \
75 | matrix.cpp \
76 | main.cpp \
77 | window.cpp \
78 | glwidget.cpp \
79 | glwidget_input.cpp \
80 | glwidget_assets.cpp \
81 | qxtspanslider.cpp \
82 | preferences.cpp \
83 | aboutdialog.cpp \
84 | OMFImport.cpp
85 |
86 |
87 | HEADERS += \
88 | matrix.h \
89 | glwidget.h \
90 | qxtspanslider.h \
91 | qxtspanslider_p.h \
92 | preferences.h \
93 | aboutdialog.h \
94 | window.h \
95 | OMFEndian.h \
96 | OMFImport.h
97 |
98 | FORMS += \
99 | preferences.ui \
100 | window.ui \
101 | aboutdialog.ui
102 |
103 | OTHER_FILES += \
104 | shaders/cube.frag \
105 | shaders/cube.vert \
106 | shaders/standard.frag \
107 | shaders/standard.vert \
108 | resources/splash.png \
109 | resources/splash2.png \
110 | resources/muview.desktop \
111 | resources/512x512/muview.png \
112 | resources/256x256/muview.png \
113 | resources/128x128/muview.png \
114 | resources/64x64/muview.png \
115 | resources/32x32/muview.png \
116 | resources/16x16/muview.png \
117 |
118 | RESOURCES += \
119 | resources.qrc
120 |
--------------------------------------------------------------------------------
/source/window.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include "glwidget.h"
18 | #include "window.h"
19 | #include "ui_window.h"
20 | #include "ui_preferences.h"
21 | #include "qxtspanslider.h"
22 |
23 | #include "OMFImport.h"
24 | //#include "OMFHeader.h"
25 |
26 | struct OMFImport;
27 |
28 | Window::Window(QStringList arguments) :
29 | QMainWindow(NULL),
30 | ui(new Ui::Window)
31 | {
32 | QCommandLineParser parser;
33 | parser.setApplicationDescription("3D Viewer of OVF/OMF Micromagnetic Data");
34 | parser.addHelpOption();
35 | parser.addVersionOption();
36 |
37 | // General input
38 | parser.addPositionalArgument("input", QCoreApplication::translate("Files or Directories", "Input files to open."));
39 |
40 | // Watch files
41 | QCommandLineOption watchDirectoryOption(QStringList() << "w" << "watch",
42 | QCoreApplication::translate("main", "Watch and update when new data appears therein."),
43 | QCoreApplication::translate("main", "directory"));
44 | parser.addOption(watchDirectoryOption);
45 |
46 | // Actually parse the arguments
47 | parser.process(arguments);
48 | const QStringList fileargs = parser.positionalArguments();
49 | QString watchDir = parser.value(watchDirectoryOption);
50 |
51 | // Initialize GUI
52 | ui->setupUi(this);
53 |
54 | // Specify an OpenGL format using the Core profile.
55 | // That is, no old-school fixed pipeline functionality
56 | QGLFormat glFormat;
57 | #ifdef __APPLE__
58 | // This actually seems to yield a 4.1 context on Mavericks
59 | glFormat.setVersion(3, 2);
60 | #else
61 | glFormat.setVersion( 3, 3 );
62 | #endif
63 | glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0
64 | glFormat.setSampleBuffers( true );
65 |
66 | // Create a GLWidget requesting our format
67 | viewport = new GLWidget( glFormat );
68 | ui->viewportHorizontalLayout->insertWidget(1,viewport, 1);
69 |
70 | // Clipboard
71 | clipboard = QApplication::clipboard();
72 |
73 | // File defaults
74 | lastSavedLocation = QDir::home();
75 | lastOpenedLocation = QDir::home();
76 | watcher = new QFileSystemWatcher;
77 |
78 | // Cache size
79 | cacheSize = 25;
80 | cachePos = 0;
81 |
82 | // Sub-windows
83 | prefs = new Preferences(this);
84 | about = new AboutDialog(this);
85 |
86 | connect(prefs, SIGNAL(finished(int)), this, SLOT(updatePrefs()));
87 |
88 | initSlider(ui->xSlider);
89 | initSlider(ui->ySlider);
90 | initSlider(ui->zSlider);
91 | initSpanSlider(ui->xSpanSlider);
92 | initSpanSlider(ui->ySpanSlider);
93 | initSpanSlider(ui->zSpanSlider);
94 | initSpanSlider(ui->thresholdSlider);
95 |
96 | // Rotation
97 | connect(ui->xSlider, SIGNAL(valueChanged(int)), viewport, SLOT(setXRotation(int)));
98 | connect(viewport, SIGNAL(xRotationChanged(int)), ui->xSlider, SLOT(setValue(int)));
99 | connect(ui->ySlider, SIGNAL(valueChanged(int)), viewport, SLOT(setYRotation(int)));
100 | connect(viewport, SIGNAL(yRotationChanged(int)), ui->ySlider, SLOT(setValue(int)));
101 | connect(ui->zSlider, SIGNAL(valueChanged(int)), viewport, SLOT(setZRotation(int)));
102 | connect(viewport, SIGNAL(zRotationChanged(int)), ui->zSlider, SLOT(setValue(int)));
103 |
104 | // Slicing
105 | connect(ui->xSpanSlider, SIGNAL(lowerValueChanged(int)), viewport, SLOT(setXSliceLow(int)));
106 | connect(ui->xSpanSlider, SIGNAL(upperValueChanged(int)), viewport, SLOT(setXSliceHigh(int)));
107 | connect(ui->ySpanSlider, SIGNAL(lowerValueChanged(int)), viewport, SLOT(setYSliceLow(int)));
108 | connect(ui->ySpanSlider, SIGNAL(upperValueChanged(int)), viewport, SLOT(setYSliceHigh(int)));
109 | connect(ui->zSpanSlider, SIGNAL(lowerValueChanged(int)), viewport, SLOT(setZSliceLow(int)));
110 | connect(ui->zSpanSlider, SIGNAL(upperValueChanged(int)), viewport, SLOT(setZSliceHigh(int)));
111 | connect(ui->thresholdSlider, SIGNAL(lowerValueChanged(int)), viewport, SLOT(setThresholdLow(int)));
112 | connect(ui->thresholdSlider, SIGNAL(upperValueChanged(int)), viewport, SLOT(setThresholdHigh(int)));
113 |
114 | // Animation
115 | ui->animSlider->setEnabled(false);
116 |
117 | // Actions
118 | connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
119 | connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(openAbout()));
120 | connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(openSettings()));
121 | connect(ui->actionFiles, SIGNAL(triggered()), this, SLOT(openFiles()));
122 | connect(ui->actionDir, SIGNAL(triggered()), this, SLOT(openDir()));
123 | connect(ui->actionCopy, SIGNAL(triggered()), this, SLOT(copyImage()));
124 |
125 | connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveImage()));
126 | connect(ui->actionSequence, SIGNAL(triggered()), this, SLOT(saveImageSequence()));
127 |
128 | connect(ui->actionCubes, SIGNAL(triggered()), this, SLOT(toggleDisplay()));
129 | connect(ui->actionCones, SIGNAL(triggered()), this, SLOT(toggleDisplay()));
130 | connect(ui->actionVectors, SIGNAL(triggered()), this, SLOT(toggleDisplay()));
131 |
132 | connect(ui->actionIncreaseSubsampling, SIGNAL(triggered()), viewport, SLOT(increaseSubsampling()));
133 | connect(ui->actionDecreaseSubsampling, SIGNAL(triggered()), viewport, SLOT(decreaseSubsampling()));
134 |
135 | displayType = new QActionGroup(this);
136 | displayType->addAction(ui->actionCubes);
137 | displayType->addAction(ui->actionCones);
138 | displayType->addAction(ui->actionVectors);
139 | ui->actionCubes->setChecked(true);
140 |
141 | signalMapper = new QSignalMapper(this);
142 | signalMapper->setMapping (ui->actionFollow, "") ;
143 | connect (signalMapper, SIGNAL(mapped(QString)), this, SLOT(watch(QString))) ;
144 | connect(ui->actionFollow, SIGNAL(triggered()), signalMapper, SLOT(map()));
145 | connect(ui->actionUnfollow, SIGNAL(triggered()), this, SLOT(stopWatch()));
146 |
147 | ui->xSlider->setValue(345 * 1600);
148 | ui->ySlider->setValue(0 * 1600);
149 | ui->zSlider->setValue(0 * 1600);
150 | setWindowTitle(tr("MuView 2.2"));
151 |
152 | // Data, don't connect until we are ready (probably still not ready here)...
153 | connect(ui->animSlider, SIGNAL(valueChanged(int)), this, SLOT(updateDisplayData(int)));
154 |
155 | // Watching a directory, if that is requested
156 | if (watchDir != "") {
157 | watch(watchDir);
158 | }
159 |
160 | // Otherwise we load files and directories
161 | if (watchDir == "" && fileargs.length() > 0) {
162 | foreach (QString item, fileargs) {
163 | QFileInfo info(item);
164 | if (!info.exists()) {
165 | qDebug() << "File " << item << " does not exist";
166 | } else {
167 | // Push our new content...
168 | if (info.isDir()) {
169 | QDir chosenDir(item);
170 | dirString = chosenDir.path()+"/";
171 | QStringList filters;
172 | filters << "*.omf" << "*.ovf";
173 | chosenDir.setNameFilters(filters);
174 | QStringList files = chosenDir.entryList();
175 |
176 | foreach (QString file, files)
177 | {
178 | filenames << (dirString+file);
179 | displayNames << (dirString+file);
180 | }
181 |
182 | } else {
183 | // just a normal file
184 | filenames << (dirString+item);
185 | displayNames << (dirString+item);
186 | }
187 | }
188 | }
189 | if (filenames.length() > 0) {
190 | processFilenames();
191 | gotoFrontOfCache();
192 | adjustAnimSlider(false); // Refresh the animation bar
193 | } else {
194 | ui->statusbar->showMessage(QString("No omf or ovf filers"));
195 | qDebug() << "No omf or ovf filers found.";
196 | }
197 | }
198 |
199 | // This seems to solve the strange issue of the QGLwidget not filling its container...
200 | viewport->setFixedSize(QSize(800,600));
201 | this->adjustSize();
202 | viewport->setFixedSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
203 |
204 | // Set preferences
205 | updatePrefs();
206 | }
207 |
208 | void Window::initSpanSlider(QxtSpanSlider *slider)
209 | {
210 | slider->setRange(0 *16, 100 * 16);
211 | slider->setSingleStep(16);
212 | slider->setPageStep(15 * 16);
213 | slider->setTickInterval(15 * 16);
214 | slider->setTickPosition(QSlider::TicksRight);
215 | slider->setHandleMovementMode(QxtSpanSlider::NoOverlapping);
216 | slider->setLowerValue(0*16);
217 | slider->setUpperValue(100*16);
218 | }
219 |
220 | void Window::initSlider(QSlider *slider)
221 | {
222 | slider->setRange(0, 360 * 1600);
223 | slider->setSingleStep(1600);
224 | slider->setPageStep(15 * 1600);
225 | slider->setTickInterval(15 * 1600);
226 | slider->setTickPosition(QSlider::TicksRight);
227 | slider->setValue(0);
228 | }
229 |
230 | void Window::adjustAnimSlider(bool back)
231 | {
232 | int numFiles = filenames.size();
233 | if (numFiles > 1) {
234 | ui->animSlider->setRange(0, numFiles-1);
235 | ui->animSlider->setSingleStep(1);
236 | ui->animSlider->setPageStep(10);
237 | ui->animSlider->setTickInterval( numFiles < 20 ? numFiles : numFiles/20);
238 | ui->animSlider->setTickPosition(QSlider::TicksRight);
239 | ui->animSlider->setEnabled(true);
240 | if (back) {
241 | ui->animSlider->setSliderPosition(numFiles-1);
242 | } else {
243 | ui->animSlider->setSliderPosition(0);
244 | }
245 | } else {
246 | ui->animSlider->setEnabled(false);
247 | }
248 | }
249 |
250 | void Window::keyPressEvent(QKeyEvent *e)
251 | {
252 | QWidget::keyPressEvent(e);
253 | }
254 |
255 | void Window::updatePrefs() {
256 | viewport->setBackgroundColor(prefs->getBackgroundColor());
257 | viewport->setSpriteDimensions(prefs->getSpriteResolution(), prefs->getVectorLength(), prefs->getVectorRadius(),
258 | prefs->getVectorTipToTail(), prefs->getVectorInnerToOuter(), prefs->getVectorOrigin());
259 | viewport->setBrightness(prefs->getBrightness());
260 | if (prefs->getImageDimensions() == QSize(-1,-1)) {
261 | viewport->setFixedSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
262 | } else {
263 | viewport->setFixedSize(prefs->getImageDimensions());
264 | this->adjustSize();
265 | }
266 | viewport->setColoredQuantity(prefs->getColorQuantity());
267 | viewport->setColorScale(prefs->getColorScale());
268 | viewport->setSpriteScale(prefs->getSpriteScale());
269 | viewport->setCustomColorScale(prefs->getCustomColorScale());
270 | }
271 |
272 | void Window::openSettings()
273 | {
274 | prefs->exec();
275 | }
276 |
277 | void Window::openAbout()
278 | {
279 | about->exec();
280 | }
281 |
282 | void Window::processFilenames() {
283 | // Looping over files
284 | for (int loadPos=0; loadPos omf = readOMF(filenames[loadPos]);
287 | if (omf.isNull()) {
288 | qDebug() << "Error loading file " << filenames[loadPos] << ", skipping...";
289 | }
290 | omfCache.push_back(omf);
291 | }
292 | cachePos = 0;
293 | }
294 |
295 | void Window::gotoFrontOfCache() {
296 | ui->statusbar->showMessage(filenames.front());
297 | viewport->updateData(omfCache.front());
298 | cachePos = 0;
299 | adjustAnimSlider(false); // Go to end of slider
300 | }
301 |
302 | void Window::gotoBackOfCache() {
303 | ui->statusbar->showMessage(filenames.back());
304 | viewport->updateData(omfCache.back());
305 | cachePos = filenames.size()-1;
306 | adjustAnimSlider(true); // Go to start of slider
307 | }
308 |
309 | void Window::clearCaches() {
310 | while (!omfCache.empty()) {
311 | omfCache.pop_back();
312 | }
313 | }
314 |
315 | void Window::openFiles()
316 | {
317 | QStringList names;
318 | names = QFileDialog::getOpenFileNames(this,
319 | tr("Open File"), lastOpenedLocation.path(),
320 | tr("OVF Files (*.omf *.ovf)"));
321 |
322 | if (names.length() > 0)
323 | {
324 | lastOpenedLocation = QDir(names.at(0));
325 | filenames.clear();
326 | foreach(QString name, names) {
327 | if (name != "") {
328 | filenames.push_back(name);
329 | displayNames.push_back(name);
330 | }
331 | }
332 | clearCaches();
333 | processFilenames();
334 | gotoFrontOfCache();
335 | }
336 | }
337 |
338 | void Window::updateWatchedFiles() {
339 | // Look at all of the files in the directory
340 | // and add those which are not in the list of
341 | // original filenames
342 |
343 | // filenames contains the list of loaded files
344 | // watchedFiles is a map of files to load and their modification timestamps
345 |
346 | // When the timestamps in wathcedFiles stop changing we actually
347 | // push the relevant files into the OMF cache.
348 |
349 | QDir chosenDir(watchedDir);
350 | QString dirString = chosenDir.path()+"/";
351 | QStringList filters;
352 | filters << "*.omf" << "*.ovf";
353 | chosenDir.setNameFilters(filters);
354 | QStringList dirFiles = chosenDir.entryList();
355 |
356 | // compare to existing list of files
357 | bool changed = false;
358 | foreach(QString dirFile, dirFiles)
359 | {
360 | if (!filenames.contains(dirString + dirFile)) {
361 | // Haven't been loaded
362 | QString fullPath = dirString + dirFile;
363 | QFileInfo info(fullPath);
364 |
365 | if (!watchedFiles.contains(fullPath)) {
366 | // Not on the watch list yet
367 | watchedFiles.insert(fullPath, info.lastModified());
368 | // Callback this method to see if the file is done changing!
369 | QTimer::singleShot(100, this, SLOT(updateWatchedFiles()));
370 | } else {
371 | // on the watch list
372 | if (info.lastModified() == watchedFiles[fullPath]) {
373 | // File size has stabalized
374 | filenames.append(fullPath);
375 | displayNames.append(dirFile);
376 | changed = true;
377 | } else {
378 | // File still changing
379 | watchedFiles[fullPath] = info.lastModified();
380 | // Callback this method to see if the file is done changing!
381 | QTimer::singleShot(100, this, SLOT(updateWatchedFiles()));
382 | }
383 | }
384 | }
385 | }
386 |
387 | if (changed) {
388 | clearCaches(); // Blank slate
389 | QSharedPointer omf = readOMF(filenames.last());
390 | if (omf.isNull()) {
391 | qDebug() << "Error loading file " << filenames.last() << ", skipping...";
392 | }
393 | omfCache.push_back(omf);
394 | gotoBackOfCache();
395 | }
396 |
397 | }
398 |
399 | void Window::updateDisplayData(int index)
400 | {
401 | // Check to see if we've cached this data already.
402 | // Add and remove elements from the front and back
403 | // of the deque until we've caught up... if we're
404 | // too far out of range just scratch everything and
405 | // reload.
406 | if ( abs(index-cachePos) >= cacheSize ) {
407 | // Out of the realm of caching: clear the cache of pre-existing elements
408 | clearCaches();
409 | cachePos = index;
410 | for (int loadPos=index; loadPos<(index+cacheSize) && loadPos omfdata = readOMF(filenames[loadPos]);
413 | if (omfdata.isNull()) {
414 | qDebug() << "Error loading file " << filenames[loadPos] << ", skipping...";
415 | }
416 | omfCache.push_back(omfdata);
417 | }
418 | cachePos = index;
419 | } else if ( index < cachePos ) {
420 | // Moving backwards, regroup for fast scrubbing!
421 | for (int loadPos=cachePos-1; loadPos >= index && loadPos omfdata = readOMF(filenames[loadPos]);
427 | if (omfdata.isNull()) {
428 | qDebug() << "Error loading file " << filenames[loadPos] << ", skipping...";
429 | }
430 | omfCache.push_front(omfdata);
431 | }
432 | cachePos = index;
433 | }
434 |
435 | // We are within the current cache
436 | if (index < filenames.size()) {
437 | if (omfCache.at(index-cachePos).isNull()) {
438 | ui->statusbar->showMessage("File " + displayNames[index] + " was not understood by Muview and is being skipped.");
439 | } else {
440 | ui->statusbar->showMessage(displayNames[index]);
441 | // Update the Display
442 | viewport->updateData(omfCache.at(index-cachePos));
443 | }
444 | } else {
445 | ui->statusbar->showMessage(QString("Don't scroll so erratically..."));
446 | }
447 | }
448 |
449 | void Window::openDir()
450 | {
451 | QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
452 | lastOpenedLocation.path(),
453 | QFileDialog::ShowDirsOnly
454 | | QFileDialog::DontResolveSymlinks);
455 |
456 | if (dir != "")
457 | {
458 | QDir chosenDir(dir);
459 | lastOpenedLocation = chosenDir;
460 | dirString = chosenDir.path()+"/";
461 | QStringList filters;
462 | filters << "*.omf" << "*.ovf";
463 | chosenDir.setNameFilters(filters);
464 | QStringList dirFiles = chosenDir.entryList();
465 | if (dirFiles.length() == 0) {
466 | qDebug() << "No .omf or .ovf files were found in the specified directory.";
467 | ui->statusbar->showMessage("No .omf or .ovf files were found in the specified directory.");
468 | } else {
469 | filenames.clear();
470 | foreach (QString file, dirFiles) {
471 | filenames.push_back(dirString + file);
472 | }
473 |
474 | // persistent storage of filenames for top overlay
475 | displayNames = dirFiles;
476 |
477 | clearCaches();
478 | processFilenames();
479 | gotoFrontOfCache();
480 | }
481 | }
482 | }
483 |
484 | void Window::saveImageFile(QString name)
485 | {
486 | if (name != "") {
487 | lastSavedLocation = QDir(name);
488 | QImage screen = viewport->grabFrameBuffer();
489 | screen.save(name, 0, 90); //format was (prefs->getFormat()).toStdString().c_str()
490 | }
491 | }
492 |
493 | void Window::copyImage()
494 | {
495 | QImage screen = viewport->grabFrameBuffer();
496 | clipboard->setImage(screen);
497 | }
498 |
499 | void Window::saveImage()
500 | {
501 | QString fileName, filter;
502 | QString format = prefs->getFormat();
503 | if (format == "JPG") {
504 | filter = tr("JPEG Images (*.jpg)");
505 | } else {
506 | filter = tr("PNG Images (*.png)");
507 | }
508 | fileName = QFileDialog::getSaveFileName(this, tr("Save Image"), lastSavedLocation.path(), tr("JPEG Images (*.jpg);;PNG Images (*.png)"), &filter);
509 | saveImageFile(fileName);
510 | }
511 |
512 | void Window::saveImageSequence()
513 | {
514 | QString dir = QFileDialog::getExistingDirectory(this, tr("Save Sequence to Directory"),
515 | lastSavedLocation.path(),
516 | QFileDialog::ShowDirsOnly
517 | | QFileDialog::DontResolveSymlinks);
518 |
519 | if (dir != "")
520 | {
521 | connect(viewport, SIGNAL(doneRenderingFrame(QString)), this, SLOT(saveImageFile(QString)));
522 |
523 | lastSavedLocation = QDir(dir);
524 | QImage screen;
525 | QString number;
526 | QString format = (prefs->getFormat()).toLower();
527 | QString outpath;
528 | for (int i=0; ianimSlider->setValue(i);
531 | outpath = dir+"/muviewSequence"+number+"."+format;
532 | ui->statusbar->showMessage("Saving file "+outpath);
533 | update();
534 | viewport->renderFrame(outpath);
535 | }
536 |
537 | disconnect(viewport, SIGNAL(doneRenderingFrame(QString)), this, SLOT(saveImageFile(QString)));
538 | }
539 | }
540 |
541 | void Window::watch(const QString& str)
542 | {
543 | QString dir;
544 | // Don't show a dialog if we get this message from the command line
545 | if (str == "") {
546 | dir = QFileDialog::getExistingDirectory(this, tr("Watch Directory"),
547 | lastOpenedLocation.path(),
548 | QFileDialog::ShowDirsOnly
549 | | QFileDialog::DontResolveSymlinks);
550 | } else {
551 | dir = str;
552 | }
553 |
554 | if (filenames.length() > 0) {
555 | filenames.clear();
556 | displayNames.clear();
557 | }
558 | clearCaches();
559 |
560 | cachePos = 0; // reset position to beginning
561 |
562 | if (dir != "")
563 | {
564 | // Added the dir to the watch list
565 | if (watcher->directories().length() > 0) {
566 | watcher->removePaths(watcher->directories());
567 | }
568 | watcher->addPath(dir);
569 | watchedDir = dir;
570 |
571 | // Now read all of the current files
572 | QDir chosenDir(dir);
573 | lastOpenedLocation = chosenDir;
574 | QString dirString = chosenDir.path()+"/";
575 | QStringList filters;
576 | filters << "*.omf" << "*.ovf";
577 | chosenDir.setNameFilters(filters);
578 | QStringList dirFiles = chosenDir.entryList();
579 |
580 | if (dirFiles.length() == 0) {
581 | qDebug() << "No .omf or .ovf files were found in the specified directory. Waiting for input.";
582 | ui->statusbar->showMessage("No .omf or .ovf files were found in the specified directory. Waiting for input.");
583 | } else {
584 | // persistent storage of filenames for status bar
585 | displayNames = dirFiles;
586 | filenames.clear();
587 | foreach (QString file, dirFiles) {
588 | filenames.push_back(dirString + file);
589 | }
590 |
591 | processFilenames();
592 | gotoBackOfCache();
593 | }
594 |
595 | connect(watcher, SIGNAL(directoryChanged(QString)),
596 | this, SLOT(updateWatchedFiles()));
597 | }
598 |
599 | }
600 |
601 | void Window::stopWatch()
602 | {
603 | if (watcher->directories().length() > 0) {
604 | watcher->removePaths(watcher->directories());
605 | disconnect(watcher, SIGNAL(directoryChanged(QString)),
606 | this, SLOT(updateWatchedFiles(QString)));
607 | }
608 | }
609 |
610 | void Window::toggleDisplay() {
611 | if (ui->actionCubes->isChecked()) {
612 | viewport->toggleDisplay(0);
613 | } else if (ui->actionCones->isChecked()) {
614 | viewport->toggleDisplay(1);
615 | } else {
616 | viewport->toggleDisplay(2);
617 | }
618 | }
619 |
620 | Window::~Window()
621 | {
622 | delete ui;
623 | }
624 |
625 |
--------------------------------------------------------------------------------
/source/window.h:
--------------------------------------------------------------------------------
1 | #ifndef WINDOW_H
2 | #define WINDOW_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | // Other parts of the interface
14 | #include "preferences.h"
15 | #include "aboutdialog.h"
16 | #include "glwidget.h"
17 |
18 | // For reading OMF files
19 | #include "matrix.h"
20 |
21 | // Forward Declarations
22 | class QSlider;
23 | class QxtSpanSlider;
24 | class QSignalMapper;
25 | class QGLFunctions;
26 | class QActionGroup;
27 | class QFileSystemWatcher;
28 |
29 | namespace Ui {
30 | class Window;
31 | }
32 |
33 | class Window : public QMainWindow
34 | {
35 | Q_OBJECT
36 |
37 | public:
38 | explicit Window(QStringList arguments);
39 | ~Window();
40 | QSize sizeHint();
41 | protected:
42 | void keyPressEvent( QKeyEvent* e );
43 |
44 | private slots:
45 | void openFiles();
46 | void openDir();
47 | void saveImage();
48 | void saveImageSequence();
49 | void saveImageFile(QString name);
50 | void copyImage();
51 | void watch(const QString& str);
52 | void stopWatch();
53 | void toggleDisplay();
54 | void updateWatchedFiles();
55 | void openSettings();
56 | void openAbout();
57 | void updateDisplayData(int index);
58 | void updatePrefs();
59 |
60 | private:
61 | Ui::Window *ui;
62 | GLWidget *viewport;
63 | QActionGroup *displayType;
64 | Preferences *prefs;
65 | AboutDialog *about;
66 | QClipboard *clipboard;
67 |
68 | // Convenience Functions for Sliders
69 | void initSlider(QSlider *slider);
70 | void initSpanSlider(QxtSpanSlider *slider);
71 | void adjustAnimSlider(bool back);
72 |
73 | // ============================================================
74 | // Storage and caching:
75 | //
76 | // A finite number of files, as governed by cacheSize, will
77 | // reside in memory at a given time, otherwise we will choke
78 | // the system on large output directories.
79 | // ============================================================
80 |
81 | int cacheSize; // Maxmimum cache size
82 | int cachePos; // Current location w.r.t list of all filenames
83 |
84 | void clearCaches();
85 | void gotoBackOfCache();
86 | void gotoFrontOfCache();
87 | void processFilenames();
88 |
89 | QVector > omfCache;
90 | QStringList filenames;
91 | QStringList displayNames;
92 |
93 | QString dirString;
94 | QDir lastSavedLocation;
95 | QDir lastOpenedLocation;
96 |
97 | // Watch dirs
98 | QSignalMapper* signalMapper;
99 | QFileSystemWatcher *watcher;
100 | QMap watchedFiles;
101 | QString watchedDir;
102 | bool noFollowUpdate;
103 |
104 | };
105 |
106 | #endif
107 |
--------------------------------------------------------------------------------
/source/window.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Window
4 |
5 |
6 |
7 | 0
8 | 0
9 | 964
10 | 607
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | :/resources/32x32/muview.png:/resources/32x32/muview.png
19 |
20 |
21 |
22 | -
23 |
24 |
-
25 |
26 |
-
27 |
28 |
29 | Rotation
30 |
31 |
32 | Qt::AlignCenter
33 |
34 |
35 |
36 | -
37 |
38 |
-
39 |
40 |
41 | Qt::Vertical
42 |
43 |
44 |
45 | -
46 |
47 |
48 | Qt::Vertical
49 |
50 |
51 |
52 | -
53 |
54 |
55 | Qt::Vertical
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | -
64 |
65 |
-
66 |
67 |
68 | Slicing
69 |
70 |
71 | Qt::AlignCenter
72 |
73 |
74 |
75 | -
76 |
77 |
-
78 |
79 |
80 | Qt::Vertical
81 |
82 |
83 |
84 | -
85 |
86 |
87 | Qt::Vertical
88 |
89 |
90 |
91 | -
92 |
93 |
94 | Qt::Vertical
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | -
103 |
104 |
-
105 |
106 |
107 | Threshold
108 |
109 |
110 | Qt::AlignCenter
111 |
112 |
113 |
114 | -
115 |
116 |
-
117 |
118 |
119 | Qt::Vertical
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 | -
130 |
131 |
-
132 |
133 |
134 | Animation Timeline (scrub through files)
135 |
136 |
137 | Qt::AlignCenter
138 |
139 |
140 |
141 | -
142 |
143 |
144 | Qt::Horizontal
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
207 |
208 |
209 |
210 | Open File(s)
211 |
212 |
213 | Ctrl+O
214 |
215 |
216 |
217 |
218 | Open Dir
219 |
220 |
221 | Ctrl+Shift+O
222 |
223 |
224 |
225 |
226 | Follow Dir
227 |
228 |
229 | Ctrl+F
230 |
231 |
232 |
233 |
234 | Unfollow Dir
235 |
236 |
237 | Ctrl+Shift+F
238 |
239 |
240 |
241 |
242 | Quit
243 |
244 |
245 | Ctrl+Q
246 |
247 |
248 |
249 |
250 | Muview Preferences
251 |
252 |
253 | Ctrl+I
254 |
255 |
256 |
257 |
258 | true
259 |
260 |
261 | Display Cubes
262 |
263 |
264 | Ctrl+1
265 |
266 |
267 |
268 |
269 | true
270 |
271 |
272 | Display Cones
273 |
274 |
275 | Ctrl+2
276 |
277 |
278 |
279 |
280 | true
281 |
282 |
283 | Display Vectors
284 |
285 |
286 | Ctrl+3
287 |
288 |
289 |
290 |
291 | About Muview
292 |
293 |
294 |
295 |
296 | false
297 |
298 |
299 | Online Help
300 |
301 |
302 |
303 |
304 | Save Image
305 |
306 |
307 | Ctrl+S
308 |
309 |
310 |
311 |
312 | Save Image Sequence
313 |
314 |
315 | Ctrl+Shift+S
316 |
317 |
318 |
319 |
320 | Copy Image
321 |
322 |
323 | Ctrl+C
324 |
325 |
326 |
327 |
328 | Increase Subsampling
329 |
330 |
331 | Ctrl+=
332 |
333 |
334 |
335 |
336 | Decrease Subsampling
337 |
338 |
339 | Ctrl+-
340 |
341 |
342 |
343 |
344 |
345 | QxtSpanSlider
346 | QSlider
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
--------------------------------------------------------------------------------