collector.h 5.43 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __COLLECTOR_H__
#define __COLLECTOR_H__

28 29
#include "Algo/Geometry/intersection.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34 35 36 37 38 39
/*****************************************
 * Class hierarchy :
 * Collector (virtual)
 * - Collector_WithinSphere
 * - Collector_OneRing
 ****************************************/

namespace CGoGN
{

40 41 42
namespace Algo
{

Pierre Kraemer's avatar
Pierre Kraemer committed
43 44 45 46
namespace Selection
{

/*********************************************************
47
 * Generic Collector
Pierre Kraemer's avatar
Pierre Kraemer committed
48
 *********************************************************/
49

Pierre Kraemer's avatar
Pierre Kraemer committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
template <typename PFP>
class Collector
{
protected:
	typedef typename PFP::VEC3 VEC3;
	typedef typename PFP::REAL REAL;

	typename PFP::MAP& map;
	const typename PFP::TVEC3& position;

	Dart centerDart;
	REAL radius;

	std::vector<Dart> insideVertices;
	std::vector<Dart> insideEdges;
	std::vector<Dart> insideFaces;
	std::vector<Dart> border;

public:
	Collector(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition);

	virtual void init(Dart d, REAL r = 0) = 0;

	virtual void collect() = 0;

75 76
	bool apply(FunctorType& f);

Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
	void sort()
	{
		std::sort(insideVertices.begin(), insideVertices.end());
		std::sort(insideEdges.begin(), insideEdges.end());
		std::sort(insideFaces.begin(), insideFaces.end());
		std::sort(border.begin(), border.end());
	}

	typename PFP::MAP& getMap() { return map; }
	const AttributeHandler<typename PFP::VEC3>& getPosition() const { return position; }

	Dart getCenter() const { return centerDart; }
	REAL getRadius() const { return radius; }

	const std::vector<Dart>& getInsideVertices() const { return insideVertices; }
	const std::vector<Dart>& getInsideEdges() const { return insideEdges; }
	const std::vector<Dart>& getInsideFaces() const { return insideFaces; }
	const std::vector<Dart>& getBorder() const { return border; }

	unsigned int getNbInsideVertices() const { return insideVertices.size(); }
	unsigned int getNbInsideEdges() const { return insideEdges.size(); }
	unsigned int getNbInsideFaces() const { return insideFaces.size(); }
	unsigned int getNbBorder() const { return border.size(); }

	template <typename PPFP>
	friend std::ostream& operator<<(std::ostream &out, const Collector<PPFP>& c);
};

/*********************************************************
 * Collector One Ring
 *********************************************************/

/*
 * insideVertices = centerDart
 * insideEdges = star (edges incident to centerDart)
 * insideFaces = triangles incident to centerDart
 * border = vertices of 1-ring
 *        = edges of 1-ring
 */
template <typename PFP>
class Collector_OneRing : public Collector<PFP>
{
public:
	Collector_OneRing(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition) :
		Collector<PFP>(mymap, myposition)
	{}
	void init(Dart d, typename PFP::REAL r = 0);
	void collect();
};

/*********************************************************
 * Collector Within Sphere
 *********************************************************/

/*
 * collect all primitives of the connected component containing "centerDart"
 * within the sphere of radius "radius" and center "position[centerDart]"
 * (hopefully) it defines a 2-manifold (if inserting border-vertices along the border-edges)
 */
template <typename PFP>
class Collector_WithinSphere : public Collector<PFP>
{
protected:
	typename PFP::VEC3 centerPosition;
	typename PFP::REAL area;
142

Pierre Kraemer's avatar
Pierre Kraemer committed
143 144 145 146 147 148 149 150 151 152 153 154
public:
	Collector_WithinSphere(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition) :
		Collector<PFP>(mymap,myposition)
	{}
	void init(Dart d, typename PFP::REAL r = 0);
	void collect();
	void computeArea();
	typename PFP::REAL getArea() const { return area; }
};

} // namespace Selection

155 156
} // namespace Algo

Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160 161
} // namespace CGoGN

#include "Algo/Selection/collector.hpp"

#endif