Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GeoModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GeoModelDev
GeoModel
Commits
4b5ef279
Commit
4b5ef279
authored
5 years ago
by
Riccardo Maria Bianchi
Browse files
Options
Downloads
Patches
Plain Diff
Add the install path to the search for visualization attributes JSON files
parent
4b3c2e8f
No related branches found
No related tags found
1 merge request
!1
New CMake setup, with 'switches', for the new monorepo
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GeoModelVisualization/VP1GeometrySystems/src/VisAttributes.cxx
+121
-47
121 additions, 47 deletions
...delVisualization/VP1GeometrySystems/src/VisAttributes.cxx
with
121 additions
and
47 deletions
GeoModelVisualization/VP1GeometrySystems/src/VisAttributes.cxx
+
121
−
47
View file @
4b5ef279
/*
Copyright (C) 2002-20
19
CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-20
20
CERN for the benefit of the ATLAS collaboration
*/
// local includes
#include
"VP1GeometrySystems/VisAttributes.h"
#include
"VP1Base/VP1QtInventorUtils.h"
// Coin3D includes
#include
<Inventor/nodes/SoMaterial.h>
#include
<iostream>
// Qt includes
#include
<QBuffer>
// nlohmann_json includes
#include
"nlohmann/json.hpp"
// C++ includes
#include
<iostream>
#include
<fstream>
#include
<iomanip>
#include
<unistd.h>
#include
<sys/types.h>
#include
<pwd.h>
#include
<map>
// utility functions to get preprocessor variables' values
#define STR_VALUE(arg) #arg
#define STR_NAME(name) STR_VALUE(name)
using
namespace
nlohmann
;
#include
"nlohmann/json.hpp"
/////////////////////////////////////// Base class ///////////////////////////////////////
#include
<map>
#include
<iostream>
using
namespace
nlohmann
;
namespace
GeoModelVis
{
struct
Triplet
{
double
R
;
double
G
;
double
B
;
};
struct
Material
{
std
::
vector
<
std
::
string
>
name
;
Triplet
diffuse
;
...
...
@@ -42,7 +54,7 @@ namespace GeoModelVis {
void
to_json
(
json
&
j
,
const
Triplet
&
t
)
{
j
=
json
{{
"R"
,
t
.
R
},{
"G"
,
t
.
G
},{
"B"
,
t
.
B
}};
}
void
to_json
(
json
&
j
,
const
Material
&
m
)
{
j
=
json
{{
"name"
,
m
.
name
},
{
"diffuse"
,
m
.
diffuse
},
...
...
@@ -90,8 +102,8 @@ void VisAttributes::init()
//
// This block of code is now skipped. It was originally used to generate
// json files from memory. I keep it here in case it is ever needed.
// This block of code is now skipped. It was originally used to generate
// json files from memory. I keep it here in case it is ever needed.
//
if
(
0
)
{
std
::
vector
<
json
>
jlist
;
...
...
@@ -119,13 +131,13 @@ void VisAttributes::init()
jlist
.
push_back
(
jMat
);
}
static
int
i
=
0
;
json
jReport
=
{{
"DetVisAttributes"
,
jlist
}};
std
::
ofstream
outJsonFile
(
"/tmp/visReport"
+
std
::
to_string
(
i
++
)
+
".json"
);
outJsonFile
<<
std
::
setw
(
4
)
<<
jReport
<<
std
::
endl
;
outJsonFile
.
close
();
}
// End of disabled part.
// End of disabled part.
}
...
...
@@ -246,26 +258,49 @@ void VisAttributes::overrideTransparencies(float transpfact)
DetVisAttributes
::
DetVisAttributes
()
{
//
// We look for: ${GXSHAREDIR}/gmexDetVisAttributes, or
// `pwd`, or
// ~/.gmexDetVisAttributes, or
// /usr/local/share/gmex/gmexDetVisAttributes, or
// /usr/share/gmex/gmexDetVisAttributes.
// TODO: document this!!
// We look for `gmexDetVisAttributes.json` in these folder and in this order:
// 1) ${GXSHAREDIR}/gmexDetVisAttributes.json
// 2) `pwd`
// 3) ~/.gmexDetVisAttributes.json (hiden file inside the user's home folder)
// 4) ${GEOMODEL_INSTALL_PREFIX}/share/gmex/gmexDetVisAttributes.json
// 5) /usr/local/share/gmex/gmexDetVisAttributes.json
// 6) /usr/share/gmex/gmexDetVisAttributes.json
//
#ifdef __APPLE__
char
buffer
[
1024
];
char
*
wdLocation
=
getcwd
(
buffer
,
1024
);
#else
char
*
wdLocation
=
get_current_dir_name
();
#endif
// struct passwd *pw = getpwuid(getuid());
// std::string homedir = pw->pw_dir;
// std::vector<std::string> locations={homedir+"/.","/usr/local/share/gmex/", "/usr/share/gmex/"};
// char * gxShareDir=getenv("GXSHAREDIR");
// if (wdLocation) locations.insert(locations.begin(), wdLocation+std::string("/"));
// if (gxShareDir) locations.insert(locations.begin(), gxShareDir+std::string("/"));
// TODO: this snippet could go in one single place and used from all three places
struct
passwd
*
pw
=
getpwuid
(
getuid
());
std
::
string
homedir
=
pw
->
pw_dir
;
std
::
vector
<
std
::
string
>
locations
=
{
homedir
+
"/."
,
"/usr/local/share/gmex/"
,
"/usr/share/gmex/"
};
// Init with case 3)
std
::
vector
<
std
::
string
>
locations
=
{
homedir
+
"/."
};
char
*
gxShareDir
=
getenv
(
"GXSHAREDIR"
);
// Add 2)
if
(
wdLocation
)
locations
.
insert
(
locations
.
begin
(),
wdLocation
+
std
::
string
(
"/"
));
// Add 1)
if
(
gxShareDir
)
locations
.
insert
(
locations
.
begin
(),
gxShareDir
+
std
::
string
(
"/"
));
// Add 4)
const
char
*
installPath
=
STR_NAME
(
GEOMODEL_INSTALL_PREFIX
);
std
::
string
installedShare
=
installPath
+
std
::
string
(
"/share/gmex/"
);
locations
.
push_back
(
installedShare
);
// Add 5) and 6)
locations
.
push_back
(
"/usr/local/share/gmex/"
);
locations
.
push_back
(
"/usr/share/gmex/"
);
for
(
const
std
::
string
&
s
:
locations
)
{
std
::
string
userFile
=
s
+
std
::
string
(
"gmexDetVisAttributes.json"
);
...
...
@@ -288,10 +323,10 @@ DetVisAttributes::DetVisAttributes() {
break
;
}
}
init
();
}
//////////////////////////////// Attributes for materials ////////////////////////////////
...
...
@@ -308,20 +343,36 @@ MatVisAttributes::MatVisAttributes() {
#else
char
*
wdLocation
=
get_current_dir_name
();
#endif
//
// We look for: ${GXSHAREDIR}/gmexMatVisAttributes, or,
// `pwd`, or
// ~/.gmexMatVisAttributes, or
// /usr/local/share/gmex/gmexMatVisAttributes, or
// /usr/share/gmex/gmexMatVisAttributes.
// TODO: document this!!
// We look for `gmexMatVisAttributes.json` in these folder and in this order:
// 1) ${GXSHAREDIR}/gmexMatVisAttributes.json
// 2) `pwd`
// 3) ~/.gmexMatVisAttributes.json (hiden file inside the user's home folder)
// 4) ${GEOMODEL_INSTALL_PREFIX}/share/gmex/gmexMatVisAttributes.json
// 5) /usr/local/share/gmex/gmexMatVisAttributes.json
// 6) /usr/share/gmex/gmexMatVisAttributes.json
//
// TODO: this snippet could go in one single place and used from all three places
struct
passwd
*
pw
=
getpwuid
(
getuid
());
std
::
string
homedir
=
pw
->
pw_dir
;
std
::
vector
<
std
::
string
>
locations
=
{
homedir
+
"/."
,
"/usr/local/share/gmex/"
,
"/usr/share/gmex/"
};
// Init with case 3)
std
::
vector
<
std
::
string
>
locations
=
{
homedir
+
"/."
};
char
*
gxShareDir
=
getenv
(
"GXSHAREDIR"
);
// Add 2)
if
(
wdLocation
)
locations
.
insert
(
locations
.
begin
(),
wdLocation
+
std
::
string
(
"/"
));
// Add 1)
if
(
gxShareDir
)
locations
.
insert
(
locations
.
begin
(),
gxShareDir
+
std
::
string
(
"/"
));
// Add 4)
const
char
*
installPath
=
STR_NAME
(
GEOMODEL_INSTALL_PREFIX
);
std
::
string
installedShare
=
installPath
+
std
::
string
(
"/share/gmex/"
);
locations
.
push_back
(
installedShare
);
// Add 5) and 6)
locations
.
push_back
(
"/usr/local/share/gmex/"
);
locations
.
push_back
(
"/usr/share/gmex/"
);
for
(
const
std
::
string
&
s
:
locations
)
{
std
::
string
userFile
=
s
+
std
::
string
(
"gmexMatVisAttributes.json"
);
if
(
access
(
userFile
.
c_str
(),
R_OK
)
==
0
)
{
...
...
@@ -329,16 +380,16 @@ MatVisAttributes::MatVisAttributes() {
std
::
ifstream
in
(
userFile
);
auto
j
=
json
::
parse
(
in
);
for
(
const
json
&
element
:
j
[
"MatVisAttributes"
])
{
GeoModelVis
::
Material
mat
;
GeoModelVis
::
from_json
(
element
,
mat
);
SoMaterial
*
m
=
new
SoMaterial
;
m
->
ambientColor
.
setValue
(
mat
.
ambient
.
R
,
mat
.
ambient
.
G
,
mat
.
ambient
.
B
);
m
->
diffuseColor
.
setValue
(
mat
.
diffuse
.
R
,
mat
.
diffuse
.
G
,
mat
.
diffuse
.
B
);
m
->
specularColor
.
setValue
(
mat
.
specular
.
R
,
mat
.
specular
.
G
,
mat
.
specular
.
B
);
m
->
emissiveColor
.
setValue
(
mat
.
emissive
.
R
,
mat
.
emissive
.
G
,
mat
.
emissive
.
B
);
m
->
shininess
.
setValue
(
mat
.
shininess
);
m
->
transparency
.
setValue
(
mat
.
transparency
);
for
(
const
std
::
string
&
s
:
mat
.
name
)
add
(
s
,
m
);
GeoModelVis
::
Material
mat
;
GeoModelVis
::
from_json
(
element
,
mat
);
SoMaterial
*
m
=
new
SoMaterial
;
m
->
ambientColor
.
setValue
(
mat
.
ambient
.
R
,
mat
.
ambient
.
G
,
mat
.
ambient
.
B
);
m
->
diffuseColor
.
setValue
(
mat
.
diffuse
.
R
,
mat
.
diffuse
.
G
,
mat
.
diffuse
.
B
);
m
->
specularColor
.
setValue
(
mat
.
specular
.
R
,
mat
.
specular
.
G
,
mat
.
specular
.
B
);
m
->
emissiveColor
.
setValue
(
mat
.
emissive
.
R
,
mat
.
emissive
.
G
,
mat
.
emissive
.
B
);
m
->
shininess
.
setValue
(
mat
.
shininess
);
m
->
transparency
.
setValue
(
mat
.
transparency
);
for
(
const
std
::
string
&
s
:
mat
.
name
)
add
(
s
,
m
);
}
break
;
}
...
...
@@ -353,11 +404,14 @@ MatVisAttributes::MatVisAttributes() {
VolVisAttributes
::
VolVisAttributes
()
{
//
// We look for: ${GXSHAREDIR}/gmexVolVisAttributes, or
// `pwd`, or
// ~/.gmexVolVisAttributes, or
// /usr/local/share/gmex/gmexVolVisAttributes, or
// /usr/share/gmex/gmexVolVisAttributes.
// TODO: document this!!
// We look for `gmexMatVisAttributes.json` in these folder and in this order:
// 1) ${GXSHAREDIR}/gmexVolVisAttributes.json
// 2) `pwd`
// 3) ~/.gmexVolVisAttributes.json (hiden file inside the user's home folder)
// 4) ${GEOMODEL_INSTALL_PREFIX}/share/gmex/gmexVolVisAttributes.json
// 5) /usr/local/share/gmex/gmexVolVisAttributes.json
// 6) /usr/share/gmex/gmexVolVisAttributes.json
//
#ifdef __APPLE__
char
buffer
[
1024
];
...
...
@@ -365,13 +419,33 @@ VolVisAttributes::VolVisAttributes() {
#else
char
*
wdLocation
=
get_current_dir_name
();
#endif
// struct passwd *pw = getpwuid(getuid());
// std::string homedir = pw->pw_dir;
// std::vector<std::string> locations= {homedir+"/.","/usr/local/share/gmex/", "/usr/share/gmex/"};
// char * gxShareDir=getenv("GXSHAREDIR");
// if (wdLocation) locations.insert(locations.begin(), wdLocation+std::string("/"));
// if (gxShareDir) locations.insert(locations.begin(), gxShareDir+std::string("/"));
// TODO: this snippet could go in one single place and used from all three places
struct
passwd
*
pw
=
getpwuid
(
getuid
());
std
::
string
homedir
=
pw
->
pw_dir
;
std
::
vector
<
std
::
string
>
locations
=
{
homedir
+
"/."
,
"/usr/local/share/gmex/"
,
"/usr/share/gmex/"
};
// Init with case 3)
std
::
vector
<
std
::
string
>
locations
=
{
homedir
+
"/."
};
char
*
gxShareDir
=
getenv
(
"GXSHAREDIR"
);
// Add 2)
if
(
wdLocation
)
locations
.
insert
(
locations
.
begin
(),
wdLocation
+
std
::
string
(
"/"
));
// Add 1)
if
(
gxShareDir
)
locations
.
insert
(
locations
.
begin
(),
gxShareDir
+
std
::
string
(
"/"
));
// Add 4)
const
char
*
installPath
=
STR_NAME
(
GEOMODEL_INSTALL_PREFIX
);
std
::
string
installedShare
=
installPath
+
std
::
string
(
"/share/gmex/"
);
locations
.
push_back
(
installedShare
);
// Add 5) and 6)
locations
.
push_back
(
"/usr/local/share/gmex/"
);
locations
.
push_back
(
"/usr/share/gmex/"
);
for
(
const
std
::
string
&
s
:
locations
)
{
std
::
string
userFile
=
s
+
std
::
string
(
"gmexVolVisAttributes.json"
);
if
(
access
(
userFile
.
c_str
(),
R_OK
)
==
0
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment