IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques Discussion :

[Vtk] Multi touch


Sujet :

Bibliothèques

  1. #1
    Membre habitué Avatar de robinsondesbois
    Homme Profil pro
    Etudiant
    Inscrit en
    Avril 2012
    Messages
    171
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Haute Loire (Auvergne)

    Informations professionnelles :
    Activité : Etudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2012
    Messages : 171
    Points : 173
    Points
    173
    Par défaut [Vtk] Multi touch
    Bonjour,

    Je travail actuellement sur Vtk et je souhaiterais implémenter des event multi touch. Je travail sous Qt 4.8.5 et Vtk 6.0. Existe-t-il une librairie qui capte les event multi touche sous windows 7 ?
    Je suis tombé sur ce "tuto" http://blogs.msdn.com/b/jennifer/arc...windows-7.aspx
    Cependant comme tous les "tuto" windows il ne fonctionne que sous windows. Mon application fonctionnera à terme sous windows 7 mais n'utilisera pas d'api windows pour l'affichage de la fenêtre.

    Cordialement,
    Robin

  2. #2
    Membre habitué Avatar de robinsondesbois
    Homme Profil pro
    Etudiant
    Inscrit en
    Avril 2012
    Messages
    171
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Haute Loire (Auvergne)

    Informations professionnelles :
    Activité : Etudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2012
    Messages : 171
    Points : 173
    Points
    173
    Par défaut
    J'ai fini par réussir ma modification des sources.

    Cette solution s'applique pour la version 6.0 de vtk. Pour les version supérieur je pense qu'il faudra juste réadapter mon code (je pense que mes explications sont suffisamment claire, en cas de problème MP moi). De toutes façon je pense que les développeurs de Vtk intégrerons les nouveaux Event de Qt dans les versions futures.

    Pour les personnes intéressées je donne ma solution.
    Pour utiliser les fonctionnalités multi-touch sous vtk il faut modifier les sources et les recompiler.
    Lors de la configuration (sous cmake) il faut bien penser à cocher toutes les options Qt et GUISupportQt. L'astuce consiste à utiliser l’événement Qt QEvent::TouchUpdate.

    //-------------------QVTKWidget---------------------------

    Dans le fichier QVTKWidget.h nous allons inclure #include <QTouchEvent>
    Dans le fichier QVTKWidget.cxx nous allons utiliser la fonction bool QVTKWidget::event(QEvent* e) pour traiter l’événement Touch.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    bool QVTKWidget::event(QEvent* e)
    {
      if(e->type() == QEvent::TouchUpdate)
      {
    	  this->mIrenAdapter->ProcessEvent(e, this->mRenWin->GetInteractor());
      }
     
      if(e->type() == QEvent::ParentAboutToChange)
        {
        this->markCachedImageAsDirty();
        if (this->mRenWin)
          {
          // Finalize the window to remove graphics resources associated with
          // this window
          if(this->mRenWin->GetMapped())
            {
            this->mRenWin->Finalize();
            }
          }
        }
      else if(e->type() == QEvent::ParentChange)
        {
        if(this->mRenWin)
          {
          x11_setup_window();
          // connect to new window
          this->mRenWin->SetWindowId( reinterpret_cast<void*>(this->winId()));
     
          // start up the window to create graphics resources for this window
          if(isVisible())
            {
            this->mRenWin->Start();
            }
          }
        }
     
      if(QObject::event(e))
        {
        return TRUE;
        }
     
      if(e->type() == QEvent::KeyPress)
        {
        QKeyEvent* ke = static_cast<QKeyEvent*>(e);
        this->keyPressEvent(ke);
        return ke->isAccepted();
        }
     
      return QWidget::event(e);
    }
    Il ne faut pas oublier de rajouter ces deux lignes de codes dans le constructeur de QVTKWidget. Ca permet de dire à Qt que nous souhaitons traiter les événements multi-touch.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    this->setAttribute(Qt::WA_AcceptTouchEvents);
      this->setAttribute(Qt::WA_StaticContents);
    //-------------------QVTKInteractorAdapter---------------------------
    Le but du jeu ici est de récupérer les valeurs qui sont intéressantes et de les stocker dans les class de Vtk.
    Modifions donc la fonction ProcessEvent :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    bool QVTKInteractorAdapter::ProcessEvent(QEvent* e, vtkRenderWindowInteractor* iren)
    {
      if(iren == NULL || e == NULL)
        return false;
     
      const QEvent::Type t = e->type();
     
      if(t == QEvent::Resize)
        {
        QResizeEvent* e2 = static_cast<QResizeEvent*>(e);
        QSize size = e2->size();
        iren->SetSize(size.width(), size.height());
        return true;
        }
     
      if(t == QEvent::FocusIn)
        {
        // For 3DConnexion devices:
        QVTKInteractor* qiren = QVTKInteractor::SafeDownCast(iren);
        if(qiren)
          {
          qiren->StartListening();
          }
        return true;
        }
     
      if(t == QEvent::FocusOut)
        {
        // For 3DConnexion devices:
        QVTKInteractor* qiren = QVTKInteractor::SafeDownCast(iren);
        if(qiren)
          {
          qiren->StopListening();
          }
        return true;
        }
     
      // the following events only happen if the interactor is enabled
      if(!iren->GetEnabled())
        return false;
     
      if(t == QEvent::TouchUpdate)
      {
    	iren->ClearTouchEvent();
    	QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(e)->touchPoints();
    	for(int i=0; i<touchPoints.size(); i++)
    	  iren->AddPosTouchEvent((int)touchPoints.at(i).pos().x(), (int)touchPoints.at(i).pos().y());
     
    	iren->InvokeEvent(vtkCommand::TouchEvent, e);
      }
     
      if(t == QEvent::MouseButtonPress ||
         t == QEvent::MouseButtonRelease ||
         t == QEvent::MouseButtonDblClick ||
         t == QEvent::MouseMove)
        {
        QMouseEvent* e2 = static_cast<QMouseEvent*>(e);
     
        // give interactor the event information
        iren->SetEventInformationFlipY(e2->x(), e2->y(),
                                    (e2->modifiers() & Qt::ControlModifier) > 0 ? 1 : 0,
                                    (e2->modifiers() & Qt::ShiftModifier ) > 0 ? 1 : 0,
                                    0,
                                    e2->type() == QEvent::MouseButtonDblClick ? 1 : 0);
     
        if(t == QEvent::MouseMove)
          {
          iren->InvokeEvent(vtkCommand::MouseMoveEvent, e2);
          }
        else if(t == QEvent::MouseButtonPress || t == QEvent::MouseButtonDblClick)
          {
          switch(e2->button())
            {
            case Qt::LeftButton:
              iren->InvokeEvent(vtkCommand::LeftButtonPressEvent, e2);
              break;
     
            case Qt::MidButton:
              iren->InvokeEvent(vtkCommand::MiddleButtonPressEvent, e2);
              break;
     
            case Qt::RightButton:
              iren->InvokeEvent(vtkCommand::RightButtonPressEvent, e2);
              break;
     
            default:
              break;
            }
          }
        else if(t == QEvent::MouseButtonRelease)
          {
          switch(e2->button())
            {
            case Qt::LeftButton:
              iren->InvokeEvent(vtkCommand::LeftButtonReleaseEvent, e2);
              break;
     
            case Qt::MidButton:
              iren->InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, e2);
              break;
     
            case Qt::RightButton:
              iren->InvokeEvent(vtkCommand::RightButtonReleaseEvent, e2);
              break;
     
            default:
              break;
            }
          }
        return true;
        }
     
      if(t == QEvent::Enter)
        {
        iren->InvokeEvent(vtkCommand::EnterEvent, e);
        return true;
        }
     
      if(t == QEvent::Leave)
        {
        iren->InvokeEvent(vtkCommand::LeaveEvent, e);
        return true;
        }
     
      if(t == QEvent::KeyPress || t == QEvent::KeyRelease)
        {
        QKeyEvent* e2 = static_cast<QKeyEvent*>(e);
     
        // get key and keysym information
        int ascii_key = e2->text().length() ? e2->text().unicode()->toLatin1() : 0;
        const char* keysym = ascii_to_key_sym(ascii_key);
        if(!keysym ||
           e2->modifiers() == Qt::KeypadModifier)
          {
          // get virtual keys
          keysym = qt_key_to_key_sym(static_cast<Qt::Key>(e2->key()),
                                     e2->modifiers());
          }
     
        if(!keysym)
          {
          keysym = "None";
          }
     
        // give interactor event information
        iren->SetKeyEventInformation(
          (e2->modifiers() & Qt::ControlModifier),
          (e2->modifiers() & Qt::ShiftModifier),
          ascii_key, e2->count(), keysym);
     
        if(t == QEvent::KeyPress)
          {
          // invoke vtk event
          iren->InvokeEvent(vtkCommand::KeyPressEvent, e2);
     
          // invoke char event only for ascii characters
          if(ascii_key)
            {
            iren->InvokeEvent(vtkCommand::CharEvent, e2);
            }
          }
        else
          {
          iren->InvokeEvent(vtkCommand::KeyReleaseEvent, e2);
          }
        return true;
        }
     
      if(t == QEvent::Wheel)
        {
        QWheelEvent* e2 = static_cast<QWheelEvent*>(e);
     
        iren->SetEventInformationFlipY(e2->x(), e2->y(),
                                   (e2->modifiers() & Qt::ControlModifier) > 0 ? 1 : 0,
                                   (e2->modifiers() & Qt::ShiftModifier ) > 0 ? 1 : 0);
     
        // invoke vtk event
        // if delta is positive, it is a forward wheel event
        if(e2->delta() > 0)
          {
          iren->InvokeEvent(vtkCommand::MouseWheelForwardEvent, e2);
          }
        else
          {
          iren->InvokeEvent(vtkCommand::MouseWheelBackwardEvent, e2);
          }
        return true;
        }
     
      if(t == QEvent::ContextMenu)
        {
        QContextMenuEvent* e2 = static_cast<QContextMenuEvent*>(e);
     
        // give interactor the event information
        iren->SetEventInformationFlipY(e2->x(), e2->y(),
                                   (e2->modifiers() & Qt::ControlModifier) > 0 ? 1 : 0,
                                   (e2->modifiers() & Qt::ShiftModifier ) > 0 ? 1 : 0);
     
        // invoke event and pass qt event for additional data as well
        iren->InvokeEvent(QVTKInteractor::ContextMenuEvent, e2);
     
        return true;
        }
     
      if(t == QEvent::DragEnter)
        {
        QDragEnterEvent* e2 = static_cast<QDragEnterEvent*>(e);
     
        // invoke event and pass qt event for additional data as well
        iren->InvokeEvent(QVTKInteractor::DragEnterEvent, e2);
     
        return true;
        }
     
      if(t == QEvent::DragLeave)
        {
        QDragLeaveEvent* e2 = static_cast<QDragLeaveEvent*>(e);
     
        // invoke event and pass qt event for additional data as well
        iren->InvokeEvent(QVTKInteractor::DragLeaveEvent, e2);
     
        return true;
        }
     
      if(t == QEvent::DragMove)
        {
        QDragMoveEvent* e2 = static_cast<QDragMoveEvent*>(e);
     
        // give interactor the event information
        iren->SetEventInformationFlipY(e2->pos().x(), e2->pos().y());
     
        // invoke event and pass qt event for additional data as well
        iren->InvokeEvent(QVTKInteractor::DragMoveEvent, e2);
        return true;
        }
     
      if(t == QEvent::Drop)
        {
        QDropEvent* e2 = static_cast<QDropEvent*>(e);
     
        // give interactor the event information
        iren->SetEventInformationFlipY(e2->pos().x(), e2->pos().y());
     
        // invoke event and pass qt event for additional data as well
        iren->InvokeEvent(QVTKInteractor::DropEvent, e2);
        return true;
        }
     
      return false;
    }

    //-------------vtkRenderWindowInteractor------------------------
    Stockons les valeurs importantes dans le .h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      int	NbTouchEvent;
      int**	TabPosTouchEvent;
    avec les fonction qui vont bien :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
      void SetNbTouchEvent(int nb) {this->NbTouchEvent = nb;}
      int GetNbTouchEvent() {return this->NbTouchEvent;}
      int** GetTabTouchEvent() {return this->TabPosTouchEvent;}
      void AddPosTouchEvent(int x, int y);
      void ClearTouchEvent();
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    void vtkRenderWindowInteractor::AddPosTouchEvent(int x, int y)
    {
    	this->NbTouchEvent++;
    	int **temp = new int*[this->NbTouchEvent];
    	for (int i=0; i<this->NbTouchEvent; i++)
    		temp[i] = new int[2];
     
    	if(this->TabPosTouchEvent != NULL)
    	{
    		for (int i=0; i<this->NbTouchEvent-1; i++)
    		{
    			temp[i][0] = this->TabPosTouchEvent[i][0];
    			temp[i][1] = this->TabPosTouchEvent[i][1];
    		}
    		for( int i=0; i<this->NbTouchEvent-1; i++)
    			delete[] this->TabPosTouchEvent[i];
    		delete[] this->TabPosTouchEvent;
    	}
     
    	temp[this->NbTouchEvent-1][0] = x;
    	temp[this->NbTouchEvent-1][1] = y;
    	this->TabPosTouchEvent = temp;
     
    }
     
    void vtkRenderWindowInteractor::ClearTouchEvent()
    {
    	if (this->TabPosTouchEvent == NULL)
    		return;
    	for( int i=0; i<this->NbTouchEvent; i++)
    		delete[] this->TabPosTouchEvent[i];
    	delete[] this->TabPosTouchEvent;
    	this->TabPosTouchEvent = NULL;
    	this->NbTouchEvent = 0;
    }
    PS: pensez à initialiser les variables

    On rajoute une fonction que nous pourrons redéfinir dans nos interactor style.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    virtual void TouchEvent();
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    //------------------------------------------------------------------
    void vtkRenderWindowInteractor::TouchEvent()
    {
    	if (!this->Enabled)
        {
        return;
        }
      this->InvokeEvent(vtkCommand::TouchEvent, NULL);
    }

    //-------------------vtkCommand--------------------------
    Ce fichier contient la liste des event de Vtk.
    On rajoute donc notre événement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    _vtk_add_event(TouchEvent)\

    //-------------------vtkInteractorStyle----------------
    notre fonction à redéfinie dans nos class filles.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    virtual void OnTouchEvent() {};
    dans le cxx on rajoute la case de la gestion de notre événement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    //----------------------------------------------------------------------------
    void vtkInteractorStyle::ProcessEvents(vtkObject* vtkNotUsed(object),
                                           unsigned long event,
                                           void* clientdata,
                                           void* calldata)
    {
      vtkInteractorStyle* self
        = reinterpret_cast<vtkInteractorStyle *>( clientdata );
     
      switch(event)
        {
        case vtkCommand::ExposeEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::ExposeEvent))
            {
            self->InvokeEvent(vtkCommand::ExposeEvent,NULL);
            }
          else
            {
            self->OnExpose();
            }
          break;
     
        case vtkCommand::ConfigureEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::ConfigureEvent))
            {
            self->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
            }
          else
            {
            self->OnConfigure();
            }
          break;
     
        case vtkCommand::EnterEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::EnterEvent))
            {
            self->InvokeEvent(vtkCommand::EnterEvent, NULL);
            }
          else
            {
            self->OnEnter();
            }
          break;
     
        case vtkCommand::LeaveEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::LeaveEvent))
            {
            self->InvokeEvent(vtkCommand::LeaveEvent,NULL);
            }
          else
            {
            self->OnLeave();
            }
          break;
     
        case vtkCommand::TimerEvent:
          {
          // The calldata should be a timer id, but because of legacy we check
          // and make sure that it is non-NULL.
          int timerId = (calldata ? *(reinterpret_cast<int*>(calldata)) : 1);
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::TimerEvent))
            {
            self->InvokeEvent(vtkCommand::TimerEvent,&timerId);
            }
          else
            {
            self->OnTimer();
            }
          }
          break;
     
        case vtkCommand::MouseMoveEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::MouseMoveEvent))
            {
            self->InvokeEvent(vtkCommand::MouseMoveEvent,NULL);
            }
          else
            {
            self->OnMouseMove();
            }
          break;
     
        case vtkCommand::LeftButtonPressEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::LeftButtonPressEvent))
            {
            self->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
            }
          else
            {
            self->OnLeftButtonDown();
            }
          break;
     
        case vtkCommand::LeftButtonReleaseEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::LeftButtonReleaseEvent))
            {
            self->InvokeEvent(vtkCommand::LeftButtonReleaseEvent,NULL);
            }
          else
            {
            self->OnLeftButtonUp();
            }
          break;
     
        case vtkCommand::MiddleButtonPressEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::MiddleButtonPressEvent))
            {
            self->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
            }
          else
            {
            self->OnMiddleButtonDown();
            }
          break;
     
        case vtkCommand::MiddleButtonReleaseEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::MiddleButtonReleaseEvent))
            {
            self->InvokeEvent(vtkCommand::MiddleButtonReleaseEvent,NULL);
            }
          else
            {
            self->OnMiddleButtonUp();
            }
          break;
     
        case vtkCommand::RightButtonPressEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::RightButtonPressEvent))
            {
            self->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
            }
          else
            {
            self->OnRightButtonDown();
            }
          break;
     
        case vtkCommand::RightButtonReleaseEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::RightButtonReleaseEvent))
            {
            self->InvokeEvent(vtkCommand::RightButtonReleaseEvent,NULL);
            }
          else
            {
            self->OnRightButtonUp();
            }
          break;
     
        case vtkCommand::MouseWheelForwardEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::MouseWheelForwardEvent))
            {
            self->InvokeEvent(vtkCommand::MouseWheelForwardEvent,NULL);
            }
          else
            {
            self->OnMouseWheelForward();
            }
          break;
     
        case vtkCommand::MouseWheelBackwardEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::MouseWheelBackwardEvent))
            {
            self->InvokeEvent(vtkCommand::MouseWheelBackwardEvent,NULL);
            }
          else
            {
            self->OnMouseWheelBackward();
            }
          break;
     
    	case vtkCommand::TouchEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::TouchEvent))
            {
    			self->InvokeEvent(vtkCommand::TouchEvent,NULL);
            }
          else
            {
    			self->OnTouchEvent();
            }
          break;
     
        case vtkCommand::KeyPressEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::KeyPressEvent))
            {
            self->InvokeEvent(vtkCommand::KeyPressEvent,NULL);
            }
          else
            {
            self->OnKeyDown();
            self->OnKeyPress();
            }
          break;
     
        case vtkCommand::KeyReleaseEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::KeyReleaseEvent))
            {
            self->InvokeEvent(vtkCommand::KeyReleaseEvent,NULL);
            }
          else
            {
            self->OnKeyUp();
            self->OnKeyRelease();
            }
          break;
     
        case vtkCommand::CharEvent:
          if (self->HandleObservers &&
              self->HasObserver(vtkCommand::CharEvent))
            {
            self->InvokeEvent(vtkCommand::CharEvent,NULL);
            }
          else
            {
            self->OnChar();
            }
          break;
     
        case vtkCommand::DeleteEvent:
          self->SetInteractor(0);
          break;
     
        case vtkCommand::TDxMotionEvent:
        case vtkCommand::TDxButtonPressEvent:
        case vtkCommand::TDxButtonReleaseEvent:
          self->DelegateTDxEvent(event,calldata);
          break;
        }
    }
    et on pense mettre à jour lors d'un changement d'interactor :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    void vtkInteractorStyle::SetInteractor(vtkRenderWindowInteractor *i)
    {
      if(i == this->Interactor)
        {
        return;
        }
     
      // if we already have an Interactor then stop observing it
      if(this->Interactor)
        {
        this->Interactor->RemoveObserver(this->EventCallbackCommand);
        }
      this->Interactor = i;
     
      // add observers for each of the events handled in ProcessEvents
      if(i)
        {
        i->AddObserver(vtkCommand::EnterEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::LeaveEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::MouseMoveEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::LeftButtonPressEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::MiddleButtonPressEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::MiddleButtonReleaseEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::RightButtonPressEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::RightButtonReleaseEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::MouseWheelForwardEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::MouseWheelBackwardEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
    	i->AddObserver(vtkCommand::TouchEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::ExposeEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::ConfigureEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::TimerEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::KeyPressEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::KeyReleaseEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::CharEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::DeleteEvent,
                       this->EventCallbackCommand,
                       this->Priority);
        i->AddObserver(vtkCommand::TDxMotionEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::TDxButtonPressEvent,
                       this->EventCallbackCommand,
                       this->Priority);
     
        i->AddObserver(vtkCommand::TDxButtonReleaseEvent,
                       this->EventCallbackCommand,
                       this->Priority);
        }
     
      this->EventForwarder->SetTarget(this->Interactor);
      if (this->Interactor)
        {
        this->AddObserver(vtkCommand::StartInteractionEvent, this->EventForwarder);
        this->AddObserver(vtkCommand::EndInteractionEvent, this->EventForwarder);
        }
      else
        {
        this->RemoveObserver(this->EventForwarder);
        }
    }
    //------------------vtkInteractorStyleTrackballCamera------------------
    On fini par redéfinir notre fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    /*=========================================================================
     
      Program:   Visualization Toolkit
      Module:    vtkInteractorStyleTrackballCamera.h
     
      Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
      All rights reserved.
      See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
     
         This software is distributed WITHOUT ANY WARRANTY; without even
         the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
         PURPOSE.  See the above copyright notice for more information.
     
    =========================================================================*/
    // .NAME vtkInteractorStyleTrackballCamera - interactive manipulation of the camera
    // .SECTION Description
    // vtkInteractorStyleTrackballCamera allows the user to interactively
    // manipulate (rotate, pan, etc.) the camera, the viewpoint of the scene.  In
    // trackball interaction, the magnitude of the mouse motion is proportional
    // to the camera motion associated with a particular mouse binding. For
    // example, small left-button motions cause small changes in the rotation of
    // the camera around its focal point. For a 3-button mouse, the left button
    // is for rotation, the right button for zooming, the middle button for
    // panning, and ctrl + left button for spinning.  (With fewer mouse buttons,
    // ctrl + shift + left button is for zooming, and shift + left button is for
    // panning.)
     
    // .SECTION See Also
    // vtkInteractorStyleTrackballActor vtkInteractorStyleJoystickCamera
    // vtkInteractorStyleJoystickActor
     
    #ifndef __vtkInteractorStyleTrackballCamera_h
    #define __vtkInteractorStyleTrackballCamera_h
     
    #include "vtkInteractionStyleModule.h" // For export macro
    #include "vtkInteractorStyle.h"
     
    class VTKINTERACTIONSTYLE_EXPORT vtkInteractorStyleTrackballCamera : public vtkInteractorStyle
    {
    public:
      static vtkInteractorStyleTrackballCamera *New();
      vtkTypeMacro(vtkInteractorStyleTrackballCamera,vtkInteractorStyle);
      void PrintSelf(ostream& os, vtkIndent indent);
     
      // Description:
      // Event bindings controlling the effects of pressing mouse buttons
      // or moving the mouse.
      virtual void OnMouseMove();
      virtual void OnLeftButtonDown();
      virtual void OnLeftButtonUp();
      virtual void OnMiddleButtonDown();
      virtual void OnMiddleButtonUp();
      virtual void OnRightButtonDown();
      virtual void OnRightButtonUp();
      virtual void OnMouseWheelForward();
      virtual void OnMouseWheelBackward();
      virtual void OnTouchEvent();
     
      // These methods for the different interactions in different modes
      // are overridden in subclasses to perform the correct motion. Since
      // they are called by OnTimer, they do not have mouse coord parameters
      // (use interactor's GetEventPosition and GetLastEventPosition)
      virtual void Rotate();
      virtual void Spin();
      virtual void Pan();
      virtual void Dolly();
     
      // Description:
      // Set the apparent sensitivity of the interactor style to mouse motion.
      vtkSetMacro(MotionFactor,double);
      vtkGetMacro(MotionFactor,double);
     
    protected:
      vtkInteractorStyleTrackballCamera();
      ~vtkInteractorStyleTrackballCamera();
     
      double MotionFactor;
     
      virtual void Dolly(double factor);
     
    private:
      vtkInteractorStyleTrackballCamera(const vtkInteractorStyleTrackballCamera&);  // Not implemented.
      void operator=(const vtkInteractorStyleTrackballCamera&);  // Not implemented.
    };
     
    #endif
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    //----------------------------------------------------------------------------
    void vtkInteractorStyleTrackballCamera::OnTouchEvent()
    {
    	this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
                              this->Interactor->GetEventPosition()[1]);
    	if (this->CurrentRenderer == NULL)
        {
    		return;
        }
     
      this->GrabFocus(this->EventCallbackCommand);
      this->StartDolly();
    }
    Voili voilou. On recompile les sources, on n'oubli pas de relinker les lib et de prendre les bonnes dll.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Mise à jour : Multi-Touch Trackpad pour Windows
    Par kOrt3x dans le forum Apple
    Réponses: 0
    Dernier message: 12/08/2009, 10h56
  2. Réponses: 12
    Dernier message: 27/12/2008, 16h42
  3. Multi-Touch Trackpad Update pour Windows XP & Vista
    Par aodix dans le forum Windows
    Réponses: 0
    Dernier message: 19/12/2008, 08h43
  4. [Projet] Nouvelle distribution Linux Multi - Touch
    Par anthonys dans le forum Distributions
    Réponses: 0
    Dernier message: 04/08/2008, 01h13
  5. Gestion flèches clavier multi touches
    Par PoZZyX dans le forum Windows Forms
    Réponses: 5
    Dernier message: 17/12/2007, 13h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo