Voreen - Volume Rendering Engine Voreen - Volume Rendering Engine
Voreen - Volume Rendering Engine Westfälische Wilhelms-Universität Münster
  • About
  • Gallery
  • Download
  • Documentation
  • Publications
  • Community

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List

include/voreen/core/datastructures/volume/volumeelement.h

00001 /**********************************************************************
00002  *                                                                    *
00003  * Voreen - The Volume Rendering Engine                               *
00004  *                                                                    *
00005  * Copyright (C) 2005-2010 The Voreen Team. <http://www.voreen.org>   *
00006  *                                                                    *
00007  * This file is part of the Voreen software package. Voreen is free   *
00008  * software: you can redistribute it and/or modify it under the terms *
00009  * of the GNU General Public License version 2 as published by the    *
00010  * Free Software Foundation.                                          *
00011  *                                                                    *
00012  * Voreen is distributed in the hope that it will be useful,          *
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
00015  * GNU General Public License for more details.                       *
00016  *                                                                    *
00017  * You should have received a copy of the GNU General Public License  *
00018  * in the file "LICENSE.txt" along with this program.                 *
00019  * If not, see <http://www.gnu.org/licenses/>.                        *
00020  *                                                                    *
00021  * The authors reserve all rights not expressly granted herein. For   *
00022  * non-commercial academic use see the license exception specified in *
00023  * the file "LICENSE-academic.txt". To get information about          *
00024  * commercial licensing please contact the authors.                   *
00025  *                                                                    *
00026  **********************************************************************/
00027 
00028 #ifndef VRN_VOLUMEELEMENT
00029 #define VRN_VOLUMEELEMENT
00030 
00031 #include <limits>
00032 
00033 // Note: please ensure that no OpenGL dependencies are added into this file
00034 
00035 namespace voreen {
00036 
00037 namespace {
00041 template<class T>
00042 T getTypeUpperLimit() {
00043     return std::numeric_limits<T>::max();
00044 }
00045 
00046 template<class T>
00047 T getTypeLowerLimit() {
00048     return std::numeric_limits<T>::min();
00049 }
00050 
00051 template<class T>
00052 bool isTypeSigned() {
00053     return std::numeric_limits<T>::is_signed;
00054 }
00055 
00056 template<class T>
00057 bool isTypeBounded() {
00058     return std::numeric_limits<T>::is_bounded;
00059 }
00060 
00061 template<>
00062 float getTypeUpperLimit() {
00063     return 1.f;
00064 }
00065 
00066 template<>
00067 float getTypeLowerLimit() {
00068     return 0.f;
00069 }
00070 
00071 template<>
00072 double getTypeUpperLimit() {
00073     return 1.0;
00074 }
00075 
00076 template<>
00077 double getTypeLowerLimit() {
00078     return 0.0;
00079 }
00080 
00081 }
00082 
00086 template<class T>
00087 class VolumeElement {
00088 public:
00089     inline static T getZero();
00090 
00091     inline static T getChannel(const T& t, size_t channel);
00092     inline static void setChannel(T value, T& t, size_t channel);
00093 
00097     inline bool static isSigned();
00098 
00104     inline bool static isBounded();
00105 
00109     inline static T rangeMax();
00110 
00114     inline static T rangeMin();
00115 
00122     inline static float rangeMaxElement();
00123 
00127     inline static float rangeMinElement();
00128 
00133     inline static float getMinElement(const T& value);
00134 
00139     inline static float getMaxElement(const T& value);
00140 
00141     inline static int getNumChannels();
00142 
00146     static double calcSquaredDifference(T val1, T val2);
00147 
00148     typedef double DoubleType;
00149     typedef T BaseType;
00150 };
00151 
00152 template<class T>
00153 class VolumeElement<tgt::Vector2<T> > {
00154 public:
00155     inline static tgt::Vector2<T> getZero();
00156 
00157     inline static T getChannel(const tgt::Vector2<T>& t, size_t channel);
00158     inline static void setChannel(T value, tgt::Vector2<T>& t, size_t channel);
00159 
00160     inline static bool isSigned();
00161 
00162     inline bool static isBounded();
00163 
00164     inline static tgt::Vector2<T> rangeMax();
00165     inline static tgt::Vector2<T> rangeMin();
00166 
00171     inline static float rangeMaxElement();
00172     inline static float rangeMinElement();
00173 
00174     inline static float getMaxElement(const tgt::Vector2<T>& value);
00175     inline static float getMinElement(const tgt::Vector2<T>& value);
00176 
00177     inline static int getNumChannels();
00178 
00183     static double calcSquaredDifference(tgt::Vector2<T> val1, tgt::Vector2<T> val2);
00184 
00185     typedef tgt::Vector2<double> DoubleType;
00186     typedef T BaseType;
00187 };
00188 
00189 template<class T>
00190 class VolumeElement<tgt::Vector3<T> > {
00191 public:
00192     inline static tgt::Vector3<T> getZero();
00193 
00194     inline static T getChannel(const tgt::Vector3<T>& t, size_t channel);
00195     inline static void setChannel(T value, tgt::Vector3<T>& t, size_t channel);
00196 
00197     inline static bool isSigned();
00198 
00199     inline bool static isBounded();
00200 
00201     inline static tgt::Vector3<T> rangeMax();
00202     inline static tgt::Vector3<T> rangeMin();
00203 
00208     inline static float rangeMaxElement();
00209     inline static float rangeMinElement();
00210 
00211     inline static float getMaxElement(const tgt::Vector3<T>& value);
00212     inline static float getMinElement(const tgt::Vector3<T>& value);
00213 
00214     inline static int getNumChannels();
00215 
00220     static double calcSquaredDifference(tgt::Vector3<T> val1, tgt::Vector3<T> val2);
00221 
00222     typedef tgt::Vector3<double> DoubleType;
00223     typedef T BaseType;
00224 };
00225 
00226 template<class T>
00227 class VolumeElement<tgt::Vector4<T> > {
00228 public:
00229     inline static tgt::Vector4<T> getZero();
00230 
00231     inline static T getChannel(const tgt::Vector4<T>& t, size_t channel);
00232 
00233     inline static void setChannel(T value, tgt::Vector4<T>& t, size_t channel);
00234 
00235     inline static bool isSigned();
00236 
00237     inline bool static isBounded();
00238 
00239     inline static tgt::Vector4<T> rangeMax();
00240     inline static tgt::Vector4<T> rangeMin();
00241 
00246     inline static float rangeMaxElement();
00247     inline static float rangeMinElement();
00248 
00249     inline static float getMaxElement(const tgt::Vector4<T>& value);
00250     inline static float getMinElement(const tgt::Vector4<T>& value);
00251 
00252     inline static int getNumChannels();
00253 
00258     static double calcSquaredDifference(tgt::Vector4<T> val1, tgt::Vector4<T> val2);
00259 
00260     typedef tgt::Vector4<double> DoubleType;
00261     typedef T BaseType;
00262 };
00263 
00264 
00265 // ==============
00266 // implementation
00267 // ==============
00268 
00269 template<class T>
00270 inline T VolumeElement<T>::getZero() {
00271     return T(0);
00272 }
00273 
00274 template<class T>
00275 #ifdef VRN_DEBUG
00276 inline T VolumeElement<T>::getChannel(const T& t, size_t channel) {
00277     tgtAssert(channel == 0, "channel must be zero");
00278 #else
00279 inline  T VolumeElement<T>::getChannel(const T& t, size_t /*channel*/) {
00280 #endif
00281     return t;
00282 }
00283 
00284 template<class T>
00285 #ifdef VRN_DEBUG
00286 inline void VolumeElement<T>::setChannel(T value, T& t, size_t channel) {
00287     tgtAssert(channel == 0, "channel must be zero");
00288 #else
00289 inline void VolumeElement<T>::setChannel(T value, T& t, size_t /*channel*/) {
00290 #endif
00291     t = value;
00292 }
00293 
00294 template<class T>
00295 inline bool VolumeElement<T>::isSigned() {
00296     return isTypeSigned<T>();
00297 }
00298 
00299 template<class T>
00300 inline bool VolumeElement<T>::isBounded() {
00301     return isTypeBounded<T>();
00302 }
00303 
00304 template<class T>
00305 inline T VolumeElement<T>::rangeMax() {
00306     return static_cast<T>( getTypeUpperLimit<T>() );
00307 }
00308 
00309 template<class T>
00310 inline T VolumeElement<T>::rangeMin() {
00311     return static_cast<T>( getTypeLowerLimit<T>() );
00312 }
00313 
00318 template<class T>
00319 inline float VolumeElement<T>::rangeMaxElement() {
00320     return static_cast<float>( getTypeUpperLimit<T>() );
00321 }
00322 
00323 template<class T>
00324 float voreen::VolumeElement<T>::getMaxElement(const T& value) {
00325     return static_cast<float>(value);
00326 }
00327 
00328 template<class T>
00329 float voreen::VolumeElement<T>::getMinElement(const T& value) {
00330     return static_cast<float>(value);
00331 }
00332 
00333 template<class T>
00334 inline float VolumeElement<T>::rangeMinElement() {
00335     return static_cast<float>( getTypeLowerLimit<T>() );
00336 }
00337 
00338 template<class T>
00339 inline int VolumeElement<T>::getNumChannels() {
00340     return 1;
00341 }
00342 
00346 template<class T>
00347 double VolumeElement<T>::calcSquaredDifference(T val1, T val2) {
00348     double result;
00349 
00350     result = static_cast<double>(val1) - static_cast<double>(val2);
00351     result = result * result;
00352 
00353     return result;
00354 }
00355 
00356 // --- Vector2 ----
00357 
00358 template<class T>
00359 inline tgt::Vector2<T> VolumeElement<tgt::Vector2<T> >::getZero() {
00360     return tgt::Vector2<T>(T(0), T(0));
00361 }
00362 
00363 template<class T>
00364 inline T VolumeElement<tgt::Vector2<T> >::getChannel(const tgt::Vector2<T>& t, size_t channel) {
00365     tgtAssert(channel < 2, "channel must be less than 2");
00366     if (channel < 2)
00367         return t[channel];
00368     else
00369         return 0;
00370 }
00371 
00372 template<class T>
00373 inline void VolumeElement<tgt::Vector2<T> >::setChannel(T value, tgt::Vector2<T>& t, size_t channel) {
00374     tgtAssert(channel < 2, "channel must be less than 2");
00375     t[channel] = value;
00376 }
00377 
00378 template<class T>
00379 inline bool VolumeElement<tgt::Vector2<T> >::isSigned() {
00380     return isTypeSigned<T>();
00381 }
00382 
00383 template<class T>
00384 inline bool VolumeElement<tgt::Vector2<T> >::isBounded() {
00385     return isTypeBounded<T>();
00386 }
00387 
00388 template<class T>
00389 inline tgt::Vector2<T> VolumeElement<tgt::Vector2<T> >::rangeMax() {
00390     return tgt::Vector2<T>(getTypeUpperLimit<T>());
00391 }
00392 
00393 template<class T>
00394 inline tgt::Vector2<T> VolumeElement<tgt::Vector2<T> >::rangeMin() {
00395     return tgt::Vector2<T>(getTypeLowerLimit<T>());
00396 }
00397 
00402 template<class T>
00403 inline float VolumeElement<tgt::Vector2<T> >::rangeMaxElement() {
00404     return static_cast<float>(getTypeUpperLimit<T>());
00405 }
00406 
00407 template<class T>
00408 inline float VolumeElement<tgt::Vector2<T> >::rangeMinElement() {
00409     return static_cast<float>(getTypeLowerLimit<T>());
00410 }
00411 
00412 template<class T>
00413 float voreen::VolumeElement<tgt::Vector2<T> >::getMaxElement(const tgt::Vector2<T>& value) {
00414     return static_cast<float>(value.x);
00415 }
00416 
00417 template<class T>
00418 float voreen::VolumeElement<tgt::Vector2<T> >::getMinElement(const tgt::Vector2<T>& value) {
00419     return static_cast<float>(value.x);
00420 }
00421 
00422 template<class T>
00423 inline int VolumeElement<tgt::Vector2<T> >::getNumChannels() {
00424     return 2;
00425 }
00426 
00431 template<class T>
00432 double VolumeElement<tgt::Vector2<T> >::calcSquaredDifference(tgt::Vector2<T> val1, tgt::Vector2<T> val2) {
00433     double result;
00434     tgt::Vector2d difference;
00435 
00436     difference.x = (double)val1.x - (double)val2.x;
00437     difference.y = (double)val1.y - (double)val2.y;
00438 
00439     difference.x = difference.x * difference.x;
00440     difference.y = difference.y * difference.y;
00441 
00442     result = difference.x + difference.y;
00443 
00444     return result;
00445 }
00446 
00447 // --- Vector3 ----
00448 
00449 template<class T>
00450 inline tgt::Vector3<T> VolumeElement<tgt::Vector3<T> >::getZero() {
00451     return tgt::Vector3<T>(T(0), T(0), T(0));
00452 }
00453 
00454 template<class T>
00455 inline T VolumeElement<tgt::Vector3<T> >::getChannel(const tgt::Vector3<T>& t, size_t channel) {
00456     tgtAssert(channel < 3, "channel must be less than 3");
00457     if (channel < 3)
00458         return t[channel];
00459     else
00460         return 0;
00461 }
00462 
00463 template<class T>
00464 inline void VolumeElement<tgt::Vector3<T> >::setChannel(T value, tgt::Vector3<T>& t, size_t channel) {
00465     tgtAssert(channel < 3, "channel must be less than 3");
00466     t[channel] = value;
00467 }
00468 
00469 template<class T>
00470 inline bool VolumeElement<tgt::Vector3<T> >::isSigned() {
00471     return isTypeSigned<T>();
00472 }
00473 
00474 template<class T>
00475 inline bool VolumeElement<tgt::Vector3<T> >::isBounded() {
00476     return isTypeBounded<T>();
00477 }
00478 
00479 template<class T>
00480 inline tgt::Vector3<T> VolumeElement<tgt::Vector3<T> >::rangeMax() {
00481     return tgt::Vector3<T>(getTypeUpperLimit<T>());
00482 }
00483 
00484 template<class T>
00485 inline tgt::Vector3<T> VolumeElement<tgt::Vector3<T> >::rangeMin() {
00486     return tgt::Vector3<T>(getTypeLowerLimit<T>());
00487 }
00488 
00493 template<class T>
00494 inline float VolumeElement<tgt::Vector3<T> >::rangeMaxElement() {
00495     return static_cast<float>(getTypeUpperLimit<T>());
00496 }
00497 
00498 template<class T>
00499 inline float VolumeElement<tgt::Vector3<T> >::rangeMinElement() {
00500     return static_cast<float>(getTypeLowerLimit<T>());
00501 }
00502 
00503 template<class T>
00504 float voreen::VolumeElement<tgt::Vector3<T> >::getMaxElement(const tgt::Vector3<T>& value) {
00505     return static_cast<float>(value.x);
00506 }
00507 
00508 template<class T>
00509 float voreen::VolumeElement<tgt::Vector3<T> >::getMinElement(const tgt::Vector3<T>& value) {
00510     return static_cast<float>(value.y);
00511 }
00512 
00513 template<class T>
00514 inline int VolumeElement<tgt::Vector3<T> >::getNumChannels() {
00515     return 3;
00516 }
00517 
00522 template<class T>
00523 double VolumeElement<tgt::Vector3<T> >::calcSquaredDifference(tgt::Vector3<T> val1, tgt::Vector3<T> val2) {
00524     double result;
00525     tgt::Vector3d difference;
00526 
00527     difference.x = (double)val1.x - (double)val2.x;
00528     difference.y = (double)val1.y - (double)val2.y;
00529     difference.z = (double)val1.z - (double)val2.z;
00530 
00531     difference.x = difference.x * difference.x;
00532     difference.y = difference.y * difference.y;
00533     difference.z = difference.z * difference.z;
00534 
00535     result = difference.x + difference.y + difference.z;
00536 
00537     return result;
00538 }
00539 
00540 // --- Vector4 ----
00541 
00542 template<class T>
00543 inline tgt::Vector4<T> VolumeElement<tgt::Vector4<T> >::getZero() {
00544     return tgt::Vector4<T>(T(0), T(0), T(0), T(0));
00545 }
00546 
00547 template<class T>
00548 inline T VolumeElement<tgt::Vector4<T> >::getChannel(const tgt::Vector4<T>& t, size_t channel) {
00549     tgtAssert(channel < 4, "channel must be less than 4");
00550     if (channel < 4)
00551         return t[channel];
00552     else
00553         return 0;
00554 }
00555 
00556 template<class T>
00557 inline void VolumeElement<tgt::Vector4<T> >::setChannel(T value, tgt::Vector4<T>& t, size_t channel) {
00558     tgtAssert(channel < 4, "channel must be less than 4");
00559     t[channel] = value;
00560 }
00561 
00562 template<class T>
00563 inline bool VolumeElement<tgt::Vector4<T> >::isSigned() {
00564     return isTypeSigned<T>();
00565 }
00566 
00567 template<class T>
00568 inline bool VolumeElement<tgt::Vector4<T> >::isBounded() {
00569     return isTypeBounded<T>();
00570 }
00571 
00572 template<class T>
00573 inline tgt::Vector4<T> VolumeElement<tgt::Vector4<T> >::rangeMax() {
00574     return tgt::Vector4<T>(getTypeUpperLimit<T>());
00575 }
00576 
00577 template<class T>
00578 inline tgt::Vector4<T> VolumeElement<tgt::Vector4<T> >::rangeMin() {
00579     return tgt::Vector4<T>(getTypeLowerLimit<T>());
00580 }
00581 
00586 template<class T>
00587 inline float VolumeElement<tgt::Vector4<T> >::rangeMaxElement() {
00588     return static_cast<float>(getTypeUpperLimit<T>());
00589 }
00590 
00591 template<class T>
00592 inline float VolumeElement<tgt::Vector4<T> >::rangeMinElement() {
00593     return static_cast<float>(getTypeLowerLimit<T>());
00594 }
00595 
00596 template<class T>
00597 float voreen::VolumeElement<tgt::Vector4<T> >::getMaxElement(const tgt::Vector4<T>& value) {
00598     return static_cast<float>(value.x);
00599 }
00600 
00601 template<class T>
00602 float voreen::VolumeElement<tgt::Vector4<T> >::getMinElement(const tgt::Vector4<T>& value) {
00603     return static_cast<float>(value.x);
00604 }
00605 
00606 template<class T>
00607 inline int VolumeElement<tgt::Vector4<T> >::getNumChannels() {
00608     return 4;
00609 }
00610 
00615 template<class T>
00616 double VolumeElement<tgt::Vector4<T> >::calcSquaredDifference(tgt::Vector4<T> val1, tgt::Vector4<T> val2) {
00617     double result;
00618     tgt::Vector4d difference;
00619 
00620     difference.x = static_cast<double>(val1.x) - static_cast<double>(val2.x);
00621     difference.y = static_cast<double>(val1.y) - static_cast<double>(val2.y);
00622     difference.z = static_cast<double>(val1.z) - static_cast<double>(val2.z);
00623     difference.w = static_cast<double>(val1.w) - static_cast<double>(val2.w);
00624 
00625     difference.x = difference.x*difference.x;
00626     difference.y = difference.y*difference.y;
00627     difference.z = difference.z*difference.z;
00628     difference.w = difference.w*difference.w;
00629 
00630     result = difference.x + difference.y + difference.z + difference.w;
00631 
00632     return result;
00633 }
00634 
00635 
00636 } // namespace voreen
00637 
00638 #endif // VRN_VOLUMEELEMENT
  • Getting Started
  • Video Tutorials
  • Build Instructions
  • Adding a Module
  • Programming Tutorials
  • API Documentation
  • FAQ
edit