Commit 563f5d26 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch 'remove-glyphs-visitor-impl' into 'master'

Remove GlyphsVisitorImpl

See merge request grp-fidentis/analyst2!459
parents 3dd6358a 0ff68999
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -9,8 +9,13 @@ import java.util.List;

/**
 * Stateless services for glyphs.
 * It is a wrapper to the stateful implementation in {@link cz.fidentis.analyst.engines.glyphs.GlyphsVisitor}.
 * <p>
 *     Based on
 *     <a href="https://ieeexplore.ieee.org/document/597794">V. Interrante et al.: Conveying the 3D shape of smoothly curving transparent surfaces via texture</a>,
 *     1997, doi: 10.1109/2945.597794
 * </p>
 *
 * @author Ondrej Simecek
 * @author Radek Oslejsek
 */
public interface GlyphServices {
+23 −9
Original line number Diff line number Diff line
package cz.fidentis.analyst.engines.glyphs;

import cz.fidentis.analyst.data.mesh.Curvature;
import cz.fidentis.analyst.data.mesh.MeshFacet;
import cz.fidentis.analyst.data.mesh.MeshModel;
import cz.fidentis.analyst.data.mesh.MeshPoint;
import cz.fidentis.analyst.data.shapes.Glyph;
import cz.fidentis.analyst.engines.glyphs.impl.GlyphsVisitorImpl;
import cz.fidentis.analyst.engines.curvature.CurvatureServices;
import cz.fidentis.analyst.engines.sampling.PointSamplingServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -16,6 +21,13 @@ import java.util.List;
@Service
public class GlyphServicesImpl implements GlyphServices {

    private final PointSamplingServices pointSamplingServices;

    @Autowired
    public GlyphServicesImpl(PointSamplingServices pointSamplingServices) {
        this.pointSamplingServices = pointSamplingServices;
    }

    @Override
    public List<Glyph> calculateGlyphSamples(MeshFacet facet, GlyphsConfig config) {
        return calculateGlyphs(Collections.singleton(facet), config);
@@ -28,15 +40,17 @@ public class GlyphServicesImpl implements GlyphServices {

    @Override
    public List<Glyph> calculateGlyphs(Collection<MeshFacet> facets, GlyphsConfig config) {
        GlyphsVisitor visitor = getVisitor(config);
        facets.forEach(facet -> visitor.visitMeshFacet(facet));
        List<Glyph> glyphs = visitor.getGlyphs();
        visitor.dispose();
        return glyphs;
        List<Glyph> glyphs = new ArrayList<>();
        List<MeshPoint> samples = pointSamplingServices.sample(facets, config.pointSamplingConfig());

        for (MeshPoint sample : samples) {
            Curvature curvature = CurvatureServices.compute(sample, facets);
            Glyph glyph = (curvature == null)
                    ? new Glyph(sample.getPosition(), sample.getNormal())
                    : new Glyph(sample.getPosition(), sample.getNormal(), curvature.maxCurvatureDir(), curvature.minCurvatureDir());
            glyphs.add(glyph);
        }

    private GlyphsVisitor getVisitor(GlyphsConfig config) {
        return new GlyphsVisitorImpl(config.pointSamplingConfig());
        return glyphs;
    }

}
+0 −27
Original line number Diff line number Diff line
package cz.fidentis.analyst.engines.glyphs;

import cz.fidentis.analyst.data.mesh.MeshVisitor;
import cz.fidentis.analyst.data.shapes.Glyph;

import java.util.List;

/**
 * Visitor, which calculate suitable position and orientation of glyphs from visited meshes.
 * It uses given sub-sampling strategy to locate glyphs.
 * <p>
 *     Based on
 *     <a href="https://ieeexplore.ieee.org/document/597794">V. Interrante et al.: Conveying the 3D shape of smoothly curving transparent surfaces via texture</a>,
 *     1997, doi: 10.1109/2945.597794
 * </p>
 *
 * @author Ondrej Simecek
 * @author Radek Oslejsek
 */
public interface GlyphsVisitor extends MeshVisitor {

    /**
     * Returns computed glyphs.
     * @return computed glyphs
     */
    List<Glyph> getGlyphs();
}
+0 −59
Original line number Diff line number Diff line
package cz.fidentis.analyst.engines.glyphs.impl;

import cz.fidentis.analyst.data.mesh.Curvature;
import cz.fidentis.analyst.data.mesh.MeshFacet;
import cz.fidentis.analyst.data.mesh.MeshPoint;
import cz.fidentis.analyst.data.shapes.Glyph;
import cz.fidentis.analyst.engines.AcaGeometryEngines;
import cz.fidentis.analyst.engines.curvature.CurvatureServices;
import cz.fidentis.analyst.engines.glyphs.GlyphsVisitor;
import cz.fidentis.analyst.engines.sampling.PointSamplingConfig;
import cz.fidentis.analyst.engines.sampling.PointSamplingStatefulService;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * The implementation of glyphs visitor interface.
 *
 * @author Ondrej Simecek
 */
public class GlyphsVisitorImpl implements GlyphsVisitor {

    private final List<MeshFacet> facets = new ArrayList<>();

    private final PointSamplingStatefulService pointSamplingServices = AcaGeometryEngines.getInstance().getBean(PointSamplingStatefulService.class);

    /**
     * Constructor.
     * @param samplingConfig Subsampling configuration. Must not be {@code null}
     */
    public GlyphsVisitorImpl(PointSamplingConfig samplingConfig) {
        pointSamplingServices.setSampling(Objects.requireNonNull(samplingConfig));
    }

    @Override
    public void visitMeshFacet(MeshFacet facet) {
        facets.add(facet);
        pointSamplingServices.sample(facet);
    }

    @Override
    public List<Glyph> getGlyphs() {
        List<Glyph> glyphs = new ArrayList<>();
        for (MeshPoint sample : pointSamplingServices.getResult()) {
            Curvature curvature = CurvatureServices.compute(sample, facets);
            Glyph glyph = (curvature == null)
                    ? new Glyph(sample.getPosition(), sample.getNormal())
                    : new Glyph(sample.getPosition(), sample.getNormal(), curvature.maxCurvatureDir(), curvature.minCurvatureDir());
            glyphs.add(glyph);
        }
        return glyphs;
    }

    @Override
    public void dispose(){
        pointSamplingServices.dispose();
    }
}