Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated Eye Calibration

  • Loading branch information...
commit adc3b56ee8ed9038bf607bb3d28bf2bcb1d95665 1 parent 87c0aaa
@mdfeist authored
View
282 BlinkAnalysis/AppViewer.cpp
@@ -16,6 +16,7 @@
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Point>
+#include <osg/LineWidth>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/GraphicsWindow>
@@ -24,6 +25,7 @@
#include "Objects.h"
#include "AppData.h"
+#include "Dikablis.h"
#include "WorldManager.h"
osgViewer::Viewer* viewer;
@@ -32,130 +34,208 @@ osg::Group* rootNode;
bool running = false;
bool visible = false;
-float VIEWER_SCALE = 1;
+bool localMarkers = false;
+
+float VIEWER_SCALE = 5.f;
void AppViewer::stopAppViewer() { running = false; }
void AppViewer::setVisible(bool bVisible) { visible = bVisible; }
-void render(void *) {
- // Started Rendering
- running = true;
+void renderEyeVector(osg::Geode* node) {
+ // Get the current client
+ ClientHandler* client = AppData::getInstance()->getClient();
- // Loop until done
- while( !viewer->done() )
- {
- // If not running stop render loop
- if (!running)
- viewer->setDone(running);
+ // Check if the client was created and is not NULL
+ if (client) {
+ // Create Points
+ // Create geo to store ray
+ osg::Geometry* geo = new osg::Geometry();
- // Check if view is visible
- if (visible) {
- // Add Geode to store all the marker points
- osg::Geode* node = new osg::Geode();
+ // Create array to hold ray
+ osg::ref_ptr<osg::Vec3Array> points = new osg::Vec3Array();
+ osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
- // Get the current client
- ClientHandler* client = AppData::getInstance()->getClient();
+ // Lock Client so marker data isn't changed
+ if (client->lock())
+ {
+ // Get current position of head
+ RigidBody* head = client->getHead();
- // Check if the client was created and is not NULL
- if (client) {
- // Lock Client so marker data isn't changed
- if (client->lock())
- {
- // Create Points
- // Create geo to store points
- osg::Geometry* geo = new osg::Geometry();
+ if (head != NULL) {
+ osg::Vec3 pos = head->getPosition();
- // Create array to hold points
- osg::ref_ptr<osg::Vec3Array> points = new osg::Vec3Array();
- osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
+ // Add to the points array
+ points->push_back( pos * VIEWER_SCALE );
+ colors->push_back(osg::Vec4(1, 0, 0, 1));
- // Get the map of all the Rigid Bodies attached to the client
- std::map<int, RigidBody*>* bodyMap = client->getRigidBodyMap();
+ osg::Matrixf headMatrix;
+ headMatrix.makeIdentity();
+ headMatrix.makeTranslate(head->getPosition());
+ headMatrix.makeRotate(head->getRotation());
- // Set the current marker index to zero
- int markerIndex = 0;
+ Dikablis::journal_struct journal = Dikablis::getJournal();
- // Loop Through all the Rigid Bodies attached to the client
- for (std::map<int, RigidBody*>::iterator it_body=bodyMap->begin(); it_body!=bodyMap->end(); ++it_body)
- {
- // Get pointer to Rigid Body
- RigidBody* body = it_body->second;
-
- // Get the vector of all the Markers attached to the Rigid Body
- std::vector<Marker>* markers = body->getMarkersVector();
-
- // Check if the markers vector is created and not null
- if (markers)
- {
- // Loop through all the markers attached to the Rigid Body
- for (std::vector<Marker>::iterator it_marker=markers->begin(); it_marker!=markers->end(); ++it_marker)
- {
- // Get Pointer to marker
- Marker marker = *it_marker;
-
- // Get current position of marker
- osg::Vec3 pos = marker.getPosition();
-
- // Add marker to the points array
- points->push_back( pos * VIEWER_SCALE );
- //points->push_back( pos / 100.f );
-
- // Add colors
- colors->push_back( marker.getColor() );
-
- // Update the current index
- markerIndex++;
- }
- }
- }
-
- // Labeled Markers
- std::map<int, Marker*>* markerMap = client->getLabeledMarkerMap();
- for (labeledmarker_iterator it_marker = markerMap->begin(); it_marker != markerMap->end(); ++it_marker)
+ int x = journal.field_x;
+ int y = journal.field_y;
+
+ osg::Vec3 ray = client->getRay(x, y);
+
+ ray = headMatrix * ray;
+
+ points->push_back( ray * VIEWER_SCALE );
+ colors->push_back(osg::Vec4(1, 0, 0, 1));
+ }
+ }
+
+ // Unlock Client so marker data can be updated
+ client->unlock();
+
+ // Add the points array to the geometry
+ geo->setVertexArray( points );
+
+ // Render the points geometry as Points
+ geo->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, points->size() ) );
+
+ // Set Color array to the geometry
+ geo->setColorArray(colors);
+ geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
+
+ // Add the geometry to the node
+ node->addDrawable( geo );
+
+ // Set the size of the points and turn off lighting
+ osg::ref_ptr<osg::StateSet> nodeState = node->getOrCreateStateSet();
+ nodeState->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+ nodeState->setAttribute( new osg::LineWidth( 3.0f ) , osg::StateAttribute::ON );
+ }
+}
+
+void renderMarkers(osg::Geode* node) {
+ // Get the current client
+ ClientHandler* client = AppData::getInstance()->getClient();
+
+ // Check if the client was created and is not NULL
+ if (client) {
+ // Lock Client so marker data isn't changed
+ if (client->lock())
+ {
+ // Create Points
+ // Create geo to store points
+ osg::Geometry* geo = new osg::Geometry();
+
+ // Create array to hold points
+ osg::ref_ptr<osg::Vec3Array> points = new osg::Vec3Array();
+ osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
+
+ // Get the map of all the Rigid Bodies attached to the client
+ std::map<int, RigidBody*>* bodyMap = client->getRigidBodyMap();
+
+ // Set the current marker index to zero
+ int markerIndex = 0;
+
+ // Loop Through all the Rigid Bodies attached to the client
+ for (std::map<int, RigidBody*>::iterator it_body=bodyMap->begin(); it_body!=bodyMap->end(); ++it_body)
+ {
+ // Get pointer to Rigid Body
+ RigidBody* body = it_body->second;
+
+ // Get the vector of all the Markers attached to the Rigid Body
+ std::vector<Marker>* markers = body->getMarkersVector();
+
+ // Check if the markers vector is created and not null
+ if (markers)
+ {
+ // Loop through all the markers attached to the Rigid Body
+ for (std::vector<Marker>::iterator it_marker=markers->begin(); it_marker!=markers->end(); ++it_marker)
{
// Get Pointer to marker
- Marker* marker = it_marker->second;
+ Marker marker = *it_marker;
// Get current position of marker
- osg::Vec3 pos = marker->getPosition();
+ osg::Vec3 pos = marker.getPosition();
// Add marker to the points array
points->push_back( pos * VIEWER_SCALE );
- //points->push_back( pos / 100.f );
// Add colors
- if (marker->isSelected())
- colors->push_back(osg::Vec4(0, 1, 0, 1));
- else
- colors->push_back(osg::Vec4(0, 0, 1, 1));
+ colors->push_back( marker.getColor() );
+
+ // Update the current index
+ markerIndex++;
}
-
- // Unlock Client so marker data can be updated
- client->unlock();
-
- // Add the points array to the geometry
- geo->setVertexArray( points );
-
- // Render the points geometry as Points
- geo->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, points->size() ) );
-
- // Set Color array to the geometry
- geo->setColorArray(colors);
- geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
-
- // Add the geometry to the node
- node->addDrawable( geo );
-
- // Set the size of the points and turn off lighting
- osg::ref_ptr<osg::StateSet> nodeState = node->getOrCreateStateSet();
- nodeState->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
- nodeState->setMode(GL_BLEND, osg::StateAttribute::ON);
- nodeState->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);
- nodeState->setAttribute( new osg::Point( 10.0f ) , osg::StateAttribute::ON );
- nodeState->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
- // End Create Points
}
- }
+ }
+
+ if (localMarkers) {
+ // Labeled Markers
+ std::map<int, Marker*>* markerMap = client->getLabeledMarkerMap();
+ for (labeledmarker_iterator it_marker = markerMap->begin(); it_marker != markerMap->end(); ++it_marker)
+ {
+ // Get Pointer to marker
+ Marker* marker = it_marker->second;
+
+ // Get current position of marker
+ osg::Vec3 pos = marker->getPosition();
+
+ // Add marker to the points array
+ points->push_back( pos * VIEWER_SCALE );
+
+ // Add colors
+ if (marker->isSelected())
+ colors->push_back(osg::Vec4(0, 1, 0, 1));
+ else
+ colors->push_back(osg::Vec4(0, 0, 1, 1));
+ }
+ }
+ // Unlock Client so marker data can be updated
+ client->unlock();
+
+ // Add the points array to the geometry
+ geo->setVertexArray( points );
+
+ // Render the points geometry as Points
+ geo->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, points->size() ) );
+
+ // Set Color array to the geometry
+ geo->setColorArray(colors);
+ geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
+
+ // Add the geometry to the node
+ node->addDrawable( geo );
+
+ // Set the size of the points and turn off lighting
+ osg::ref_ptr<osg::StateSet> nodeState = node->getOrCreateStateSet();
+ nodeState->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+ nodeState->setMode(GL_BLEND, osg::StateAttribute::ON);
+ nodeState->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);
+ nodeState->setAttribute( new osg::Point( 10.0f ) , osg::StateAttribute::ON );
+ nodeState->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
+ // End Create Points
+ }
+ }
+}
+
+void render(void *) {
+ // Started Rendering
+ running = true;
+
+ // Loop until done
+ while( !viewer->done() )
+ {
+ // If not running stop render loop
+ if (!running)
+ viewer->setDone(running);
+
+ // Check if view is visible
+ if (visible) {
+ // Add Geode to store all the marker points
+ osg::Geode* node = new osg::Geode();
+
+ // Render the OptiTrack Markers
+ renderMarkers(node);
+
+ // Render Eye Vector
+ renderEyeVector(node);
// Add Node containing all the points to the scene
rootNode->addChild( node );
View
22 BlinkAnalysis/ClientHandler.cpp
@@ -44,6 +44,8 @@ ClientHandler::ClientHandler(void)
this->rigidBodyTool = -1;
this->dikablisEyeVectorArray = (float*) malloc(sizeof(float) * ClientHandler::DikablisViewingSize);
+
+ this->headid = 0;
}
// Cleans up the ClientHandler
@@ -56,6 +58,14 @@ ClientHandler::~ClientHandler(void)
free(this->dikablisEyeVectorArray);
}
+void ClientHandler::setRayCalibration(float *vectorArray) {
+ if (this->dikablisEyeVectorArray != NULL &&
+ vectorArray != NULL) {
+ for (unsigned int i = 0; i < DikablisViewingSize; i++) {
+ this->dikablisEyeVectorArray[i] = vectorArray[i];
+ }
+ }
+}
osg::Vec3 ClientHandler::getRay(int x, int y) {
osg::Vec3 ray;
@@ -74,6 +84,18 @@ osg::Vec3 ClientHandler::getRay(int x, int y) {
return ray;
}
+void ClientHandler::setHeadId(int id) {
+ this->headid = id;
+}
+
+int ClientHandler::getHeadId() {
+ return this->headid;
+}
+
+RigidBody* ClientHandler::getHead() {
+ return getRigidBody(this->headid);
+}
+
// Add a Rigid Body to the ClientHandler
bool ClientHandler::addRigidBody(int id, RigidBody* rigidBody)
{
View
8 BlinkAnalysis/ClientHandler.h
@@ -59,6 +59,8 @@ class ClientHandler
// Used to store the calibrated eye vectors
float *dikablisEyeVectorArray;
+
+ int headid;
public:
ClientHandler(void); // Constructor
@@ -152,7 +154,11 @@ class ClientHandler
static unsigned long getDikablisViewingMargin() { return DikablisViewingMargin; }
static unsigned long getDikablisViewingSize() { return DikablisViewingSize; }
- //void setRay(osg::Vec3 ray, int x, int y);
+ void setRayCalibration(float *vectorArray);
osg::Vec3 getRay(int x, int y);
+
+ void setHeadId(int id);
+ int getHeadId();
+ RigidBody* getHead();
};
View
49 BlinkAnalysis/EyeCalibration.cpp
@@ -73,13 +73,23 @@ bool EyeCalibration::addPoint() {
ray = viewing->getPosition() - head->getPosition();
ray = headMatrix * ray;
ray.normalize();
- ray = ray/ray.z();
+ ray = ray/ray.y();
Dikablis::journal_struct journal;
journal = Dikablis::getJournal();
CalibrationPoint point(journal.field_x, journal.field_y, ray);
- calibrationPoints.push_back(point);
+
+ bool exists = false;
+ for (unsigned int i = 0; i < calibrationPoints.size(); i++) {
+ if (point.equal(calibrationPoints[i])) {
+ exists = true;
+ break;
+ }
+ }
+
+ if (!exists)
+ calibrationPoints.push_back(point);
return true;
}
@@ -695,6 +705,8 @@ bool EyeCalibration::calibrate() {
}
}
+// Testing
+#if 0
// Draw points
for (unsigned int c = 0; c < calibrationPoints.size(); c++) {
CalibrationPoint point = calibrationPoints[c];
@@ -742,6 +754,17 @@ bool EyeCalibration::calibrate() {
}
saveRayMap();
+#endif
+
+ ClientHandler* client = AppData::getInstance()->getClient();
+
+ if (client) {
+ client->setRayCalibration(this->eyeVectorArray);
+ client->setHeadId(this->rbHeadId);
+ } else {
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Failed: Unable to find client.\n");
+ return false;
+ }
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Done\n");
@@ -1007,30 +1030,16 @@ void EyeCalibration::saveRayMap() {
void EyeCalibration::createTestData() {
- CalibrationPoint point1(20, 5, osg::Vec3(255.f, 0.f, 0.f));
+ CalibrationPoint point1(20, 5, osg::Vec3(-1.2f, -1.f, 2.f));
calibrationPoints.push_back(point1);
- CalibrationPoint point2(322, 2, osg::Vec3(125.f, 125.f, 0.f));
+ CalibrationPoint point2(700, 25, osg::Vec3(1.4f, -1.f, 1.6f));
calibrationPoints.push_back(point2);
- CalibrationPoint point3(700, 25, osg::Vec3(0, 0.f, 125.f));
+ CalibrationPoint point3(-10, 520, osg::Vec3(-0.8, -1.f, -1.4f));
calibrationPoints.push_back(point3);
- CalibrationPoint point4(-10, 280, osg::Vec3(0.f, 125.f, 0.f));
+ CalibrationPoint point4(730, 542, osg::Vec3(1.f, -1.f, -1.3f));
calibrationPoints.push_back(point4);
- CalibrationPoint point5(374, 180, osg::Vec3(0.f, 0.f, 255.f));
- calibrationPoints.push_back(point5);
-
- CalibrationPoint point6(742, 320, osg::Vec3(0.f, 125.f, 125.f));
- calibrationPoints.push_back(point6);
-
- CalibrationPoint point7(4, 480, osg::Vec3(125.f, 0.f, 125.f));
- calibrationPoints.push_back(point7);
-
- CalibrationPoint point8(280, 550, osg::Vec3(125.f, 0.f, 0.f));
- calibrationPoints.push_back(point8);
-
- CalibrationPoint point9(724, 520, osg::Vec3(0.f, 255.f, 255.f));
- calibrationPoints.push_back(point9);
}
View
19 BlinkAnalysis/EyeCalibrationWizardForm.h
@@ -620,17 +620,22 @@ private: System::Void pageChanged(System::Object^ sender, System::EventArgs^ e
// Check Valid information for each page
if (this->wizardPages->SelectedTab == this->headSelectPage &&
this->eyeCalibration->getHeadId() < 0) {
- this->nextBtn->Enabled = false;
+ this->nextBtn->Enabled = false;
} else if (this->wizardPages->SelectedTab == this->objectSelectPage &&
this->eyeCalibration->getViewingObjectId() < 0) {
- this->nextBtn->Enabled = false;
+ this->nextBtn->Enabled = false;
+ } else if (this->wizardPages->SelectedTab == this->calculatingPage) {
+ this->nextBtn->Enabled = false;
} else {
- this->nextBtn->Enabled = true;
+ this->nextBtn->Enabled = true;
}
// Calculate Calibration Points
- if (this->wizardPages->SelectedTab == this->calculatingPage)
- this->eyeCalibration->calibrate();
+ if (this->wizardPages->SelectedTab == this->calculatingPage) {
+ if (this->eyeCalibration->calibrate()) {
+ this->nextBtn->Enabled = true;
+ }
+ }
// Done and change text in the next button to finished
if (this->wizardPages->SelectedIndex == this->wizardPages->TabCount - 1)
@@ -697,8 +702,8 @@ private: System::Void selectAsObjectBtn_Click(System::Object^ sender, System::E
}
}
private: System::Void addCalibrationPointBtn_Click(System::Object^ sender, System::EventArgs^ e) {
- //this->eyeCalibration->addPoint();
- this->eyeCalibration->createTestData();
+ this->eyeCalibration->addPoint();
+ //this->eyeCalibration->createTestData();
}
public: System::Void calibrationOutputLog(String^ value) {
if (this->calibrationOutputLogLabel->InvokeRequired)
Please sign in to comment.
Something went wrong with that request. Please try again.