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

📄 soqt_moving_points_3.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 2 页
字号:
  }  float fix_point_size(double ps) const {    if (ps <= point_size_bounds_[0]) return point_size_bounds_[0];    else if (ps >= point_size_bounds_[1]) return point_size_bounds_[1];    return ps;  }  Draw_mode mode_;  bool draw_labels_;  double radius_;  SbVec2f point_size_bounds_;  float point_size_granularity_;  double point_size_;  SimTraits tr_;  IK ik_;  //! I don't really want this mutable, but Inventor doesn't like constant nodes  mutable SoQt_handle<SoCoordinate3> coords_;  SoQt_handle<SoGroup> spheres_;  SoQt_handle<SoShapeKit> points_;  SoQt_handle<SoDrawStyle> style_;  SoQt_handle<SoGroup> labels_;  CGAL::Sign direction_of_time_;  SoOneShotSensor* soss_;  Table_listener listener_;  Guil guil_;  Siml siml_;  typename SimTraits::Kinetic_kernel::Reverse_time rt_;};template <class Tr, class G>void SoQt_moving_points_3<Tr, G>::update_coordinates(){  //std::cout << "updateing coordinates\n";  //if (parent_==NULL) return;  ik_.set_time(guil_.notifier()->current_time());  coords_->point.setNum(size());  SbVec3f *pts= coords_->point.startEditing();  SbVec3f *vpts=NULL;  if (points_!= NULL) {    SoCoordinate3 *c= SO_GET_PART(points_, "coordinate3", SoCoordinate3);    vpts= c->point.startEditing();  }  int cp=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, ++cp) {    //std::cout << "drawing point " << *it  << "= " << ik_.to_static(*it) << std::endl;    typename IK::Static_kernel::Point_3 pt= ik_.current_coordinates_object()(*it);    pts[it->to_index()].setValue(CGAL::to_double(pt.x()), CGAL::to_double(pt.y()),			      CGAL::to_double(pt.z()));    if (vpts != NULL) vpts[cp].setValue(CGAL::to_double(pt.x()),					CGAL::to_double(pt.y()),					CGAL::to_double(pt.z()));    if (spheres_!= NULL) {      SoNode *n= spheres_->getChild(cp);      CGAL_assertion(n->isOfType(SoShapeKit::getClassTypeId()));      SoShapeKit *sh= reinterpret_cast<SoShapeKit*>(n);      SoTransform *tr= SO_GET_PART(sh, "localTransform", SoTransform);      tr->translation.setValue(CGAL::to_double(pt.x()), CGAL::to_double(pt.y()),			       CGAL::to_double(pt.z()));    }    if (labels_!= NULL) {      SoNode *n= labels_->getChild(cp);      CGAL_assertion(n->isOfType(SoShapeKit::getClassTypeId()));      SoShapeKit *sh= reinterpret_cast<SoShapeKit*>(n);      SoTransform *tr= SO_GET_PART(sh, "localTransform", SoTransform);      tr->translation.setValue(CGAL::to_double(pt.x())+radius_, CGAL::to_double(pt.y())+radius_,			       CGAL::to_double(pt.z())+radius_);    }  }  coords_->point.finishEditing();  if (vpts!= NULL) {    SoCoordinate3 *c= SO_GET_PART(points_, "coordinate3", SoCoordinate3);    c->point.finishEditing();  }}template <class Tr, class G>void SoQt_moving_points_3<Tr, G>::update_tree(){  //if (parent_==NULL) return;  int maxl=-1;  int num=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) {    if (static_cast<int>(it->to_index()) > maxl) maxl= it->to_index();    ++num;  }  if (labels_ != NULL) {    guil_.root()->removeChild(labels_.get());    labels_=NULL;  }  if (points_ != NULL) {    guil_.root()->removeChild(points_.get());    points_=NULL;  }  if (spheres_ != NULL) {    guil_.root()->removeChild(spheres_.get());    spheres_=NULL;  }  if (maxl==-1) return;  //std::cout << "updateing tree\n";  coords_->point.setNum(maxl+1);  if (mode_==POINT ) {    points_ = new SoShapeKit;    SoQt_handle<SoCoordinate3> c= new SoCoordinate3;    c->point.setNum(num);    SoQt_handle<SoMaterial> mat= new SoMaterial;    mat->diffuseColor.setValue(.8, 0,0);    mat->ambientColor.setValue(.8,0,0);    points_->setPart("material", mat.get());    points_->setPart("coordinate3", c.get());    SoQt_handle<SoPointSet> ps= new SoPointSet;    ps->numPoints.setValue(num);    points_->setPart("shape", ps.get());    SoQt_handle<SoAppearanceKit> ak= new SoAppearanceKit;    ak->setPart("drawStyle", style_.get());    points_->setPart("appearance", ak.get());    guil_.root()->addChild(points_.get());  }  else {    spheres_= new SoGroup;    guil_.root()->addChild(spheres_.get());    SoQt_handle<SoMaterial> smat= new SoMaterial;    smat->diffuseColor.setValue(.8, 0,0);    for (int i=0; i< num; ++i) {      SoQt_handle<SoShapeKit> kit = new SoShapeKit;      spheres_->addChild(kit.get());      SoQt_handle<SoSphere> s= new SoSphere;      s->radius.setValue(radius_);      kit->setPart("shape", s.get());      SoQt_handle<SoTransform> tr= new SoTransform;      kit->setPart("localTransform", tr.get());      kit->setPart("material", smat.get());    }  }  if (draw_labels_ != 0) {    SoQt_handle<SoMaterial> mat= new SoMaterial;    mat->diffuseColor.setValue(1,1,1);    mat->emissiveColor.setValue(1,1,1);    labels_= new SoGroup;    for (typename MPT::Key_iterator kit = tr_.active_points_3_table_handle()->keys_begin();	 kit != tr_.active_points_3_table_handle()->keys_end(); ++kit) {      SoQt_handle<SoShapeKit> k = new SoShapeKit;      labels_->addChild(k.get());      SoQt_handle<SoText2> s= new SoText2;      std::string name = kit->string();      s->string.setValue(name.c_str());      k->setPart("shape", s.get());      SoQt_handle<SoTransform> tr= new SoTransform;      k->setPart("localTransform", tr.get());      k->setPart("material", mat.get());    }    guil_.root()->addChild(labels_.get());  }}template <class Tr, class G>void SoQt_moving_points_3<Tr, G>::set_up_scene_graph(SoSeparator* parent){  std::cout << "add to scene graph\n";  SoEventCallback *myevcb= new SoEventCallback;  myevcb->addEventCallback(SoKeyboardEvent::getClassTypeId(),keyboard_callback, this);  parent->addChild(myevcb);  style_=new SoDrawStyle;  style_->pointSize.setValue(fix_point_size(point_size_));  coords_= new SoCoordinate3;  parent->addChild(style_.get());  parent->addChild(coords_.get());  update_tree();}template <class Tr, class G>void SoQt_moving_points_3<Tr, G>::reverse_time(){  //std::cout << "reversing time.\n";  if (direction_of_time_== CGAL::POSITIVE) direction_of_time_=CGAL::NEGATIVE;  else  direction_of_time_=CGAL::POSITIVE;  tr_.active_points_3_table_handle()->set_is_editing(true);  //typename MP::Traits::Reverse_time rt= tr_.active_points_3_table_pointer()->traits_object().reverse_time_object();  for (typename Tr::Active_points_3_table::Key_iterator kit= tr_.active_points_3_table_handle()->keys_begin(); kit != tr_.active_points_3_table_handle()->keys_end(); ++kit) {    tr_.active_points_3_table_handle()->set(*kit, rt_(tr_.active_points_3_table_handle()->at(*kit)));  }  tr_.active_points_3_table_handle()->set_is_editing(false);}template <class Tr, class G>void SoQt_moving_points_3<Tr, G>:: set_radius(double radius){  radius_=radius;  if (spheres_!= NULL) {    for (int i=0; i< spheres_->getNumChildren(); ++i) {      SoNode *c= spheres_->getChild(i);      CGAL_assertion(c->isOfType(SoShapeKit::getClassTypeId()));      SoShapeKit *kit= reinterpret_cast<SoShapeKit*>(c);      SoSphere *s= SO_GET_PART(kit, "shape", SoSphere);      s->radius.setValue(radius_);    }  }}template <class Tr, class G>void SoQt_moving_points_3<Tr, G>::set_point_size(double ps){  point_size_=ps;  style_->pointSize.setValue(ps);}template <class Tr, class G>void SoQt_moving_points_3<Tr, G>::write(std::ostream &out) const{  ik_.set_time(guil_.notifier()->current_time());  for (typename MPT::Key_iterator it= tr_.active_points_3_table_handle()->keys_begin();       it != tr_.active_points_3_table_handle()->keys_end(); ++it) {    out << *it;    out << ": " << ik_.current_coordinates_object()(*it) << std::endl;  }}CGAL_KINETIC_END_NAMESPACE;#endif                                            // guard

⌨️ 快捷键说明

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