Skip to content
Snippets Groups Projects
Commit 2566a74d authored by Julien Michel's avatar Julien Michel
Browse files

ENH (Visu Refactoring) VectorData rendering (almost done)

parent cc7e42ba
No related branches found
No related tags found
No related merge requests found
......@@ -24,9 +24,11 @@ namespace otb
{
GlWidget
::GlWidget() : Fl_Gl_Window(0,0,0,0), m_Identifier("Default"), m_UseGlAcceleration(false),
::GlWidget() : Fl_Gl_Window(0,0,0,0), m_Identifier(), m_UseGlAcceleration(false),
m_BackgroundColor()
{
m_Identifier = "Default";
#ifdef OTB_GL_USE_ACCEL
m_UseGlAcceleration = true;
#endif
......
......@@ -71,8 +71,8 @@ public:
typedef typename GlComponentType::VectorType VectorType;
typedef typename GlComponentType::PointType PointType;
typedef ObjectList<GlComponentType> GlComponentListType;
typedef typename GlComponentListType::Pointer GlComponentListPointerType;
typedef typename GlComponentListType::Iterator GlComponentIteratorType;
typedef typename GlComponentListType::Pointer GlComponentListPointerType;
typedef typename GlComponentListType::Iterator GlComponentIteratorType;
/** Reads the OpenGl buffer from an image pointer
* \param image The image pointer,
......
......@@ -132,11 +132,12 @@ private:
typedef void (CALLBACK * FunctionPointerType)();
// Static Combine callback for tesselation
static void TesselationCombineCallback(GLdouble coords[2],GLdouble * data[4], GLfloat weights[4],GLdouble **dataOut)
static void TesselationCombineCallback(GLdouble coords[3],GLdouble * data[4], GLfloat weights[4],GLdouble **dataOut)
{
GLdouble * vertex = new GLdouble[2];
GLdouble * vertex = new GLdouble[3];
vertex[0] = coords[0];
vertex[1] = coords[1];
vertex[2] = coords[2];
*dataOut = vertex;
}
......
......@@ -47,9 +47,9 @@ VectorDataGlComponent<TVectorData>
// Setting up the tesselator callbacks
gluTessCallback(m_GluTesselator,GLU_TESS_BEGIN, (FunctionPointerType) glBegin);
gluTessCallback(m_GluTesselator,GLU_TESS_END, (FunctionPointerType) glEnd);
gluTessCallback(m_GluTesselator,GLU_TESS_ERROR, (FunctionPointerType) VectorDataGlComponent<TVectorData>::TesselationErrorCallback);
gluTessCallback(m_GluTesselator,GLU_TESS_VERTEX, (FunctionPointerType) glVertex2dv);
gluTessCallback(m_GluTesselator,GLU_TESS_COMBINE,(FunctionPointerType) VectorDataGlComponent<TVectorData>::TesselationCombineCallback);
gluTessCallback(m_GluTesselator,GLU_TESS_ERROR, (FunctionPointerType) TesselationErrorCallback);
gluTessCallback(m_GluTesselator,GLU_TESS_VERTEX, (FunctionPointerType) glVertex3dv);
gluTessCallback(m_GluTesselator,GLU_TESS_COMBINE,(FunctionPointerType) TesselationCombineCallback);
}
template <class TVectorData>
......@@ -118,6 +118,7 @@ VectorDataGlComponent<TVectorData>
}
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
glLineWidth(1);
}
template <class TVectorData>
void
......@@ -204,9 +205,10 @@ VectorDataGlComponent<TVectorData>
PointType screenPoint = transform->TransformPoint(spacePoint);
// Convert to double array
GLdouble * glp = new GLdouble[2];
GLdouble * glp = new GLdouble[3];
glp[0]=screenPoint[0];
glp[1]=screenPoint[1];
glp[2]=0.;
vertexBuffer.push_back(glp);
// Add a point to the outer boundary
......@@ -242,9 +244,10 @@ VectorDataGlComponent<TVectorData>
PointType screenPoint = transform->TransformPoint(spacePoint);
// Convert to double array
GLdouble * glp = new GLdouble[2];
GLdouble * glp = new GLdouble[3];
glp[0]=screenPoint[0];
glp[1]=screenPoint[1];
glp[2]=0.;
vertexBuffer.push_back(glp);
// Add a point to the outer boundary
......@@ -260,7 +263,7 @@ VectorDataGlComponent<TVectorData>
// End the polygon
gluTessEndPolygon(m_GluTesselator);
// Do not forget to free all the vertex
// // Do not forget to free all the vertex
for(typename VertexVectorType::iterator it = vertexBuffer.begin();
it!=vertexBuffer.end();++it)
{
......
......@@ -260,6 +260,17 @@ otbImageWidgetWithVectorDataGlComponent
${INPUTDATA}/poupees.png 0
)
IF(OTB_DATA_USE_LARGEINPUT)
ADD_TEST(vrTvImageViewerEndToEndWithVectorData ${VISUREFAC_TESTS1}
otbImageViewerEndToEndWithVectorData
${IMAGEDATA}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF
${INPUTDATA}/ToulouseRoad-examples.shp
${INPUTDATA}/DEM/srtm_directory
200 500 200 0
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
# Testing srcs
SET(VisuRefac_SRCS1
......@@ -297,6 +308,7 @@ otbHistogramCurveNew.cxx
otbCurves2DWidgetWithHistogram.cxx
otbVectorDataGlComponentNew.cxx
otbImageWidgetWithVectorDataGlComponent.cxx
otbImageViewerEndToEndWithVectorData.cxx
)
# Building testing executables
......
/*=========================================================================
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.
=========================================================================*/
#include "otbImageLayerRenderingModel.h"
#include "otbVectorImage.h"
#include "itkRGBPixel.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbImageLayerGenerator.h"
#include "otbImageLayer.h"
#include "otbImageView.h"
#include <FL/Fl.H>
#include "otbImageWidgetController.h"
#include "otbWidgetResizingActionHandler.h"
#include "otbChangeScaledExtractRegionActionHandler.h"
#include "otbChangeExtractRegionActionHandler.h"
#include "otbChangeScaleActionHandler.h"
#include "otbPixelDescriptionModel.h"
#include "otbPixelDescriptionActionHandler.h"
#include "otbPixelDescriptionView.h"
// Vector data includes
#include "otbVectorData.h"
#include "otbVectorDataFileReader.h"
#include "otbVectorDataProjectionFilter.h"
#include "otbVectorDataGlComponent.h"
int otbImageViewerEndToEndWithVectorData( int argc, char * argv[] )
{
// params
const char * infname = argv[1];
const char * vinfname = argv[2];
const char * demdir = argv[3];
const unsigned int scrollSize = atoi(argv[4]);
const unsigned int fullSize = atoi(argv[5]);
const unsigned int zoomSize = atoi(argv[6]);
const double run = atoi(argv[7]);
// typedefs
typedef double PixelType;
typedef itk::RGBPixel<unsigned char> RGBPixelType;
typedef otb::Image<RGBPixelType,2> OutputImageType;
typedef otb::VectorImage<PixelType,2> ImageType;
typedef otb::ImageLayer<ImageType> LayerType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType;
typedef otb::ImageLayerRenderingModel<OutputImageType> ModelType;
typedef otb::ImageView<ModelType> ViewType;
typedef otb::ImageWidgetController ControllerType;
typedef otb::WidgetResizingActionHandler
<ModelType,ViewType> ResizingHandlerType;
typedef otb::ChangeScaledExtractRegionActionHandler
<ModelType,ViewType> ChangeScaledRegionHandlerType;
typedef otb::ChangeExtractRegionActionHandler
<ModelType,ViewType> ChangeRegionHandlerType;
typedef otb::ChangeScaleActionHandler
<ModelType,ViewType> ChangeScaleHandlerType;
typedef otb::PixelDescriptionModel<OutputImageType> PixelDescriptionModelType;
typedef otb::PixelDescriptionActionHandler
< PixelDescriptionModelType, ViewType> PixelDescriptionActionHandlerType;
typedef otb::PixelDescriptionView
< PixelDescriptionModelType > PixelDescriptionViewType;
// VectorData
typedef otb::VectorData<double> VectorDataType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
typedef otb::VectorDataProjectionFilter<VectorDataType,
VectorDataType> VectorDataProjectionFilterType;
typedef otb::VectorDataGlComponent<VectorDataType> VectorDataGlComponentType;
// Instantiation
ModelType::Pointer model = ModelType::New();
PixelDescriptionModelType::Pointer pixelModel = PixelDescriptionModelType::New();
pixelModel->SetLayers(model->GetLayers());
// Reading input image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
reader->GenerateOutputInformation();
// /// Prepare the VectorData
VectorDataFileReaderType::Pointer vreader = VectorDataFileReaderType::New();
vreader->SetFileName(vinfname);
vreader->UpdateOutputInformation();
VectorDataProjectionFilterType::Pointer vproj = VectorDataProjectionFilterType::New();
vproj->SetInput(vreader->GetOutput());
vproj->SetOutputKeywordList(reader->GetOutput()->GetImageKeywordlist());
vproj->SetOutputOrigin(reader->GetOutput()->GetOrigin());
vproj->SetOutputSpacing(reader->GetOutput()->GetSpacing());
vproj->SetDEMDirectory(demdir);
vproj->Update();
VectorDataGlComponentType::Pointer vgl = VectorDataGlComponentType::New();
vgl->SetVectorData(vproj->GetOutput());
// Generate the layer
LayerGeneratorType::Pointer generator = LayerGeneratorType::New();
generator->SetImage(reader->GetOutput());
generator->GenerateLayer();
// Add the layer to the model
model->AddLayer(generator->GetLayer());
// Build a view
ViewType::Pointer view = ViewType::New();
view->SetModel(model);
view->GetScrollWidget()->AddGlComponent(vgl);
view->GetFullWidget()->AddGlComponent(vgl);
view->GetZoomWidget()->AddGlComponent(vgl);
// Build a controller
ControllerType::Pointer controller = ControllerType::New();
view->SetController(controller);
// Add the resizing handler
ResizingHandlerType::Pointer resizingHandler = ResizingHandlerType::New();
resizingHandler->SetModel(model);
resizingHandler->SetView(view);
controller->AddActionHandler(resizingHandler);
// Add the change scaled region handler
ChangeScaledRegionHandlerType::Pointer changeScaledHandler =ChangeScaledRegionHandlerType::New();
changeScaledHandler->SetModel(model);
changeScaledHandler->SetView(view);
controller->AddActionHandler(changeScaledHandler);
// Add the change extract region handler
ChangeRegionHandlerType::Pointer changeHandler =ChangeRegionHandlerType::New();
changeHandler->SetModel(model);
changeHandler->SetView(view);
controller->AddActionHandler(changeHandler);
// Add the change scaled handler
ChangeScaleHandlerType::Pointer changeScaleHandler =ChangeScaleHandlerType::New();
changeScaleHandler->SetModel(model);
changeScaleHandler->SetView(view);
controller->AddActionHandler(changeScaleHandler);
// Add the pixel description action handler
PixelDescriptionActionHandlerType::Pointer pixelActionHandler = PixelDescriptionActionHandlerType::New();
pixelActionHandler->SetView(view);
pixelActionHandler->SetModel(pixelModel);
controller->AddActionHandler(pixelActionHandler);
// Build a pixel description view
PixelDescriptionViewType::Pointer pixelView = PixelDescriptionViewType::New();
pixelView->SetModel(pixelModel);
Fl_Window pixelWindow(fullSize,50);
if(fullSize > 0)
{
pixelWindow.add(pixelView->GetPixelDescriptionWidget());
pixelWindow.resizable(pixelView->GetPixelDescriptionWidget());
pixelWindow.show();
pixelView->GetPixelDescriptionWidget()->show();
pixelView->GetPixelDescriptionWidget()->resize(0,0,fullSize,50);
}
Fl_Window scrollWindow(scrollSize,scrollSize);
if(scrollSize > 0)
{
scrollWindow.add(view->GetScrollWidget());
scrollWindow.resizable(view->GetScrollWidget());
scrollWindow.show();
view->GetScrollWidget()->show();
view->GetScrollWidget()->resize(0,0,scrollSize,scrollSize);
}
Fl_Window fullWindow(fullSize,fullSize);
if(fullSize > 0)
{
fullWindow.add(view->GetFullWidget());
fullWindow.resizable(view->GetFullWidget());
fullWindow.show();
view->GetFullWidget()->show();
view->GetFullWidget()->resize(0,0,fullSize,fullSize);
}
Fl_Window zoomWindow(zoomSize,zoomSize);
if(zoomSize > 0)
{
zoomWindow.add(view->GetZoomWidget());
zoomWindow.resizable(view->GetZoomWidget());
zoomWindow.show();
view->GetZoomWidget()->show();
view->GetZoomWidget()->resize(0,0,zoomSize,zoomSize);
}
if(run)
{
Fl::run();
}
else
{
Fl::check();
}
zoomWindow.remove(view->GetZoomWidget());
scrollWindow.remove(view->GetScrollWidget());
fullWindow.remove(view->GetFullWidget());
pixelWindow.remove(pixelView->GetPixelDescriptionWidget());
return EXIT_SUCCESS;
}
......@@ -147,7 +147,7 @@ int otbImageWidgetWithVectorDataGlComponent( int argc, char * argv[] )
widget->AddGlComponent(vdgl);
widget->redraw();
Fl::check();
Fl::run();
......
......@@ -60,4 +60,5 @@ void RegisterTests()
REGISTER_TEST(otbCurves2DWidgetWithHistogram);
REGISTER_TEST(otbVectorDataGlComponentNew);
REGISTER_TEST(otbImageWidgetWithVectorDataGlComponent);
REGISTER_TEST(otbImageViewerEndToEndWithVectorData);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment