From: clement r. <kl...@us...> - 2005-11-07 20:29:39
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29975 Added Files: newMarieDataList.cpp extractMarieDataList.cpp Log Message: initial add --- NEW FILE: newMarieDataList.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau * * This library is free software; 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; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You can contact MARIE development team at http://marie.sourceforge.net */ #include "MarieObject.h" #include "DataList.h" #include "BufferedNode.h" #include <sstream> #include <string> #include "Vector.h" using namespace FD; namespace marie { class newMarieDataList; DECLARE_NODE(newMarieDataList) /*Node * * @name newMarieDataList * @category RobotFlow:MARIE:DATA * @description Create an object of type MarieObject containing a DataList data * * @input_name VECTOR * @input_type Vector<ObjectRef> * @input_description ObjectRef Vector conataining marie data to include in the new list * * @output_name DATA_LIST * @output_description Output MarieObject containing a DataList data * @output_type MarieObject * END*/ using namespace std; class newMarieDataList : public BufferedNode { private: int m_inputID; int m_outputID; public: newMarieDataList(string nodeName, ParameterSet params) : BufferedNode(nodeName,params) { //inputs m_inputID = addInput("VECTOR"); //outputs m_outputID = addOutput("DATA_LIST"); } void calculate(int output_id, int count, Buffer &out) { ObjectRef InputValue = getInput(m_inputID,count); if (!InputValue->isNil()) { RCPtr<Vector<ObjectRef> > vectorObject = InputValue; //create new Marie DataList DataList *dList = new DataList(); //get all the element of the vector std::vector<ObjectRef>::const_iterator it = vectorObject->begin(); for(; it != vectorObject->end(); it++) { try { RCPtr<MarieObject> marieObject = *it; dList->insertBack(marieObject->getData()); } catch(BaseException* e) { throw e->add(new GeneralException("newMarieDataList : invalid data type in input vector : not a MarieObject.", __FILE__, __LINE__)); } } out[count] = ObjectRef(new MarieObject(dList)); } else { out[count] = nilObject; } } };//class newMarieDataList }//namespace marie --- NEW FILE: extractMarieDataList.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau / Clement Raievsky * * This library is free software; 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; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You can contact MARIE development team at http://marie.sourceforge.net */ #include <sstream> #include <string> #include "BufferedNode.h" #include "MarieObject.h" #include "DataList.h" #include "Vector.h" using namespace FD; namespace marie { //forward declaration class extractMarieDataList; DECLARE_NODE(extractMarieDataList) /*Node * * @name extractMarieDataList * @category RobotFlow:MARIE:DATA * @description Extract data in the FlowDesigner format from MarieObject * * @input_name DATA_LIST * @input_type MarieObject * @input_description input MarieObject object containing a DataList * * @output_name VECTOR * @output_description Vector object equivalent to MARIE DataList. WARNING : order in MARIE DataList is not guaranted. The Flowdesigner object is a vector of composite which are of the form : <X <double>, Y <double>, THETA <double>, ID <int>> * @output_type Vector<ObjectRef> * END*/ using namespace std; class extractMarieDataList : public BufferedNode { private: //intputs int m_dataListID; //outputs int m_vectorID; public: extractMarieDataList(string nodeName, ParameterSet params) : BufferedNode(nodeName,params) { //inputs m_dataListID = addInput("DATA_LIST"); //outputs m_vectorID = addOutput("VECTOR"); } void calculate(int output_id, int count, Buffer &out) { try { //get input RCPtr<MarieObject> dataPtr = getInput(m_dataListID,count); DataList *dataList = dynamic_cast<DataList*>(dataPtr->getData()); if (dataList != NULL) { const std::list<DataAbstract*> myList = dataList->getList(); Vector<ObjectRef> *myVector = new Vector<ObjectRef>(); std::list<DataAbstract*>::const_iterator iter = myList.begin(); for (;iter != myList.end(); iter++) { myVector->push_back(ObjectRef(new MarieObject((*iter)->clone()))); } //output vector out[count] = ObjectRef(myVector); } else { std::cerr << "FD::extractMarieDataList -> MarieObject received data not of DataList type" << std::endl; out[count] = nilObject; } } catch (BaseException *e) { e->print(cerr); e->add(new GeneralException("Unable to process",__FILE__,__LINE__)); throw e; } } };//class extractMarieDataList }//namespace marie |