138 lines
3.8 KiB
C++
138 lines
3.8 KiB
C++
/*//////////////////////////////////////////////////////////////////////////////
|
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
|
All rights reserved
|
|
|
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
|
|
|
------------------------------------------------------------------
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 3.0 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////*/
|
|
|
|
#ifndef U_VTKHANDLERWIDGET_H
|
|
#define U_VTKHANDLERWIDGET_H
|
|
|
|
#include "Math/Dense.h"
|
|
#include "uLibVtkInterface.h"
|
|
|
|
#include <vtk3DWidget.h>
|
|
#include <vtkSmartPointer.h>
|
|
|
|
// Forward declarations of VTK classes in global namespace
|
|
class vtkActor;
|
|
class vtkCallbackCommand;
|
|
class vtkCellPicker;
|
|
class vtkTransform;
|
|
class vtkObject;
|
|
class vtkPlane;
|
|
class vtkRenderWindowInteractor;
|
|
|
|
namespace uLib {
|
|
namespace Vtk {
|
|
|
|
/**
|
|
* @class vtkHandlerWidget
|
|
* @brief A Blender-like transform gizmo for move, rotate, and scale.
|
|
*/
|
|
class vtkHandlerWidget : public ::vtk3DWidget {
|
|
public:
|
|
static vtkHandlerWidget *New();
|
|
vtkTypeMacro(vtkHandlerWidget, ::vtk3DWidget);
|
|
|
|
vtkHandlerWidget();
|
|
virtual ~vtkHandlerWidget();
|
|
|
|
virtual void SetEnabled(int enabling) override;
|
|
static void ProcessEvents(::vtkObject *caller, unsigned long event,
|
|
void *clientdata, void *calldata);
|
|
|
|
void OnLeftButtonDown();
|
|
void OnLeftButtonUp();
|
|
void OnMouseMove();
|
|
|
|
enum InteractionState {
|
|
IDLE = 0,
|
|
TRANS_X,
|
|
TRANS_Y,
|
|
TRANS_Z,
|
|
ROT_X,
|
|
ROT_Y,
|
|
ROT_Z,
|
|
SCALE_X,
|
|
SCALE_Y,
|
|
SCALE_Z,
|
|
ROT_CAM
|
|
};
|
|
|
|
enum ReferenceFrame {
|
|
GLOBAL = 0,
|
|
LOCAL,
|
|
CENTER,
|
|
CENTER_LOCAL,
|
|
NORMAL, // Not implemented
|
|
PARENT // Not implemented
|
|
};
|
|
|
|
void SetReferenceFrame(ReferenceFrame frame);
|
|
ReferenceFrame GetReferenceFrame() const { return this->m_Frame; }
|
|
|
|
using ::vtk3DWidget::PlaceWidget;
|
|
virtual void PlaceWidget(double bounds[6]) override;
|
|
virtual void PlaceWidget() override;
|
|
|
|
// Transform handling //
|
|
void SetTransform(::vtkTransform *t);
|
|
void GetTransform(::vtkTransform *t);
|
|
|
|
::vtkRenderer *GetOverlayRenderer() { return this->m_OverlayRenderer; }
|
|
|
|
protected:
|
|
void CreateGizmos();
|
|
void UpdateGizmoPosition();
|
|
void Highlight(::vtkProp *prop);
|
|
|
|
vtkSmartPointer<::vtkRenderer> m_OverlayRenderer;
|
|
ReferenceFrame m_Frame;
|
|
|
|
int Interaction;
|
|
::vtkProp *m_HighlightedProp;
|
|
double m_OriginalColor[3];
|
|
|
|
// Visual components //
|
|
vtkSmartPointer<::vtkActor> m_AxesX, m_AxesY, m_AxesZ; // Arrows
|
|
vtkSmartPointer<::vtkActor> m_RotX, m_RotY, m_RotZ; // Rings
|
|
vtkSmartPointer<::vtkActor> m_RotCam; // Camera ring
|
|
vtkSmartPointer<::vtkActor> m_ScaleX, m_ScaleY, m_ScaleZ; // Cubes
|
|
|
|
vtkSmartPointer<::vtkPlane> m_ClipPlane;
|
|
|
|
vtkSmartPointer<::vtkCellPicker> m_Picker;
|
|
|
|
double StartEventPosition[2];
|
|
double m_StartPickPosition[3];
|
|
vtkSmartPointer<::vtkTransform> m_InitialTransform;
|
|
|
|
private:
|
|
vtkHandlerWidget(const vtkHandlerWidget &) = delete;
|
|
void operator=(const vtkHandlerWidget &) = delete;
|
|
};
|
|
|
|
} // namespace Vtk
|
|
} // namespace uLib
|
|
|
|
#endif // U_VTKHANDLERWIDGET_H
|