diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-05-11 14:59:00 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-05-11 14:59:00 +0000 |
commit | 64d6cd8a7ed46be4a34b4818705186f8e0998ab1 (patch) | |
tree | 0a889a5ff9bdb7a010bb9e028a5dc2ca0d05be65 /src/gui | |
parent | ff64cec5fdf5b18e6aee31e8b3148a0305e1d1de (diff) | |
download | vhc-64d6cd8a7ed46be4a34b4818705186f8e0998ab1.tar.gz vhc-64d6cd8a7ed46be4a34b4818705186f8e0998ab1.tar.bz2 vhc-64d6cd8a7ed46be4a34b4818705186f8e0998ab1.zip |
Rajoute getHorizontalAt() pour tous les elements, en vue des faisceaux
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/Main.cc | 134 | ||||
-rw-r--r-- | src/gui/ParticleRenderer.h | 3 | ||||
-rw-r--r-- | src/gui/Renderer.h | 12 | ||||
-rw-r--r-- | src/gui/Stage.cc | 10 | ||||
-rw-r--r-- | src/gui/Stage.h | 16 | ||||
-rw-r--r-- | src/gui/util.h | 9 |
6 files changed, 79 insertions, 105 deletions
diff --git a/src/gui/Main.cc b/src/gui/Main.cc index 6ae9c67..28ba09f 100644 --- a/src/gui/Main.cc +++ b/src/gui/Main.cc @@ -15,7 +15,9 @@ #include "StraightElement.h" #include "Dipole.h" #include "Particle.h" -#include "FODO.h" +//#include "FODO.h" +#include "Quadrupole.h" +#include "Element.h" #include "Vector3D.h" #include "constants.h" #include <vector> @@ -38,6 +40,21 @@ std::vector< Particle > createParticles(const Vector3D& position, int n, double return v; } +Element** FODO(Vector3D entry, Vector3D exit, double Rs, double L, double b) { + double l = (entry - exit).norm() / 2.0 - 1; + Vector3D d = (exit - entry).unit(); + Quadrupole* fq = new Quadrupole(entry, entry + d * l, Rs, b); + StraightElement* s1 = new StraightElement(fq->getExitPosition(), fq->getExitPosition() + d * L, Rs); + Quadrupole* dq = new Quadrupole(s1->getExitPosition(), s1->getExitPosition() + d * l, Rs, -b); + StraightElement* s2 = new StraightElement(dq->getExitPosition(), exit, Rs); + Element** fodo = new Element*[4]; + (fodo)[0] = fq; + (fodo)[1] = s1; + (fodo)[2] = dq; + (fodo)[3] = s2; + + return fodo; +} Accelerator* standard() { /* @@ -87,34 +104,41 @@ Une particule : double B = 5.8915820038873; double b = 1.2; - FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.1, 1.0, b); - Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.1, 1, Vector3D(0, 0, B)); - FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.1, 1, b); - Dipole e4 = Dipole(e3.getExitPosition(), Vector3D(-3, -2, 0), 0.1, 1, Vector3D(0, 0, B)); - FODO e5 = FODO(e4.getExitPosition(), Vector3D(-3, 2, 0), 0.1, 1.0, b); - Dipole e6 = Dipole(e5.getExitPosition(), Vector3D(-2, 3, 0), 0.1, 1, Vector3D(0, 0, B)); - FODO e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.1, 1.0, b); - Dipole e8 = Dipole(e7.getExitPosition(), e1.getEntryPosition(), 0.1, 1, Vector3D(0, 0, B)); + Element** e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.1, 1.0, b); + + //FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.1, 1.0, b); + Dipole e2 = Dipole(Vector3D(3, -2, 0), Vector3D(2, -3, 0), 0.1, 1, Vector3D(0, 0, B)); + + Element** e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.1, 1, b); + Dipole e4 = Dipole(Vector3D(-2, -3, 0), Vector3D(-3, -2, 0), 0.1, 1, Vector3D(0, 0, B)); + Element** e5 = FODO(e4.getExitPosition(), Vector3D(-3, 2, 0), 0.1, 1.0, b); + Dipole e6 = Dipole(Vector3D(-3, 2, 0), Vector3D(-2, 3, 0), 0.1, 1, Vector3D(0, 0, B)); + Element** e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.1, 1.0, b); + Dipole e8 = Dipole(Vector3D(2, 3, 0), Vector3D(3, 2, 0), 0.1, 1, Vector3D(0, 0, B)); Accelerator* acc = new Accelerator(); - acc->add(e1); + //acc->add(e1); + for (int i = 0; i < 4; ++i) acc->add(e1[i][0]); acc->add(e2); - acc->add(e3); + for (int i = 0; i < 4; ++i) acc->add(e3[i][0]); + //acc->add(e3); acc->add(e4); - acc->add(e5); + for (int i = 0; i < 4; ++i) acc->add(e5[i][0]); + //acc->add(e5); acc->add(e6); - acc->add(e7); + for (int i = 0; i < 4; ++i) acc->add(e7[i][0]); + //acc->add(e7); acc->add(e8); acc->close(); //proton - Particle p1 = Particle(Vector3D(3.00, 0, 0), constants::PROTON_MASS, constants::E, 2 * constants::GeV, -Vector3D::j); + Particle p1 = Particle(Vector3D(3.01, 0, 0), constants::PROTON_MASS, constants::E, 2 * constants::GeV, -Vector3D::j); Particle p2 = Particle(Vector3D(2.99, 0, 0), constants::PROTON_MASS, constants::E, 2 * constants::GeV, -Vector3D::j); acc->add(p1); acc->add(p2); //anti-proton - Particle ap1 = Particle(Vector3D(3.00, 0, 0), constants::PROTON_MASS, -constants::E, 2 * constants::GeV, Vector3D::j); + Particle ap1 = Particle(Vector3D(3.01, 0, 0), constants::PROTON_MASS, -constants::E, 2 * constants::GeV, Vector3D::j); Particle ap2 = Particle(Vector3D(2.99, 0, 0), constants::PROTON_MASS, -constants::E, 2 * constants::GeV, Vector3D::j); acc->add(ap1); acc->add(ap2); @@ -131,84 +155,6 @@ Une particule : return acc; } -Accelerator* standardAccelerator() { - FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.2, 1.0, 5.0); - Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.2, 1); - FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.2, 1, 5.0); - Dipole e4 = Dipole(e3.getExitPosition(), Vector3D(-3, -2, 0), 0.2, 1); - FODO e5 = FODO(e4.getExitPosition(), Vector3D(-3, 2, 0), 0.2, 1.0, 5.0); - Dipole e6 = Dipole(e5.getExitPosition(), Vector3D(-2, 3, 0), 0.2, 1); - FODO e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.2, 1.0, 5.0); - Dipole e8 = Dipole(e7.getExitPosition(), e1.getEntryPosition(), 0.2, 1); - Accelerator* acc = new Accelerator(); - acc->add(e1); - acc->add(e2); - acc->add(e3); - acc->add(e4); - acc->add(e5); - acc->add(e6); - acc->add(e7); - acc->add(e8); - - std::vector< Particle > ps = createParticles(e1.getEntryPosition(), 100000); - - for (int i = 0; i < ps.size(); ++i) { - acc->add(ps[i]); - } - - acc->close(); - - return acc; -} - -Accelerator* linear() { - Accelerator* acc = new Accelerator(); - - for(int i = 0; i < 10; ++i) { - FODO e = FODO(Vector3D(4, 0, 0) * i, Vector3D(4, 0, 0) * (i + 1), 0.1, 1, 1.2); - acc->add(e); - } - - Particle e(Vector3D(0, 0.05, 0.01), constants::PROTON_MASS, constants::E, 2 * constants::GeV, Vector3D::i); - acc->add(e); - acc->close(); - - return acc; -} -/* -Accelerator* singleDipole() { - Vector3D entry = Vector3D(0, 2, 0); - Vector3D exit = Vector3D(2, 0, 0); - double sectionRadius = 0.2; - double curvature = 0.5; - Vector3D direction = entry.cross(Vector3D::k); - - double mass = constants::ELECTRON_MASS; - double charge = constants::E; - double energy = 1 * 1E9 * constants::E; - - - Particle particle = Particle(entry, mass, charge, energy, direction); - double Bz = particle.getGamma() * particle.getMass() * curvature * particle.getVelocity().norm() / particle.getCharge(); - std::cout << "|B:|" << Bz << std::endl; - Dipole element = Dipole(entry, exit, sectionRadius, curvature, Vector3D::k * Bz); - - Accelerator* acc = new Accelerator(); - - Element*\ celement = acc->add(element); - - std::vector< Particle > ps = createParticles(element.getEntryPosition(), 10, constants::ELECTRON_MASS, constants::E, energy, direction); - - for (int i = 0; i < ps.size(); ++i) { - Particle* cparticle = acc->add(ps[i]); - cparticle->setElement(celement); - } - - Particle* cparticle = acc->add(particle); - cparticle->setElement(celement); - return acc; -}*/ - int main(int argc, char *argv[]) { @@ -225,7 +171,7 @@ int main(int argc, char *argv[]) window.show(); - //window.showFullScreen(); + window.showFullScreen(); //app.setActiveWindow(&window); return app.exec(); diff --git a/src/gui/ParticleRenderer.h b/src/gui/ParticleRenderer.h index 216c869..458cf5c 100644 --- a/src/gui/ParticleRenderer.h +++ b/src/gui/ParticleRenderer.h @@ -23,7 +23,8 @@ public: ParticleRenderer(); virtual ~ParticleRenderer(); - void render(const Particle& particle) const; + + virtual void render(const Particle& particle) const; void enableDrawSpheres(bool value); diff --git a/src/gui/Renderer.h b/src/gui/Renderer.h index a673957..6be4373 100644 --- a/src/gui/Renderer.h +++ b/src/gui/Renderer.h @@ -16,7 +16,19 @@ public: Renderer() {}; virtual ~Renderer() {}; + /** Methode qui doit etre appelee avant de dessiner une collection d'objets par <code>render</code>. + * Cette methode gere des <code>glBegin()</code> en arriere-plan. */ + //virtual void begin() = 0; + + /** Dessine un objet. */ virtual void render(const T& item) const = 0; + + //template <typename Container> + //virtual void render(std::forward_iterator) const; + + /** Methode qui doit etre appelee avant de dessiner une collection d'objets par <code>render</code>. + * Cette methode gere des <code>glBegin()</code> en arriere-plan. */ + //virtual void end() = 0; }; } diff --git a/src/gui/Stage.cc b/src/gui/Stage.cc index 4b9e5e7..81c405d 100644 --- a/src/gui/Stage.cc +++ b/src/gui/Stage.cc @@ -31,8 +31,8 @@ Stage::Stage(QWidget* parent): timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(update())); - timer->start(1000.0/100); + connect(timer, SIGNAL(timeout()), this, SLOT(updateGL())); + timer->start(1); setMouseTracking(true); } @@ -80,9 +80,10 @@ void Stage::paintGL() { QString("pitch: ") + QString::number(camera.getPitch()), QString("-----accelerator-----"), QString("Elements: ") + QString::number(accelerator->getElements().size()), - QString("Particles: ") + QString::number(accelerator->getParticles().size()) + QString("Particles: ") + QString::number(accelerator->getParticles().size()), + QString("") + accelerator->getParticles().front()->toString().c_str() }; - displayText(text, 10); + displayText(text, 11); //renderText(0,60,QString("") + accelerator->getParticle(0)->getElement()->magneticFieldAt(accelerator->getParticle(0)->getPosition()).toString().c_str()); //renderText(0,72,QString("") + accelerator->getParticle(0)->toString().c_str()); axes(); @@ -125,6 +126,7 @@ void Stage::paintGL() { glDisable(GL_BLEND); glColor3d(0, 0, 1); + for (list<Particle*>::const_iterator i = accelerator->getParticles().begin(); i != accelerator->getParticles().end(); ++i) { particleRenderer.render(**i); } diff --git a/src/gui/Stage.h b/src/gui/Stage.h index 04cb1da..b3afdb9 100644 --- a/src/gui/Stage.h +++ b/src/gui/Stage.h @@ -61,22 +61,26 @@ protected: void mouseMoveEvent(QMouseEvent* event); private: - Camera camera; + //io KeyManager keyManager; + //graphics + Camera camera; + ElementRenderer elementRenderer; + ParticleRenderer particleRenderer; + QPoint center; + util::DisplayMode displayMode; + + //simulation QTimer* timer; QTime time; int frameTime; //ms - double h; bool paused; - ElementRenderer elementRenderer; - ParticleRenderer particleRenderer; - util::DisplayMode displayMode; - QPoint center; + }; diff --git a/src/gui/util.h b/src/gui/util.h index 9cfded6..075c2d0 100644 --- a/src/gui/util.h +++ b/src/gui/util.h @@ -19,6 +19,15 @@ enum DisplayMode { POINTS = 2 }; +/** Classe utilitaire pour verifier une relation d'heritage. + * Cette classe ne compile que si A est une sous-classe de B + * voir http://www2.research.att.com/~bs/bs_faq2.html#constraints pour plus d'informations. */ +template<class A, class B> +struct DerivedFrom { + static void constraints(A* p) { A* pb = p; } + DerivedFrom() { void(*p)(A*) = constraints; } +}; + /** Dessine un tore autour de l'origine, sur le plan xy. * @param R rayon du tore * @param r rayon du "cylindre" du tore |