otbGlView.h 18.2 KB
Newer Older
1
/*=========================================================================
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  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.

=========================================================================*/
Julien Michel's avatar
INIT  
Julien Michel committed
18
19
20
#ifndef otb_GlView_h
#define otb_GlView_h

21
22

#include "otbGeoInterface.h"
Julien Michel's avatar
INIT  
Julien Michel committed
23
#include "otbGlActor.h"
24
#include "otbViewSettings.h"
Julien Michel's avatar
INIT  
Julien Michel committed
25
26
27

#include <map>
#include <vector>
28
#include <cassert>
29

Julien Michel's avatar
INIT  
Julien Michel committed
30
31
32
namespace otb
{

33
34
35
36
37
38
39
template< typename T >
void
assert_quiet_NaN( T val )
{
  assert( !std::numeric_limits< T >::has_quiet_NaN ||
	  ( std::numeric_limits< T >::has_quiet_NaN &&
	    val!=std::numeric_limits< T >::quiet_NaN() ) );
40
41
  // make production build happy
  ((void)val);
42
43
44
45
46
47
48
49
50
}

template< typename T >
void
assert_signaling_NaN( T val )
{
  assert( !std::numeric_limits< T >::has_signaling_NaN ||
	  ( std::numeric_limits< T >::has_signaling_NaN &&
	    val!=std::numeric_limits< T >::signaling_NaN() ) );
51
52
  // make production build happy
  ((void)val);
53
54
55
56
57
58
59
60
}

template< typename T >
void
assert_NaN( T val )
{
  assert_quiet_NaN( val );
  assert_signaling_NaN( val );
61
62
  // make production build happy
  ((void)val);
63
64
}

65
66
67
68
69
70
71
72
73
74
75
76
77
/** 
 * The GlView class acts like an OpenGl scene where actors deriving
 * from the GlActor class can be rendered. The GlView class contains the
 * OpenGl viewport and manages:
 * - The size of the viewport,
 * - The entire refresh loop, including light or heavy rendering of
 * all actors and all OpenGl specific stuff needed before and after
 * the actors update,
 * - The actors stack (order in which actors are rendered).
 * 
 * All parameters related to scene description (origin, spacing, angle
 * ...) are stored and managed by the ViewSettings class.
 */
Julien Michel's avatar
INIT  
Julien Michel committed
78
79
80
81
82
83
84
85
86
87
88
89
90
class GlView 
  : public itk::Object
{
public:
  typedef GlView                                          Self;
  typedef itk::Object                                     Superclass;
  typedef itk::SmartPointer<Self>                         Pointer;
  typedef itk::SmartPointer<const Self>                   ConstPointer;

  typedef otb::GlActor                                    ActorType;
  typedef std::map<std::string,ActorType::Pointer>        ActorMapType;
  typedef std::vector<std::string>                        StringVectorType;

91
92
93
94
95
  /**
   * Type definition for otb::GlActor storage key.
   */
  typedef StringVectorType::value_type KeyType;

Julien Michel's avatar
INIT  
Julien Michel committed
96
97
  itkNewMacro(Self);

98
99
100
101
102
103
  /**
   * The Intialize method will reset the OpenGl viewport to the given
   * size, clear view settings and remove any existing actor.
   * \param sx Width of the viewport
   * \param sy Height of the viewport
   */ 
Julien Michel's avatar
INIT  
Julien Michel committed
104
105
  void Initialize(unsigned int sx, unsigned int sy);

106
107
108
109
110
111
112
113
114
115
116
117
  /**
   * This method allows to add a new actor (deriving from GlActor) to
   * the GlView. The actor can be identified by an optional key. If
   * not provided, and the default value is used, the method will
   * generate a key to identify the actor. In both case, the key is
   * returned by the method.  
   * \param actor The actor to be added
   * \param key The key to be used to identify the actor (default to
   * empty string)
   * \return The key identifying the actor (either passed to the
   * method or generated by it).
   */
Julien Michel's avatar
INIT  
Julien Michel committed
118
119
  std::string AddActor(ActorType * actor, const std::string & key = "");

120
121
122
123
124
125
126
  /** 
   * This method will try to remove the actor identified by the given
   * key.
   * \param key The key identifying the actor to remove
   * \return True if the actor has been found and removed, false
   * otherwise
   */
127
128
  bool RemoveActor(const std::string & key);

129
130
131
  /**
   * This method will remove all existing actors at once.
   */
Julien Michel's avatar
INIT  
Julien Michel committed
132
133
  void ClearActors();

134
135
136
137
138
139
140
  /**
   * This method allows to retrieve a pointer to the actor identified
   * by the given key.
   * \param key The key identifying the actor to retrieve
   * \return A pointer to the retrieved actor. This pointer will be
   * null if no actor could be found with this key.
   */  
141
  ActorType::Pointer GetActor(const std::string & key) const;
Julien Michel's avatar
INIT  
Julien Michel committed
142

143
144
145
146
147
148
149
150
151
  /**
   * Tells wether an otb::GlActor is contained given its storage key.
   *
   * @param key otb::GlActor storage key.
   *
   * @return true if an otb::GlActor is contained given storage key.
   */
  bool ContainsActor( const KeyType & key ) const;

152
153
154
155
156
  /**
   * This method will return a vector containing the keys of all
   * actors.
   * \return A vector of string containing the keys of all actors.
   */ 
157
158
  std::vector<std::string> GetActorsKeys() const;

159
160
161
162
  /**
   * This method handles all the things that should be done before
   * rendering.
   */
Julien Michel's avatar
INIT  
Julien Michel committed
163
164
  void BeforeRendering();

165
166
167
168
  /**
   * This method handles all the things that should be after before
   * rendering.
   */
Julien Michel's avatar
INIT  
Julien Michel committed
169
170
  void AfterRendering();

171
172
173
174
175
176
  /**
   * This method will update the rendering of the OpenGl viewport,
   * taking into account all parameters in the ViewSettings, without
   * fetching any missing data from disk or RAM. It is therefore very
   * fast.
   */
Julien Michel's avatar
INIT  
Julien Michel committed
177
178
  void LightRender();

179
180
181
182
183
184
  /**
   * This method will update the rendering of the OpenGl viewport,
   * taking into account all parameters in the ViewSettings, but will
   * first compute and load any missing data for a complete
   * rendering. As such, this update routine can be time consuming.
   */
Julien Michel's avatar
INIT  
Julien Michel committed
185
186
187
188
189
190
191
192
193
  void HeavyRender();

  // Resize viewport
  void Resize(unsigned int sx, unsigned int sy);

  itkSetObjectMacro(Settings,ViewSettings);
  itkGetObjectMacro(Settings,ViewSettings);
  itkGetConstObjectMacro(Settings,ViewSettings);

194
195
  //comment this macro (not compiling with OTB 3.X)
  // Get Rendering order
196
197
  const StringVectorType & GetRenderingOrder() const
  {
198
    return m_RenderingOrder;
199
200
201
  };

  /**
202
203
   * Arbitrary set the rendering order of some or all of contained
   * otb::GlActor instances.
204
205
206
207
   *
   * Keys which are not contained will be ignored.
   *
   * @param keys The ordered sequence of keys.
208
209
   * @param front <code>true</code> to order selected otb::GlActor
   *              instances in front of non-selected ones.
210
   */
211
212
  void SetRenderingOrder( const StringVectorType & keys,
                          bool front );
Julien Michel's avatar
Julien Michel committed
213

214
215
216
217
218
219
  // This will rotate the rendering order (without modifying the order)
  void RotateRenderingOrder(bool down = false);

  // Move actor in rendering order
  void MoveActorInRenderingOrder(std::string key, bool down = false);

220
221
222
223
  // Move actor to the end of rendering order (either front if front
  // is set to true or back if front is set to false)
  void MoveActorToEndOfRenderingOrder(std::string key, bool front = false);

224
  /**
225
226
   * Reproject point and spacing expressed in viewport coordinate
   * system into given actor coordinate system.
227
228
   */
  template< typename P, typename S, typename P2, typename S2 >
229
230
231
232
233
234
  bool ReprojectFromView( P & center,
			  S & spacing,
			  const KeyType & key,
			  const P2 & vcenter,
			  const S2 & vspacing,
			  double norm = 1000.0 ) const;
235

236
237
238
  /**
   */
  template< typename P >
239
  bool GetExtent( P & origin, P & extent, bool isOverlay =false ) const;
240
241
242
243

  /**
   */
  template< typename Point, typename Spacing >
244
245
246
  bool ZoomToExtent( const Spacing & native,
		     Point & center,
		     Spacing & spacing ) const;
247
248
249
250

  /**
   */
  template< typename Point, typename Spacing >
251
252
253
254
  bool ZoomToLayer( const KeyType & key,
		    const Spacing & native,
		    Point & center,
		    Spacing & spacing ) const;
255

256
257
258
259
260
  /**
   */
  template< typename Point, typename Spacing >
  bool ZoomToRegion( const Point & origin,
		     const Point & extent,
261
		     const Spacing & native,
262
263
264
		     Point & center,
		     Spacing & spacing ) const;

265
266
267
268
269
270
271
  /**
   */
  template< typename Point, typename Spacing >
  bool ZoomToFull( const KeyType & key,
		   Point & center,
		   Spacing & spacing,
		   double units = 1000.0 ) const;
272

273
274
275
276
  /**
   */
  void SaveScreenshot( const std::string & filename ) const;

Julien Michel's avatar
INIT  
Julien Michel committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
protected:
  GlView();

  virtual ~GlView();

private:
  // prevent implementation
  GlView(const Self&);
  void operator=(const Self&);

  ViewSettings::Pointer m_Settings;

  ActorMapType          m_Actors;

  StringVectorType      m_RenderingOrder;

}; // End class GlView

295
296
297
298

template< typename P, typename S, typename P2, typename S2 >
bool
GlView
299
300
301
302
303
304
::ReprojectFromView( P & center,
		     S & spacing,
		     const KeyType & key,
		     const P2 & vcenter,
		     const S2 & vspacing,
		     double norm ) const
305
{
306
  // std::cout << "otb::GlView@" << std::hex << this << std::endl << "{" << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
307

308
309
310
311
312
313
314
  assert_NaN( vcenter[ 0 ] );
  assert_NaN( vcenter[ 1 ] );

  assert_NaN( vspacing[ 0 ] );
  assert_NaN( vspacing[ 1 ] );


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
  //
  // Reference actor has not been found.
  otb::GlActor::Pointer actor( GetActor( key ) );

  if( actor.IsNull() )
    return false;


  //
  // Reference actor does not implement geo-interface.
  const otb::GeoInterface * geo =
    dynamic_cast< const GeoInterface * >( actor.GetPointer() );

  if( geo==NULL )
    return false;


  //
  // Compute transform origin.
334
  if( !geo->TransformFromViewport( center, vcenter, true ) )
335
336
337
338
339
340
341
342
    return false;

  //
  // Compute transformed X-axis extremity.
  GeoInterface::Point2d x( vcenter );

  x[ 0 ] += norm * vspacing[ 0 ]; 

343
  // std::cout << "X {" << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
344

345
346
347
  if( !geo->TransformFromViewport( x, x, true ) )
    return false;

348
  // std::cout << "x: " << x[ 0 ] << ", " << x[ 1 ] << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
349

350
351
  // assert_NaN( x[ 0 ] );
  // assert_NaN( x[ 1 ] );
Stéphane Albert's avatar
Stéphane Albert committed
352

353
  // std::cout << "}" << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
354

355
356
357
358
359
360
  //
  // Compute transformed Y-axis extremity.
  GeoInterface::Point2d y( vcenter );

  y[ 1 ] += norm * vspacing[ 1 ];

361
  // std::cout << "Y {" << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
362

363
364
365
  if( !geo->TransformFromViewport( y, y, true ) )
    return false; 

366
  // std::cout << "y: " << y[ 0 ] << ", " << y[ 1 ] << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
367

368
369
  // assert_NaN( y[ 0 ] );
  // assert_NaN( y[ 1 ] );
Stéphane Albert's avatar
Stéphane Albert committed
370

371
  // std::cout << "}" << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
372

373
374
375
376
377
378
379
380
381
  //
  // Compute transformed spacing.
  //
  // Note SAT:
  //     Formula has been taken from IceViewer::key_callback(). I think
  // that the norm of the transformed X and Y axises is not
  // the new spacing if transform contains a rotation.
  //     To correct this, transformed X and Y vectors should be
  // projected against reference actor X and Y axises (using vectorial
382
  // dot product).
383

384
385
  x[ 0 ] -= center[ 0 ];
  x[ 1 ] -= center[ 1 ];
386

387
388
  y[ 0 ] -= center[ 0 ];
  y[ 1 ] -= center[ 1 ];
389
390
391
392

  spacing[ 0 ] = vcl_sqrt( x[ 0 ] * x[ 0 ] + x[ 1 ] * x[ 1 ] ) / norm;
  spacing[ 1 ] = vcl_sqrt( y[ 0 ] * y[ 0 ] + y[ 1 ] * y[ 1 ] ) / norm;

393
394
395
396
397
398
399
400
401
  // Sign of x-spacing is done by sign( x . (1, 0) ) which is sign( x[ 0 ] )
  // Sign of y-spacing is done by sign( y . (0, 1) ) which is sign[ y[ 1 ] )

  if( x[ 0 ]<0.0 )
    spacing[ 0 ] = -spacing[ 0 ];

  if( y[ 1 ]<0.0 )
    spacing[ 1 ] = -spacing[ 1 ];

402
403
404
405
406
407
408
409
  //
  // Chech outputs.
  assert_NaN( center[ 0 ] );
  assert_NaN( center[ 1 ] );

  assert_NaN( spacing[ 0 ] );
  assert_NaN( spacing[ 1 ] );

410
  // std::cout << "} otb::GlView@" << std::hex << this << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
411

412
413
  //
  // Ok.
414
415
416
  return true;
}

417
418

template< typename P >
419
bool
420
GlView
421
::GetExtent( P & origin, P & extent, bool isOverlay ) const
422
423
424
{
  if( m_Actors.empty() )
    {
Stéphane Albert's avatar
Stéphane Albert committed
425
426
    origin.Fill( 0 );
    extent.Fill( 0 );
427

428
    return false;
429
430
431
432
433
434
435
436
437
438
439
440
441
    }


  origin[ 0 ] = std::numeric_limits< typename P::ValueType >::infinity();
  origin[ 1 ] = std::numeric_limits< typename P::ValueType >::infinity();

  extent[ 0 ] = -std::numeric_limits< typename P::ValueType >::infinity();
  extent[ 1 ] = -std::numeric_limits< typename P::ValueType >::infinity();

  for( ActorMapType::const_iterator it( m_Actors.begin() );
       it!=m_Actors.end();
       ++it )
    {
442
    assert( !it->second.IsNull() );
443

444
445
446
447
    if( it->second->GetOverlay()==isOverlay )
      {
      P o;
      P e;
Stéphane Albert's avatar
Stéphane Albert committed
448

449
450
      o.Fill( 0 );
      e.Fill( 0 );
451

452
      it->second->GetExtent( o[ 0 ], o[ 1 ], e[ 0 ], e[ 1 ] );
453

454

455
456
      if( o[ 0 ]<origin[ 0 ] )
	origin[ 0 ] = o[ 0 ];
457

458
459
      if( o[ 1 ]<origin[ 1 ] )
	origin[ 1 ] = o[ 1 ];
460

461
462
      if( o[ 0 ]>extent[ 0 ] )
	extent[ 0 ] = o[ 0 ];
463

464
465
      if( o[ 1 ]>extent[ 1 ] )
	extent[ 1 ] = o[ 1 ];
466
467


468
469
      if( e[ 0 ]<origin[ 0 ] )
	origin[ 0 ] = e[ 0 ];
470

471
472
      if( e[ 1 ]<origin[ 1 ] )
	origin[ 1 ] = e[ 1 ];
473

474
475
      if( e[ 0 ]>extent[ 0 ] )
	extent[ 0 ] = e[ 0 ];
476

477
478
479
      if( e[ 1 ]>extent[ 1 ] )
	extent[ 1 ] = e[ 1 ];
      }
480
    }
481
482
483
484
485
486
487
488

  return true;
}


template< typename Point, typename Spacing >
bool
GlView
489
::ZoomToExtent( const Spacing & native, Point & center, Spacing & spacing ) const
490
491
492
493
{
  Point o;
  Point e;

Stéphane Albert's avatar
Stéphane Albert committed
494
495
496
  o.Fill( 0 );
  e.Fill( 0 );

497
498
499
500
  // Get origin and extent of all layers in viewport system.
  if( !GetExtent( o, e ) )
    return false;

501
502
503
  // std::cout << "origin: [ " << o[ 0 ] << ", " << o[ 1 ] << " ]" << std::endl;
  // std::cout << "extent: [ " << e[ 0 ] << ", " << e[ 1 ] << " ]" << std::endl;

504
  // Zoom to overall region.
505
  return ZoomToRegion( o, e, native, center, spacing );
506
507
508
509
510
511
}


template< typename Point, typename Spacing >
bool
GlView
512
513
514
515
::ZoomToLayer( const KeyType & key,
	       const Spacing & native,
	       Point & center,
	       Spacing & spacing ) const
516
517
518
519
{
  Point o;
  Point e;

520
  // Get layer actor.
521
  GlActor::Pointer actor( GetActor( key ) );
522
523
524
525

  // If not found...
  if( actor.IsNull() )
    return false;
526
527
528
529

  // Get origin and extent of layer.
  actor->GetExtent( o[ 0 ], o[ 1 ], e[ 0 ], e[ 1 ] );

530
  // Zoom layer region.
531
  return ZoomToRegion( o, e, native, center, spacing );
532
533
534
535
536
537
538
539
}


template< typename Point, typename Spacing >
bool
GlView
::ZoomToRegion( const Point & origin,
		const Point & extent,
540
		const Spacing & native,
541
542
543
		Point & center,
		Spacing & spacing ) const
{
544
545
546
547
548
549
550
  // std::cout
  //   << std::hex << this << std::dec
  //   << "::ZoomToRegion( "
  //   << "[ " << origin[ 0 ] << ", " << origin[ 1 ] << "], "
  //   << "[ " << extent[ 0 ] << ", " << extent[ 1 ] << "], "
  //   << "[ " << native[ 0 ] << ", " << native[ 1 ] << "] )"
  //   << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
551

552
  // Compute center point.
553
  center.SetToMidPoint( origin, extent );
554

555
  // std::cout << "-> center: " << center[ 0 ] << ", " << center[ 1 ] << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
556

557
558
  // Get scale of (o, e) in viewport.
  assert( !m_Settings.IsNull() );
559
  double scale = m_Settings->GetScale( origin, extent, true );
560

561
  // std::cout << "-> scale: " << scale << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
562

563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
  /*
  assert( !std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() ||
	  ( std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() &&
	    native[ 0 ]!=std::numeric_limits< typename Spacing::ValueType >::quiet_NaN()
	  )
  );
  assert( !std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() ||
	  ( std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() &&
	  native[ 1 ]!=std::numeric_limits< typename Spacing::ValueType >::quiet_NaN()
	  )
  );

  assert( !std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() ||
	  ( std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() &&
	    native[ 0 ]!=std::numeric_limits< typename Spacing::ValueType >::quiet_NaN()
	  )
  );
  assert( !std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() ||
	  ( std::numeric_limits< typename Spacing::ValueType >::has_quiet_NaN() &&
	  native[ 1 ]!=std::numeric_limits< typename Spacing::ValueType >::quiet_NaN()
	  )
  );
  */

587
  // Apply signed scale.
588
589
  spacing[ 0 ] = ( native[ 0 ]<0.0 ? -1 : +1 ) * scale;
  spacing[ 1 ] = ( native[ 1 ]<0.0 ? -1 : +1 ) * scale;
590

591
  // std::cout << "-> spacing: " << spacing[ 0 ] << ", " << spacing[ 1 ] << std::endl;
Stéphane Albert's avatar
Stéphane Albert committed
592

593
594
595
596
597
598
599
600
  // Ok.
  return true;
}


template< typename Point, typename Spacing >
bool
GlView
601
602
603
604
::ZoomToFull( const KeyType & key,
	      Point & center,
	      Spacing & spacing,
	      double units ) const
605
{
606
607
608
609
610
  // std::cout
  //   << std::hex << this << std::dec
  //   << "::ZoomToFull();"
  //   << std::endl;

611
  // Get layer actor.
612
  GlActor::Pointer actor( GetActor( key ) );
613
614
615
616

  // If not found...
  if( actor.IsNull() )
    return false;
617
618

  // Get geo-interface.
619
620
  const GeoInterface * geo =
    dynamic_cast< const GeoInterface * >( actor.GetPointer() );
621
622
623
624
625
626
627
628
629
630

  if( geo==NULL )
    return false;

  // Get viewport current center and spacing.
  assert( !m_Settings.IsNull() );

  center = m_Settings->GetViewportCenter();
  spacing = m_Settings->GetSpacing();

631
632
  // std::cout << "-> spacing: " << spacing[ 0 ] << ", " << spacing[ 1 ] << std::endl;

633
634
635
  // Get native spacing.
  GeoInterface::Spacing2 n_spacing( geo->GetSpacing() );

636
  // std::cout << "-> n_spacing: " << n_spacing[ 0 ] << ", " << n_spacing[ 1 ] << std::endl;
637
638

  // Transform center point to image space.
639
640
  Point o;

641
  if( !geo->TransformFromViewport( o, center, true ) )
642
643
    return false;

644
  //
645
646
647
648
649
650
651
  // Consider arbitrary point on the X-axis.
  Point e;

  e[ 0 ] = center[ 0 ] + units * spacing[ 0 ];
  e[ 1 ] = center[ 1 ];

  // Transform considered point.
652
  if( !geo->TransformFromViewport( e, e, true ) )
653
654
655
656
657
658
659
    return false;

  // Compute extent vector.
  e[ 0 ] -= o[ 0 ];
  e[ 1 ] -= o[ 1 ];

  // Apply extent vector length to view spacing.
660
661
662
  //
  // MANTIS-1178: Lenght of vector e must be divided by native
  // spacing.
663
664
665
  //
  // MANTIS-1203: absolute value of native spacing should be
  // considered (to avoid flipping effects).
666
  spacing[ 0 ] =
667
    vcl_abs( n_spacing[ 0 ] ) * units * spacing[ 0 ] /
668
    vcl_sqrt( e[ 0 ] * e[ 0 ] + e[ 1 ] * e[ 1 ] );
669

670
  //
671
672
673
674
675
  // Consider arbitrary point on the Y-axis.
  e[ 0 ] = center[ 0 ];
  e[ 1 ] = center[ 1 ] + units * spacing[ 1 ];

  // Transform considered point.
676
  if( !geo->TransformFromViewport( e, e, true ) )
677
678
679
680
681
682
683
    return false;

  // Compute extent vector.
  e[ 0 ] -= o[ 0 ];
  e[ 1 ] -= o[ 1 ];

  // Apply extent vector length to view spacing.
684
685
686
  //
  // MANTIS-1178: Lenght of vector e must be divided by native
  // spacing.
687
688
689
  //
  // MANTIS-1203: absolute value of native spacing should be
  // considered (to avoid flipping effects).
690
  spacing[ 1 ] =
691
    vcl_abs( n_spacing[ 1 ] ) * units * spacing[ 1 ] /
692
    vcl_sqrt( e[ 0 ] * e[ 0 ] + e[ 1 ] * e[ 1 ] );
693

694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
  // std::cout << "-> spacing: " << spacing[ 0 ] << ", " << spacing[ 1 ] << std::endl;

  //
  // Compute aspect-ratio corrected spacing (smallest pixel is chosen
  // as 1:1 reference).
  //
  // MANTIS-1202
  // {
  if( vcl_abs( spacing[ 0 ] ) < vcl_abs( spacing[ 1 ] ) )
    spacing[ 1 ] = spacing[ 0 ];
  else
    spacing[ 0 ] = spacing[ 1 ];
  // }
  // MANTIS-1202

  // std::cout << "-> spacing: " << spacing[ 0 ] << ", " << spacing[ 1 ] << std::endl;

711
  //
712
713
  // Ok.
  return true;
714
715
}

Julien Michel's avatar
INIT  
Julien Michel committed
716
717
718
} // End namespace otb

#endif