buffer.h 7.47 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
* 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 BUFFER_H
#define BUFFER_H

namespace CGoGN
{

namespace Algo
{

46 47 48
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
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
namespace MC
{

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


template <typename DART>
class HalfCube
{
public:
	/**
	* 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>
class Buffer
{
protected:
	
	/**
	* first slice of HalfCubes
	*/
	HalfCube<DART> *m_hcSlice0;
	
	/**
	* second slice of HalfCubes
	*/
	HalfCube<DART> *m_hcSlice1;
	
	/**
	* position of the first slice in image
	*/	
127
	int m_lZpos;
Pierre Kraemer's avatar
Pierre Kraemer committed
128 129 130 131

	/**
	* width of slice
	*/	
132
	int m_lWidth;
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134 135 136

	/**
	* heigth of slice
	*/	
137
	int m_lHeight;
Pierre Kraemer's avatar
Pierre Kraemer committed
138 139 140 141 142 143 144 145 146 147
	
public:


	/**
	* constructor
	*************
	* @param   _lWidth the width of image to buffer
	* @param   _lHeight the height of image to buffer
	*/
148
	Buffer(int _lWidth, int _lHeight);
Pierre Kraemer's avatar
Pierre Kraemer committed
149 150 151 152 153
	
	~Buffer();

	/**
	* @name Function to store the index of a point on edge O..11 of a cube
154 155 156
	* @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
157 158 159 160 161 162 163 164
	*/
	//@{
	/**
	*  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
	*/
165 166 167 168 169 170 171 172 173 174 175 176
	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
177 178 179 180 181
	//@}

	/**
	* @name Function to get the index of point store on edge O..11 of a cube
	****************************************************
182 183 184
	* @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
185 186 187 188 189 190 191 192 193
	*/
	//@{
	/**
	* 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
	*/
194 195 196 197 198 199 200 201 202 203 204 205
	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
206 207 208 209 210 211 212 213 214
	//@}
	
	/**
	* get the address of Face Cube dart Table 
	*************************************
	* @param  _lX x coordinate of cube
	* @param  _lY y coordinate of cube
	* @return   table of faces
	*/
215
	DART* getFacesCubeTableAdr(int _lX,int _lY);
Pierre Kraemer's avatar
Pierre Kraemer committed
216 217 218 219 220 221 222 223 224

	/**
	* 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
	*/	
225
	const DART* getFacesCube(int _lX,int _lY,int _lZ) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
226 227 228 229 230 231 232 233 234
		
	
	/**
	* 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
	*/	
235
	void setFacesCube(int _lX,int _lY, const DART* const _lFace);
Pierre Kraemer's avatar
Pierre Kraemer committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

	
	/**
	* 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
	*/	

252
	void setExternalNeighbour(char _cEdge, int _lX, int _lY, DART _lNeighbour);
Pierre Kraemer's avatar
Pierre Kraemer committed
253 254 255 256 257 258 259 260 261

	/**
	* 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
	*/	
262
	DART getExternalNeighbour(char _cEdge, int _lX, int _lY) const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
263 264 265

};

266
}
Pierre Kraemer's avatar
Pierre Kraemer committed
267 268 269 270 271 272 273
} // end namespace
} // end namespace
} // end namespace

#include "buffer.hpp"

#endif