ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
VP1SoMaterialMixer::Imp Class Reference
Collaboration diagram for VP1SoMaterialMixer::Imp:

Public Member Functions

void setMaterialFieldsAsAverageOfMatList (SoMaterial *mat, const std::set< SoMaterial * > &matlist)
 
void setMaterialFieldsAsAverageOfMatList (SoMaterial *mat, const std::map< SoMaterial *, double > &matlist)
 
void monitorMaterial (SoMaterial *)
 
void materialChanged (SoMaterial *)
 
SoMaterial * defaultMaterial ()
 

Static Public Member Functions

static float norm (const float &x)
 
static void materialChangedCB (void *data, SoSensor *)
 
static bool inputMaterialValid (SoMaterial *)
 

Public Attributes

VP1SoMaterialMixertheclass
 
SoMaterial * defmat
 
std::map< std::set< SoMaterial * >, SoMaterial * > matlists2mixedmats
 
std::map< std::map< SoMaterial *, double >, SoMaterial * > matlists2mixedmats_weighted
 
std::map< SoMaterial *, SoNodeSensor * > mat2sensors
 

Static Public Attributes

static std::map< SoSensor *, VP1SoMaterialMixer::Imp * > sensor2matmixerimp
 

Detailed Description

Definition at line 18 of file VP1SoMaterialMixer.cxx.

Member Function Documentation

◆ defaultMaterial()

SoMaterial* VP1SoMaterialMixer::Imp::defaultMaterial ( )
inline

Definition at line 34 of file VP1SoMaterialMixer.cxx.

35  {
36  if (!defmat) {
37  defmat = new SoMaterial;
38  defmat->ref();
39  }
40  return defmat;
41  }

◆ inputMaterialValid()

bool VP1SoMaterialMixer::Imp::inputMaterialValid ( SoMaterial *  m)
static

Definition at line 118 of file VP1SoMaterialMixer.cxx.

119 {
120  return m
121  && m->ambientColor.getNum() == 1
122  && m->diffuseColor.getNum() == 1
123  && m->specularColor.getNum() == 1
124  && m->emissiveColor.getNum() == 1
125  && m->transparency.getNum() == 1
126  && m->shininess.getNum() == 1;
127 
128 }

◆ materialChanged()

void VP1SoMaterialMixer::Imp::materialChanged ( SoMaterial *  mat)

Definition at line 160 of file VP1SoMaterialMixer.cxx.

161 {
162  //First look in lists for un-weighted mixtures:
163  std::map<std::set<SoMaterial*>,SoMaterial*>::const_iterator it, itE = matlists2mixedmats.end();
164  for (it = matlists2mixedmats.begin();it!=itE;++it) {
165  std::set<SoMaterial*>::iterator it2(it->first.begin()),it2E(it->first.end());
166  for (;it2!=it2E;++it2) {
167  if (mat==*it2) {
168  setMaterialFieldsAsAverageOfMatList(it->second,it->first);
169  break;
170  }
171  }
172  }
173  //Then look in lists for weighted mixtures:
174  std::map<std::map<SoMaterial*,double>,SoMaterial*>::const_iterator it3, it3E = matlists2mixedmats_weighted.end();
175  for (it3 = matlists2mixedmats_weighted.begin();it3!=it3E;++it3) {
176  std::map<SoMaterial*,double>::const_iterator it4(it3->first.begin()),it4E(it3->first.end());
177  for (;it4!=it4E;++it4) {
178  if (mat==it4->first) {
179  setMaterialFieldsAsAverageOfMatList(it3->second,it3->first);
180  break;
181  }
182  }
183  }
184 
185 }

◆ materialChangedCB()

void VP1SoMaterialMixer::Imp::materialChangedCB ( void *  data,
SoSensor *  sensor 
)
static

Definition at line 131 of file VP1SoMaterialMixer.cxx.

132 {
133  SoMaterial *material = (SoMaterial *)data;
134  if (!inputMaterialValid(material)) {
135  VP1Msg::message("ERROR: Monitored material changed to invalid state"
136  " (multiple values in a field). Ignore changes.");
137  return;
138  }
139 
141  if (it!=sensor2matmixerimp.end())
142  it->second->materialChanged(material);
143 }

◆ monitorMaterial()

void VP1SoMaterialMixer::Imp::monitorMaterial ( SoMaterial *  mat)

Definition at line 146 of file VP1SoMaterialMixer.cxx.

147 {
148  if (mat2sensors.find(mat)!=mat2sensors.end())
149  return;//We already monitor this material.
150 
151  SoNodeSensor * sensor = new SoNodeSensor(Imp::materialChangedCB, mat);
152  sensor->attach(mat);
153  sensor2matmixerimp[sensor] = this;
154  mat2sensors[mat]=sensor;
155  mat->ref();
156 
157 }

◆ norm()

static float VP1SoMaterialMixer::Imp::norm ( const float &  x)
inlinestatic

Definition at line 23 of file VP1SoMaterialMixer.cxx.

23 { return (x<0.0f?0.0f:(x>1.0f?1.0f:x));}

◆ setMaterialFieldsAsAverageOfMatList() [1/2]

void VP1SoMaterialMixer::Imp::setMaterialFieldsAsAverageOfMatList ( SoMaterial *  mat,
const std::map< SoMaterial *, double > &  matlist 
)

Definition at line 228 of file VP1SoMaterialMixer.cxx.

229 {
230  float w, totweight(0.0f);
231  float ambient_r(0.0f), ambient_g(0.0f), ambient_b(0.0f);
232  float diffuse_r(0.0f), diffuse_g(0.0f), diffuse_b(0.0f);
233  float specular_r(0.0f), specular_g(0.0f), specular_b(0.0f);
234  float emissive_r(0.0f), emissive_g(0.0f), emissive_b(0.0f);
235  float shininess(0.0f), transparency(0.0f);
236  float r,g,b;
237  std::map<SoMaterial*,double>::const_iterator it(matlist.begin()), itE(matlist.end());
238  SoMaterial * m;
239  for (;it!=itE;++it) {
240  m = it->first;
241  w = it->second;
242  totweight += w;
243  m->ambientColor[0].getValue(r,g,b); ambient_r += w*r; ambient_g += w*g; ambient_b += w*b;
244  m->diffuseColor[0].getValue(r,g,b); diffuse_r += w*r; diffuse_g += w*g; diffuse_b += w*b;
245  m->specularColor[0].getValue(r,g,b); specular_r += w*r; specular_g += w*g; specular_b += w*b;
246  m->emissiveColor[0].getValue(r,g,b); emissive_r += w*r; emissive_g += w*g; emissive_b += w*b;
247  shininess += m->shininess[0]*w;
248  transparency += m->transparency[0]*w;
249  }
250 
251  float n = 1.0f/totweight;
252  bool save = mat->enableNotify(false);
253  mat->ambientColor.setValue(norm(n*ambient_r),norm(n*ambient_g),norm(n*ambient_b));
254  mat->diffuseColor.setValue(norm(n*diffuse_r),norm(n*diffuse_g),norm(n*diffuse_b));
255  mat->specularColor.setValue(norm(n*specular_r),norm(n*specular_g),norm(n*specular_b));
256  mat->emissiveColor.setValue(norm(n*emissive_r),norm(n*emissive_g),norm(n*emissive_b));
257  mat->shininess.setValue(norm(n*shininess));
258  mat->transparency.setValue(norm(n*transparency));
259  if (save) {
260  mat->enableNotify(true);
261  mat->touch();
262  if (VP1Msg::verbose()){
263  theclass->messageVerbose("Material ("+str(mat)+") updated and touched");
264  }
265  } else {
266  if (VP1Msg::verbose()){
267  theclass->messageVerbose("Material ("+str(mat)+") updated but notifications were off");
268  }
269  }
270 }

◆ setMaterialFieldsAsAverageOfMatList() [2/2]

void VP1SoMaterialMixer::Imp::setMaterialFieldsAsAverageOfMatList ( SoMaterial *  mat,
const std::set< SoMaterial * > &  matlist 
)

Definition at line 188 of file VP1SoMaterialMixer.cxx.

189 {
190  float ambient_r(0.0f), ambient_g(0.0f), ambient_b(0.0f);
191  float diffuse_r(0.0f), diffuse_g(0.0f), diffuse_b(0.0f);
192  float specular_r(0.0f), specular_g(0.0f), specular_b(0.0f);
193  float emissive_r(0.0f), emissive_g(0.0f), emissive_b(0.0f);
194  float shininess(0.0f), transparency(0.0f);
195  float r,g,b;
196  std::set<SoMaterial*>::const_iterator it(matlist.begin()), itE(matlist.end());
197  for (;it!=itE;++it) {
198  (*it)->ambientColor[0].getValue(r,g,b); ambient_r += r; ambient_g += g; ambient_b += b;
199  (*it)->diffuseColor[0].getValue(r,g,b); diffuse_r += r; diffuse_g += g; diffuse_b += b;
200  (*it)->specularColor[0].getValue(r,g,b); specular_r += r; specular_g += g; specular_b += b;
201  (*it)->emissiveColor[0].getValue(r,g,b); emissive_r += r; emissive_g += g; emissive_b += b;
202  shininess += (*it)->shininess[0];
203  transparency += (*it)->transparency[0];
204  }
205 
206  float n = 1.0f/matlist.size();
207  bool save = mat->enableNotify(false);
208  mat->ambientColor.setValue(norm(n*ambient_r),norm(n*ambient_g),norm(n*ambient_b));
209  mat->diffuseColor.setValue(norm(n*diffuse_r),norm(n*diffuse_g),norm(n*diffuse_b));
210  mat->specularColor.setValue(norm(n*specular_r),norm(n*specular_g),norm(n*specular_b));
211  mat->emissiveColor.setValue(norm(n*emissive_r),norm(n*emissive_g),norm(n*emissive_b));
212  mat->shininess.setValue(norm(n*shininess));
213  mat->transparency.setValue(norm(n*transparency));
214  if (save) {
215  mat->enableNotify(true);
216  mat->touch();
217  if (VP1Msg::verbose()){
218  theclass->messageVerbose("Material ("+str(mat)+") updated and touched");
219  }
220  } else {
221  if (VP1Msg::verbose()){
222  theclass->messageVerbose("Material ("+str(mat)+") updated but notifications were off");
223  }
224  }
225 }

Member Data Documentation

◆ defmat

SoMaterial* VP1SoMaterialMixer::Imp::defmat

Definition at line 33 of file VP1SoMaterialMixer.cxx.

◆ mat2sensors

std::map<SoMaterial*,SoNodeSensor*> VP1SoMaterialMixer::Imp::mat2sensors

Definition at line 46 of file VP1SoMaterialMixer.cxx.

◆ matlists2mixedmats

std::map<std::set<SoMaterial*>,SoMaterial*> VP1SoMaterialMixer::Imp::matlists2mixedmats

Definition at line 44 of file VP1SoMaterialMixer.cxx.

◆ matlists2mixedmats_weighted

std::map<std::map<SoMaterial*,double>,SoMaterial*> VP1SoMaterialMixer::Imp::matlists2mixedmats_weighted

Definition at line 45 of file VP1SoMaterialMixer.cxx.

◆ sensor2matmixerimp

std::map< SoSensor *, VP1SoMaterialMixer::Imp * > VP1SoMaterialMixer::Imp::sensor2matmixerimp
static

Definition at line 27 of file VP1SoMaterialMixer.cxx.

◆ theclass

VP1SoMaterialMixer* VP1SoMaterialMixer::Imp::theclass

Definition at line 20 of file VP1SoMaterialMixer.cxx.


The documentation for this class was generated from the following file:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
skel.it
it
Definition: skel.GENtoEVGEN.py:396
VP1SoMaterialMixer::Imp::materialChangedCB
static void materialChangedCB(void *data, SoSensor *)
Definition: VP1SoMaterialMixer.cxx:131
VP1SoMaterialMixer::Imp::setMaterialFieldsAsAverageOfMatList
void setMaterialFieldsAsAverageOfMatList(SoMaterial *mat, const std::set< SoMaterial * > &matlist)
Definition: VP1SoMaterialMixer.cxx:188
x
#define x
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
TruthTest.itE
itE
Definition: TruthTest.py:25
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
VP1SoMaterialMixer::Imp::matlists2mixedmats_weighted
std::map< std::map< SoMaterial *, double >, SoMaterial * > matlists2mixedmats_weighted
Definition: VP1SoMaterialMixer.cxx:45
beamspotman.n
n
Definition: beamspotman.py:731
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
VP1SoMaterialMixer::Imp::matlists2mixedmats
std::map< std::set< SoMaterial * >, SoMaterial * > matlists2mixedmats
Definition: VP1SoMaterialMixer.cxx:44
hist_file_dump.f
f
Definition: hist_file_dump.py:135
VP1SoMaterialMixer::Imp::mat2sensors
std::map< SoMaterial *, SoNodeSensor * > mat2sensors
Definition: VP1SoMaterialMixer.cxx:46
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1SoMaterialMixer::Imp::norm
static float norm(const float &x)
Definition: VP1SoMaterialMixer.cxx:23
VP1SoMaterialMixer::Imp::defmat
SoMaterial * defmat
Definition: VP1SoMaterialMixer.cxx:33
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition: VP1Msg.cxx:30
VP1SoMaterialMixer::Imp::inputMaterialValid
static bool inputMaterialValid(SoMaterial *)
Definition: VP1SoMaterialMixer.cxx:118
VP1SoMaterialMixer::Imp::sensor2matmixerimp
static std::map< SoSensor *, VP1SoMaterialMixer::Imp * > sensor2matmixerimp
Definition: VP1SoMaterialMixer.cxx:27
VP1SoMaterialMixer::Imp::theclass
VP1SoMaterialMixer * theclass
Definition: VP1SoMaterialMixer.cxx:20
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200