source: trunk/src/Cubes/invertCube.cc @ 1207

Last change on this file since 1207 was 1207, checked in by MatthewWhiting, 11 years ago

Simplifying the inversion step, by devolving the detection-related commands to Detection, and putting it all in the one Cube::invert() call.

File size: 2.6 KB
Line 
1// -----------------------------------------------------------------------
2// invertCube.cc: Multiply the flux of a Cube by -1.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <duchamp/Cubes/cubes.hh>
29#include <duchamp/Detection/detection.hh>
30
31namespace duchamp
32{
33
34  void Cube::invert()
35  {
36    /// @details A function that multiplies all non-Blank pixels by
37    ///  -1.  This is used when searching for negative features. This
38    ///  only has an effect when the main array has been allocated.
39
40    if(this->arrayAllocated){
41      for(size_t i=0; i<this->numPixels; i++)
42        if(!this->isBlank(i)){
43          this->array[i] *= -1.;
44          if(this->reconExists) this->recon[i] *= -1.;
45        }
46    }
47    std::vector<Detection>::iterator obj;
48    for(obj=this->objectList->begin(); obj<this->objectList->end(); obj++)
49        obj->invert();
50
51  }
52
53  void Cube::reInvert()
54  {
55    /// @details A function that switches the array back to the
56    ///  original sign by calling Cube::invert(). It also inverts the
57    ///  fluxes in all the detected objects.  This is used when
58    ///  searching for negative features.
59   
60    this->invert();
61
62    std::vector<Detection>::iterator obj;
63    for(obj=this->objectList->begin(); obj<this->objectList->end(); obj++){
64      obj->setNegative(true);
65      obj->setTotalFlux(-1. * obj->getTotalFlux() );
66      obj->setIntegFlux(-1. * obj->getIntegFlux() );
67      obj->setPeakFlux(-1. * obj->getPeakFlux() );
68    }
69
70  }
71
72}
Note: See TracBrowser for help on using the repository browser.