00001 #include "InterestPointRenderer.h" 00002 00003 InterestPointRenderer::InterestPointRenderer(const std::vector<const OrientedPoint2D *> *_points, 00004 const std::vector<double> * _scales): 00005 m_interestPoints(_points), 00006 m_scales(_scales) 00007 { 00008 if(!_points || (_scales && _points->size() != _scales->size())){ 00009 m_interestPoints = NULL; 00010 m_scales = NULL; 00011 } 00012 if(m_interestPoints){ 00013 m_GLUPoints.resize(m_interestPoints->size()); 00014 for(unsigned int i = 0; i < m_GLUPoints.size(); i++){ 00015 m_GLUPoints[i] = gluNewQuadric(); 00016 } 00017 m_colors.resize(m_interestPoints->size(),Color(1.f,0.f,0.f,1.f)); 00018 } 00019 m_scaleFactor = 1.f; 00020 m_depth = 0.f; 00021 setSubdivision(80, 12); 00022 } 00023 00024 InterestPointRenderer::~InterestPointRenderer(){ 00025 for(unsigned int i = 0; i < m_GLUPoints.size(); i++){ 00026 gluDeleteQuadric(m_GLUPoints[i]); 00027 } 00028 } 00029 00030 InterestPointRenderer::InterestPointRenderer(const InterestPointRenderer& _renderer): 00031 m_interestPoints(_renderer.getInterestPoints()), 00032 m_scales(_renderer.getScales()), 00033 m_GLUPoints(0), 00034 m_colors(_renderer.m_colors) 00035 { 00036 if(m_interestPoints){ 00037 m_GLUPoints.resize(m_interestPoints->size()); 00038 } 00039 for(unsigned int i = 0; i < m_GLUPoints.size(); i++){ 00040 m_GLUPoints[i] = gluNewQuadric(); 00041 } 00042 m_depth = _renderer.m_depth; 00043 m_scaleFactor = _renderer.getScaleFactor(); 00044 _renderer.getSubdivision(m_subdivision[0], m_subdivision[1]); 00045 } 00046 00047 InterestPointRenderer& InterestPointRenderer::operator=(const InterestPointRenderer& _renderer){ 00048 setInterestPoints(_renderer.getInterestPoints(), _renderer.getScales()); 00049 m_scaleFactor = _renderer.getScaleFactor(); 00050 m_colors = _renderer.getColors(); 00051 m_depth = _renderer.m_depth; 00052 _renderer.getSubdivision(m_subdivision[0], m_subdivision[1]); 00053 return *this; 00054 } 00055 00056 void InterestPointRenderer::setInterestPoints(const std::vector<const OrientedPoint2D *> *_points, 00057 const std::vector<double> * _scales) 00058 { 00059 if(_points && _scales && _points->size() == _scales->size()){ 00060 m_interestPoints = _points; 00061 m_scales = _scales; 00062 } else { 00063 m_interestPoints = NULL; 00064 m_scales = NULL; 00065 return; 00066 } 00067 00068 if(m_interestPoints->size() == m_GLUPoints.size()) return; 00069 00070 unsigned int i = m_interestPoints->size(); 00071 for(; i < m_GLUPoints.size(); i++){ 00072 gluDeleteQuadric(m_GLUPoints[i]); 00073 } 00074 00075 i = m_GLUPoints.size(); 00076 m_GLUPoints.resize(m_interestPoints->size()); 00077 for(; i < m_GLUPoints.size(); i++){ 00078 m_GLUPoints[i] = gluNewQuadric(); 00079 } 00080 } 00081 00082 00083 void InterestPointRenderer::render(){ 00084 if(!m_interestPoints) return; 00085 glPushMatrix(); 00086 glTranslatef(0.f, 0.f, m_depth); 00087 for (unsigned int index = 0; index < m_interestPoints->size(); index++) { 00088 glPushMatrix(); 00089 glTranslated((*m_interestPoints)[index]->x, (*m_interestPoints)[index]->y, 0); 00090 glRotated(rad2deg((*m_interestPoints)[index]->theta), 0., 0., 1.); 00091 glColor4f(m_colors[index].red(), m_colors[index].green(), m_colors[index].blue(), m_colors[index].alpha()); 00092 double size = m_scaleFactor * (*m_scales)[index]; 00093 00094 glBegin(GL_LINES); 00095 glVertex3f(0.0f,0.0f,0.0f); 00096 glVertex3f(size, 0.f ,0.0f); 00097 glEnd(); 00098 00099 glBegin(GL_LINE_STRIP); 00100 for(double i = -M_PI; i <= M_PI; i += 2.0*M_PI/(double)m_subdivision[0]) 00101 glVertex3f(cos(i)*size, sin(i)*size,0.0f); 00102 glEnd(); 00103 00104 gluSphere(m_GLUPoints[index], 0.02f, m_subdivision[0], m_subdivision[1]); 00105 glPopMatrix(); 00106 } 00107 glPopMatrix(); 00108 }