00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __mitkVolumeIterator_h
00012 #define __mitkVolumeIterator_h
00013
00014 #ifndef MITK_VER_OOC
00015 #include "mitkVolume.h"
00016 #else
00017 #include "mitkICVolume.h"
00018 #endif
00019
00020
00023
00024
00025
00026
00027
00028 class mitkVolumeIteratorBase
00029 {
00030 public:
00031 mitkVolumeIteratorBase() {}
00032
00033 ~mitkVolumeIteratorBase() {}
00034
00035 virtual void SetVolume(mitkVolume* vol) = 0;
00036
00037
00038 virtual ScalarPixelType GetPixel(const ScalarIndexType* index, int ch=0) = 0;
00039 virtual ScalarPixelType GetPixel(const VectorIndexType& index, int ch=0) = 0;
00040 virtual ScalarPixelType GetPixel(ScalarIndexType x, ScalarIndexType y, ScalarIndexType z, int ch=0) = 0;
00041 virtual void GetPixel(const ScalarIndexType* index, ScalarPixelType* value) = 0;
00042 virtual void GetPixel(const VectorIndexType& index, VectorPixelType& value) = 0;
00043
00044 virtual void SetPixel(ScalarPixelType val, ScalarIndexType x, ScalarIndexType y, ScalarIndexType z, int ch=0) = 0;
00045
00046 virtual void GetSequence(ScalarPixelType* values, int mode) = 0;
00047 virtual void SetSequence(const ScalarPixelType* values, int mode) = 0;
00048
00049
00050 virtual void GetNeighbors2x(const ScalarIndexType* index, ScalarPixelType* value, int ch=0) = 0;
00051
00052 virtual void GetNeighbors4x(const ScalarIndexType* index, ScalarPixelType* value, int ch=0) = 0;
00053
00054
00055
00056 virtual ScalarPixelType Value() = 0;
00057 virtual ScalarParameterType Value(int c) = 0;
00058 virtual void Get(ScalarPixelType* v) = 0;
00059 virtual void Get(VectorPixelType& v) = 0;
00060 virtual void Get(ScalarParameterType* v) = 0;
00061 virtual void Get(VectorParameterType& v) = 0;
00062
00063 virtual void Set(const ScalarPixelType& pixel) = 0;
00064 virtual void Set(const ScalarPixelType* pixel) = 0;
00065 virtual void Set(const VectorPixelType& pixel) = 0;
00066 virtual void Set(const ScalarParameterType& pixel) = 0;
00067 virtual void Set(const ScalarParameterType* pixel) = 0;
00068 virtual void Set(const VectorParameterType& pixel) = 0;
00069
00070 virtual void GoToBegin(void) = 0;
00071 virtual void GoToEnd(void) = 0;
00072 virtual void GoToNextRow(void) = 0;
00073 virtual void GoToNextCol(void) = 0;
00074 virtual void GoToNextSlice(void) = 0;
00075 virtual void GoToNextX(int mode) = 0;
00076 virtual void SetIndex(const VectorIndexType &ind) = 0;
00077
00078
00079
00080
00081 virtual void operator++() = 0;
00082 virtual void operator--() = 0;
00083
00084
00085 virtual void SetNumberOfSamples( unsigned long number ) {}
00086 virtual unsigned long GetNumberOfSamples( void ) const {return 0;}
00087 virtual void ReinitializeSeed() {}
00088 virtual void ReinitializeSeed(int) {}
00089
00090 void SetDefaultChannel(int ch)
00091 {
00092 m_DefaultChannel = ch;
00093 }
00094
00095 virtual bool IsAtBegin(void) const
00096 {
00097 bool res = true;
00098 for(unsigned int i=0;i<m_ImageDimension;i++)
00099 if(m_PositionIndex[i] != m_BeginIndex[i])
00100 res = false;
00101 return res;
00102 }
00103
00104 virtual bool IsAtEnd(void) const
00105 {
00106 return !m_Remaining;
00107 }
00108
00109 void SetRegion(const VectorIndexType& region)
00110 {
00111 m_Region = region;
00112 if(m_ImageDimension == 0) return;
00113 this->initRegion();
00114 }
00115
00116 const VectorIndexType & GetRegion(void) const
00117 {
00118 return m_Region;
00119 }
00120
00121 const VectorIndexType & GetEntireImageRegion(void)
00122 {
00123 if(m_ImageDimension == 0) return m_Region;
00124
00125 if(m_Region.size() == 0)
00126 {
00127 m_Region = VectorIndexType(m_ImageDimension*2,0);
00128 }
00129
00130 for(unsigned int i=0;i<m_ImageDimension;i++)
00131 {
00132 m_Region[i*2] = 0;
00133 m_Region[i*2+1] = m_Dimensions[i] - 1;
00134 }
00135
00136 return m_Region;
00137 }
00138
00139 const VectorIndexType& GetIndex(void) const
00140 {
00141 return m_PositionIndex;
00142 }
00143
00144 virtual ScalarIndexType ComputeOffset(const VectorIndexType& index)
00145 {
00146 ScalarIndexType offset = 0;
00147 for(unsigned int i=0;i<m_ImageDimension;i++)
00148 {
00149 offset += index[i] * m_Increments[i];
00150 }
00151 return offset;
00152 }
00153
00154 virtual ScalarIndexType ComputeOffset(const ScalarIndexType* index)
00155 {
00156 ScalarIndexType offset = 0;
00157 for(unsigned int i=0;i<m_ImageDimension;i++)
00158 {
00159 offset += index[i] * m_Increments[i];
00160 }
00161 return offset;
00162 }
00163
00164 virtual ScalarIndexType ComputeOffset(const ScalarIndexType x, const ScalarIndexType y, const ScalarIndexType z=0)
00165 {
00166 ScalarIndexType offset = 0;
00167 offset += x * m_Increments[0];
00168 offset += y * m_Increments[1];
00169 offset += z * m_Increments[2];
00170 return offset;
00171 }
00172
00173 unsigned int GetNumberOfPixelsInRegion()
00174 {
00175 unsigned int counts = m_Region[1] - m_Region[0] + 1;
00176 for(unsigned int i=1;i<m_ImageDimension;i++)
00177 {
00178 counts *= m_Region[2*i+1] - m_Region[2*i] + 1;
00179 }
00180 return (counts == 1) ? 0 : counts;
00181 }
00182
00183 virtual void SetIOMode(int mode) {};
00184
00185 protected:
00186 virtual void init() = 0;
00187 virtual void initRegion() = 0;
00188
00189 mitkVolume* m_Volume;
00190
00191 VectorIndexType m_PositionIndex;
00192 VectorIndexType m_BeginIndex;
00193 VectorIndexType m_EndIndex;
00194
00195 VectorIndexType m_Region;
00196 int m_Dimensions[3];
00197 int m_Dimensions2[3];
00198 int m_Increments[3];
00199 int m_DefaultChannel;
00200
00201 unsigned int m_ImageDimension;
00202 unsigned int m_NumberOfChannels;
00203 bool m_Remaining;
00204 };
00205
00206
00207
00208
00209
00210 template<class T>
00211 class mitkVolumeIterator : public mitkVolumeIteratorBase
00212 {
00213 protected:
00214 virtual void init();
00215 virtual void initRegion();
00216
00217 T* m_DataPointer;
00218
00219 T* m_Position;
00220 T* m_Begin;
00221 T* m_End;
00222
00223 ScalarIndexType m_OffsetTable[3];
00224 ScalarIndexType m_IncremetTable[8];
00225
00226 public:
00227 mitkVolumeIterator();
00228
00229 mitkVolumeIterator(mitkVolume* vol);
00230
00231 mitkVolumeIterator(mitkVolume* vol, VectorIndexType& region);
00232
00233 ~mitkVolumeIterator() {};
00234
00235 virtual void SetIOMode(int mode) {};
00236
00237 virtual void SetVolume(mitkVolume* vol);
00238
00239 virtual ScalarPixelType GetPixel(const ScalarIndexType* index, int ch=0)
00240 {
00241 ScalarIndexType offset = this->ComputeOffset(index) + ch;
00242 return static_cast<ScalarPixelType>( *(m_DataPointer + offset) );
00243 }
00244
00245 virtual ScalarPixelType GetPixel(const VectorIndexType & index, int ch=0)
00246 {
00247 ScalarIndexType offset = this->ComputeOffset(index) + ch;
00248 return static_cast<ScalarPixelType>( *(m_DataPointer + offset) );
00249 }
00250
00251 virtual ScalarPixelType GetPixel(ScalarIndexType x, ScalarIndexType y, ScalarIndexType z=0, int ch=0)
00252 {
00253 ScalarIndexType offset = this->ComputeOffset(x,y,z) + ch;
00254 return static_cast<ScalarPixelType>( *(m_DataPointer + offset) );
00255 }
00256
00257 virtual void GetPixel(const ScalarIndexType* index, ScalarPixelType* value)
00258 {
00259 ScalarIndexType offset = this->ComputeOffset(index);
00260 T* pos = m_DataPointer + offset;
00261 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00262 {
00263 value[i] = static_cast<ScalarPixelType>( *pos );
00264 pos++;
00265 }
00266 }
00267
00268 virtual void GetPixel(const VectorIndexType & index, VectorPixelType& value)
00269 {
00270 ScalarIndexType offset = this->ComputeOffset(index);
00271 T* pos = m_DataPointer + offset;
00272 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00273 {
00274 value[i] = static_cast<ScalarPixelType>( *pos );
00275 pos++;
00276 }
00277 }
00278
00279 virtual void SetPixel(ScalarPixelType val, ScalarIndexType x, ScalarIndexType y, ScalarIndexType z, int ch=0)
00280 {
00281 ScalarIndexType offset = this->ComputeOffset(x,y,z) + ch;
00282 *(m_DataPointer + offset) = static_cast<T>( val );
00283 }
00284
00285 virtual void GetSequence(ScalarPixelType* values, int mode);
00286 virtual void SetSequence(const ScalarPixelType* values, int mode);
00287
00288 virtual ScalarPixelType Value()
00289 {
00290 return static_cast<ScalarPixelType>( *m_Position );
00291 }
00292
00293 virtual ScalarParameterType Value(int c)
00294 {
00295 return static_cast<ScalarParameterType>( *(m_Position + c) );
00296 }
00297
00298 virtual void Set(const ScalarPixelType* pixel)
00299 {
00300 T* pos = m_Position;
00301 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00302 {
00303 *pos = static_cast<T>( pixel[i] );
00304 pos++;
00305 }
00306 }
00307
00308 virtual void Set(const VectorPixelType& pixel)
00309 {
00310 T* pos = m_Position;
00311 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00312 {
00313 *pos = static_cast<T>( pixel[i] );
00314 pos++;
00315 }
00316 }
00317
00318 virtual void Set(const ScalarParameterType* pixel)
00319 {
00320 T* pos = m_Position;
00321 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00322 {
00323 *pos = static_cast<T>( pixel[i] );
00324 pos++;
00325 }
00326 }
00327
00328 virtual void Set(const VectorParameterType& pixel)
00329 {
00330 T* pos = m_Position;
00331 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00332 {
00333 *pos = static_cast<T>( pixel[i] );
00334 pos++;
00335 }
00336 }
00337
00338 virtual void Set(const ScalarPixelType& pixel)
00339 {
00340 T* pos = m_Position;
00341 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00342 {
00343 *pos = static_cast<T>( pixel );
00344 pos++;
00345 }
00346 }
00347
00348 virtual void Set(const ScalarParameterType& pixel)
00349 {
00350 T* pos = m_Position;
00351 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00352 {
00353 *pos = static_cast<T>( pixel );
00354 pos++;
00355 }
00356 }
00357
00358 virtual void Get(ScalarPixelType* v)
00359 {
00360 T* pos = m_Position;
00361 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00362 {
00363 v[i] = static_cast<ScalarPixelType>( *pos );
00364 pos++;
00365 }
00366 }
00367
00368 virtual void Get(VectorPixelType& v)
00369 {
00370 T* pos = m_Position;
00371 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00372 {
00373 v[i] = static_cast<ScalarPixelType>( *pos );
00374 pos++;
00375 }
00376 }
00377
00378 virtual void Get(VectorParameterType& v)
00379 {
00380 T* pos = m_Position;
00381 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00382 {
00383 v[i] = static_cast<ScalarParameterType>( *pos );
00384 pos++;
00385 }
00386 }
00387
00388 virtual void Get(ScalarParameterType* v)
00389 {
00390 T* pos = m_Position;
00391 for(unsigned int i=0;i<m_NumberOfChannels;i++)
00392 {
00393 v[i] = static_cast<ScalarParameterType>( *pos );
00394 pos++;
00395 }
00396 }
00397
00398 virtual void GetNeighbors2x(const ScalarIndexType* index, ScalarPixelType* value, int ch=0);
00399 virtual void GetNeighbors4x(const ScalarIndexType* index, ScalarPixelType* value, int ch=0);
00400
00401 virtual void GoToBegin(void);
00402 virtual void GoToEnd(void);
00403 virtual void GoToNextRow(void);
00404 virtual void GoToNextCol(void);
00405 virtual void GoToNextSlice(void);
00406 virtual void GoToNextX(int mode);
00407
00408 virtual void SetIndex(const VectorIndexType &ind);
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 virtual void operator++();
00421 virtual void operator--();
00422
00423 private:
00424 mitkVolumeIterator(const mitkVolumeIterator&);
00425 void operator=(const mitkVolumeIterator&);
00426
00427 };
00428
00430
00431
00432 template<class T>
00433 mitkVolumeIterator<T>::mitkVolumeIterator()
00434 {
00435 m_Volume = NULL;
00436 m_Remaining = false;
00437 m_ImageDimension = 0;
00438 m_NumberOfChannels = 0;
00439 m_DefaultChannel = 0;
00440 }
00441
00442 template<class T>
00443 mitkVolumeIterator<T>::mitkVolumeIterator(mitkVolume* vol)
00444 {
00445 m_Remaining = false;
00446 m_ImageDimension = 0;
00447 m_NumberOfChannels = 0;
00448 m_DefaultChannel = 0;
00449
00450 this->SetVolume(vol);
00451 }
00452
00453 template<class T>
00454 mitkVolumeIterator<T>::mitkVolumeIterator(mitkVolume* vol, VectorIndexType& region)
00455 {
00456 m_Remaining = false;
00457 m_ImageDimension = 0;
00458 m_NumberOfChannels = 0;
00459 m_DefaultChannel = 0;
00460
00461 this->SetRegion(region);
00462 this->SetVolume(vol);
00463 }
00464
00465 template<class T>
00466 void mitkVolumeIterator<T>::init()
00467 {
00468 m_BeginIndex = VectorIndexType(m_ImageDimension, 0);
00469 m_EndIndex = VectorIndexType(m_ImageDimension, 0);
00470
00471 this->initRegion();
00472
00473
00474 if(m_ImageDimension == 2)
00475 {
00476 m_IncremetTable[0] = 0;
00477 m_IncremetTable[1] = m_Increments[0];
00478 m_IncremetTable[2] = m_Increments[1];
00479 m_IncremetTable[3] = m_Increments[1] + m_Increments[0];
00480 }
00481 else if(m_ImageDimension == 3)
00482 {
00483 m_IncremetTable[0] = 0;
00484 m_IncremetTable[1] = m_Increments[0];
00485 m_IncremetTable[2] = m_Increments[1];
00486 m_IncremetTable[3] = m_Increments[1] + m_Increments[0];
00487 m_IncremetTable[4] = m_Increments[2];
00488 m_IncremetTable[5] = m_Increments[2] + m_Increments[0];
00489 m_IncremetTable[6] = m_Increments[2] + m_Increments[1];
00490 m_IncremetTable[7] = m_Increments[2] + m_Increments[1] + m_Increments[0];
00491 }
00492
00493 }
00494
00495 template<class T>
00496 void mitkVolumeIterator<T>::initRegion()
00497 {
00498 unsigned int i;
00499
00500 for(i=0;i<m_ImageDimension;i++)
00501 {
00502 m_BeginIndex[i] = m_Region[2*i];
00503 m_EndIndex[i] = m_Region[2*i+1];
00504 }
00505
00506
00507 ScalarIndexType offset = this->ComputeOffset(m_BeginIndex);
00508 m_Begin = m_DataPointer + offset;
00509
00510 offset = this->ComputeOffset(m_EndIndex);
00511 m_End = m_DataPointer + offset;
00512
00513 this->GoToBegin();
00514
00515
00516 for(i=0;i<m_ImageDimension;i++)
00517 {
00518 m_OffsetTable[i] = m_Increments[i] * (m_Region[2*i+1] - m_Region[2*i] );
00519 }
00520 }
00521
00522 template<class T>
00523 void mitkVolumeIterator<T>::SetVolume(mitkVolume* vol)
00524 {
00525 if(vol == NULL) return;
00526
00527
00528 #ifdef MITK_VER_OOC
00529 if(vol->GetDataObjectType() != MITK_IC_VOLUME)
00530 {
00531
00532 return;
00533 }
00534 #endif
00535
00536
00537 m_Volume = vol;
00538
00539
00540 m_DataPointer = (T*) m_Volume->GetData();
00541
00542 m_ImageDimension = m_Volume->GetImageNum() == 1 ? 2: 3;
00543 m_NumberOfChannels = m_Volume->GetNumberOfChannel();
00544
00545
00546 m_Volume->GetDimensions(m_Dimensions);
00547
00548 for(unsigned int i = 0;i<m_ImageDimension;i++)
00549 m_Dimensions2[i] = 2 * m_Dimensions[i] - 2;
00550
00551
00552 m_Volume->GetIncrements(m_Increments);
00553
00554 if(m_Region.size() == 0)
00555 {
00556 this->GetEntireImageRegion();
00557 }
00558
00559 this->init();
00560 }
00561
00562 template<class T>
00563 void mitkVolumeIterator<T>::GoToBegin(void)
00564 {
00565 m_PositionIndex = m_BeginIndex;
00566 m_Position = m_Begin;
00567
00568 if( this->GetNumberOfPixelsInRegion() )
00569 {
00570 m_Remaining = true;
00571 }
00572 else
00573 {
00574 m_Remaining = false;
00575 }
00576 }
00577
00578 template<class T>
00579 void mitkVolumeIterator<T>::GoToEnd(void)
00580 {
00581 m_PositionIndex = m_EndIndex;
00582
00583 m_Position = m_End;
00584 m_Remaining = false;
00585 }
00586
00587 template<class T>
00588 void mitkVolumeIterator<T>::GoToNextRow(void)
00589 {
00590 m_Position -= (m_PositionIndex[0] - m_BeginIndex[0]) * m_Increments[0];
00591 m_PositionIndex[0] = m_BeginIndex[0];
00592
00593 m_Remaining = false;
00594 for( unsigned int i=1; i<m_ImageDimension; i++ )
00595 {
00596 m_PositionIndex[i]++;
00597 if( m_PositionIndex[i] <= m_EndIndex[i] )
00598 {
00599 m_Position += m_Increments[i];
00600 m_Remaining = true;
00601 break;
00602 }
00603 else
00604 {
00605 m_Position -= m_OffsetTable[i];
00606 m_PositionIndex[i] = m_BeginIndex[i];
00607 }
00608 }
00609 }
00610
00611 template<class T>
00612 void mitkVolumeIterator<T>::GoToNextCol(void)
00613 {
00614 m_Position -= (m_PositionIndex[1]- m_BeginIndex[1]) * m_Increments[1];
00615 m_PositionIndex[1] = m_BeginIndex[1];
00616
00617 m_Remaining = false;
00618 for( unsigned int i=0; i<m_ImageDimension; i++ )
00619 {
00620 if(i==1) continue;
00621
00622 m_PositionIndex[i]++;
00623 if( m_PositionIndex[i] <= m_EndIndex[i] )
00624 {
00625 m_Position += m_Increments[i];
00626 m_Remaining = true;
00627 break;
00628 }
00629 else
00630 {
00631 m_Position -= m_OffsetTable[i];
00632 m_PositionIndex[i] = m_BeginIndex[i];
00633 }
00634 }
00635 }
00636
00637 template<class T>
00638 void mitkVolumeIterator<T>::GoToNextSlice(void)
00639 {
00640 m_Position -= (m_PositionIndex[2]- m_BeginIndex[2]) * m_Increments[2];
00641 m_PositionIndex[2] = m_BeginIndex[2];
00642
00643 m_Remaining = false;
00644 for( unsigned int i=0; i<m_ImageDimension-1; i++ )
00645 {
00646 m_PositionIndex[i]++;
00647 if( m_PositionIndex[i] <= m_EndIndex[i] )
00648 {
00649 m_Position += m_Increments[i];
00650 m_Remaining = true;
00651 break;
00652 }
00653 else
00654 {
00655 m_Position -= m_OffsetTable[i];
00656 m_PositionIndex[i] = m_BeginIndex[i];
00657 }
00658 }
00659 }
00660
00661 template<class T>
00662 void mitkVolumeIterator<T>::GoToNextX(int mode)
00663 {
00664 switch(mode)
00665 {
00666 case 0:
00667 this->GoToNextRow();
00668 break;
00669 case 1:
00670 this->GoToNextCol();
00671 break;
00672 case 2:
00673 this->GoToNextSlice();
00674 break;
00675 }
00676 }
00677
00678 template<class T>
00679 void mitkVolumeIterator<T>::SetIndex(const VectorIndexType &ind)
00680 {
00681 m_Position = m_DataPointer + this->ComputeOffset( ind );
00682
00683 for(unsigned int i=0; i<m_ImageDimension; i++)
00684 m_PositionIndex[i] = ind[i];
00685 }
00686
00687 template<class T>
00688 void mitkVolumeIterator<T>::operator++()
00689 {
00690 m_Remaining = false;
00691 for( unsigned int i=0; i<m_ImageDimension; i++ )
00692 {
00693 m_PositionIndex[i]++;
00694 if( m_PositionIndex[i] <= m_EndIndex[i] )
00695 {
00696 m_Position += m_Increments[i];
00697 m_Remaining = true;
00698 break;
00699 }
00700 else
00701 {
00702 m_Position -= m_OffsetTable[i];
00703 m_PositionIndex[i] = m_BeginIndex[i];
00704 }
00705 }
00706
00707 if( !m_Remaining )
00708 {
00709 m_Position = m_End;
00710 }
00711 }
00712
00713 template<class T>
00714 void mitkVolumeIterator<T>::operator--()
00715 {
00716 m_Remaining = false;
00717 for( unsigned int i=0; i<m_ImageDimension; i++ )
00718 {
00719 if( m_PositionIndex[i] > m_BeginIndex[i] )
00720 {
00721 m_PositionIndex[i]--;
00722 m_Position -= m_Increments[i];
00723 m_Remaining = true;
00724 break;
00725 }
00726 else
00727 {
00728 m_Position += m_OffsetTable[i];
00729 m_PositionIndex[i] = m_EndIndex[i];
00730 }
00731 }
00732
00733 if( !m_Remaining )
00734 {
00735 m_Position = m_End;
00736 }
00737 }
00738
00739 template<class T>
00740 inline void mitkVolumeIterator<T>::GetNeighbors2x(const ScalarIndexType* index, ScalarPixelType* value, int ch)
00741 {
00742 ScalarIndexType offset = this->ComputeOffset(index);
00743 T* pos = m_DataPointer + offset + ch;
00744
00745 if(m_ImageDimension == 2)
00746 {
00747 value[0] = static_cast<ScalarPixelType>( *(pos) );
00748 value[1] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[1]) );
00749 value[2] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[2]) );
00750 value[3] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[3]) );
00751 }
00752 else if(m_ImageDimension == 3)
00753 {
00754 value[0] = static_cast<ScalarPixelType>( *(pos) );
00755 value[1] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[1]) );
00756 value[2] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[2]) );
00757 value[3] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[3]) );
00758 value[4] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[4]) );
00759 value[5] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[5]) );
00760 value[6] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[6]) );
00761 value[7] = static_cast<ScalarPixelType>( *(pos + m_IncremetTable[7]) );
00762 }
00763
00764 }
00765
00766 template<class T>
00767 inline void mitkVolumeIterator<T>::GetNeighbors4x(const ScalarIndexType* index, ScalarPixelType* value, int ch)
00768 {
00769 unsigned int i,j;
00770 ScalarIndexType nIndex[3][4];
00771
00772 for(i=0;i<m_ImageDimension;i++) {
00773 for (j = 0; j < 4; j++)
00774 {
00775 nIndex[i][j] = index[i] - 1 + j;
00776
00777 if(m_Dimensions[i] == 1)
00778 {
00779 nIndex[i][j] = 0;
00780 }
00781 else
00782 {
00783 if(nIndex[i][j] < 0)
00784 {
00785 nIndex[i][j] = -nIndex[i][j] - m_Dimensions2[i] * ((-nIndex[i][j]) / m_Dimensions2[i]);
00786 }
00787 else
00788 {
00789 nIndex[i][j] = nIndex[i][j] - m_Dimensions2[i] * (nIndex[i][j] / m_Dimensions2[i]);
00790 }
00791 }
00792
00793 if (m_Dimensions[i] <= nIndex[i][j])
00794 {
00795 nIndex[i][j] = m_Dimensions2[i] - nIndex[i][j];
00796 }
00797 }
00798 }
00799
00800 if(m_ImageDimension == 2)
00801 {
00802 for(j = 0; j < 4; j++) {
00803 for(i = 0; i < 4; i++) {
00804 value[i+4*j] = (ScalarPixelType) m_DataPointer[m_Increments[1] * nIndex[1][j]
00805 + m_Increments[0] * nIndex[0][i] +ch];
00806 }
00807 }
00808 }
00809 else
00810 {
00811 for(unsigned int k = 0; k < 4; k++) {
00812 for(j = 0; j < 4; j++) {
00813 for(i = 0; i < 4; i++) {
00814 value[i+4*j+16*k] = (ScalarPixelType) m_DataPointer[m_Increments[2] * nIndex[2][k]
00815 + m_Increments[1] * nIndex[1][j]
00816 + m_Increments[0] * nIndex[0][i] + ch];
00817 }
00818 }
00819 }
00820 }
00821 }
00822
00823 template<class T>
00824 inline void mitkVolumeIterator<T>::GetSequence(ScalarPixelType* values, int mode)
00825 {
00826
00827
00828
00829
00830
00831
00832
00833
00834 int i,j=0;
00835 T* pos = m_Position;
00836 switch(mode)
00837 {
00838 case 0:
00839 for(i=m_Region[0];i<=m_Region[1];i++)
00840 {
00841 values[j] = (ScalarPixelType) *(pos+m_DefaultChannel);
00842 pos += m_Increments[0];
00843 j++;
00844 }
00845 break;
00846 case 1:
00847 for(i=m_Region[2];i<=m_Region[3];i++)
00848 {
00849 values[j] = (ScalarPixelType) *(pos+m_DefaultChannel);
00850 pos += m_Increments[1];
00851 j++;
00852 }
00853 break;
00854 case 2:
00855 for(i=m_Region[4];i<=m_Region[5];i++)
00856 {
00857 values[j] = (ScalarPixelType) *(pos+m_DefaultChannel);
00858 pos += m_Increments[2];
00859 j++;
00860 }
00861 break;
00862 default:
00863
00864 break;
00865 }
00866 }
00867
00868 template<class T>
00869 inline void mitkVolumeIterator<T>::SetSequence(const ScalarPixelType* values, int mode)
00870 {
00871 int i,j=0;
00872 T* pos = m_Position;
00873 switch(mode)
00874 {
00875 case 0:
00876 for(i=m_Region[0];i<=m_Region[1];i++)
00877 {
00878 *(pos+m_DefaultChannel) = (T) values[j];
00879 pos += m_Increments[0];
00880 j++;
00881 }
00882 break;
00883 case 1:
00884 for(i=m_Region[2];i<=m_Region[3];i++)
00885 {
00886 *(pos+m_DefaultChannel) = (T) values[j];
00887 pos += m_Increments[1];
00888 j++;
00889 }
00890 break;
00891 case 2:
00892 for(i=m_Region[4];i<=m_Region[5];i++)
00893 {
00894 *(pos+m_DefaultChannel) = (T) values[j];
00895 pos += m_Increments[2];
00896 j++;
00897 }
00898 break;
00899 default:
00900
00901 break;
00902 }
00903 }
00904
00905 #ifndef MITK_VER_OOC
00906 namespace MITK_VOL_ITERATOR
00907 {
00908
00909 static bool GenerateVolumeIterator(mitkVolume* vol, mitkVolumeIteratorBase* &it, bool autorelease = false)
00910 {
00911 if( it != NULL && autorelease)
00912 {
00913 delete it;
00914 }
00915
00916 bool run_flag = true;
00917
00918 switch(vol->GetDataType())
00919 {
00920 case MITK_DOUBLE:
00921 it = new mitkVolumeIterator<double>(vol);
00922 break;
00923 case MITK_FLOAT:
00924 it = new mitkVolumeIterator<float>(vol);
00925 break;
00926 case MITK_LONG:
00927 it = new mitkVolumeIterator<long>(vol);
00928 break;
00929 case MITK_UNSIGNED_LONG:
00930 it = new mitkVolumeIterator<unsigned long>(vol);
00931 break;
00932 case MITK_INT:
00933 it = new mitkVolumeIterator<int>(vol);
00934 break;
00935 case MITK_UNSIGNED_INT:
00936 it = new mitkVolumeIterator<unsigned int>(vol);
00937 break;
00938 case MITK_SHORT:
00939 it = new mitkVolumeIterator<short>(vol);
00940 break;
00941 case MITK_UNSIGNED_SHORT:
00942 it = new mitkVolumeIterator<unsigned short>(vol);
00943 break;
00944 case MITK_CHAR:
00945 it = new mitkVolumeIterator<char>(vol);
00946 break;
00947 case MITK_UNSIGNED_CHAR:
00948 it = new mitkVolumeIterator<unsigned char>(vol);
00949 break;
00950 default:
00951 it = NULL;
00952 run_flag = false;
00953 }
00954 return run_flag;
00955 }
00956
00957 }
00958
00959 #endif //MITK_VER_OOC
00960
00961
00962
00963
00964
00965
00966
00967
00968 #endif
00969