-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.cxx
84 lines (66 loc) · 2.44 KB
/
widget.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <vtkSmartPointer.h>
#include <vtkSeedWidget.h>
#include <vtkSeedRepresentation.h>
#include <vtkPointHandleRepresentation2D.h>
#include <vtkProperty2D.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageViewer2.h>
#include <vtkJPEGReader.h>
#include <vtkImageActor.h>
#include <vtkImageActorPointPlacer.h>
int main( int argc, char *argv[] )
{
if( argc != 3 )
{
std::cerr << "Usage:" << std::endl;
std::cerr << argv[0] << " <Image (*.jpg)> <output filename (*.txt)>" << std::endl;
return EXIT_FAILURE;
}
vtkSmartPointer<vtkJPEGReader> jpegReader = vtkSmartPointer<vtkJPEGReader>::New();
jpegReader->SetFileName( argv[1] );
jpegReader->Update();
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection( jpegReader->GetOutputPort() );
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
vtkSmartPointer<vtkRenderer> renderer = imageViewer->GetRenderer();
double imageBounds[6];
imageViewer->GetImageActor()->GetBounds(imageBounds);
vtkSmartPointer<vtkImageActorPointPlacer> placer = vtkSmartPointer<vtkImageActorPointPlacer>::New();
placer->SetImageActor( imageViewer->GetImageActor() );
vtkSmartPointer<vtkPointHandleRepresentation2D> handle =
vtkSmartPointer<vtkPointHandleRepresentation2D>::New();
handle->GetProperty()->SetColor(1,0,0);
handle->SetPointPlacer( placer );
vtkSmartPointer<vtkSeedRepresentation> seedRep =
vtkSmartPointer<vtkSeedRepresentation>::New();
seedRep->SetHandleRepresentation(handle);
vtkSmartPointer<vtkSeedWidget> seedWidget =
vtkSmartPointer<vtkSeedWidget>::New();
seedWidget->SetInteractor(renderWindowInteractor);
seedWidget->SetRepresentation(seedRep);
seedWidget->On();
seedWidget->Render();
renderer->ResetCamera();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
seedWidget->Off();
int N = seedRep->GetNumberOfSeeds();
std::ofstream ofs;
ofs.open( argv[2] );
if( !ofs.is_open() )
{
std::cerr << "can't open " << argv[2] << std::endl;
return EXIT_FAILURE;
}
for( int i = 0; i < N; i++ )
{
double pos[3];
seedRep->GetSeedWorldPosition( i, pos );
ofs << pos[0] << " " << imageBounds[3] - pos[1] << std::endl;
}
ofs.close();
return EXIT_SUCCESS;
}