Commit 3ec93186 authored by Andy Cedilnik's avatar Andy Cedilnik
Browse files

Improve image iterator and add a simple test for it

parent 913c7961
......@@ -62,6 +62,8 @@ vtkIdentityTransform
vtkIdList
vtkIdTypeArray
vtkImageData
vtkImageIterator
vtkImageProgressIterator
vtkImplicitFunctionCollection
vtkIndent
vtkInstantiator
......@@ -174,6 +176,8 @@ WRAP_EXCLUDE_FILES(
vtkCallbackCommand
vtkOldStyleCallbackCommand
vtkErrorCode
vtkImageIterator
vtkImageProgressIterator
)
IF(VTK_MAKE_INSTANTIATOR)
......
......@@ -19,6 +19,7 @@ ADD_EXECUTABLE(otherByteSwap otherByteSwap)
ADD_EXECUTABLE(otherCellArray otherCellArray)
ADD_EXECUTABLE(otherCellTypes otherCellTypes)
ADD_EXECUTABLE(otherFieldData otherFieldData)
ADD_EXECUTABLE(TestImageIterator TestImageIterator)
ADD_TEST(ObjectFactory ${CXX_TEST_PATH}/ObjectFactory)
ADD_TEST(otherArrays ${CXX_TEST_PATH}/otherArrays)
......@@ -34,3 +35,4 @@ ADD_TEST(otherByteSwap ${CXX_TEST_PATH}/otherByteSwap)
ADD_TEST(otherCellArray ${CXX_TEST_PATH}/otherCellArray)
ADD_TEST(otherCellTypes ${CXX_TEST_PATH}/otherCellTypes)
ADD_TEST(otherFieldData ${CXX_TEST_PATH}/otherFieldData)
ADD_TEST(TestImageIterator ${CXX_TEST_PATH}/TestImageIterator)
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageIterator.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of image iterators
// .SECTION Description
// this program tests the image iterators
// At this point it only creates an object of every supported type.
#include "vtkDebugLeaks.h"
#include "vtkImageIterator.h"
#include "vtkImageProgressIterator.h"
#include "vtkImageData.h"
template<typename T>
int DoTest(T* = 0)
{
int ext[6] = { 0, 0, 0, 0, 0, 0 };
vtkImageData *id = vtkImageData::New();
vtkImageIterator<T> *it = new vtkImageIterator<T>(id,ext);
vtkImageProgressIterator<T> *ipt
= new vtkImageProgressIterator<T>(id,ext,0,0);
delete it;
delete ipt;
return 0;
id->Delete();
}
int main()
{
vtkDebugLeaks::PromptUserOff();
DoTest<char>();
DoTest<int>();
DoTest<long>();
DoTest<short>();
DoTest<float>();
DoTest<double>();
DoTest<unsigned long>();
DoTest<unsigned short>();
DoTest<unsigned char>();
DoTest<unsigned int>();
return 0;
}
......@@ -17,43 +17,7 @@
=========================================================================*/
#ifndef CMAKE_NO_EXPLICIT_TEMPLATE_INSTATIATION
#include "vtkImageIterator.h"
#include "vtkImageData.h"
#endif
template <typename DType>
vtkImageIterator<DType>::vtkImageIterator(vtkImageData *id, int *ext)
{
this->Pointer = (DType *)id->GetScalarPointerForExtent(ext);
id->GetIncrements(this->Increments[0], this->Increments[1],
this->Increments[2]);
id->GetContinuousIncrements(ext,this->ContinuousIncrements[0],
this->ContinuousIncrements[1],
this->ContinuousIncrements[2]);
this->EndPointer =
(DType *)id->GetScalarPointer(ext[1],ext[3],ext[5]) +this->Increments[0];
this->SpanEndPointer =
this->Pointer + this->Increments[0]*(ext[1] - ext[0] + 1);
this->SliceEndPointer =
this->Pointer + this->Increments[1]*(ext[3] - ext[2] + 1);
}
template <typename DType>
void vtkImageIterator<DType>::NextSpan()
{
this->Pointer = this->Pointer + this->Increments[1];
this->SpanEndPointer += this->Increments[1];
if (this->Pointer >= this->SliceEndPointer)
{
this->Pointer = this->Pointer + this->ContinuousIncrements[2];
this->SliceEndPointer += this->Increments[2];
}
}
#ifndef CMAKE_NO_EXPLICIT_TEMPLATE_INSTANTIATION
#include "vtkImageIterator.txx"
template class VTK_COMMON_EXPORT vtkImageIterator<char>;
template class VTK_COMMON_EXPORT vtkImageIterator<int>;
......
......@@ -72,9 +72,8 @@ protected:
int ContinuousIncrements[3];
};
#ifdef CMAKE_NO_EXPLICIT_TEMPLATE_INSTANTIATION
// include the code
#include "vtkImageIterator.cxx"
#endif
#ifdef CMAKE_NO_EXPLICIT_TEMPLATE_INSTATIATION
#include "vtkImageIterator.txx"
#endif
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageIterator.txx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef CMAKE_NO_EXPLICIT_TEMPLATE_INSTATIATION
#include "vtkImageIterator.h"
#endif
#include "vtkImageData.h"
template <typename DType>
vtkImageIterator<DType>::vtkImageIterator(vtkImageData *id, int *ext)
{
this->Pointer = (DType *)id->GetScalarPointerForExtent(ext);
id->GetIncrements(this->Increments[0], this->Increments[1],
this->Increments[2]);
id->GetContinuousIncrements(ext,this->ContinuousIncrements[0],
this->ContinuousIncrements[1],
this->ContinuousIncrements[2]);
this->EndPointer =
(DType *)id->GetScalarPointer(ext[1],ext[3],ext[5]) +this->Increments[0];
this->SpanEndPointer =
this->Pointer + this->Increments[0]*(ext[1] - ext[0] + 1);
this->SliceEndPointer =
this->Pointer + this->Increments[1]*(ext[3] - ext[2] + 1);
}
template <typename DType>
void vtkImageIterator<DType>::NextSpan()
{
this->Pointer = this->Pointer + this->Increments[1];
this->SpanEndPointer += this->Increments[1];
if (this->Pointer >= this->SliceEndPointer)
{
this->Pointer = this->Pointer + this->ContinuousIncrements[2];
this->SliceEndPointer += this->Increments[2];
}
}
......@@ -16,52 +16,8 @@
=========================================================================*/
#ifndef CMAKE_NO_EXPLICIT_TEMPLATE_INSTATIATION
#include "vtkImageProgressIterator.h"
#include "vtkImageData.h"
#include "vtkProcessObject.h"
#endif
template <typename DType>
vtkImageProgressIterator<DType>::vtkImageProgressIterator(vtkImageData *imgd,
int *ext,
vtkProcessObject *po,
int id) :
vtkImageIterator<DType>(imgd,ext)
{
this->Target =
(unsigned long)((ext[5] - ext[4]+1)*(ext[3] - ext[2]+1)/50.0);
this->Target++;
this->Count = 0;
this->Count2 = 0;
this->ProcessObject = po;
this->ID = id;
}
template <typename DType>
void vtkImageProgressIterator<DType>::NextSpan()
{
this->Pointer = this->Pointer + this->Increments[1];
this->SpanEndPointer += this->Increments[1];
if (this->Pointer >= this->SliceEndPointer)
{
this->Pointer = this->Pointer + this->ContinuousIncrements[2];
this->SliceEndPointer += this->Increments[2];
}
if (this->ID)
{
if (this->Count2 == this->Target)
{
this->Count += this->Count2;
this->ProcessObject->UpdateProgress(this->Count/(50.0*this->Target));
this->Count2 = 0;
}
this->Count2++;
}
}
#ifndef CMAKE_NO_EXPLICIT_TEMPLATE_INSTANTIATION
#include "vtkImageProgressIterator.txx"
template class VTK_COMMON_EXPORT vtkImageProgressIterator<char>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<int>;
......
......@@ -56,7 +56,7 @@ protected:
#ifdef CMAKE_NO_EXPLICIT_TEMPLATE_INSTANTIATION
// include the code
#include "vtkImageProgressIterator.cxx"
#include "vtkImageProgressIterator.txx"
#endif
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageProgressIterator.txx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef CMAKE_NO_EXPLICIT_TEMPLATE_INSTATIATION
#include "vtkImageProgressIterator.h"
#include "vtkImageData.h"
#include "vtkProcessObject.h"
#endif
template <typename DType>
vtkImageProgressIterator<DType>::vtkImageProgressIterator(vtkImageData *imgd,
int *ext,
vtkProcessObject *po,
int id) :
vtkImageIterator<DType>(imgd,ext)
{
this->Target =
(unsigned long)((ext[5] - ext[4]+1)*(ext[3] - ext[2]+1)/50.0);
this->Target++;
this->Count = 0;
this->Count2 = 0;
this->ProcessObject = po;
this->ID = id;
}
template <typename DType>
void vtkImageProgressIterator<DType>::NextSpan()
{
this->Pointer = this->Pointer + this->Increments[1];
this->SpanEndPointer += this->Increments[1];
if (this->Pointer >= this->SliceEndPointer)
{
this->Pointer = this->Pointer + this->ContinuousIncrements[2];
this->SliceEndPointer += this->Increments[2];
}
if (this->ID)
{
if (this->Count2 == this->Target)
{
this->Count += this->Count2;
this->ProcessObject->UpdateProgress(this->Count/(50.0*this->Target));
this->Count2 = 0;
}
this->Count2++;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment