Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
optical-design-viewer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
optical-design-viewer
Commits
de4948ab
Commit
de4948ab
authored
Jun 27, 2014
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+zmx-to-xml converter
parent
47107181
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
3 deletions
+124
-3
convert_zmx.php
convert_zmx.php
+98
-0
files.php
files.php
+5
-1
lens_design.js
lens_design.js
+21
-2
test_utf16le.zmx
local/test_utf16le.zmx
+0
-0
No files found.
convert_zmx.php
0 → 100644
View file @
de4948ab
<?php
/*
FILE NAME : convert_zmx.php
DESCRIPTION: optical design
REVISION: 1.00
AUTHOR: Oleg Dzhimiev <oleg@elphel.com>
LICENSE: AGPL, see http://www.gnu.org/licenses/agpl.txt
Copyright (C) 2014 Elphel, Inc.
*/
function
convert_zmx
(
$path
){
$contents
=
file_get_contents
(
$path
);
$lines
=
explode
(
"
\n
"
,
$contents
);
$surface_enable
=
false
;
$index
=
0
;
$surfaces
=
Array
();
for
(
$i
=
0
;
$i
<
count
(
$lines
);
$i
++
){
$str
=
mb_convert_encoding
(
$lines
[
$i
],
'UTF-8'
,
'UTF-16'
);
//$str = $lines[$i];
if
(
$surface_enable
){
$s
=
explode
(
' '
,
$str
);
foreach
(
$s
as
$a
=>
$b
){
$tmp
=
trim
(
$b
);
if
(
$tmp
==
"CURV"
)
{
$surfaces
[
$index
][
"CURV"
]
=
$s
[
$a
+
1
];
break
;}
if
(
$tmp
==
"DISZ"
)
{
$surfaces
[
$index
][
"DISZ"
]
=
$s
[
$a
+
1
];
break
;}
if
(
$tmp
==
"GLAS"
)
{
$surfaces
[
$index
][
"GLAS"
]
=
$s
[
$a
+
1
];
break
;}
if
(
$tmp
==
"DIAM"
)
{
$surfaces
[
$index
][
"DIAM"
]
=
$s
[
$a
+
1
];
break
;}
if
(
$tmp
==
"STOP"
)
{
$surfaces
[
$index
][
"STOP"
]
=
true
;
break
;}
}
}
if
(
strpos
(
$str
,
"SURF"
)
!==
false
)
{
$surface_enable
=
true
;
}
//considering POPS line as the end
if
(
strpos
(
$str
,
"POPS"
)
!==
false
)
{
$surface_enable
=
false
;
$index
++
;
}
}
//surfaces array is ready
$found_1st_glass
=
false
;
$xml
=
""
;
$distance
=
0
;
for
(
$i
=
0
;
$i
<
count
(
$surfaces
);
$i
++
){
$elem
=
$surfaces
[
$i
];
if
(
isset
(
$elem
[
"GLAS"
])
||
isset
(
$elem
[
"STOP"
]))
{
$xml
.=
"
\t
<element>
\n
"
;
$xml
.=
"
\t\t
<distance>"
.
$distance
.
"</distance>
\n
"
;
$xml
.=
"
\t\t
<thickness>"
.
trim
(
$elem
[
"DISZ"
])
.
"</thickness>
\n
"
;
$xml
.=
"
\t\t
<material>"
.
$elem
[
"GLAS"
]
.
"</material>
\n
"
;
if
(
isset
(
$elem
[
"STOP"
]))
$xml
.=
"
\t\t
<name>aperture stop</name>
\n
"
;
else
$xml
.=
"
\t\t
<name></name>
\n
"
;
$xml
.=
"
\t\t
<front>
\n
"
;
if
(
isset
(
$elem
[
"STOP"
]))
$xml
.=
"
\t\t\t
<height>"
.
(
-
2
*
$elem
[
"DIAM"
])
.
"</height>
\n
"
;
else
$xml
.=
"
\t\t\t
<height>"
.
(
+
2
*
$elem
[
"DIAM"
])
.
"</height>
\n
"
;
if
(
$elem
[
"CURV"
]
==
0
)
$elem
[
"CURV"
]
=
0.000001
;
if
(
!
isset
(
$elem
[
"STOP"
]))
$xml
.=
"
\t\t\t
<rcurve>"
.
(
1
/
$elem
[
"CURV"
])
.
"</rcurve>
\n
"
;
else
$xml
.=
"
\t\t\t
<rcurve>0</rcurve>
\n
"
;
$xml
.=
"
\t\t\t
<k>0</k>
\n
"
;
$xml
.=
"
\t\t\t
<a1>0</a1>
\n
"
;
$xml
.=
"
\t\t\t
<a2>0</a2>
\n
"
;
$xml
.=
"
\t\t\t
<a3>0</a3>
\n
"
;
$xml
.=
"
\t\t\t
<a4>0</a4>
\n
"
;
$xml
.=
"
\t\t
</front>
\n
"
;
$xml
.=
"
\t\t
<back>
\n
"
;
if
(
isset
(
$elem
[
"STOP"
]))
$xml
.=
"
\t\t\t
<height>0</height>
\n
"
;
else
$xml
.=
"
\t\t\t
<height>"
.
(
2
*
$surfaces
[
$i
+
1
][
"DIAM"
])
.
"</height>
\n
"
;
if
(
$surfaces
[
$i
+
1
][
"CURV"
]
==
0
)
$surfaces
[
$i
+
1
][
"CURV"
]
=
0.000001
;
if
(
!
isset
(
$elem
[
"STOP"
]))
$xml
.=
"
\t\t\t
<rcurve>"
.
(
1
/
$surfaces
[
$i
+
1
][
"CURV"
])
.
"</rcurve>
\n
"
;
else
$xml
.=
"
\t\t\t
<rcurve>0</rcurve>
\n
"
;
$xml
.=
"
\t\t\t
<k>0</k>
\n
"
;
$xml
.=
"
\t\t\t
<a1>0</a1>
\n
"
;
$xml
.=
"
\t\t\t
<a2>0</a2>
\n
"
;
$xml
.=
"
\t\t\t
<a3>0</a3>
\n
"
;
$xml
.=
"
\t\t\t
<a4>0</a4>
\n
"
;
$xml
.=
"
\t\t
</back>
\n
"
;
$xml
.=
"
\t
</element>
\n
"
;
$found_1st_glass
=
true
;
}
if
(
$found_1st_glass
)
$distance
+=
$elem
[
"DISZ"
];
}
$final_xml
=
"<?xml version='1.0' encoding='UTF-8'?>
\n
<Document>
\n
"
.
$xml
.
"</Document>"
;
return
$final_xml
;
}
?>
\ No newline at end of file
files.php
View file @
de4948ab
...
...
@@ -17,10 +17,14 @@ else die("-2");
if
(
isset
(
$_GET
[
'path'
]))
$default_path
=
$_GET
[
'path'
];
else
die
(
"-3"
);
require
(
"convert_zmx.php"
);
if
(
$cmd
==
"save"
)
{
file_put_contents
(
"
$default_path
/
$file
"
,
file_get_contents
(
"php://input"
));
}
elseif
(
$cmd
==
"read"
)
{
$content
=
file_get_contents
(
"
$default_path
/
$file
"
);
$ext
=
pathinfo
(
$file
,
PATHINFO_EXTENSION
);
if
(
$ext
==
"zmx"
)
$content
=
convert_zmx
(
"
$default_path
/
$file
"
);
else
$content
=
file_get_contents
(
"
$default_path
/
$file
"
);
header
(
"Content-Type: text/xml
\n
"
);
header
(
"Content-Length: "
.
strlen
(
$content
)
.
"
\n
"
);
header
(
"Pragma: no-cache
\n
"
);
...
...
lens_design.js
View file @
de4948ab
...
...
@@ -112,6 +112,16 @@ function array_update_entries(){
}
}
}
var
total_power
=
0
;
for
(
i
=
0
;
i
<
e
.
length
;
i
++
){
if
(
e
[
i
].
front
.
h
>
0
)
{
tmp
=
find_optical_power
(
e
[
i
])
total_power
+=
tmp
;
console
.
log
(
"Optical power of element #"
+
i
+
" is "
+
tmp
+
" diopters"
);
}
}
console
.
log
(
"Total optical power is "
+
total_power
);
table_update_all
();
}
...
...
@@ -928,7 +938,16 @@ function find_aperture_stop_ray(x,y,alpha,height,dalpha,old_cv,limit){
}
}
function
find_optical_power
(
element
){
var
n
=
+
Glass
[
element
.
m
.
toUpperCase
()].
n
;
var
r1
=
+
element
.
front
.
c
;
var
r2
=
+
element
.
back
.
c
;
var
d
=
+
element
.
t
;
var
inv_f
=
(
n
-
1
)
*
(
1
/
r1
-
1
/
r2
+
(
n
-
1
)
*
d
/
n
/
(
r1
*
r2
));
var
f
=
1
/
inv_f
;
console
.
log
(
"f = "
+
f
+
" mm"
);
return
inv_f
*
1000
;
}
var
Glass
=
{
...
...
local/test_utf16le.zmx
0 → 100644
View file @
de4948ab
B
VERS 131008 2037 22001
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment