Upload preprocess_manual.js
Browse files- preprocess_manual.js +117 -75
preprocess_manual.js
CHANGED
|
@@ -1090,12 +1090,14 @@ parser.parsePLY(gsPath, true).then((plyData) => {
|
|
| 1090 |
// 2. 点群を分析
|
| 1091 |
const pcaResult = computePCA(plyData.vertices);
|
| 1092 |
|
|
|
|
|
|
|
| 1093 |
// 3. 回転が必要な場合、ユーザーに通知
|
| 1094 |
if (pcaResult.needsRotation) {
|
| 1095 |
console.warn('[preprocessManual] ⚠️ PLY coordinate system is NOT aligned with world axes');
|
| 1096 |
console.warn('[preprocessManual] This may cause visual mismatch between Box and filtering');
|
| 1097 |
|
| 1098 |
-
// ⭐
|
| 1099 |
const shouldNormalize = confirm(
|
| 1100 |
'⚠️ Warning: This PLY file has a tilted coordinate system.\n\n' +
|
| 1101 |
'This may cause the bounding box to appear tilted.\n\n' +
|
|
@@ -1104,110 +1106,150 @@ parser.parsePLY(gsPath, true).then((plyData) => {
|
|
| 1104 |
);
|
| 1105 |
|
| 1106 |
if (shouldNormalize) {
|
| 1107 |
-
console.log('[preprocessManual]
|
| 1108 |
-
|
| 1109 |
-
// 簡易的な方法: バウンディングボックスの主軸に合わせる
|
| 1110 |
-
// より高度な方法: 固有ベクトルを計算して完全に整列
|
| 1111 |
-
|
| 1112 |
-
// ここでは、Y軸が「上」になるように回転する簡易版
|
| 1113 |
-
// 実際のPLYの傾きに応じて調整が必要
|
| 1114 |
|
| 1115 |
const { center } = pcaResult;
|
| 1116 |
|
| 1117 |
-
//
|
|
|
|
|
|
|
|
|
|
| 1118 |
plyData.vertices.forEach(v => {
|
| 1119 |
v.x -= center.x;
|
| 1120 |
v.y -= center.y;
|
| 1121 |
v.z -= center.z;
|
| 1122 |
});
|
| 1123 |
-
|
| 1124 |
console.log('[preprocessManual] ✓ PLY centered at origin');
|
| 1125 |
|
| 1126 |
-
////////////////// add 12/16 18:30
|
| 1127 |
-
|
| 1128 |
// ========================================
|
| 1129 |
-
//
|
| 1130 |
-
// Line 1124 の後に追加
|
| 1131 |
// ========================================
|
| 1132 |
-
|
| 1133 |
-
|
| 1134 |
-
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1144 |
|
| 1145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1146 |
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1150 |
|
| 1151 |
plyData.vertices.forEach(v => {
|
| 1152 |
-
|
| 1153 |
-
|
| 1154 |
-
|
| 1155 |
-
|
| 1156 |
-
|
| 1157 |
-
maxZ = Math.max(maxZ, v.z);
|
| 1158 |
});
|
| 1159 |
|
| 1160 |
-
|
| 1161 |
-
const sizeX = maxX - minX;
|
| 1162 |
-
const sizeY = maxY - minY;
|
| 1163 |
-
const sizeZ = maxZ - minZ;
|
| 1164 |
-
|
| 1165 |
-
console.log('[preprocessManual] Original sizes:', { sizeX, sizeY, sizeZ });
|
| 1166 |
|
| 1167 |
-
|
|
|
|
|
|
|
| 1168 |
|
| 1169 |
-
|
| 1170 |
-
|
| 1171 |
-
rotationNeeded.makeRotationZ(Math.PI / 2);
|
| 1172 |
-
console.log('[preprocessManual] Rotating X→Y (90° around Z)');
|
| 1173 |
-
} else if (sizeZ > sizeY) {
|
| 1174 |
-
// Z軸が最長 → Y軸に回転
|
| 1175 |
-
rotationNeeded.makeRotationX(Math.PI / 2);
|
| 1176 |
-
console.log('[preprocessManual] Rotating Z→Y (90° around X)');
|
| 1177 |
-
}
|
| 1178 |
|
| 1179 |
-
|
| 1180 |
-
|
| 1181 |
-
plyData.vertices.forEach(v => {
|
| 1182 |
-
const pos = new THREE.Vector3(v.x, v.y, v.z);
|
| 1183 |
-
pos.applyMatrix4(rotationNeeded);
|
| 1184 |
-
v.x = pos.x;
|
| 1185 |
-
v.y = pos.y;
|
| 1186 |
-
v.z = pos.z;
|
| 1187 |
-
});
|
| 1188 |
-
|
| 1189 |
-
console.log('[preprocessManual] ✓ PLY rotated to align with world axes');
|
| 1190 |
-
|
| 1191 |
-
// ⭐ 重要: GSにも同じ変換を適用するためフラグを立てる
|
| 1192 |
-
window.plyAlignmentApplied = true;
|
| 1193 |
-
window.plyAlignmentMatrix = rotationNeeded;
|
| 1194 |
-
}
|
| 1195 |
}
|
| 1196 |
-
|
| 1197 |
-
|
| 1198 |
-
|
| 1199 |
-
//
|
| 1200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1201 |
} else {
|
| 1202 |
console.log('[preprocessManual] User chose to keep original orientation');
|
| 1203 |
console.log('[preprocessManual] Box rotation sliders should be used to match PLY orientation');
|
| 1204 |
}
|
|
|
|
| 1205 |
} else {
|
| 1206 |
console.log('[preprocessManual] ✓ PLY coordinate system is already aligned');
|
| 1207 |
}
|
| 1208 |
-
|
| 1209 |
console.log('[preprocessManual] ===== PLY ANALYSIS COMPLETE =====');
|
| 1210 |
-
|
|
|
|
|
|
|
|
|
|
| 1211 |
// ========================================
|
| 1212 |
// 元のコードを続ける
|
| 1213 |
// ========================================
|
|
|
|
| 1090 |
// 2. 点群を分析
|
| 1091 |
const pcaResult = computePCA(plyData.vertices);
|
| 1092 |
|
| 1093 |
+
//////////////////////1095-1210 start
|
| 1094 |
+
|
| 1095 |
// 3. 回転が必要な場合、ユーザーに通知
|
| 1096 |
if (pcaResult.needsRotation) {
|
| 1097 |
console.warn('[preprocessManual] ⚠️ PLY coordinate system is NOT aligned with world axes');
|
| 1098 |
console.warn('[preprocessManual] This may cause visual mismatch between Box and filtering');
|
| 1099 |
|
| 1100 |
+
// ⭐ 自動的に座標系を正規化
|
| 1101 |
const shouldNormalize = confirm(
|
| 1102 |
'⚠️ Warning: This PLY file has a tilted coordinate system.\n\n' +
|
| 1103 |
'This may cause the bounding box to appear tilted.\n\n' +
|
|
|
|
| 1106 |
);
|
| 1107 |
|
| 1108 |
if (shouldNormalize) {
|
| 1109 |
+
console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1110 |
|
| 1111 |
const { center } = pcaResult;
|
| 1112 |
|
| 1113 |
+
// ========================================
|
| 1114 |
+
// STEP 1: 中心化(1回だけ実行)
|
| 1115 |
+
// ========================================
|
| 1116 |
+
console.log('[preprocessManual] Step 1: Centering PLY...');
|
| 1117 |
plyData.vertices.forEach(v => {
|
| 1118 |
v.x -= center.x;
|
| 1119 |
v.y -= center.y;
|
| 1120 |
v.z -= center.z;
|
| 1121 |
});
|
|
|
|
| 1122 |
console.log('[preprocessManual] ✓ PLY centered at origin');
|
| 1123 |
|
|
|
|
|
|
|
| 1124 |
// ========================================
|
| 1125 |
+
// STEP 2: バウンディングボックスを再計算
|
|
|
|
| 1126 |
// ========================================
|
| 1127 |
+
console.log('[preprocessManual] Step 2: Recalculating bounding box...');
|
| 1128 |
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
| 1129 |
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
| 1130 |
+
|
| 1131 |
+
plyData.vertices.forEach(v => {
|
| 1132 |
+
minX = Math.min(minX, v.x);
|
| 1133 |
+
minY = Math.min(minY, v.y);
|
| 1134 |
+
minZ = Math.min(minZ, v.z);
|
| 1135 |
+
maxX = Math.max(maxX, v.x);
|
| 1136 |
+
maxY = Math.max(maxY, v.y);
|
| 1137 |
+
maxZ = Math.max(maxZ, v.z);
|
| 1138 |
+
});
|
| 1139 |
+
|
| 1140 |
+
const sizeX = maxX - minX;
|
| 1141 |
+
const sizeY = maxY - minY;
|
| 1142 |
+
const sizeZ = maxZ - minZ;
|
| 1143 |
+
|
| 1144 |
+
console.log('[preprocessManual] Centered sizes:', {
|
| 1145 |
+
sizeX: sizeX.toFixed(2),
|
| 1146 |
+
sizeY: sizeY.toFixed(2),
|
| 1147 |
+
sizeZ: sizeZ.toFixed(2)
|
| 1148 |
+
});
|
| 1149 |
+
|
| 1150 |
+
// ========================================
|
| 1151 |
+
// STEP 3: Y軸が最長になるように回転
|
| 1152 |
+
// ========================================
|
| 1153 |
+
console.log('[preprocessManual] Step 3: Checking if rotation is needed...');
|
| 1154 |
+
console.log('[preprocessManual] Longest axis:',
|
| 1155 |
+
sizeX > sizeY && sizeX > sizeZ ? 'X' :
|
| 1156 |
+
sizeZ > sizeY ? 'Z' : 'Y');
|
| 1157 |
+
|
| 1158 |
+
let rotationNeeded = new THREE.Matrix4(); // Identity matrix
|
| 1159 |
+
let rotationApplied = false;
|
| 1160 |
+
|
| 1161 |
+
if (sizeX > sizeY && sizeX > sizeZ) {
|
| 1162 |
+
// X軸が最長 → Y軸に回転
|
| 1163 |
+
console.log('[preprocessManual] ⚙️ Rotating: X → Y (90° around Z axis)');
|
| 1164 |
+
rotationNeeded.makeRotationZ(Math.PI / 2);
|
| 1165 |
+
rotationApplied = true;
|
| 1166 |
|
| 1167 |
+
} else if (sizeZ > sizeY && sizeZ > sizeX) {
|
| 1168 |
+
// Z軸が最長 → Y軸に回転
|
| 1169 |
+
console.log('[preprocessManual] ⚙️ Rotating: Z → Y (90° around X axis)');
|
| 1170 |
+
rotationNeeded.makeRotationX(Math.PI / 2);
|
| 1171 |
+
rotationApplied = true;
|
| 1172 |
|
| 1173 |
+
} else {
|
| 1174 |
+
// Y軸がすでに最長
|
| 1175 |
+
console.log('[preprocessManual] ✓ Y-axis is already the longest, no rotation needed');
|
| 1176 |
+
}
|
| 1177 |
+
|
| 1178 |
+
// ========================================
|
| 1179 |
+
// STEP 4: 回転を適用(必要な場合のみ)
|
| 1180 |
+
// ========================================
|
| 1181 |
+
if (rotationApplied) {
|
| 1182 |
+
console.log('[preprocessManual] Step 4: Applying rotation to all vertices...');
|
| 1183 |
|
| 1184 |
plyData.vertices.forEach(v => {
|
| 1185 |
+
const pos = new THREE.Vector3(v.x, v.y, v.z);
|
| 1186 |
+
pos.applyMatrix4(rotationNeeded);
|
| 1187 |
+
v.x = pos.x;
|
| 1188 |
+
v.y = pos.y;
|
| 1189 |
+
v.z = pos.z;
|
|
|
|
| 1190 |
});
|
| 1191 |
|
| 1192 |
+
console.log('[preprocessManual] ✓ PLY rotated to align with world axes');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1193 |
|
| 1194 |
+
// ⭐ 重要: GSにも同じ変換を適用するためフラグを立てる
|
| 1195 |
+
window.plyAlignmentApplied = true;
|
| 1196 |
+
window.plyAlignmentMatrix = rotationNeeded.clone();
|
| 1197 |
|
| 1198 |
+
console.log('[preprocessManual] ✓ Alignment matrix saved for GS display');
|
| 1199 |
+
console.log('[preprocessManual] Matrix elements:', rotationNeeded.elements.slice(0, 4));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1200 |
|
| 1201 |
+
} else {
|
| 1202 |
+
console.log('[preprocessManual] Step 4: Skipped (no rotation needed)');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1203 |
}
|
| 1204 |
+
|
| 1205 |
+
// ========================================
|
| 1206 |
+
// STEP 5: 最終確認(サイズの再計算)
|
| 1207 |
+
// ========================================
|
| 1208 |
+
console.log('[preprocessManual] Step 5: Verifying final result...');
|
| 1209 |
+
|
| 1210 |
+
minX = Infinity; minY = Infinity; minZ = Infinity;
|
| 1211 |
+
maxX = -Infinity; maxY = -Infinity; maxZ = -Infinity;
|
| 1212 |
+
|
| 1213 |
+
plyData.vertices.forEach(v => {
|
| 1214 |
+
minX = Math.min(minX, v.x);
|
| 1215 |
+
minY = Math.min(minY, v.y);
|
| 1216 |
+
minZ = Math.min(minZ, v.z);
|
| 1217 |
+
maxX = Math.max(maxX, v.x);
|
| 1218 |
+
maxY = Math.max(maxY, v.y);
|
| 1219 |
+
maxZ = Math.max(maxZ, v.z);
|
| 1220 |
+
});
|
| 1221 |
+
|
| 1222 |
+
const finalSizeX = maxX - minX;
|
| 1223 |
+
const finalSizeY = maxY - minY;
|
| 1224 |
+
const finalSizeZ = maxZ - minZ;
|
| 1225 |
+
|
| 1226 |
+
console.log('[preprocessManual] Final sizes:', {
|
| 1227 |
+
sizeX: finalSizeX.toFixed(2),
|
| 1228 |
+
sizeY: finalSizeY.toFixed(2),
|
| 1229 |
+
sizeZ: finalSizeZ.toFixed(2)
|
| 1230 |
+
});
|
| 1231 |
+
console.log('[preprocessManual] Final center:', {
|
| 1232 |
+
x: ((minX + maxX) / 2).toFixed(2),
|
| 1233 |
+
y: ((minY + maxY) / 2).toFixed(2),
|
| 1234 |
+
z: ((minZ + maxZ) / 2).toFixed(2)
|
| 1235 |
+
});
|
| 1236 |
+
|
| 1237 |
+
console.log('[preprocessManual] ===== AUTO-ALIGNMENT COMPLETE =====');
|
| 1238 |
+
|
| 1239 |
} else {
|
| 1240 |
console.log('[preprocessManual] User chose to keep original orientation');
|
| 1241 |
console.log('[preprocessManual] Box rotation sliders should be used to match PLY orientation');
|
| 1242 |
}
|
| 1243 |
+
|
| 1244 |
} else {
|
| 1245 |
console.log('[preprocessManual] ✓ PLY coordinate system is already aligned');
|
| 1246 |
}
|
| 1247 |
+
|
| 1248 |
console.log('[preprocessManual] ===== PLY ANALYSIS COMPLETE =====');
|
| 1249 |
+
|
| 1250 |
+
|
| 1251 |
+
////////////////////1095-1210 end
|
| 1252 |
+
|
| 1253 |
// ========================================
|
| 1254 |
// 元のコードを続ける
|
| 1255 |
// ========================================
|