29 #ifndef _CASA_LINE_FINDING_UTILS_H_
30 #define _CASA_LINE_FINDING_UTILS_H_
60 template<
typename DataType>
62 DataType
const in_data[],
bool const in_mask[],
63 size_t const bin_size,
size_t const num_out,
64 DataType out_data[],
bool out_mask[],
65 size_t const offset = 0,
bool const keepsize =
false);
79 float const in_data[],
bool const in_mask[],
92 static_assert(static_cast<uint8_t>(
true)==1,
"cast of bool failed");
93 static_assert(static_cast<uint8_t>(
false)==0,
"cast of bool failed");
94 uint8_t
const *data8 =
reinterpret_cast<uint8_t
const *
>(
data);
95 static_assert(
sizeof(data[0])==
sizeof(data8[0]),
96 "bool and uint8_t has different size");
97 for (
size_t i = 0; i < num_data; ++i) {
116 float const in_data[],
bool const in_mask[],
117 float const threshold,
bool out_mask[]);
140 template<
typename DataType>
142 DataType
const in_data[], DataType
const threshold,
144 for (
size_t i = 0; i < num_data; ++i) {
162 template<
typename DataType>
164 DataType
const in_data[],
165 DataType
const threshold_array[],
167 for (
size_t i = 0; i < num_data; ++i) {
168 sign[i] =
signCompare(in_data[i], threshold_array[i]);
180 static void deBinRanges(
size_t const bin_size,
size_t const offset,
181 std::list<std::pair<size_t, size_t>>& range_list);
196 int8_t
const sign[],
bool const mask[],
197 std::list<std::pair<size_t, size_t>>& range_list);
208 template<
typename DataType>
210 DataType
const data[]) {
211 return (data[num_data / 2] + data[num_data / 2 - ((num_data + 1) % 2)])
212 /
static_cast<DataType
>(2);
227 bool const mask[],
float fraction = 1.0);
239 std::list<std::pair<size_t, size_t>>& out_range);
252 bool const mask[],
size_t const maxgap,
253 std::list<std::pair<size_t, size_t>>& range_list);
263 std::list<std::pair<size_t, size_t>>& range_list);
274 std::list<std::pair<size_t, size_t>>& from);
286 size_t const maxwidth,
287 std::list<std::pair<size_t, size_t>>& range_list);
296 std::list<std::pair<size_t, size_t>>& range_list);
305 std::list<std::pair<size_t, size_t>>& range_list);
312 std::ostringstream oss;
313 oss <<
"number of Lines = " << line_list.size() << std::endl;
314 for (std::list<std::pair<size_t,size_t>>::iterator iter = line_list.begin();
315 iter!=line_list.end(); ++iter) {
316 oss <<
"- [ " << (*iter).first <<
", " << (*iter).second <<
" ] (width: "
317 << (*iter).second-(*iter).first+1 <<
")" << std::endl;
327 std::list<std::pair<size_t, size_t>>& range_list,
328 std::pair<size_t, size_t>& new_range,
size_t const cursor = 0);
336 template<
typename DataType>
338 DataType
const& threshold) {
339 if (data > threshold)
341 else if (data < threshold)
static void extendRangeBySign(size_t num_sign, int8_t const sign[], bool const mask[], std::list< std::pair< size_t, size_t >> &range_list)
static void deBinRanges(size_t const bin_size, size_t const offset, std::list< std::pair< size_t, size_t >> &range_list)
static void createSignByThresholds(size_t const num_data, DataType const in_data[], DataType const threshold_array[], int8_t sign[])
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
static DataType getMedianOfSorted(size_t const num_data, DataType const data[])
static size_t countTrue(size_t num_data, bool const data[])
static void mergeOverlapInTwoLists(std::list< std::pair< size_t, size_t >> &to, std::list< std::pair< size_t, size_t >> &from)
LatticeExprNode ntrue(const LatticeExprNode &expr)
static size_t binDataAndMask(size_t const num_in, DataType const in_data[], bool const in_mask[], size_t const bin_size, size_t const num_out, DataType out_data[], bool out_mask[], size_t const offset=0, bool const keepsize=false)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
static void rejectNarrowRange(size_t const minwidth, std::list< std::pair< size_t, size_t >> &range_list)
static void mergeSmallGapByFraction(double const fraction, size_t const maxwidth, std::list< std::pair< size_t, size_t >> &range_list)
LatticeExprNode sign(const LatticeExprNode &expr)
static int8_t signCompare(DataType const &data, DataType const &threshold)
static void calculateMAD(size_t const num_data, float const in_data[], bool const in_mask[], float mad[])
static string FormatLineString(std::list< std::pair< size_t, size_t >> &line_list)
static void maskToRangesList(size_t const num_mask, bool const mask[], std::list< std::pair< size_t, size_t >> &out_range)
static void mergeOverlappingRanges(std::list< std::pair< size_t, size_t >> &range_list)
static void createSignByAThreshold(size_t const num_data, DataType const in_data[], DataType const threshold, int8_t sign[])
static void mergeGapByFalse(size_t const num_mask, bool const mask[], size_t const maxgap, std::list< std::pair< size_t, size_t >> &range_list)
static void rejectWideRange(size_t const maxwidth, std::list< std::pair< size_t, size_t >> &range_list)
static size_t mergeARangeToList(std::list< std::pair< size_t, size_t >> &range_list, std::pair< size_t, size_t > &new_range, size_t const cursor=0)
static float maskedMedian(size_t num_data, float const *data, bool const mask[], float fraction=1.0)
static void createMaskByAThreshold(size_t const num_data, float const in_data[], bool const in_mask[], float const threshold, bool out_mask[])