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

📄 soqt_moving_weighted_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_weighted_points_3.h $// $Id: SoQt_moving_weighted_points_3.h 37003 2007-03-10 16:55:12Z spion $////// Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>#ifndef CGAL_KINETIC_QT_MOVING_WEIGHTED_POINT_TABLE_3_H#define CGAL_KINETIC_QT_MOVING_WEIGHTED_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/nodes/SoSeparator.h>#include <Inventor/nodes/SoCoordinate3.h>#include <Inventor/nodes/SoSphere.h>#include <Inventor/nodekits/SoShapeKit.h>#include <Inventor/nodes/SoTransform.h>#include <Inventor/nodes/SoPointSet.h>#include <Inventor/nodes/SoGroup.h>#include <Inventor/nodes/SoDrawStyle.h>#include <Inventor/nodes/SoMaterial.h>#include <Inventor/nodes/SoText2.h>#include <Inventor/nodekits/SoAppearanceKit.h>//#include <CGAL/Kinetic/IO/Qt_gui_3.h>#include <Inventor/events/SoEvent.h>#include <Inventor/events/SoButtonEvent.h>#include <Inventor/events/SoKeyboardEvent.h>#include <Inventor/nodes/SoEventCallback.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.  How points are drawn can be controlled from the keyboard  - L toggles drawing labels.  - S has the points be drawn as spheres with radius equal to the square root of the weight.  - P has the points be drawn as GL points with some (constant) size  - T has tbe points be drawn as transparent spheres*/template <class Traits, class GUI>class SoQt_moving_weighted_points_3: public Ref_counted< SoQt_moving_weighted_points_3<Traits, GUI> >{protected:  typedef SoQt_moving_weighted_points_3<Traits, GUI> This;  typedef typename Traits::Instantaneous_kernel IK;  typedef typename Traits::Active_points_3_table MPT;  typedef typename Traits::Simulator Simulator;  typedef typename GUI::Listener Gui_listener;  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(typename MPT::Handle 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;private:  //! This cannot be trivially copied with out ill effects  SoQt_moving_weighted_points_3(const This &){ CGAL_assertion(0);}  const This operator=(const This &o) const  {    CGAL_assertion(0);  }public:  //! This is for a bitfield  typedef enum Draw_mode {POINT=1, SPHERE=0, TRANSPARENT_SPHERE=2}    Draw_mode;  //! Defaults to outline drawing  SoQt_moving_weighted_points_3( Traits tr,				 typename GUI::Handle sim ): tr_(tr),							      ik_(tr.instantaneous_kernel_object()),							      listener_(tr_.active_points_3_table_handle(), this),							      guil_(sim, this),							      siml_(sim->simulator(), this),							      rt_(tr_.kinetic_kernel_object().reverse_time_object()) {    soss_= NULL;    draw_labels_= true;    point_size_= 5;    direction_of_time_=CGAL::POSITIVE;    set_up_scene_graph(guil_.root());  };  virtual ~SoQt_moving_weighted_points_3() {    if (soss_!= NULL) {      soss_->unschedule();      delete soss_;    }  }  //! Access the SoCoordinate3 where it puts the current coordinates.  SoCoordinate3 *coordinate_node() const  {    return coords_.get();  }  //void set_radius(double radius);  void set_point_size(double ps);  virtual void write(std::ostream &out) const;  //! The 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 if the labels are drawn  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 .1;  }  double label_size() {    return 2*.1;  }  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;    }    else if (kbe->getKey()== SoKeyboardEvent::T && kbe->getState()== SoButtonEvent::UP) {      th->mode_=TRANSPARENT_SPHERE;      handled=true;    }    if (handled) {      // let keystrokes be reused      // eventCB->setHandled();      if (th->soss_ ==NULL) {	th->soss_= new SoOneShotSensor(update_callback, th);	th->soss_->schedule();      }    }

⌨️ 快捷键说明

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