Commit 4e6966e0 authored by Andrey Filippov's avatar Andrey Filippov

Debugging gltf export

parent 82b27573
...@@ -27,6 +27,18 @@ ...@@ -27,6 +27,18 @@
<description>A Maven project implementing imagej-elphel plugin</description> <description>A Maven project implementing imagej-elphel plugin</description>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<!-- ssh support - see https://www.baeldung.com/java-ssh-connection --> <!-- ssh support - see https://www.baeldung.com/java-ssh-connection -->
<!-- https://mvnrepository.com/artifact/org.apache.sshd/sshd-core --> <!-- https://mvnrepository.com/artifact/org.apache.sshd/sshd-core -->
<dependency> <dependency>
......
...@@ -903,7 +903,7 @@ public class OpticalFlow { ...@@ -903,7 +903,7 @@ public class OpticalFlow {
* @param debug_level if > 0; print number of tiles to correlate * @param debug_level if > 0; print number of tiles to correlate
* @return flowXY vectors only for tiles to be updated or null if no tiles left * @return flowXY vectors only for tiles to be updated or null if no tiles left
*/ */
double [][] recalculateFlowXY( static double [][] recalculateFlowXY(
final double [][] flowXY, // will update final double [][] flowXY, // will update
final double [][] flowXY_prev, // previous flowXY (may be null for tiles) final double [][] flowXY_prev, // previous flowXY (may be null for tiles)
final double [][] corr_vectorsXY, final double [][] corr_vectorsXY,
......
...@@ -76,6 +76,60 @@ class TileCluster{ ...@@ -76,6 +76,60 @@ class TileCluster{
public Rectangle getBounds() {return bounds;} public Rectangle getBounds() {return bounds;}
public boolean [] getBorder() {return border;} public boolean [] getBorder() {return border;}
public double [] getDisparity() {return disparity;} public double [] getDisparity() {return disparity;}
public double [] getSubDisparity(int indx) { // disparity should be NaN for unused !
if (clust_list == null) {
return null;
}
Rectangle sub_bounds = clust_list.get(indx).bounds;
double [] sub_disparity = new double [sub_bounds.width * sub_bounds.height];
int src_x = sub_bounds.x - bounds.x;
for (int dst_y = 0; dst_y < sub_bounds.height; dst_y++) {
int src_y = dst_y + sub_bounds.y - bounds.y;
System.arraycopy(
disparity,
src_y * bounds.width + src_x,
sub_disparity,
dst_y * sub_bounds.width,
sub_bounds.width);
}
return sub_disparity;
}
public boolean [] getSubBorder(int indx) { // disparity should be NaN for unused !
if (clust_list == null) {
return null;
}
Rectangle sub_bounds = clust_list.get(indx).bounds;
boolean [] sub_border = new boolean [sub_bounds.width * sub_bounds.height];
int src_x = sub_bounds.x - bounds.x;
for (int dst_y = 0; dst_y < sub_bounds.height; dst_y++) {
int src_y = dst_y + sub_bounds.y - bounds.y;
System.arraycopy(
border,
src_y * bounds.width + src_x,
sub_border,
dst_y * sub_bounds.width,
sub_bounds.width);
}
return sub_border;
}
public boolean [] getSubSelected(int indx) { // disparity should be NaN for unused !
if (clust_list == null) {
return null;
}
double [] sub_disparity = getSubDisparity(indx);
boolean [] sub_selection = new boolean [sub_disparity.length];
for (int i = 0; i < sub_disparity.length; i++) {
sub_selection[i] = !Double.isNaN(sub_disparity[i]);
}
return sub_selection;
}
public boolean [] getSelected() { public boolean [] getSelected() {
if (disparity == null) { if (disparity == null) {
return null; return null;
...@@ -132,42 +186,6 @@ class TileCluster{ ...@@ -132,42 +186,6 @@ class TileCluster{
} }
/*
public TileCluster combine (TileCluster tileCluster) {
TileCluster outer, inner;
if (bounds.contains(tileCluster.bounds)) {
outer = this;
inner = tileCluster;
} else if (tileCluster.bounds.contains(bounds)) {
outer = tileCluster;
inner = this;
} else {
Rectangle outer_bounds = bounds.union(tileCluster.bounds);
outer = new TileCluster(outer_bounds, null, null);
outer.combine(this); //
inner = tileCluster;
}
int dst_x = inner.bounds.x - outer.bounds.x;
for (int src_y = 0; src_y < bounds.height; src_y++) {
int dst_y = src_y + inner.bounds.y - outer.bounds.y;
System.arraycopy(
inner.border,
src_y * bounds.width,
outer.border,
dst_y * outer.bounds.width + dst_x,
bounds.width);
System.arraycopy(
inner.disparity,
src_y * bounds.width,
outer.disparity,
dst_y * outer.bounds.width + dst_x,
bounds.width);
}
return outer;
}
*/
public void add(TileCluster tileCluster) { public void add(TileCluster tileCluster) {
if (!bounds.contains(tileCluster.bounds)) { if (!bounds.contains(tileCluster.bounds)) {
throw new IllegalArgumentException ("TileCluster.add(): Added cluster should fit into this "); throw new IllegalArgumentException ("TileCluster.add(): Added cluster should fit into this ");
...@@ -193,16 +211,6 @@ class TileCluster{ ...@@ -193,16 +211,6 @@ class TileCluster{
disparity, disparity,
dst_y * bounds.width + dst_x, dst_y * bounds.width + dst_x,
tileCluster.bounds.width); tileCluster.bounds.width);
/**
if ((cluster_index != null) && (tileCluster.cluster_index != null)) {
System.arraycopy(
tileCluster.cluster_index,
src_y * tileCluster.bounds.width,
cluster_index,
dst_y * bounds.width + dst_x,
tileCluster.bounds.width);
}
*/
} }
return; return;
} }
......
This diff is collapsed.
package com.elphel.imagej.x3d.export;
/**
**
** TriMesh - triangular mesh representation
**
** Copyright (C) 2022 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** TriMesh.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
public class TriMesh {
public String texture_image;
public double [][] worldXYZ;
public double [][] texCoord;
public int [][] triangles;
public TriMesh (
String texture_image,
double [][] worldXYZ,
double [][] texCoord,
int [][] triangles) {
this.texture_image = texture_image;
this.worldXYZ = worldXYZ;
this.texCoord = texCoord;
this.triangles = triangles;
}
public String getImage() {return texture_image;}
int [][] getTriangles() {return triangles;}
double [][] getTexCoord() {
return texCoord;
}
public double [][] getTexCoord(boolean inv_x, boolean inv_y, boolean swap_xy) {
if (!inv_x && !inv_y && !swap_xy) {
return texCoord;
}
double [][] inv_tex_coord = new double [texCoord.length][2];
double scale_x = inv_x ? -1.0 : 1.0;
double scale_y = inv_y ? -1.0 : 1.0;
if (swap_xy) {
for (int i = 0; i <texCoord.length; i++) {
inv_tex_coord[i][0] = scale_y * texCoord[i][1];
inv_tex_coord[i][1] = scale_x * texCoord[i][0];
}
} else {
for (int i = 0; i <texCoord.length; i++) {
inv_tex_coord[i][0] = scale_x * texCoord[i][0];
inv_tex_coord[i][1] = scale_y * texCoord[i][1];
}
}
return inv_tex_coord;
}
public double [][] getCoordinates(){
return worldXYZ;
}
/**
* 0: XYZ -> XYZ
* 1: XYZ -> YZX
* 2: XYZ -> ZXY
* 3: XYZ -> XZY
* 4: XYZ -> ZYX
* 5: XYZ -> YXZ
* @param inv_x
* @param inv_y
* @param inv_z
* @param swap3
* @return
*/
public double [][] getCoordinates(boolean inv_x, boolean inv_y, boolean inv_z, int swap3) {
if (!inv_x && !inv_y && !inv_y && (swap3 == 0)) {
return worldXYZ;
}
double [][] inv_worldXYZ = new double [worldXYZ.length][3];
double scale_x = inv_x ? -1.0 : 1.0;
double scale_y = inv_y ? -1.0 : 1.0;
double scale_z = inv_z ? -1.0 : 1.0;
switch (swap3) {
case 0: // XYZ -> XYZ
for (int i = 0; i <texCoord.length; i++) {
inv_worldXYZ[i][0] = scale_x * worldXYZ[i][0];
inv_worldXYZ[i][1] = scale_y * worldXYZ[i][1];
inv_worldXYZ[i][2] = scale_z * worldXYZ[i][2];
}
break;
case 1: // XYZ -> YZX
for (int i = 0; i <texCoord.length; i++) {
inv_worldXYZ[i][1] = scale_x * worldXYZ[i][0];
inv_worldXYZ[i][2] = scale_y * worldXYZ[i][1];
inv_worldXYZ[i][0] = scale_z * worldXYZ[i][2];
}
break;
case 2: // XYZ -> ZXY
for (int i = 0; i <texCoord.length; i++) {
inv_worldXYZ[i][2] = scale_x * worldXYZ[i][0];
inv_worldXYZ[i][0] = scale_y * worldXYZ[i][1];
inv_worldXYZ[i][1] = scale_z * worldXYZ[i][2];
}
break;
case 3: // XYZ -> XZY
for (int i = 0; i <texCoord.length; i++) {
inv_worldXYZ[i][0] = scale_x * worldXYZ[i][0];
inv_worldXYZ[i][2] = scale_y * worldXYZ[i][1];
inv_worldXYZ[i][1] = scale_z * worldXYZ[i][2];
}
break;
case 4: // XYZ -> ZYX
for (int i = 0; i <texCoord.length; i++) {
inv_worldXYZ[i][2] = scale_x * worldXYZ[i][0];
inv_worldXYZ[i][1] = scale_y * worldXYZ[i][1];
inv_worldXYZ[i][0] = scale_z * worldXYZ[i][2];
}
break;
case 5: // XYZ -> YXZ
for (int i = 0; i <texCoord.length; i++) {
inv_worldXYZ[i][1] = scale_x * worldXYZ[i][0];
inv_worldXYZ[i][0] = scale_y * worldXYZ[i][1];
inv_worldXYZ[i][2] = scale_z * worldXYZ[i][2];
}
break;
default: return null;
}
return inv_worldXYZ;
}
}
package com.elphel.imagej.x3d.export; package com.elphel.imagej.x3d.export;
/**
**
** WavefrontExport - generate Wavefront OBJ representation of the model
**
** Copyright (C) 2018 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** WavefrontExport.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
......
...@@ -76,6 +76,7 @@ public class X3dOutput { ...@@ -76,6 +76,7 @@ public class X3dOutput {
this.clt_3d_passes = clt_3d_passes; this.clt_3d_passes = clt_3d_passes;
} }
// init document, bounding box, backdrop // init document, bounding box, backdrop
// 09.18.2022 - made work w/o background
public void generateBackground(boolean use_backdrop) public void generateBackground(boolean use_backdrop)
{ {
try { try {
...@@ -104,6 +105,11 @@ public class X3dOutput { ...@@ -104,6 +105,11 @@ public class X3dOutput {
el_TopGroup.setAttribute("bboxSize", String.format("%.3f %.3f %.3f ",bbox[1][0],bbox[1][1],bbox[1][2])); el_TopGroup.setAttribute("bboxSize", String.format("%.3f %.3f %.3f ",bbox[1][0],bbox[1][1],bbox[1][2]));
el_Scene.appendChild(el_TopGroup); el_Scene.appendChild(el_TopGroup);
if (clt_3d_passes == null) {
System.out.println("Not using background without clt_3d_passes");
return;
}
CLTPass3d bgnd_pass = clt_3d_passes.get(0); CLTPass3d bgnd_pass = clt_3d_passes.get(0);
...@@ -167,6 +173,10 @@ public class X3dOutput { ...@@ -167,6 +173,10 @@ public class X3dOutput {
sb_tex_coords.append(String.format("%.4f %.4f", texCoord[i][0], texCoord[i][1])); sb_tex_coords.append(String.format("%.4f %.4f", texCoord[i][0], texCoord[i][1]));
} }
String sindex = sb_coord_index.toString(); // for both coordIndex and texCoordIndex String sindex = sb_coord_index.toString(); // for both coordIndex and texCoordIndex
if (sindex.length() == 0) {
System.out.println("addCluster(): sindex.length() == 0");
System.out.println("addCluster(): sindex.length() == 0");
}
String scoord = sb_coords.toString(); String scoord = sb_coords.toString();
String stcoord = sb_tex_coords.toString(); String stcoord = sb_tex_coords.toString();
......
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