PluginFunctionsViewControls.hh 16.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70




//=============================================================================
//
//  Standard Functions
//
//=============================================================================

/**
 * \file PluginFunctions.hh
 * This file contains functions which can be used by plugins to access data in the framework.
 */

//
#ifndef PLUGINFUNCTIONS_VIEWCONTROL_HH
#define PLUGINFUNCTIONS_VIEWCONTROL_HH

#include <OpenFlipper/common/Types.hh>

#include <ACG/Scenegraph/SceneGraph.hh>
Jan Möbius's avatar
Jan Möbius committed
71
#include <ACG/Scenegraph/DrawModes.hh>
72 73 74 75 76 77 78 79 80 81
#include <ACG/GL/GLState.hh>
#include <OpenFlipper/common/ViewerProperties.hh>

/** The Namespace PluginFunctions contains functions for all plugins. These functions should be used to get the
 *  objects to work on or to set modes in the examiner widget. */
namespace PluginFunctions {

const int ALL_VIEWERS   = -2;
const int ACTIVE_VIEWER = -1;

82 83 84 85 86 87 88 89
const int VIEW_FREE   = 0;
const int VIEW_TOP    = 1;
const int VIEW_BOTTOM = 2;
const int VIEW_LEFT   = 3;
const int VIEW_RIGHT  = 4;
const int VIEW_FRONT  = 5;
const int VIEW_BACK   = 6;

90 91 92 93 94 95
//=======================================
// Get/set status of viewers
    /** @name Viewer Status and properties
    * @{ */
//=======================================

Jan Möbius's avatar
Jan Möbius committed
96 97 98 99
/** \brief Get the viewer properties
 *  Use this functions to get basic viewer properties such as backgroundcolor or rendering options.
 *
 * @param _id Which viewer should be used? ACTIVE_VIEWER will get the properties of the active Viewer which is the default
100 101
 */
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
102
Viewer::ViewerProperties& viewerProperties(int _id = ACTIVE_VIEWER );
103 104 105 106 107 108 109 110 111 112 113 114 115

/** @} */


//=======================================
// View settings
    /** @name View settings
    * @{ */
//=======================================

/** Lock scene rotation via mouse
 *
 * @param _mode allow or disallow rotation
116 117 118 119
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
120 121
 */
DLLEXPORT
122 123 124 125 126 127 128 129 130 131 132
void allowRotation(bool _mode, int _viewer = ACTIVE_VIEWER);

/** is scene rotation locked
 *
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
bool allowRotation(int _viewer = ACTIVE_VIEWER);
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

/** \brief Set current GL Context to main context
 */
DLLEXPORT
void setMainGLContext();


/** \brief Set the viewing direction
 * @param _dir direction
 * @param _up up vector
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
149
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up  , int _viewer = ACTIVE_VIEWER);
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
/** \brief Retrieve a viewing ray from the active examiner that can be used for raycasting.
 *
 * @param   _x              The widgetspace x Coordinate
 * @param   _y              The widgetspace y Coordinate
 * @param   _outOrigin      A reference to the ACG::Vec3d that shall hold the origin
 *                          of the viewing Ray in worldspace coordinates.
 * @param   _outDirection   A reference to the ACG::Vec3d that shall hold the direction
 *                          of the viewing Ray in worldspace (normalized)
 **/
DLLEXPORT
void viewingRay(int _x, int _y,
               ACG::Vec3d& _outOrigin, ACG::Vec3d& _outDirection);

/** \brief Retrieve a viewing ray from the specified examiner that can be used for raycasting.
 *
 * @param   _x              The widgetspace x Coordinate
 * @param   _y              The widgetspace y Coordinate
 * @param   _outOrigin      A reference to the ACG::Vec3d that shall hold the origin
 *                          of the viewing Ray in worldspace coordinates.
 * @param   _outDirection   A reference to the ACG::Vec3d that shall hold the direction
 *                          of the viewing Ray in worldspace (normalized)
 * @param   _viewerIndex    The index to specify an examiner that shall be used
 **/
DLLEXPORT
void viewingRay(int _x, int _y,
               ACG::Vec3d& _outOrigin, ACG::Vec3d& _outDirection, int _viewerIndex);

178 179 180 181 182 183 184 185 186 187 188 189
/** \brief Set the look at transformation directly
* @param _eye eye point
* @param _center center point
* @param _up up vector
* @param _viewer Id of the viewer to use.
*                ALL_VIEWERS    will set all viewers (Default)
*                ACTIVE_VIEWER active viewer
*                0..3 Choose viewer explicitly
*/
DLLEXPORT
void lookAt(const ACG::Vec3d& _eye, const ACG::Vec3d& _center, const ACG::Vec3d& _up, int _viewer = ACTIVE_VIEWER);

190 191 192 193 194 195 196 197 198 199 200
/** \brief Set the Scene position
 * @param _center Center of the current scene
 * @param _radius Radius of the scene ( Use scene_radius to get the current radius )
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
void setScenePos(const ACG::Vec3d& _center, const double _radius  , int _viewer = ALL_VIEWERS);

201 202 203 204 205 206 207 208 209 210
/** \brief Set the trackball Center
*
* The scene is rotated around the trackball center when using the mouse 
*
* @param _center Center of the trackball
* @param _viewer Id of the viewer to use.
*                ALL_VIEWERS    will set all viewers (Default)
*                ACTIVE_VIEWER active viewer
*                0..3 Choose viewer explicitly
*/
Jan Möbius's avatar
Jan Möbius committed
211
DLLEXPORT
212 213 214 215 216 217 218 219 220 221 222 223
void setTrackBallCenter(const ACG::Vec3d& _center, int _viewer );


/** \brief Get the trackball Center
*
* The scene is rotated around the trackball center when using the mouse 
*
* @param _viewer Id of the viewer to use.
*                ALL_VIEWERS    will set all viewers (Default)
*                ACTIVE_VIEWER active viewer
*                0..3 Choose viewer explicitly
*/
Jan Möbius's avatar
Jan Möbius committed
224
DLLEXPORT
Dirk Wilden's avatar
Dirk Wilden committed
225
const ACG::Vec3d trackBallCenter( int _viewer );
226

227 228 229 230 231 232 233 234
/** \brief Set the scene position
 *
 * Same as  setScenePos(const ACG::Vec3d& _center, double _radius) but reuses the current radius
 *
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
235
 * @param _center Center of the current scene
236 237 238 239 240 241 242 243
 */
DLLEXPORT
void setScenePos(const ACG::Vec3d& _center  , int _viewer = ALL_VIEWERS);

/** \brief Get the current scene center
 *
 */
DLLEXPORT
244
const ACG::Vec3d sceneCenter( int _viewer = ALL_VIEWERS );
245

246
/** \brief Returns the current scene radius from the active examiner widget
247 248 249 250 251 252
 *
 * Returns the Radius of the scene
 */
DLLEXPORT
double sceneRadius();

253 254 255 256 257 258 259 260
DLLEXPORT
/** \brief Returns the current scene radius from a given examiner viewer
*
* Returns the Radius of the scene
* @param _viewer Give the viewer which should be asked for its current scene radius
*/
double sceneRadius( int _viewer );

261 262 263
DLLEXPORT
void setSceneRadius(double _radius , int _viewer = ALL_VIEWERS);

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
/** \brief Translate viewer pos by given vector
 *
 * Translates the scene by a given vector. ( This is only a view transformation and does not
 * effect the scene center. To really translate the scene, use setScenePos );
 * @param _vector translation
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
void translate( const ACG::Vec3d &_vector  , int _viewer = ALL_VIEWERS);

/** \brief Rotate Scene around axis
 *
 * Rotates the current scene.
 * @param _axis   Rotation axis
 * @param _angle  Rotation Angle
 * @param _center Rotation Center
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
void rotate(const ACG::Vec3d&  _axis,
            const double       _angle,
            const ACG::Vec3d&  _center,
            int                _viewer = ALL_VIEWERS);


/** \brief Go to home position
 *
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
void viewHome(int _viewer = ALL_VIEWERS);

/** \brief View the whole scene
 *
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
void viewAll(int _viewer = ALL_VIEWERS);

/** \brief Get the current viewing Direction
 *
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
322
ACG::Vec3d viewingDirection(int _viewer = ACTIVE_VIEWER);
323

324 325 326 327 328 329 330 331 332
/** \brief Check if the projection is orthographic
 * @param _viewer Id of the viewer to use.
 *                ALL_VIEWERS    will set all viewers (Default)
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
bool isProjectionOrthographic( int _viewer = ACTIVE_VIEWER );

333 334 335 336 337 338 339
/** \brief Get the current viewer position
 *
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
340
ACG::Vec3d eyePos(int _viewer = ACTIVE_VIEWER);
341 342 343 344 345 346 347 348

/** \brief Get the current up vector
 *
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
349
ACG::Vec3d upVector(int _viewer = ACTIVE_VIEWER);
350 351 352

/** \brief Switch to orthographic Projection
 *
Jan Möbius's avatar
Jan Möbius committed
353 354 355
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
356 357
 */
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
358
void orthographicProjection( int _viewer = ALL_VIEWERS );
359

360 361 362 363 364
/** \brief Set field of view angle
 *
 * @param _fovy   Field of view (in (1, 180) degrees)
 */
DLLEXPORT
365
void setFOVY( double _fovy );
366

367 368 369 370 371
/** \brief Get field of view angle
 */
DLLEXPORT
double fovy(int _viewer = ACTIVE_VIEWER);

372 373
/** \brief Switch to perspective Projection
 *
Jan Möbius's avatar
Jan Möbius committed
374 375 376
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
377 378
 */
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
379
void perspectiveProjection( int _viewer = ALL_VIEWERS );
380 381 382 383 384 385 386 387 388

/** \brief Set the draw Mode of a Viewer.\n
 *
 * The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
 * They can be combined.
 *
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
389 390
 *
 * @param _mode New drawmode of the given viewer
391 392
 */
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
393
void setDrawMode( const ACG::SceneGraph::DrawModes::DrawMode& _mode , int _viewer = ALL_VIEWERS);
394 395 396 397 398 399 400 401 402

/** \brief Get the current draw Mode of a Viewer
 *
 *
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
403
ACG::SceneGraph::DrawModes::DrawMode drawMode( int _viewer = ACTIVE_VIEWER );
404 405 406 407 408 409 410 411


/** \brief Set the background color of the examiner widget.
 *
 */
DLLEXPORT
void setBackColor( OpenMesh::Vec4f _color);

412 413 414 415 416 417 418 419 420 421 422 423
/** \brief Set a fixed View for a viewer
 *
 *
 * @param _mode id for the mode
 * @param _viewer Id of the viewer to use.
 *                ACTIVE_VIEWER active viewer
 *                0..3 Choose viewer explicitly
 */
DLLEXPORT
void setFixedView(int _mode, int _viewer = ACTIVE_VIEWER );


424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
/** @} */


//=======================================
// Do animations in examiner viewer
    /** @name Animations
    * @{ */
//=======================================

/**  Fly to point and set new viewing direction (animated).
 * @param _position New viewer position ( the new eye point of the viewer )
 * @param _center   The new scene center ( the point we are looking at )
 * @param _time     Animation time in ms
 */
DLLEXPORT
void flyTo (const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time=1000.0);

441 442 443 444 445 446 447 448 449 450

/**  Fly to point and keep viewing direction (animated).
 * @param _center    The new scene center ( the point we are looking at )
 * @param _move_back Get closer if \c _move_back=\c true, get more distant else.
 * @param _time      Animation time in ms
 */
DLLEXPORT
void flyTo (const ACG::Vec3d &_center, bool _move_back = true, double _time=1000.0);


451 452 453 454 455 456 457 458
/** @} */

//=======================================
// Provide snapshot functions
    /** @name Snapshots
    * @{ */
//=======================================

Mike Kremer's avatar
Mike Kremer committed
459
/**  Take a snapshot of the current view
460 461 462 463 464 465 466 467 468 469 470 471
 * @param _viewer   Viewer id
 * @param _image    An image to store pixel data in
 * @param _width    Image width 
 * @param _height   Image height
 * @param _alpha    Make background transparent
 * @param _hideCoordsys   Hide coordsys node
 * @param _samples  Number of samples (multisampling)
 */
DLLEXPORT
void viewerSnapshot(int _viewer, QImage& _image, int _width = 0, int _height = 0,
                    bool _alpha = false, bool _hideCoordsys = false, int _samples = 1);

472 473
/** @} */

474 475 476
DLLEXPORT
void invalidatePickCaches();

477 478 479
}

#endif //PLUGINFUNCTIONS_HH