windowing.h 7.84 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef WINDOWING_H
#define WINDOWING_H

#include "Algo/MC/type.h"

#include <iostream>

namespace CGoGN
{

namespace Algo
{

38 39 40
namespace Surface
{

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

/**
 * Common windowing class
 * @param DataType the type of image voxel
 *
 * Windowing derived  classes are used as template,
 * and minimum interface are function
 * - inside
 * - insideWich
 * - interpole
 *
 */
template<class DataType>
class WindowingClass
{
protected:
	/// value that cut space in two lower is outside upper is inside
	DataType m_value;

	/// min value (lower values are outside object
	DataType m_min;

	/// max value (upper values are outside object
	DataType m_max;

public:
	/**
	 * Default constructor
	 */
	WindowingClass() : m_value(), m_min(), m_max() {}

	/**
	 * copy constructor
	 */
	WindowingClass(const WindowingClass& wind) : m_value(wind.m_value), m_min(wind.m_min), m_max(wind.m_max) {}

	/**
	 * set the iso value to use
	 * @param val the isovalue
	 */
	void setIsoValue(DataType val) {
		m_value = val;
	}

	/**
	 * set the min and max  value to use
	 * @param min the min value
	 * @param max the max value
	 */
	void setMinMax(DataType min, DataType max) {
		m_min = min;
		m_max = max;
	}
};

/**
 * Windowing class: inside is only voxel with value equal to isoValue
 * @param DataType the type of image voxel
 */
template<class DataType>
class WindowingEqual : public WindowingClass<DataType>
{
public:

	WindowingEqual(){}

	/**
	 * copy constructor
	 */
	WindowingEqual(const WindowingEqual& wind) : WindowingClass<DataType>(wind) {}

	/**
	 * @return a label corresponding to value
	 * @param val voxel value
	 * @return label
	 */
	int16 insideWich(DataType val) const {
		return static_cast<int16>(val);
	}

	/**
	 * @return true if voxel is inside the object
	 */
	bool inside(DataType val) const {
		return val == this->m_value;
	}

	/**
	 * Give interpolation between to voxel value. Here always 0.5
	 * @param val1 voxel first value
	 * @param val2 voxel second value
	 */
	float interpole(DataType val1, DataType val2) const {
		return 0.5f;
	}
};

/**
 * Windowing class: inside is only voxel with value different of isoValue
 * @param DataType the type of image voxel
 */
template<class DataType>
class WindowingDiff : public WindowingClass<DataType>
{
public:

	WindowingDiff(){}

	/**
	 * copy constructor
	 */
	WindowingDiff(const WindowingDiff& wind) : WindowingClass<DataType>(wind) {}

	/**
	 * @return a label corresponding to value
	 * @param val voxel value
	 * @return label
	 */
	int16 insideWich(DataType val) const {
		return static_cast<int16>(val);
	}

	/**
	 * @return true if voxel is inside the object
	 */
	bool inside(DataType val) const {
		return val != this->m_value;
	}

	/**
	 * Give interpolation between to voxel value. Here always 0.5
	 * @param val1 voxel first value
	 * @param val2 voxel second value
	 */
	float interpole(DataType, DataType) const {
		return 0.5f;
	}
};

/**
 * Windowing class: inside is only voxel with value greater than of isoValue
 * @param DataType the type of image voxel
 */
template<class DataType>
class WindowingGreater : public WindowingClass<DataType>
{
public:

	WindowingGreater() {}

	/**
	 * copy constructor
	 */
	WindowingGreater(const WindowingGreater& wind) : WindowingClass<DataType>(wind) {}

	/**
	 * @return a label corresponding to value
	 * @param val voxel value
	 * @return label
	 */
	int16 insideWich(DataType val) const {
		return static_cast<int16>(val);
	}

	/**
	 * @return true if voxel is inside the object
	 */
	bool inside(DataType val) const {
Sylvain Thery's avatar
Sylvain Thery committed
211
		return  (val >= this->m_value);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	}

	/**
	 * Give interpolation between to voxel value
	 * @param val1 voxel first value
	 * @param val2 voxel second value
	 */
	float interpole(DataType val1, DataType val2) const {
		return  static_cast<float>(this->m_value - val1) / static_cast<float>(val2 - val1);
	}
};

/**
 * Windowing class: inside is only voxel with value greater than of isoValue
 * @param DataType the type of image voxel
 */
template<class DataType>
class WindowingLess : public WindowingClass<DataType>
{
public:

	WindowingLess() {}

	/**
	 * copy constructor
	 */
	WindowingLess(const WindowingLess& wind) : WindowingClass<DataType>(wind) {}

	/**
	 * @return a label corresponding to value
	 * @param val voxel value
	 * @return label
	 */
	int16 insideWich(DataType val) const {
		return static_cast<int16>(val);
	}

	/**
	 * @return true if voxel is inside the object
	 */
	bool inside(DataType val) const {
		return  (val<=this->m_value);
	}

	/**
	 * Give interpolation between to voxel value
	 * @param val1 voxel first value
	 * @param val2 voxel second value
	 */
	float interpole(DataType val1, DataType val2) const {
		return  static_cast<float>(this->m_value - val1) / static_cast<float>(val2 - val1);
	}
};


/**
 * Windowing class: inside is only voxel with value between min and max
 * @param DataType the type of image voxel
 */
template<class DataType>
class WindowingInterval : public WindowingClass<DataType>
{
public:

	WindowingInterval() {}

	/**
	 * copy constructor
	 */
	WindowingInterval(const WindowingInterval& wind) : WindowingClass<DataType>(wind) {}

	/**
	 * @return a label corresponding to value
	 * @param val voxel value
	 * @return label
	 */
	int16 insideWich(DataType val) const {
		return static_cast<int16>(val);
	}

	/**
	 * @return true if voxel is inside the object
	 */
	bool inside(DataType val) const {
		return (val>=this->m_min) && (val<=this->m_max);
	}

	/**
	 * Give interpolation between to voxel value
	 * @param val1 voxel first value
	 * @param val2 voxel second value
	 */
	float interpole(DataType val1, DataType val2) const {
		if (val1 < val2)
		{
			if (val1 < this->m_min)
			{
				return static_cast<float>(this->m_min - val1) / static_cast<float>(val2 - val1);
			}
			return static_cast<float>(this->m_max - val1) / static_cast<float>(val2 - val1);
		}

		if (val2 < this->m_min)
		{
			return static_cast<float>(this->m_min - val2) / static_cast<float>(val1 - val2);
		}
		return static_cast<float>(this->m_max - val2) / static_cast<float>(val1 - val2);
	}
};

322
}
Pierre Kraemer's avatar
Pierre Kraemer committed
323 324 325 326 327 328 329
} // end namespace
} // end namespace
} // end namespace

#endif