#include #include #include #include #include ; //#include ; //#include ; class Point { public: double x,y,z; Point() : x(0), y(0), z(0) {}; Point(double xx, double yy, double zz): x(xx), y(yy), z(zz) {}; double px() {return x;} double py() {return y;} double pz() {return z;} friend ostream& operator << (ostream& stm, const Point& p) { stm<> (istream& istm, Voltage& vlt){}; }; //---------------------------------------------------------- class Electrode : public Point, public Voltage { //int status; public: Electrode() : Voltage(){}; //SetStatus(int s) { status=s; } SetVal(double xx, double yy, double zz, double uu, int s) {x=xx; y=yy; z=zz; u=uu; status=s;} friend ostream& operator << ( ostream& stm, const Electrode& elec ); friend istream& operator >> (istream& istm, Electrode& elec); }; ostream& operator << ( ostream& stm, const Electrode& elec ) { stm<<"ELECTRODE," <> (istream& istm, Electrode& elec) { char tmpc; int i; //eating initial string // E L E C T R O D E , istm>>tmpc>>tmpc>>tmpc>>tmpc>>tmpc>>tmpc>>tmpc>>tmpc>>tmpc>>tmpc; istm >>elec.hId>>tmpc >>elec.vId>>tmpc >>elec.u>>tmpc >>elec.x>>tmpc >>elec.y>>tmpc >>elec.z>>tmpc >>elec.status; return istm; } //---------------------------------------------------------- class Charge : public Point { //protected: public: int Id; double q; Charge() : Point(), Id(0), q(0){}; Charge(double xx, double yy, double zz, double qq): Point(xx,yy,zz), q(qq){} void SetId(int Num) { Id = Num; } friend ostream& operator << ( ostream& stm, const Charge& c ) { stm<<"CHARGE"<<","<> (istream& istm, Charge& c) {}; }; /////////////////////////////////////////////////////////////////// class Mapping; class Sequence { TLink * _ActCharge; int _ActChargeid; int _maxVid; int _maxHid; public: TList voltages; TList charges; SetActCharge(TLink * &c) { _ActCharge = c; } SetActChargeN(int n) { SetActCharge( charges.Get(n) ); } int maxVid(){ return _maxVid; } int maxHid(){ return _maxHid; } TLink * ActCharge() { return _ActCharge; } AddCharge(Charge c) { charges.Add(c); SetActCharge(charges.Get(1)); } RemoveActCharge() { charges.Remove(ActCharge() ); SetActCharge(charges.Get(1)); // it will be beter set as active previous charge here // not the first one } Charge * GetActCharge() { if( _ActCharge != 0) { return (Charge *)(_ActCharge->Data() ) ; } } int GetActChargeId() { if( _ActCharge != 0) { return _ActCharge->id() ; } } ModifyActCharge(double xx, double yy, double zz, double qq) { if( _ActCharge != 0) { ( (Charge *)(_ActCharge->Data() ) )->x=xx; ( (Charge *)(_ActCharge->Data() ) )->y=yy; ( (Charge *)(_ActCharge->Data() ) )->z=zz; ( (Charge *)(_ActCharge->Data() ) )->q=qq; } } //find the neaerst charge from point (x,y,z) TLink * FindCharge(double x, double y, double z) { const Link* pLink = charges.GetHead(); //_pHead; TLink* tpLink=(TLink*)pLink; TLink* tpLink1=(TLink*)pLink; Charge * p=(Charge *)(tpLink->Data()); double distance=(p->x-x)*(p->x-x)+(p->y-y)*(p->y-y)+(p->z-z)*(p->z-z); double curdistance=distance; while ( pLink != 0 ) { tpLink = (TLink*)pLink; p =(Charge*)(tpLink->Data()); curdistance=(p->x-x)*(p->x-x)+(p->y-y)*(p->y-y)+(p->z-z)*(p->z-z); if(curdistanceNext(); } return tpLink1; } //------------ SetmaxHVId() { const Link* pLink = voltages.GetHead(); //_pHead; TLink* tpLink = (TLink*)pLink; Voltage * p=(Voltage *)(tpLink->Data()); int maxH = 0; int maxV = 0; int curH=maxH; int curV=maxV; while ( pLink != 0 ) { tpLink = (TLink*)pLink; p =(Voltage*)(tpLink->Data()); curH=(p->hId); curV=(p->vId); if( maxH < curH ){ maxH=curH;} if( maxV < curV ){ maxV=curV;} pLink = pLink->Next(); } _maxHid = maxH; _maxVid = maxV; } //----------------- Sequence() : _ActCharge(0), _ActChargeid(0) {} Sequence(Sequence &seq) : voltages(seq.voltages), charges(seq.charges) {}; friend ostream& operator << ( ostream& stm, const Sequence& seq ) { stm<> (istream& istm, Sequence& seq) {}; //------------------------------------------------------------------ //definition for potential of n electric charges PT( , , ) [V] //------------------------------------------------------------------ double Potential(double x, double y, double z) { //GAMMA electricity constant double GAMMA = 8987551787.3681764; double PT = 0; const Link * pLink = charges.GetHead(); TLink * pTLink = (TLink *)pLink; const Charge * pc; //ofstream fill("charge.tst"); while ( pLink != 0 ) { pc = ( (TLink *)pLink )->Data(); double delta = sqrt( pow( (x - ( pc->px()) ), 2) +pow( (y - ( pc->py()) ), 2) +pow( (z - ( pc->pz()) ), 2 )); PT = PT + (GAMMA*(pc->q ) )/(delta); //fill<px())<<"," // <<(pc->py())<<"," // <<(pc->pz())<<"," // <<(pc->q)<<"," // <<"delta = "< Next() ; } return PT; } Calculate(){} }; //--------------------------------------- #define MAPPING_EMPTY 0 #define MAPPING_ELECTRODES_LOADED 1 #define MAPPING_OK 2 class Mapping { int _status; TLink * _ActSeq; int _ActSeqid; int _GND; TList electrodes; TList sequences; public: Calculate() { ofstream ffil("pot1.tst"); ffil< voltages.GetHead(); TLink * pTLink = (TLink *)pLink; TLink * pTLink1 = (TLink *)pLink1; const Electrode * pe; const Voltage * pv; Sequence * pseq = GetActSequence(); double potential; while( pLink != 0 ) { pTLink = (TLink *)pLink; pTLink1 = (TLink *)pLink1; pe = pTLink->Data(); pv = pTLink1->Data(); potential = pseq->Potential( pe->px(), pe->py(), pe->pz()); //scale potential in [uV] potential = 1000000*potential - _GND; pv->SetVoltage( potential ); //ffil<px()<<","<py()<<","<pz()<<","<Next(); pLink1= pLink1 ->Next(); } } Beep() { MessageBeep(0);MessageBeep(0);MessageBeep(0);MessageBeep(0); }; int Status() { return _status; } SetStatus(int status) {_status = status;} //TLink * GetElectrodes() // { return ( TLink * ) electrodes.GetHead(); } TList * GetElectrodes() { return &electrodes; } int AddSequence(); TLink * ActSeq() { return _ActSeq; } SetActSeq( TLink * &s) { _ActSeq = s; } SetActSeqN(int n) { SetActSeq( sequences.Get(n) ); } RemoveActSequence() { sequences.Remove(ActSeq() ); SetActSeq(sequences.Get(1)); // it will be beter set as active previous sequence here // not the first one (like in charges) } Sequence *GetActSequence() { if( _ActSeq != 0) { return (Sequence *)(_ActSeq->Data() ) ; } } //CHARGES FUNCTION AddCharge(Charge c) { if(_ActSeq != 0) { (_ActSeq->Data())->AddCharge(c); //cout<Data())->RemoveActCharge();} } ModifyActCharge(double xx, double yy, double zz, double qq) { if(_ActSeq != 0) { (_ActSeq->Data())->ModifyActCharge( xx, yy, zz, qq); } } Charge * GetActCharge() { if(_ActSeq != 0) { (_ActSeq->Data())->GetActCharge(); } } Mapping(): _status(MAPPING_EMPTY), _ActSeq(0), _ActSeqid(0), _GND(0) {}; friend ostream& operator << ( ostream& stm, const Mapping& mpg ); friend LoadElectrodes(Mapping& map, char * path); }; ostream& operator << ( ostream& stm, const Mapping& mpg ) { stm< fbrowser(&map.electrodes, path); fbrowser.ReadObjects(); map.SetStatus(MAPPING_ELECTRODES_LOADED); } //**************************************** Mapping::AddSequence() { if(_status == MAPPING_EMPTY) {return -1; } //errorr if(_status == MAPPING_ELECTRODES_LOADED) { TList tmpVltList; TList_iterator ESrcTiter(electrodes); const TLink * EsrcTLink; while( EsrcTLink=ESrcTiter++ ) { tmpVltList.Add( *(EsrcTLink->Data()) ); } Sequence s; TList_iterator SrcTiter(tmpVltList); const TLink * srcTLink; while( srcTLink=SrcTiter++ ) { s.voltages.Add( *(srcTLink->Data()) ); } sequences.Add(s); SetStatus(MAPPING_OK); SetActSeq(sequences.Get(1)); GetActSequence()->SetmaxHVId(); return 1; } if(_status == MAPPING_OK) { //cout<Data()) ); SetActSeq(sequences.Get(1)); GetActSequence()->SetmaxHVId(); return 1; } }