Changeset 2719 for trunk/src/PlotHelper.cpp
- Timestamp:
- 01/09/13 18:16:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PlotHelper.cpp
r2718 r2719 15 15 #include <casa/Quanta/Quantum.h> 16 16 #include <casa/Quanta/QuantumHolder.h> 17 #include <casa/Quanta/MVAngle.h> 17 18 #include <casa/Logging/LogIO.h> 18 19 … … 33 34 namespace asap { 34 35 35 PlotHelper::PlotHelper() : dircoord_ (0)36 PlotHelper::PlotHelper() : dircoord_p(0) 36 37 { 37 38 #ifdef KS_DEBUG … … 40 41 }; 41 42 42 PlotHelper::PlotHelper( const ScantableWrapper &s) : dircoord_ (0)43 PlotHelper::PlotHelper( const ScantableWrapper &s) : dircoord_p(0) 43 44 { 44 45 #ifdef KS_DEBUG … … 52 53 cout << "Called PlotHelper destructor" << endl; 53 54 #endif 54 if (dircoord_ ){55 #ifdef KS_DEBUG 56 cout << "Destructing dircoord_ " << endl;57 #endif 58 delete dircoord_ ;59 dircoord_ = 0;55 if (dircoord_p){ 56 #ifdef KS_DEBUG 57 cout << "Destructing dircoord_p" << endl; 58 #endif 59 delete dircoord_p; 60 dircoord_p = 0; 60 61 } 61 62 }; … … 132 133 throw(AipsError("ny should be > 0")); 133 134 // Destroy old coord 134 if (dircoord_ ){135 #ifdef KS_DEBUG 136 cout << "Destructing dircoord_" << endl;137 #endif 138 delete dircoord_ ;139 dircoord_ = 0;135 if (dircoord_p){ 136 #ifdef KS_DEBUG 137 cout << "Destructing old dircoord_p" << endl; 138 #endif 139 delete dircoord_p; 140 dircoord_p = 0; 140 141 } 141 142 … … 227 228 if (!MDirection::getType(mdt,sepoch)) 228 229 throw AipsError("Invalid direction reference in center"); 229 if (stset && (mdt != stdt)) 230 throw AipsError("Direction reference of center should be the same as input scantable"); 230 if (stset){ 231 if ( !needst && 232 !MDirection::getType( stdt, data_p->getDirectionRefString() ) ) 233 throw AipsError("Failed to get direction reference from scantable."); 234 if (mdt != stdt) 235 throw AipsError("Direction reference of center should be the same as input scantable"); 236 } 231 237 QuantumHolder qh ; 232 238 String err ; … … 288 294 os << "Spacing: ( " << abs(incx) << " rad , " << abs(incy) << " rad )" <<endl; 289 295 290 Matrix<Double> xform(2,2) ; 291 xform = 0.0 ; 292 xform.diagonal() = 1.0 ; 293 dircoord_ = new DirectionCoordinate(mdt, projtype, 294 centx, centy, incx, incy, 295 xform, 296 0.5*Double(nx), 297 0.5*Double(ny)) ; // pixel at center 298 {//Summary 299 os << "Successfully generated grid coordinate:" << LogIO::POST; 300 Vector<String> units = dircoord_->worldAxisUnits(); 301 Vector<Double> refv = dircoord_->referenceValue(); 302 os <<"- Reference Direction : " << MDirection::showType(dircoord_->directionType()) 303 << " " << refv[0] << units[0] << " " << refv[1] << units[1] << LogIO::POST; 304 Vector<Double> refpix = dircoord_->referencePixel(); 305 os <<"- Reference Pixel : [" << refpix[0] << ", " << refpix[1] << "]" << LogIO::POST; 306 Vector<Double> inc = dircoord_->increment(); 307 os <<"- Increments : [" << inc[0] << ", " << inc[1] << "]" << LogIO::POST; 308 os <<"- Projection Type : " << dircoord_->projection().name() << LogIO::POST; 309 } 296 setupCoord(mdt, projtype, centx, centy, incx, incy, 297 0.5*Double(nx), 0.5*Double(ny)) ; // pixel at center) 298 310 299 }; 311 300 … … 321 310 throw(AipsError("ny should be > 0")); 322 311 // Destroy old coord 323 if (dircoord_ ){324 #ifdef KS_DEBUG 325 cout << "Destructing dircoord_" << endl;326 #endif 327 delete dircoord_ ;328 dircoord_ = 0;312 if (dircoord_p){ 313 #ifdef KS_DEBUG 314 cout << "Destructing old dircoord_p" << endl; 315 #endif 316 delete dircoord_p; 317 dircoord_p = 0; 329 318 } 330 319 … … 339 328 Projection::Type projType(Projection::type(String(projname))); 340 329 330 setupCoord(mdt, projType, centX, centY, incX, incY, 331 0.5*Double(nx), 0.5*Double(ny)) ; // pixel at center 332 // 0.5*Double(nx-1), 0.5*Double(ny-1)) ; // pixel at grid 333 334 }; 335 336 337 void PlotHelper::setupCoord(const MDirection::Types mdt, 338 const Projection::Type pjt, 339 const Double centx, const Double centy, 340 const Double incx, const Double incy, 341 const Double refx, const Double refy) 342 { 343 LogIO os(LogOrigin("PlotHelper","setupCoord()", WHERE)); 344 // Destroy old coord 345 if (dircoord_p){ 346 #ifdef KS_DEBUG 347 cout << "Destructing old dircoord_p" << endl; 348 #endif 349 delete dircoord_p; 350 dircoord_p = 0; 351 } 352 341 353 Matrix<Double> xform(2,2) ; 342 354 xform = 0.0 ; 343 355 xform.diagonal() = 1.0 ; 344 dircoord_ = new DirectionCoordinate(mdt, projType, 345 centX, centY, incX, incY, 346 xform, 347 0.5*Double(nx), 348 0.5*Double(ny)) ; // pixel at center 349 // 0.5*Double(nx-1), 350 // 0.5*Double(ny-1)) ; // pixel at grid 356 dircoord_p = new DirectionCoordinate(mdt, pjt, centx, centy, incx, incy, 357 xform, refx, refy); 351 358 {//Summary 352 359 os << "Successfully generated grid coordinate:" << LogIO::POST; 353 Vector<String> units = dircoord_->worldAxisUnits(); 354 Vector<Double> refv = dircoord_->referenceValue(); 355 os <<"- Reference Direction : " << MDirection::showType(dircoord_->directionType()) 356 << " " << refv[0] << units[0] << " " << refv[1] << units[1] << LogIO::POST; 357 Vector<Double> refpix = dircoord_->referencePixel(); 360 Vector<String> units = dircoord_p->worldAxisUnits(); 361 Vector<Double> refv = dircoord_p->referenceValue(); 362 os <<"- Reference Direction : " 363 << MDirection::showType(dircoord_p->directionType()) 364 << " " << refv[0] << units[0] << " " << refv[1] << units[1] << LogIO::POST; 365 Vector<Double> refpix = dircoord_p->referencePixel(); 358 366 os <<"- Reference Pixel : [" << refpix[0] << ", " << refpix[1] << "]" << LogIO::POST; 359 Vector<Double> inc = dircoord_ ->increment();367 Vector<Double> inc = dircoord_p->increment(); 360 368 os <<"- Increments : [" << inc[0] << ", " << inc[1] << "]" << LogIO::POST; 361 os <<"- Projection Type : " << dircoord_->projection().name() << LogIO::POST; 362 } 363 }; 364 365 vector<double> PlotHelper::getGridPixel(const int whichrow){ 369 os <<"- Projection Type : " << dircoord_p->projection().name() << LogIO::POST; 370 } 371 }; 372 373 vector<double> PlotHelper::getGridPixel(const int whichrow) 374 { 366 375 if (data_p->nrow() < 1) 367 376 throw AipsError("Scantable is not set. Could not get direction."); 368 377 else if (whichrow > int(data_p->nrow()) - 1) 369 378 throw AipsError("Row index out of range."); 370 if (!dircoord_ )379 if (!dircoord_p) 371 380 throw AipsError("Direction coordinate is not defined."); 372 381 … … 378 387 cout << "searching pixel position (world = " << data_p->getDirectionString(whichrow) << " = [" << world.getAngle("rad").getValue()[0] << ", " << world.getAngle("rad").getValue()[1] << "])" << endl; 379 388 #endif 380 dircoord_ ->toPixel(pixel, world);389 dircoord_p->toPixel(pixel, world); 381 390 #ifdef KS_DEBUG 382 391 cout << "got pixel = [" << pixel[0] << ", " << pixel[1] << "]" << endl; … … 387 396 }; 388 397 398 string PlotHelper::getGridRef() 399 { 400 if (!dircoord_p) 401 throw AipsError("Direction coordinate is not defined. Please set it first."); 402 403 string outref; 404 405 Vector<String> units = dircoord_p->worldAxisUnits(); 406 Vector<Double> refv = dircoord_p->referenceValue(); 407 MVAngle lon( Quantum<Double>(refv[0], units[0]) ); 408 MVAngle lat ( Quantum<Double>(refv[1], units[1]) ); 409 outref = MDirection::showType(dircoord_p->directionType()) + " " 410 + lon(0.0).string(MVAngle::TIME, 9) + " " 411 + lat.string(MVAngle::ANGLE+MVAngle::DIG2, 9); 412 413 return outref; 414 }; 415 416 vector<double> PlotHelper::getGridCellVal() 417 { 418 if (!dircoord_p) 419 throw AipsError("Direction coordinate is not defined. Please set it first."); 420 421 vector<double> outinc(2); 422 Vector<Double> inc = dircoord_p->increment(); 423 Vector<String> units = dircoord_p->worldAxisUnits(); 424 MVAngle qincx( Quantum<Double>(inc[0], units[0]) ); 425 MVAngle qincy( Quantum<Double>(inc[1], units[1]) ); 426 outinc[0] = (double) abs(qincx.radian()); 427 outinc[1] = (double) abs(qincy.radian()); 428 429 return outinc; 430 }; 431 432 389 433 } //namespace asap
Note: See TracChangeset
for help on using the changeset viewer.