Search in sources :

Example 41 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SkelFootprint method debugFindCleanProfiles.

public static void debugFindCleanProfiles(List<Line> footprint, SkelGen skelGen, ProgressMonitor m, Tweed tweed) {
    MultiMap<SuperLine, List<Prof>> profSets = new MultiMap<>();
    for (Line l : footprint) profileRuns((SuperLine) l, profSets);
    List<List<Prof>> ordered = new ArrayList<>();
    Map<List<Prof>, SuperLine> pairs = new LinkedHashMap<>();
    for (SuperLine l : profSets.keySet()) for (List<Prof> lp : profSets.get(l)) {
        pairs.put(lp, l);
        ordered.add(lp);
    }
    JSlider bunch = new JSlider(0, ordered.size() - 1);
    JButton button = new JButton("go");
    Plot plot = new Plot(bunch, button);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PaintThing.debug.clear();
            plot.toPaint.clear();
            List<Prof> ps = ordered.get(bunch.getValue());
            SuperLine sl = pairs.get(ps);
            if (sl != null && ps != null) {
                PaintThing.debug(new Color(0, 0, 0, 50), 1, ps);
                Prof clean = Prof.parameterize(ps);
                Prof c2 = new Prof(clean);
                for (Point2d p : c2) p.x += 10;
                // plot.toPaint.add( clean ) );
                PaintThing.debug(new Color(0, 170, 255), 3f, c2);
                Prof mid = ps.get(ps.size() / 2);
                tweed.enqueue(new Runnable() {

                    @Override
                    public void run() {
                        Jme3z.removeAllChildren(tweed.debug);
                        for (Prof p : ps) {
                            // p = p.moveToX0();
                            p.render(tweed, tweed.debug, ColorRGBA.Blue, (float) TweedSettings.settings.profileHSampleDist);
                        }
                        Point3d pt = mid.to3d(mid.get(0));
                        pt.y = 0;
                        Geometry geom = new Geometry("material_", clean.renderStrip(1, null));
                        Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
                        mat.setColor("Diffuse", ColorRGBA.Blue);
                        mat.setColor("Ambient", ColorRGBA.Red);
                        geom.setMaterial(mat);
                        // tweed.debug.attachChild( geom );
                        tweed.debug.updateGeometricState();
                        tweed.debug.updateModelBound();
                        tweed.gainFocus();
                    }
                });
            }
            plot.repaint();
        }
    });
    bunch.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            button.doClick();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) Plot(org.twak.utils.ui.Plot) Color(java.awt.Color) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) Material(com.jme3.material.Material) LinkedHashMap(java.util.LinkedHashMap) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Geometry(com.jme3.scene.Geometry) MultiMap(org.twak.utils.collections.MultiMap) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) SuperLine(org.twak.viewTrace.SuperLine) JSlider(javax.swing.JSlider) List(java.util.List) ArrayList(java.util.ArrayList) ChangeListener(javax.swing.event.ChangeListener)

Example 42 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SkelFootprint method cleanFootprints.

private static void cleanFootprints(HalfMesh2 mesh) {
    for (HalfFace hf : mesh.faces) for (HalfEdge e : hf.edges()) if (e.over != null && e.over.face != e.face)
        e.over = null;
    Map<HalfEdge, Double> mergePoint = new HashMap();
    Predicate<HalfEdge> badEdges = new Predicate<HalfMesh2.HalfEdge>() {

        @Override
        public boolean test(HalfEdge t) {
            if (// is edge within a single face
            t.over != null)
                // preserve as hole-marker
                return false;
            double len = t.length();
            if (t.length() < 0.2) {
                mergePoint.put(t, 0.5);
                return true;
            }
            double angleNext = t.line().absAngle(t.next.line());
            final double tol = 0.1;
            if (t.next.over == null && len < t.next.length() && angleNext > Math.PI - tol) {
                mergePoint.put(t, 0.);
                return true;
            }
            if (t.next.over == null && angleNext < tol) {
                mergePoint.put(t, 0.);
                return true;
            }
            HalfEdge prev = t.findBefore();
            double anglePrev = t.line().absAngle(prev.line());
            if (prev.over == null && len <= prev.length() && anglePrev > Math.PI - tol) {
                mergePoint.put(t, 1.);
                return true;
            }
            if (prev.over == null && anglePrev < tol) {
                mergePoint.put(t, 1.);
                return true;
            }
            return false;
        }
    };
    f: for (HalfFace f : new ArrayList<>(mesh.faces)) {
        Set<HalfEdge> togo = Streamz.stream(f.edges()).filter(badEdges).collect(Collectors.toSet());
        while (!togo.isEmpty()) {
            HalfEdge g = togo.iterator().next(), p = g.findBefore(), n = g.next;
            togo.remove(g);
            togo.remove(p);
            togo.remove(n);
            if (g.replaceByPoint(mesh, g.line().fromPPram(mergePoint.get(g))))
                continue f;
            HalfEdge pp = p.findBefore();
            Streamz.stream(pp, p, n, n.next).forEach(o -> togo.remove(o));
            Streamz.stream(pp, p, n, n.next).filter(badEdges).forEach(e -> togo.add(e));
        }
    }
    for (HalfFace f : mesh.faces) {
        Set<Point2d> seen = new HashSet<>();
        for (HalfEdge e : f) {
            if (seen.contains(e.end) && e.over == null && e.next.over == null) {
                HalfEdge n = e.next;
                Point2d edited;
                Vector2d b4 = e.line().dir(), af = n.line().dir();
                b4.normalize();
                af.normalize();
                b4.set(b4.y, -b4.x);
                af.set(af.y, -af.x);
                b4.add(af);
                b4.scale(1 / b4.length());
                edited = new Point2d(b4);
                edited.add(e.end);
                n.start = edited;
                e.end = new Point2d(edited);
            }
            seen.add(e.end);
        }
    }
}
Also used : Color(java.awt.Color) XStream(com.thoughtworks.xstream.XStream) Arrays(java.util.Arrays) FloatBuffer(java.nio.FloatBuffer) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) Type(com.jme3.scene.VertexBuffer.Type) Arrayz(org.twak.utils.collections.Arrayz) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) SkelGen(org.twak.tweed.gen.skel.SkelGen) MutableDouble(org.twak.utils.MutableDouble) ColorRGBAPainter(org.twak.viewTrace.ColorRGBAPainter) Map(java.util.Map) Cache(org.twak.utils.Cache) Material(com.jme3.material.Material) ChangeListener(javax.swing.event.ChangeListener) Streamz(org.twak.utils.collections.Streamz) Point3d(javax.vecmath.Point3d) ChangeEvent(javax.swing.event.ChangeEvent) VertexBuffer(com.jme3.scene.VertexBuffer) LoopL(org.twak.utils.collections.LoopL) Predicate(java.util.function.Predicate) Line(org.twak.utils.Line) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) Set(java.util.Set) HalfMesh2(org.twak.utils.geom.HalfMesh2) CollisionResult(com.jme3.collision.CollisionResult) Vector2d(javax.vecmath.Vector2d) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) List(java.util.List) JSlider(javax.swing.JSlider) Optional(java.util.Optional) Rainbow(org.twak.utils.ui.Rainbow) CollisionResults(com.jme3.collision.CollisionResults) Mesh(com.jme3.scene.Mesh) Geometry(com.jme3.scene.Geometry) IntStream(java.util.stream.IntStream) ActionListener(java.awt.event.ActionListener) DBSCANClusterer(org.apache.commons.math3.ml.clustering.DBSCANClusterer) Vector2f(com.jme3.math.Vector2f) HashMap(java.util.HashMap) MiniFacade(org.twak.viewTrace.facades.MiniFacade) Cach(org.twak.utils.Cach) Plot(org.twak.utils.ui.Plot) SwingConstants(javax.swing.SwingConstants) TreeSet(java.util.TreeSet) Clusterable(org.apache.commons.math3.ml.clustering.Clusterable) Tweed(org.twak.tweed.Tweed) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Mathz(org.twak.utils.Mathz) PaintThing(org.twak.utils.PaintThing) NoSuchElementException(java.util.NoSuchElementException) ProgressMonitor(javax.swing.ProgressMonitor) LinkedHashSet(java.util.LinkedHashSet) MatParam(com.jme3.material.MatParam) JButton(javax.swing.JButton) Texture2D(com.jme3.texture.Texture2D) Iterator(java.util.Iterator) MultiMap(org.twak.utils.collections.MultiMap) BufferUtils(com.jme3.util.BufferUtils) Vector3f(com.jme3.math.Vector3f) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) MegaFacade(org.twak.tweed.gen.ProfileGen.MegaFacade) ModeCollector(org.twak.viewTrace.ModeCollector) JOptionPane(javax.swing.JOptionPane) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) Jme3z(org.twak.siteplan.jme.Jme3z) Ray(com.jme3.math.Ray) SuperLine(org.twak.viewTrace.SuperLine) LineHeight(org.twak.viewTrace.facades.LineHeight) Format(com.jme3.scene.VertexBuffer.Format) Cluster(org.apache.commons.math3.ml.clustering.Cluster) ColorRGBA(com.jme3.math.ColorRGBA) FileReader(java.io.FileReader) ImageRaster(com.jme3.texture.image.ImageRaster) Comparator(java.util.Comparator) Collections(java.util.Collections) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) MutableDouble(org.twak.utils.MutableDouble) Predicate(java.util.function.Predicate) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) HalfMesh2(org.twak.utils.geom.HalfMesh2) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 43 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SkelFootprint method boundMesh.

public static HalfMesh2 boundMesh(List<Line> footprint) {
    double[] minMax = minMax(10, footprint);
    HalfMesh2.Builder builder = new HalfMesh2.Builder(SuperEdge.class, SuperFace.class);
    builder.newPoint(new Point2d(minMax[0], minMax[3]));
    builder.newPoint(new Point2d(minMax[1], minMax[3]));
    builder.newPoint(new Point2d(minMax[1], minMax[2]));
    builder.newPoint(new Point2d(minMax[0], minMax[2]));
    builder.newFace();
    HalfMesh2 mesh = builder.done();
    return mesh;
}
Also used : Point2d(javax.vecmath.Point2d) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) HalfMesh2(org.twak.utils.geom.HalfMesh2)

Example 44 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SkelFootprint method dbgShowProfiles.

private void dbgShowProfiles(HalfMesh2 mesh, List<Prof> globalProfs, Map<SuperEdge, double[]> profFit, String name) {
    Node n = new Node();
    Jme3z.removeAllChildren(n);
    int colI = 0;
    for (HalfFace f : mesh) {
        ColorRGBA col = Jme3z.toJme(Rainbow.getColour(colI++));
        colI = colI % 6;
        Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
        mat.setColor("Diffuse", col);
        mat.setColor("Ambient", col);
        mat.setBoolean("UseMaterialColors", true);
        if (true) {
            Loop<Point3d> loop = new Loop<>();
            for (HalfEdge e : f) loop.append(new Point3d(e.start.x, 0, e.start.y));
            MeshBuilder mb = new MeshBuilder();
            mb.add(loop.singleton(), null, false);
            Geometry g = new Geometry("floorplan", mb.getMesh());
            g.setMaterial(mat);
            n.attachChild(g);
        }
        for (HalfEdge e : f) {
            SuperEdge se = (SuperEdge) e;
            Prof bestProf = null;
            if (globalProfs == null)
                bestProf = se.prof;
            else {
                // if (se.profLine != null) {
                // 
                // SuperLine sl = ((SuperLine)se.profLine);
                // MegaFacade mf = (MegaFacade) sl.properties.get( MegaFacade.class.getName() );
                // 
                // List<Prof> pfs = mf.getTween( se.start, se.end, 0.3 );
                // 
                // if (!pfs.isEmpty())
                // bestProf = Prof.parameterize( sl, pfs );
                // else {
                // bestProf = clean.get( 0 );
                // double bestScore = Double.MAX_VALUE;
                // 
                // for ( Prof c : clean ) {
                // 
                // double score = 0;
                // boolean good = false;
                // for ( Prof r : mf.getTween( se.start, se.end, 0.3 ) ) {
                // score += c.distance( r, true, false, true );
                // good = true;
                // }
                // if ( good && score < bestScore ) {
                // bestScore = score;
                // bestProf = c;
                // }
                // 
                // }
                // }
                // 
                // 
                // }
                // if (bestProf)
                // ((SuperLine))
                // 
                double[] fitV = profFit.get(se);
                if (fitV == null)
                    continue;
                double bestScore = Double.MAX_VALUE;
                for (int ii = 0; ii < fitV.length; ii++) {
                    double d = fitV[ii];
                    if (d < bestScore) {
                        bestScore = d;
                        bestProf = globalProfs.get(ii);
                    }
                }
            // 
            // double bestScore = Double.MAX_VALUE;
            // 
            // for ( int ii = 0; ii < fitV.length; ii++ ) {
            // double d = fitV[ ii ];
            // if ( d < bestScore ) {
            // bestScore = d;
            // bestProf = globalProfs.get( ii );
            // }
            // }
            // if (false)
            // se.prof = bestProf;
            }
            if (bestProf != null) {
                Geometry g = new Geometry();
                Point3d cen = Pointz.to3(se.line().fromPPram(0.5));
                Prof goodOrientation = Prof.buildProfile(Pointz.to3(se.line()), cen);
                for (Point2d p : bestProf) goodOrientation.add(p);
                g.setMesh(goodOrientation.renderStrip(1.5, cen));
                g.setMaterial(mat);
                n.attachChild(g);
                g.updateGeometricState();
                g.updateModelBound();
            }
        }
    }
    skelGen.tweed.frame.addGen(new JmeGen(name, tweed, n), false);
}
Also used : Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) MeshBuilder(org.twak.siteplan.jme.MeshBuilder)

Example 45 with Point2d

use of javax.vecmath.Point2d in project Smiles2Monomers by yoann-dufresne.

the class MonomersSerialization method deserializeObject.

private void deserializeObject(Monomer mono, ObjectInputStream ois) {
    try {
        int nbAtoms = ois.readInt();
        if (nbAtoms != mono.getMolecule().getAtomCount()) {
            System.err.println("Bad serialized value for atom count in " + mono.getCode());
        }
        for (IAtom a : mono.getMolecule().atoms()) {
            Point2d p = new Point2d(ois.readDouble(), ois.readDouble());
            a.setPoint2d(p);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Point2d(javax.vecmath.Point2d) IOException(java.io.IOException) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

Point2d (javax.vecmath.Point2d)84 Line (org.twak.utils.Line)37 ArrayList (java.util.ArrayList)29 Point3d (javax.vecmath.Point3d)27 List (java.util.List)18 Vector2d (javax.vecmath.Vector2d)17 SuperLine (org.twak.viewTrace.SuperLine)17 File (java.io.File)15 Vector3d (javax.vecmath.Vector3d)15 Map (java.util.Map)14 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)14 HashMap (java.util.HashMap)13 Loop (org.twak.utils.collections.Loop)13 Collectors (java.util.stream.Collectors)12 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 Tweed (org.twak.tweed.Tweed)11 Matrix4d (javax.vecmath.Matrix4d)10 LinearForm (org.twak.utils.geom.LinearForm)10