00001 #include "CorrespondenceRenderer.h"
00002
00003 CorrespondenceRenderer::CorrespondenceRenderer(const std::vector< std::pair<Point2D, Point2D> > *correspondences, const std::vector< double > *distances):
00004 m_correspondences(correspondences),
00005 m_distances(NULL),
00006 m_referenceDepth(0),
00007 m_dataDepth(0),
00008 m_maxDistance(0)
00009 {
00010 if(m_correspondences){
00011 m_colors.resize(m_correspondences->size(),Color(1.f,0.f,0.f,1.f));
00012 if(distances && m_correspondences->size() == distances->size()){
00013 m_distances = distances;
00014 for(unsigned int i = 0; i < m_distances->size(); i++){
00015 m_maxDistance = m_maxDistance > (*m_distances)[i] ? m_maxDistance : (*m_distances)[i];
00016 }
00017 }
00018 }
00019 }
00020
00021 void CorrespondenceRenderer::setCorrespondences(const std::vector< std::pair<Point2D, Point2D> > *correspondences, const std::vector< double > *distances)
00022 {
00023 m_correspondences = correspondences;
00024 m_distances = distances;
00025 if(m_correspondences){
00026 m_colors.resize(m_correspondences->size(),Color(1.f,0.f,0.f,1.f));
00027 if(distances && m_correspondences->size() == distances->size()){
00028 m_distances = distances;
00029 for(unsigned int i = 0; i < m_distances->size(); i++){
00030 m_maxDistance = m_maxDistance > (*m_distances)[i] ? m_maxDistance : (*m_distances)[i];
00031 }
00032 }
00033 }
00034 }
00035
00036 void CorrespondenceRenderer::render()
00037 {
00038 if(!m_correspondences) return;
00039 glPushMatrix();
00040 float width;
00041 glGetFloatv(GL_LINE_WIDTH, &width);
00042 glLineWidth(5.0);
00043 glBegin(GL_LINES);
00044 for(unsigned int i = 0; i < m_correspondences->size(); i++){
00045 float alpha = m_distances ? 1.f - (*m_distances)[i]/m_maxDistance : 1.f;
00046
00047 glColor4f(alpha, alpha, alpha, 1.f);
00048 glVertex3f((*m_correspondences)[i].first.x, (*m_correspondences)[i].first.y, m_referenceDepth);
00049 glVertex3f((*m_correspondences)[i].second.x, (*m_correspondences)[i].second.y, m_dataDepth);
00050 }
00051 glEnd();
00052 glLineWidth(width);
00053 glPopMatrix();
00054 }