OTB  6.7.0
Orfeo Toolbox
mvdAbstractImageModel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef mvdAbstractImageModel_h
23 #define mvdAbstractImageModel_h
24 
25 //
26 // Configuration include.
28 #include "ConfigureMonteverdi.h"
29 
30 #include "OTBMonteverdiCoreExport.h"
31 
32 /*****************************************************************************/
33 /* INCLUDE SECTION */
34 
35 //
36 // Qt includes (sorted by alphabetic order)
38 
39 //
40 // System includes (sorted by alphabetic order)
41 
42 //
43 // ITK includes (sorted by alphabetic order)
44 
45 //
46 // OTB includes (sorted by alphabetic order)
48 #include "otbImage.h" // Needed to get otb::internal::Get/SetSignedSpacing()
49 //
50 // Monteverdi includes (sorted by alphabetic order)
51 #include "mvdAbstractLayerModel.h"
52 #include "mvdImageProperties.h"
53 #include "mvdTypes.h"
54 
55 /*****************************************************************************/
56 /* PRE-DECLARATION SECTION */
57 
58 //
59 // External classes pre-declaration.
60 namespace
61 {
62 }
63 
64 namespace mvd
65 {
66 //
67 // Internal classes pre-declaration.
68 class HistogramModel;
69 class ImageProperties;
70 class QuicklookModel;
71 
72 
73 /*****************************************************************************/
74 /* CLASS DEFINITION SECTION */
75 
80 class OTBMonteverdiCore_EXPORT AbstractImageModel :
81  public AbstractLayerModel
82 {
83 
84  /*-[ QOBJECT SECTION ]-----------------------------------------------------*/
85 
86  Q_OBJECT;
87 
88  /*-[ PUBLIC SECTION ]------------------------------------------------------*/
89 
90 //
91 // Public types.
92 public:
98  class BuildContext
99  {
100  //
101  // Public methods.
102  public:
103 
110  class BuildContext
111  {
112  //
113  // Public methods.
114  public:
115  BuildContext() :
116  m_Id( -1 ),
117  m_Filename(),
118  m_Quicklook(),
119  m_Histogram(),
120  m_Settings( NULL ),
121  m_Properties( NULL ),
122  m_IsBeingStored( false )
123  {
124  }
125 
127  BuildContext( const QString& filename ) :
128  m_Id( -1 ),
129  m_Filename( filename ),
130  m_Quicklook(),
131  m_Histogram(),
132  m_Settings( NULL ),
133  m_Properties( NULL ),
134  m_IsBeingStored( true )
135  {
136  assert( !filename.isEmpty() );
137  }
138 
140  BuildContext( void* const settings,
141  ImageProperties* const properties ) :
142  m_Id( -1 ),
143  m_Filename(),
144  m_Quicklook(),
145  m_Histogram(),
146  m_Settings( settings ),
147  m_Properties( properties ),
148  m_IsBeingStored( false )
149  {
150  }
151 
154  inline bool IsBeingStored() const
155  {
156  return m_IsBeingStored;
157  }
158 
159  //
160  // Public attributes
161  public:
162  int m_Id;
163  QString m_Filename;
164  QString m_Quicklook;
165  QString m_Histogram;
166  void * const m_Settings;
167  ImageProperties * const m_Properties;
168 
169  private:
170  bool m_IsBeingStored;
171 
172  };
173 
174 //
175 // Public methods.
176 public:
177 
179  ~AbstractImageModel() override;
180 
182  inline int GetId() const;
183 
187  inline const ImageProperties* GetProperties() const;
188 
192  inline ImageProperties* GetProperties();
193 
199  inline void SetProperties( const ImageProperties& properties );
200 
202  const QuicklookModel* GetQuicklookModel() const;
203 
205  QuicklookModel* GetQuicklookModel();
206 
208  inline const HistogramModel* GetHistogramModel() const;
209 
211  inline HistogramModel* GetHistogramModel();
212 
216  virtual ImageBaseType::ConstPointer ToImageBase() const =0;
217 
221  virtual ImageBaseType::Pointer ToImageBase() =0;
222 
226  inline const ImageRegionType& GetLodLargestRegion() const;
227 
232  inline const ImageRegionType& GetNativeLargestRegion() const;
233 
238  inline const SpacingType& GetNativeSpacing() const;
239 
244  inline const SpacingType& GetEstimatedGroundSpacing() const;
245 
247  inline CountType GetNbComponents() const;
248 
251  QStringList GetBandNames( bool enhanced =false ) const;
252 
256  virtual CountType GetNbLod() const =0;
257 
262  inline void SetCurrentLod( CountType lod );
263 
267  inline CountType GetCurrentLod() const;
268 
271  inline const SpacingType GetSpacing() const;
272 
275  inline const PointType& GetOrigin() const;
276 
279  inline PointType GetCenter() const;
280 
281 //
282 // Public SLOTS.
283 public slots:
284 
288  inline void RefreshHistogram();
289 
290  /*-[ SIGNALS SECTION ]-----------------------------------------------------*/
291 
292 //
293 // Signals.
294 signals:
296  void SpacingChanged( const SpacingType& );
297 
298  /*-[ PROTECTED SECTION ]---------------------------------------------------*/
299 
300 //
301 // Protected methods.
302 protected:
303 
305  AbstractImageModel( QObject* p =NULL );
306 
312  inline void SetProperties( ImageProperties* properties );
313 
319  void RefreshHistogram( void* const context );
320 
323  inline
325  GetMetaDataInterface() const;
326 
327  //
328  // AbstractModel methods.
329 
330  void virtual_BuildModel( void* context ) override;
331 
332 //
333 // Protected attributes.
334 protected:
335 
340  ImageRegionType m_NativeLargestRegion;
341 
346  SpacingType m_NativeSpacing;
347 
352  SpacingType m_EstimatedGroundSpacing;
353 
354  /*-[ PRIVATE SECTION ]-----------------------------------------------------*/
355 
356 //
357 // Private methods.
358 private:
359 
362  virtual void virtual_SetCurrentLod( CountType lod ) =0;
363 
371  virtual void virtual_RefreshHistogram() {};
372 
373 //
374 // Private attributes.
375 private:
378  int m_Id;
379 
382  CountType m_CurrentLod;
383 
386  ImageProperties* m_Properties;
387 
388  /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
389 
390 //
391 // Slots.
392 private slots:
393 };
394 
395 } // end namespace 'mvd'
396 
397 /*****************************************************************************/
398 /* INLINE SECTION */
399 
400 //
401 // ITK includes (sorted by alphabetic order)
402 
403 //
404 // OTB includes (sorted by alphabetic order)
405 
406 //
407 // Monteverdi includes (sorted by alphabetic order)
408 #include "mvdHistogramModel.h"
409 
410 namespace mvd
411 {
412 
413 /*****************************************************************************/
414 int
415 AbstractImageModel
416 ::GetId() const
417 {
418  return m_Id;
419 }
420 
421 /*****************************************************************************/
422 inline
423 const ImageProperties*
424 AbstractImageModel
425 ::GetProperties() const
426 {
427  return m_Properties;
428 }
429 
430 /*****************************************************************************/
431 inline
432 ImageProperties*
433 AbstractImageModel
434 ::GetProperties()
435 {
436  return m_Properties;
437 }
438 
439 /*****************************************************************************/
440 inline
441 void
442 AbstractImageModel
443 ::SetProperties( const ImageProperties& properties )
444 {
445  assert( m_Properties!=NULL );
446 
447  *m_Properties = properties;
448 }
449 
450 /*****************************************************************************/
451 const HistogramModel*
452 AbstractImageModel
453 ::GetHistogramModel() const
454 {
455  return findChild< const HistogramModel* >();
456 }
457 
458 /*****************************************************************************/
459 HistogramModel*
460 AbstractImageModel
461 ::GetHistogramModel()
462 {
463  return findChild< HistogramModel* >();
464 }
465 
466 /*****************************************************************************/
467 CountType
468 AbstractImageModel
469 ::GetCurrentLod() const
470 {
471  return m_CurrentLod;
472 }
473 
475 void
476 AbstractImageModel
477 ::SetCurrentLod( CountType lod )
478 {
479  assert( lod<GetNbLod() );
480  virtual_SetCurrentLod( lod );
482 
483  m_CurrentLod = lod;
484 
485  // if everything ok emit the new spacing of the current lod
486  emit SpacingChanged( otb::internal::GetSignedSpacing(
487  static_cast< ImageBaseType * > ( ToImageBase() ) ) );
488 }
489 
490 /*****************************************************************************/
491 inline
492 const ImageRegionType&
493 AbstractImageModel
494 ::GetLodLargestRegion() const
495 {
496  return ToImageBase()->GetLargestPossibleRegion();
497 }
498 
499 /*****************************************************************************/
500 inline
501 const ImageRegionType&
502 AbstractImageModel
503 ::GetNativeLargestRegion() const
504 {
505  return m_NativeLargestRegion;
506 }
507 
508 /*****************************************************************************/
509 inline
510 const SpacingType&
511 AbstractImageModel
512 ::GetNativeSpacing() const
513 {
514  return m_NativeSpacing;
515 }
516 
517 
518 /*****************************************************************************/
519 inline
520 const SpacingType&
521 AbstractImageModel
522 ::GetEstimatedGroundSpacing() const
523 {
524  return m_EstimatedGroundSpacing;
525 }
526 
527 /*****************************************************************************/
528 inline
529 CountType
530 AbstractImageModel
531 ::GetNbComponents() const
532 {
533  return ToImageBase()->GetNumberOfComponentsPerPixel();
534 }
535 
536 /*****************************************************************************/
537 inline
539 AbstractImageModel
540 ::GetMetaDataInterface() const
541 {
542  return otb::ConstCast< const otb::ImageMetadataInterfaceBase >(
544  ToImageBase()->GetMetaDataDictionary()
545  )
546  );
547 }
548 
549 /*****************************************************************************/
550 inline
551 const PointType&
552 AbstractImageModel
553 ::GetOrigin() const
554 {
555  assert( !ToImageBase().IsNull() );
556 
557  return ToImageBase()->GetOrigin();
558 }
559 
560 /*****************************************************************************/
561 inline
562 const SpacingType
563 AbstractImageModel
564 ::GetSpacing() const
565 {
566  assert( !ToImageBase().IsNull() );
567 
569  static_cast< ImageBaseType const * >( ToImageBase() ) );
570 }
571 
573 inline
574 PointType
575 AbstractImageModel
576 ::GetCenter() const
577 {
578  PointType center( GetOrigin() );
579  SpacingType spacing( GetSpacing() );
580  SizeType size( GetNativeLargestRegion().GetSize() );
582 
583  center[ 0 ] += 0.5 * spacing[ 0 ] * static_cast< double >( size[ 0 ] );
584  center[ 1 ] += 0.5 * spacing[ 1 ] * static_cast< double >( size[ 1 ] );
585 
586  return center;
587 }
588 
589 /*****************************************************************************/
590 inline
591 void
592 AbstractImageModel
593 ::RefreshHistogram()
594 {
595  virtual_RefreshHistogram();
596 }
597 
598 /*****************************************************************************/
599 inline
600 void
601 AbstractImageModel
602 ::SetProperties( ImageProperties* properties )
603 {
604  if( m_Properties==properties )
605  return;
606 
607  delete m_Properties;
608 
609  m_Properties = properties;
610 }
611 
612 } // end namespace 'mvd'
613 
614 #endif // mvdAbstractImageModel_h
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
static ImageMetadataInterfaceBasePointerType CreateIMI(const MetaDataDictionaryType &dict)
unsigned int CountType
Definition: mvdTypes.h:80
itk::ImageRegion< Monteverdi_DIMENSION > ImageRegionType
Definition: mvdTypes.h:129
ImageType::SpacingType GetSignedSpacing(const ImageType *input)
Definition: otbImage.h:41
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
VectorImageType::SpacingType SpacingType
Definition: mvdTypes.h:181
VectorImageType::PointType PointType
Definition: mvdTypes.h:189