1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkGeoSphereTransform.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16   Copyright 2008 Sandia Corporation.
17   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18   the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20 
21 #include "vtkGeoSphereTransform.h"
22 
23 #include "vtkDoubleArray.h"
24 #include "vtkGeoMath.h"
25 #include "vtkGlobeSource.h"
26 #include "vtkMath.h"
27 #include "vtkObjectFactory.h"
28 #include "vtkPoints.h"
29 
30 vtkStandardNewMacro(vtkGeoSphereTransform);
31 
vtkGeoSphereTransform()32 vtkGeoSphereTransform::vtkGeoSphereTransform()
33 {
34   this->ToRectangular = true;
35   this->BaseAltitude = 0.0;
36 }
37 
~vtkGeoSphereTransform()38 vtkGeoSphereTransform::~vtkGeoSphereTransform()
39 {
40 }
41 
PrintSelf(ostream & os,vtkIndent indent)42 void vtkGeoSphereTransform::PrintSelf( ostream& os, vtkIndent indent )
43 {
44   this->Superclass::PrintSelf(os, indent);
45   os << indent << "ToRectangular: " << this->ToRectangular << endl;
46   os << indent << "BaseAltitude: " << this->BaseAltitude << endl;
47 }
48 
Inverse()49 void vtkGeoSphereTransform::Inverse()
50 {
51   this->ToRectangular = !this->ToRectangular;
52   this->Modified();
53 }
54 
InternalTransformPoint(const float in[3],float out[3])55 void vtkGeoSphereTransform::InternalTransformPoint( const float in[3], float out[3] )
56 {
57   double ind[3];
58   double oud[3];
59   int i;
60   for ( i = 0; i < 3; ++ i )
61     ind[i] = in[i];
62   this->InternalTransformPoint( ind, oud );
63   for ( i = 0; i < 3; ++ i )
64     out[i] = static_cast<float>(oud[i]);
65 }
66 
InternalTransformPoint(const double in[3],double out[3])67 void vtkGeoSphereTransform::InternalTransformPoint( const double in[3], double out[3] )
68 {
69   if ( this->ToRectangular )
70     {
71     vtkGlobeSource::ComputeGlobePoint(
72       in[0], in[1], vtkGeoMath::EarthRadiusMeters() + in[2] + this->BaseAltitude, out);
73     }
74   else
75     {
76     vtkGlobeSource::ComputeLatitudeLongitude(const_cast<double*>(in), out[0], out[1]);
77     out[2] = vtkMath::Norm(in) - vtkGeoMath::EarthRadiusMeters() - this->BaseAltitude;
78     }
79 }
80 
InternalTransformDerivative(const float in[3],float out[3],float derivative[3][3])81 void vtkGeoSphereTransform::InternalTransformDerivative( const float in[3], float out[3], float derivative[3][3] )
82 {
83   double ind[3];
84   double oud[3];
85   double drd[3][3];
86   int i;
87   for ( i = 0; i < 3; ++ i )
88     ind[i] = in[i];
89   this->InternalTransformDerivative( ind, oud, drd );
90   for ( i = 0; i < 3; ++ i )
91     {
92     out[i] = static_cast<float>(oud[i]);
93     for ( int j = 0; j < 3; ++ j )
94       {
95       derivative[i][j] = drd[i][j];
96       }
97     }
98 }
99 
InternalTransformDerivative(const double in[3],double out[3],double derivative[3][3])100 void vtkGeoSphereTransform::InternalTransformDerivative( const double in[3], double out[3], double derivative[3][3] )
101 {
102   // FIXME: Compute derivatives here
103   (void) in;
104   (void) out;
105   (void) derivative;
106 }
107 
108 
MakeTransform()109 vtkAbstractTransform* vtkGeoSphereTransform::MakeTransform()
110 {
111   vtkGeoSphereTransform* geoTrans = vtkGeoSphereTransform::New();
112   return geoTrans;
113 }
114 
115