Closed bingzhenChen closed 5 years ago
First off, thank you for your interest in the Tinfour project. Looking at the code example in your post, it looks like you've already made good progress in using the Tinfour software.
There are a couple of ways to do what you want. A good place to start would be to use the TriangleCollector. The implementation is efficient and relatively easy to use. Some code follows. For my example, I've used randomly generated vertices rather than your loadPointSet() method, but the idea is the same.
package org.tinfour.example.collector;
import java.util.List;
import java.util.function.Consumer;
import org.tinfour.common.IQuadEdge;
import org.tinfour.common.SimpleTriangle;
import org.tinfour.common.Vertex;
import org.tinfour.demo.utils.TestVertices;
import org.tinfour.standard.IncrementalTin;
import org.tinfour.utils.TriangleCollector;
public class ExampleTriangleCollector {
static class ExampleCollector implements Consumer<SimpleTriangle> {
@Override
public void accept(SimpleTriangle t) {
// here we
IQuadEdge a = t.getEdgeA();
IQuadEdge b = t.getEdgeB();
IQuadEdge c = t.getEdgeC();
// it is a little confusing here... we get the first point
// from each edge. So for each edge, we call getA().
// In a future version, SimpleTriangle will be
// enhanced with methods named getVertexA(), getVertexB(),
// and getVertexC() to do this operation in a less confusing manner.
Vertex A = a.getA();
Vertex B = b.getA();
Vertex C = c.getA();
System.out.println("Triangle ");
System.out.println(" A= " + A.toString());
System.out.println(" B= " + B.toString());
System.out.println(" C= " + C.toString());
}
}
public static void main(String[] args) {
IncrementalTin tin = new IncrementalTin(1.0);
List<Vertex> vertexList = TestVertices.makeRandomVertices(5, 0);
tin.add(vertexList, null);
ExampleCollector collector = new ExampleCollector();
TriangleCollector.visitSimpleTriangles(tin, collector);
}
}
There is an article about the TriangleCollector class on the Tinfour wiki at Tutorial Using TriangleCollector Techniques
In my own work, I often find that the edge-iterator classes and methods are good solutions for many problems. You can read more about them at Tutorial Using Edge-Based Techniques
Finally, I'd like to thank you for asking this question. It is always helpful to get user insights on the API design. In this case, it never occurred to me that a user would need an API for getting the vertices from the SimpleTriangle class. Now that I have seen your question, it seems like a valuable improvement.
thank you very much, your answer is very helpful and Tinfour help me lot.
I have posted updates of the SimpleTriangle class that includes access methods for getting the individual vertices. The previous version provided access methods for edges, but not vertices.
To use these methods, you will have to download and build code from the Tinfour project. I will not be posting compiled Jars to Maven Central until other work is complete. That will probably not happen until July.
This issue is now closed. Thank you for asking this interesting questions.
There is now an iterator for SimpleTriangles in the API
IncrementalTin tin; // constructed and populated
int nTriangle = 0;
for(SimpleTriangle triangle: tin.triangles()){
nTriangle++;
}
I need the three coordinates of each triangle,not a picture,what should i do?