void MMD_Polynomial::Normalize( void ) { if( getNewMaxPow() > MMD_Polynomial_MAX_POW_VALUE ) throw "Power value is too big in the operation with polynom"; switch( getType() ) { case DSRDATA_TYPE_INTEGER: _getNormalCoef_integer(); break; case DSRDATA_TYPE_REAL: _getNormalCoef_real(); break; case DSRDATA_TYPE_COMPLEX: _getNormalCoef_complex(); break; default: break; } term_pow.Flush(); for( long i = 0; i < getTermCount(); i++ ) { CDSRInteger iV( i ); UniWord uw( iV ); term_pow.Add( uw ); } is_normal = true; }
MMD_Polynomial::MMD_Polynomial( CParseDsrSymbolTable& _smbtable, enum CDsrDataTypes nested_type, long term_c ) : MMD_Object( _smbtable, _smbtable.getTypeTable().makeDataTypeNode( new CDsrDataType_Polynomial( _smbtable.getTypeTable().makeDataTypeNode( nested_type ) ) ) ), term_pow( 8, 0, 8 ), term_coef( 8, 0, 8 ) { var_name = _T(""); if( term_c > 0 ) { long i; CDSRInteger iV( 0 ); CDSRReal rV( 0 ); CDSRComplex cV( 0 ); switch( getType() ) { case DSRDATA_TYPE_INTEGER: for( i = 0; i < term_c; i++ ) { UniWord uw( iV ); term_pow.Add( uw ); term_coef.Add( uw ); } break; case DSRDATA_TYPE_REAL: for( i = 0; i < term_c; i++ ) { UniWord uw1( iV ); UniWord uw2( rV ); term_pow.Add( uw1 ); term_coef.Add( uw2 ); } break; case DSRDATA_TYPE_COMPLEX: for( i = 0; i < term_c; i++ ) { UniWord uw1( iV ); UniWord uw2( cV ); term_pow.Add( uw1 ); term_coef.Add( uw2 ); } break; default: break; } } max_pow = -1; is_normal = 0; }
MMD_Polynomial::MMD_Polynomial( CParseDsrSymbolTable& _smbtable, long is ) : MMD_Object( _smbtable, _smbtable.getTypeTable().makeDataTypeNode( new CDsrDataType_Polynomial( _smbtable.getTypeTable().makeDataTypeNode( DSRDATA_TYPE_INTEGER ) ) ) ), term_pow( 8, 0, 8 ), term_coef( 8, 0, 8 ) { var_name = _T(""); UniWord uw1( CDSRInteger( 0 ) ); CDSRInteger iV( is ); UniWord uw2( iV ); term_pow.Add( uw1 ); term_coef.Add( uw2 ); max_pow = -1; is_normal = 0; }
//[[Rcpp::export]] Rcpp::List collapse_single_cpp( Rcpp::IntegerVector ances, Rcpp::IntegerVector desc, Rcpp::NumericVector elen, Rcpp::NumericVector nnode, Rcpp::LogicalVector show_progress) { int n_singles = n_singletons(ances); std::vector<int> tab_node = tabulate_tips(ances); Rcpp::IntegerVector tab_node_rcpp(tab_node.size()); tab_node_rcpp = tab_node; Rcpp::IntegerVector position_singleton = which_integer(tab_node_rcpp, Rcpp::IntegerVector::create(1)); Rcpp::IntegerVector position_singleton_orig = position_singleton; RProgress::RProgress pb("Progress [:bar] :current/:total (:percent) :eta", (double) n_singles, 60); if (show_progress) { pb.tick(0); } while (position_singleton.size() > 0) { // Rcpp::Rcout << "tabNode is "; // for (unsigned k = 0; k < tabNode.size(); ++k) // Rcpp::Rcout << " " << tabNode[k]; // Rcpp::Rcout << std::endl; // Rcpp::Rcout << "position singleton is "; // for (unsigned k = 0; k < positionSingleton.size(); ++k) // Rcpp::Rcout << " " << positionSingleton[k]; // Rcpp::Rcout << std::endl; int i = position_singleton[0]; Rcpp::IntegerVector iV(1); iV = i; //Rcpp::Rcout << "i is " << i << " and iV is " << iV << std::endl; Rcpp::IntegerVector prev_node = which_integer(desc, iV + 1); Rcpp::IntegerVector next_node = which_integer(ances, iV + 1); //Rcpp::Rcout << "prev_node is " << prev_node << " and next_node is " << next_node << std::endl; //Rcpp::Rcout << "before desc:"; //for (unsigned k = 0; k < desc.size(); ++k) // Rcpp::Rcout << " " << desc[k]; //Rcpp::Rcout << std::endl; desc[prev_node] = desc[next_node]; //Rcpp::Rcout << "after desc:"; //for (unsigned k = 0; k < desc.size(); ++k) // Rcpp::Rcout << " " << desc[k]; //Rcpp::Rcout << std::endl; Rcpp::IntegerVector to_rm = which_integer(ances, iV + 1); //Rcpp::Rcout << "to_rm is " << to_rm << std::endl; desc.erase(to_rm[0]); ances.erase(to_rm[0]); desc = match_and_substract(desc, iV); ances = match_and_substract(ances, iV); nnode = nnode - 1; if (elen.size() > 0) { elen[prev_node] = elen[prev_node] + elen[next_node]; elen.erase(next_node[0]); } tab_node = tabulate_tips(ances); tab_node_rcpp(tab_node.size()); tab_node_rcpp = tab_node; position_singleton = which_integer(tab_node_rcpp, Rcpp::IntegerVector::create(1)); if (show_progress) { pb.tick(); } } Rcpp::List res = Rcpp::List::create( Rcpp::Named("ances") = ances, Rcpp::Named("desc") = desc, Rcpp::Named("Nnode") = nnode, Rcpp::Named("edge.length") = elen, Rcpp::Named("position_singletons") = position_singleton_orig); return res; }
/** OVERRIDE THE HANDLE METHOD: The handle() method should return true if the event has been dealt with and no if it's passed to other handlers. We do not wish it to be handled by any other handler we may also have defined. Whether you return true or false depends on the behaviour you want - here we have no other handlers defined so return true. **/ virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { switch (ea.getEventType()) { /** HANDLE MOUSE EVENTS: Mouse events have associated event names, and mouse position co-ordinates. **/ case osgGA::GUIEventAdapter::RELEASE: { //SOLUTION: you do the picking in another method of your event handler //osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); //pick(ea,viewer); //SOLUTION 2: //you do the picking directly here in the release event /** PERFORM SOME ACTION: Once we have received the mouse event, we can perform some action. Here we perform mouse picking. Mouse picking can be thought of as shooting a "ray" from the mouse position into our scene, and determining which parts of the scene intersect with the ray. Typically we will only be interested in the first false (if any) object that the ray hits. We can then perform some action. In this example, we are going to interact with our car model - if the mouse has "picked" it, we will start a simple rotation on it. **/ /** PERFORM MOUSE PICKING: In OSG, mouse picking can be done in a few slightly different ways, however, the OSG documentation recommends using the following steps: (see for example osgintersection example) **/ /** 1. Create either a PolytopeIntersector, or a LineIntersector using the normalized mouse co-ordinates.**/ osg::ref_ptr<osgUtil::LineSegmentIntersector> lI = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::PROJECTION, ea.getXnormalized(), ea.getYnormalized()); /** 2. Create an IntersectionVisitor, passing the Intersector as parameter to the constructor. **/ osgUtil::IntersectionVisitor iV(lI); /** 3. Launch the IntersectionVisitor on the root node of the scene graph. In an OSGART application, we can launch it on the osgART::Scene node. **/ _scene->accept(iV); /** 4. If the Intersector contains any intersections obtain the NodePath and search it to find the Node of interest. **/ if (lI->containsIntersections()) { osg::NodePath nodePath = lI->getFirstIntersection().nodePath; /** Here we search the NodePath for the node of interest. This is where we can make use of our node naming. If we find the Transform node named "CAR", we obtain its AnimationPathCallback - if it is currently paused we "un-pause" it, and vice-versa. **/ for (unsigned int i = 0; i <= (nodePath.size()-1); i++) { std::cout<<i<<std::endl; std::cout<<nodePath[i]->getName()<<std::endl; if (nodePath[i]->getName() == "CAR") { std::cout<<"Hit the car !!"<<std::endl; osg::AnimationPathCallback* cb = dynamic_cast<osg::AnimationPathCallback*>(nodePath[i]->getUpdateCallback()); if (cb->getPause()==true) cb->setPause(false); else cb->setPause(true); return true; } } } } default: return false; } }