--- /dev/null
+#include <vtkSmartPointer.h>
+#include <vtkProperty.h>
+#include <vtkContourWidget.h>
+#include <vtkOrientedGlyphContourRepresentation.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCommand.h>
+#include <vtkDebugLeaks.h>
+#include <vtkCamera.h>
+#include <vtkPlane.h>
+#include <vtkPolyData.h>
+#include <vtkCellArray.h>
+#include <vtkPoints.h>
+#include <vtkMath.h>
+#include <vtkWidgetEvent.h>
+#include <vtkWidgetEventTranslator.h>
+#include <vtkInteractorStyleTrackballCamera.h>
+#include <vtkInteractorStyleImage.h>
+
+#include <vtkPNGReader.h>
+#include <vtkImageViewer2.h>
+#include <vtkObjectFactory.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkPolyData.h>
+#include <vtkActor.h>
+
+
+vtkSmartPointer<vtkContourWidget> contourWidget;
+vtkSmartPointer<vtkPolyData> pd;
+vtkSmartPointer<vtkRenderWindowInteractor> interactor;
+vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep;
+
+class KeyPressInteractorStyle : public vtkInteractorStyleImage//vtkInteractorStyleTrackballCamera
+{
+public:
+ static KeyPressInteractorStyle* New();
+ vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);
+
+
+
+ virtual void OnKeyPress()
+ {
+ // Get the keypress
+ vtkRenderWindowInteractor *rwi = this->Interactor;
+ std::string key = rwi->GetKeySym();
+
+ // Output the key that was pressed
+ std::cout << "Pressed " << key << std::endl;
+
+ // Handle an arrow key
+ if (key == "Up")
+ {
+ contourWidget =
+ vtkSmartPointer<vtkContourWidget>::New();
+ contourWidget->SetInteractor(interactor);
+ contourWidget->SetRepresentation(contourRep);
+ contourWidget->On();
+
+ std::cout << "add and move points" << std::endl;
+ contourWidget->GetEventTranslator()->RemoveTranslation(
+ vtkCommand::LeftButtonPressEvent);
+ contourWidget->GetEventTranslator()->SetTranslation(
+ vtkCommand::LeftButtonPressEvent,
+ vtkWidgetEvent::Translate);
+
+ //contourWidget->Initialize(pd);
+ //contourWidget->Render();
+
+ //interactor->Initialize();
+ //interactor->Start();
+ //Interactor->Disable();
+ }
+
+ // Handle a "normal" key
+ if (key == "Down")
+ {
+ std::cout << "Remove points" << std::endl;
+ contourWidget->GetEventTranslator()->RemoveTranslation(
+ vtkCommand::LeftButtonPressEvent);
+ contourWidget->GetEventTranslator()->SetTranslation(
+ vtkCommand::LeftButtonPressEvent,
+ vtkWidgetEvent::Delete);
+
+ }
+
+ // Forward events
+ vtkInteractorStyleTrackballCamera::OnKeyPress();
+ }
+
+};
+vtkStandardNewMacro(KeyPressInteractorStyle);
+
+int main( int argc, char *argv[] )
+{
+ // Create the RenderWindow, Renderer and both Actors
+ //
+ vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
+ vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
+ renderWindow->AddRenderer(renderer);
+
+ interactor =
+ vtkSmartPointer<vtkRenderWindowInteractor>::New();
+ interactor->SetRenderWindow(renderWindow);
+
+ vtkSmartPointer<KeyPressInteractorStyle> style =
+ vtkSmartPointer<KeyPressInteractorStyle>::New();
+ interactor->SetInteractorStyle(style);
+ style->EndRotate();
+ style->SetCurrentRenderer(renderer);
+
+ renderer->SetBackground(0.1, 0.2, 0.4);
+ renderWindow->SetSize(600, 600);
+
+ // image 2d reader
+ vtkSmartPointer<vtkPNGReader> reader =
+ vtkSmartPointer<vtkPNGReader>::New();
+ reader->SetFileName("C:\\Users\\JoseLuis\\Downloads\\pulmon.png");
+
+ // Visualize
+ vtkSmartPointer<vtkImageViewer2> imageViewer =
+ vtkSmartPointer<vtkImageViewer2>::New();
+ imageViewer->SetInputConnection(reader->GetOutputPort());
+ vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
+ vtkSmartPointer<vtkRenderWindowInteractor>::New();
+ imageViewer->SetupInteractor(renderWindowInteractor);
+
+
+ renderWindowInteractor->Start();
+
+ // contour representation
+ contourRep =
+ vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
+ contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red
+
+ contourWidget =
+ vtkSmartPointer<vtkContourWidget>::New();
+ contourWidget->SetInteractor(interactor);
+ contourWidget->SetRepresentation(contourRep);
+ contourWidget->On();
+
+ pd = vtkSmartPointer<vtkPolyData>::New();
+
+ vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
+ vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
+ vtkIdType* lineIndices = new vtkIdType[21];
+ for (int i = 0; i< 20; i++)
+ {
+ const double angle = 2.0*vtkMath::Pi()*i/20.0;
+ points->InsertPoint(static_cast<vtkIdType>(i), 0.1*cos(angle),
+ 0.1*sin(angle), 0.0 );
+ lineIndices[i] = static_cast<vtkIdType>(i);
+ }
+
+ lineIndices[20] = 0;
+ lines->InsertNextCell(21,lineIndices);
+ delete [] lineIndices;
+ pd->SetPoints(points);
+ pd->SetLines(lines);
+
+ imageViewer->Render();
+ imageViewer->GetRenderer()->ResetCamera();
+
+ vtkSmartPointer<vtkPolyData> poly = contourRep->GetContourRepresentationAsPolyData();
+
+ vtkSmartPointer<vtkPolyDataMapper> map = vtkSmartPointer<vtkPolyDataMapper>::New();
+ map->SetInputData(poly);
+
+ vtkSmartPointer<vtkActor> act = vtkSmartPointer<vtkActor>::New();
+ act->SetMapper(map);
+
+
+ imageViewer->GetRenderer()->AddActor(act);
+ //imageViewer->Render();
+
+ contourWidget->Initialize(pd);
+ contourWidget->Render();
+ renderer->ResetCamera();
+ renderWindow->Render();
+
+
+
+ interactor->Initialize();
+ interactor->Start();
+
+ //contourWidget->Off();
+
+ return EXIT_SUCCESS;
+}