Compacting CMake unit test macros into one macro using conditional statement - foreach

I want to reduce the CMake macro calls in my code below and compact it into one CMake macro call to execute my operation using an if-else statement.
I need to run ctest (using CMake) by passing different height and width parameters.
Please consider this as some arithmetic operations.
In my case, depending on width, my height ranges will change like this:
Width = 8 ,then height will be 8 16 24
Width = 16 ,then height will be 16 24
Width = 24 ,then height will be 24 32
So, is it possible to use some if-else statement in the CMake file to make a single call to EXECUTE_OPERATION(${width_val} ${height_val} )?
My current CMake file looks like this:
set(width 8)
set(size 8 16 24 )
foreach(size_val ${size}
foreach(width_val ${width})
EXECUTE_OPEARTION(${width_val} ${height_val} )
endforeach(width_val)
endforeach(size_val)
---------------------------
set(width 16)
set(height 16 24 )
foreach(height_val ${height}
foreach(width_val ${width})
EXECUTE_OPEARTION(${width_val} ${height_val} )
endforeach(width_val)
endforeach(size_val)
---------------------------
set(width 24)
set(size 24 32 )
foreach(size_val ${size}
foreach(width_val ${width})
EXECUTE_OPEARTION(${width_val} ${height_val} )
endforeach(width_val)
endforeach(size_val)
---------------------------
I tried to do this using the following, but it did not work:
set(width 8 16 24 )
if(width == 8)
set(height 8 16 24 )
elif(width == 16)
set(height 16 24 )
elif(width == 24)
set(height 24 32)
foreach(height_val ${height}
foreach(width_val ${width})
EXECUTE_OPEARTION(${width_val} ${height_val} )
endforeach(width_val)
endforeach(size_val)

Your if-statement seems to have Python syntax. You should use elseif instead of elif. Also, the CMake if-statement syntax to test for equality is EQUAL, not ==.
In addition, you need to move the if-statement block within the foreach() block in order for this to work. Try something like this:
# Define the width values to iterate through.
set(width 8 16 24)
# Iterate through each width value.
foreach(width_val ${width})
# Set the height values, based on the current width value.
if(${width_val} EQUAL 8)
set(height 8 16 24)
elseif(${width_val} EQUAL 16)
set(height 16 24)
elseif(${width_val} EQUAL 24)
set(height 24 32)
endif()
# Loop through each height value.
foreach(height_val ${height})
message("Calling EXECUTE_OPEARTION() with args: Width: ${width_val}, Height: ${height_val}")
EXECUTE_OPEARTION(${width_val} ${height_val})
endforeach(height_val)
endforeach(width_val)
This prints the following, verifying the function is called with the correct arguments:
Calling EXECUTE_OPEARTION() with args: Width: 8, Height: 8
Calling EXECUTE_OPEARTION() with args: Width: 8, Height: 16
Calling EXECUTE_OPEARTION() with args: Width: 8, Height: 24
Calling EXECUTE_OPEARTION() with args: Width: 16, Height: 16
Calling EXECUTE_OPEARTION() with args: Width: 16, Height: 24
Calling EXECUTE_OPEARTION() with args: Width: 24, Height: 24
Calling EXECUTE_OPEARTION() with args: Width: 24, Height: 32

Related

Prawn::Errors::CannotFit: Table's width was set too small to contain its contents

I am trying to create a table in Prawn using the following code however the columns widths do not suite well for me with columns width I have now. Given that I still have some free space, I want to expand a little bit the second and last columns so I increased both of them to 55.mm and 20.mm accordingly but I am getting an error
Prawn::Errors::CannotFit: Table's width was set too small to contain its contents (min width 450.70866141732284, requested 442).
Why does expanding a column width throws Tabe too small error?
I have calculated the total width of the columns:
9.mm + 45.mm + 20.mm + 20.mm + 20.mm + 30.mm + 15.mm + 20.mm #=> 507.40157480314963
I don't understand it. What am I doing wrong?
bounding_box [0, 792], width: 612, height: 792 do
bounding_box [30, 792], width: 442, height: 792 do
line_items_table
end
end
def line_items_table
table line_item_rows, table_options do
row(0).background_color = TABLE_BACKGROUND_COLOR
columns(2..-1).align = :right
end
end
def table_options
{
cell_style: { border_width: 0 },
column_widths: TABLE_COLUMN_WIDTHS,
header: true,
# width: 160.mm
}
end
def line_item_rows
[TABLE_HEADERS]
end
TABLE_COLUMN_WIDTHS = { 0 => 9.mm, 1 => 45.mm, 2 => 20.mm, 3 => 20.mm, 4 => 30.mm, 5 => 15.mm, 6 => 15.mm }.freeze
TABLE_HEADERS = [I18n.t('pdf.headers.row_num'), I18n.t('pdf.headers.name'),
I18n.t('pdf.headers.quantity'), I18n.t('pdf.headers.price_net_amount'), I18n.t('pdf.headers.net_amount'),
I18n.t('pdf.headers.vat'), I18n.t('pdf.headers.gross_amount')].freeze
#Table headers above are: 'No', 'Name', 'Qauntity', 'Net Sale', 'Net amount', 'Gross amount', 'VAT'
Table's width was set too small to contain its contents (min width 450.7, requested 442)
meaning your total column width must below 442, and your total currently is 450.7,
you should change it to below 442
you have line code that set 442
bounding_box [30, 792], width: 442, height: 792 do
if you want to set bigger then my suggestion you should change it first

What Linear Mapping Function

What linear mapping function is required to map a gray image from [30-200] to [0, 255]?
I have already done some work and this is what I have come up with, but I would like to know if it's the correct way to do it:
min : 30, want to map to 0
mid : 85, want to map to 128
max : 200, want to map to 255
if (i <= mid), M(i) = 127*(i - min)/(mid - min)
if (i > mid), M(i) = 128 + (255 - 128)*(i - mid - 1)/(max - mid - 1);
This appears to be correct to me because:
if i = 30, it should map to 0. Plugging the information in:
M(30) = 127*(30-30)/(85 - 30) = 0
If i = 85, it should map to 127:
M(85) = 127*(85 - 30) / (85 - 30) = 127
If i = 200, it should map to 200:
M(200) = 128 + (255 - 128)*(200 - 85 - 1)/(200 - 85 - 1) = 255
Thank you.
If you apply a linear mapping, the middle of the first interval will be automatically mapped to the middle of the second interval (you can see it as Thales principle). So you need to apply only one equation: y=a.x+b
To solve this equation you have two information: a.30+b=0, and
a.200+b=255.
Then you solve this and you obtain: a=1.5, and b=-45.
And be careful, the middle of [30, 200] is not 85 but 115 (=30+85).
Finally you can check, if you apply 1.5*x-45=y, you successfully obtain: 30->0, 200->255, and 115->127.5

C++ setw equivalent for Lua?

I'm trying to print out information in a form of a table where the spacing between never changes, kind of like setw from c++
You can use string.format(). Formatting reference is same as in ISO C's sprintf() and printf(). For quick reference you may use e.g. this website.
print(string.format("%10d%10d%10d", 114, 523, 15224))
will result in:
114 523 15224
Basically you can go with (for integers):
function printTable(t, length)
for _,row in pairs(t) do
local format = ""
for i=1,#row do format = format .. "%" .. length .. "d" end
print(string.format(format, table.unpack(row)))
end
end
It is not the most efficient way but it will do the work:
> S = {{432, 324, 5325, 4356}, {4325, 5643, 223, 543}, {234, 1, 23, 656}}
> printTable(S, 8)
432 324 5325 4356
4325 5643 223 543
234 1 23 656

Calculate the minimum and maximum in cvInRangeS

cvCvtColor(frame, hsv_frame, CV_BGR2HSV);
cvInRangeS(hsv_frame, hsv_min, hsv_max, thresholded);
I try to follow blue ball. To determine the maximum and minimum I open a picture I took with the camera, open it MS paint and doubles at (180/240) result out of me in H
And (255/240) the result of S and L
then i recive the next values:
108 113 115 112 105 H
145 40 107 129 143 S
97 129 96 102 124 L
So I chose the next values:
CvScalar hsv_min = cvScalar( 105, 40, 96 );
CvScalar hsv_max = cvScalar( 115, 140, 130);
But when I try to follow it hardly ever see him
Am I wrong calculation? or what can i do to improve the result?
First of all why do you convert your image to HSV and then talk about HSL? If I'm not mistaken they are different color spaces.
To determinate blue color using HSV color space use this range:
Min (H/S/V): 90, 50, 50
Max (H/S/V): 130, 255, 255
Also this online converter should help you.
And don't forget that Hue value after converting image to HSV using CV_BGR2HSV code is in range [0..180], while using CV_BGR2HSV_FULL will give you range [0..360].

problem with using statement in gnuplot

I'm trying to plot some data. I have a file looking like this
50 11 1 1
100 29 1 6
200 62 4 26
300 104 9 39
and a plotfile
# Vergleich
set terminal png
set output "streetsegments.png"
set datafile separator "\t"
set yrange [0:105]
set ytics ("0" 0, "10" 10, "20" 20, "30" 30, "40" 40, "50" 50, "75" 75, "100" 100)
set xtics ("50" 50, "100" 100, "200" 200,"300" 300)
set xrange [0:300]
set xlabel "Error in meters"
set ylabel "Street segments"
set notitle
plot "segments" using 1:2 t 'foo' with lp, \
"segments" u 1:3 t 'bar' with lp, \
"segments" u 1:4 t 'baz' with lp
But when plotting, it doesn't show anything besides the titles of the lines, but no lines themselves are drawn. Any idea, why this doesn't work?
When only plotting on column (by not using the "using"-statement ) it works just fine.
Works for me. Try again removing the set datafile separator "\t" line and see if that solves it.

Resources