PDA

View Full Version : Java to Pascal Conversion



BenLand100
03-28-2006, 02:02 AM
Everyone knows the java conditional statement:

Condition ? True_Value : False_Value
So what is the best way to represent this in pascal? If possible a one line thing would be perfect. ;)

masquerader
03-28-2006, 03:03 AM
ah, no, i dont think so :(

if(condition)then
result:=value
else
result:=value

BenLand100
03-28-2006, 03:28 AM
Ouch for me :( ...

if (f6 * f7 <= (float) 0 ? Math.abs(f6) >= Math.abs(f7) ? (f5 = Math.abs(f6 * f12)) >= Math.abs(f7 * f18 - (f6 + f7) * f16) && f5 > Math.abs(f7 * f19 - (f6 + f7) * f15) : (f5 = Math.abs(f7 * f12)) >= Math.abs(f6 * f18 - (f7 + f6) * f13) && f5 > Math.abs(f6 * f19 - (f7 + f6) * f14) : Math.abs(f6) >= Math.abs(f7) ? (f5 = Math.abs(f6 * f12)) >= Math.abs(f7 * f20 + (f6 - f7) * f16) && f5 > Math.abs(f7 * f17 + (f6 - f7) * f15) : (f5 = Math.abs(f7 * f12)) >= Math.abs(f6 * f20 + (f7 - f6) * f14) && f5 > Math.abs(f6 * f17 + (f7 - f6) * f13)) {

I remember first post=p
03-28-2006, 05:03 AM
Wow, let the powers of Mr. Math be renowned!

Pwnd
03-28-2006, 06:48 AM
Ben, I hate you.

moparisthebest
03-28-2006, 07:16 AM
Ben, I hate you.

dont emo people hate everyone? :p :D

<3 pwnd :)

Flyboy
03-28-2006, 08:01 AM
Ouch for me :( ...

if (f6 * f7 <= (float) 0 ? Math.abs(f6) >= Math.abs(f7) ? (f5 = Math.abs(f6 * f12)) >= Math.abs(f7 * f18 - (f6 + f7) * f16) && f5 > Math.abs(f7 * f19 - (f6 + f7) * f15) : (f5 = Math.abs(f7 * f12)) >= Math.abs(f6 * f18 - (f7 + f6) * f13) && f5 > Math.abs(f6 * f19 - (f7 + f6) * f14) : Math.abs(f6) >= Math.abs(f7) ? (f5 = Math.abs(f6 * f12)) >= Math.abs(f7 * f20 + (f6 - f7) * f16) && f5 > Math.abs(f7 * f17 + (f6 - f7) * f15) : (f5 = Math.abs(f7 * f12)) >= Math.abs(f6 * f20 + (f7 - f6) * f14) && f5 > Math.abs(f6 * f17 + (f7 - f6) * f13)) {

rofl

some days I can't tell if he is just messing with us or if that formula makes sense :rolleyes:

Pwnd
03-28-2006, 06:44 PM
dont emo people hate everyone? :p :D

<3 pwnd :)
No, just people that are good at math and thier girlfriend basically lives with them.

masquerader
03-28-2006, 09:38 PM
lol, i did make something that might work though:

function cond(bool:boolean; truevalue,falsevalue:integer):integer;
begin
if(bool)then
result:=truevalue
else
result:=falsevalue;
end;
you could put whatever greater than/less than statement in for bool and it should work:

a:=cond(2+2=4,1,0)

that line looks mucho complicated though :p

Bebe
03-29-2006, 12:17 AM
Ben, you should just keep it as Java (I know what your doing, and it would take forever to convert to pascal ;)). Just make a Scar--->Java interaction; If possible.

Also, all I could find was a Pascal to Java converter. :)

XxKanexX
03-29-2006, 02:58 AM
Ben, you should just keep it as Java (I know what your doing, and it would take forever to convert to pascal ;)). Just make a Scar--->Java interaction; If possible.

Also, all I could find was a Pascal to Java converter. :)
So if Ben eventually does convert it he can convert it back. :D

<3

BenLand100
03-29-2006, 03:09 AM
Lol, you guys think that's complicated you should see the part that actualy gets the gradiant map and thresholds the image ;) (I'm working on computer vision stuff (canny algorithm now ;)))

Bebe
03-29-2006, 03:25 AM
You showed me what your doing...... was amazing :p

BenLand100
03-29-2006, 04:17 PM
Ok. If anyone is up to a challenge i need this converted as without this method no pascal edge detection :(

private void canny_core(float scale, int gaussianWidth) {
boolean flag = false;
boolean flag1 = false;
derivative_mag = new int[picsize];
float gausValues1[] = new float[gaussianWidth];
float gausValues2[] = new float[gaussianWidth];
float gausValues3[] = new float[gaussianWidth];
data = image2pixels(sourceImage);
int curGausIndex = 0;
do {
if (curGausIndex >= gaussianWidth)
break;
float curGausPt = gaussian(curGausIndex, scale);
if (curGausPt <= 0.005F && curGausIndex >= 2)
break;
float gausVal1 = gaussian((float) curGausIndex - 0.5F, scale);
float gausVal2 = gaussian((float) curGausIndex + 0.5F, scale);
float gausVal3 = gaussian(curGausIndex, scale * 0.5F);
gausValues1[curGausIndex] = (curGausPt + gausVal1 + gausVal2) / 3F / (6.283185F * scale * scale);
gausValues2[curGausIndex] = gausVal2 - gausVal1;
gausValues3[curGausIndex] = 1.6F * gausVal3 - curGausPt;
curGausIndex++;
} while (true);
int gausEndIndex = curGausIndex;
float gaussValuesX[] = new float[picsize];
float gaussValuesY[] = new float[picsize];
int xGausEndIndex = width - (gausEndIndex - 1);
int yGausStartIndex = width * (gausEndIndex - 1);
int yGausEndIndex = width * (height - (gausEndIndex - 1));
for (int xScan = gausEndIndex - 1; xScan < xGausEndIndex; xScan++) {
for (int yScan = yGausStartIndex; yScan < yGausEndIndex; yScan += width) {
int curIndex = xScan + yScan;
float curPixelValueX = (float) data[curIndex] * gausValues1[0];
float curPixelValueY = curPixelValueX;
int gaussCounter = 1;
int rowCounter = curIndex - width;
for (int yCounter = curIndex + width; gaussCounter < gausEndIndex; yCounter += width) {
curPixelValueX += gausValues1[gaussCounter] * (float) (data[rowCounter] + data[yCounter]);
curPixelValueY += gausValues1[gaussCounter] * (float) (data[curIndex - gaussCounter] + data[curIndex + gaussCounter]);
gaussCounter++;
rowCounter -= width;
}
gaussValuesX[curIndex] = curPixelValueX;
gaussValuesY[curIndex] = curPixelValueY;
}
}

float xMags[] = new float[picsize];
for (int xScan = gausEndIndex - 1; xScan < xGausEndIndex; xScan++) {
for (int yScan = yGausStartIndex; yScan < yGausEndIndex; yScan += width) {
float curMag = 0.0F;
int curIndex = xScan + yScan;
for (int xMagScan = 1; xMagScan < gausEndIndex; xMagScan++)
curMag += gausValues2[xMagScan] * (gaussValuesX[curIndex - xMagScan] - gaussValuesX[curIndex + xMagScan]);

xMags[curIndex] = curMag;
}

}

gaussValuesX = null;
float yMags[] = new float[picsize];
for (int xScan = curGausIndex; xScan < width - curGausIndex; xScan++) {
for (int yScan = yGausStartIndex; yScan < yGausEndIndex; yScan += width) {
float curMag = 0.0F;
int curIndex = xScan + yScan;
int yCount = 1;
for (int yMagScan = width; yCount < gausEndIndex; yMagScan += width) {
curMag += gausValues2[yCount] * (gaussValuesY[curIndex - yMagScan] - gaussValuesY[curIndex + yMagScan]);
yCount++;
}

yMags[curIndex] = curMag;
}

}

gaussValuesY = null;
xGausEndIndex = width - gausEndIndex;
yGausStartIndex = width * gausEndIndex;
yGausEndIndex = width * (height - gausEndIndex);
for (int xScan = gausEndIndex; xScan < xGausEndIndex; xScan++) {
for (int yScan = yGausStartIndex; yScan < yGausEndIndex; yScan += width) {
int curIndex = xScan + yScan;
int tC = curIndex - width;
int bC = curIndex + width;
int cL = curIndex - 1;
int cR = curIndex + 1;
int tL = tC - 1;
int tR = tC + 1;
int bL = bC - 1;
int bR = bC + 1;
float xMag = xMags[curIndex];
float yMag = yMags[curIndex];
float avgCC = hypotenuse(xMag, yMag);
int k = (int) ((double) avgCC * 20D);
derivative_mag[curIndex] = k >= 256 ? 255 : k;
float avgTC = hypotenuse(xMags[tC], yMags[tC]);
float avgBC = hypotenuse(xMags[bC], yMags[bC]);
float avgCL = hypotenuse(xMags[cL], yMags[cL]);
float avgCR = hypotenuse(xMags[cR], yMags[cR]);
float avgTR = hypotenuse(xMags[tR], yMags[tR]);
float avgBR = hypotenuse(xMags[bR], yMags[bR]);
float avgBL = hypotenuse(xMags[bL], yMags[bL]);
float avgTL = hypotenuse(xMags[tL], yMags[tL]);
float f5;
if (xMag * yMag <= (float) 0 ? Math.abs(xMag) >= Math.abs(yMag) ? (f5 = Math.abs(xMag * avgCC)) >= Math.abs(yMag * avgTR - (xMag + yMag) * avgCR) && f5 > Math.abs(yMag * avgBL - (xMag + yMag) * avgCL) : (f5 = Math.abs(yMag * avgCC)) >= Math.abs(xMag * avgTR - (yMag + xMag) * avgTC) && f5 > Math.abs(xMag * avgBL - (yMag + xMag) * avgBC) : Math.abs(xMag) >= Math.abs(yMag) ? (f5 = Math.abs(xMag * avgCC)) >= Math.abs(yMag * avgBR + (xMag - yMag) * avgCR) && f5 > Math.abs(yMag * avgTL + (xMag - yMag) * avgCL) : (f5 = Math.abs(yMag * avgCC)) >= Math.abs(xMag * avgBR + (yMag - xMag) * avgBC) && f5 > Math.abs(xMag * avgTL + (yMag - xMag) * avgTC)) {
magnitude[curIndex] = derivative_mag[curIndex];
orientation[curIndex] = (int) (Math.atan2(yMag, xMag) * (double) 40F);
}
}
}

derivative_mag = null;
xMags = null;
yMags = null;
}

Krazy_Meerkat
03-29-2006, 07:50 PM
If I knew what some of those commands did I would offer some help :p
At least hypotenuse won't be that hard to do.

BenLand100
03-29-2006, 09:13 PM
If I knew what some of those commands did I would offer some help :p
At least hypotenuse won't be that hard to do.

I can do everything but that last bit ;)

phantombmx
03-29-2006, 09:39 PM
..........

good luck on that ben..:rolleyes: i wouldnt know what to do even if a monkey jumped outa my butt

BenLand100
03-30-2006, 01:24 AM
lol, i did make something that might work though:

function cond(bool:boolean; truevalue,falsevalue:integer):integer;
begin
if(bool)then
result:=truevalue
else
result:=falsevalue;
end; you could put whatever greater than/less than statement in for bool and it should work:

a:=cond(2+2=4,1,0)

that line looks mucho complicated though :p If you look closely the values my conditionals return are boolean ;)

function Cond(Condition: boolean; True_Value, False_Value: boolean): boolean;
begin
case Condition of
true: result:= True_Value;
false: result:= False_Value;
end;
end; So, my huge If-Then statement will be:

if Cond(xMag * yMag <= 0.0,
Cond(Abs(xMag) >= Abs(yMag),
(xMagAvg >= Abs(yMag * avgTR - (xMag + yMag) * avgCR)) and (xMagAvg > Abs(yMag * avgBL - (xMag + yMag) * avgCL)),
(yMagAvg >= Abs(xMag * avgTR - (yMag + xMag) * avgTC)) and (yMagAvg > Abs(xMag * avgBL - (yMag + xMag) * avgBC))),
Cond(Abs(xMag) >= Abs(yMag),
(xMagAvg >= Abs(yMag * avgBR + (xMag - yMag) * avgCR)) and (xMagAvg > Abs(yMag * avgTL + (xMag - yMag) * avgCL)),
(yMagAvg >= Abs(xMag * avgBR + (yMag - xMag) * avgBC)) and (yMagAvg > Abs(xMag * avgTL + (yMag - xMag) * avgTC))))
then
You can make some sence out of it when its stretched out eh :p

XxKanexX
03-30-2006, 04:20 AM
Woh, Ben. I'm speechless.

Imagine you at 30.. You'll probably be programming the world to spin. :p

BenLand100
03-30-2006, 01:51 PM
Woh, Ben. I'm speechless.

Imagine you at 30.. You'll probably be programming the world to spin. :p You didn't know why it spins now :p ;)

The Un-Named
03-30-2006, 02:43 PM
Don't you mean "You didn't know why it spins until now"?

BenLand100
03-30-2006, 04:37 PM
Don't you mean "You didn't know why it spins until now"?
No, mine is correct ;) I am good at grammer just not spelling :p

Wizzup?
03-30-2006, 06:44 PM
No, mine is correct ;) I am good at grammer just not spelling :p

:eek: It's grammar* - I dont know if you did it on purpose though, lol.

BenLand100
03-31-2006, 12:37 AM
:eek: It's grammar* - I dont know if you did it on purpose though, lol.
That wasen't on purpose :p I can't spell ;)