File: base.h

package info (click to toggle)
meshlab 1.3.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,096 kB
  • ctags: 33,630
  • sloc: cpp: 224,813; ansic: 8,170; xml: 119; makefile: 80
file content (333 lines) | stat: -rw-r--r-- 13,535 bytes parent folder | download | duplicates (4)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
75
76
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/****************************************************************************
* VCGLib                                                            o o     *
* Visual and Computer Graphics Library                            o     o   *
*                                                                _   O  _   *
* Copyright(C) 2004                                                \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *   
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program 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 General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/

/****************************************************************************
History

$Log: not supported by cvs2svn $
Revision 1.1  2005/09/28 17:19:28  m_di_benedetto
First Commit.


****************************************************************************/

#ifndef __VCGLIB_SPATIALINDEX_H
#define __VCGLIB_SPATIALINDEX_H

// standard headers
#include <assert.h>

// vcg headers
#include <vcg/space/point3.h>
#include <vcg/space/ray3.h>
#include <vcg/space/box3.h>

namespace vcg {

/****************************************************************************
Class SpatialIndex

Description:
	This class exposes the base interface for all spatial indexing data
	structures, i.e. grids, bounding volume trees.

Template Parameters:
	OBJTYPE:      Type of the indexed objects.
	SCALARTYPE:   Scalars type for structure's internal data (may differ from
	              object's scalar type).

****************************************************************************/

template <class OBJTYPE, class SCALARTYPE>
class SpatialIndex {
public:
	/**************************************************************************
	Commonly used typedefs.
	**************************************************************************/
	typedef SpatialIndex<OBJTYPE, SCALARTYPE> ClassType;
	typedef OBJTYPE ObjType;
	typedef SCALARTYPE ScalarType;
	typedef ObjType * ObjPtr;
	typedef Point3<ScalarType> CoordType;
	typedef vcg::Box3<ScalarType> BoxType;

	/**************************************************************************
	Method Set.

	Description:
		The Set method initializes the spatial structure.

	Template Parameters:
		OBJITER:  Objects Container's iterator type.

	Method Parameters:
		_oBegin : [IN] begin objects container's iterator
		_oEnd   : [IN] end objects container's iterator

	Return Value:
		None.

	**************************************************************************/
	template <class OBJITER>
	void Set(const OBJITER & _oBegin, const OBJITER & _oEnd) {
		assert(0);      // this is a base interface.
		(void)_oBegin;  // avoid "unreferenced parameter" compiler warning.
		(void)_oEnd;
	}

  /**************************************************************************
  Method Empty.
  Description:
    check if the spatial structure is empty.

  Return Value:
    true if it is empty.
  **************************************************************************/

  bool Empty() {
    assert(0);      // this is a base interface.
    return true;
  }

	/**************************************************************************
	Method GetClosest.

	Description:
		The GetClosest method finds the closest object given a point.
		It also finds the closest point and minimum distance.

	Template Parameters:
		OBJPOINTDISTFUNCTOR : Object-Point distance functor type;
		                      this type must implement an operator () with signature
													  bool operator () (const ObjType & obj, const CoordType & p, ScalarType & d, CoordType & q)
													 where:
													   obj [IN] is a reference to the current object being tested,
													   p [IN] is the query point,
													   d [IN/OUT] is in input the reject distance and in output the closest distance,
													   q [OUT] is the closest point.
													 The operator returns true if the closest distance is less than input reject distance.
		OBJMARKER           : The type of a marker functor.

	Method Parameters:
		_getPointDistance : [IN] Functor for point-distance calculation.
		_marker           : [IN] Functor for marking objects already tested.
		_p                : [IN] The query point.
		_maxDist          : [IN] Maximum reject distance.
		_minDist          : [OUT] Closest distance.
		_closestPt        : [OUT] Closest point.

	Return Value:
		A pointer to the closest object (if any).

	**************************************************************************/
	template <class OBJPOINTDISTFUNCTOR, class OBJMARKER>
	ObjPtr GetClosest(
		OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker, const CoordType & _p, const ScalarType & _maxDist,
		ScalarType & _minDist, CoordType & _closestPt) {
		assert(0);
		(void)_getPointDistance;
		(void)_marker;
		(void)_p;
		(void)_maxDist;
		(void)_minDist;
		(void)_closestPt;
		return ((ObjPtr)0);
	}

	/**************************************************************************
	Method GetKClosest.

	Description:
		The GetKClosest method finds the K closest object given a point.
		It also finds the closest points and minimum distances.

	Template Parameters:
		OBJPOINTDISTFUNCTOR : Object-Point distance functor type;
		                      this type must implement an operator () with signature
													  bool operator () (const ObjType & obj, const CoordType & p, ScalarType & d, CoordType & q)
													 where:
													   obj [IN] is a reference to the current object being tested,
													   p [IN] is the query point,
													   d [IN/OUT] is in input the reject distance and in output the closest distance,
													   q [OUT] is the closest point.
													 The operator returns true if the closest distance is less than input reject distance.
		OBJMARKER           : The type of a marker functor.
		OBJPTRCONTAINER     : The type of a object pointers container.
		DISTCONTAINER       : The type of a container which, in return, will contain the closest distances.
		POINTCONTAINER      : The type of a container which, in return, will contain the closest points.

	Method Parameters:
		_getPointDistance : [IN] Functor for point-distance calculation.
		_marker           : [IN] Functor for marking objects already tested.
		_k                : [IN] The number of closest objects to search for.
		_p                : [IN] The query point.
		_maxDist          : [IN] Maximum reject distance.
		_objectPtrs       : [OUT] Container which, in return, will contain pointers to the closest objects.
		_distances        : [OUT] Container which, in return, will contain the closest distances.
		_objectPtrs       : [OUT] Container which, in return, will contain the closest points.

	Return Value:
		The number of closest objects found.

	**************************************************************************/
	template <class OBJPOINTDISTFUNCTOR, class OBJMARKER, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
	unsigned int GetKClosest(
		OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker, const unsigned int _k, const CoordType & _p, const ScalarType & _maxDist,
		OBJPTRCONTAINER & _objectPtrs, DISTCONTAINER & _distances, POINTCONTAINER & _points) {
		assert(0);
		(void)_getPointDistance;
		(void)_marker;
		(void)_k;
		(void)_p;
		(void)_maxDist;
		(void)_objectPtrs;
		(void)_distances;
		(void)_points;
		return (0);
	}
	
	
	/**************************************************************************
	Method GetInSphere.

	Description:
		The GetInSphere method finds all the objects in the specified sphere

	Template Parameters:
		OBJPOINTDISTFUNCTOR : Object-Point distance functor type;
		                      this type must implement an operator () with signature
													  bool operator () (const ObjType & obj, const CoordType & p, ScalarType & d, CoordType & q)
													 where:
													   obj [IN] is a reference to the current object being tested,
													   p [IN] is the query point,
													   d [IN/OUT] is in input the reject distance and in output the closest distance,
													   q [OUT] is the closest point.
													 The operator returns true if the closest distance is less than input reject distance.
		OBJMARKER           : The type of a marker functor.
		OBJPTRCONTAINER     : The type of a object pointers container.
		DISTCONTAINER       : The type of a container which, in return, will contain the closest distances.
		POINTCONTAINER      : The type of a container which, in return, will contain the closest points.

	Method Parameters:
		_getPointDistance : [IN] Functor for point-distance calculation.
		_marker           : [IN] Functor for marking objects already tested.
		_p                : [IN] The query point.
		_r		          : [IN]  The radius of the specified sphere.
		_objectPtrs       : [OUT] Container which, in return, will contain pointers to the in-sphere objects.
		_distances        : [OUT] Container which, in return, will contain the in-sphere distances.
		_objectPtrs       : [OUT] Container which, in return, will contain the in-sphere nearests points for each object.

	Return Value:
		The number of in-sphere objects found.

	**************************************************************************/
	template <class OBJPOINTDISTFUNCTOR, class OBJMARKER, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
	unsigned int GetInSphere(
		OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker,const CoordType & _p, const ScalarType & _r,OBJPTRCONTAINER & _objectPtrs, DISTCONTAINER & _distances, POINTCONTAINER & _points) {
		assert(0);
		(void)_getPointDistance;
		(void)_marker;
		(void)_p;
		(void)_r;
		(void)_objectPtrs;
		(void)_distances;
		(void)_points;
		return (0);
	}

	/**************************************************************************
	Method GetInBox.

	Description:
		The GetInBox returns all the object in the specified bbox

	Template Parameters:

		OBJMARKER           : The type of a marker functor.
		OBJPTRCONTAINER     : The type of a object pointers container.
	
	Method Parameters:
		_marker           : [IN] Functor for marking objects already tested.
		_bbox             : [IN] The bounding box of spatial query.
		_objectPtrs       : [OUT] Container which, in return, will contain pointers to the closest objects.
		

	Return Value:
		The number of in-box objects found.

	**************************************************************************/
	template <class OBJMARKER, class OBJPTRCONTAINER>
	unsigned int GetInBox(OBJMARKER & _marker, const BoxType _bbox,OBJPTRCONTAINER & _objectPtrs) {
		assert(0);
		(void)_marker;
		(void)_bbox;
		(void)_objectPtrs;
		return (0);
	}
	

	
	/**************************************************************************
	Method DoRay.

	Description:
		The DoRay method finds the first object in the structure hit by a ray.

	Template Parameters:
		OBJRAYISECTFUNCTOR : Object-Ray intersection functor type;
		                      this type must implement an operator () with signature
													  bool operator () (const ObjType & obj, const Ray3<scalarType> ray, ScalarType & t)
													 where:
													   obj [IN] is a reference to the current object being tested,
													   ray [IN] is the query ray,
													   t [OUT] is the parameter of the ray equation at which intersection occurs.
													 The operator returns true if the the object has been hit by the ray (i.e. they intersect).
		OBJMARKER          : The type of a marker functor.

	Method Parameters:
		_rayIntersector : [IN] Functor for object-ray intersection.
		_marker         : [IN] Functor for marking objects already tested.
		_ray            : [IN] The query ray.
		_maxDist        : [IN] Maximum reject distance.
		_t              : [OUT] the parameter of the ray equation at which intersection occurs.

	Return Value:
		A pointer to the first object hit by the ray (if any).

	**************************************************************************/
	template <class OBJRAYISECTFUNCTOR, class OBJMARKER>
	ObjPtr DoRay(OBJRAYISECTFUNCTOR & _rayIntersector, OBJMARKER & _marker, const Ray3<ScalarType> & _ray, const ScalarType & _maxDist, ScalarType & _t) {
		assert(0);
		(void)_rayIntersector;
		(void)_marker;
		(void)_ray;
		(void)_maxDist;
		(void)_t;
		return ((ObjPtr)0);
	}

};

} // end namespace vcg

#endif // #ifndef __VCGLIB_SPATIALINDEX_H