ATLAS Offline Software
Loading...
Searching...
No Matches
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) {
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}
std::map< std::map< SoMaterial *, double >, SoMaterial * > matlists2mixedmats_weighted
std::map< std::set< SoMaterial * >, SoMaterial * > matlists2mixedmats
void setMaterialFieldsAsAverageOfMatList(SoMaterial *mat, const std::set< SoMaterial * > &matlist)

◆ 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
140 std::map<SoSensor*,VP1SoMaterialMixer::Imp*>::iterator it = sensor2matmixerimp.find(sensor);
141 if (it!=sensor2matmixerimp.end())
142 it->second->materialChanged(material);
143}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
static std::map< SoSensor *, VP1SoMaterialMixer::Imp * > sensor2matmixerimp
static bool inputMaterialValid(SoMaterial *)

◆ 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}
static void materialChangedCB(void *data, SoSensor *)
std::map< SoMaterial *, SoNodeSensor * > mat2sensors

◆ norm()

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));}
#define 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{};
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 if (totweight==0){
251 VP1Msg::message("ERROR: denominator is zero; setting to 1");
252 totweight = 1.f;
253 }
254 float n = 1.0f/totweight;
255 bool save = mat->enableNotify(false);
256 mat->ambientColor.setValue(norm(n*ambient_r),norm(n*ambient_g),norm(n*ambient_b));
257 mat->diffuseColor.setValue(norm(n*diffuse_r),norm(n*diffuse_g),norm(n*diffuse_b));
258 mat->specularColor.setValue(norm(n*specular_r),norm(n*specular_g),norm(n*specular_b));
259 mat->emissiveColor.setValue(norm(n*emissive_r),norm(n*emissive_g),norm(n*emissive_b));
260 mat->shininess.setValue(norm(n*shininess));
261 mat->transparency.setValue(norm(n*transparency));
262 if (save) {
263 mat->enableNotify(true);
264 mat->touch();
265 if (VP1Msg::verbose()){
266 theclass->messageVerbose("Material ("+str(mat)+") updated and touched");
267 }
268 } else {
269 if (VP1Msg::verbose()){
270 theclass->messageVerbose("Material ("+str(mat)+") updated but notifications were off");
271 }
272 }
273}
static bool verbose()
Definition VP1Msg.h:31
static float norm(const float &x)
VP1SoMaterialMixer * theclass
int r
Definition globals.cxx:22

◆ 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: