00001 package commandline.JUnitTest;
00002
00003 import java.util.ArrayList;
00004 import java.util.HashSet;
00005 import java.util.Iterator;
00006
00007 import junit.framework.TestCase;
00008
00009 import commandline.CodingUtils.DataStructure;
00010 import commandline.CodingUtils.XMLCodedFile;
00011 import commandline.Encoder.EncoderEdge;
00012 import commandline.Encoder.SnijPixelPiercingWaardeStrategy;
00013 import commandline.ImageStuff.GeometricObjects.GenericEdge;
00014 import commandline.ImageStuff.GeometricObjects.ParametrizedPiercingVertex;
00015 import commandline.ImageStuff.GeometricObjects.Triangle;
00016 import commandline.ImageStuff.GeometricObjects.Vertex;
00017 import commandline.ImageStuff.GeometricObjects.Impl.TriangleImplType;
00018 import commandline.NormalMeshAlgorithm.Configuration;
00019 import commandline.NormalMeshAlgorithm.SnijPixelStrategy;
00020
00021 public class testTriangle extends TestCase {
00022 ParametrizedPiercingVertex a,b,c;
00023 SnijPixelStrategy snij;
00024 EncoderEdge een,twee,drie;
00025 DataStructure dataStructure;
00026 Configuration configuration;
00027 protected void setUp() throws Exception {
00028 super.setUp();
00029 configuration=new Configuration();
00030 dataStructure=new DataStructure(new XMLCodedFile(1000));
00031 a= new ParametrizedPiercingVertex(0,10,1,0,Vertex.NO_AREAO,null);
00032 b= new ParametrizedPiercingVertex(55,15,0,0,Vertex.NO_AREAO,null);
00033 c=new ParametrizedPiercingVertex(110,20,2,0,Vertex.NO_AREAO,null);
00034 snij=new SnijPixelPiercingWaardeStrategy(configuration);
00035 new Image_test().testsetUpImage();
00036 een=new EncoderEdge(a,b,configuration.getMaxRico());
00037 twee=new EncoderEdge(b,c,configuration.getMaxRico());
00038 drie=new EncoderEdge(c,a,configuration.getMaxRico());
00039 }
00040
00041 public void testConstructor() throws Exception{
00042 new Triangle(een ,twee ,drie ,TriangleImplType.INTERPOLOLATING);
00043
00044 }
00045
00046 public void testRegister() throws Exception{
00047 Triangle t=new Triangle(een ,twee ,drie,TriangleImplType.INTERPOLOLATING );
00048 t.register(dataStructure);
00049 Triangle retrieved=dataStructure.getTriangles().get(dataStructure.getTriangles().size()-1);
00050 assertEquals(true,retrieved==t);
00051
00052 }
00053
00054 public void testGetCommon() throws Exception{
00055 Triangle t=new Triangle(een ,twee ,drie,TriangleImplType.INTERPOLOLATING );
00056 assertNotNull(t.getVertex(0));
00057 assertNotNull(t.getVertex(1));
00058 assertNotNull(t.getVertex(2));
00059
00060 }
00061
00062 public void testGetVertices() throws Exception{
00063 Triangle t=new Triangle(een ,twee , drie,TriangleImplType.INTERPOLOLATING );
00064 assertEquals(3,t.getOrderedVertices().size());
00065
00066 }
00067
00068 public static boolean isAGoodTriangle(Triangle t){
00069 ArrayList<Vertex> vertexList= new ArrayList<Vertex>(3);
00070 GenericEdge nul , een ,twee;
00071 nul=t.getEdge(0);
00072 een=t.getEdge(1);
00073 twee=t.getEdge(2);
00074
00075 HashSet<Vertex> temp = new HashSet<Vertex>();
00076 temp.add(nul.getBegin());
00077 temp.add(nul.getEind());
00078 temp.add(een.getBegin());
00079 temp.add(een.getEind());
00080 temp.add(twee.getBegin());
00081 temp.add(twee.getEind());
00082 Iterator<Vertex> iter=temp.iterator();
00083 while(iter.hasNext()){
00084 vertexList.add(iter.next());
00085 }
00086 if(vertexList.size()==3){
00087 return true;
00088 }
00089 else{
00090 return false;
00091 }
00092
00093
00094 }
00095
00096 }