Commit 0a9fb2bd authored by Alexis Girault's avatar Alexis Girault Committed by Kitware Robot

Merge topic 'orientation-image-isocontour'

1aa07e3e vtkFlyingEdges2D: Add support for image orientation
b5dc4423 vtkFlyingEdges3D: Add support for image orientation
691e1528 vtkMarchingSquares: Add support for image orientation
9414d605 vtkMarchingCubes: Update tests to account for orientation
4e8b769f vtkMarchingCubes: Add support for image orientation
d17c2aab vtkMarchingCubes: Add python test
c392f54f New helper class to transform out of image data
9e179c2a Add vtkMatrix4x4::IsIdentity() method
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Rejected-by: Alexis Girault's avatarAlexis Girault <alexis.girault@kitware.com>
Acked-by: Ken Martin's avatarKen Martin <ken.martin@kitware.com>
Merge-request: !5590
parents 7b3b4837 1aa07e3e
Pipeline #138491 running with stage
......@@ -91,6 +91,7 @@ set(classes
vtkHyperTreeGridOrientedGeometryCursor
vtkImageData
vtkImageIterator
vtkImageTransform
vtkImplicitBoolean
vtkImplicitDataSet
vtkImplicitFunction
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageTransform.h
Copyright (c) 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.
=========================================================================*/
/**
* @class vtkImageTransform
* @brief helper class to transform output of non-axis-aligned images
*
* vtkImageTransform is a helper class to transform the output of
* image filters (i.e., filter that input vtkImageData) by applying the
* Index to Physical transformation frmo the input image, which can
* include origin, spacing, direction. The transformation process is
* threaded with vtkSMPTools for performance.
*
* Typically in application the single method TransformPointSet() is
* invoked to transform the output of an image algorithm (assuming
* that the image's direction/orientation matrix is
* non-identity). Note that vtkPointSets encompass vtkPolyData as well
* as vtkUnstructuredGrids. In the future other output types may be
* added. Note that specific methods for transforming points, normals,
* and vectors is also provided by this class in case additional
* output data arrays need to be transformed (since
* TransformPointSet() only processes data arrays labeled as points,
* normals, and vectors).
*
* @warning
* This class has been threaded with vtkSMPTools. Using TBB or other
* non-sequential type (set in the CMake variable
* VTK_SMP_IMPLEMENTATION_TYPE) may improve performance significantly.
*
*/
#ifndef vtkImageTransform_h
#define vtkImageTransform_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkObject.h"
class vtkDataArray;
class vtkImageData;
class vtkMatrix3x3;
class vtkMatrix4x4;
class vtkPointSet;
class VTKCOMMONDATAMODEL_EXPORT vtkImageTransform : public vtkObject
{
public:
//@{
/**
* Standard methods for construction, type information, printing.
*/
static vtkImageTransform *New();
vtkTypeMacro(vtkImageTransform,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent) override;
//@}
/**
* Given a vtkImageData (and hence its associated orientation
* matrix), and an instance of vtkPointSet, transform its points, as
* well as any normals and vectors, associated with the
* vtkPointSet. This is a convenience function, internally it calls
* TranslatePoints(), TransformPoints(), TransformNormals(), and/or
* TransformVectors() as appropriate. Note that both the normals and
* vectors associated with the point and cell data are transformed.
*/
static void TransformPointSet(vtkImageData *im, vtkPointSet *ps);
/**
* Given x-y-z points represented by a vtkDataArray,
* translate the points using the image origin. This
* method is useful if there is no orientation or
* spacing to apply.
*/
static void TranslatePoints(double *t, vtkDataArray *da);
/**
* Given x-y-z points represented by a vtkDataArray,
* transform the points using the matrix provided.
*/
static void TransformPoints(vtkMatrix4x4 *m4, vtkDataArray *da);
/**
* Given three-component normals represented by a vtkDataArray,
* transform the normals using the matrix provided.
*/
static void TransformNormals(vtkMatrix3x3 *m3,
double spacing[3],
vtkDataArray *da);
/**
* Given three-component vectors represented by a vtkDataArray,
* transform the vectors using the matrix provided.
*/
static void TransformVectors(vtkMatrix3x3 *m3,
double spacing[3],
vtkDataArray *da);
protected:
vtkImageTransform();
~vtkImageTransform() {}
private:
vtkImageTransform(const vtkImageTransform&) = delete;
void operator=(const vtkImageTransform&) = delete;
};
#endif
......@@ -87,6 +87,11 @@ public:
{ vtkMatrix4x4::Identity(*this->Element); this->Modified();}
static void Identity(double elements[16]);
/**
* Returns true if this matrix is equal to the identity matrix.
*/
bool IsIdentity();
/**
* Matrix Inversion (adapted from Richard Carling in "Graphics Gems,"
* Academic Press, 1990).
......@@ -228,5 +233,16 @@ inline void vtkMatrix4x4::SetElement(int i, int j, double value)
}
}
//----------------------------------------------------------------------------
inline bool vtkMatrix4x4::IsIdentity()
{
double *M = *this->Element;
return
M[0] == 1.0 && M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 &&
M[4] == 0.0 && M[5] == 1.0 && M[6] == 0.0 && M[7] == 0.0 &&
M[8] == 0.0 && M[9] == 0.0 && M[10] == 1.0 && M[11] == 0.0 &&
M[12] == 0.0 && M[13] == 0.0 && M[14] == 0.0 && M[15] == 1.0;
}
#endif
......@@ -16,6 +16,7 @@
#include "vtkImageData.h"
#include "vtkCellArray.h"
#include "vtkImageTransform.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
......@@ -81,9 +82,7 @@ public:
// Internal variables used by the various algorithm methods. Interfaces VTK
// image data in a form more convenient to the algorithm.
vtkIdType Dims[2];
double Origin[3];
double Spacing[3];
double Z;
int K;
int Axis0;
int Min0;
int Max0;
......@@ -103,14 +102,6 @@ public:
// Instantiate and initialize key data members.
vtkFlyingEdges2DAlgorithm();
// Adjust the origin to the lower-left corner of the volume (if necessary)
void AdjustOrigin(int updateExt[6])
{
this->Origin[0] = this->Origin[0] + this->Spacing[0]*updateExt[0];
this->Origin[1] = this->Origin[1] + this->Spacing[1]*updateExt[2];
this->Origin[2] = this->Origin[2] + this->Spacing[2]*updateExt[4];
}
// The three passes of the algorithm.
void ProcessXEdge(double value, T* inPtr, vtkIdType row); //PASS 1
void ProcessYEdges(vtkIdType row); //PASS 2
......@@ -165,24 +156,24 @@ public:
}
// Interpolate along a pixel axes edge.
void InterpolateAxesEdge(double value, T *s0, float x0[3], T* s1,
float x1[3], vtkIdType vId)
void InterpolateAxesEdge(double value, T *s0, int ijk0[3], T* s1,
int ijk1[3], vtkIdType vId)
{
double t = (value - *s0) / (*s1 - *s0);
float *x = this->NewPoints + 3*vId;
x[0] = x0[0] + t*(x1[0]-x0[0]);
x[1] = x0[1] + t*(x1[1]-x0[1]);
x[2] = this->Z;
x[0] = ijk0[0] + t*(ijk1[0]-ijk0[0]) + this->Min0;
x[1] = ijk0[1] + t*(ijk1[1]-ijk0[1]) + this->Min1;
x[2] = this->K;
}
// Interpolate along an arbitrary edge, typically one that may be on the
// volume boundary. This means careful computation of stuff requiring
// neighborhood information (e.g., gradients).
void InterpolateEdge(double value, T *s, float x[3], unsigned char edgeNum,
void InterpolateEdge(double value, T *s, int ijk[3], unsigned char edgeNum,
unsigned char edgeUses[4], vtkIdType *eIds);
// Produce the output points on the pixel axes for this pixel cell.
void GeneratePoints(double value, unsigned char loc, T *sPtr, float x[3],
void GeneratePoints(double value, unsigned char loc, T *sPtr, int ijk[3],
unsigned char *edgeUses, vtkIdType *eIds);
// Helper function to set up the point ids on pixel edges.
......@@ -321,7 +312,7 @@ vtkFlyingEdges2DAlgorithm():XCases(nullptr),EdgeMetaData(nullptr),Scalars(nullpt
// Interpolate a new point along a boundary edge. Make sure to consider
// proximity to boundary when computing gradients, etc.
template <class T> void vtkFlyingEdges2DAlgorithm<T>::
InterpolateEdge(double value, T *s, float x[3],unsigned char edgeNum,
InterpolateEdge(double value, T *s, int ijk[3], unsigned char edgeNum,
unsigned char edgeUses[12], vtkIdType *eIds)
{
// if this edge is not used then get out
......@@ -338,42 +329,42 @@ InterpolateEdge(double value, T *s, float x[3],unsigned char edgeNum,
const unsigned char *offsets = this->VertOffsets[vertMap[0]];
s0 = s + offsets[0]*this->Inc0 + offsets[1]*this->Inc1;
x0[0] = x[0] + offsets[0]*this->Spacing[this->Axis0];
x0[1] = x[1] + offsets[1]*this->Spacing[this->Axis1];
x0[0] = ijk[0] + offsets[0];
x0[1] = ijk[1] + offsets[1];
offsets = this->VertOffsets[vertMap[1]];
s1 = s + offsets[0]*this->Inc0 + offsets[1]*this->Inc1;
x1[0] = x[0] + offsets[0]*this->Spacing[this->Axis0];
x1[1] = x[1] + offsets[1]*this->Spacing[this->Axis1];
x1[0] = ijk[0] + offsets[0];
x1[1] = ijk[1] + offsets[1];
// Okay interpolate
double t = (value - *s0) / (*s1 - *s0);
float *xPtr = this->NewPoints + 3*vId;
xPtr[0] = x0[0] + t*(x1[0]-x0[0]);
xPtr[1] = x0[1] + t*(x1[1]-x0[1]);
xPtr[2] = this->Z;
xPtr[0] = x0[0] + t*(x1[0]-x0[0]) + this->Min0;
xPtr[1] = x0[1] + t*(x1[1]-x0[1]) + this->Min1;
xPtr[2] = this->K;
}
//----------------------------------------------------------------------------
// Generate the output points and optionally normals, gradients and
// interpolate attributes.
template <class T> void vtkFlyingEdges2DAlgorithm<T>::
GeneratePoints(double value, unsigned char loc, T *sPtr, float x[3],
GeneratePoints(double value, unsigned char loc, T *sPtr, int ijk[3],
unsigned char *edgeUses, vtkIdType *eIds)
{
// Create a slightly faster path for pixel axes interior to the image.
float x1[3];
int ijk1[3];
if ( edgeUses[0] ) //x axes edge
{
x1[0] = x[0] + this->Spacing[this->Axis0];
x1[1] = x[1];
this->InterpolateAxesEdge(value, sPtr, x, sPtr+this->Inc0, x1, eIds[0]);
ijk1[0] = ijk[0] + 1;
ijk1[1] = ijk[1];
this->InterpolateAxesEdge(value, sPtr, ijk, sPtr+this->Inc0, ijk1, eIds[0]);
}
if ( edgeUses[2] ) //y axes edge
{
x1[0] = x[0];
x1[1] = x[1] + this->Spacing[this->Axis1];
this->InterpolateAxesEdge(value, sPtr, x, sPtr+this->Inc1, x1, eIds[2]);
ijk1[0] = ijk[0];
ijk1[1] = ijk[1] + 1;
this->InterpolateAxesEdge(value, sPtr, ijk, sPtr+this->Inc1, ijk1, eIds[2]);
}
// Otherwise do more general gyrations. These are boundary situations where
......@@ -383,16 +374,16 @@ GeneratePoints(double value, unsigned char loc, T *sPtr, float x[3],
switch (loc)
{
case 2: //+x edge
this->InterpolateEdge(value, sPtr, x, 3, edgeUses, eIds);
this->InterpolateEdge(value, sPtr, ijk, 3, edgeUses, eIds);
break;
case 8: //+y
this->InterpolateEdge(value, sPtr, x, 1, edgeUses, eIds);
this->InterpolateEdge(value, sPtr, ijk, 1, edgeUses, eIds);
break;
case 10: //+x +y
this->InterpolateEdge(value, sPtr, x, 1, edgeUses, eIds);
this->InterpolateEdge(value, sPtr, x, 3, edgeUses, eIds);
this->InterpolateEdge(value, sPtr, ijk, 1, edgeUses, eIds);
this->InterpolateEdge(value, sPtr, ijk, 3, edgeUses, eIds);
break;
default: //interior, or -x,-y boundary
......@@ -586,9 +577,9 @@ GenerateOutput(double value, T* rowPtr, vtkIdType row)
// that active pixel axes edges are interpolated to produce points and
// possibly interpolate attribute data.
T *sPtr;
float x[3];
x[1] = this->Origin[this->Axis1] + row*this->Spacing[this->Axis1];
x[2] = this->Z;
int ijk[3];
ijk[1] = row;
ijk[2] = this->K;
for (i=xL; i < xR; ++i)
{
if ( (numLines=this->GetNumberOfPrimitives(eCase)) > 0 )
......@@ -602,9 +593,9 @@ GenerateOutput(double value, T* rowPtr, vtkIdType row)
if ( this->CaseIncludesAxes(eCase) || loc != Interior )
{
sPtr = rowPtr + i*this->Inc0;
x[0] = this->Origin[this->Axis0] + i*this->Spacing[this->Axis0];
ijk[0] = i;
edgeUses = this->GetEdgeUses(eCase);
this->GeneratePoints(value, loc, sPtr, x, edgeUses, eIds);
this->GeneratePoints(value, loc, sPtr, ijk, edgeUses, eIds);
}
this->AdvancePixelIds(eCase,eIds);
......@@ -643,9 +634,6 @@ ContourImage(vtkFlyingEdges2D *self, T *scalars, vtkPoints *newPts,
// Figure out which 2D plane the image lies in. Capture information for
// subsequent processing.
vtkFlyingEdges2DAlgorithm<T> algo;
input->GetOrigin(algo.Origin);
input->GetSpacing(algo.Spacing);
algo.AdjustOrigin(updateExt);
if (updateExt[4] == updateExt[5])
{ // z collapsed
algo.Axis0 = 0;
......@@ -656,7 +644,7 @@ ContourImage(vtkFlyingEdges2D *self, T *scalars, vtkPoints *newPts,
algo.Min1 = updateExt[2];
algo.Max1 = updateExt[3];
algo.Inc1 = incs[1];
algo.Z = algo.Origin[2] + (updateExt[4]*algo.Spacing[2]);
algo.K = updateExt[4];
algo.Axis2 = 2;
}
else if (updateExt[2] == updateExt[3])
......@@ -669,7 +657,7 @@ ContourImage(vtkFlyingEdges2D *self, T *scalars, vtkPoints *newPts,
algo.Min1 = updateExt[4];
algo.Max1 = updateExt[5];
algo.Inc1 = incs[2];
algo.Z = algo.Origin[1] + (updateExt[2]*algo.Spacing[1]);
algo.K = updateExt[2];
algo.Axis2 = 1;
}
else if (updateExt[0] == updateExt[1])
......@@ -682,7 +670,7 @@ ContourImage(vtkFlyingEdges2D *self, T *scalars, vtkPoints *newPts,
algo.Min1 = updateExt[4];
algo.Max1 = updateExt[5];
algo.Inc1 = incs[2];
algo.Z = algo.Origin[0] + (updateExt[0]*algo.Spacing[0]);
algo.K = updateExt[0];
algo.Axis2 = 0;
}
else
......@@ -901,6 +889,8 @@ int vtkFlyingEdges2D::RequestData( vtkInformation *vtkNotUsed(request),
newScalars->Delete();
}
vtkImageTransform::TransformPointSet(input, output);
return 1;
}
......
This diff is collapsed.
......@@ -18,6 +18,7 @@
#include "vtkCharArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkImageTransform.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIntArray.h"
......@@ -83,7 +84,7 @@ vtkMTimeType vtkMarchingCubes::GetMTime()
// NOTE: We calculate the negative of the gradient for efficiency
template <class T>
void vtkMarchingCubesComputePointGradient(int i, int j, int k, T *s, int dims[3],
vtkIdType sliceSize, double spacing[3], double n[3])
vtkIdType sliceSize, double n[3])
{
double sp, sm;
......@@ -92,19 +93,19 @@ void vtkMarchingCubesComputePointGradient(int i, int j, int k, T *s, int dims[3]
{
sp = s[i+1 + j*dims[0] + k*sliceSize];
sm = s[i + j*dims[0] + k*sliceSize];
n[0] = (sm - sp) / spacing[0];
n[0] = sm - sp;
}
else if ( i == (dims[0]-1) )
{
sp = s[i + j*dims[0] + k*sliceSize];
sm = s[i-1 + j*dims[0] + k*sliceSize];
n[0] = (sm - sp) / spacing[0];
n[0] = sm - sp;
}
else
{
sp = s[i+1 + j*dims[0] + k*sliceSize];
sm = s[i-1 + j*dims[0] + k*sliceSize];
n[0] = 0.5 * (sm - sp) / spacing[0];
n[0] = 0.5 * (sm - sp);
}
// y-direction
......@@ -112,19 +113,19 @@ void vtkMarchingCubesComputePointGradient(int i, int j, int k, T *s, int dims[3]
{
sp = s[i + (j+1)*dims[0] + k*sliceSize];
sm = s[i + j*dims[0] + k*sliceSize];
n[1] = (sm - sp) / spacing[1];
n[1] = sm - sp;
}
else if ( j == (dims[1]-1) )
{
sp = s[i + j*dims[0] + k*sliceSize];
sm = s[i + (j-1)*dims[0] + k*sliceSize];
n[1] = (sm - sp) / spacing[1];
n[1] = sm - sp;
}
else
{
sp = s[i + (j+1)*dims[0] + k*sliceSize];
sm = s[i + (j-1)*dims[0] + k*sliceSize];
n[1] = 0.5 * (sm - sp) / spacing[1];
n[1] = 0.5 * (sm - sp);
}
// z-direction
......@@ -132,19 +133,19 @@ void vtkMarchingCubesComputePointGradient(int i, int j, int k, T *s, int dims[3]
{
sp = s[i + j*dims[0] + (k+1)*sliceSize];
sm = s[i + j*dims[0] + k*sliceSize];
n[2] = (sm - sp) / spacing[2];
n[2] = sm - sp;
}
else if ( k == (dims[2]-1) )
{
sp = s[i + j*dims[0] + k*sliceSize];
sm = s[i + j*dims[0] + (k-1)*sliceSize];
n[2] = (sm - sp) / spacing[2];
n[2] = sm - sp;
}
else
{
sp = s[i + j*dims[0] + (k+1)*sliceSize];
sm = s[i + j*dims[0] + (k-1)*sliceSize];
n[2] = 0.5 * (sm - sp) / spacing[2];
n[2] = 0.5 * (sm - sp);
}
}
......@@ -153,7 +154,6 @@ void vtkMarchingCubesComputePointGradient(int i, int j, int k, T *s, int dims[3]
//
template <class T>
void vtkMarchingCubesComputeGradient(vtkMarchingCubes *self,T *scalars, int dims[3],
double origin[3], double spacing[3],
vtkIncrementalPointLocator *locator,
vtkDataArray *newScalars,
vtkDataArray *newGradients,
......@@ -217,13 +217,13 @@ void vtkMarchingCubesComputeGradient(vtkMarchingCubes *self,T *scalars, int dims
break;
}
kOffset = k*sliceSize;
pts[0][2] = origin[2] + (k+extent[4]) * spacing[2];
zp = pts[0][2] + spacing[2];
pts[0][2] = k+extent[4];
zp = pts[0][2] + 1;
for ( j=0; j < (dims[1]-1); j++)
{
jOffset = j*dims[0];
pts[0][1] = origin[1] + (j+extent[2]) * spacing[1];
yp = pts[0][1] + spacing[1];
pts[0][1] = j+extent[2];
yp = pts[0][1] + 1;
for ( i=0; i < (dims[0]-1); i++)
{
//get scalar values
......@@ -246,8 +246,8 @@ void vtkMarchingCubesComputeGradient(vtkMarchingCubes *self,T *scalars, int dims
}
//create voxel points
pts[0][0] = origin[0] + (i+extent[0]) * spacing[0];
xp = pts[0][0] + spacing[0];
pts[0][0] = i+extent[0];
xp = pts[0][0] + 1;
pts[1][0] = xp;
pts[1][1] = pts[0][1];
......@@ -282,14 +282,14 @@ void vtkMarchingCubesComputeGradient(vtkMarchingCubes *self,T *scalars, int dims
//create gradients if needed
if (NeedGradients)
{
vtkMarchingCubesComputePointGradient(i,j,k, scalars, dims, sliceSize, spacing, gradients[0]);
vtkMarchingCubesComputePointGradient(i+1,j,k, scalars, dims, sliceSize, spacing, gradients[1]);
vtkMarchingCubesComputePointGradient(i+1,j+1,k, scalars, dims, sliceSize, spacing, gradients[2]);
vtkMarchingCubesComputePointGradient(i,j+1,k, scalars, dims, sliceSize, spacing, gradients[3]);
vtkMarchingCubesComputePointGradient(i,j,k+1, scalars, dims, sliceSize, spacing, gradients[4]);
vtkMarchingCubesComputePointGradient(i+1,j,k+1, scalars, dims, sliceSize, spacing, gradients[5]);
vtkMarchingCubesComputePointGradient(i+1,j+1,k+1, scalars, dims, sliceSize, spacing, gradients[6]);
vtkMarchingCubesComputePointGradient(i,j+1,k+1, scalars, dims, sliceSize, spacing, gradients[7]);
vtkMarchingCubesComputePointGradient(i,j,k, scalars, dims, sliceSize, gradients[0]);
vtkMarchingCubesComputePointGradient(i+1,j,k, scalars, dims, sliceSize, gradients[1]);
vtkMarchingCubesComputePointGradient(i+1,j+1,k, scalars, dims, sliceSize, gradients[2]);
vtkMarchingCubesComputePointGradient(i,j+1,k, scalars, dims, sliceSize, gradients[3]);
vtkMarchingCubesComputePointGradient(i,j,k+1, scalars, dims, sliceSize, gradients[4]);
vtkMarchingCubesComputePointGradient(i+1,j,k+1, scalars, dims, sliceSize, gradients[5]);
vtkMarchingCubesComputePointGradient(i+1,j+1,k+1, scalars, dims, sliceSize, gradients[6]);
vtkMarchingCubesComputePointGradient(i,j+1,k+1, scalars, dims, sliceSize, gradients[7]);
}
for (contNum=0; contNum < numValues; contNum++)
{
......@@ -389,7 +389,6 @@ int vtkMarchingCubes::RequestData(
vtkDataArray *inScalars;
int dims[3], extent[6];
vtkIdType estimatedSize;
double spacing[3], origin[3];
double bounds[6];
int numContours=this->ContourValues->GetNumberOfContours();
double *values=this->ContourValues->GetValues();
......@@ -418,8 +417,6 @@ int vtkMarchingCubes::RequestData(
return 1;
}
input->GetDimensions(dims);
input->GetOrigin(origin);
input->GetSpacing(spacing);
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
......@@ -436,8 +433,8 @@ int vtkMarchingCubes::RequestData(
// compute bounds for merging points
for ( int i=0; i<3; i++)
{
bounds[2*i] = origin[i] + extent[2*i] * spacing[i];
bounds[2*i+1] = origin[i] + extent[2*i+1] * spacing[i];
bounds[2*i] = extent[2*i];
bounds[2*i+1] = extent[2*i+1];
}
if ( this->Locator == nullptr )
{
......@@ -487,7 +484,7 @@ int vtkMarchingCubes::RequestData(
{
vtkTemplateMacro(
vtkMarchingCubesComputeGradient(this, static_cast<VTK_TT*>(scalars),
dims,origin,spacing,this->Locator,
dims,this->Locator,
newScalars,newGradients,
newNormals,newPolys,values,
numContours)
......@@ -504,7 +501,7 @@ int vtkMarchingCubes::RequestData(
inScalars->GetTuples(0,dataSize,image);
double *scalars = image->GetPointer(0);
vtkMarchingCubesComputeGradient(this,scalars,dims,origin,spacing,this->Locator,
vtkMarchingCubesComputeGradient(this,scalars,dims,this->Locator,
newScalars,newGradients,
newNormals,newPolys,values,numContours);
image->Delete();
......@@ -545,6 +542,8 @@ int vtkMarchingCubes::RequestData(
this->Locator->Initialize(); //free storage
}
vtkImageTransform::TransformPointSet(input, output);
return 1;
}
......
......@@ -18,6 +18,7 @@
#include "vtkCharArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkImageTransform.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIntArray.h"
......@@ -101,14 +102,14 @@ vtkMTimeType vtkMarchingSquares::GetMTime()
//
template <class T>
void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3],
int start[2], int end[2], int offset[3], double ar[3],
double origin[3], double *values, int numValues,
int start[2], int end[2], int offset[3],
double *values, int numValues,
vtkIncrementalPointLocator *p, vtkCellArray *lines)
{
int i, j;
int i, j, pts[4][3], xp, yp, *x1, *x2;
vtkIdType ptIds[2];
double t, *x1, *x2, x[3], xp, yp;
double pts[4][3], min, max;
double t, x[3];
double min, max;
int contNum, jOffset, idx, ii, jj, index, *vert;
static const int CASE_MASK[4] = {1,2,8,4};
vtkMarchingSquaresLineCases *lineCase, *lineCases;
......@@ -137,15 +138,15 @@ void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3
}
//assign coordinate value to non-varying coordinate direction
x[dir[2]] = origin[dir[2]] + roi[dir[2]*2]*ar[dir[2]];
x[dir[2]] = roi[dir[2]*2];
// Traverse all pixel cells, generating line segments using marching squares.
for ( j=roi[start[1]]; j < roi[end[1]]; j++ )
{
jOffset = j * offset[1];
pts[0][dir[1]] = origin[dir[1]] + j*ar[dir[1]];
yp = origin[dir[1]] + (j+1)*ar[dir[1]];
pts[0][dir[1]] = j;
yp = j+1;
for ( i=roi[start[0]]; i < roi[end[0]]; i++)
{
......@@ -163,8 +164,8 @@ void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3
}
//create pixel points
pts[0][dir[0]] = origin[dir[0]] + i*ar[dir[0]];
xp = origin[dir[0]] + (i+1)*ar[dir[0]];
pts[0][dir[0]] = i;
xp = i+1;
pts[1][dir[0]] = xp;
pts[1][dir[1]] = pts[0][dir[1]];
......@@ -250,7 +251,6 @@ int vtkMarchingSquares::RequestData(
vtkDataArray *newScalars = nullptr;
int i, dims[3], roi[6], dataSize, dim, plane=0;
int *ext;
double origin[3], ar[3];
int start[2], end[2], offset[3], dir[3], estimatedSize;
int numContours=this->ContourValues->GetNumberOfContours();
double *values=this->ContourValues->GetValues();
......@@ -276,8 +276,6 @@ int vtkMarchingSquares::RequestData(
//
input->GetDimensions(dims);
ext = input->GetExtent();
input->GetOrigin(origin);
input->GetSpacing(ar);
dataSize = dims[0] * dims[1] * dims[2];
if ( input->GetDataDimension() != 2 )
......@@ -391,7 +389,7 @@ int vtkMarchingSquares::RequestData(
{
vtkTemplateMacro(
vtkContourImage(static_cast<VTK_TT*>(scalars),newScalars,
roi,dir,start,end,offset,ar,origin,
roi,dir,start,end,offset,
values,numContours,this->Locator,newLines)
);
}//switch
......@@ -406,7 +404,7 @@ int vtkMarchingSquares::RequestData(
newScalars = vtkFloatArray::New();
newScalars->Allocate(5000,25000);
double *scalars = image->GetPointer(0);
vtkContourImage(scalars,newScalars,roi,dir,start,end,offset,ar,origin,
vtkContourImage(scalars,newScalars,roi,dir,start,end,offset,
values,numContours,this->Locator,newLines);
image->Delete();
}
......@@ -431,6 +429,8 @@ int vtkMarchingSquares::RequestData(
this->Locator->Initialize();
output->Squeeze();
vtkImageTransform::TransformPointSet(input, output);
return 1;
}
......