Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

image.h 7.76 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef IMAGE_H
#define IMAGE_H


Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
29
#include "Geometry/vector_gen.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30

Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
31
#include "Utils/img3D_IO.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32

Sylvain Thery's avatar
Sylvain Thery committed
33
#ifdef WITH_ZINRI
Pierre Kraemer's avatar
Pierre Kraemer committed
34
#include "Zinrimage.h"
Sylvain Thery's avatar
Sylvain Thery committed
35
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
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

namespace CGoGN
{

namespace Algo
{

namespace MC
{

/**
 * voxel image class
 *
 * The class Image manage 3D voxel image
 * of any type
 * @param DataType the type of voxel
 */
template< typename  DataType >
class Image
{
protected:
	/**
	 * pointer to data
	 */
	DataType *m_Data;

	/**
	 * X size
	 */
	int m_WX;

	/**
	 * Y size
	 */
	int m_WY;

	/**
	 * Z size
	 */
	int m_WZ;

	/**
	 * slice size
	 */
80
	int m_WXY;
Pierre Kraemer's avatar
Pierre Kraemer committed
81
82
83
84
85


	/**
	 * X origin
	 */
86
	int m_OX;
Pierre Kraemer's avatar
Pierre Kraemer committed
87
88
89
90

	/**
	 * Y origin
	 */
91
	int m_OY;
Pierre Kraemer's avatar
Pierre Kraemer committed
92
93
94
95

	/**
	 * Z origin
	 */
96
	int m_OZ;
Pierre Kraemer's avatar
Pierre Kraemer committed
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


	/**
	 * Voxel X size
	 */
	float m_SX;

	/**
	 * Voxel Y size
	 */
	float m_SY;

	/**
	 * Voxel Z size
	 */
	float m_SZ;

	/**
	 * memory allocated ?
	 */
	bool m_Alloc;

	/**
	* Test if a point is in the image
	*
	* @param  _V the coordinates to test
	*/
	//bool correct(const gmtl::Vec3i& _V);

Sylvain Thery's avatar
Sylvain Thery committed
126
#ifdef WITH_ZINRI
Pierre Kraemer's avatar
Pierre Kraemer committed
127
128
129
130
	/**
	 * internal inrimage prt
	 */
	PTRINRIMAGE mImage;
Sylvain Thery's avatar
Sylvain Thery committed
131
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
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

public:

	/**
	* default constructor
	*/
	Image();

	/**
	* destructor
	*/
	~Image();


	/**
	* Load a file (png) in an empty image
	* @param _cName file to open
	*/
	bool loadPNG3D(const char *_cName);


	/**
	* Load an ipb-format file in an empty image
	* @param _cName file to open
	*/
	bool loadIPB(const char* _cName);

	/**
	* Load an inr.gz format file in an empty image
	* @param filname file to open
	*/
	bool loadInrgz(const char* filename);

	/**
	* Constructor
	* @param data pointer on voxel
	* @param wx width in X
	* @param wy width in Y
	* @param wz width in Z
	* @param sx voxel size in X
	* @param sy voxel size in Y
	* @param sz voxel size in Z
	* @param copy	sets to true if data must be copying, false if data are used directly (and release by the destructor).
	*/
176
	Image(DataType *data, int wx, int wy, int wz, float sx, float sy, float sz, bool copy = false );
Pierre Kraemer's avatar
Pierre Kraemer committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197


	/**
	* Load a raw image
	*/
	void loadRaw(char *filename);

	/**
	 * Load a vox file
	 */
	void loadVox(char *filename);

	/**
	* save current image into file
	* @param _cName file to save
	*/
    void saveInrMask(const char* _cName);

    /**
	* get the width along X axis
	*/
198
	int getWidthX() const { return m_WX;}
Pierre Kraemer's avatar
Pierre Kraemer committed
199
200
201
202

	/**
	* get the width along Y axis
	*/
203
	int getWidthY() const { return m_WY;}
Pierre Kraemer's avatar
Pierre Kraemer committed
204
205
206
207

	/**
	* get the width along Z axis
	*/
208
	int getWidthZ() const { return m_WZ;}
Pierre Kraemer's avatar
Pierre Kraemer committed
209
210
211
212

	/**
	* get widthX*widthY (size of a slice)
	*/
213
	int getWidthXY() const { return m_WXY;}
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
216
217
218
219
220
221
222
223
224
225
226

	/** set the real size of voxel of image
	 * @param vx x size
	 * @param vy y size
	 * @param vz z size
	 */
	void setVoxelSize(float vx, float vy, float vz) { m_SX = vx; m_SY = vy; m_SZ = vz;}

	/** set origin (equivalent of frame size)
	 * @param ox x size
	 * @param oy y size
	 * @param oz z size
	 */
227
	void setOrigin(int ox, int oy, int oz) {m_OX = ox; m_OY = oy; m_OZ = oz;}
Pierre Kraemer's avatar
Pierre Kraemer committed
228
229
230
231
232

	/**
	 * get the origin
	 * @return a vector with origin
	 */
Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
233
	Geom::Vec3i getOrigin() const { return Geom::Vec3i(m_OX, m_OY, m_OZ);}
Pierre Kraemer's avatar
Pierre Kraemer committed
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

	/**
	* get the data const version
	*/
	const DataType* getData() const {return m_Data;}

	/**
	* get the data non const version
	*/
	DataType* getData() {return m_Data;}

	/**
	* get the subsampling width in X of current slot
	*/
	float getVoxSizeX() const { return m_SX;}

	/**
	* get the subsampling width in Y of current slot
	*/
	float getVoxSizeY() const { return m_SY;}

	/**
	* get the subsampling width in Z of current slot
	*/
	float getVoxSizeZ() const { return m_SZ;}


	/**
	* get the voxel value
	*
	* @param  _lX,_lY,_lZ position
	* @return the value of the voxel
	*/
267
	DataType getVoxel(int _lX,int _lY, int _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
268
269
270
271
272
273
274

	/**
	* get the voxel address (const ptr)
	*
	* @param _lX,_lY,_lZ position
	* @return the address of the voxel
	*/
275
	const DataType* getVoxelPtr(int _lX,int _lY, int _lZ) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
276
277
278
279
280
281
282

	/**
	* get the voxel address
	*
	* @param  _lX,_lY,_lZ position
	* @return the address of the voxel
	*/
283
	DataType* getVoxelPtr(int _lX,int _lY, int _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
284
285
286
287
288
289
290
291


	/**
	* get the voxel value
	*
	* @param  _Vec vector of voxel position
	* @return the value of the voxel
	*/
Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
292
	DataType getVoxel( const Geom::Vec3i &_Vec);
Pierre Kraemer's avatar
Pierre Kraemer committed
293
294
295
296
297
298
299


	/**
	*  Blur the image with pseudo gaussian filter
	* @param   _lWidth width of filtering
	* @return the new image
	*/
300
	Image<DataType>* filtering(int _lWidth);
Pierre Kraemer's avatar
Pierre Kraemer committed
301
302
303
304
305
306

	/**
	*  add Frame of zero around the image
	* @param  _lWidth the width of frame to add
	* @return the new image
	*/
307
	Image<DataType>* addFrame(int _lWidth) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
308
309
310
311
312

	/**
	 * Get the lower corner of bounding AABB
	 */
//	gmtl::Vec3f boundMin() const { return gmtl::Vec3f(0.0f, 0.0f, 0.0f);}
Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
313
	Geom::Vec3f boundMin() const { return Geom::Vec3f(m_SX*m_OX, m_SY*m_OY, m_SZ*m_OZ);}
Pierre Kraemer's avatar
Pierre Kraemer committed
314
315
316
317
318

	/**
	 * Get the upper corner of bounding AABB
	 */
//	gmtl::Vec3f boundMax() const { return gmtl::Vec3f(m_SX*(m_WX-2*m_OX), m_SY*(m_WY-2*m_OY), m_SZ*(m_WZ-2*m_OZ));}
Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
319
	Geom::Vec3f boundMax() const { return Geom::Vec3f(m_SX*(m_WX-m_OX), m_SY*(m_WY-m_OY), m_SZ*(m_WZ-m_OZ));}
Pierre Kraemer's avatar
Pierre Kraemer committed
320
321
322
323
324
325
326
	/**
	 * Compute the volume in cm3
	 * @param wind the windowing function
	 */
	template< typename Windowing >
	float computeVolume(const Windowing& wind) const;

Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
327
328
329
330
	/**
	 * local (3x3) blur of image
	 */
	Image<DataType>* Blur3();
Pierre Kraemer's avatar
Pierre Kraemer committed
331
332
333
334
335
336


	void createMaskOffsetSphere(std::vector<int>& table, int _i32radius);

	float computeCurvatureCount(const DataType *ptrVox, const std::vector<int>& sphere, DataType val);

Sylvain Thery's avatar
Sylvain Thery committed
337
338
339
340
	float computeCurvatureCount3(const DataType *ptrVox, const std::vector<int>& cylX, const std::vector<int>& cylY, const std::vector<int>& cyl2, DataType val);

	void createMaskOffsetCylinders(std::vector<int>& tableX, std::vector<int>& tableY, std::vector<int>& tableZ, int _i32radius);

341
	void addCross();
Sylvain Thery's avatar
Sylvain Thery committed
342
343
344
345
346
347

	void createNormalSphere(std::vector<Geom::Vec3f>& table, int _i32radius);

	Geom::Vec3f computeNormal(DataType *ptrVox, const std::vector<Geom::Vec3f>& sphere, DataType val, unsigned int radius);

	bool checkSaddlecomputeNormal(const Geom::Vec3f& P, const Geom::Vec3f& normal, unsigned int radius);
Pierre Kraemer's avatar
Pierre Kraemer committed
348
349
350
351
352
353
354
};


} // end namespace
} // end namespace
} // end namespace

Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
355
#include "Algo/MC/image.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
356
357
358
359



#endif