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