diff --git a/Code/Visualization/otbCircleGlComponent.cxx b/Code/Visualization/otbCircleGlComponent.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9795e8b4227605b57330c0bf42f77457ae7c5766 --- /dev/null +++ b/Code/Visualization/otbCircleGlComponent.cxx @@ -0,0 +1,130 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbCircleGlComponent_cxx +#define __otbCircleGlComponent_cxx + +#include "otbCircleGlComponent.h" + + +namespace otb +{ +CircleGlComponent +::CircleGlComponent() : m_IndexList(),m_Spacing(), m_Origin(), m_GluTesselator(), + m_ColorList(), m_LineWidth(1.5), m_Radius(2), m_RedColor() +{ + // Default color is red + m_RedColor.Fill(0); + m_RedColor[0]=1.; + m_RedColor[3]=0.5; + + + // Intialize origin and spacing + m_Origin.Fill(0.); + m_Spacing.Fill(1.); + m_Radius = 10; + // Create the tesselator + m_GluTesselator = gluNewTess(); +} + +CircleGlComponent +::~CircleGlComponent() +{ + // Delete the tesselator + gluDeleteTess(m_GluTesselator); +} + + +void +CircleGlComponent +::Render(const RegionType& extent,const AffineTransformType * space2ScreenTransform) +{ + if(m_IndexList.size() == 0) + { + // nothing to render, return + return; + } + + // Set up blending and color + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4d(m_RedColor[0],m_RedColor[1],m_RedColor[2],m_RedColor[3]); + + // Set up line width + double previousWidth = 0.; + glGetDoublev(GL_LINE_WIDTH,&previousWidth); + + // convert line width to screen line width + VectorType imageLineWidth; + imageLineWidth.Fill(m_LineWidth); + VectorType screenLineWidth = space2ScreenTransform->TransformVector(imageLineWidth); + glLineWidth(screenLineWidth[0]); + // Do we need to render boundaries only (for polygons) + gluTessProperty(m_GluTesselator,GLU_TESS_BOUNDARY_ONLY,false); + + // Enabling line antialiasing + glEnable(GL_POINT_SMOOTH); + + for(unsigned int i=0; i<m_IndexList.size(); i++) + { + this->Render(i,extent,space2ScreenTransform); + } + + glDisable(GL_POINT_SMOOTH); + glDisable(GL_BLEND); + //glLineWidth(previousWidth); +} + + +void +CircleGlComponent +::Render(unsigned int id, const RegionType & extent, const AffineTransformType * space2ScreenTransform) +{ + glColor4d(m_ColorList[id][0],m_ColorList[id][1],m_ColorList[id][2],m_ColorList[id][3]); + + // Take into account pixel spacing and origin + //PointType spacePoint = dataNode->GetPoint(); + PointType spacePoint; + spacePoint[0]*= m_Spacing[0]; + spacePoint[1]*= m_Spacing[1]; + spacePoint[0] = m_IndexList[id][0] + m_Origin[0]; + spacePoint[1] = m_IndexList[id][1] + m_Origin[1]; + + // Transform to a screen point + PointType screenPoint = space2ScreenTransform->TransformPoint(spacePoint); + + // Draw a disk + glEnable(GL_BLEND); + glPointSize(m_Radius); + glBegin(GL_POINTS); + glVertex2d(screenPoint[0],screenPoint[1]); + glEnd(); + + // Draw the center + //glColor4d(m_ColorList[id][0],m_ColorList[id][1],m_ColorList[id][2],1) + glColor4d(0, 0, 0, 1); + glEnable(GL_BLEND); + glPointSize(2); + glBegin(GL_POINTS); + glVertex2d(screenPoint[0],screenPoint[1]); + glEnd(); +} + +} +#endif + + diff --git a/Code/Visualization/otbCircleGlComponent.h b/Code/Visualization/otbCircleGlComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..4c2ded1e77e0648c7219819e15a6a2615c3031d8 --- /dev/null +++ b/Code/Visualization/otbCircleGlComponent.h @@ -0,0 +1,184 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbCircleGlComponent_h +#define __otbCircleGlComponent_h + +#include "otbGlComponent.h" +#include "itkPreOrderTreeIterator.h" + +# ifdef __APPLE__ +# include <OpenGL/glu.h> +# else +# include <GL/glu.h> +# endif + +// There are function prototype conflits under cygwin between standard w32 API +// and standard C ones +#ifndef CALLBACK +#if defined(_WINDOWS) || defined(__CYGWIN__) +#define CALLBACK __stdcall +#else +#define CALLBACK +#endif +#endif + + +namespace otb +{ +/** \class CircleGlComponent +* \brief This Gl Component to render a Circle. +* No checking is done upon the adequation between the Circle +* projection and the underlying image projection. +* +* Origin and Spacing allows to fit to the image axis. +* \ingroup Visualization + */ + +class CircleGlComponent : public GlComponent +{ +public: + /** Standard class typedefs */ + typedef CircleGlComponent Self; + typedef GlComponent Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + typedef Superclass::RegionType RegionType; + + // affine transform + typedef Superclass::AffineTransformType AffineTransformType; + typedef AffineTransformType::InputPointType PointType; + typedef AffineTransformType::InputVectorType VectorType; + typedef Superclass::ColorType ColorType; + + typedef itk::Index<> IndexType; + typedef std::vector<IndexType> IndexListType; + typedef std::vector<ColorType> ColorListType; + + /** Runtime information */ + itkTypeMacro(CircleGlComponent,GlComponent); + + /** New macro */ + itkNewMacro(Self); + + /// Render the vector data + virtual void Render(const RegionType& extent,const AffineTransformType * space2ScreenTransform); + + /** Set/Get the grid spacing */ + itkSetMacro(Spacing,VectorType); + itkGetConstReferenceMacro(Spacing,VectorType); + + /** Set/Get the grid origin */ + itkSetMacro(Origin,PointType); + itkGetConstReferenceMacro(Origin,PointType); + + /** Set/Get the index to render */ + void SetIndexList(IndexListType idList) { m_IndexList = idList; }; + IndexListType GetIndexList() { return m_IndexList; }; + void AddIndex(IndexType id) { m_IndexList.push_back(id); m_ColorList.push_back(m_RedColor); }; + void RemoveIndex(unsigned int id) + { + if( id >= m_IndexList.size() ) + itkExceptionMacro(<<"Index out of size "); + + m_IndexList.erase(m_IndexList.begin()+id); + }; + + /** Set/Get the color */ + void SetColorList(ColorListType colorList) { m_ColorList = colorList; }; + ColorListType GetColorList() { return m_ColorList; }; + void ChangeColor(ColorType color, unsigned int id) + { + if( id >= m_ColorList.size() ) + itkExceptionMacro(<<"Index out of size "); + + m_ColorList[id] = color; + }; + void RemoveColor(unsigned int id) + { + if( id >= m_ColorList.size() ) + itkExceptionMacro(<<"Index out of size "); + + m_ColorList.erase(m_ColorList.begin()+id); + }; + + /** Clear all*/ + void Clear() { m_IndexList.clear(); m_ColorList.clear(); }; + void ClearIndex(unsigned int id) + { + this->RemoveIndex(id); + this->RemoveColor(id); + }; + + /** Set/Get the line width */ + itkSetMacro(LineWidth,double); + itkGetMacro(LineWidth,double); + + /** Set/Get the circle radius. */ + itkSetMacro(Radius,double); + itkGetMacro(Radius,double); + +protected: + /** Constructor */ + CircleGlComponent(); + /** Destructor */ + virtual ~CircleGlComponent(); + /** Printself method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + } + + // Recursive rendering method + virtual void Render(unsigned int id, const RegionType & extent, const AffineTransformType * space2ScreenTransform); + + +private: + CircleGlComponent(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + /// Index point to render + IndexListType m_IndexList; + + /// Spacing of the image grid + VectorType m_Spacing; + + /// Origin of the image + PointType m_Origin; + + /// The GluTesselator object to render complex polygons + GLUtesselator * m_GluTesselator; + + /// Color of the vector layer + ColorListType m_ColorList; + + /** The line width */ + double m_LineWidth; + + /** The circle radius */ + double m_Radius; + + /** Default color : red*/ + ColorType m_RedColor; + +}; // end class +} // end namespace otb + +#endif + + +