Commit e55621a0 authored by Andrey Filippov's avatar Andrey Filippov

Implemented following the previous segments and the elevations to flat

ground
parent 31fcc689
package com.elphel.imagej.common;
import java.util.Properties;
import java.util.Set;
public class FilterProperties {
public static Properties keep(
Properties properies,
Set<String> keys) {
Properties filtered_properties = new Properties();
for (String key:keys) {
if (properies.getProperty(key) != null) {
filtered_properties.setProperty(key, properies.getProperty(key));
}
}
return filtered_properties;
}
public static Properties remove(
Properties properies,
Set<String> keys) {
Properties filtered_properties = new Properties();
for (String key:properies.stringPropertyNames()) {
if (!keys.contains(key)) {
filtered_properties.setProperty(key, properies.getProperty(key));
}
}
return filtered_properties;
}
}
......@@ -61,6 +61,7 @@ public class McpServer {
server.createContext("/mcp/fs/head", new FsHeadHandler());
server.createContext("/mcp/fs/tail", new FsTailHandler());
server.createContext("/mcp/fs/glob", new FsGlobHandler());
server.createContext("/mcp/fs/csvcol", new FsCsvColHandler());
server.setExecutor(null);
server.start();
if (Eyesis_Correction.MCP_DEBUG_LEVEL >= Eyesis_Correction.MINIMAL_DEBUG_MCP) {
......@@ -188,11 +189,17 @@ public class McpServer {
List<java.nio.file.Path> roots = McpFsAccess.getAllowedRoots();
StringBuilder sb = new StringBuilder();
sb.append("{\"ok\":true,\"roots\":[");
int outIndex = 0;
for (int i = 0; i < roots.size(); i++) {
if (i > 0) {
java.nio.file.Path root = roots.get(i);
if (!java.nio.file.Files.isDirectory(root)) {
continue;
}
if (outIndex > 0) {
sb.append(",");
}
sb.append("\"").append(jsonEscape(roots.get(i).toString())).append("\"");
sb.append("\"").append(jsonEscape(root.toString())).append("\"");
outIndex++;
}
sb.append("]}");
sendJson(exchange, 200, sb.toString());
......@@ -425,6 +432,70 @@ public class McpServer {
}
}
// codex 2026-01-28: read a single column from a delimited text file (1-based column index)
private class FsCsvColHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
Map<String, String> params = parseParams(exchange);
String pathStr = params.get("path");
String colStr = params.get("col");
if (pathStr == null || colStr == null) {
sendJson(exchange, 400, "{\"ok\":false,\"error\":\"Missing path or col\"}");
return;
}
int col = parseInt(colStr, -1);
if (col < 1) {
sendJson(exchange, 400, "{\"ok\":false,\"error\":\"Column index must be >= 1\"}");
return;
}
java.nio.file.Path path = McpFsAccess.normalizePath(pathStr);
if (path == null || !McpFsAccess.isAllowed(path)) {
sendJson(exchange, 403, "{\"ok\":false,\"error\":\"Path not allowed\"}");
return;
}
if (!java.nio.file.Files.isRegularFile(path)) {
sendJson(exchange, 400, "{\"ok\":false,\"error\":\"Not a file\"}");
return;
}
String sep = params.get("sep");
String delim = "\t";
if (sep != null && !sep.isEmpty()) {
if ("\\t".equals(sep) || "tab".equalsIgnoreCase(sep)) {
delim = "\t";
} else {
delim = sep;
}
}
int max = parseInt(params.get("max"), 100000);
if (max < 1) {
max = 1;
}
String splitRegex = java.util.regex.Pattern.quote(delim);
List<String> values = new ArrayList<String>();
try (java.io.BufferedReader reader = java.nio.file.Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(splitRegex, -1);
String value = (col <= parts.length) ? parts[col - 1] : "";
values.add(value);
if (values.size() >= max) {
break;
}
}
}
StringBuilder sb = new StringBuilder();
sb.append("{\"ok\":true,\"col\":").append(col).append(",\"values\":[");
for (int i = 0; i < values.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append("\"").append(jsonEscape(values.get(i))).append("\"");
}
sb.append("]}");
sendJson(exchange, 200, sb.toString());
}
}
private String buildStatusJson() {
int stopRequested = owner.getSyncStopRequested();
StringBuilder sb = new StringBuilder();
......
......@@ -257,10 +257,16 @@ public class QuadCLTCPU {
public CorrectionFPN correctionFPN = null;
public GroundPlane ground_plane = null;
/*
public HashSet<String> getRefScenes(){
return ref_scenes;
}
*/
public String [] getRefScenes() { // increasing timestamps
String [] names = ref_scenes.toArray(new String[0]);
Arrays.sort(names);
return names;
}
public void resetRefScenes() {
ref_scenes = null;
......@@ -823,7 +829,7 @@ public class QuadCLTCPU {
CLTParameters clt_parameters,
int quat_lma_mode,
double avg_height,
double translation_weight,
double translation_weight, // 1.0 - pure translation, 0.0 - pure rotation
QuadCLT[] quadCLTs,
double [][][] xyzatr,
double [][][] ims_xyzatr,
......@@ -1903,13 +1909,34 @@ public class QuadCLTCPU {
}
}
return fl;
// if ((fl[0] >= 0) && (fl[1] >= 0)) {
// return fl;
// } else {
// return null;
// }
}
public int [] getFirstLastIndex(String [] scene_names) { // should be ordered accending ts
int [] fl = null;
if ((timestamp_first != null) && (timestamp_last != null)) {
fl = new int [] {-1,-1};
if (scene_names != null) {
int i = 0;
for (; i < scene_names.length; i++) if (scene_names[i] != null) {
if (timestamp_first.equals(scene_names[i])) {
fl[0] = i;
break;
}
}
for (; i < scene_names.length; i++) if (scene_names[i] != null) {
if (timestamp_last.equals(scene_names[i])) {
fl[1] = i;
break;
}
}
}
}
return fl;
}
/**
* Set reference scene pointer by a reference scene timestamp.
* @param ts reference scene pointer as String
......@@ -1935,6 +1962,9 @@ public class QuadCLTCPU {
timestamp_first = ts0;
timestamp_last = ts1;
}
public String[] getFirstLastTimestamps() {
return new String [] {timestamp_first,timestamp_last};
}
/**
* Set first, last scene pointers by instances.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment