Commit 81bd64e0 authored by Ken Martin's avatar Ken Martin
Browse files

updates

parent e6a8ee88
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageIterator.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
of any contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
* Modified source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#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];
// handle y z volumes quickly as well
if (id->GetExtent()[1] == id->GetExtent()[0])
{
this->SpanEndPointer = this->Pointer +
this->Increments[1]*(ext[3] - ext[2] + 1);
this->SliceEndPointer = this->EndPointer;
this->ContinuousIncrements[0] = this->ContinuousIncrements[1];
this->ContinuousIncrements[1] = this->ContinuousIncrements[2];
this->Increments[0] = this->Increments[1];
this->Increments[1] = this->Increments[2];
}
else // normal volumes
{
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
template class VTK_COMMON_EXPORT vtkImageIterator<char>;
template class VTK_COMMON_EXPORT vtkImageIterator<int>;
template class VTK_COMMON_EXPORT vtkImageIterator<long>;
template class VTK_COMMON_EXPORT vtkImageIterator<short>;
template class VTK_COMMON_EXPORT vtkImageIterator<float>;
template class VTK_COMMON_EXPORT vtkImageIterator<double>;
template class VTK_COMMON_EXPORT vtkImageIterator<unsigned long>;
template class VTK_COMMON_EXPORT vtkImageIterator<unsigned short>;
template class VTK_COMMON_EXPORT vtkImageIterator<unsigned char>;
template class VTK_COMMON_EXPORT vtkImageIterator<unsigned int>;
#endif
......@@ -58,64 +58,47 @@ template<typename DType> class VTK_COMMON_EXPORT vtkImageIterator
public:
typedef DType *SpanIterator;
vtkImageIterator(vtkImageData *id, int *ext)
{
m_Ptr = (DType *)id->GetScalarPointerForExtent(ext);
id->GetIncrements(m_Inc[0], m_Inc[1], m_Inc[2]);
id->GetContinuousIncrements(ext,m_CInc[0], m_CInc[1], m_CInc[2]);
m_EndPtr =
(DType *)id->GetScalarPointer(ext[1], ext[3], ext[5]) + m_Inc[0];
// handle y z volumes quickly as well
if (id->GetExtent()[1] == id->GetExtent()[0])
{
m_SpanEndPtr = m_Ptr + m_Inc[1]*(ext[3] - ext[2] + 1);
m_SliceEndPtr = m_EndPtr;
m_CInc[0] = m_CInc[1];
m_CInc[1] = m_CInc[2];
m_Inc[0] = m_Inc[1];
m_Inc[1] = m_Inc[2];
}
else // normal volumes
{
m_SpanEndPtr = m_Ptr + m_Inc[0]*(ext[1] - ext[0] + 1);
m_SliceEndPtr = m_Ptr + m_Inc[1]*(ext[3] - ext[2] + 1);
}
}
// Description:
// Create an image iterator fora given image data and a given extent
vtkImageIterator(vtkImageData *id, int *ext);
// Description:
// Move the iterator to the next span
void NextSpan();
void NextSpan()
{
m_Ptr = m_Ptr + m_Inc[1];
m_SpanEndPtr += m_Inc[1];
if (m_Ptr >= m_SliceEndPtr)
{
m_Ptr = m_Ptr + m_CInc[2];
m_SliceEndPtr += m_Inc[2];
}
}
// Description:
// Return an iterator (pointer) for the span
SpanIterator BeginSpan()
{
return m_Ptr;
return this->Pointer;
}
// Description:
// Return an iterator (pointer) for the end of the span
SpanIterator EndSpan()
{
return m_SpanEndPtr;
return this->SpanEndPointer;
}
// Description:
// tets if the end of the extent has been reached
bool IsAtEnd()
{
return (m_Ptr >= m_EndPtr);
return (this->Pointer >= this->EndPointer);
}
protected:
DType *m_Ptr;
DType *m_SpanEndPtr;
DType *m_SliceEndPtr;
DType *m_EndPtr;
int m_Inc[3];
int m_CInc[3];
DType *Pointer;
DType *SpanEndPointer;
DType *SliceEndPointer;
DType *EndPointer;
int Increments[3];
int ContinuousIncrements[3];
};
#ifdef CMAKE_NO_EXPLICIT_TEMPLATE_INSTANTIATION
// include the code
#include "vtkImageIterator.cxx"
#endif
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageProgressIterator.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
of any contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
* Modified source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#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
template class VTK_COMMON_EXPORT vtkImageProgressIterator<char>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<int>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<long>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<short>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<float>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<double>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<unsigned long>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<unsigned short>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<unsigned char>;
template class VTK_COMMON_EXPORT vtkImageProgressIterator<unsigned int>;
#endif
......@@ -51,52 +51,36 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define __vtkImageProgressIterator_h
#include "vtkImageIterator.h"
#include "vtkProcessObject.h"
class vtkProcessObject;
template<typename DType> class VTK_COMMON_EXPORT vtkImageProgressIterator :
public vtkImageIterator<DType>
{
public:
// Description:
// Create a progress iterator for the provided image data
// and extent to iterate over. The passes progress object will
// receive any UpdateProgress calls if the thread id is zero
vtkImageProgressIterator(vtkImageData *imgd, int *ext,
vtkProcessObject *po,
int id): vtkImageIterator<DType>(imgd,ext)
{
m_Target =
(unsigned long)((ext[5] - ext[4]+1)*(ext[3] - ext[2]+1)/50.0);
m_Target++;
m_Count = 0;
m_Count2 = 0;
m_ProcessObject = po;
m_Id = id;
}
void NextSpan()
{
m_Ptr = m_Ptr + m_Inc[1];
m_SpanEndPtr += m_Inc[1];
if (m_Ptr >= m_SliceEndPtr)
{
m_Ptr = m_Ptr + m_CInc[2];
m_SliceEndPtr += m_Inc[2];
}
if (m_Id)
{
if (m_Count2 == m_Target)
{
m_Count += m_Count2;
m_ProcessObject->UpdateProgress(m_Count/(50.0*m_Target));
m_Count2 = 0;
}
m_Count2++;
}
}
vtkProcessObject *po, int id);
// Description:
// Move the iterator to the next span, may call UpdateProgress on the
// filter (vtkProcessObject)
void NextSpan();
protected:
vtkProcessObject *m_ProcessObject;
unsigned long m_Count;
unsigned long m_Count2;
unsigned long m_Target;
int m_Id;
vtkProcessObject *ProcessObject;
unsigned long Count;
unsigned long Count2;
unsigned long Target;
int ID;
};
#ifdef CMAKE_NO_EXPLICIT_TEMPLATE_INSTANTIATION
// include the code
#include "vtkImageProgressIterator.cxx"
#endif
#endif
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