Revision: 34026
          http://brlcad.svn.sourceforge.net/brlcad/?rev=34026&view=rev
Author:   homovulgaris
Date:     2009-03-13 18:07:47 +0000 (Fri, 13 Mar 2009)

Log Message:
-----------
adding BranchNode definition and methods to pcMathVM

Modified Paths:
--------------
    brlcad/trunk/src/libpc/pcMathVM.cpp
    brlcad/trunk/src/libpc/pcMathVM.h

Modified: brlcad/trunk/src/libpc/pcMathVM.cpp
===================================================================
--- brlcad/trunk/src/libpc/pcMathVM.cpp 2009-03-12 22:00:21 UTC (rev 34025)
+++ brlcad/trunk/src/libpc/pcMathVM.cpp 2009-03-13 18:07:47 UTC (rev 34026)
@@ -359,7 +359,49 @@
 {
     return *fp;
 }
+/** BranchNode Methods */
 
+BranchNode::BranchNode(Stack const & stack1, Stack const & stack2)
+       : func_(stack1, stack2)
+{}
+
+boost::shared_ptr<Node> BranchNode::clone() const
+{
+    return boost::shared_ptr<Node>(new BranchNode(*this));
+}
+
+MathFunction const & BranchNode::func() const
+{
+    return func_;
+}
+
+std::size_t BranchNode::nbranches() const
+{
+    return 2;
+}
+
+Stack * BranchNode::branch(std::size_t i)
+{
+    if (i > 1)
+        return 0;
+    return i == 0 ? &func_.stack1_ : &func_.stack2_;
+}
+
+BranchNode::BranchFunc::BranchFunc(Stack const & stack1, Stack const & stack2)
+    : MathFunction("branch"),
+    stack1_(stack1), stack2_(stack2)
+{}
+
+std::size_t BranchNode::BranchFunc::arity() const
+{
+    return 1;
+}
+
+double BranchNode::BranchFunc::evalp(std::vector<double> const & params) const
+{
+    return evaluate(params[0] ? stack1_ : stack2_);
+}
+
 /** Functions assisting evaluation */
 
 NumberNode * getNumberNode(Stack::iterator i)

Modified: brlcad/trunk/src/libpc/pcMathVM.h
===================================================================
--- brlcad/trunk/src/libpc/pcMathVM.h   2009-03-12 22:00:21 UTC (rev 34025)
+++ brlcad/trunk/src/libpc/pcMathVM.h   2009-03-13 18:07:47 UTC (rev 34026)
@@ -255,6 +255,28 @@
 private:
     boost::shared_ptr<MathFunction> fp;
 };
+
+struct BranchNode : public FunctionNode
+{
+    BranchNode(Stack const & stack1, Stack const & stack2);
+    boost::shared_ptr<Node> clone() const;
+    MathFunction const & func() const;
+
+    std::size_t nbranches() const;
+    Stack * branch(std::size_t i);
+private:
+    struct BranchFunc : public MathFunction {
+       BranchFunc(Stack const & stack1, Stack const & stack2);
+       
+       std::size_t arity() const;
+       double evalp(std::vector<double> const & params) const;
+
+       Stack stack1_;
+       Stack stack2_;
+    };
+    BranchFunc func_;
+};
+
 #endif
 /** @} */
 /*


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to