Skip to content

Commit 2ca471c

Browse files
Abstract method of reading vertexes and point clouds can now handle multiple features assigned to a single point better
1 parent 0e1d6a4 commit 2ca471c

File tree

14 files changed

+310
-89
lines changed

14 files changed

+310
-89
lines changed

applications/src/main/java/boofcv/app/MeshViewerApp.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import boofcv.struct.image.InterleavedU8;
2828
import boofcv.struct.mesh.VertexMesh;
2929
import org.apache.commons.io.FilenameUtils;
30-
import org.ddogleg.struct.DogArray_I32;
3130

3231
import javax.swing.*;
3332
import java.awt.*;
@@ -49,7 +48,6 @@ public MeshViewerApp() {
4948
private static void loadFile( File file ) {
5049
// Load the mesh
5150
var mesh = new VertexMesh();
52-
var colors = new DogArray_I32();
5351
String extension = FilenameUtils.getExtension(file.getName()).toLowerCase(Locale.ENGLISH);
5452
var type = switch (extension) {
5553
case "ply" -> PointCloudIO.Format.PLY;
@@ -61,7 +59,7 @@ private static void loadFile( File file ) {
6159
};
6260

6361
try (var input = new FileInputStream(file)) {
64-
PointCloudIO.load(type, input, mesh, colors);
62+
PointCloudIO.load(type, input, mesh);
6563
} catch (IOException e) {
6664
e.printStackTrace(System.err);
6765
System.exit(1);
@@ -86,8 +84,8 @@ private static void loadFile( File file ) {
8684
SwingUtilities.invokeLater(() -> {
8785
var panel = new MeshViewerPanel();
8886
panel.setMesh(mesh, false);
89-
if (colors.size > 0)
90-
panel.setVertexColors("RGB", colors.data);
87+
if (mesh.rgb.size > 0)
88+
panel.setVertexColors("RGB", mesh.rgb.data);
9189
if (_image != null)
9290
panel.setTextureImage(_image);
9391
panel.setPreferredSize(new Dimension(500, 500));

main/boofcv-geo/src/main/java/boofcv/alg/cloud/DisparityToColorPointCloud.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Peter Abeles. All Rights Reserved.
2+
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
33
*
44
* This file is part of BoofCV (http://boofcv.org).
55
*
@@ -175,7 +175,10 @@ private void process( GrayU8 disparity, ColorImage color, PointCloudWriter outpu
175175
// Bring it back into left camera frame
176176
GeometryMath_F32.multTran(rectifiedR, p, p);
177177

178-
output.add(p.x, p.y, p.z, getColor(color, pixelX, pixelY));
178+
output.startPoint();
179+
output.location(p.x, p.y, p.z);
180+
output.color(getColor(color, pixelX, pixelY));
181+
output.stopPoint();
179182
}
180183
}
181184
}
@@ -217,7 +220,10 @@ private void process( GrayF32 disparity, ColorImage color, PointCloudWriter outp
217220
// Bring it back into left camera frame
218221
GeometryMath_F32.multTran(rectifiedR, p, p);
219222

220-
output.add(p.x, p.y, p.z, getColor(color, pixelX, pixelY));
223+
output.startPoint();
224+
output.location(p.x, p.y, p.z);
225+
output.color(getColor(color, pixelX, pixelY));
226+
output.stopPoint();
221227
}
222228
}
223229
}

main/boofcv-geo/src/main/java/boofcv/alg/cloud/PointCloudWriter.java

+60-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Peter Abeles. All Rights Reserved.
2+
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
33
*
44
* This file is part of BoofCV (http://boofcv.org).
55
*
@@ -40,10 +40,21 @@ public interface PointCloudWriter {
4040
*/
4141
void initialize( int size, boolean hasColor );
4242

43+
/** A new point is being added with new attributes to follow */
44+
void startPoint();
45+
46+
/** It's done specifying attributes for the point */
47+
void stopPoint();
48+
4349
/**
44-
* Adds a 3D point with color information
50+
* Set the 3D location of the point
4551
*/
46-
void add( double x, double y, double z, int rgb );
52+
void location( double x, double y, double z );
53+
54+
/**
55+
* Sets the points color
56+
*/
57+
void color( int rgb );
4758

4859
class CloudArraysF32 implements PointCloudWriter {
4960
// Storage for point cloud
@@ -57,10 +68,17 @@ class CloudArraysF32 implements PointCloudWriter {
5768
cloudXyz.reserve(size*3);
5869
}
5970

60-
@Override public void add( double x, double y, double z, int rgb ) {
71+
@Override public void startPoint() {}
72+
73+
@Override public void stopPoint() {}
74+
75+
@Override public void location( double x, double y, double z ) {
6176
cloudXyz.add((float)x);
6277
cloudXyz.add((float)y);
6378
cloudXyz.add((float)z);
79+
}
80+
81+
@Override public void color( int rgb ) {
6482
cloudRgb.add(rgb);
6583
}
6684

@@ -79,10 +97,15 @@ static PointCloudWriter wrapF32( DogArray<Point3D_F32> cloud ) {
7997
cloud.reset();
8098
}
8199

82-
@Override
83-
public void add( double x, double y, double z, int rgb ) {
100+
@Override public void startPoint() {}
101+
102+
@Override public void stopPoint() {}
103+
104+
@Override public void location( double x, double y, double z ) {
84105
cloud.grow().setTo((float)x, (float)y, (float)z);
85106
}
107+
108+
@Override public void color( int rgb ) {}
86109
};
87110
}
88111

@@ -93,8 +116,13 @@ static PointCloudWriter wrapF64( DogArray<Point3D_F64> cloud ) {
93116
cloud.reset();
94117
}
95118

96-
@Override
97-
public void add( double x, double y, double z, int rgb ) {
119+
@Override public void startPoint() {}
120+
121+
@Override public void stopPoint() {}
122+
123+
@Override public void color( int rgb ) {}
124+
125+
@Override public void location( double x, double y, double z ) {
98126
cloud.grow().setTo(x, y, z);
99127
}
100128
};
@@ -107,9 +135,18 @@ static PointCloudWriter wrapF32RGB( DogArray<Point3dRgbI_F32> cloud ) {
107135
cloud.reset();
108136
}
109137

110-
@Override
111-
public void add( double x, double y, double z, int rgb ) {
112-
cloud.grow().setTo((float)x, (float)y, (float)z, rgb);
138+
@Override public void startPoint() {
139+
cloud.grow();
140+
}
141+
142+
@Override public void stopPoint() {}
143+
144+
@Override public void location( double x, double y, double z ) {
145+
cloud.getTail().setTo((float)x, (float)y, (float)z);
146+
}
147+
148+
@Override public void color( int rgb ) {
149+
cloud.getTail().rgb = rgb;
113150
}
114151
};
115152
}
@@ -120,9 +157,18 @@ static PointCloudWriter wrapF64RGB( DogArray<Point3dRgbI_F64> cloud ) {
120157
cloud.reset();
121158
}
122159

123-
@Override
124-
public void add( double x, double y, double z, int rgb ) {
125-
cloud.grow().setTo(x, y, z, rgb);
160+
@Override public void startPoint() {
161+
cloud.grow();
162+
}
163+
164+
@Override public void stopPoint() {}
165+
166+
@Override public void location( double x, double y, double z ) {
167+
cloud.getTail().setTo(x, y, z);
168+
}
169+
170+
@Override public void color( int rgb ) {
171+
cloud.getTail().rgb = rgb;
126172
}
127173
};
128174
}

main/boofcv-geo/src/test/java/boofcv/alg/cloud/TestPointCloudWriter.java

+42-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Peter Abeles. All Rights Reserved.
2+
* Copyright (c) 2024, Peter Abeles. All Rights Reserved.
33
*
44
* This file is part of BoofCV (http://boofcv.org).
55
*
@@ -35,32 +35,41 @@ class TestPointCloudWriter extends BoofStandardJUnit {
3535

3636
static abstract class PcwTests {
3737
boolean supportsColor = true;
38+
3839
public abstract PointCloudWriter create();
40+
3941
public abstract int size( PointCloudWriter data );
40-
public abstract Point3D_F64 getPoint(PointCloudWriter data , int i );
41-
public abstract int getColor(PointCloudWriter data , int i);
42+
43+
public abstract Point3D_F64 getPoint( PointCloudWriter data, int i );
44+
45+
public abstract int getColor( PointCloudWriter data, int i );
4246

4347
@Test
4448
void simpleXyzColor() {
4549
PointCloudWriter alg = create();
4650

47-
assertEquals(0,size(alg));
48-
alg.add(0,1,2, 345);
49-
assertEquals(1,size(alg));
50-
alg.add(2,1,3,3434);
51-
assertEquals(2,size(alg));
52-
53-
if( supportsColor ) {
51+
assertEquals(0, size(alg));
52+
alg.startPoint();
53+
alg.location(0, 1, 2);
54+
alg.color(345);
55+
alg.stopPoint();
56+
assertEquals(1, size(alg));
57+
alg.startPoint();
58+
alg.location(2, 1, 3);
59+
alg.color(3434);
60+
alg.stopPoint();
61+
assertEquals(2, size(alg));
62+
63+
if (supportsColor) {
5464
assertEquals(345, getColor(alg, 0));
5565
assertEquals(3434, getColor(alg, 1));
5666
}
5767

58-
Point3D_F64 found = getPoint(alg,1);
59-
assertEquals(2,found.x, UtilEjml.TEST_F64);
60-
assertEquals(1,found.y, UtilEjml.TEST_F64);
61-
assertEquals(3,found.z, UtilEjml.TEST_F64);
68+
Point3D_F64 found = getPoint(alg, 1);
69+
assertEquals(2, found.x, UtilEjml.TEST_F64);
70+
assertEquals(1, found.y, UtilEjml.TEST_F64);
71+
assertEquals(3, found.z, UtilEjml.TEST_F64);
6272
}
63-
6473
}
6574

6675
@Nested
@@ -72,18 +81,18 @@ public PointCloudWriter create() {
7281
}
7382

7483
@Override
75-
public int size(PointCloudWriter data) {
84+
public int size( PointCloudWriter data ) {
7685
return ((CloudArraysF32)data).cloudXyz.size/3;
7786
}
7887

7988
@Override
80-
public Point3D_F64 getPoint(PointCloudWriter data, int i) {
89+
public Point3D_F64 getPoint( PointCloudWriter data, int i ) {
8190
var list = ((CloudArraysF32)data).cloudXyz;
82-
return new Point3D_F64( list.get(i*3), list.get(i*3+1), list.get(i*3+2));
91+
return new Point3D_F64(list.get(i*3), list.get(i*3 + 1), list.get(i*3 + 2));
8392
}
8493

8594
@Override
86-
public int getColor(PointCloudWriter data, int i) {
95+
public int getColor( PointCloudWriter data, int i ) {
8796
var list = ((CloudArraysF32)data).cloudRgb;
8897
return list.get(i);
8998
}
@@ -102,18 +111,18 @@ public PointCloudWriter create() {
102111
}
103112

104113
@Override
105-
public int size(PointCloudWriter data) {
114+
public int size( PointCloudWriter data ) {
106115
return cloud.size;
107116
}
108117

109118
@Override
110-
public Point3D_F64 getPoint(PointCloudWriter data, int i) {
119+
public Point3D_F64 getPoint( PointCloudWriter data, int i ) {
111120
Point3D_F32 c = cloud.get(i);
112-
return new Point3D_F64( c.x, c.y, c.z);
121+
return new Point3D_F64(c.x, c.y, c.z);
113122
}
114123

115124
@Override
116-
public int getColor(PointCloudWriter data, int i) {
125+
public int getColor( PointCloudWriter data, int i ) {
117126
throw new RuntimeException("Not supported");
118127
}
119128
}
@@ -131,17 +140,17 @@ public PointCloudWriter create() {
131140
}
132141

133142
@Override
134-
public int size(PointCloudWriter data) {
143+
public int size( PointCloudWriter data ) {
135144
return cloud.size;
136145
}
137146

138147
@Override
139-
public Point3D_F64 getPoint(PointCloudWriter data, int i) {
148+
public Point3D_F64 getPoint( PointCloudWriter data, int i ) {
140149
return cloud.get(i);
141150
}
142151

143152
@Override
144-
public int getColor(PointCloudWriter data, int i) {
153+
public int getColor( PointCloudWriter data, int i ) {
145154
throw new RuntimeException("Not supported");
146155
}
147156
}
@@ -158,18 +167,18 @@ public PointCloudWriter create() {
158167
}
159168

160169
@Override
161-
public int size(PointCloudWriter data) {
170+
public int size( PointCloudWriter data ) {
162171
return cloud.size;
163172
}
164173

165174
@Override
166-
public Point3D_F64 getPoint(PointCloudWriter data, int i) {
175+
public Point3D_F64 getPoint( PointCloudWriter data, int i ) {
167176
Point3D_F32 c = cloud.get(i);
168-
return new Point3D_F64( c.x, c.y, c.z);
177+
return new Point3D_F64(c.x, c.y, c.z);
169178
}
170179

171180
@Override
172-
public int getColor(PointCloudWriter data, int i) {
181+
public int getColor( PointCloudWriter data, int i ) {
173182
return cloud.get(i).rgb;
174183
}
175184
}
@@ -186,19 +195,18 @@ public PointCloudWriter create() {
186195
}
187196

188197
@Override
189-
public int size(PointCloudWriter data) {
198+
public int size( PointCloudWriter data ) {
190199
return cloud.size;
191200
}
192201

193202
@Override
194-
public Point3D_F64 getPoint(PointCloudWriter data, int i) {
203+
public Point3D_F64 getPoint( PointCloudWriter data, int i ) {
195204
return cloud.get(i);
196205
}
197206

198207
@Override
199-
public int getColor(PointCloudWriter data, int i) {
208+
public int getColor( PointCloudWriter data, int i ) {
200209
return cloud.get(i).rgb;
201210
}
202211
}
203-
204212
}

0 commit comments

Comments
 (0)