Une mise-à-jour est prévue le 9 juillet entre 13:00 et 14:00. Le service sera inaccessible ou instable pendant cette période. Merci de votre compréhension.

grmNeighborhood.cxx 1.98 KB
Newer Older
Pierre Lassalle's avatar
Pierre Lassalle committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*=========================================================================

  Program: Generic Region Merging Library
  Language: C++
  author: Lassalle Pierre
  contact: lassallepierre34@gmail.com



  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "grmNeighborhood.h"

namespace grm
{
22 23
	void FOURNeighborhood(__int64 * neighborhood,
						  const std::size_t id,
Pierre Lassalle's avatar
Pierre Lassalle committed
24 25 26
						  const unsigned int width,
						  const unsigned int height)
	{	
27 28
		const std::size_t x = id % width;
		const std::size_t y = id / width;
Pierre Lassalle's avatar
Pierre Lassalle committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42

		/* top */
		neighborhood[0] = ( y > 0 ? (id - width) : -1 );

		/* right */
		neighborhood[1] = ( x < (width - 1) ? (id + 1) : -1 );

		/* bottom */
		neighborhood[2] = ( y < (height - 1) ? (id + width) : -1 );

		/* left */
		neighborhood[3] = ( x > 0 ? (id - 1) : -1 );
	}
	
43 44
	void EIGHTNeighborhood(__int64 * neighborhood,
						   const std::size_t id,
Pierre Lassalle's avatar
Pierre Lassalle committed
45 46 47
						  const unsigned int width,
						  const unsigned int height)
	{
48 49
		const std::size_t x = id % width;
		const std::size_t y = id / width;
Pierre Lassalle's avatar
Pierre Lassalle 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 75

		/* top */
		neighborhood[0] = ( y > 0 ? (id - width) : -1 );

		/* top right */
		neighborhood[1] = ( (y > 0 && x < (width - 1) ) ? (id - width + 1) : -1 );
		
		/* right */
		neighborhood[2] = ( x < (width - 1) ? (id + 1) : -1 );

		/* bottom right */
		neighborhood[3] = ( (x < (width - 1) && y < (height - 1) ) ? (id + 1 + width) : -1);

		/* bottom */
		neighborhood[4] = ( y < (height - 1) ? (id + width) : -1 );

		/* bottom left */
		neighborhood[5] = ( (y < (height - 1) && x > 0) ? (id + width - 1) : -1 );
		
		/* left */
		neighborhood[6] = ( x > 0 ? (id - 1) : -1 );

		/* top left */
		neighborhood[7] = ( (x > 0 && y > 0) ? (id -width - 1) : - 1);
	}
} // end of namespace grm