You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. A function creating a HMesh2D from a list of polygons and an array of 2D vertex coordinates
publicstaticHMesh2DcreateHMesh2D(int[][] faces, double[][] vertexCoords) {
// Create face sourceFaceSourcefaceSource = newFaceSource(faces);
// Create vertex coordinates sourceCoord2DSourcecoord2DSource = newCoord2DSource(vertexCoords);
// Build the half-edge data structure from the faces and the coordinatesreturnfaceSource.toHMesh(coord2DSource).orElseThrow(IllegalStateException::new);
}
3. Assign values to polygons according to values attached to their vertices
// The polygons as arrays of indices to vertices: int[][] faces = ...;
// The values attached to the verticesdouble[] vertexValues = ...
// Create a faces sourceFaceSourcefaceSource = newFaceSource(faces);
// Create a converter to HMeshToHMeshConverterconverter = newToHMeshConverter();
// Build the half-edge data structure from the facesHConversion<HMesh> conversion = converter.convert(faceSource)
.orElseThrow(RuntimeException::new);
// Get the created half-edge data structureHMeshmesh = conversion.mesh();
// Map the original vertex values to the half-edge data structure's verticesHDData<HVertex> meshVertexValues = conversion.meshVertexDoubleData(i -> vertexValues[i]);
// Create a data collection for the half-edge data structure's facesHDData<HFace> meshFaceValues = mesh.createFaceDoubleData();
// Set each face value as the sum of the values associated to the vertices on its bordermeshFaceValues.setAll(f -> {
doublesum = 0;
// Compute the sum of the value assigned to the vertices of the face borderfor (HVertexv : f.vertices()) {
sum += meshVertexValues.get(v);
}
// Assign the computed value to the facereturnsum;
});
4. Assign values to vertices according to values attached to surrounding polygons
// The polygons as arrays of indices to vertices: int[][] faces = ...;
// The values attached to the polygonsdouble[] faceValues = ...
// Create a faces sourceFaceSourcefaceSource = newFaceSource(faces);
// Create a converter to HMeshToHMeshConverterconverter = newToHMeshConverter();
// Build the half-edge data structure from the facesHConversion<HMesh> conversion = converter.convert(faceSource)
.orElseThrow(RuntimeException::new);
// Get the created half-edge data structureHMeshmesh = conversion.mesh();
// Map the original face values to the half-edge data structure's facesHDData<HFace> meshFaceValues = conversion.meshFaceDoubleData(i -> faceValues[i]);
// Create a data collection for the half-edge data structure's verticesHDData<HVertex> meshVertexValues = mesh.createVertexDoubleData();
// Set each vertex value as the average of the values associated to its neighboring polygonsmeshVertexValues.setAll(vertex -> {
doublemean = 0;
intcount = 0;
// Iterate on all the polygons connected to the vertexfor (HFaceface : vertex.outgoingEdges().map(HEdge::face)) {
mean += meshFaceValues.get(face);
count += 1;
}
// A vertex always connected to several faces, so count > 0returnmean / count;
});
5. Remove from a polygonal mesh all vertices whose associated value is superior to a limit
// The polygons as arrays of indices to vertices: int[][] faces = ...;
// The values attached to the verticesint[] vertexValues = ...
// The limitintlimit = ...
// Create a faces sourceFaceSourcefaceSource = newFaceSource(faces);
// Create a converter to HMeshToHMeshConverterconverter = newToHMeshConverter();
// Build the half-edge data structure from the facessourcesHConversion<HMesh> conversion = converter.convert(faceSource)
.orElseThrow(RuntimeException::new);
// Get the created half-edge data structureHMeshmesh = conversion.mesh();
// Map the original vertex weights to the half-edge data structure's verticesHIData<HVertex> meshVertexValues = conversion.meshVertexIntData(i -> vertexValues[i]);
// Get the vertices associated with a value > limitList<HVertex> verticesToRemove = mesh.vertices()
.filter(v -> meshVertexValues.get(v) > limit)
.collect(Collectors.toList());
for (HVertexvertex : verticesToRemove) {
mesh.removeVertex(vertex);
}