MorphoGraphX
Misc.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef MISC_H
12 #define MISC_H
13 
18 #include <Config.hpp>
19 #include <GL.hpp>
20 
21 #include <Color.hpp>
22 #include <EdgeData.hpp>
23 #include <MGXViewer/qglviewer.h>
24 #include <Vector.hpp>
25 #include <VertexData.hpp>
26 #include <VVGraph.hpp>
27 
28 #include <QDir>
29 #include <QList>
30 #include <QtGui>
31 
32 namespace mgx {
33 
34 static const QString UM(QString::fromWCharArray(L"\xb5m")); // um
35 static const QString UM2(QString::fromWCharArray(L"\xb5m\xb2")); // um^2
36 static const QString UM3(QString::fromWCharArray(L"\xb5m\xb3")); // um^3
37 static const QString UM_1(QString::fromWCharArray(L"\xb5m\x207B\xb9")); // um^-1
38 static const QString UM_2(QString::fromWCharArray(L"\xb5m\x207B\xb2")); // um^-2
39 
40 #ifdef _MSC_VER
41 template class mgx_EXPORT graph::Vertex<VertexData>;
42 template class mgx_EXPORT graph::Edge<EdgeData>;
43 template class mgx_EXPORT graph::VVGraph<VertexData, EdgeData>;
44 #endif
45 
46 // Type of the VV graph
47 typedef graph::VVGraph<VertexData, EdgeData> vvgraph;
48 
49 // Type of a vertex
50 typedef vvgraph::vertex_t vertex;
51 
52 // Type of an edge
53 typedef vvgraph::edge_t edge;
54 
56 typedef util::Vector<2, int> Point2i;
57 typedef util::Vector<3, GLuint> Point3GLui;
58 typedef util::Vector<4, GLuint> Point4GLui;
59 typedef util::Vector<3, GLubyte> Point3GLub;
60 typedef util::Vector<4, GLubyte> Point4GLub;
61 typedef util::Color<float> Colorf;
62 typedef util::Vector<3, float> Point3f;
63 
64 namespace util {
66 mgx_EXPORT QDir resourcesDir();
68 mgx_EXPORT QDir userProcessesDir();
70 mgx_EXPORT QList<QDir> processesDirs();
72 mgx_EXPORT QDir libsDir();
74 mgx_EXPORT QDir includesDir();
76 mgx_EXPORT QDir docsDir();
77 
79 inline Point3GLub vMapColor(uint u)
80 {
81  u++;
82  return (Point3GLub(u / (256 * 256), u / 256 % 256, u % 256));
83 }
84 
86 inline uint vMapColor(Point3GLub& p) {
87  return ((int(p.x()) * 256 * 256 + int(p.y()) * 256 + int(p.z())) - 1);
88 }
89 
92 {
93  s.replace("\\", "\\\\");
94  s.replace(" ", "\\s");
95  s.replace("\n", "\\n");
96  s.replace("\t", "\\t");
97  s.replace("\"", "\\\"");
98  s.replace("\'", "\\\'");
99  return s;
100 }
101 
104 {
105  s.replace("\\\'", "\'");
106  s.replace("\\\"", "\"");
107  s.replace("\\s", " ");
108  s.replace("\\n", "\n");
109  s.replace("\\t", "\t");
110  s.replace("\\\\", "\\");
111  return s;
112 }
113 
116 {
117  s.replace("\\", "\\\\");
118  s.replace("\n", "\\n");
119  s.replace("\t", "\\t");
120  s.replace("\"", "\\\"");
121  s.replace("\'", "\\\'");
122  return s;
123 }
124 
127 {
128  s.replace("\\\'", "\'");
129  s.replace("\\\"", "\"");
130  s.replace("\\n", "\n");
131  s.replace("\\t", "\t");
132  s.replace("\\\\", "\\");
133  return s;
134 }
135 
136 } // namespace util
137 } // namespace mgx
138 #endif
fromWCharArray(const wchar_t *string, int size=-1)
This file contains the definition of a vertex.
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:661
QString shield_python(QString s)
Shield a string to send it to the python interpreter.
Definition: Misc.hpp:115
replace(int position, int n, const QString &after)
Point3GLub vMapColor(uint u)
Map unique colors to indices.
Definition: Misc.hpp:79
mgx_EXPORT QDir resourcesDir()
Returns resource directory.
graph::VVGraph< VertexData, EdgeData > vvgraph
Type of the VV graph holding the actual mesh.
Definition: Mesh.hpp:46
This file contains the definition of an edge data.
vvgraph::vertex_t vertex
Type of a vertex.
Definition: Mesh.hpp:49
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:670
mgx_EXPORT QDir docsDir()
Returns the documentation directory.
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
QString shield(QString s)
Create representation of a string that can be written in a single line, without spaces.
Definition: Misc.hpp:91
Edge< EdgeData > edge_t
Weak pointer on an edge.
Definition: VVGraph.hpp:91
mgx_EXPORT QDir libsDir()
Returns the libraries directory.
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:679
mgx_EXPORT QList< QDir > processesDirs()
Returns processes directory.
mgx_EXPORT QDir includesDir()
Returns the includes directory.
mgx_EXPORT QDir userProcessesDir()
Returns user processes directory.
QString unshield_python(QString s)
Retrieve a string that is retrieved from the python representation.
Definition: Misc.hpp:126
Contain the definition of the VVGraph template class.
QString unshield(QString s)
Retrieve a string that has been shielded with shield.
Definition: Misc.hpp:103
Defines the Color class template.
vvgraph::edge_t edge
Type of an edge.
Definition: Mesh.hpp:52
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can&#39;t...