/* * PointCloudAdaptor.hpp * * Created on: Feb 21, 2011 * Author: heber */ #ifndef POINTCLOUDADAPTOR_HPP_ #define POINTCLOUDADAPTOR_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Assert.hpp" #include "IPointCloud.hpp" #include "Tesselation/TesselPoint.hpp" #include "LinearAlgebra/Vector.hpp" /** Adaptor class to IPointCloud, specialized for all needed classes. */ template class PointCloudAdaptor: public IPointCloud { public: PointCloudAdaptor(container_type *_list, const std::string _name) : list(_list), name(_name) {} virtual ~PointCloudAdaptor() { list = NULL; } const std::string& GetName() const { return name; } Vector *GetCenter() const { Vector *Center = new Vector(0., 0., 0.); int num = 0; for (iterator_type iter = iterator_type(list->begin()); iter != iterator_type(list->end()); ++iter) { (*Center) += ((*iter)->getPosition()); num++; } Center->Scale(1. / num); return Center; } TesselPoint *GetPoint() { ASSERT(!IsEnd(), "PointCloudAdaptor::getPoint() - invalid InternalIterator."); return (*InternalIterator)->getTesselPoint(); } int GetMaxId() const { int maxid = -1; for (iterator_type iter = iterator_type(list->begin()); iter != iterator_type(list->end()); ++iter) { if ((maxid == -1) || ((*iter)->getNr() > maxid)) { maxid = (*iter)->getNr(); } } return maxid; } void GoToNext() { if (InternalIterator != iterator_type(list->end())) ++InternalIterator; } void GoToFirst() { InternalIterator = iterator_type(list->begin()); } bool IsEmpty() const { return list->begin() == list->end(); } bool IsEnd() const { return InternalIterator == iterator_type(list->end()); } private: container_type *list; iterator_type InternalIterator; const std::string name; }; #endif /* POINTCLOUDADAPTOR_HPP_ */