31 offeringTopic(getProperty<std::string>(
"ViconDataTopicName").getValue());
32 offeringTopic(getProperty<std::string>(
"DebugDrawerTopicName").getValue());
38 listener = getTopic<ViconMarkerProviderListenerInterfacePrx>(getProperty<std::string>(
"ViconDataTopicName").getValue());
39 debugDrawer = getTopic<DebugDrawerInterfacePrx>(getProperty<std::string>(
"DebugDrawerTopicName").getValue());
41 std::string address = getProperty<std::string>(
"Hostname").getValue();
42 address +=
":" +
to_string(getProperty<int>(
"Port").getValue());
44 ARMARX_INFO <<
"Connecting to VICON server at " << address <<
"...";
49 if (
dsClient.IsConnected().Connected)
51 ARMARX_INFO <<
"Connected to VICON server. Setting up configuration...";
53 if (
dsClient.EnableMarkerData().Result &&
dsClient.EnableUnlabeledMarkerData().Result &&
dsClient.SetStreamMode(ViconDataStreamSDK::CPP::StreamMode::ClientPull).Result)
55 ARMARX_INFO <<
"Setup complete. Starting polling thread.";
72 ARMARX_ERROR <<
"Exception while connecting to vicon server!";
94 if (!
dsClient.IsConnected().Connected)
101 if (
dsClient.GetFrame().Result != ViconDataStreamSDK::CPP::Result::Success)
103 ARMARX_WARNING <<
"Failed to receive frame, will retry in one second! (Is VICON Nexus currently running in online or playback mode?)";
108 DebugDrawerColoredPointCloud pointCloud;
109 pointCloud.pointSize = 10;
112 std::map<std::string, Vector3f> labeledMarkers;
113 int labeledMarkerCount = 0;
114 int subjectCount =
dsClient.GetSubjectCount().SubjectCount;
116 for (
int curSubj = 0; curSubj < subjectCount; ++curSubj)
118 std::string subjectName =
dsClient.GetSubjectName(curSubj).SubjectName;
120 int subjectMarkerCount =
dsClient.GetMarkerCount(subjectName).MarkerCount;
121 for (
int i = 0; i < subjectMarkerCount; ++i)
123 std::string markerName =
dsClient.GetMarkerName(subjectName, i).MarkerName;
124 double* translation =
dsClient.GetMarkerGlobalTranslation(subjectName, markerName).Translation;
127 v.e0 = translation[0];
128 v.e1 = translation[1];
129 v.e2 = translation[2];
130 labeledMarkers[subjectName +
":" + markerName] =
v;
132 DebugDrawerColoredPointCloudElement p;
139 pointCloud.points.push_back(p);
141 ++labeledMarkerCount;
150 listener->reportLabeledViconMarkerFrame(labeledMarkers);
153 std::vector<Vector3f> unlabeledMarkers;
154 int unlabeledMarkerCount =
dsClient.GetUnlabeledMarkerCount().MarkerCount;
156 for (
int i = 0; i < unlabeledMarkerCount; ++i)
158 double* translation =
dsClient.GetUnlabeledMarkerGlobalTranslation(i).Translation;
161 v.e0 = translation[0];
162 v.e1 = translation[1];
163 v.e2 = translation[2];
164 unlabeledMarkers.push_back(
v);
166 DebugDrawerColoredPointCloudElement p;
173 pointCloud.points.push_back(p);
176 listener->reportUnlabeledViconMarkerFrame(unlabeledMarkers);
178 ARMARX_DEBUG <<
"Frame processed: " << subjectCount <<
" subjects, " << labeledMarkerCount <<
" labeled markers, " << unlabeledMarkers.size() <<
" unlabeled markers";
180 debugDrawer->setColoredPointCloudVisu(
"ViconMarkerProvider",
"MarkerCloud", pointCloud);