| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

MagneticFieldType Class Reference

#include <Types.h>

Collaboration diagram for MagneticFieldType:

[legend]
List of all members.

Public Member Functions

virtual std::string name () const
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual Lib::IIterator * iterator ()
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual Lib::Variable value (Lib::Identifier, const std::string &, void *)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual void visualize (Lib::Identifier, void *)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 MagneticFieldType (IUserInterfaceSvc *, IMagneticFieldSvc *)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Private Attributes

std::string fName
IUserInterfaceSvcfUISvc
IMagneticFieldSvcfMagneticFieldSvc

Detailed Description

Definition at line 26 of file Types.h.


Constructor & Destructor Documentation

MagneticFieldType::MagneticFieldType ( IUserInterfaceSvc ,
IMagneticFieldSvc  
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 121 of file Types.cpp.

00125 :OnX::BaseType(aUISvc->printer())
00126 ,fName("MagneticField")
00127 ,fUISvc(aUISvc)
00128 ,fMagneticFieldSvc(aMagneticFieldSvc)
00131 {
00132   addProperty("id",Lib::Property::POINTER);
00133 }


Member Function Documentation

std::string MagneticFieldType::name (  )  const [virtual]

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 135 of file Types.cpp.

00138 {
00139   return fName;
00140 }

Lib::IIterator * MagneticFieldType::iterator (  )  [virtual]

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 142 of file Types.cpp.

00146 {
00147   // One shoot only iterator.
00148   class Iterator : public Lib::IIterator {
00149   public: //Lib::IIterator
00150     virtual Lib::Identifier object() { return fMagneticFieldSvc; }
00151     virtual void* tag() { return 0; }
00152     virtual void next() {fMagneticFieldSvc = 0;}
00153   public:
00154     Iterator(IMagneticFieldSvc* aMagneticFieldSvc)
00155       :fMagneticFieldSvc(aMagneticFieldSvc){}
00156   private:
00157     IMagneticFieldSvc* fMagneticFieldSvc;
00158   };
00159 
00160   return new Iterator(fMagneticFieldSvc);
00161 }

Lib::Variable MagneticFieldType::value ( Lib::Identifier  ,
const std::string &  ,
void *   
) [virtual]

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 163 of file Types.cpp.

00170 {
00171   if(aName=="id") {
00172     return Lib::Variable(printer(),(void*)aIdentifier);
00173   } else {
00174     return Lib::Variable(printer());
00175   }
00176 }

void MagneticFieldType::visualize ( Lib::Identifier  ,
void *   
) [virtual]

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 178 of file Types.cpp.

00190 {
00191   if(!fMagneticFieldSvc) return;
00192   if(!fUISvc) return;
00193   if(!fUISvc->session()) return;
00194   ISession& session = *(fUISvc->session());
00195 
00196   SoRegion* soRegion = fUISvc->currentSoRegion();
00197   if(!soRegion) return;
00198 
00199   std::string value;
00200   double dvalue,d1,d2,d3;
00201   std::vector<double> ds;
00202   std::vector<int> ls;
00203 
00204   // Default values :
00205   float sx = 100;  // Size of a cell in x.
00206   float sy = 100;  // Size of a cell in y.
00207   unsigned int nx = 80; // Number of cell in x.
00208   unsigned int ny = 80; // Number of cell in y.
00209   SbVec3f gridStart(-(sx * nx)/2,-(sy * ny)/2,1000);
00210   SbVec3f gridX(1,0,0);
00211   SbVec3f gridY(0,1,0);
00212   float fieldMin = 0.0001F; // Below that, field is colored in grey.
00213   float fieldMax = 0.003F;
00214   float colorMin = 0.3F; // Color for fieldMin.
00215   float colorMax = 1;    // Color for fieldMax.
00216   float hr = 1, hg = 1, hb = 1;
00217   float transparency = 0;
00218 
00219   if(session.parameterValue("modeling.magneticField.gridPosition",value))
00220     if(Lib::smanip::todoubles(value,ds) && (ds.size()==3) ) {
00221       gridStart.setValue((float)ds[0],(float)ds[1],(float)ds[2]);
00222     }
00223   if(session.parameterValue("modeling.magneticField.gridX",value)) 
00224     if(Lib::smanip::todoubles(value,ds) && (ds.size()==3) ) {
00225       gridX.setValue((float)ds[0],(float)ds[1],(float)ds[2]);
00226     }
00227   if(session.parameterValue("modeling.magneticField.gridY",value))
00228     if(Lib::smanip::todoubles(value,ds) && (ds.size()==3) ) {
00229       gridY.setValue((float)ds[0],(float)ds[1],(float)ds[2]);
00230     }
00231   if(session.parameterValue("modeling.magneticField.gridCells",value))
00232     if(Lib::smanip::toints(value,ls) && (ls.size()==2) ) {
00233       nx = ls[0];
00234       ny = ls[1];
00235     }
00236   if(session.parameterValue("modeling.magneticField.gridCellSize",value))
00237     if(Lib::smanip::todoubles(value,ds) && (ds.size()==2) ) {
00238       sx = (float)ds[0];
00239       sy = (float)ds[1];
00240     }
00241   if(session.parameterValue("modeling.magneticField.min",value))
00242     if(Lib::smanip::todouble(value,dvalue)) fieldMin = (float)dvalue;
00243   if(session.parameterValue("modeling.magneticField.max",value))
00244     if(Lib::smanip::todouble(value,dvalue)) fieldMax = (float)dvalue;
00245   if(session.parameterValue("modeling.magneticField.colorMin",value))
00246     if(Lib::smanip::todouble(value,dvalue)) colorMin = (float)dvalue;
00247   if(session.parameterValue("modeling.magneticField.colorMax",value))
00248     if(Lib::smanip::todouble(value,dvalue)) colorMax = (float)dvalue;
00249   if(session.parameterValue("modeling.transparency",value))
00250     if(Lib::smanip::todouble(value,dvalue)) transparency = (float)dvalue;
00251   if(session.parameterValue("modeling.highlightColor",value))
00252     if(Lib::smanip::torgb(value,d1,d2,d3)) { 
00253       hr = (float)d1; 
00254       hg = (float)d2; 
00255       hb = (float)d3;
00256     }
00257 
00258   if(fieldMax<=fieldMin) return;
00259   if(colorMax<=colorMin) return;
00260 
00261   // Build name (for picking) :
00262   std::string s;
00263   Lib::smanip::printf(s,128,"MagneticField/0x%lx",(unsigned long)aIdentifier);
00264   SbName name(s.c_str());
00265     
00266   bool sceneEmpty = true;
00267   SoSeparator* cells = new SoSeparator;
00268 
00269   SoCoordinate3* coordinate3 = new SoCoordinate3;
00270   cells->addChild(coordinate3);
00271 
00272   int32_t coordIndex[5];
00273   int icoord = 0;
00274 
00275   float colorSlope = (colorMax-colorMin)/(fieldMax-fieldMin);
00276   for(unsigned int ix=0;ix<nx;ix++) {
00277     for(unsigned int iy=0;iy<ny;iy++) {
00278 
00279       SbVec3f center = 
00280         gridStart + gridX * (ix * sx + sx/2) + gridY * (iy * sy + sy/2);
00281       Gaudi::XYZPoint point(center[0],center[1],center[2]);
00282       Gaudi::XYZVector field;
00283       fMagneticFieldSvc->fieldVector( point, field);
00284       float value = (float)field.mag2();
00285       value = sqrt(value);
00286       
00287       if( (value<fieldMin) || (value>=fieldMax) ) continue;
00288 
00289       float r = colorSlope * (value - fieldMin) + colorMin;
00290       float g = 0;
00291       float b = 0;
00292 
00293       //FIXME : 
00294       //  A SoStyleCache for the below materials slows down the creation
00295       //  We should have a gradient table.
00296       // Material :
00297       SoHighlightMaterial* highlightMaterial = new SoHighlightMaterial;
00298       highlightMaterial->setName("highlight");
00299       highlightMaterial->diffuseColor.setValue(SbColor(r,g,b));
00300       highlightMaterial->highlightColor.setValue(SbColor(hr,hg,hb));
00301       highlightMaterial->transparency.setValue(transparency);
00302       cells->addChild(highlightMaterial);
00303 
00304       int32_t pointn = 4;
00305       SbVec3f line[4];
00306       line[0] = gridStart + gridX * (ix * sx) + gridY * (iy * sy);
00307       line[1] = gridStart + gridX * (ix * sx + sx) + gridY * (iy * sy);
00308       line[2] = gridStart + gridX * (ix * sx + sx) + gridY * (iy * sy + sy);
00309       line[3] = gridStart + gridX * (ix * sx) + gridY * (iy * sy + sy);
00310       coordIndex[0] = icoord + 0;
00311       coordIndex[1] = icoord + 1;
00312       coordIndex[2] = icoord + 2;
00313       coordIndex[3] = icoord + 3;
00314       coordIndex[4] = SO_END_FACE_INDEX;
00315 
00316       coordinate3->point.setValues(icoord,pointn,line);
00317       icoord += pointn;
00318 
00319       SoIndexedFaceSet* faceSet = new SoIndexedFaceSet;
00320       faceSet->coordIndex.setValues(0,pointn+1,coordIndex);
00321       faceSet->setName(name);
00322       cells->addChild(faceSet);
00323 
00324       sceneEmpty = false;
00325     }
00326   }
00327   
00328   if(sceneEmpty) {
00329 
00330     cells->unref();
00331 
00332   } else {
00333     // Build scene graph :
00334     SoSeparator* separator = new SoSeparator;
00335     separator->setName("sceneGraph");
00336 
00337     SoStyleCache* styleCache = soRegion->styleCache();
00338 
00339     separator->addChild(styleCache->getLightModelBaseColor());
00340     separator->addChild(styleCache->getFilled());
00341     separator->addChild(styleCache->getNormalBindingPerFace());
00342     separator->addChild(styleCache->getNormalZ());
00343 
00344     separator->addChild(cells);
00345 
00346     soRegion->resetUndo();    
00347     region_addToStaticScene(*soRegion,separator);
00348 
00349   }
00350 
00351 }


Member Data Documentation

std::string MagneticFieldType::fName [private]

Definition at line 36 of file Types.h.

IUserInterfaceSvc* MagneticFieldType::fUISvc [private]

Definition at line 37 of file Types.h.

IMagneticFieldSvc* MagneticFieldType::fMagneticFieldSvc [private]

Definition at line 38 of file Types.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:29 2011 for SoDet by doxygen 1.4.7