Developer Documentation

TypeLight.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44
45
46
47 #ifndef TYPELIGHTPLUGIN_HH
48 #define TYPELIGHTPLUGIN_HH
49
50 #include <QObject>
51
52 #include <OpenFlipper/common/Types.hh>
53 #include <ObjectTypes/Light/Light.hh>
54 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
55 #include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
56 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
57 #include <OpenFlipper/BasePlugin/TypeInterface.hh>
58 #include <OpenFlipper/BasePlugin/MouseInterface.hh>
59 #include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
60 #include <OpenFlipper/BasePlugin/PickingInterface.hh>
61
62 class TypeLightPlugin : public QObject, BaseInterface, LoadSaveInterface, LoggingInterface, TypeInterface, MouseInterface,
63 ToolbarInterface, PickingInterface
64 {
65 Q_OBJECT
66 Q_INTERFACES(BaseInterface)
67 Q_INTERFACES(LoadSaveInterface)
68 Q_INTERFACES(LoggingInterface)
69 Q_INTERFACES(TypeInterface)
70 Q_INTERFACES(MouseInterface)
71 Q_INTERFACES(ToolbarInterface)
72 Q_INTERFACES(PickingInterface)
73
74 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TypeLight")
75
76 signals:
77 // Logging interface
78 void log(Logtype _type, QString _message);
79 void log(QString _message);
80
81 // LoadSave Interface
82 void addEmptyObject(DataType _type, int& _id);
83 void emptyObjectAdded( int _id );
84 void deleteObject(int _id);
85
86 // BaseInterface
87 void updatedObject(int _id, const UpdateType& _type);
88 void updateView();
89
90 // ToolbarInterface
91 void getToolBar( QString _name, QToolBar*& _toolbar );
92
93 // PickingInterface
94 void addPickMode(const std::string& _mode);
95 void addHiddenPickMode(const std::string& _mode);
96 void setPickModeMouseTracking (const std::string& _mode, bool _mouseTracking);
97 void setPickModeToolbar(const std::string& _mode, QToolBar * _toolbar);
98
99 private slots:
100
101 // BaseInterface
102 void noguiSupported( ) {};
103
104 // PickingInterface
105 void slotPickModeChanged (const std::string& _pickMode);
106
107 // Is called whenever the scene is cleared
108 void slotAllCleared();
109
110 // Adds three default light sources to scene
111 void addDefaultLights();
112 // ... and removes them
113 void removeDefaultLights();
114
115 // Load/Save Interface
116 void addedEmptyObject(int _id);
117 void objectDeleted(int _id);
118
119 // MouseInterface
120 //void slotMouseEventLight( QMouseEvent* _event);
121 void slotMouseEventLight( QMouseEvent* _event );
122
123 private:
124
126 void rotateLights(ACG::Vec3d& _axis, double _angle);
127
129 void rotateLightDirection(ACG::Vec3d& _axis, double _angle);
130
132 void updateLights();
133
138 bool computeClickOnTrackball(const QPoint& _v2D, ACG::Vec3d& _clickOnSphere, ACG::GLState& _state);
139
144 bool computeClickOnLightTrackball(const QPoint& _v2D, ACG::Vec3d& _clickOnSphere, ACG::GLState& _state);
145
146 public:
147
148 ~TypeLightPlugin() {};
149 TypeLightPlugin();
150
151 QString name() { return (QString("TypeLight")); };
152 QString description( ) { return (QString(tr("Register Light type"))); };
153
154 bool registerType();
155
156 public slots:
157
158 // Base Interface
159 QString version() { return QString("1.0"); };
160
161 // Type Interface
162 int addEmpty();
163 DataType supportedType() { return DATA_LIGHT; };
164
165 void pluginsInitialized();
166
167 // Add default light
168 int addDefaultLight(QString _name);
169
170 void showReducedUi(bool reduced);
171
172 private slots:
173
174 void slotLightModeRequest(bool _checked);
175 void slotPickModeRequest(QAction* _action);
176
177 void slotSetAllOrTarget(bool _checked);
178
179 private:
180
182 float findDepth();
183
184 // Find distance of farthest light source from trackball center
185 double getFarthestRadius();
186
188 void addAssistLines();
189
191 std::vector<int> lightSources_;
192
193 bool defaultLights_;
194
195 // Matrix for rotating light position
196 ACG::GLMatrixd light_matrix_;
197
198 // Toolbar for light mode
199 QToolBar* toolbar_;
200
201 // Toolbar that show detailed options for light mode
202 QToolBar* lightOptions_;
203
204 // GUI elements
205 QAction* lightAction_;
206
207 QAction* moveMode_;
208 QAction* translateMode_;
209 QAction* rotateMode_;
210
211 QAction* allLightsMode_;
212 QAction* viewerToolbarAction_;
213
214 // True if only target lights should be transformed
215 bool onlyTargets_;
216
217 // Mouse interactions
218 QPoint lastPoint2D_;
219 ACG::Vec3d lastPoint3D_;
220 //bool lastPoint_hitSphere_;
221 // depth of plane olong which objects are translated
222 // if middle mouse button is pressed
223 float planeDepth_;
224 ACG::Vec3d transVec_;
225 bool rotation_;
226
227 // Radius of trackball for most distant light source
228 double radius_;
229
230 // Depth of light source that is closest to camera
231 float depth_;
232
233 // Picked light stuff
234 ACG::Vec3d lightCenter_;
235 double lightRadius_;
236 int lightId_;
237
238 bool hitLightTrackball_;
239 bool hitTrackball_;
240
241 };
242
243 #endif //TYPELIGHTPLUGIN_HH
TypeLightPlugin::description
QString description()
Return a description of what the plugin is doing.
Definition: TypeLight.hh:152
UpdateType
Update type class.
Definition: UpdateType.hh:60
TypeLightPlugin::slotAllCleared
void slotAllCleared()
Called if the whole scene is cleared.
Definition: TypeLight.cc:84
TypeLightPlugin::addedEmptyObject
void addedEmptyObject(int _id)
An empty object has been added.
Definition: TypeLight.cc:392
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:92
MouseInterface.hh
TypeLightPlugin::rotateLights
void rotateLights(ACG::Vec3d &_axis, double _angle)
Rotate light sources.
Definition: TypeLight.cc:729
LoadSaveInterface
Interface for all plugins which want to Load or Save files and create Objects.
Definition: LoadSaveInterface.hh:59
LoggingInterface.hh
PickingInterface.hh
TypeInterface
Interface class for type definitions.
Definition: TypeInterface.hh:63
TypeLightPlugin::computeClickOnTrackball
bool computeClickOnTrackball(const QPoint &_v2D, ACG::Vec3d &_clickOnSphere, ACG::GLState &_state)
Compute click on trackball containing the light source.
Definition: TypeLight.cc:667
TypeLightPlugin::updateLights
void updateLights()
Update light sources&#39; positions.
Definition: TypeLight.cc:766
TypeLightPlugin::slotPickModeChanged
void slotPickModeChanged(const std::string &_pickMode)
The pickingMode has changed.
Definition: TypeLight.cc:294
MouseInterface
Interface class for receiving mouse events.
Definition: MouseInterface.hh:61
LoggingInterface
Interface for all Plugins which do logging to the logging window of the framework.
Definition: LoggingInterface.hh:112
TypeLightPlugin
Definition: TypeLight.hh:62
TypeLightPlugin::rotateLightDirection
void rotateLightDirection(ACG::Vec3d &_axis, double _angle)
Rotate spot light direction.
Definition: TypeLight.cc:738
ACG::GLState
Definition: GLState.hh:213
BaseInterface.hh
TypeLightPlugin::supportedType
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: TypeLight.hh:163
PickingInterface
Allow access to picking functions.
Definition: PickingInterface.hh:62
ACG::GLMatrixT< double >
ToolbarInterface.hh
LoadSaveInterface.hh
TypeLightPlugin::addAssistLines
void addAssistLines()
Get number of non-directional light sources.
BaseInterface
Interface class from which all plugins have to be created.
Definition: BaseInterface.hh:65
DATA_LIGHT
#define DATA_LIGHT
Definition: Light.hh:58
ToolbarInterface
Add a toolbox to OpenFlipper.
Definition: ToolbarInterface.hh:62
TypeInterface.hh
Types.hh
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
OpenMesh::VectorT
Definition: Vector11T.hh:83
Light.hh
TypeLightPlugin::name
QString name()
Return a name for the plugin.
Definition: TypeLight.hh:151
TypeLightPlugin::objectDeleted
void objectDeleted(int _id)
An object was deleted.
Definition: TypeLight.cc:411
TypeLightPlugin::computeClickOnLightTrackball
bool computeClickOnLightTrackball(const QPoint &_v2D, ACG::Vec3d &_clickOnSphere, ACG::GLState &_state)
Compute click on trackball of light source.
Definition: TypeLight.cc:698
TypeLightPlugin::lightSources_
std::vector< int > lightSources_
Count light sources in scene.
Definition: TypeLight.hh:191
TypeLightPlugin::pluginsInitialized
void pluginsInitialized()
Initialize Plugin step 2.
Definition: TypeLight.cc:194
TypeLightPlugin::slotMouseEventLight
void slotMouseEventLight(QMouseEvent *_event)
Mouse Event from main application ( Light Mode )
Definition: TypeLight.cc:482
TypeLightPlugin::addEmpty
int addEmpty()
Create an empty object.
Definition: TypeLight.cc:368
TypeLightPlugin::findDepth
float findDepth()
Find depth of nearest light source.
Definition: TypeLight.cc:423