00001 //# LELArrayBase.h: Base class for LELArray holding the mask 00002 //# Copyright (C) 1999,2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef LATTICES_LELARRAYBASE_H 00029 #define LATTICES_LELARRAYBASE_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/casa/Arrays/Array.h> 00035 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 // <summary> 00040 // Base class for LELArray holding the mask. 00041 // </summary> 00042 00043 // <use visibility=local> 00044 00045 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00046 // </reviewed> 00047 00048 // <synopsis> 00049 // This LEL class holds an array with a mask. 00050 // The mask can be a single Bool valid for all elements of the array. 00051 // Otherwise it is a full mask with the same shape as the array. 00052 // </synopsis> 00053 00054 // <motivation> 00055 // It maskes it possible to handle an array with its mask as a single object. 00056 // </motivation> 00057 00058 // <todo asof="1998/01/20"> 00059 // </todo> 00060 00061 00062 class LELArrayBase 00063 { 00064 public: 00065 // Default constructor sets to mask all true. 00066 LELArrayBase() 00067 : itsMaskPtr(0) {} 00068 00069 // Constructor takes mask. 00070 LELArrayBase (const Array<Bool>& mask) 00071 : itsMaskPtr(new Array<Bool>(mask)) {} 00072 00073 // Copy constructor (reference semantics). 00074 LELArrayBase (const LELArrayBase& other); 00075 00076 ~LELArrayBase(); 00077 00078 // Assignment (reference semantics). 00079 LELArrayBase& operator= (const LELArrayBase& other); 00080 00081 // Does the value have a mask? 00082 Bool isMasked() const 00083 { return (itsMaskPtr != 0); } 00084 00085 // Get mask. 00086 // <group> 00087 const Array<Bool>& mask() const 00088 { return *itsMaskPtr; } 00089 Array<Bool>& mask() 00090 { return *itsMaskPtr; } 00091 // </group> 00092 00093 // Remove the mask. 00094 void removeMask(); 00095 00096 // Set the mask from given array (takes reference). 00097 void setMask (const Array<Bool>& other); 00098 00099 // Set the mask from the mask of the other value. 00100 void setMask (const LELArrayBase& other); 00101 00102 // Set the mask from given array (takes reference). 00103 void setMask (Array<Bool>& other); 00104 00105 // Set the mask by combining the masks of both values. 00106 void setMask (const LELArrayBase& left, const LELArrayBase& right) 00107 { setMask (left); combineMask (right); } 00108 00109 // Combine the mask of this and the other value (by anding them). 00110 // <group> 00111 void combineMask (const LELArrayBase& other) 00112 { if (other.isMasked()) combineMask (other.mask()); } 00113 void combineMask (const Array<Bool>& mask); 00114 // </group> 00115 00116 // Combine the mask with the given value in case of an OR or AND. 00117 // It means the mask is set to true if value is desiredValue 00118 // (which should be True for OR and False for AND). 00119 // <group> 00120 // Combine with a single scalar value for which the mask is false. 00121 void combineOrAnd (Bool desiredValue, const Array<Bool>& value); 00122 00123 // Combine for two arrays taking the true/false array values into account. 00124 // The mask and value are set to desiredValue if the temp value is desiredValue. 00125 void combineOrAnd (Bool desiredValue, Array<Bool>& value, 00126 const Array<Bool>& temp); 00127 00128 // Combine for two arrays taking the true/false array values and mask 00129 // into account. 00130 // The mask and value are set to desiredValue if the temp value is desiredValue 00131 // and its temp mask it true. 00132 // The mask is set to false if the temp mask is False. 00133 void combineOrAnd (Bool desiredValue, Array<Bool>& value, 00134 const Array<Bool>& temp, const Array<Bool>& tempMask); 00135 // </group> 00136 00137 private: 00138 Array<Bool>* itsMaskPtr; 00139 }; 00140 00141 00142 00143 } //# NAMESPACE CASACORE - END 00144 00145 #endif