27 #include "wcslib/wcs.h"
37 using namespace hippodraw;
50 m_x_limits ( -180.0, +180.0 ),
51 m_y_limits ( - 90.0, + 90.0 ),
62 double xlo,
double xhi,
63 double ylo,
double yhi) :
64 BinaryTransform ( z, is_periodic, needs_grid, needs_x_ticks, needs_y_ticks ),
65 m_x_limits ( xlo, xhi ),
66 m_y_limits ( ylo, yhi ),
75 m_x_limits( t.limitX() ),
76 m_y_limits( t.limitY() ),
77 m_x_offset( t.xOffset() ),
78 m_y_offset( t.yOffset() )
149 if ( x2 < -DBL_EPSILON )
154 if ( overshoot > DBL_EPSILON ) {
164 if ( x2 < -DBL_EPSILON )
169 if ( undershoot > DBL_EPSILON)
178 if ( y2 < -DBL_EPSILON )
return moduloSubY ( y1, -y2 );
182 if ( overshoot > DBL_EPSILON ) {
193 if ( y2 < -DBL_EPSILON )
return moduloAddY ( y1, -y2 );
197 if ( undershoot > DBL_EPSILON )
return m_y_limits.
high() - undershoot;
205 double x_lo = lat.
low ();
206 double x_hi = lat.
high ();
208 double y_lo = lon.
low ();
209 double y_hi = lon.
high ();
214 double x_max = -1000;
216 double y_max = -1000;
219 double dx = ( x_hi - x_lo ) / n;
220 double dy = ( y_hi - y_lo ) / n;
224 for (
int i = 0;
i <= n;
i++)
229 x_min = ( x_min < x ) ? x_min : x;
230 x_max = ( x_max > x ) ? x_max : x;
231 y_min = ( y_min < y ) ? y_min : y;
232 y_max = ( y_max > y ) ? y_max : y;
236 for (
int i = 0;
i <= n;
i++)
241 x_min = ( x_min < x ) ? x_min : x;
242 x_max = ( x_max > x ) ? x_max : x;
243 y_min = ( y_min < y ) ? y_min : y;
244 y_max = ( y_max > y ) ? y_max : y;
248 for (
int i = 0;
i <= n;
i++)
253 x_min = ( x_min < x ) ? x_min : x;
254 x_max = ( x_max > x ) ? x_max : x;
255 y_min = ( y_min < y ) ? y_min : y;
256 y_max = ( y_max > y ) ? y_max : y;
260 for (
int i = 0;
i <= n;
i++)
265 x_min = ( x_min < x ) ? x_min : x;
266 x_max = ( x_max > x ) ? x_max : x;
267 y_min = ( y_min < y ) ? y_min : y;
268 y_max = ( y_max > y ) ? y_max : y;
271 return Rect ( x_min, y_min, x_max - x_min, y_max - y_min );
287 const vector < AxisTick > &
313 return ( (
double)abs( x - y ) <= 2.0 * ( y * FLT_EPSILON + FLT_MIN ) );
320 double rangeLength = range.
length();
323 rangeLength *= scale_factor;
326 double rmag = floor( log10( rangeLength ) );
329 double scalelow = range.
low() * scale_factor;
330 double scalehigh = range.
high() * scale_factor;
333 double pmag = max( floor( log10( abs ( scalehigh ) ) ),
334 floor( log10( abs ( scalelow ) ) ) );
352 const vector < AxisTick > &
356 double y = 0.0, ylabel;
371 bool use_pmag = abs ( pmag ) > 3.0;
389 decimals =
static_cast<int>( pmag - rmag );
392 if( !decimals ) decimals++;
409 decimals =
static_cast<int>( abs( rmag ) );
420 sprintf( pstr,
"%%1.%df", decimals );
424 double range_high = range.
high();
425 range_high *= scale_factor;
427 while( y <= range_high ||
FLT_EQUAL( range_high, y ) )
434 else if ( axistype ==
Axes::Y ) {
441 if ( use_pmag ) ylabel = value / pow( 10.0, pmag );
444 value /= scale_factor;
445 sprintf( labl, pstr, ylabel );
449 if ( tick_step == 0.0 )
break;
473 initwcs(
const std::string &transformName,
double* crpix,
474 double* crval,
double* cdelt,
double crota2,
bool galactic)
478 assert(
sizeof(wcsprm)<=2000);
484 wcsini(1, naxis,
m_wcs);
488 lon_type = (galactic?
"GLON-" :
"RA---") + transformName,
489 lat_type = (galactic?
"GLAT-" :
"DEC--") + transformName;
490 strcpy(
m_wcs->ctype[0], lon_type.c_str() );
491 strcpy(
m_wcs->ctype[1], lat_type.c_str() );
493 for(
int i=0;
i<naxis; ++
i){
508 const std::string what
509 (
"HippoDraw has not been compiled with WCSLIB support" );
510 throw std::runtime_error ( what );
524 double imgcrd[2], pixcrd[2];
525 double phi[1], theta[1];
528 double worldcrd[] ={lon,lat};
531 wcss2p(
m_wcs, ncoords, nelem, worldcrd, phi, theta, imgcrd, pixcrd, stat);
551 double worldcrd[2], imgcrd[2];
552 double phi[1], theta[1];
555 double pixcrd[] = {lon,lat};
558 wcsp2s(
m_wcs, ncoords, nelem, pixcrd, imgcrd, phi, theta, worldcrd, stat);
562 if ( returncode == 8 )
return false;
580 std::vector< double > & lat )
const
584 assert ( lat.size() == lon.size() );
585 int size = lat.size();
588 vector < double > worldcrd ( 2*size );
589 for (
int i = 0;
i <
size;
i++ ) {
590 worldcrd[2*
i]= lon[
i];
591 worldcrd[2*
i+1]= lat[
i];
597 vector < double > pixcrd( 2*size );
598 vector < double > imgcrd( 2*size );
599 vector < double > phi( size );
600 vector < double > theta( size );
601 vector < int > stat ( size );
604 wcss2p (
m_wcs, ncoords, nelem, &worldcrd[0], &phi[0], &theta[0],
605 &imgcrd[0], &pixcrd[0], &stat[0] );
608 for (
int i = 0;
i <
size;
i++ ) {
610 lat[
i]=pixcrd[2*
i+1];
std::vector< AxisTick > m_ticks
The ticks last generated by this transform.
virtual void validate(Range &lat, Range &lon) const
Validates the Ranges.
double moduloAdd(double a1, double a2, hippodraw::Axes::Type axis) const
Modulo Addition along either X or Y axis.
Range m_x_limits
The limits on X axis of the transform.
void initwcs(const std::string &transformName, double *crpix, double *crval, double *cdelt, double crota2, bool galactic)
Initialize the WCS transform type.
virtual const Range & limitY() const
Returns the Range limits of the second coordinate.
double high() const
Returns the maximum of the range object.
A class to maintain tick coordinates and string values.
UnaryTransform class interface.
void setFirstTick(const double &first_tick)
Sets the value for first tick step.
double moduloAddX(double x1, double x2) const
Modulo Addition along X axis.
hippodrw::Rect class interface
double moduloAddY(double y1, double y2) const
Modulo Addition along Y axis.
hippodraw::PeriodicBinaryTransform class interface
double yOffset() const
Returns the yOffset of the (periodic) transform.
virtual void adjustValues(AxisModelBase &model, hippodraw::Axes::Type axes, const Range &limit)
Sets the range of given axis to be a new "nice" within the limits given.
double xOffset() const
Returns the xOffset of the (periodic) transform.
void setLow(double x)
Sets the minimum of the range object.
void setXOffset(double x_offset)
Sets the xOffset of the (periodic) transform.
virtual const Range & limitX() const
Returns the Range limits of the first coordinate.
virtual ~PeriodicBinaryTransform()
The virtual destructor.
Range m_y_limits
The limits on Y axis of the transform.
const std::vector< AxisTick > & genTicks(AxisModelBase &axis, hippodraw::Axes::Type axistype)
Generates the ticks in the axis.
void setHigh(double x)
Sets the maximum of the range object.
A Periodic transform that transforms coordinates from one 2D coordinate system to another...
double moduloSubY(double y1, double y2) const
Modulo Subtraction along Y axis.
virtual void transform(double &lon, double &lat) const
Transform the coordinates on the X and Y axes.
double FLT_EQUAL(double x, double y)
void setPMag(const double &pmag)
Sets the magnitude of the power of ten for the tick labels.
double moduloSub(double s1, double s2, hippodraw::Axes::Type axis) const
Modulo Subtraction along either X or Y axis.
intp size(numeric::array arr)
void throwWCSMissing() const
Throws an exception if WCSLIB support is missing.
The AxisModelBase class maintains the Range and scaling of an axis.
double length() const
Returns the length of the range object.
Class representing a rectangle.
double getScaleFactor() const
Returns the scale factor.
virtual const std::vector< AxisTick > & setTicks(AxisModelBase &axis_model, hippodraw::Axes::Type axis)
void setYOffset(double y_offset)
Sets the yOffset of the (periodic) transform.
hippodraw::AxisModelBase class interface
double getRMag() const
Sets the magnitude of the range.
double moduloSubX(double x1, double x2) const
Modulo Subtraction along X axis.
double getPMag() const
Returns the magnitude of the power of ten for the tick labels.
A transform that transforms coordinates from one 2D coordinate system to another. ...
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
A transform that transforms coordinates in one dimension from one coordinate system to another...
void setRMag(const double &rmag)
Sets the magnitude of the range.
double low() const
Returns the minimum of the range object.
virtual Rect calcRectangle(const Range &x, const Range &y)
Returns a rectangle enclosing the transformed data space.
void setTickStep(const double &t_step)
Sets the tick step.
Expresses a range of values.
PeriodicBinaryTransform()
The default constructor.
void setFirstTick(AxisModelBase &axis)
Sets the first tick on the axis.
void setTickStep(AxisModelBase &axis)
Helps to decide the tick size for the corresponding axis.
UnaryTransform * m_z
The transform on the Z axis.
virtual void setUsePMag(const bool &use_p_mag)
Use to set the value of the member variable m_use_pmag.
virtual bool inverseTransform(double &lon, double &lat) const
Transform the transformed coordinates on X and Y axis back to the original true data space...
double m_x_offset
The xoffset of this periodic transform.
double m_y_offset
The yoffset of this periodic transform.
double getFirstTick() const
Returns the value for the first tick step.
virtual bool isLinearInXY() const
Returns true if the transform would be one to one on both the X and Y axes.
double getTickStep() const
Returns the tick step in the true coordinate system.