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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: OneViewAndTrackingUsingMicronTracker.cxx,v $
Language: C++
Date: $Date: 2009-06-12 15:23:31 $
Version: $Revision: 1.1 $
Copyright (c) ISC Insight Software Consortium. All rights reserved.
See IGSTKCopyright.txt or http://www.igstk.org/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 notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
// Warning about: identifier was truncated to '255' characters
// in the debug information (MVC6.0 Debug)
#pragma warning( disable : 4284 )
#endif
#include "OneViewAndTrackingUsingMicronTrackerImplementation.h"
#include "igstkView3D.h"
#include "igstkEllipsoidObject.h"
#include "igstkCylinderObject.h"
#include "igstkEllipsoidObjectRepresentation.h"
#include "igstkCylinderObjectRepresentation.h"
int main(int argc, char** argv )
{
igstk::RealTimeClock::Initialize();
if( argc < 4 )
{
std::cerr << " Usage: " << argv[0] << "\t"
<< "MicronTracker_Camera_Calibration_file" << "\t"
<< "MicronTracker_initialization_file" << "\t"
<< "Marker_template_directory " << std::endl;
return EXIT_FAILURE;
}
OneViewAndTrackingUsingMicronTrackerImplementation application;
// Create the ellipsoid
igstk::EllipsoidObject::Pointer ellipsoid = igstk::EllipsoidObject::New();
ellipsoid->SetRadius(200,200,300); // about a human skull
double validityTimeInMilliseconds = 1e20; // in seconds
igstk::Transform transform;
igstk::Transform::VectorType translation;
translation[0] = 0.0;
translation[1] = 0.0;
translation[2] = 0.0;
igstk::Transform::VersorType rotation;
rotation.Set( 0.0, 0.0, 0.0, 1.0 );
igstk::Transform::ErrorType errorValue = 0.01; // 10 microns
transform.SetTranslationAndRotation(
translation, rotation, errorValue, validityTimeInMilliseconds );
std::cout << "Transform to static ellipsoid = " << transform << std::endl;
// Create the ellipsoid representation
igstk::EllipsoidObjectRepresentation::Pointer
ellipsoidRepresentation = igstk::EllipsoidObjectRepresentation::New();
ellipsoidRepresentation->RequestSetEllipsoidObject( ellipsoid );
ellipsoidRepresentation->SetColor(0.0,1.0,0.0);
ellipsoidRepresentation->SetOpacity(1.0);
// Create the cylinder
igstk::CylinderObject::Pointer cylinder = igstk::CylinderObject::New();
cylinder->SetRadius(1.0);
cylinder->SetHeight(300.0);
// Create the cylinder representation
igstk::CylinderObjectRepresentation::Pointer
cylinderRepresentation = igstk::CylinderObjectRepresentation::New();
cylinderRepresentation->RequestSetCylinderObject( cylinder );
cylinderRepresentation->SetColor(1.0,0.0,0.0);
cylinderRepresentation->SetOpacity(1.0);
// instantiate a 3D view
typedef igstk::View3D View3DType;
View3DType::Pointer view3D = View3DType::New();
// set a logger
view3D->SetLogger( application.GetLogger() );
// Make the view the parent of the tracker
application.AttachTrackerToView( view3D );
view3D->RequestAddObject( ellipsoidRepresentation );
view3D->RequestAddObject( cylinderRepresentation );
application.Display3D->RequestSetView( view3D );
application.Show();
std::string CameraCalibrationFileDirectory = argv[1];
std::string InitializationFile = argv[2];
std::string markerTemplateDirectory = argv[3];
application.InitializeTracker(
InitializationFile,
CameraCalibrationFileDirectory,
markerTemplateDirectory );
application.ConfigureTrackerToolsAndAttachToTheTracker();
// Associate the cylinder spatial object to the first tracker tool
application.AttachObjectToTrackerTool ( 1, cylinder );
// Associate the ellispsoid spatial object to the second tracker tool
application.AttachObjectToTrackerTool ( 2, ellipsoid );
igstk::Transform toolTransform;
igstk::Transform::VectorType position;
// Set the refresh rate and start
// the pulse generators of the views.
view3D->SetRefreshRate( 30 );
view3D->RequestResetCamera();
view3D->RequestStart();
while( !application.HasQuitted() )
{
Fl::wait(0.001);
igstk::PulseGenerator::CheckTimeouts();
if( application.IsTrackingTurnedOn())
{
application.GetTrackerToolTransform( 1, toolTransform );
position = toolTransform.GetTranslation();
std::cout << "Trackertool1:"
<< " Position = (" << position[0]
<< "," << position[1] << "," << position[2]
<< ")" << std::endl;
application.GetTrackerToolTransform( 2, toolTransform );
position = toolTransform.GetTranslation();
std::cout << "Trackertool2:"
<< " Position = (" << position[0]
<< "," << position[1] << "," << position[2]
<< ")" << std::endl;
}
}
return EXIT_SUCCESS;
}
|