SpikeStream Nemo Plugin
0.2
|
00001 //SpikeStream includes 00002 #include "Pattern.h" 00003 using namespace spikestream; 00004 00005 //Qt includes 00006 #include <QDebug> 00007 00008 //Other includes 00009 #include <iostream> 00010 using namespace std; 00011 00012 00014 Pattern::Pattern(){ 00015 } 00016 00017 00019 Pattern::Pattern(const Pattern& patt){ 00020 this->name = patt.name; 00021 this->boxList = patt.boxList; 00022 this->pointList = patt.pointList; 00023 } 00024 00025 00027 Pattern::~Pattern(){ 00028 } 00029 00030 00031 /*----------------------------------------------------------*/ 00032 /*------ PUBLIC METHODS ------*/ 00033 /*----------------------------------------------------------*/ 00034 00036 void Pattern::addBox(const Box& box){ 00037 boxList.append(box); 00038 } 00039 00040 00042 void Pattern::addPoint(const Point3D& point){ 00043 pointList.append(point); 00044 } 00045 00046 00048 bool Pattern::contains(const Point3D& point){ 00049 //Is the point contained within any of the boxes? 00050 QList<Box>::iterator boxListEnd = boxList.end(); 00051 for(QList<Box>::iterator iter = boxList.begin(); iter!=boxListEnd; ++iter){ 00052 if(iter->contains(point)) 00053 return true; 00054 } 00055 00056 //Does the point match any of the points? 00057 QList<Point3D>::iterator pointListEnd = pointList.end(); 00058 for(QList<Point3D>::iterator iter = pointList.begin(); iter!=pointListEnd; ++iter){ 00059 if(point == *iter) 00060 return true; 00061 } 00062 return false; 00063 } 00064 00065 00067 Pattern Pattern::getAlignedPattern(const Box& box) const{ 00068 //Get a copy of this pattern 00069 Pattern alignedPattern(*this); 00070 00071 //Get a box enclosing this pattern 00072 Box thisBoundingBox = Box::getEnclosingBox(boxList, pointList); 00073 00074 //Get the centres of the new and current patterns 00075 Point3D thisCentre = thisBoundingBox.centre(); 00076 00077 Point3D boxCentre = box.centre(); 00078 float dx = boxCentre.getXPos() - thisCentre.getXPos(); 00079 float dy = boxCentre.getYPos() - thisCentre.getYPos(); 00080 float dz = boxCentre.getZPos() - thisCentre.getZPos(); 00081 00082 //Translate the new pattern and return it. 00083 alignedPattern.translate(dx, dy, dz); 00084 return alignedPattern; 00085 } 00086 00087 00089 void Pattern::print() const { 00090 cout<<"------------- Pattern: "<<name.toStdString()<<" ---------------------"<<endl; 00091 QList<Box>::const_iterator boxListEnd = boxList.end(); 00092 for(QList<Box>::const_iterator iter = boxList.begin(); iter!=boxListEnd; ++iter){ 00093 cout<<iter->toString().toStdString()<<endl; 00094 } 00095 00096 //Does the point match any of the points? 00097 QList<Point3D>::const_iterator pointListEnd = pointList.end(); 00098 for(QList<Point3D>::const_iterator iter = pointList.begin(); iter!=pointListEnd; ++iter){ 00099 cout<<iter->toString().toStdString()<<endl; 00100 } 00101 } 00102 00104 void Pattern::reset(){ 00105 name = "Unnamed"; 00106 boxList.clear(); 00107 pointList.clear(); 00108 } 00109 00110 00112 void Pattern::translate(float dx, float dy, float dz){ 00113 //Translate the boxes 00114 QList<Box>::iterator boxListEnd = boxList.end(); 00115 for(QList<Box>::iterator iter = boxList.begin(); iter!=boxListEnd; ++iter){ 00116 (*iter).translate(dx, dy, dz); 00117 } 00118 00119 //Translate the points 00120 QList<Point3D>::iterator pointListEnd = pointList.end(); 00121 for(QList<Point3D>::iterator iter = pointList.begin(); iter!=pointListEnd; ++iter){ 00122 (*iter).translate(dx, dy, dz); 00123 } 00124 } 00125 00126 00128 Pattern& Pattern::operator=(const Pattern& rhs){ 00129 if(this == &rhs) 00130 return *this; 00131 00132 this->name = rhs.name; 00133 this->boxList = rhs.boxList; 00134 this->pointList = rhs.pointList; 00135 00136 return *this; 00137 } 00138 00139 00141 bool Pattern::operator==(const Pattern& rhs){ 00142 if(this == &rhs)//Same object 00143 return true; 00144 00145 if( (this->name == rhs.name) && (this->boxList == rhs.boxList) && (this->pointList == rhs.pointList)) 00146 return true; 00147 return false; 00148 } 00149