// // $Id: SiDisk.cpp,v 1.15 2001/02/03 22:53:35 hobbs Exp $ // // File: SiDisk.cpp // Purpose: Implement SiDisk and it's associated class SiSubDisk // Created: 18-NOV-1997 Thomas Trippe // // $Revision: 1.15 $ // // // Include files (iostream added by A. Patwa 8/26/98) #include #include "SiDisk.hpp" #include #include #include #include // Global definitions using namespace std; using namespace dgs; bool operator<(const SiDisk& lhs, const SiDisk&rhs) { return lhs.get_position()[2] < rhs.get_position()[2]; } bool operator ==(const SiSubDisk& lhs, const SiSubDisk &rhs) { if( lhs.get_position() != rhs.get_position() ) return false; if( lhs._wedgeholders.size() != rhs._wedgeholders.size() ) return false; for( int i=0 ; i& wedgeholders, float phi1,float separation, bool spun): _subdisk1(radius,nwedgeholders/2,phi0,(const SiWedgeHolder*)0), _subdisk2(radius,nwedgeholders/2,phi1,(const SiWedgeHolder*)0) { const float pi=3.1415926535898; //Can we get this elsewhere? const float twopi=2.0*pi; //Can we get this elsewhere? if (phi0==0) { // Position the subdisks. CartesianCoordinate pos1(0.0,0.0,-separation/2.0); position_child_at(pos1,_subdisk1); CartesianCoordinate pos2(0.0,0.0,separation/2.0); position_child_at(pos2,_subdisk2); for( int i=0 ; i<(nwedgeholders/2) ; i++ ) { // Position odd numbered wedge holders in subdisk 1 _subdisk1._wedgeholders[i] = wedgeholders[2*i]; float phi = phi0 + i*twopi/(nwedgeholders/2); CylindricalCoordinate pos3(radius,phi,0.0); _subdisk1.position_child_at(pos3,_subdisk1._wedgeholders[i]); if( flipped ) { _subdisk1.flip_wedgeholder(i); } // Position even numbered wedge holders in subdisk2 _subdisk2._wedgeholders[i] = wedgeholders[2*i+1]; phi = phi1 + i*twopi/(nwedgeholders/2); CylindricalCoordinate pos4(radius,phi,0.0); _subdisk2.position_child_at(pos4,_subdisk2._wedgeholders[i]); } if (spun) { for( int i=0 ; i<(nwedgeholders/2) ; i++ ) { _subdisk1.flip_wedgeholder(i); _subdisk2.flip_wedgeholder(i); } // now switch the z position of subdisk1 and subdisk2 CartesianCoordinate pos5(0.0,0.0,separation/2.0); position_child_at(pos5,_subdisk1); CartesianCoordinate pos6(0.0,0.0,-separation/2.0); position_child_at(pos6,_subdisk2); } } if (phi0 > pi/12.) { // Position the subdisks. CartesianCoordinate pos1(0.0,0.0,-separation/2.0); position_child_at(pos1,_subdisk1); CartesianCoordinate pos2(0.0,0.0,separation/2.0); position_child_at(pos2,_subdisk2); for( int i=0 ; i<(nwedgeholders/2) ; i++ ) { // Position odd numbered wedge holders in subdisk 1 _subdisk1._wedgeholders[i] = wedgeholders[2*i]; float phi = phi0 + i*twopi/(nwedgeholders/2); CylindricalCoordinate pos3(radius,phi,0.0); _subdisk1.position_child_at(pos3,_subdisk1._wedgeholders[i]); if( flipped ) { _subdisk1.flip_wedgeholder(i); } // Position even numbered wedge holders in subdisk2 _subdisk2._wedgeholders[i] = wedgeholders[2*i+1]; phi = phi1 + i*twopi/(nwedgeholders/2); CylindricalCoordinate pos4(radius,phi,0.0); _subdisk2.position_child_at(pos4,_subdisk2._wedgeholders[i]); } if (spun) { for( int i=0 ; i<(nwedgeholders/2) ; i++ ) { _subdisk1.flip_wedgeholder(i); _subdisk2.flip_wedgeholder(i); } // now switch the z position of subdisk1 and subdisk2 CartesianCoordinate pos5(0.0,0.0,separation/2.0); position_child_at(pos5,_subdisk1); CartesianCoordinate pos6(0.0,0.0,-separation/2.0); position_child_at(pos6,_subdisk2); } } if(phi0>0 && phi0<=pi/12.) { // Position the subdisks. CartesianCoordinate pos2(0.0,0.0,separation/2.0); position_child_at(pos2,_subdisk1); CartesianCoordinate pos1(0.0,0.0,-separation/2.0); position_child_at(pos1,_subdisk2); for( int i=0 ; i<(nwedgeholders/2) ; i++ ) { // Position even numbered wedge holders in subdisk 1 _subdisk1._wedgeholders[i] = wedgeholders[2*i+1]; float phi = phi0 + i*twopi/(nwedgeholders/2); CylindricalCoordinate pos3(radius,phi,0.0); _subdisk1.position_child_at(pos3,_subdisk1._wedgeholders[i]); // Position odd numbered wedge holders in subdisk2 _subdisk2._wedgeholders[i] = wedgeholders[2*i]; phi = phi1 + i*twopi/(nwedgeholders/2); CylindricalCoordinate pos4(radius,phi,0.0); _subdisk2.position_child_at(pos4,_subdisk2._wedgeholders[i]); if( flipped ) { _subdisk2.flip_wedgeholder(i); } } if (spun) { for( int i=0 ; i<(nwedgeholders/2) ; i++ ) { _subdisk1.flip_wedgeholder(i); _subdisk2.flip_wedgeholder(i); } // now switch the z position of subdisk1 and subdisk2 CartesianCoordinate pos5(0.0,0.0,-separation/2.0); position_child_at(pos5,_subdisk1); CartesianCoordinate pos6(0.0,0.0,separation/2.0); position_child_at(pos6,_subdisk2); } } } // Accessors const list SiDisk::get_children() // // Purpose: // States: // { list kids,kids1,kids2; kids1=_subdisk1.get_children(); kids2=_subdisk2.get_children(); kids.splice(kids.end(),kids1); kids.splice(kids.end(),kids2); return kids; } void SiDisk::resize(float dr) // // Purpose: Change the radius of a disk // States: // { bool pass =_subdisk1.resize(0.0,dr,0.0) && _subdisk2.resize(0.0,dr,0.0); // Must include the 0.0 arguments here because _subdisk1 and _subdisk2 // inherit from Disk, which is an AnnularSurfaceSection with rmin=0 and // phimax=2pi. It is resized by resize(drmin,drmax,dphimax). } int SiDisk::get_wedgeholder_count() const { return _subdisk1.get_wedgeholder_count() + _subdisk2.get_wedgeholder_count(); } const SiWedgeHolder* SiDisk::get_wedgeholder(int iwedho) const { int i = (iwedho+1)/2; if( iwedho%2 == 1 ) return _subdisk1.get_wedgeholder(i); else return _subdisk2.get_wedgeholder(i); } SiWedgeHolder* SiDisk::get_mutable_wedgeholder(int iwedho) { int i = (iwedho+1)/2; if( iwedho%2 == 1 ) return _subdisk1.get_mutable_wedgeholder(i); else return _subdisk2.get_mutable_wedgeholder(i); } std::ostream& operator<<(std::ostream& os, const SiDisk& me) { os << "SiDisk at " << me.get_position() << " has two SiSubDisks with radii " << me._subdisk1.get_rmax() << " located at "<< me._subdisk1.get_position() << " and " << me._subdisk2.get_position() <<" with a total of " << me.get_wedgeholder_count() << " wedge holders:" << endl; for( int i=1 ; i<=me.get_wedgeholder_count() ; i++ ) { os << " No. " << i << " "; int isub = (i+1)/2; if( (i%2) == 1 ) os << *(me._subdisk1.get_wedgeholder(isub)) << endl; else os << *(me._subdisk2.get_wedgeholder(isub)) << endl; } return os; } //----------------------------------------------------------------------------- // // Implement SiSubDisk here // //----------------------------------------------------------------------------- SiSubDisk::SiSubDisk() { } SiSubDisk::SiSubDisk(float radius, int nwedgeholders, float phi0, const SiWedgeHolder* prototype/*NULL*/): Disk(radius) { const SiWedgeHolder* use_this; // If no SiWedgeHolder is passed, just fill the vector with empties... if( prototype ) use_this = prototype; else use_this = new SiWedgeHolder; const float twopi=2*3.1415926535898; //Can I get this elsewhere? for( int i=0 ; i &wedgeholders): Disk(radius), _wedgeholders(wedgeholders) { const float twopi=2*3.1415926535898; //Can I get this elsewhere? for( int i=0 ; i SiSubDisk::get_children() { list kids; for( int i=0 ; i<_wedgeholders.size() ; i++ ) { kids.push_back(&_wedgeholders[i]); } return kids; } // Accessors int SiSubDisk::get_wedgeholder_count() const // // Purpose: // { return _wedgeholders.size(); } SiWedgeHolder* SiSubDisk::get_mutable_wedgeholder(int iwedho) // // Purpose: Return a reference to a wedge holder. The wedge holder may be // modified. // { return &_wedgeholders[iwedho-1]; } const SiWedgeHolder* SiSubDisk::get_wedgeholder(int iwedho) const // // Purpose: Return a reference to a wedge holder. The wedge holder may not // be modified. // { return &_wedgeholders[iwedho-1]; } void SiSubDisk::flip_wedgeholder(int i) // // Purpose: Flip a wedgeholder so that the p-side points inward. // { double pi=3.1415926535898; GeometryXform spin =_wedgeholders[i].get_relative_position(get_position()); GeometryXform spinY180(0.0,0.0,0.0,pi/2.0,pi,-pi/2.0); spin = spin.apply(spinY180); _wedgeholders[i].set_relative_position(get_position(),spin); }