/** * Requests a single tile to be used in Helioviewer.org. * * TODO 2011/04/19: How much longer would it take to request tiles if * meta data was refetched from database instead of * being passed in? * * @return object The image tile */ public function getTile() { include_once HV_ROOT_DIR . '/../src/Database/ImgIndex.php'; include_once HV_ROOT_DIR . '/../src/Image/JPEG2000/JP2Image.php'; include_once HV_ROOT_DIR . '/../src/Helper/RegionOfInterest.php'; // Tilesize $tileSize = 512; $params = $this->_params; // Look up image properties $imgIndex = new Database_ImgIndex(); $image = $imgIndex->getImageInformation($this->_params['id']); $this->_options['date'] = $image['date']; // Tile filepath $filepath = $this->_getTileCacheFilename($image['filepath'], $image['filename'], $params['imageScale'], $params['x'], $params['y']); // Create directories in cache $this->_createTileCacheDir($image['filepath']); // JP2 filepath $jp2Filepath = HV_JP2_DIR . $image['filepath'] . '/' . $image['filename']; // Reference pixel offset at the original image scale $offsetX = $image['refPixelX'] - $image['width'] / 2; $offsetY = -($image['refPixelY'] - $image['height'] / 2); // Instantiate a JP2Image $jp2 = new Image_JPEG2000_JP2Image($jp2Filepath, $image['width'], $image['height'], $image['scale']); // Region of interest $roi = $this->_tileCoordinatesToROI($params['x'], $params['y'], $params['imageScale'], $image['scale'], $tileSize, $offsetX, $offsetY); // Choose type of tile to create // TODO 2011/04/18: Generalize process of choosing class to use //error_log(json_encode($image['uiLabels'])); if (count($image['uiLabels']) >= 3 && $image['uiLabels'][1]['name'] == 'SECCHI') { if (substr($image['uiLabels'][2]['name'], 0, 3) == 'COR') { $type = 'CORImage'; } else { $type = strtoupper($image['uiLabels'][2]['name']) . 'Image'; } } else { if ($image['uiLabels'][0]['name'] == 'TRACE') { $type = strtoupper($image['uiLabels'][0]['name']) . 'Image'; } else { if ($image['uiLabels'][0]['name'] == 'Hinode') { $type = 'XRTImage'; } else { if (count($image['uiLabels']) >= 2) { $type = strtoupper($image['uiLabels'][1]['name']) . 'Image'; } } } } include_once HV_ROOT_DIR . '/../src/Image/ImageType/' . $type . '.php'; $classname = 'Image_ImageType_' . $type; // Create the tile $tile = new $classname($jp2, $filepath, $roi, $image['uiLabels'], $offsetX, $offsetY, $this->_options, $image['sunCenterOffsetParams']); // Save and display $tile->save(); $tile->display(); }