001//
002// This file is auto-generated. Please don't modify it!
003//
004package org.opencv.imgproc;
005
006import java.util.ArrayList;
007import java.util.List;
008import org.opencv.core.Mat;
009import org.opencv.core.MatOfFloat4;
010import org.opencv.core.MatOfFloat6;
011import org.opencv.core.MatOfInt;
012import org.opencv.core.MatOfPoint2f;
013import org.opencv.core.Point;
014import org.opencv.core.Rect;
015import org.opencv.utils.Converters;
016
017// C++: class Subdiv2D
018
019public class Subdiv2D {
020
021    protected final long nativeObj;
022    protected Subdiv2D(long addr) { nativeObj = addr; }
023
024    public long getNativeObjAddr() { return nativeObj; }
025
026    // internal usage only
027    public static Subdiv2D __fromPtr__(long addr) { return new Subdiv2D(addr); }
028
029    // C++: enum <unnamed>
030    public static final int
031            PTLOC_ERROR = -2,
032            PTLOC_OUTSIDE_RECT = -1,
033            PTLOC_INSIDE = 0,
034            PTLOC_VERTEX = 1,
035            PTLOC_ON_EDGE = 2,
036            NEXT_AROUND_ORG = 0x00,
037            NEXT_AROUND_DST = 0x22,
038            PREV_AROUND_ORG = 0x11,
039            PREV_AROUND_DST = 0x33,
040            NEXT_AROUND_LEFT = 0x13,
041            NEXT_AROUND_RIGHT = 0x31,
042            PREV_AROUND_LEFT = 0x20,
043            PREV_AROUND_RIGHT = 0x02;
044
045
046    //
047    // C++:   cv::Subdiv2D::Subdiv2D()
048    //
049
050    /**
051     * creates an empty Subdiv2D object.
052     *     To create a new empty Delaunay subdivision you need to use the #initDelaunay function.
053     */
054    public Subdiv2D() {
055        nativeObj = Subdiv2D_0();
056    }
057
058
059    //
060    // C++:   cv::Subdiv2D::Subdiv2D(Rect rect)
061    //
062
063    /**
064     *
065     *
066     *     @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.
067     *
068     *     The function creates an empty Delaunay subdivision where 2D points can be added using the function
069     *     insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime
070     *     error is raised.
071     */
072    public Subdiv2D(Rect rect) {
073        nativeObj = Subdiv2D_1(rect.x, rect.y, rect.width, rect.height);
074    }
075
076
077    //
078    // C++:  void cv::Subdiv2D::initDelaunay(Rect rect)
079    //
080
081    /**
082     * Creates a new empty Delaunay subdivision
083     *
084     *     @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.
085     */
086    public void initDelaunay(Rect rect) {
087        initDelaunay_0(nativeObj, rect.x, rect.y, rect.width, rect.height);
088    }
089
090
091    //
092    // C++:  int cv::Subdiv2D::insert(Point2f pt)
093    //
094
095    /**
096     * Insert a single point into a Delaunay triangulation.
097     *
098     *     @param pt Point to insert.
099     *
100     *     The function inserts a single point into a subdivision and modifies the subdivision topology
101     *     appropriately. If a point with the same coordinates exists already, no new point is added.
102     *     @return the ID of the point.
103     *
104     *     <b>Note:</b> If the point is outside of the triangulation specified rect a runtime error is raised.
105     */
106    public int insert(Point pt) {
107        return insert_0(nativeObj, pt.x, pt.y);
108    }
109
110
111    //
112    // C++:  void cv::Subdiv2D::insert(vector_Point2f ptvec)
113    //
114
115    /**
116     * Insert multiple points into a Delaunay triangulation.
117     *
118     *     @param ptvec Points to insert.
119     *
120     *     The function inserts a vector of points into a subdivision and modifies the subdivision topology
121     *     appropriately.
122     */
123    public void insert(MatOfPoint2f ptvec) {
124        Mat ptvec_mat = ptvec;
125        insert_1(nativeObj, ptvec_mat.nativeObj);
126    }
127
128
129    //
130    // C++:  int cv::Subdiv2D::locate(Point2f pt, int& edge, int& vertex)
131    //
132
133    /**
134     * Returns the location of a point within a Delaunay triangulation.
135     *
136     *     @param pt Point to locate.
137     *     @param edge Output edge that the point belongs to or is located to the right of it.
138     *     @param vertex Optional output vertex the input point coincides with.
139     *
140     *     The function locates the input point within the subdivision and gives one of the triangle edges
141     *     or vertices.
142     *
143     *     @return an integer which specify one of the following five cases for point location:
144     * <ul>
145     *   <li>
146     *       The point falls into some facet. The function returns #PTLOC_INSIDE and edge will contain one of
147     *        edges of the facet.
148     *   </li>
149     *   <li>
150     *       The point falls onto the edge. The function returns #PTLOC_ON_EDGE and edge will contain this edge.
151     *   </li>
152     *   <li>
153     *       The point coincides with one of the subdivision vertices. The function returns #PTLOC_VERTEX and
154     *        vertex will contain a pointer to the vertex.
155     *   </li>
156     *   <li>
157     *       The point is outside the subdivision reference rectangle. The function returns #PTLOC_OUTSIDE_RECT
158     *        and no pointers are filled.
159     *   </li>
160     *   <li>
161     *       One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error
162     *        processing mode is selected, #PTLOC_ERROR is returned.
163     *   </li>
164     * </ul>
165     */
166    public int locate(Point pt, int[] edge, int[] vertex) {
167        double[] edge_out = new double[1];
168        double[] vertex_out = new double[1];
169        int retVal = locate_0(nativeObj, pt.x, pt.y, edge_out, vertex_out);
170        if(edge!=null) edge[0] = (int)edge_out[0];
171        if(vertex!=null) vertex[0] = (int)vertex_out[0];
172        return retVal;
173    }
174
175
176    //
177    // C++:  int cv::Subdiv2D::findNearest(Point2f pt, Point2f* nearestPt = 0)
178    //
179
180    /**
181     * Finds the subdivision vertex closest to the given point.
182     *
183     *     @param pt Input point.
184     *     @param nearestPt Output subdivision vertex point.
185     *
186     *     The function is another function that locates the input point within the subdivision. It finds the
187     *     subdivision vertex that is the closest to the input point. It is not necessarily one of vertices
188     *     of the facet containing the input point, though the facet (located using locate() ) is used as a
189     *     starting point.
190     *
191     *     @return vertex ID.
192     */
193    public int findNearest(Point pt, Point nearestPt) {
194        double[] nearestPt_out = new double[2];
195        int retVal = findNearest_0(nativeObj, pt.x, pt.y, nearestPt_out);
196        if(nearestPt!=null){ nearestPt.x = nearestPt_out[0]; nearestPt.y = nearestPt_out[1]; } 
197        return retVal;
198    }
199
200    /**
201     * Finds the subdivision vertex closest to the given point.
202     *
203     *     @param pt Input point.
204     *
205     *     The function is another function that locates the input point within the subdivision. It finds the
206     *     subdivision vertex that is the closest to the input point. It is not necessarily one of vertices
207     *     of the facet containing the input point, though the facet (located using locate() ) is used as a
208     *     starting point.
209     *
210     *     @return vertex ID.
211     */
212    public int findNearest(Point pt) {
213        return findNearest_1(nativeObj, pt.x, pt.y);
214    }
215
216
217    //
218    // C++:  void cv::Subdiv2D::getEdgeList(vector_Vec4f& edgeList)
219    //
220
221    /**
222     * Returns a list of all edges.
223     *
224     *     @param edgeList Output vector.
225     *
226     *     The function gives each edge as a 4 numbers vector, where each two are one of the edge
227     *     vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3].
228     */
229    public void getEdgeList(MatOfFloat4 edgeList) {
230        Mat edgeList_mat = edgeList;
231        getEdgeList_0(nativeObj, edgeList_mat.nativeObj);
232    }
233
234
235    //
236    // C++:  void cv::Subdiv2D::getLeadingEdgeList(vector_int& leadingEdgeList)
237    //
238
239    /**
240     * Returns a list of the leading edge ID connected to each triangle.
241     *
242     *     @param leadingEdgeList Output vector.
243     *
244     *     The function gives one edge ID for each triangle.
245     */
246    public void getLeadingEdgeList(MatOfInt leadingEdgeList) {
247        Mat leadingEdgeList_mat = leadingEdgeList;
248        getLeadingEdgeList_0(nativeObj, leadingEdgeList_mat.nativeObj);
249    }
250
251
252    //
253    // C++:  void cv::Subdiv2D::getTriangleList(vector_Vec6f& triangleList)
254    //
255
256    /**
257     * Returns a list of all triangles.
258     *
259     *     @param triangleList Output vector.
260     *
261     *     The function gives each triangle as a 6 numbers vector, where each two are one of the triangle
262     *     vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5].
263     */
264    public void getTriangleList(MatOfFloat6 triangleList) {
265        Mat triangleList_mat = triangleList;
266        getTriangleList_0(nativeObj, triangleList_mat.nativeObj);
267    }
268
269
270    //
271    // C++:  void cv::Subdiv2D::getVoronoiFacetList(vector_int idx, vector_vector_Point2f& facetList, vector_Point2f& facetCenters)
272    //
273
274    /**
275     * Returns a list of all Voronoi facets.
276     *
277     *     @param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector.
278     *     @param facetList Output vector of the Voronoi facets.
279     *     @param facetCenters Output vector of the Voronoi facets center points.
280     */
281    public void getVoronoiFacetList(MatOfInt idx, List<MatOfPoint2f> facetList, MatOfPoint2f facetCenters) {
282        Mat idx_mat = idx;
283        Mat facetList_mat = new Mat();
284        Mat facetCenters_mat = facetCenters;
285        getVoronoiFacetList_0(nativeObj, idx_mat.nativeObj, facetList_mat.nativeObj, facetCenters_mat.nativeObj);
286        Converters.Mat_to_vector_vector_Point2f(facetList_mat, facetList);
287        facetList_mat.release();
288    }
289
290
291    //
292    // C++:  Point2f cv::Subdiv2D::getVertex(int vertex, int* firstEdge = 0)
293    //
294
295    /**
296     * Returns vertex location from vertex ID.
297     *
298     *     @param vertex vertex ID.
299     *     @param firstEdge Optional. The first edge ID which is connected to the vertex.
300     *     @return vertex (x,y)
301     */
302    public Point getVertex(int vertex, int[] firstEdge) {
303        double[] firstEdge_out = new double[1];
304        Point retVal = new Point(getVertex_0(nativeObj, vertex, firstEdge_out));
305        if(firstEdge!=null) firstEdge[0] = (int)firstEdge_out[0];
306        return retVal;
307    }
308
309    /**
310     * Returns vertex location from vertex ID.
311     *
312     *     @param vertex vertex ID.
313     *     @return vertex (x,y)
314     */
315    public Point getVertex(int vertex) {
316        return new Point(getVertex_1(nativeObj, vertex));
317    }
318
319
320    //
321    // C++:  int cv::Subdiv2D::getEdge(int edge, int nextEdgeType)
322    //
323
324    /**
325     * Returns one of the edges related to the given edge.
326     *
327     *     @param edge Subdivision edge ID.
328     *     @param nextEdgeType Parameter specifying which of the related edges to return.
329     *     The following values are possible:
330     * <ul>
331     *   <li>
332     *        NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge)
333     *   </li>
334     *   <li>
335     *        NEXT_AROUND_DST next around the edge vertex ( eDnext )
336     *   </li>
337     *   <li>
338     *        PREV_AROUND_ORG previous around the edge origin (reversed eRnext )
339     *   </li>
340     *   <li>
341     *        PREV_AROUND_DST previous around the edge destination (reversed eLnext )
342     *   </li>
343     *   <li>
344     *        NEXT_AROUND_LEFT next around the left facet ( eLnext )
345     *   </li>
346     *   <li>
347     *        NEXT_AROUND_RIGHT next around the right facet ( eRnext )
348     *   </li>
349     *   <li>
350     *        PREV_AROUND_LEFT previous around the left facet (reversed eOnext )
351     *   </li>
352     *   <li>
353     *        PREV_AROUND_RIGHT previous around the right facet (reversed eDnext )
354     *   </li>
355     * </ul>
356     *
357     *     ![sample output](pics/quadedge.png)
358     *
359     *     @return edge ID related to the input edge.
360     */
361    public int getEdge(int edge, int nextEdgeType) {
362        return getEdge_0(nativeObj, edge, nextEdgeType);
363    }
364
365
366    //
367    // C++:  int cv::Subdiv2D::nextEdge(int edge)
368    //
369
370    /**
371     * Returns next edge around the edge origin.
372     *
373     *     @param edge Subdivision edge ID.
374     *
375     *     @return an integer which is next edge ID around the edge origin: eOnext on the
376     *     picture above if e is the input edge).
377     */
378    public int nextEdge(int edge) {
379        return nextEdge_0(nativeObj, edge);
380    }
381
382
383    //
384    // C++:  int cv::Subdiv2D::rotateEdge(int edge, int rotate)
385    //
386
387    /**
388     * Returns another edge of the same quad-edge.
389     *
390     *     @param edge Subdivision edge ID.
391     *     @param rotate Parameter specifying which of the edges of the same quad-edge as the input
392     *     one to return. The following values are possible:
393     * <ul>
394     *   <li>
395     *        0 - the input edge ( e on the picture below if e is the input edge)
396     *   </li>
397     *   <li>
398     *        1 - the rotated edge ( eRot )
399     *   </li>
400     *   <li>
401     *        2 - the reversed edge (reversed e (in green))
402     *   </li>
403     *   <li>
404     *        3 - the reversed rotated edge (reversed eRot (in green))
405     *   </li>
406     * </ul>
407     *
408     *     @return one of the edges ID of the same quad-edge as the input edge.
409     */
410    public int rotateEdge(int edge, int rotate) {
411        return rotateEdge_0(nativeObj, edge, rotate);
412    }
413
414
415    //
416    // C++:  int cv::Subdiv2D::symEdge(int edge)
417    //
418
419    public int symEdge(int edge) {
420        return symEdge_0(nativeObj, edge);
421    }
422
423
424    //
425    // C++:  int cv::Subdiv2D::edgeOrg(int edge, Point2f* orgpt = 0)
426    //
427
428    /**
429     * Returns the edge origin.
430     *
431     *     @param edge Subdivision edge ID.
432     *     @param orgpt Output vertex location.
433     *
434     *     @return vertex ID.
435     */
436    public int edgeOrg(int edge, Point orgpt) {
437        double[] orgpt_out = new double[2];
438        int retVal = edgeOrg_0(nativeObj, edge, orgpt_out);
439        if(orgpt!=null){ orgpt.x = orgpt_out[0]; orgpt.y = orgpt_out[1]; } 
440        return retVal;
441    }
442
443    /**
444     * Returns the edge origin.
445     *
446     *     @param edge Subdivision edge ID.
447     *
448     *     @return vertex ID.
449     */
450    public int edgeOrg(int edge) {
451        return edgeOrg_1(nativeObj, edge);
452    }
453
454
455    //
456    // C++:  int cv::Subdiv2D::edgeDst(int edge, Point2f* dstpt = 0)
457    //
458
459    /**
460     * Returns the edge destination.
461     *
462     *     @param edge Subdivision edge ID.
463     *     @param dstpt Output vertex location.
464     *
465     *     @return vertex ID.
466     */
467    public int edgeDst(int edge, Point dstpt) {
468        double[] dstpt_out = new double[2];
469        int retVal = edgeDst_0(nativeObj, edge, dstpt_out);
470        if(dstpt!=null){ dstpt.x = dstpt_out[0]; dstpt.y = dstpt_out[1]; } 
471        return retVal;
472    }
473
474    /**
475     * Returns the edge destination.
476     *
477     *     @param edge Subdivision edge ID.
478     *
479     *     @return vertex ID.
480     */
481    public int edgeDst(int edge) {
482        return edgeDst_1(nativeObj, edge);
483    }
484
485
486    @Override
487    protected void finalize() throws Throwable {
488        delete(nativeObj);
489    }
490
491
492
493    // C++:   cv::Subdiv2D::Subdiv2D()
494    private static native long Subdiv2D_0();
495
496    // C++:   cv::Subdiv2D::Subdiv2D(Rect rect)
497    private static native long Subdiv2D_1(int rect_x, int rect_y, int rect_width, int rect_height);
498
499    // C++:  void cv::Subdiv2D::initDelaunay(Rect rect)
500    private static native void initDelaunay_0(long nativeObj, int rect_x, int rect_y, int rect_width, int rect_height);
501
502    // C++:  int cv::Subdiv2D::insert(Point2f pt)
503    private static native int insert_0(long nativeObj, double pt_x, double pt_y);
504
505    // C++:  void cv::Subdiv2D::insert(vector_Point2f ptvec)
506    private static native void insert_1(long nativeObj, long ptvec_mat_nativeObj);
507
508    // C++:  int cv::Subdiv2D::locate(Point2f pt, int& edge, int& vertex)
509    private static native int locate_0(long nativeObj, double pt_x, double pt_y, double[] edge_out, double[] vertex_out);
510
511    // C++:  int cv::Subdiv2D::findNearest(Point2f pt, Point2f* nearestPt = 0)
512    private static native int findNearest_0(long nativeObj, double pt_x, double pt_y, double[] nearestPt_out);
513    private static native int findNearest_1(long nativeObj, double pt_x, double pt_y);
514
515    // C++:  void cv::Subdiv2D::getEdgeList(vector_Vec4f& edgeList)
516    private static native void getEdgeList_0(long nativeObj, long edgeList_mat_nativeObj);
517
518    // C++:  void cv::Subdiv2D::getLeadingEdgeList(vector_int& leadingEdgeList)
519    private static native void getLeadingEdgeList_0(long nativeObj, long leadingEdgeList_mat_nativeObj);
520
521    // C++:  void cv::Subdiv2D::getTriangleList(vector_Vec6f& triangleList)
522    private static native void getTriangleList_0(long nativeObj, long triangleList_mat_nativeObj);
523
524    // C++:  void cv::Subdiv2D::getVoronoiFacetList(vector_int idx, vector_vector_Point2f& facetList, vector_Point2f& facetCenters)
525    private static native void getVoronoiFacetList_0(long nativeObj, long idx_mat_nativeObj, long facetList_mat_nativeObj, long facetCenters_mat_nativeObj);
526
527    // C++:  Point2f cv::Subdiv2D::getVertex(int vertex, int* firstEdge = 0)
528    private static native double[] getVertex_0(long nativeObj, int vertex, double[] firstEdge_out);
529    private static native double[] getVertex_1(long nativeObj, int vertex);
530
531    // C++:  int cv::Subdiv2D::getEdge(int edge, int nextEdgeType)
532    private static native int getEdge_0(long nativeObj, int edge, int nextEdgeType);
533
534    // C++:  int cv::Subdiv2D::nextEdge(int edge)
535    private static native int nextEdge_0(long nativeObj, int edge);
536
537    // C++:  int cv::Subdiv2D::rotateEdge(int edge, int rotate)
538    private static native int rotateEdge_0(long nativeObj, int edge, int rotate);
539
540    // C++:  int cv::Subdiv2D::symEdge(int edge)
541    private static native int symEdge_0(long nativeObj, int edge);
542
543    // C++:  int cv::Subdiv2D::edgeOrg(int edge, Point2f* orgpt = 0)
544    private static native int edgeOrg_0(long nativeObj, int edge, double[] orgpt_out);
545    private static native int edgeOrg_1(long nativeObj, int edge);
546
547    // C++:  int cv::Subdiv2D::edgeDst(int edge, Point2f* dstpt = 0)
548    private static native int edgeDst_0(long nativeObj, int edge, double[] dstpt_out);
549    private static native int edgeDst_1(long nativeObj, int edge);
550
551    // native support for java finalize()
552    private static native void delete(long nativeObj);
553
554}