|
http://www.sim.no http://www.coin3d.org |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
Inheritance diagram for SoXtExaminerViewer:

This class is the viewer considered to be the most "general purpose" viewer, and it is often used in rapid prototyping to examine simple models aswell as complete scenes (although for the latter, you might be better off with one of the other viewer classes).
Here is a complete, stand-alone example that shows how to set up an SoXtExaminerViewer as a model viewer that loads Inventor and VRML files from disk and places them inside the viewer for the end-user to examine:
#include <Inventor/Xt/SoXt.h> #include <Inventor/Xt/viewers/SoXtExaminerViewer.h> #include <Inventor/nodes/SoBaseColor.h> #include <Inventor/nodes/SoCone.h> #include <Inventor/nodes/SoSeparator.h> int main(int argc, char ** argv) { if (argc < 2) { (void)fprintf(stderr, "\n\n\tUsage: %s <modelfilename>\n\n", argc > 0 ? argv[0] : "viewerapp"); exit(1); } // Initialize SoXt and Inventor API libraries. This returns a main // window to use. Widget mainwin = SoXt::init(argc, argv, argv[0]); // Open the argument file.. SoInput in; SbBool ok = in.openFile(argv[1]); if (!ok) { exit(1); } // ..and import it. SoSeparator * root = SoDB::readAll(&in); if (root == NULL) { exit(1); } root->ref(); // Use the ExaminerViewer, for a nice interface for 3D model // inspection. SoXtExaminerViewer * viewer = new SoXtExaminerViewer(mainwin); viewer->setSceneGraph(root); viewer->show(); // Pop up the main window. SoXt::show(mainwin); // Loop until exit. SoXt::mainLoop(); // Clean up resources. delete viewer; root->unref(); return 0; }
SoXtExaminerViewer has a convenient interface for repositioning and reorientation of the camera, by panning, rotating and zooming it's position. The following controls can be used:
The SoXtExaminerViewer provides a user decoration's button for toggling between orthographic or perspective camera view volumes and projection methods. This is the bottom-most click button on the right decoration border.
It also inherits the decoration buttons from the SoXtFullViewer: the arrow for switching to "scenegraph interaction" mode, the hand for setting back to "camera interaction" mode, the house for "reset camera to home position", the blueprint house for "set new camera home position", the eye for "zoom camera out to view full scene" and the flashlight for setting "click to seek" mode.
Note that a common faulty assumption about all the viewer-classes is that user interaction (in the "examine"-mode, not the scenegraph-interaction mode) influences the model or 3D-scene in the view. This is not correct, as it is always the viewer's camera that is translated and rotated.
The initial position of the camera is placed such that all of the scenegraph's geometry fits within it's view.
Public Member Functions | |
| SoXtExaminerViewer (Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER) | |
| ~SoXtExaminerViewer () | |
| void | setAnimationEnabled (const SbBool enable) |
| SbBool | isAnimationEnabled (void) const |
| void | stopAnimating (void) |
| SbBool | isAnimating (void) const |
| void | setFeedbackVisibility (const SbBool enable) |
| SbBool | isFeedbackVisible (void) const |
| void | setFeedbackSize (const int size) |
| int | getFeedbackSize (void) const |
| virtual void | setViewing (SbBool enable) |
| virtual void | setCamera (SoCamera *camera) |
| virtual void | setCursorEnabled (SbBool enable) |
Protected Member Functions | |
| SoXtExaminerViewer (Widget parent, const char *name, SbBool embed, SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type, SbBool build) | |
| virtual void | leftWheelMotion (float val) |
| virtual void | bottomWheelMotion (float val) |
| virtual void | rightWheelMotion (float val) |
| virtual void | createViewerButtons (Widget parent, SbPList *buttonlist) |
| virtual const char * | getDefaultWidgetName (void) const |
| virtual const char * | getDefaultTitle (void) const |
| virtual const char * | getDefaultIconTitle (void) const |
| virtual SbBool | processSoEvent (const SoEvent *const event) |
| virtual void | setSeekMode (SbBool enable) |
| virtual void | actualRedraw (void) |
| virtual void | afterRealizeHook (void) |
Friends | |
| class | SoGuiExaminerViewerP |
| class | SoXtExaminerViewerP |
| SoXtExaminerViewer::SoXtExaminerViewer | ( | Widget | parent = NULL, |
|
| const char * | name = NULL, |
|||
| SbBool | embed = TRUE, |
|||
| SoXtFullViewer::BuildFlag | flag = BUILD_ALL, |
|||
| SoXtViewer::Type | type = BROWSER | |||
| ) |
Public constructor.
| SoXtExaminerViewer::~SoXtExaminerViewer | ( | ) |
The destructor.
| SoXtExaminerViewer::SoXtExaminerViewer | ( | Widget | parent, | |
| const char * | name, | |||
| SbBool | embed, | |||
| SoXtFullViewer::BuildFlag | flag, | |||
| SoXtViewer::Type | type, | |||
| SbBool | build | |||
| ) | [protected] |
Protected constructor for derived viewers.
| void SoXtExaminerViewer::setAnimationEnabled | ( | const SbBool | enable | ) |
Decide if it should be possible to start a spin animation of the model in the viewer by releasing the mouse button while dragging.
If the enable flag is FALSE and we're currently animating, the spin will be stopped.
| SbBool SoXtExaminerViewer::isAnimationEnabled | ( | void | ) | const |
Query whether or not it is possible to start a spinning animation by releasing the left mouse button while dragging the mouse.
| void SoXtExaminerViewer::stopAnimating | ( | void | ) |
Stop the model from spinning.
| SbBool SoXtExaminerViewer::isAnimating | ( | void | ) | const |
Query if the model in the viewer is currently in spinning mode after a user drag.
| void SoXtExaminerViewer::setFeedbackVisibility | ( | const SbBool | enable | ) |
Set the flag deciding whether or not to show the axis cross.
| SbBool SoXtExaminerViewer::isFeedbackVisible | ( | void | ) | const |
Check if the feedback axis cross is visible.
| void SoXtExaminerViewer::setFeedbackSize | ( | const int | size | ) |
Set the size of the feedback axiscross. The value is interpreted as an approximate percentage chunk of the dimensions of the total canvas.
| int SoXtExaminerViewer::getFeedbackSize | ( | void | ) | const |
Return the size of the feedback axis cross. Default is 25.
| void SoXtExaminerViewer::setViewing | ( | SbBool | enable | ) | [virtual] |
Set view mode.
If the view mode is on, user events will be caught and used to influence the camera position / orientation. If view mode is off, all events in the viewer canvas (like for instance keypresses or mouseclicks and -movements) will be passed along to the scene graph.
Default is to have the view mode active.
Reimplemented from SoXtFullViewer.
| void SoXtExaminerViewer::setCamera | ( | SoCamera * | camera | ) | [virtual] |
Set the camera we want the viewer to manipulate when interacting with the viewer controls.
The camera passed in as an argument to this method must already be part of the viewer's scenegraph. You do not inject viewpoint cameras to the viewer with this method.
You should rather insert a camera into the scene graph first (if necessary, often one will be present already), then register it as the camera used by the viewer controls with this method.
If the application code doesn't explicitly set up a camera through this method, the viewer will automatically scan through the scenegraph to find a camera to use. If no camera is available in the scenegraph at all, it will set up it's own camera.
Reimplemented from SoXtViewer.
| void SoXtExaminerViewer::setCursorEnabled | ( | SbBool | enable | ) | [virtual] |
Decide whether or not the mouse pointer cursor should be visible in the rendering canvas.
Reimplemented from SoXtViewer.
| void SoXtExaminerViewer::leftWheelMotion | ( | float | val | ) | [protected, virtual] |
Called repeatedly as the user drags the thumbwheel in the left frame. Override this method in subclassed viewers to provide your own functionality on the thumbwheel.
Reimplemented from SoXtFullViewer.
| void SoXtExaminerViewer::bottomWheelMotion | ( | float | val | ) | [protected, virtual] |
Called repeatedly as the user drags the thumbwheel in the bottom frame. Override this method in subclassed viewers to provide your own functionality on the thumbwheel.
Reimplemented from SoXtFullViewer.
| void SoXtExaminerViewer::rightWheelMotion | ( | float | val | ) | [protected, virtual] |
Called repeatedly as the user drags the thumbwheel in the right frame. Override this method in subclassed viewers to provide your own functionality on the thumbwheel.
Reimplemented from SoXtFullViewer.
| void SoXtExaminerViewer::createViewerButtons | ( | Widget | parent, | |
| SbPList * | buttonlist | |||
| ) | [protected, virtual] |
Set up the viewer buttons with pixmaps and event connections.
One important note if you want to override this method to add your own buttons to the list (in the explanation below, it is assumed that you know how virtual function table pointers are handled by C++):
createViewerButtons() is called (indirectly) from the constructors of the viewer classes. This means that you need to delay it's invocation until your own subclass's constructor is run, because otherwise your re-implementation won't have been added to the internal virtual function table yet.
Delaying a superclass viewer from building it's decorations is done by passing build==FALSE as the last argument of the protected constructors. You will then have to explicitly trigger the building in your own constructor.
Here's a minimal example that shows the steps needed to be able to override createViewerButtons() from SoXtExaminerViewer:
class MyExaminerViewer : public SoXtExaminerViewer { public: MyExaminerViewer(Widget parent); protected: virtual void createViewerButtons(Widget parent, SbPList * buttonlist); }; MyExaminerViewer::MyExaminerViewer(Widget parent) : SoXtExaminerViewer(parent, NULL, TRUE, SoXtFullViewer::BUILD_ALL, SoXtFullViewer::BROWSER, // build == FALSE, to delay creation of decorations FALSE) { // Explicitly trigger the construction of viewer decorations. Widget widget = this->buildWidget(this->getParentWidget()); this->setBaseWidget(widget); } void MyExaminerViewer::createViewerButtons(Widget parent, SbPList * buttonlist) { SoXtExaminerViewer::createViewerButtons(parent, buttonlist); // [now add your own button(s) to the buttonlist] }
Reimplemented from SoXtFullViewer.
| const char * SoXtExaminerViewer::getDefaultWidgetName | ( | void | ) | const [protected, virtual] |
This method returns the default name of a component widget class.
It should be overridden by derived non-abstract classes for the topmost widget in the component to have a proper name.
Reimplemented from SoXtRenderArea.
| const char * SoXtExaminerViewer::getDefaultTitle | ( | void | ) | const [protected, virtual] |
This method returns the default window caption string of the component.
It should be overridden by derived non-abstract classes so the window and popup menu will get a proper title.
Reimplemented from SoXtRenderArea.
| const char * SoXtExaminerViewer::getDefaultIconTitle | ( | void | ) | const [protected, virtual] |
This method returns the default icon title of the component.
It should be overridden by derived non-abstract classes so icons will get proper titles.
Reimplemented from SoXtRenderArea.
| SbBool SoXtExaminerViewer::processSoEvent | ( | const SoEvent *const | event | ) | [protected, virtual] |
Toolkit-native events are attempted converted to Coin-generic events in the SoXtRenderArea::processEvent() method. If this succeeds, they are forwarded to this method.
This is a virtual method, and is overridden in it's subclasses to catch events of particular interest to the viewer classes, for instance.
Return TRUE iff the event was processed. If not it should be passed on further up in the inheritance hierarchy by the caller. This last point is extremely important to take note of if you are expanding the toolkit with your own viewer class.
This method is not part of the original SGI InventorXt API. Note that you can still override the toolkit-native processEvent() method instead of this "generic" method.
Reimplemented from SoXtFullViewer.
| void SoXtExaminerViewer::setSeekMode | ( | SbBool | enable | ) | [protected, virtual] |
Put the viewer in or out of "waiting-to-seek" mode.
If the user performs a mouse button click when the viewer is in "waiting-to-seek" mode, the camera will be repositioned so the camera focal point lies on the point of the geometry under the mouse cursor.
Reimplemented from SoXtViewer.
| void SoXtExaminerViewer::actualRedraw | ( | void | ) | [protected, virtual] |
This method instantly redraws the normal (non-overlay) scenegraph by calling SoSceneManager::render().
Subclasses may override this method to add their own rendering before or after Coin renders it's scenegraph.
The following is a complete example that demonstrates one way of adding both a background image and foreground (overlay) geometry to the "normal" rendering:
// This example shows how to put a permanent background image on your // viewer canvas, below the 3D graphics, plus overlay foreground // geometry. Written by mortene. Copyright Systems in Motion 2002. // ************************************************************************* #include <Inventor/Xt/SoXt.h> #include <Inventor/Xt/viewers/SoXtExaminerViewer.h> #include <Inventor/nodes/SoBaseColor.h> #include <Inventor/nodes/SoCone.h> #include <Inventor/nodes/SoCube.h> #include <Inventor/nodes/SoImage.h> #include <Inventor/nodes/SoLightModel.h> #include <Inventor/nodes/SoOrthographicCamera.h> #include <Inventor/nodes/SoRotationXYZ.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoTranslation.h> #include <GL/gl.h> // ************************************************************************* class MyExaminerViewer : public SoXtExaminerViewer { public: MyExaminerViewer(Widget parent, const char * filename); ~MyExaminerViewer(); protected: virtual void actualRedraw(void); private: SoSeparator * bckgroundroot; SoSeparator * foregroundroot; SoRotationXYZ * arrowrotation; }; MyExaminerViewer::MyExaminerViewer(Widget parent, const char * filename) : SoXtExaminerViewer(parent) { // Coin should not clear the pixel-buffer, so the background image // is not removed. this->setClearBeforeRender(FALSE, TRUE); // Set up background scenegraph with image in it. this->bckgroundroot = new SoSeparator; this->bckgroundroot->ref(); SoOrthographicCamera * cam = new SoOrthographicCamera; cam->position = SbVec3f(0, 0, 1); cam->height = 1; // SoImage will be at z==0.0. cam->nearDistance = 0.5; cam->farDistance = 1.5; SoImage * img = new SoImage; img->vertAlignment = SoImage::HALF; img->horAlignment = SoImage::CENTER; img->filename = filename; this->bckgroundroot->addChild(cam); this->bckgroundroot->addChild(img); // Set up foreground, overlayed scenegraph. this->foregroundroot = new SoSeparator; this->foregroundroot->ref(); SoLightModel * lm = new SoLightModel; lm->model = SoLightModel::BASE_COLOR; SoBaseColor * bc = new SoBaseColor; bc->rgb = SbColor(1, 1, 0); cam = new SoOrthographicCamera; cam->position = SbVec3f(0, 0, 5); cam->height = 10; cam->nearDistance = 0; cam->farDistance = 10; const double ARROWSIZE = 2.0; SoTranslation * posit = new SoTranslation; posit->translation = SbVec3f(-2.5 * ARROWSIZE, 1.5 * ARROWSIZE, 0); arrowrotation = new SoRotationXYZ; arrowrotation->axis = SoRotationXYZ::Z; SoTranslation * offset = new SoTranslation; offset->translation = SbVec3f(ARROWSIZE/2.0, 0, 0); SoCube * cube = new SoCube; cube->width = ARROWSIZE; cube->height = ARROWSIZE/15.0; this->foregroundroot->addChild(cam); this->foregroundroot->addChild(lm); this->foregroundroot->addChild(bc); this->foregroundroot->addChild(posit); this->foregroundroot->addChild(arrowrotation); this->foregroundroot->addChild(offset); this->foregroundroot->addChild(cube); } MyExaminerViewer::~MyExaminerViewer() { this->bckgroundroot->unref(); this->foregroundroot->unref(); } void MyExaminerViewer::actualRedraw(void) { // Must set up the OpenGL viewport manually, as upon resize // operations, Coin won't set it up until the SoGLRenderAction is // applied again. And since we need to do glClear() before applying // the action.. const SbViewportRegion vp = this->getViewportRegion(); SbVec2s origin = vp.getViewportOriginPixels(); SbVec2s size = vp.getViewportSizePixels(); glViewport(origin[0], origin[1], size[0], size[1]); const SbColor col = this->getBackgroundColor(); glClearColor(col[0], col[1], col[2], 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render our scenegraph with the image. SoGLRenderAction * glra = this->getGLRenderAction(); glra->apply(this->bckgroundroot); // Render normal scenegraph. SoXtExaminerViewer::actualRedraw(); // Increase arrow angle with 1/1000 ° every frame. arrowrotation->angle = arrowrotation->angle.getValue() + (0.001 / M_PI * 180); // Render overlay front scenegraph. glClear(GL_DEPTH_BUFFER_BIT); glra->apply(this->foregroundroot); } // ************************************************************************* int main(int argc, char ** argv) { if (argc != 2) { (void)fprintf(stderr, "\n\n\tUsage: %s <image-filename>\n\n", argv[0]); exit(1); } Widget window = SoXt::init(argv[0]); MyExaminerViewer * viewer = new MyExaminerViewer(window, argv[1]); viewer->setSceneGraph(new SoCone); viewer->show(); SoXt::show(window); SoXt::mainLoop(); delete viewer; return 0; } // *************************************************************************
Reimplemented from SoXtViewer.
| void SoXtExaminerViewer::afterRealizeHook | ( | void | ) | [protected, virtual] |
A function "hook" / callback invoked just after the window for the component has been realized.
Override this if you need specific initialization for your own component or viewer class to happen right after it has been made visible, but remember to call upwards in the inheritance hierarchy:
void MyLittleViewer::afterRealizeHook(void) { <superclass>::afterRealizeHook(); // [own initialization here] }
Reimplemented from SoXtRenderArea.
Copyright © 1998-2005 by Systems in Motion AS. All rights reserved.
Generated on Tue Dec 2 23:15:46 2008 for SoXt by Doxygen. 1.4.7