Main Page | Namespace List | Data Structures | File List | Data Fields | Globals

interface.cpp

Go to the documentation of this file.
00001 # include <math.h>
00002 
00003 # include <interface.h>
00004 # include <network.h>
00005 # include <qgl.h>
00006 # include <inn.h>
00007 # include <qtextedit.h>
00008 
00009 using namespace qglviewer ;
00010 
00011 extern Network * network ;
00012 extern Inn * inn ;
00013 
00014 // Constructor must call the base class constructor.
00015 Viewer::Viewer(QWidget *parent,const char *name) : QGLViewer(parent, name) {
00016         //help();
00017         startTimer(20);
00018         setDrawAxis(false) ;
00019         idfrom_ = -1 ;
00020         idto_ = -1 ;
00021 }
00022 
00023 
00024 void Viewer::init() {
00025         mode_ = NONE ;
00026         
00027         glEnable (GL_BLEND);
00028         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00029         
00030         // Make camera the default manipulated frame.
00031         setManipulatedFrame( camera()->frame() );
00032         
00033         // Set a generic plane constraint
00034         constraint = new LocalConstraint() ;
00035         constraint->setTranslationConstraint(AxisPlaneConstraint::PLANE, Vec(0.0,1.0,0.0));
00036         layerconstraint = new LocalConstraint() ;
00037         layerconstraint->setTranslationConstraint(AxisPlaneConstraint::FORBIDDEN, Vec(1.0,1.0,1.0));
00038         layerconstraint->setRotationConstraint(AxisPlaneConstraint::FORBIDDEN, Vec(1.0,1.0,1.0));
00039         
00040         // Use "frame(i)->setConstraint(constraint)" to affect this constraint
00041         
00042         // Swap the CAMERA and FRAME state keys (NoButton and Control)
00043         // Save CAMERA binding first. See setMouseStateKey() documentation.
00044         setMouseStateKey(QGLViewer::FRAME,  Qt::ControlButton);
00045         
00046         setSceneRadius(3.0);
00047         showEntireScene();
00048         
00049         float x, y, z ;
00050         camera()->getPosition( x, y, z ) ;
00051         camera()->setPosition( x, y+1.3, z ) ;
00052 }
00053 
00054 int Viewer::mode(void) {
00055         return mode_ ;
00056 }
00057 
00058 void Viewer::setMode(int mode) {
00059         mode_ = mode ;
00060 }
00061 
00062 void Viewer::resetMode(void) {
00063         idfrom_ = -1 ;
00064         idto_ = -1 ;
00065         mode_ = NONE ;
00066 }
00067 
00068 
00069 void Viewer::draw() {
00070         network->setShininess( 32 ) ;
00071         network->draw(selectedName()) ;
00072         if(mode_==ADDAXON) {
00073                 QFont font("Arial", 16) ;
00074                 renderText( 10, 50, "Axon mode is on", font ) ;
00075         }
00076 }
00077 
00078 void Viewer::drawText( float x, float y, float z, const QString& s, const QFont& q ) {
00079         renderText( x, y, z, s, q ) ;
00080 }
00081 
00082 
00083 void Viewer::drawWithNames() {
00084         network->setShininess( 4 ) ;
00085         network->draw(selectedName(), true) ;
00086 }
00087 
00088 void Viewer::fastDraw() {
00089         network->setShininess( 4 ) ;
00090         network->draw(selectedName()) ;
00091 }
00092 
00093 void Viewer::postSelection(int x, int y) {
00094         if(mode()==ADDAXON  && network->existNeuron(selectedName())) {
00095                 if( idfrom_ < 0 ) idfrom_ = selectedName() ;
00096                 else {
00097                         idto_ = selectedName() ;
00098                         if( network->getLayerNumTheNeuronIsOn(idfrom_)<network->getLayerNumTheNeuronIsOn(idto_)
00099                                 && !network->existAxon( idfrom_, idto_ ) ) 
00100                                 network->addAxon( idfrom_, idto_ ) ;
00101                         else if( network->getLayerNumTheNeuronIsOn(idfrom_)>network->getLayerNumTheNeuronIsOn(idto_)
00102                                 && !network->existAxon( idto_, idfrom_ ) )
00103                                 network->addAxon( idto_, idfrom_ ) ;
00104                         idfrom_ = -1 ;
00105                         idto_ = -1 ;
00106                 }
00107         } else if (selectedName() == -1 && !network->frame(selectedName()) ) {
00108       // Camera will be the default frame is no object is selected.
00109       setManipulatedFrame( camera()->frame() );
00110     } else {
00111       setManipulatedFrame(network->frame(selectedName()));
00112       if(network->existNeuron(selectedName()))
00113         network->frame(selectedName())->setConstraint(constraint) ;
00114       else if(network->existLayer(selectedName()))
00115         network->frame(selectedName())->setConstraint(layerconstraint) ;
00116     }
00117 }
00118 
00119 void Viewer::timerEvent(QTimerEvent*) {
00120     updateGL();
00121 }
00122 
00123 QString Viewer::helpString() const {
00124   QString text("<h2>Intuitive Neural Network</h2>");
00125   text += "";
00126   text += "";
00127   text += "";
00128   return text;
00129 }

Generated on Fri Dec 3 14:57:50 2004 for INN by doxygen 1.3.6