#include "vtkPointData.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkImageActor.h"
#include "vtkActor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"
#include "vtkGlyph3DMapper.h"
#include "vtkArrowSource.h"
static void
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << "inputImageFile" << std::endl;
return EXIT_FAILURE;
}
std::string inputFileName = argv[1];
const auto input = itk::ReadImage<UnsignedCharImageType>(inputFileName);
gradientFilter->SetInput(input);
gradientFilter->Update();
originalConnector->SetInput(input);
originalActor->SetInput(originalConnector->GetOutput());
VectorImageToVTKImage(gradientFilter->GetOutput(), gradientImage);
gradientMapper->ScalingOn();
gradientMapper->SetScaleFactor(.05);
gradientMapper->SetSourceConnection(arrowSource->GetOutputPort());
gradientMapper->SetInputConnection(gradientImage->GetProducerPort());
gradientMapper->Update();
gradientActor->SetMapper(gradientMapper);
double leftViewport[4] = { 0.0, 0.0, 0.5, 1.0 };
double rightViewport[4] = { 0.5, 0.0, 1.0, 1.0 };
renderWindow->SetSize(600, 300);
renderWindow->AddRenderer(leftRenderer);
leftRenderer->SetViewport(leftViewport);
renderWindow->AddRenderer(rightRenderer);
rightRenderer->SetViewport(rightViewport);
rightRenderer->SetBackground(1, 0, 0);
leftRenderer->AddActor(originalActor);
rightRenderer->AddActor(gradientActor);
renderWindowInteractor->SetInteractorStyle(style);
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
void
{
VTKImage->SetExtent(0, imageSize[0] - 1, 0, imageSize[1] - 1, 0, 0);
vectors->SetNumberOfComponents(3);
vectors->SetNumberOfTuples(imageSize[0] * imageSize[1]);
vectors->SetName("GradientVectors");
int counter = 0;
for (unsigned int j = 0; j < imageSize[1]; ++j)
{
for (unsigned int i = 0; i < imageSize[0]; ++i)
{
index[0] = i;
index[1] = j;
float v[2];
v[0] = pixel[0];
v[1] = pixel[1];
v[2] = 0;
vectors->InsertTupleValue(counter, v);
counter++;
}
}
VTKImage->GetPointData()->SetVectors(vectors);
}