bufferGen.h 7.86 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

/***************************************************************************
                          buffer.h

Store points and faces of preceding
cubes to optimize algorithm, to share
vertices and compute neighbourhood
                             -------------------
    begin                : Tue Jul 31 2001
    copyright            : (C) 2001 by Sylvain THERY
    email                : 
 ***************************************************************************/

#ifndef BUFFERGEN_H
#define BUFFERGEN_H

namespace CGoGN
{

namespace Algo
{

namespace MC
{


/**
* A data structure which store 3 indices (one for each axe) of points and
* a table of faces indices
*
*/


template <typename DART>
struct HalfCubeGen
{
	/**
	* index of point on edge X (XY=0)
	*/
	unsigned int m_lX;
	
	/**
	* index of point on edge Y (XZ=0)
	*/
	unsigned int m_lY;
	
	/**
	* index of point on edge Z (XY=0)
	*/
	unsigned int m_lZ;

	/**
	* index of edge of face finishing on edge X (XY=0)
	*/
	DART m_lNX;
	
	/**
	* index of edge of face finishing on edge Y (XZ=0)
	*/
	DART m_lNY;
	
	/**
	* index of edge of face finishing on edge Z (XY=0)
	*/
	DART m_lNZ;	
	
	/**
	* table of edges included in the cube
	*/
	DART m_lFaceEdges[5]; 

};



/**
* @brief Buffer class to speed-up the marching cube
*
* The Buffer class store two slices of HalfCube whose permit
* to have a direct access to points that have been already
* created, and also to faces
*
*/

template <typename DART, typename DATATYPE >
class BufferGen
{
protected:
	
	/**
	* first slice of HalfCubes
	*/
	HalfCubeGen<DART> *m_hcSlice0;
	
	/**
	* second slice of HalfCubes
	*/
	HalfCubeGen<DART> *m_hcSlice1;

	DATATYPE *m_dataSl0;

	DATATYPE *m_dataSl1;

	
	/**
	* position of the first slice in image
	*/	
131
	int m_lZpos;
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135

	/**
	* width of slice
	*/	
136
	int m_lWidth;
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140

	/**
	* heigth of slice
	*/	
141
	int m_lHeight;
Pierre Kraemer's avatar
Pierre Kraemer committed
142 143 144 145 146 147 148 149 150 151
	
public:


	/**
	* constructor
	*************
	* @param   _lWidth the width of image to buffer
	* @param   _lHeight the height of image to buffer
	*/
152
	BufferGen(int _lWidth, int _lHeight);
Pierre Kraemer's avatar
Pierre Kraemer committed
153 154 155 156 157 158 159 160 161
	
	~BufferGen();

	long getWidth() { return m_lWidth;}
	long getHeight() { return m_lHeight;}


	/**
	* @name Function to store the index of a point on edge O..11 of a cube
162 163 164
	* @param  int _lX coordinate of the cube
	* @param  int _lY coordinate of the cube
	* @param  int _lPoint the index of the point
Pierre Kraemer's avatar
Pierre Kraemer committed
165 166 167 168 169 170 171 172
	*/
	//@{
	/**
	*  store the index of a point on edge O..11 of a cube
	* @param  _lX coordinate of the cube
	* @param  _lY coordinate of the cube
	* @param  _lPoint the embedding
	*/
173 174 175 176 177 178 179 180 181 182 183 184
	void setPointEdge0 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge1 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge2 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge3 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge4 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge5 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge6 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge7 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge8 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge9 (int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge10(int _lX,int _lY, unsigned int _lPoint);
	void setPointEdge11(int _lX,int _lY, unsigned int _lPoint);
Pierre Kraemer's avatar
Pierre Kraemer committed
185 186 187 188 189
	//@}

	/**
	* @name Function to get the index of point store on edge O..11 of a cube
	****************************************************
190 191 192
	* @param  int _lX coordinate of the cube
	* @param  int _lY coordinate of the cube
	* @param  int _lPoint the index of the point
Pierre Kraemer's avatar
Pierre Kraemer committed
193 194 195 196 197 198 199 200 201
	*/
	//@{
	/**
	* get the index of point store on edge O..11 of a cube
	****************************************************
	* @param  _lX coordinate of the cube
	* @param  _lY coordinate of the cube
	* @return   the index of the point
	*/
202 203 204 205 206 207 208 209 210 211 212 213
	unsigned int getPointEdge0 (int _lX,int _lY);
	unsigned int getPointEdge1 (int _lX,int _lY);
	unsigned int getPointEdge2 (int _lX,int _lY);
	unsigned int getPointEdge3 (int _lX,int _lY);
	unsigned int getPointEdge4 (int _lX,int _lY);
	unsigned int getPointEdge5 (int _lX,int _lY);
	unsigned int getPointEdge6 (int _lX,int _lY);
	unsigned int getPointEdge7 (int _lX,int _lY);
	unsigned int getPointEdge8 (int _lX,int _lY);
	unsigned int getPointEdge9 (int _lX,int _lY);
	unsigned int getPointEdge10(int _lX,int _lY);
	unsigned int getPointEdge11(int _lX,int _lY);
Pierre Kraemer's avatar
Pierre Kraemer committed
214 215 216 217 218 219 220 221 222
	//@}
	
	/**
	* get the address of Face Cube dart Table 
	*************************************
	* @param  _lX x coordinate of cube
	* @param  _lY y coordinate of cube
	* @return   table of faces
	*/
223
	DART* getFacesCubeTableAdr(int _lX,int _lY);
Pierre Kraemer's avatar
Pierre Kraemer committed
224 225 226 227 228 229 230 231 232

	/**
	* get dart table of faces stored on edge O..11 of a cube
	*
	* @param   _lX x coordinate of the cube
	* @param   _lY y coordinate of the cube
	* @param   _lZ z coordinate of the cube
	* @return   table of faces
	*/	
233
	const DART* getFacesCube(int _lX,int _lY,int _lZ) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
234 235 236 237 238 239 240 241 242
		
	
	/**
	* store indices of faces  on edge O..11 of a cube
	****************************************************
	* @param   _lX x coordinate of the cube
	* @param   _lY y coordinate of the cube
	* @param   _lFace table of faces index
	*/	
243
	void setFacesCube(int _lX,int _lY, const DART* const _lFace);
Pierre Kraemer's avatar
Pierre Kraemer committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259

	
	/**
	* swap from slice n to n+1 (Z++)
	*/
	void nextSlice();

	/**
	* set neighbour of faces stored on edge O..11 of a cube
	*
	* @param _cEdge code of the edge
	* @param   _lX x coordinate of the cube
	* @param   _lY y coordinate of the cube
	* @param   _lNeighbour neighbour to store
	*/	

260
	void setExternalNeighbour(char _cEdge, int _lX, int _lY, DART _lNeighbour);
Pierre Kraemer's avatar
Pierre Kraemer committed
261 262 263 264 265 266 267 268 269

	/**
	* get neighbour stored on edge O..11 of a cube
	* 
	* @param _cEdge code of the edge
	* @param   _lX x coordinate of the cube
	* @param   _lY y coordinate of the cube
	* @return   the neighbour
	*/	
270
	DART getExternalNeighbour(char _cEdge, int _lX, int _lY) const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
271 272


273
	void setData(int _lX, int _lY, DATATYPE data);
Pierre Kraemer's avatar
Pierre Kraemer committed
274

275
	DATATYPE getData(int _lX, int _lY);
Pierre Kraemer's avatar
Pierre Kraemer committed
276

277
	void setData2(int _lX, int _lY, DATATYPE data);
Pierre Kraemer's avatar
Pierre Kraemer committed
278

279
	DATATYPE getData2(int _lX, int _lY);
Pierre Kraemer's avatar
Pierre Kraemer committed
280 281 282 283 284 285 286 287 288 289 290 291

	DATATYPE* getDataPtr() { return m_dataSl0;}
	DATATYPE* getData2Ptr() {return m_dataSl1;}
};

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

#include "bufferGen.hpp"

#endif