Commit d76ddab6 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Implemented basic version of Model...

ENH: Implemented basic version of Model (AbstractModel<-AbstractImageModel->VectorImageModel); loading on File/Open and storing in Application.
parent 8fbb5198
......@@ -48,8 +48,11 @@ namespace mvd
/*******************************************************************************/
Application
::Application( int& argc, char** argv ) :
I18nApplication( argc, argv )
I18nApplication( argc, argv ),
m_Model( NULL )
{
IMPLEMENT_APP_SINGLETON( mvdApp );
InitializeCore();
QObject::connect(
......
......@@ -26,20 +26,29 @@
//
// Qt includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
#
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModel.h"
#include "mvdI18nApplication.h"
//
// External classes pre-declaration.
namespace
{
}
//
// Class declaration.
namespace mvd
{
DECLARE_APP_SINGLETON( Application, mvdApp );
//
// Class declaration.
/** \class Application
*
*/
......@@ -58,6 +67,32 @@ public:
/** Destructor */
virtual ~Application();
/**
*/
inline void SetModel( AbstractModel* model )
{
delete m_Model;
m_Model = model;
m_Model->setParent( this );
}
/**
*/
inline const AbstractModel*
GetModel() const
{
const_cast< const Application* >( this )->GetModel();
}
/**
*/
inline AbstractModel*
GetModel()
{
return m_Model;
}
//
// SIGNALS.
signals:
......@@ -80,6 +115,7 @@ private:
//
// Private attributes.
private:
AbstractModel* m_Model;
//
// SLOTS
......
......@@ -42,6 +42,8 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "ConfigureMonteverdi2.h"
#include "mvdApplication.h"
#include "mvdVectorImageModel.h"
namespace mvd
{
......@@ -57,7 +59,8 @@ namespace mvd
MainWindow
::MainWindow( QWidget* parent, Qt::WindowFlags flags ) :
QMainWindow( parent, flags ),
m_UI( new mvd::Ui::MainWindow() )
m_UI( new mvd::Ui::MainWindow() ),
m_ImageView()
{
m_UI->setupUi( this );
......@@ -124,22 +127,48 @@ MainWindow
{
return;
}
// TODO: Replace with complex model (list of DatasetModel) when implemented.
VectorImageModel* newVectorImageModel = new VectorImageModel();
//
// TODO: Move piece of code below to ImageModel.
ReaderType::Pointer reader( ReaderType::New() );
reader->SetFileName( filename.toLatin1().data() );
reader->UpdateOutputInformation();
newVectorImageModel->setObjectName(
"mvd::VectorImageModel('" + filename + "'"
);
try
{
newVectorImageModel->loadFile( filename );
dynamic_cast< Application* >( qApp )->SetModel( newVectorImageModel );
}
catch( std::exception& exc )
{
delete newVectorImageModel;
newVectorImageModel = NULL;
QMessageBox::warning( this, tr("Exception!"), exc.what() );
return;
}
// typedef support for layers
typedef ImageLayer<VectorImageType, ImageType> LayerType;
typedef otb::ImageLayer<VectorImageType, ImageType> LayerType;
typedef LayerType::Pointer LayerPointerType;
typedef ImageLayerGenerator<LayerType> LayerGeneratorType;
typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType;
typedef LayerGeneratorType::RenderingFunctionType RenderingFunctionType;
// Layer Generator
LayerGeneratorType::Pointer layerGenerator = LayerGeneratorType::New();
#if 0
layerGenerator->SetImage(reader->GetOutput());
#else
layerGenerator->SetImage(
// dynamic_cast< VectorImageModel* >( mvdApp->GetModel()
// )->GetOutput( 0 )
dynamic_cast< VectorImageModel* >
( dynamic_cast< Application* >
( qApp )->GetModel() )->GetOutput( 0 )
);
#endif
layerGenerator->GenerateQuicklookOff();
layerGenerator->GenerateLayer();
......
......@@ -25,24 +25,28 @@
//
// Qt includes (sorted by alphabetic order)
#include <QtGui>
//#include <QtGui>
//
// OTB includes (sorted by alphabetic order)
#include "mvdImageView.h"
// ITK includes (sorted by alphabetic order)
#include "itkRGBAPixel.h"
#include "otbVectorImage.h"
//
// OTB includes (sorted by alphabetic order)
#include "otbImageLayerRenderingModel.h"
#include "otbImageFileReader.h"
#include "otbVectorImage.h"
//
// Monteverdi includes (sorted by alphabetic order)
// Warning! it's generally not a good idea to use namespaces in header files.
using namespace otb;
using namespace itk;
#include "ConfigureMonteverdi2.h"
#include "mvdImageView.h"
//
// External class pre-declaration.
namespace
{
}
namespace mvd
{
......@@ -61,9 +65,11 @@ class MainWindow
{
Q_OBJECT;
//
// Public types.
public:
typedef otb::VectorImage<double, 2> VectorImageType;
// typedef otb::VectorImage<double, 2> VectorImageType;
typedef itk::RGBAPixel<unsigned char> PixelType;
typedef otb::Image<PixelType, 2> ImageType;
typedef ImageType::RegionType RegionType;
......@@ -72,20 +78,47 @@ public:
typedef otb::ImageLayerRenderingModel<ImageType> RenderingModelType;
typedef mvd::ImageView<RenderingModelType> ImageViewType;
//
// Public methods.
public:
/** Constructor */
MainWindow( QWidget* Parent =0, Qt::WindowFlags flags =0 );
/** Destructor */
virtual ~MainWindow();
//
// SIGNALS.
signals:
//
// Protected methods.
protected:
//
// Protected attributes.
protected:
//
// Private SLOTS.
private:
/**
*/
void Initialize();
//
// Private methods.
private:
/**
*/
Ui::MainWindow* m_UI;
/**
*/
ImageViewType::Pointer m_ImageView;
//
// Private attributes.
private slots:
void on_action_Open_activated();
};
......
......@@ -30,16 +30,19 @@
#include "mvdTypes.h"
//
// OTB includes (sorted by alphabetic order)
// ITK includes (sorted by alphabetic order)
#include "itkRGBAPixel.h"
#include "itkAffineTransform.h"
//
// OTB includes (sorted by alphabetic order)
#include "otbImage.h"
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdImageViewManipulator.h"
#include "mvdImageModelRenderer.h"
#include "mvdAbstractImageModel.h"
#include "mvdImageModelRenderer.h"
#include "mvdImageViewManipulator.h"
//
// Global definitions.
......
......@@ -25,6 +25,7 @@
//
// Qt includes (sorted by alphabetic order)
#include <QtGui>
//
// OTB includes (sorted by alphabetic order)
......@@ -34,12 +35,18 @@
#include "mvdTypes.h"
//
// Class pre-declaration.
// Macros.
#define DECLARE_APP_SINGLETON( _type, _id ) class _type; static _type* _id;
#define IMPLEMENT_APP_SINGLETON( _id ) { assert( _id==NULL ); _id = this; }
//
// Class declaration.
// Class pre-declaration.
namespace mvd
{
//
// Class declaration.
/** \class I18nApplication
*
*/
......
......@@ -34,7 +34,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdTypes.h"
#include "ConfigureMonteverdi2.h"
//
// External classes pre-declaration.
......
......@@ -25,7 +25,10 @@
//
// Qt includes (sorted by alphabetic order)
//// Including QtGui here prevents conflicting with ITK at compile-time.
#if 0 // re-activate when compile-type errors appear.
#include <QtGui>
#endif
//
// ITK includes (sorted by alphabetic order)
......@@ -56,24 +59,46 @@ namespace mvd
/**
*/
typedef itk::ImageRegion< Monteverdi2_DIMENSION_TYPE >
TImageRegion2;
ImageRegionType;
/**
*/
typedef itk::Index< Monteverdi2_DIMENSION_TYPE >
IndexType;
/*******************************************************************************/
/**
*/
typedef otb::Image< Monteverdi2_FLOATING_TYPE, Monteverdi2_DIMENSION_TYPE >
TImage2f;
ScalarImageType;
/**
*/
typedef otb::ImageFileReader< TImage2f >
TImageFileReader2f;
typedef otb::ImageFileReader< ScalarImageType >
ScalarImageFileReaderType;
/*******************************************************************************/
/**
*/
typedef
otb::VectorImage< Monteverdi2_FLOATING_TYPE, Monteverdi2_DIMENSION_TYPE >
TVectorImage2f;
VectorImageType;
/**
*/
typedef otb::ImageFileReader< VectorImageType >
VectorImageFileReaderType;
/*******************************************************************************/
/**
*/
typedef otb::ImageFileReader< TVectorImage2f >
TVectorImageFileReader2f;
#if 1
typedef mvd::VectorImageType DefaultImageType;
typedef mvd::VectorImageFileReaderType DefaultImageFileReaderType;
#else
typedef mvd::ScalarImageType DefaultImageType;
typedef mvd::ScalarImageFileReaderType DefaultImageFileReaderType;
#endif
/*******************************************************************************/
......
......@@ -57,6 +57,28 @@ VectorImageModel
{
}
/*******************************************************************************/
void
VectorImageModel
::loadFile( const QString& filename )
{
#if 1
DefaultImageFileReaderType::Pointer imageFileReader(
DefaultImageFileReaderType::New()
);
imageFileReader->SetFileName( filename.toLatin1().data() );
imageFileReader->UpdateOutputInformation();
m_ImageFileReader = imageFileReader;
#else
m_ImageFileReader = DefaultImageFileReaderType::New();
m_ImageFileReader->SetFileName( filename.toLatin1().data() );
m_ImageFileReader->UpdateOutputInformation();
#endif
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -66,6 +66,25 @@ public:
/** Destructor */
virtual ~VectorImageModel();
/**
*/
inline
DefaultImageFileReaderType::OutputImageType*
GetOutput( int index )
{
return m_ImageFileReader->GetOutput( index );
}
inline
const DefaultImageFileReaderType::OutputImageType*
GetOutput( int index ) const
{
const_cast< const VectorImageModel* >( this )->GetOutput( index );
}
/**
*/
void loadFile( const QString& filename );
//
// SIGNALS.
signals:
......@@ -79,13 +98,17 @@ protected:
protected:
//
// Private methods.
// Private types.
private:
//
// Private methods.
private:
//
// Private attributes.
private:
DefaultImageFileReaderType::Pointer m_ImageFileReader;
//
// SLOTS.
......
......@@ -52,6 +52,6 @@
//
// Miscellaneous
#define Monteverdi2_FLOATING_TYPE @Monteverdi2_FLOATING_TYPE@
#define Monteverdi2_DIMENSION_TYPE 2
#define Monteverdi2_DIMENSION_TYPE int(2)
#endif // __ConfigureMonteverdi2_h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment