EGS_AffineTransform* EGS_AffineTransform::getTransformation(EGS_Input *i) { if( !i ) return 0; EGS_Input *input; bool delete_it = false; if( i->isA("transformation") ) input = i; else { input = i->takeInputItem("transformation"); if( !input ) return 0; delete_it = true; } EGS_Vector t; vector<EGS_Float> tmp; int err = input->getInput("translation",tmp); if( !err && tmp.size() == 3 ) t = EGS_Vector(tmp[0],tmp[1],tmp[2]); EGS_AffineTransform *result; err = input->getInput("rotation vector",tmp); if( !err && tmp.size() == 3 ) result = new EGS_AffineTransform( EGS_RotationMatrix(EGS_Vector(tmp[0],tmp[1],tmp[2])),t); else { err = input->getInput("rotation",tmp); if( !err ) { if( tmp.size() == 2 ) result = new EGS_AffineTransform( EGS_RotationMatrix(tmp[0],tmp[1]),t); else if( tmp.size() == 3 ) result = new EGS_AffineTransform( EGS_RotationMatrix(tmp[0],tmp[1],tmp[2]),t); else if( tmp.size() == 4 ) { EGS_Vector tmp1(tmp[0],tmp[1],tmp[2]); EGS_RotationMatrix R1(tmp1); EGS_RotationMatrix R2(EGS_RotationMatrix::rotZ(tmp[3])); EGS_RotationMatrix Rtot = R1.inverse()*R2*R1; result = new EGS_AffineTransform(Rtot,t); } else if( tmp.size() == 9 ) { EGS_RotationMatrix R(tmp[0],tmp[1],tmp[2], tmp[3],tmp[4],tmp[5], tmp[6],tmp[7],tmp[8]); if( !R.isRotation() ) egsWarning("getTransformation: the rotation specified by\n" " %g %g %g\n %g %g %g\n %g %g %g\n" " is not a rotation\n",tmp[0],tmp[1],tmp[2], tmp[3],tmp[4],tmp[5],tmp[6],tmp[7],tmp[8]); result = new EGS_AffineTransform(R,t); } else result = new EGS_AffineTransform(EGS_RotationMatrix(),t); } else result = new EGS_AffineTransform(EGS_RotationMatrix(),t); } if( delete_it ) delete input; return result; }
EGS_Object *EGS_ObjectFactory::createObjects(EGS_Input *i, const string §ion_delimeter, const string &object_delimeter, const string &select_key, const char *funcname, bool unique) { if (!i) { egsWarning("EGS_ObjectFactory::createObjects(): null input?\n"); return 0; } EGS_Input *input = i; if (!i->isA(section_delimeter)) { input = i->takeInputItem(section_delimeter); if (!input) { egsWarning("EGS_ObjectFactory::createObjects(): the input is" " not of type %s and also does not have items of this type\n", section_delimeter.c_str()); return 0; } } EGS_Input *ij; int errors = 0; while ((ij = input->takeInputItem(object_delimeter)) != 0) { EGS_Object *o = createSingleObject(ij,funcname,unique); if (!o) { errors++; } delete ij; } if (errors) egsWarning("EGS_ObjectFactory::createObjects(): %d errors" " occured while creating objects\n",errors); string sought_object; EGS_Object *o = 0; if (objects.size() > 0) { o = objects[objects.size()-1]; } int err = input->getInput(select_key,sought_object); if (!err) { o = getObject(sought_object); if (!o) egsWarning("EGS_ObjectFactory::createObjects(): an object " "with the name %s does not exist\n",sought_object.c_str()); } return o; }
EGS_ENVELOPEG_EXPORT EGS_BaseGeometry* createGeometry(EGS_Input *input) { if( !input ) { egsWarning(eeg_message1,eeg_message2); return 0; } // // *** new indexing style // int indexing = 0; input->getInput("new indexing style",indexing); // // *** Base geometry // EGS_Input *i = input->takeInputItem(eeg_keyword1); if( !i ) { egsWarning(eeg_message1,eeg_message3); return 0; } EGS_Input *ig = i->takeInputItem(eeg_keyword2); EGS_BaseGeometry *g; if( ig ) { // defined inline g = EGS_BaseGeometry::createSingleGeometry(ig); delete ig; if( !g ) { egsWarning(eeg_message1,eeg_message4); delete i; return 0; } } else { // defined via a name of a previously defined geometry string bgname; int err = i->getInput(eeg_keyword1,bgname); delete i; if( err ) { egsWarning(eeg_message1,eeg_message5); return 0; } g = EGS_BaseGeometry::getGeometry(bgname); if( !g ) { egsWarning(eeg_message6,bgname.c_str()); return 0; } } vector<EnvelopeAux *> fgeoms; EGS_Input *ix; while( (ix = input->takeInputItem("inscribe in regions")) != 0 ) { vector<string> values; ix->getInput("inscribe in regions",values); if( values.size() < 2 ) egsWarning("createGeometry(envelope geometry):" " %d inputs for 'inscribe in regions'? 2 or more are needed\n",values.size()); else { EGS_BaseGeometry *gj = EGS_BaseGeometry::getGeometry(values[0]); if( !gj ) egsWarning(eeg_message6,values[0].c_str()); else { EnvelopeAux *aux = new EnvelopeAux; aux->g = gj; aux->nreg = values.size()-1; aux->regs = new int [aux->nreg]; for(int j=0; j<aux->nreg; j++) aux->regs[j] = atoi(values[j+1].c_str()); fgeoms.push_back(aux); } } delete ix; } if( fgeoms.size() > 0 ) { EGS_BaseGeometry *result = new EGS_FastEnvelope(g,fgeoms,"",indexing); result->setName(input); for(int j=0; j<fgeoms.size(); j++) delete fgeoms[j]; return result; } // // *** Inscribed geometries // i = input->takeInputItem(eeg_keyword3); vector<EGS_BaseGeometry *> geoms; if( !i ) { if( fgeoms.size() ) egsWarning(eeg_message1,eeg_message7); } else { // first try for inscribed geometries defined inline while( (ig = i->takeInputItem(eeg_keyword2)) != 0 ) { EGS_BaseGeometry *gj = EGS_BaseGeometry::createSingleGeometry(ig); delete ig; if( !gj ) egsWarning(eeg_message1,eeg_message8); else geoms.push_back(gj); } // if geoms.size() is 0, check if inscribed geometries are defined // via names of previously defined geometries. if( !geoms.size() ) { vector<string> igeoms; int err = i->getInput(eeg_keyword3,igeoms); if( err || !igeoms.size() ) egsWarning(eeg_message1,eeg_message7); else { for(unsigned int j=0; j<igeoms.size(); j++) { EGS_BaseGeometry *gj = EGS_BaseGeometry::getGeometry(igeoms[j]); if( !gj ) egsWarning(eeg_message6,igeoms[j].c_str()); else geoms.push_back(gj); } } } delete i; } /* EGS_BaseGeometry *result = fgeoms.size() ? new EGS_EnvelopeGeometry(g,fgeoms,geoms) : new EGS_EnvelopeGeometry(g,geoms); */ EGS_BaseGeometry *result = new EGS_EnvelopeGeometry(g,geoms,"",indexing); result->setName(input); result->setLabels(input); return result; }
EGS_OCTREE_EXPORT EGS_BaseGeometry *createGeometry(EGS_Input *input) { EGS_Input *i; // check that we have an input if (!input) { egsWarning(eoctree_message1,eoctree_message2); return 0; } // read bounding boxes vector<EGS_Octree_bbox> vBox; while (i = input->takeInputItem(eoctree_key0)) { // read the bounding box minimum vector<EGS_Float> v; int err = i->getInput(eoctree_key1, v); if (err) { egsWarning(eoctree_message1, eoctree_message5); return 0; } if (v.size() != 3) { egsWarning(eoctree_message1, eoctree_message6); return 0; } EGS_Vector bboxMin(v[0],v[1],v[2]); // read the bounding box maximum err = i->getInput(eoctree_key2, v); if (err) { egsWarning(eoctree_message1, eoctree_message7); return 0; } if (v.size() != 3) { egsWarning(eoctree_message1, eoctree_message8); return 0; } EGS_Vector bboxMax(v[0],v[1],v[2]); // read the bounding box resolution vector<int> bboxRes; err = i->getInput(eoctree_key3, bboxRes); if (err) { egsWarning(eoctree_message1, eoctree_message9); return 0; } if (bboxRes.size() != 3) { egsWarning(eoctree_message1, eoctree_message10); return 0; } EGS_Octree_bbox box = EGS_Octree_bbox(bboxMin, bboxMax, bboxRes); vBox.push_back(box); } if (vBox.size() < 1) { egsWarning(eoctree_message1, eoctree_message15); return 0; } // read discard child option bool discardChild = true; string discard; if (input->getInputItem(eoctree_key5)) { int err = input->getInput(eoctree_key5, discard); if (err) { egsWarning(eoctree_message1, eoctree_message11); return 0; } if (discard.find("yes")==string::npos && discard.find("no")==string::npos) { egsWarning(eoctree_message1, eoctree_message12); return 0; } if (discard.find("no")!=string::npos) { discardChild = false; } } // read prune tree option bool pruneTree = true; string prune; if (input->getInputItem(eoctree_key6)) { int err = input->getInput(eoctree_key6, prune); if (err) { egsWarning(eoctree_message1, eoctree_message16); return 0; } if (prune.find("yes")==string::npos && prune.find("no")==string::npos) { egsWarning(eoctree_message1, eoctree_message17); return 0; } if (prune.find("no")!=string::npos) { pruneTree = false; } } // read and load the child geometry string gname; { int err = input->getInput(eoctree_key4, gname); if (err) { egsWarning(eoctree_message1, eoctree_message13); return 0; } } EGS_BaseGeometry *g = EGS_BaseGeometry::getGeometry(gname); if (!g) { egsWarning(eoctree_message1, eoctree_message14); return 0; } // create the octree geometry EGS_Octree *octree = new EGS_Octree(vBox, pruneTree, g); octree->setName(input); octree->setLabels(input); octree->printInfo(); if (discardChild) { delete g; } return octree; }
EGS_SMART_ENVELOPE_EXPORT EGS_BaseGeometry* createGeometry(EGS_Input *input) { if( !input ) { egsWarning(eeg_message1,eeg_message2); return 0; } // // *** Base geometry // EGS_Input *i = input->takeInputItem(eeg_keyword1); if( !i ) { egsWarning(eeg_message1,eeg_message3); return 0; } EGS_Input *ig = i->takeInputItem(eeg_keyword2); EGS_BaseGeometry *g; if( ig ) { // defined inline g = EGS_BaseGeometry::createSingleGeometry(ig); delete ig; if( !g ) { egsWarning(eeg_message1,eeg_message4); delete i; return 0; } } else { // defined via a name of a previously defined geometry string bgname; int err = i->getInput(eeg_keyword1,bgname); delete i; if( err ) { egsWarning(eeg_message1,eeg_message5); return 0; } g = EGS_BaseGeometry::getGeometry(bgname); if( !g ) { egsWarning(eeg_message6,bgname.c_str()); return 0; } } vector<SmartEnvelopeAux *> fgeoms; int nbase = g->regions(); EGS_Input *ix; while( (ix = input->takeInputItem("inscribe geometry")) != 0 ) { vector<string> values; ix->getInput("inscribe geometry",values); if( values.size() < 2 ) egsWarning("createGeometry(smart envelope):" " %d inputs for 'inscribe geometry'? 2 or more are needed\n",values.size()); else { EGS_BaseGeometry *gj = EGS_BaseGeometry::getGeometry(values[0]); if( !gj ) egsWarning(eeg_message6,values[0].c_str()); else { SmartEnvelopeAux *aux = new SmartEnvelopeAux; aux->g = gj; aux->ireg = atoi(values[1].c_str()); aux->type = values.size() == 3 ? atoi(values[2].c_str()) : 0; //egsInformation("set geometr: %s %d %d\n",values[0].c_str(),aux->ireg,aux->type); if( aux->ireg < 0 || aux->ireg >= nbase ) { egsWarning("createGeometry(smart envelope): wrong " "region index %d for inscribed geometry %s\n", aux->ireg,gj->getName().c_str()); delete aux; } else fgeoms.push_back(aux); } } delete ix; } EGS_BaseGeometry *result = new EGS_SmartEnvelope(g,fgeoms,""); result->setName(input); result->setLabels(input); for(int j=0; j<fgeoms.size(); j++) delete fgeoms[j]; return result; }
EGS_RangeRejection* EGS_RangeRejection::getRangeRejection(EGS_Input *input, EGS_Interpolator *i_ededx, EGS_Interpolator *i_pdedx) { EGS_Input *rr; bool delete_it; if( input->isA("range rejection") ) { rr = input; delete_it = false; } else { rr = input->takeInputItem("range rejection"); if( !rr ) return 0; delete_it = true; } int iaux; int err = rr->getInput("rejection",iaux); EGS_RangeRejection *result = 0; if( !err && iaux > 0 ) { result = new EGS_RangeRejection; if( iaux == 1 ) result->type = RangeDiscard; else { result->type = RussianRoulette; result->probi = iaux; } EGS_Float aux; err = rr->getInput("Esave",aux); if( !err && aux >= 0 ) result->Esave = aux; string cavity_geometry; err = rr->getInput("cavity geometry",cavity_geometry); if( !err ) { result->cgeom = EGS_BaseGeometry::getGeometry(cavity_geometry); if( !result->cgeom ) egsWarning("\n\n********** no geometry named" " %s exists => using region-by-region rejection only\n"); } if( result->Esave <= the_useful->prm && result->type == RangeDiscard ) { egsWarning("\n\n********* rr_flag = 1 but Esave = 0 =>" " not using range rejection\n\n"); delete result; result = 0; } if( result && result->type != None && result->cgeom ) { string rej_medium; int irej_medium = -1; err = rr->getInput("rejection range medium",rej_medium); if( !err ) { int imed = EGS_BaseGeometry::getMediumIndex(rej_medium); if( imed < 0 ) egsWarning("\n\n*********** no medium" " with name %s initialized => using region-by-region rejection only\n", rej_medium.c_str()); else irej_medium = imed; } if( irej_medium < 0 ) { result->cgeom = 0; result->type = RangeDiscard; } else { // // *** prepare an interpolator for the electron range // in the range rejection medium // int i = irej_medium; // save some typing EGS_Float log_emin = i_ededx[i].getXmin(); EGS_Float log_emax = i_ededx[i].getXmax(); int nbin = 512; EGS_Float dloge = (log_emax - log_emin)/nbin; EGS_Float *erange = new EGS_Float [nbin]; EGS_Float *prange = new EGS_Float [nbin]; erange[0] = 0; prange[0] = 0; EGS_Float ededx_old = i_ededx[i].interpolate(log_emin); EGS_Float pdedx_old = i_pdedx[i].interpolate(log_emin); EGS_Float Eold = exp(log_emin); EGS_Float efak = exp(dloge); for(int j=1; j<nbin; j++) { EGS_Float elke = log_emin + dloge*j; EGS_Float E = Eold*efak; EGS_Float ededx = i_ededx[i].interpolate(elke); EGS_Float pdedx = i_pdedx[i].interpolate(elke); if( ededx < ededx_old ) erange[j] = erange[j-1]+1.02*(E-Eold)/ededx; else erange[j] = erange[j-1]+1.02*(E-Eold)/ededx_old; if( pdedx < pdedx_old ) prange[j] = prange[j-1]+1.02*(E-Eold)/pdedx; else prange[j] = prange[j-1]+1.02*(E-Eold)/pdedx_old; Eold = E; ededx_old = ededx; pdedx_old = pdedx; } result->erange.initialize(nbin,log_emin,log_emax,erange); result->prange.initialize(nbin,log_emin,log_emax,prange); } } } if( delete_it ) delete rr; return result; }