📄 soqt_moving_weighted_points_3.h
字号:
} unsigned int size() { /*unsigned int ct=0; for (typename MPT::Keys_iterator it= tr_.active_points_3_table_handle()->keys_begin(); it != tr_.active_points_3_table_handle()->keys_end(); ++it, ++ct); return ct;*/ return tr_.active_points_3_table_handle()->size(); } Traits tr_; Draw_mode mode_; bool draw_labels_; double point_size_; 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 Traits::Kinetic_kernel::Reverse_time rt_;};template <class T, class G>void SoQt_moving_weighted_points_3<T,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::Weighted_point pt= ik_.current_coordinates_object()(*it); double w= CGAL::to_double(pt.weight()); if (w < 0) w=0; double radius = std::sqrt(w); pts[it->to_index()].setValue(CGAL::to_double(pt.point().x()), CGAL::to_double(pt.point().y()), CGAL::to_double(pt.point().z())); if (vpts != NULL) vpts[cp].setValue(CGAL::to_double(pt.point().x()), CGAL::to_double(pt.point().y()), CGAL::to_double(pt.point().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.point().x()), CGAL::to_double(pt.point().y()), CGAL::to_double(pt.point().z())); SoSphere *sph= SO_GET_PART(sh, "shape", SoSphere); sph->radius.setValue(radius); } if (labels_!= NULL) { double offset; if (mode_ == POINT) { offset=label_offset(); } else { offset= 1.2*radius/std::sqrt(3.0); } 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.point().x())+offset, CGAL::to_double(pt.point().y())+offset, CGAL::to_double(pt.point().z())+offset); } } coords_->point.finishEditing(); if (vpts!= NULL) { SoCoordinate3 *c= SO_GET_PART(points_, "coordinate3", SoCoordinate3); c->point.finishEditing(); }}template <class T, class G>void SoQt_moving_weighted_points_3<T,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); if (mode_== TRANSPARENT_SPHERE) { smat->transparency.setValue(.5); } 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(.01); 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 T, class G>void SoQt_moving_weighted_points_3<T,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(point_size_); coords_= new SoCoordinate3; parent->addChild(style_.get()); parent->addChild(coords_.get()); update_tree();}template <class T, class G>void SoQt_moving_weighted_points_3<T,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_handle()->traits_object().reverse_time_object(); for (typename MPT::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);}//s->radius.setValue(radius_);template <class T, class G>void SoQt_moving_weighted_points_3<T,G>::set_point_size(double ps){ point_size_=ps; style_->pointSize.setValue(ps);}template <class T, class G>void SoQt_moving_weighted_points_3<T,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 + -