Commit 691e1528 authored by Alexis Girault's avatar Alexis Girault

vtkMarchingSquares: Add support for image orientation

parent 9414d605
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "vtkCharArray.h" #include "vtkCharArray.h"
#include "vtkDoubleArray.h" #include "vtkDoubleArray.h"
#include "vtkFloatArray.h" #include "vtkFloatArray.h"
#include "vtkImageTransform.h"
#include "vtkInformation.h" #include "vtkInformation.h"
#include "vtkInformationVector.h" #include "vtkInformationVector.h"
#include "vtkIntArray.h" #include "vtkIntArray.h"
...@@ -101,14 +102,14 @@ vtkMTimeType vtkMarchingSquares::GetMTime() ...@@ -101,14 +102,14 @@ vtkMTimeType vtkMarchingSquares::GetMTime()
// //
template <class T> template <class T>
void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3], void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3],
int start[2], int end[2], int offset[3], double ar[3], int start[2], int end[2], int offset[3],
double origin[3], double *values, int numValues, double *values, int numValues,
vtkIncrementalPointLocator *p, vtkCellArray *lines) vtkIncrementalPointLocator *p, vtkCellArray *lines)
{ {
int i, j; int i, j, pts[4][3], xp, yp, *x1, *x2;
vtkIdType ptIds[2]; vtkIdType ptIds[2];
double t, *x1, *x2, x[3], xp, yp; double t, x[3];
double pts[4][3], min, max; double min, max;
int contNum, jOffset, idx, ii, jj, index, *vert; int contNum, jOffset, idx, ii, jj, index, *vert;
static const int CASE_MASK[4] = {1,2,8,4}; static const int CASE_MASK[4] = {1,2,8,4};
vtkMarchingSquaresLineCases *lineCase, *lineCases; vtkMarchingSquaresLineCases *lineCase, *lineCases;
...@@ -137,15 +138,15 @@ void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3 ...@@ -137,15 +138,15 @@ void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3
} }
//assign coordinate value to non-varying coordinate direction //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. // Traverse all pixel cells, generating line segments using marching squares.
for ( j=roi[start[1]]; j < roi[end[1]]; j++ ) for ( j=roi[start[1]]; j < roi[end[1]]; j++ )
{ {
jOffset = j * offset[1]; jOffset = j * offset[1];
pts[0][dir[1]] = origin[dir[1]] + j*ar[dir[1]]; pts[0][dir[1]] = j;
yp = origin[dir[1]] + (j+1)*ar[dir[1]]; yp = j+1;
for ( i=roi[start[0]]; i < roi[end[0]]; i++) 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 ...@@ -163,8 +164,8 @@ void vtkContourImage(T *scalars, vtkDataArray *newScalars, int roi[6], int dir[3
} }
//create pixel points //create pixel points
pts[0][dir[0]] = origin[dir[0]] + i*ar[dir[0]]; pts[0][dir[0]] = i;
xp = origin[dir[0]] + (i+1)*ar[dir[0]]; xp = i+1;
pts[1][dir[0]] = xp; pts[1][dir[0]] = xp;
pts[1][dir[1]] = pts[0][dir[1]]; pts[1][dir[1]] = pts[0][dir[1]];
...@@ -250,7 +251,6 @@ int vtkMarchingSquares::RequestData( ...@@ -250,7 +251,6 @@ int vtkMarchingSquares::RequestData(
vtkDataArray *newScalars = nullptr; vtkDataArray *newScalars = nullptr;
int i, dims[3], roi[6], dataSize, dim, plane=0; int i, dims[3], roi[6], dataSize, dim, plane=0;
int *ext; int *ext;
double origin[3], ar[3];
int start[2], end[2], offset[3], dir[3], estimatedSize; int start[2], end[2], offset[3], dir[3], estimatedSize;
int numContours=this->ContourValues->GetNumberOfContours(); int numContours=this->ContourValues->GetNumberOfContours();
double *values=this->ContourValues->GetValues(); double *values=this->ContourValues->GetValues();
...@@ -276,8 +276,6 @@ int vtkMarchingSquares::RequestData( ...@@ -276,8 +276,6 @@ int vtkMarchingSquares::RequestData(
// //
input->GetDimensions(dims); input->GetDimensions(dims);
ext = input->GetExtent(); ext = input->GetExtent();
input->GetOrigin(origin);
input->GetSpacing(ar);
dataSize = dims[0] * dims[1] * dims[2]; dataSize = dims[0] * dims[1] * dims[2];
if ( input->GetDataDimension() != 2 ) if ( input->GetDataDimension() != 2 )
...@@ -391,7 +389,7 @@ int vtkMarchingSquares::RequestData( ...@@ -391,7 +389,7 @@ int vtkMarchingSquares::RequestData(
{ {
vtkTemplateMacro( vtkTemplateMacro(
vtkContourImage(static_cast<VTK_TT*>(scalars),newScalars, vtkContourImage(static_cast<VTK_TT*>(scalars),newScalars,
roi,dir,start,end,offset,ar,origin, roi,dir,start,end,offset,
values,numContours,this->Locator,newLines) values,numContours,this->Locator,newLines)
); );
}//switch }//switch
...@@ -406,7 +404,7 @@ int vtkMarchingSquares::RequestData( ...@@ -406,7 +404,7 @@ int vtkMarchingSquares::RequestData(
newScalars = vtkFloatArray::New(); newScalars = vtkFloatArray::New();
newScalars->Allocate(5000,25000); newScalars->Allocate(5000,25000);
double *scalars = image->GetPointer(0); 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); values,numContours,this->Locator,newLines);
image->Delete(); image->Delete();
} }
...@@ -431,6 +429,8 @@ int vtkMarchingSquares::RequestData( ...@@ -431,6 +429,8 @@ int vtkMarchingSquares::RequestData(
this->Locator->Initialize(); this->Locator->Initialize();
output->Squeeze(); output->Squeeze();
vtkImageTransform::TransformPointSet(input, output);
return 1; return 1;
} }
......
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