def test_regularWiredPolygon(self): """ Result image is the same as regularPolygon but with wire connecting the vertices. """ regularWiredImage, regularWiredCanvas = getImage( 'L', (640, 480), 'white') drawWire(regularWiredCanvas, regularPolygon(3, np.array([160, 120]), 50)) drawWire(regularWiredCanvas, regularPolygon(4, np.array([480, 120]), 90)) drawWire(regularWiredCanvas, regularPolygon(5, np.array([420, 360]), 60)) drawWire(regularWiredCanvas, regularPolygon(6, np.array([160, 360]), 80)) drawWire(regularWiredCanvas, regularPolygon(7, np.array([320, 160]), 70)) imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) regularWiredImage.save(resultFile) regularWiredImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_randomPolygon(self): """ drawing random vertices location - un-wired """ randomImage, randomCanvas = getImage('L', (640, 480), 'white') seed = 5 draw(randomCanvas, randomPolygon(seed, 3, np.array([160, 120]), 200), '3r') draw(randomCanvas, randomPolygon(seed, 4, np.array([480, 120]), 200), '4r') draw(randomCanvas, randomPolygon(seed, 5, np.array([480, 360]), 200), '5r') draw(randomCanvas, randomPolygon(seed, 6, np.array([160, 360]), 200), '6r') draw(randomCanvas, randomPolygon(seed, 7, np.array([320, 240]), 200), '7r') imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) randomImage.save(resultFile) randomImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_regularRotatedWiredPolygon(self): """ Result image for regularPolygon using rotated points with wire. """ regularRotatedWiredImage, regularRotatedWiredCanvas = getImage( 'L', (640, 480), 'white') center = np.array([320, 240]) draw(regularRotatedWiredCanvas, [center], 'center') drawWire(regularRotatedWiredCanvas, (rotate( (regularPolygon(3, np.array([160, 120]), 50)), center, 45.0))) drawWire(regularRotatedWiredCanvas, (rotate( (regularPolygon(4, np.array([480, 120]), 90)), center, 45.0))) drawWire(regularRotatedWiredCanvas, (rotate( (regularPolygon(5, np.array([420, 360]), 60)), center, 45.0))) drawWire(regularRotatedWiredCanvas, (rotate( (regularPolygon(6, np.array([160, 360]), 80)), center, 45.0))) drawWire(regularRotatedWiredCanvas, (rotate( (regularPolygon(7, np.array([320, 160]), 70)), center, 45.0))) imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) regularRotatedWiredImage.save(resultFile) regularRotatedWiredImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_scaleTransform(self): """ This test is to create polygons and performs scaling on them. """ imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) # Result image for transform resultImage, resulCanvas = getImage('L', (640, 480), 'white') drawSolid(resulCanvas, regularPolygon(3, np.array([320, 240]), 50), 'black') drawSolid(resulCanvas, regularPolygon(5, np.array([80, 60]), 70), 'black') drawSolid(resulCanvas, regularPolygon(4, np.array([480, 380]), 70), 'black') drawWire( resulCanvas, scale(np.array([320, 240]), (regularPolygon(3, np.array([320, 240]), 50)), 3)) drawWire( resulCanvas, scale(np.array([80, 60]), (regularPolygon(5, np.array([80, 60]), 70)), 1.3)) drawWire( resulCanvas, scale(np.array([480, 380]), (regularPolygon(4, np.array([480, 380]), 70)), 2)) resultImage.save(resultFile) resultImage.close() validate(resultFile, resultFile)
def DisplayImage(self, saveImage = 'False', showImage = 'False'): ''' This function is to do two tasks: - save a resultant image into a file - display it to the user without saving it. :param saveImage: :param showImage: :return: ''' if not os.path.exists(self.AggregateOutputPath): os.makedirs(self.AggregateOutputPath) imageName = 'Aggregate-'+ str(uuid.uuid4()) + '.png' resultFile = os.path.join(self.AggregateOutputPath, imageName) image, canvas = getImage('L', (640, 480), 'white') for i in range(self.NrOfShapesAggr[0]): points = self.AggrVertices[0][i] drawWire(canvas, points) if saveImage == 'True': image.save(resultFile) print("Image has been saved to directory /test/Aggregate ") else: print("Image hasn't been saved") if showImage == 'True': image.show() else: print("Image won't be shown")
def test_rotateTransform(self): """ This function is to test rotated points in 2D """ # first create an empty white image resultImage, resultCanvas = getImage('L', (640, 480), 'white') # get the name through the module name imageName = fileName(sys._getframe().f_code.co_name) # call function get_path from PathsModule.py to set the path for results and reference folder location resultFile, referenceFile = getPath(imageName) # plot the points with no rotation draw(resultCanvas, self.points, '+') # specify the centre for rotation and draw it. center = np.array([180, 140]) draw(resultCanvas, [center], 'center') # apply rotation and draw the resultant points rotatedPoints = rotate(self.points, center, 90.0) draw(resultCanvas, rotatedPoints, 'X') # save it into predetermined file. resultImage.save(resultFile) resultImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_drawWire(self): """ This test is to draw a line between two vertices """ # Create the file name and its saving path, and specify the reference file to compare to. imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) # create an empty image with a specific dimension with white background, and black/white colored image, canvas = getImage('L', (640, 480), 'white') drawWire(canvas, regularPolygon(3, np.array([160, 120]), 50)) drawWire(canvas, regularPolygon(4, np.array([480, 120]), 90)) drawWire(canvas, regularPolygon(5, np.array([420, 360]), 60)) drawWire(canvas, regularPolygon(6, np.array([160, 360]), 80)) drawWire(canvas, regularPolygon(7, np.array([320, 160]), 70)) # saving the file and closing it image.save(resultFile) image.close() # validate the resultant file against the reference images validate(referenceFile, resultFile)
def test_regularPolygon(self): """ This test draws a multi-vertices (3,4,5,6,7) at specific locations. """ # Result image for regularPolygon regularImage, regularCanvas = getImage('L', (640, 480), 'white') draw(regularCanvas, regularPolygon(3, np.array([160, 120]), 50), '3') draw(regularCanvas, regularPolygon(4, np.array([480, 120]), 90), '4') draw(regularCanvas, regularPolygon(5, np.array([420, 360]), 60), '5') draw(regularCanvas, regularPolygon(6, np.array([160, 360]), 80), '6') draw(regularCanvas, regularPolygon(7, np.array([320, 160]), 70), '7') imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) regularImage.save(resultFile) regularImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_Polygonshape(self): """ Result image for combined shapes """ shapeImage, shapeCanvas = getImage('L', (640, 480), 'white') center = np.array([320, 240]) drawWire(shapeCanvas, (rotate((regularPolygon(3, np.array([320, 240]), 110)), np.array([450, 200]), 30.0))) drawWire(shapeCanvas, (rotate( (regularPolygon(4, np.array([320, 240]), 120)), center, 45.0))) imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) shapeImage.save(resultFile) shapeImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_draw(self): """ This test is to draw a number of vertices labeled as 'A' """ # Create the file name and its saving path, and specify the reference file to compare to. image_name = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(image_name) # create an empty image with a specific dimension with white background, and black/white colored image, canvas = getImage('L', (15, 90), 'white') for i in range(len(drawPoints) - 1): draw(canvas, (drawPoints[i + 0], drawPoints[i + 1]), 'A') # saving the file and closing it image.save(resultFile) image.close() # validate the resultant file against the reference images validate(referenceFile, resultFile)
def test_translateTransform(self): """ this test perform translation on created shapes. """ imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) # Result image for transform resultImage, resultCanvas = getImage('L', (640, 480), 'white') draw(resultCanvas, translate(regularPolygon(4, (120, 340), 100), 240, 0), "black") draw(resultCanvas, translate(regularPolygon(4, (120, 340), 100), 240, -90), "black") draw(resultCanvas, translate(regularPolygon(4, (120, 340), 100), 339.4, -45), "black") resultImage.save(resultFile) resultImage.close() validate(resultFile, resultFile)
def test_regularRotatedPolygon(self): """ This test creates polygons with 3,4,5,6,7 edges and rotate them around a predefined centre of rotate. the angle of rotation is 45. """ # Result image for regularPolygon with rotated points regularRotatedImage, regularRotatedCanvas = getImage( 'L', (640, 480), 'white') center = np.array([320, 240]) draw(regularRotatedCanvas, [center], 'center') draw(regularRotatedCanvas, (rotate( (regularPolygon(3, np.array([160, 120]), 50)), center, 45.0)), '3r') draw(regularRotatedCanvas, (rotate( (regularPolygon(4, np.array([480, 120]), 90)), center, 45.0)), '4r') draw(regularRotatedCanvas, (rotate( (regularPolygon(5, np.array([420, 360]), 60)), center, 45.0)), '5r') draw(regularRotatedCanvas, (rotate( (regularPolygon(6, np.array([160, 360]), 80)), center, 45.0)), '6r') draw(regularRotatedCanvas, (rotate( (regularPolygon(7, np.array([320, 160]), 70)), center, 45.0)), '7r') imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) regularRotatedImage.save(resultFile) regularRotatedImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_randomRotatedPolygon(self): """ this test is to create random vertices and rotate them about a specific center """ randomRotatedImage, randomRotatedCanvas = getImage( 'L', (640, 480), 'white') center = np.array([320, 240]) draw(randomRotatedCanvas, [center], 'center') seed = 5 draw(randomRotatedCanvas, (rotate( (randomPolygon(seed, 3, np.array([160, 120]), 50)), center, 90.0)), '3r') draw(randomRotatedCanvas, (rotate( (randomPolygon(seed, 4, np.array([480, 120]), 90)), center, 90.0)), '4r') draw(randomRotatedCanvas, (rotate( (randomPolygon(seed, 5, np.array([420, 360]), 60)), center, 90.0)), '5r') draw(randomRotatedCanvas, (rotate( (randomPolygon(seed, 6, np.array([160, 360]), 80)), center, 90.0)), '6r') draw(randomRotatedCanvas, (rotate( (randomPolygon(seed, 7, np.array([320, 160]), 70)), center, 90.0)), '7r') imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) randomRotatedImage.save(resultFile) randomRotatedImage.close() # compare results against reference data validate(referenceFile, resultFile)
def test_drawSolid(self): """ This test is to create polygons filled with a particular color: red, blue,...ect. """ # first, Create the file name and its saving path, and specify the reference file to compare to. imageName = fileName(sys._getframe().f_code.co_name) resultFile, referenceFile = getPath(imageName) # Next, create an empty image with a specific dimension with white background, and black/white colored image, canvas = getImage('RGB', (640, 480), 'white') drawSolid(canvas, regularPolygon(3, np.array([160, 120]), 50), 'red') drawSolid(canvas, regularPolygon(4, np.array([480, 120]), 90), 'blue') drawSolid(canvas, regularPolygon(5, np.array([420, 360]), 60), 'green') drawSolid(canvas, regularPolygon(6, np.array([160, 360]), 80), 'black') drawSolid(canvas, regularPolygon(7, np.array([320, 160]), 70), 'brown') # saving the file and closing it image.save(resultFile) image.close() # validate the resultant file against the reference images validate(referenceFile, resultFile)