Skip to content

Commit d4a4c11

Browse files
authored
Merge pull request #3 from tinevez/int-interface
Rename the triangles and vertices interface size() method to return an int.
2 parents f187778 + 115c9ee commit d4a4c11

19 files changed

+96
-122
lines changed

src/main/java/net/imglib2/mesh/Meshes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static RealPoint center( final Mesh m )
6969
p.move( v );
7070

7171
for ( int d = 0; d < 3; d++ )
72-
p.setPosition( p.getDoublePosition( d ) / m.vertices().size(), d );
72+
p.setPosition( p.getDoublePosition( d ) / m.vertices().sizel(), d );
7373

7474
return p;
7575
}
@@ -366,7 +366,7 @@ public static Iterable< BufferMesh > connectedComponents( final Mesh mesh )
366366
public static void scale( final Mesh mesh, final double[] scale )
367367
{
368368
final Vertices vertices = mesh.vertices();
369-
final long nVertices = vertices.size();
369+
final long nVertices = vertices.sizel();
370370
for ( long i = 0; i < nVertices; i++ )
371371
{
372372
final double x = vertices.x( i );

src/main/java/net/imglib2/mesh/alg/MeshConnectedComponents.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
/**
2020
* Connected components algorithm for meshes.
21-
*
21+
*
2222
* @author Jean-Yves Tinevez
2323
*
2424
*/
@@ -27,7 +27,7 @@ public class MeshConnectedComponents
2727

2828
/**
2929
* Returns the number of connected components in this mesh.
30-
*
30+
*
3131
* @param mesh
3232
* the mesh.
3333
* @return the number of connected components.
@@ -36,7 +36,7 @@ public static final int n( final Mesh mesh )
3636
{
3737
final Triangles triangles = mesh.triangles();
3838
final Vertices vertices = mesh.vertices();
39-
final int nVertices = ( int ) vertices.size();
39+
final int nVertices = vertices.size();
4040

4141
final TIntObjectHashMap< TIntArrayList > map = triangleMap( mesh );
4242
final BitSet visited = new BitSet( nVertices );
@@ -116,15 +116,15 @@ private static final boolean visit( final int v, final BitSet visited, final TIn
116116

117117
/**
118118
* Returns the map of vertex id to the list of triangles they belong to.
119-
*
119+
*
120120
* @param mesh
121121
*/
122122
private static final TIntObjectHashMap< TIntArrayList > triangleMap( final Mesh mesh )
123123
{
124124
final Triangles triangles = mesh.triangles();
125-
final int nTriangles = ( int ) triangles.size();
125+
final int nTriangles = triangles.size();
126126
final Vertices vertices = mesh.vertices();
127-
final int nVertices = ( int ) vertices.size();
127+
final int nVertices = vertices.size();
128128

129129
final TIntObjectHashMap< TIntArrayList > map = new TIntObjectHashMap<>( nVertices );
130130
for ( int tid = 0; tid < nTriangles; tid++ )
@@ -166,7 +166,7 @@ public MyCCIterator( final Mesh mesh )
166166
{
167167
this.mesh = mesh;
168168
this.map = triangleMap( mesh );
169-
this.nVertices = ( int ) mesh.vertices().size();
169+
this.nVertices = mesh.vertices().size();
170170
this.visited = new BitSet( nVertices );
171171
this.currentStartVertex = 0;
172172
this.next = prefetch();

src/main/java/net/imglib2/mesh/alg/MeshCursor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public long getLongPosition( final int d )
217217
@Override
218218
public Cursor< T > copyCursor()
219219
{
220-
final BufferMesh dest = new BufferMesh( mesh.vertices().isize(), mesh.triangles().isize() );
220+
final BufferMesh dest = new BufferMesh( mesh.vertices().size(), mesh.triangles().size() );
221221
Meshes.copy( mesh, dest );
222222
return new MeshCursor<>( ra.copyRandomAccess(), dest, cal.clone() );
223223
}

src/main/java/net/imglib2/mesh/alg/RemoveDuplicateVertices.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
* %%
88
* Redistribution and use in source and binary forms, with or without
99
* modification, are permitted provided that the following conditions are met:
10-
*
10+
*
1111
* 1. Redistributions of source code must retain the above copyright notice,
1212
* this list of conditions and the following disclaimer.
1313
* 2. Redistributions in binary form must reproduce the above copyright notice,
1414
* this list of conditions and the following disclaimer in the documentation
1515
* and/or other materials provided with the distribution.
16-
*
16+
*
1717
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1818
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -47,7 +47,7 @@ public class RemoveDuplicateVertices
4747
public static Mesh calculate( final Mesh mesh, final int precision )
4848
{
4949
final Map< String, IndexedVertex > vertices = new LinkedHashMap<>();
50-
final int[][] triangles = new int[ ( int ) mesh.triangles().size() ][ 3 ];
50+
final int[][] triangles = new int[ mesh.triangles().size() ][ 3 ];
5151

5252
int trianglesCount = 0;
5353
for ( final net.imglib2.mesh.obj.Triangle triangle : mesh.triangles() )

src/main/java/net/imglib2/mesh/alg/SimplifyMesh.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
* %%
88
* Redistribution and use in source and binary forms, with or without
99
* modification, are permitted provided that the following conditions are met:
10-
*
10+
*
1111
* 1. Redistributions of source code must retain the above copyright notice,
1212
* this list of conditions and the following disclaimer.
1313
* 2. Redistributions in binary form must reproduce the above copyright notice,
1414
* this list of conditions and the following disclaimer in the documentation
1515
* and/or other materials provided with the distribution.
16-
*
16+
*
1717
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1818
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -237,7 +237,7 @@ private void readMesh()
237237
vertices.clear();
238238
refs.clear();
239239

240-
final Point[] meshVerts = new Point[ ( int ) inMesh.vertices().size() ];
240+
final Point[] meshVerts = new Point[ inMesh.vertices().size() ];
241241
final Iterator< net.imglib2.mesh.obj.Vertex > iterator = inMesh.vertices().iterator();
242242
for ( int i = 0; i < inMesh.vertices().size(); i++ )
243243
{
@@ -288,7 +288,7 @@ private void readMesh()
288288
public Mesh simplify( final float target_percent, final double agressiveness )
289289
{
290290

291-
final int target_count = ( int ) ( inMesh.triangles().size() * target_percent );
291+
final int target_count = ( int ) ( inMesh.triangles().sizel() * target_percent );
292292
return simplify( target_count, agressiveness );
293293
}
294294

@@ -315,7 +315,7 @@ private Mesh simplify( final int target_count, final double agressiveness )
315315
* System.out.println(String.format("Simplify Target: %d of %d (%d%%)",
316316
* target_count, triangles.size(), target_count * 100 /
317317
* triangles.size()));
318-
*
318+
*
319319
* final long timeStart = System.currentTimeMillis();
320320
*/
321321

@@ -435,7 +435,7 @@ private Mesh simplify( final int target_count, final double agressiveness )
435435
// ready
436436
/*
437437
* long timeEnd = System.currentTimeMillis();
438-
*
438+
*
439439
* System.out.println(String.
440440
* format("Simplify: %d/%d %d%% removed in %d ms", triangle_count -
441441
* deleted_triangles, triangle_count, deleted_triangles * 100 /

src/main/java/net/imglib2/mesh/alg/TaubinSmoothing.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* <p>
1414
* Adapted by the Javascript code of mykolalysenko, MIT license.
1515
* https://github.com/mikolalysenko/taubin-smooth/blob/master/smooth.js
16-
*
16+
*
1717
* @author Jean-Yves Tinevez
1818
* @see <a href="https://doi.org/10.1109/ICCV.1995.466848">Taubin, G. “Curve and
1919
* Surface Smoothing without Shrinkage.” In Proceedings of IEEE
@@ -26,7 +26,7 @@ public class TaubinSmoothing
2626
/**
2727
* Smooth the specified mesh using the Taubin smoothing algorithm, with
2828
* default parameters.
29-
*
29+
*
3030
* @param mesh
3131
* the mesh to smooth.
3232
* @return a new smoothed mesh.
@@ -39,7 +39,7 @@ public static final BufferMesh smooth( final Mesh mesh )
3939
/**
4040
* Smooth the specified mesh using the Taubin smoothing algorithm, using
4141
* cotangent weights.
42-
*
42+
*
4343
* @param mesh
4444
* the mesh to smooth.
4545
* @param iters
@@ -66,7 +66,7 @@ public static final BufferMesh smooth( final Mesh mesh, final int iters, final d
6666

6767
/**
6868
* Smooth the specified mesh using the Taubin smoothing algorithm.
69-
*
69+
*
7070
* @param mesh
7171
* the mesh to smooth.
7272
* @param iters
@@ -85,8 +85,8 @@ public static final BufferMesh smooth( final Mesh mesh, final int iters, final d
8585
public static final BufferMesh smooth( final Mesh mesh, final int iters, final double lambda, final double mu,
8686
final TaubinWeightType weightType )
8787
{
88-
final int nvs = ( int ) mesh.vertices().size();
89-
final int nts = ( int ) mesh.triangles().size();
88+
final int nvs = mesh.vertices().size();
89+
final int nts = mesh.triangles().size();
9090
final BufferMesh meshA = new BufferMesh( nvs, nts );
9191
Meshes.copy( mesh, meshA );
9292
final BufferMesh meshB = new BufferMesh( nvs, nts );
@@ -114,7 +114,7 @@ public static final BufferMesh smooth( final Mesh mesh, final int iters, final d
114114
throw new IllegalArgumentException( "Unhandled weight type: " + weightType );
115115
}
116116

117-
final BufferMesh out = new BufferMesh( ( int ) meshA.vertices().size(), ( int ) meshA.triangles().size() );
117+
final BufferMesh out = new BufferMesh( meshA.vertices().size(), meshA.triangles().size() );
118118
Meshes.calculateNormals( meshA, out );
119119
return out;
120120
}
@@ -123,8 +123,8 @@ private static void smoothStepCotangent( final Triangles triangles, final Buffer
123123
final double[] trace, final double weigth )
124124
{
125125

126-
final int nvs = ( int ) source.vertices().size();
127-
final int nts = ( int ) source.triangles().size();
126+
final int nvs = source.vertices().size();
127+
final int nts = source.triangles().size();
128128

129129
// Zero target.
130130
for ( int i = 0; i < nvs; i++ )
@@ -205,8 +205,8 @@ private static void smoothStepNaive( final Triangles triangles, final BufferMesh
205205
final double[] trace, final double weigth )
206206
{
207207

208-
final int nvs = ( int ) source.vertices().size();
209-
final int nts = ( int ) source.triangles().size();
208+
final int nvs = source.vertices().size();
209+
final int nts = source.triangles().size();
210210

211211
// Zero target.
212212
for ( int i = 0; i < nvs; i++ )

src/main/java/net/imglib2/mesh/alg/zslicer/ZSlicer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public static List< Slice > slices( final Mesh mesh, final double[] zs, final do
6767
final Triangles triangles = mesh.triangles();
6868
final Vertices vertices = mesh.vertices();
6969

70-
final double[] minZs = new double[ ( int ) triangles.size() ];
71-
final double[] maxZs = new double[ ( int ) triangles.size() ];
70+
final double[] minZs = new double[ triangles.size() ];
71+
final double[] maxZs = new double[ triangles.size() ];
7272
for ( int t = 0; t < triangles.size(); t++ )
7373
{
7474
final long v0 = triangles.vertex0( t );
@@ -256,7 +256,7 @@ public static Slice slice( final Mesh mesh, final double z, final double zScale
256256
final Vertices vertices = mesh.vertices();
257257

258258
final TIntArrayList intersecting = new TIntArrayList();
259-
for ( long f = 0; f < triangles.size(); f++ )
259+
for ( long f = 0; f < triangles.sizel(); f++ )
260260
{
261261
final long v0 = triangles.vertex0( f );
262262
final long v1 = triangles.vertex1( f );

src/main/java/net/imglib2/mesh/io/ply/PLYMeshIO.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ public static final byte[] writeBinary( final Mesh mesh )
224224
"format binary_little_endian 1.0\n" + //
225225
"comment This binary PLY mesh was created with imagej-mesh.\n";
226226
final String vertexHeader = "" + //
227-
"element vertex " + mesh.vertices().size() + "\n" + //
227+
"element vertex " + mesh.vertices().sizel() + "\n" + //
228228
"property float x\nproperty float y\nproperty float z\n" + //
229229
"property float nx\nproperty float ny\nproperty float nz\n" + //
230230
"property float u\nproperty float v\n";
231-
final String triangleHeader = "element face " + mesh.triangles().size()
231+
final String triangleHeader = "element face " + mesh.triangles().sizel()
232232
+ "\nproperty list uchar int vertex_index\n";
233233
final String endHeader = "end_header\n";
234234
final long bytes = header.getBytes().length + //
235235
vertexHeader.getBytes().length + triangleHeader.getBytes().length + endHeader.getBytes().length
236-
+ mesh.vertices().size() * vertexBytes + //
237-
mesh.triangles().size() * triangleBytes;
236+
+ mesh.vertices().sizel() * vertexBytes + //
237+
mesh.triangles().sizel() * triangleBytes;
238238
if ( bytes > Integer.MAX_VALUE )
239239
throw new IllegalArgumentException( "Mesh data too large: " + bytes );
240240

@@ -246,12 +246,12 @@ public static final byte[] writeBinary( final Mesh mesh )
246246
buffer.put( endHeader.getBytes() );
247247

248248
// Do not populate file if there are no vertices
249-
if ( mesh.vertices().size() == 0 )
249+
if ( mesh.vertices().sizel() == 0 )
250250
return buffer.array();
251251

252252
// Write vertices
253253
final TLongIntHashMap refToVertId = //
254-
new TLongIntHashMap( ( int ) mesh.vertices().size() );
254+
new TLongIntHashMap( mesh.vertices().size() );
255255
int vertId = 0;
256256
for ( final Vertex v : mesh.vertices() )
257257
{
@@ -282,21 +282,21 @@ public static final byte[] writeBinary( final Mesh mesh )
282282
public static final byte[] writeAscii( final Mesh mesh ) throws IOException
283283
{
284284
final String header = "ply\nformat ascii 1.0\ncomment This binary PLY mesh was created with imagej-mesh.\n";
285-
final String vertexHeader = "element vertex " + mesh.vertices().size()
285+
final String vertexHeader = "element vertex " + mesh.vertices().sizel()
286286
+ "\nproperty float x\nproperty float y\nproperty float z\nproperty float nx\nproperty float ny\nproperty float nz\nproperty float u\n property float v\n";
287-
final String triangleHeader = "element face " + mesh.triangles().size()
287+
final String triangleHeader = "element face " + mesh.triangles().sizel()
288288
+ "\nproperty list uchar int vertex_index\n";
289289
final String endHeader = "end_header\n";
290290

291291
// TODO: Fail fast more robustly if mesh is too large.
292292
// But need to modify the API to not return a byte[].
293-
if ( mesh.vertices().size() > Integer.MAX_VALUE )
293+
if ( mesh.vertices().sizel() > Integer.MAX_VALUE )
294294
throw new IllegalArgumentException( "Too many vertices: " + //
295-
mesh.vertices().size() );
295+
mesh.vertices().sizel() );
296296

297-
if ( mesh.triangles().size() > Integer.MAX_VALUE )
297+
if ( mesh.triangles().sizel() > Integer.MAX_VALUE )
298298
throw new IllegalArgumentException( "Too many triangles: " + //
299-
mesh.triangles().size() );
299+
mesh.triangles().sizel() );
300300

301301
final ByteArrayOutputStream os = new ByteArrayOutputStream();
302302

@@ -308,14 +308,14 @@ public static final byte[] writeAscii( final Mesh mesh ) throws IOException
308308
writer.write( endHeader );
309309

310310
// Do not populate file if there are no vertices
311-
if ( mesh.vertices().size() == 0 )
311+
if ( mesh.vertices().sizel() == 0 )
312312
{
313313
writer.flush();
314314
return os.toByteArray();
315315
}
316316

317317
// Write vertices
318-
final TLongIntHashMap refToVertId = new TLongIntHashMap( ( int ) mesh.vertices().size() );
318+
final TLongIntHashMap refToVertId = new TLongIntHashMap( mesh.vertices().size() );
319319
int vertId = 0;
320320
for ( final Vertex v : mesh.vertices() )
321321
{

src/main/java/net/imglib2/mesh/io/stl/STLMeshIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static final void read( final Mesh mesh, final byte[] data )
8888
/** Writes the facets into a byte[] that can then be saved into a file */
8989
public static final byte[] write( final Mesh mesh )
9090
{
91-
final long facetCount = mesh == null ? 0 : mesh.triangles().size();
91+
final long facetCount = mesh == null ? 0 : mesh.triangles().sizel();
9292
final long longBytes = HEADER_BYTES + COUNT_BYTES + facetCount * FACET_BYTES;
9393
if ( longBytes > Integer.MAX_VALUE )
9494
{ throw new IllegalArgumentException( "Too many triangles: " + facetCount ); }

0 commit comments

Comments
 (0)