8 #include "PlusConfigure.h" 15 #include <vtkCallbackCommand.h> 16 #include <vtkSmartPointer.h> 17 #include <vtksys/CommandLineArguments.hxx> 24 vtkNew<vtkPlusOpenIGTLinkServer>
server;
26 void PrintLogsCallback(vtkObject* obj,
unsigned long eid,
void* clientdata,
void* calldata);
30 LOG_INFO(
"Server status: Reading configuration.");
32 vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
33 if (dataCollector->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
35 LOG_ERROR(
"Datacollector failed to read configuration");
40 vtkSmartPointer<vtkIGSIOTransformRepository> transformRepository = vtkSmartPointer<vtkIGSIOTransformRepository>::New();
41 if (transformRepository->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
43 LOG_ERROR(
"Transform repository failed to read configuration");
47 LOG_INFO(
"Server status: Connecting to devices.");
50 LOG_ERROR(
"Datacollector failed to connect to devices");
56 LOG_ERROR(
"Datacollector failed to start");
60 XML_FIND_NESTED_ELEMENT_REQUIRED(serverElement, configRootElement,
"PlusOpenIGTLinkServer");
62 LOG_DEBUG(
"Initializing Plus OpenIGTLink server... ");
63 if (
server->Start(dataCollector, transformRepository, serverElement, configFilePath) !=
PLUS_SUCCESS)
71 int main(
int argc,
char** argv)
73 bool printHelp(
false);
74 std::string clientConfigFileName;
75 std::string serverConfigFileName;
76 bool renderingOff(
false);
78 vtksys::CommandLineArguments args;
79 args.Initialize(argc, argv);
81 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
83 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
84 args.AddArgument(
"--client-config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &clientConfigFileName,
"Config file containing the client configuration.");
85 args.AddArgument(
"--server-config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &serverConfigFileName,
"Config file containing the server configuration.");
86 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
90 std::cerr <<
"Problem parsing arguments" << std::endl;
91 std::cout <<
"\n\nvtkPlusOpenIGTLinkTrackerTest help:" << args.GetHelp() << std::endl;
99 std::cout <<
"\n\nvtkPlusOpenIGTLinkTrackerTest help:" << args.GetHelp() << std::endl;
104 LOG_INFO(
"Reading server config file...");
105 vtkNew<vtkXMLDataElement> serverConfigRootElement;
108 LOG_ERROR(
"Unable to read configuration from file " << serverConfigFileName.c_str());
114 LOG_ERROR(
"Unable to start server");
119 LOG_INFO(
"Reading client config file...");
120 vtkNew<vtkXMLDataElement> clientConfigRootElement;
123 LOG_ERROR(
"Unable to read configuration from file " << clientConfigFileName.c_str());
126 vtkNew<vtkPlusOpenIGTLinkTracker> client;
129 vtkNew<vtkCallbackCommand> callbackCommand;
131 client->AddObserver(
"WarningEvent", callbackCommand);
132 client->AddObserver(
"ErrorEvent", callbackCommand);
133 client->SetDeviceId(
"TrackerDevice");
134 if (client->ReadConfiguration(clientConfigRootElement) !=
PLUS_SUCCESS)
136 LOG_ERROR(
"Unable to configure client.");
140 LOG_INFO(
"Connect client...");
143 LOG_ERROR(
"Unable to connect client to server.");
149 LOG_ERROR(
"Unable to start recording of client device.");
161 auto channel = *client->GetOutputChannelsStart();
164 LOG_ERROR(
"No channel configured for device.");
168 igsioTrackedFrame frame;
171 LOG_ERROR(
"Unable to retrieve frame from device.");
175 client->Disconnect();
176 LOG_INFO(
"Exit successfully");
183 if (eid == vtkCommand::GetEventIdFromString(
"WarningEvent"))
185 LOG_WARNING((
const char*)calldata);
187 else if (eid == vtkCommand::GetEventIdFromString(
"ErrorEvent"))
189 LOG_ERROR((
const char*)calldata);
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
PlusStatus StartServer(vtkXMLDataElement *configRootElement, const std::string &configFilePath)
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
vtkNew< vtkPlusOpenIGTLinkServer > server