⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soqt_moving_points_3.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 2 页
字号:
// Copyright (c) 2005  Stanford University (USA).// All rights reserved.//// This file is part of CGAL (www.cgal.org); 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; version 2.1 of the License.// See the file LICENSE.LGPL distributed with CGAL.//// Licensees holding a valid commercial license may use this file in// accordance with the commercial license agreement provided with the software.//// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.//// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.3-branch/Kinetic_data_structures/demo/Kinetic_data_structures/include/SoQt_moving_points_3.h $// $Id: SoQt_moving_points_3.h 37003 2007-03-10 16:55:12Z spion $////// Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>#ifndef CGAL_KINETIC_QT_MOVING_POINT_TABLE_3_H#define CGAL_KINETIC_QT_MOVING_POINT_TABLE_3_H#include <CGAL/Kinetic/basic.h>#include <CGAL/Kinetic/Ref_counted.h>#include <CGAL/Kinetic/Simulator_objects_listener.h>#include "SoQt_handle.h"#include <Inventor/events/SoButtonEvent.h>#include <Inventor/events/SoEvent.h>#include <Inventor/events/SoKeyboardEvent.h>#include <Inventor/nodekits/SoAppearanceKit.h>#include <Inventor/nodekits/SoShapeKit.h>#include <Inventor/nodes/SoCoordinate3.h>#include <Inventor/nodes/SoDrawStyle.h>#include <Inventor/nodes/SoEventCallback.h>#include <Inventor/nodes/SoGroup.h>#include <Inventor/nodes/SoMaterial.h>#include <Inventor/nodes/SoPointSet.h>#include <Inventor/nodes/SoSeparator.h>#include <Inventor/nodes/SoSphere.h>#include <Inventor/nodes/SoText2.h>#include <Inventor/nodes/SoTransform.h>#include <Inventor/sensors/SoOneShotSensor.h>CGAL_KINETIC_BEGIN_NAMESPACE;//! A graphical moving point set in 3D/*!  This class shows how to interact with the Coin and Qt based 3D gui.  The appearance can be controlled from the keyboard.  - L toggles labels  - S draws the points as constant radius spheres  - P draws the points as points*/template <class SimTraits, class GUI>class SoQt_moving_points_3: public Ref_counted< SoQt_moving_points_3<SimTraits, GUI> >{protected:  typedef SoQt_moving_points_3<SimTraits, GUI> This;  typedef typename SimTraits::Active_points_3_table MPT;  typedef typename SimTraits::Simulator Simulator;  typedef typename GUI::Listener Gui_listener;  typedef typename SimTraits::Instantaneous_kernel IK;  typedef typename Simulator::Listener Simulator_listener;  typedef CGAL::Kinetic::Simulator_objects_listener<Simulator_listener, This> Siml;  friend class CGAL::Kinetic::Simulator_objects_listener<Simulator_listener, This> ;  class Guil;  typedef typename MPT::Data::Coordinate::NT NT;  class Table_listener: public MPT::Listener  {    typedef typename MPT::Listener P;  public:    Table_listener(MPT* mpt, This *t): MPT::Listener(mpt), t_(t){}    virtual void new_notification(typename MPT::Listener::Notification_type et) {      if (et == P::IS_EDITING && P::notifier()->is_editing()==false) {	if (P::notifier()->inserted_begin() != P::notifier()->inserted_end()	    || P::notifier()->erased_begin() != P::notifier()->erased_end()) {	  t_->update_tree();	  t_->update_coordinates();	}      }    }  protected:    This *t_;  };  friend class Table_listener;  typedef typename SimTraits::Active_points_3_table Moving_point_table;private:  //! This cannot be trivially copied with out ill effects  SoQt_moving_points_3(const This &){CGAL_assertion(0);}  const This operator=(const This &o) const  {    CGAL_assertion(0);  }public:  //! The different modes for drawing  typedef enum Draw_mode {POINT=1, SPHERE=0}    Draw_mode;  //! Defaults to outline drawing  SoQt_moving_points_3(SimTraits tr, typename GUI::Handle sim):  tr_(tr),								  ik_(tr.instantaneous_kernel_object()),								  listener_(tr.active_points_3_table_handle(), this),								  guil_(sim, this),								  siml_(tr.simulator_handle(), this),								  rt_(tr.kinetic_kernel_object().reverse_time_object()) {    soss_= NULL;    draw_labels_= true;    radius_=.1;    point_size_= 5;    direction_of_time_=CGAL::POSITIVE;    set_up_scene_graph(guil_.root());    sim->soqt_examiner_viewer_pointer()->getPointSizeLimits(point_size_bounds_, point_size_granularity_);  };  virtual ~SoQt_moving_points_3() {    if (soss_!= NULL) {      soss_->unschedule();      delete soss_;    }  }  //! The node where the coordinates are put.  SoCoordinate3 *coordinate_node() const  {    return coords_.get();  }  //! Set the radius to draw the points.  void set_radius(double radius);  //! The the point size.  void set_point_size(double ps);  virtual void write(std::ostream &out) const;  //! The current draw mode  Draw_mode draw_mode() {    return mode_;  }  //! Set whether points or balls are drawn  void set_draw_mode(Draw_mode dm) {    mode_= dm;    update_tree();    update_coordinates();  }  //! Set whether the point labels are displayed  bool draw_labels() const  {    return draw_labels_;  }  //! Set the draw_labels bit.  void set_draw_labels(bool tf) {    draw_labels_=tf;    update_tree();    update_coordinates();  }protected:  CGAL::Sign direction_of_time() const  {    return direction_of_time_;  }  void reverse_time();  class Guil: public Gui_listener  {  public:    Guil(typename GUI::Handle& h, This *t): Gui_listener(h), t_(t){}    void new_notification(typename Gui_listener::Notification_type nt) {      if (nt== Gui_listener::CURRENT_TIME) {	t_->update_coordinates();      }    }  protected:    This *t_;  };  friend class Guil;  void set_up_scene_graph(SoSeparator* parent);  void update_coordinates();  void update_tree();  double label_offset() {    return radius_;  }  double label_size() {    return 2*radius_;  }  static void update_callback(void *data, SoSensor *) {    This *th = reinterpret_cast<This*>(data);    delete th->soss_;    th->soss_=NULL;    th->update_tree();    th->update_coordinates();  }  static void keyboard_callback(void *data, SoEventCallback *eventCB) {    This *th = reinterpret_cast<This*>(data);    const SoEvent *event= eventCB->getEvent();    CGAL_assertion(event->isOfType(SoKeyboardEvent::getClassTypeId()));    const SoKeyboardEvent *kbe= reinterpret_cast<const SoKeyboardEvent*>(event);    //std::cout << "Pressed " << kbe->getPrintableCharacter() << std::endl;    bool handled=false;    if (kbe->getKey()== SoKeyboardEvent::L && kbe->getState()== SoButtonEvent::UP) {      bool dl= th->draw_labels();      handled= true;      th->draw_labels_=!dl;    }    else if (kbe->getKey()== SoKeyboardEvent::S && kbe->getState()== SoButtonEvent::UP) {      th->mode_=SPHERE;      handled=true;    }    else if (kbe->getKey()== SoKeyboardEvent::P && kbe->getState()== SoButtonEvent::UP) {      th->mode_=POINT;      handled=true;    }    if (handled) {      //eventCB->setHandled();      if (th->soss_ ==NULL) {	th->soss_= new SoOneShotSensor(update_callback, th);	th->soss_->schedule();      }    }  }  unsigned int size() {    unsigned int ct=0;    for (typename MPT::Key_iterator it= tr_.active_points_3_table_handle()->keys_begin();	 it != tr_.active_points_3_table_handle()->keys_end(); ++it, ++ct);    return ct;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -