diff --git a/DataView/NetCdfConfigureDialog.cpp b/DataView/NetCdfConfigureDialog.cpp index adc7e275e44b021de673518992e6df5bc157db09..c6fbce24b5fcb12a6ced8c946ec3de7057bbd7f7 100644 --- a/DataView/NetCdfConfigureDialog.cpp +++ b/DataView/NetCdfConfigureDialog.cpp @@ -335,7 +335,7 @@ void NetCdfConfigureDialog::createMesh() if (dimArrayT2mMax[i] < -10000 ) dimArrayT2mMax[i] = -9999; // all values < -10000, set to "no-value" } - std::pair <double,double> originNetCdf (originLon,originLat); // lon,lat + double originNetCdf[3] = {originLon,originLat,0}; // lon,lat MshElemType::type meshElemType = MshElemType::QUAD; UseIntensityAs::type useIntensity = UseIntensityAs::MATERIAL; diff --git a/VtkVis/CMakeLists.txt b/VtkVis/CMakeLists.txt index d98326dac0bd38de0799b7aad48ba2d3d78e6688..f75fb7555796da6438a8300f7b1cbc623e802c35 100644 --- a/VtkVis/CMakeLists.txt +++ b/VtkVis/CMakeLists.txt @@ -31,6 +31,7 @@ SET( SOURCES VtkMeshSource.cpp VtkPolylinesSource.cpp VtkPointsSource.cpp + VtkRaster.cpp VtkSelectionFilter.cpp VtkStationSource.cpp VtkSurfacesSource.cpp @@ -87,6 +88,7 @@ SET( HEADERS VtkMeshSource.h VtkPolylinesSource.h VtkPointsSource.h + VtkRaster.h VtkSelectionFilter.h VtkStationSource.h VtkSurfacesSource.h diff --git a/VtkVis/VtkGeoImageSource.cpp b/VtkVis/VtkGeoImageSource.cpp index a2481baecab40ef3aee824d64cff971fec40dc48..4cb880a95b7409b999f6f9d918788d321dc6f7fb 100644 --- a/VtkVis/VtkGeoImageSource.cpp +++ b/VtkVis/VtkGeoImageSource.cpp @@ -8,7 +8,8 @@ // ** INCLUDES ** #include "VtkGeoImageSource.h" -#include "OGSRaster.h" +//#include "OGSRaster.h" +#include "VtkRaster.h" #include <vtkFloatArray.h> #include <vtkImageChangeInformation.h> @@ -52,14 +53,8 @@ void vtkSimpleImageFilterExampleExecute(vtkImageData* input, VtkGeoImageSource::VtkGeoImageSource() { - _imageSource = vtkQImageToImageSource::New(); _imageInfo = vtkImageChangeInformation::New(); _imageShift = vtkImageShiftScale::New(); - - _imageInfo->SetInputConnection(_imageSource->GetOutputPort()); - _imageShift->SetInputConnection(_imageInfo->GetOutputPort()); - _imageShift->SetOutputScalarTypeToUnsignedChar(); - this->SetInputConnection(_imageShift->GetOutputPort()); } VtkGeoImageSource::~VtkGeoImageSource() @@ -76,15 +71,26 @@ void VtkGeoImageSource::PrintSelf(ostream& os, vtkIndent indent) void VtkGeoImageSource::setImageFilename(QString filename) { - QImage* raster = new QImage; - QPointF origin; - double spacing; - OGSRaster::loadImage(filename, *raster, origin, spacing); - this->setImage(*raster); - delete raster; + //QImage* raster = new QImage; + //QPointF origin; + //double spacing; + //OGSRaster::loadImage(filename, *raster, origin, spacing); + //this->setImage(*raster); + //delete raster; // correct raster position by half a pixel for correct visualisation - this->setOrigin(origin.x()+(spacing/2.0), origin.y()+(spacing/2.0), -10.0); - this->setSpacing(spacing); + this->_imageSource = VtkRaster::loadImage(filename.toStdString()); + + _imageShift->SetInputConnection(_imageSource->GetOutputPort()); + _imageShift->SetOutputScalarTypeToUnsignedChar(); + _imageInfo->SetInputConnection(_imageShift->GetOutputPort()); + this->SetInputConnection(_imageShift->GetOutputPort()); + + double origin[3]; + double spacing[3]; + this->_imageSource->GetOutput()->GetOrigin(origin); + this->_imageSource->GetOutput()->GetSpacing(spacing); + this->setOrigin(origin[0]+(spacing[0]/2.0), origin[1]+(spacing[0]/2.0), -10.0); + this->setSpacing(spacing[0]); this->SetName(filename); } @@ -93,25 +99,13 @@ vtkImageData* VtkGeoImageSource::getImageData() return this->_imageSource->GetImageDataInput(0); } -std::pair<double, double> VtkGeoImageSource::getOrigin() -{ - double* origin = this->_imageInfo->GetOutputOrigin(); - std::pair<double, double> p(origin[0], origin[1]); - return p; -} - -double VtkGeoImageSource::getSpacing() -{ - double* spacing = this->_imageInfo->GetOutputSpacing(); - return spacing[0]; -} - +/* void VtkGeoImageSource::setImage(QImage& image) { _imageSource->SetQImage(&image); _imageSource->Update(); // crashes otherwise } - +*/ void VtkGeoImageSource::setOrigin(double x, double y, double z) { _imageInfo->SetOutputOrigin(x, y, z); diff --git a/VtkVis/VtkGeoImageSource.h b/VtkVis/VtkGeoImageSource.h index c21e175c6c7599f5cdaa56e7687043698fcb485b..4c942aed41bdf13229db9113d90179bd6ca32731 100644 --- a/VtkVis/VtkGeoImageSource.h +++ b/VtkVis/VtkGeoImageSource.h @@ -30,17 +30,11 @@ public: vtkImageData* getImageData(); - std::pair<double, double> getOrigin(); - - double getSpacing(); + vtkImageChangeInformation* getImageChangeTransformation() const { return _imageInfo; }; void setImageFilename(QString filename); - void setImage(QImage& image); - - void setOrigin(double x, double y, double z); - - void setSpacing(double spacing); + //void setImage(QImage& image); virtual void SetUserProperty(QString name, QVariant value); @@ -54,11 +48,16 @@ protected: /// @brief Filter execution. virtual void SimpleExecute(vtkImageData* input, vtkImageData* output); + void setOrigin(double x, double y, double z); + + void setSpacing(double spacing); + + private: VtkGeoImageSource(const VtkGeoImageSource&); // Not implemented. void operator=(const VtkGeoImageSource&); // Not implemented - vtkQImageToImageSource* _imageSource; + vtkImageAlgorithm* _imageSource; vtkImageChangeInformation* _imageInfo; vtkImageShiftScale* _imageShift; }; diff --git a/VtkVis/VtkMeshConverter.cpp b/VtkVis/VtkMeshConverter.cpp index dd417b90ea63cd66aeb13e190c2ed33fabca31a2..387f5ba3a33cbfe25f1a5a740632a42812d5165e 100644 --- a/VtkVis/VtkMeshConverter.cpp +++ b/VtkVis/VtkMeshConverter.cpp @@ -21,8 +21,8 @@ GridAdapter* VtkMeshConverter::convertImgToMesh(vtkImageData* img, - const std::pair<double,double> &origin, - const double &scalingFactor, + const double origin[3], + const double scalingFactor, MshElemType::type elem_type, UseIntensityAs::type intensity_type) { @@ -76,7 +76,7 @@ GridAdapter* VtkMeshConverter::convertImgToMesh(vtkImageData* img, } GridAdapter* VtkMeshConverter::convertImgToMesh(const double* img, - const std::pair<double,double> &origin, + const double origin[3], const size_t imgHeight, const size_t imgWidth, const double &scalingFactor, @@ -133,7 +133,7 @@ GridAdapter* VtkMeshConverter::convertImgToMesh(const double* img, GridAdapter* VtkMeshConverter::constructMesh(const double* pixVal, int* node_idx_map, const bool* visNodes, - const std::pair<double,double> &origin, + const double origin[3], const size_t &imgHeight, const size_t &imgWidth, const double &scalingFactor, @@ -144,8 +144,8 @@ GridAdapter* VtkMeshConverter::constructMesh(const double* pixVal, const size_t incWidth = imgWidth+1; GridAdapter* grid = new GridAdapter(NULL); size_t node_idx_count(0); - const double x_offset(origin.first - scalingFactor/2.0); - const double y_offset(origin.second - scalingFactor/2.0); + const double x_offset(origin[0] - scalingFactor/2.0); + const double y_offset(origin[1] - scalingFactor/2.0); for (size_t i = 0; i < incWidth; i++) for (size_t j = 0; j < incHeight; j++) diff --git a/VtkVis/VtkMeshConverter.h b/VtkVis/VtkMeshConverter.h index 17ad98bf6578a7d7ec38e32c591f3b88134fe2d1..151d4e713284bbf1995829e0774cfaa3e9b57b4f 100644 --- a/VtkVis/VtkMeshConverter.h +++ b/VtkVis/VtkMeshConverter.h @@ -36,8 +36,8 @@ public: * \param intensity_type defines how image intensities are interpreted */ static GridAdapter* convertImgToMesh(vtkImageData* img, - const std::pair<double,double> &origin, - const double &scalingFactor, + const double origin[3], + const double scalingFactor, MshElemType::type elem_type, UseIntensityAs::type intensity_type); @@ -47,7 +47,7 @@ public: * \param intensity_type defines how image intensities are interpreted */ static GridAdapter* convertImgToMesh(const double* img, - const std::pair<double,double> &origin, + const double origin[3], const size_t imgHeight, const size_t imgWidth, const double &scalingFactor, @@ -62,7 +62,7 @@ private: static GridAdapter* constructMesh(const double* pixVal, int* node_idx_map, const bool* visNodes, - const std::pair<double,double> &origin, + const double origin[3], const size_t &imgHeight, const size_t &imgWidth, const double &scalingFactor, diff --git a/VtkVis/VtkRaster.cpp b/VtkVis/VtkRaster.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc233ffa6e4443baf2fa167339bb236c61aed978 --- /dev/null +++ b/VtkVis/VtkRaster.cpp @@ -0,0 +1,353 @@ +/** + * \file VtkRaster.cpp + * 2012/02/01 KR Initial implementation + */ + +#include "VtkRaster.h" + +#include <cmath> +#include <iomanip> +#include <iostream> +#include <sstream> + +#include <QFileInfo> + +#include "OGSError.h" +#include "StringTools.h" + +#include <vtkFloatArray.h> +#include <vtkPointData.h> + +#include <vtkImageAlgorithm.h> +#include <vtkImageImport.h> + + +/* +#ifdef libgeotiff_FOUND +#include "geo_tiffp.h" +#include "xtiffio.h" +#endif +*/ +vtkImageAlgorithm* VtkRaster::loadImage(const std::string &fileName, bool autoscale /* = true */) +{ + QFileInfo fileInfo(QString::fromStdString(fileName)); + + if (fileInfo.suffix().toLower() == "asc") + { + return loadImageFromASC(fileName, autoscale); + } +/* +#ifdef libgeotiff_FOUND + else if (fileInfo.suffix().toLower() == "tif") + { + if (!loadImageFromTIFF(fileName, raster)) + return false; + } +#endif + else if (!loadImageFromFile(fileName, raster)) + return false; +*/ +} + +vtkImageImport* VtkRaster::loadImageFromASC(const std::string &fileName, bool autoscale) +{ + double x0(0), y0(0), delta(1); + size_t width(0), height(0); + float* data = loadDataFromASC(fileName, x0, y0, width, height, delta); + + //delta = 1; + //x0 = 0; y0=0; + vtkImageImport* image = vtkImageImport::New(); + image->SetDataSpacing(delta, delta, delta); + image->SetDataOrigin(x0, y0, 0); + image->SetWholeExtent(x0, x0+width-1, y0, y0+height-1, 0, 0); + image->SetDataExtent(x0, x0+width-1, y0, y0+height-1, 0, 0); + //image->SetDataExtentToWholeExtent(); + image->SetDataScalarTypeToFloat(); + //image->SetDataScalarTypeToUnsignedChar(); + image->SetNumberOfScalarComponents(1); + image->SetImportVoidPointer(data, 0); + image->Update(); + + return image; +} + +bool VtkRaster::readASCHeader(ascHeader &header, std::ifstream &in) +{ + std::string line, tag, value; + + in >> tag; + if (tag.compare("ncols") == 0) + { + in >> value; + header.ncols = atoi(value.c_str()); + } + else + return false; + in >> tag; + if (tag.compare("nrows") == 0) + { + in >> value; + header.nrows = atoi(value.c_str()); + } + else + return false; + in >> tag; + if (tag.compare("xllcorner") == 0) + { + in >> value; + header.x = strtod(replaceString(",", ".", value).c_str(),0); + } + else + return false; + in >> tag; + if (tag.compare("yllcorner") == 0) + { + in >> value; + header.y = strtod(replaceString(",", ".", value).c_str(),0); + } + else + return false; + in >> tag; + if (tag.compare("cellsize") == 0) + { + in >> value; + header.cellsize = strtod(replaceString(",", ".", value).c_str(),0); + } + else + return false; + in >> tag; + if (tag.compare("NODATA_value") == 0) + { + in >> value; + header.noData = atoi(value.c_str()); + } + else + return false; + + // correct raster position by half a pixel for correct visualisation + // argh! wrong! correction has to happen in visualisation object, otherwise the actual data is wrong + //header.x = header.x + (header.cellsize / 2); + //header.y = header.y + (header.cellsize / 2); + + return true; +} + +float* VtkRaster::loadDataFromASC(const std::string &fileName, + double &x0, + double &y0, + size_t &width, + size_t &height, + double &delta) +{ + std::ifstream in( fileName.c_str() ); + + if (!in.is_open()) + { + std::cout << "VtkRaster::loadImageFromASC() - Could not open file..." << std::endl; + return NULL; + } + + ascHeader header; + + if (readASCHeader(header, in)) + { + x0 = header.x; + y0 = header.y; + width = header.ncols; + height = header.nrows; + delta = header.cellsize; + + float* values = new float[header.ncols * header.nrows]; + + int index(0); + std::string s(""); + // read the file into a double-array + for (int j = 0; j < header.nrows; j++) + { + index = (header.nrows - j - 1) * header.ncols; + for (int i = 0; i < header.ncols; i++) + { + in >> s; + values[index + i] = static_cast<float>(strtod(replaceString(",", ".", s).c_str(),0)); + } + } + + in.close(); + return values; + } + return NULL; +} +/* +#ifdef libgeotiff_FOUND +bool VtkRaster::loadImageFromTIFF(const std::string &fileName, + QImage &raster, + QPointF &origin, + double &cellsize) +{ + TIFF* tiff = XTIFFOpen(fileName.toStdString().c_str(), "r"); + + if (tiff) + { + GTIF* geoTiff = GTIFNew(tiff); + + if (geoTiff) + { + int imgWidth = 0, imgHeight = 0, nImages = 0, pntCount = 0; + double* pnts = 0; + + // get actual number of images in the tiff file + do { + nImages++; + } while (TIFFReadDirectory(tiff)); + if (nImages > 1) + std::cout << "OGSRaster::loadImageFromTIFF() - File contains " << + nImages << " images. This method is not tested for this case." << + std::endl; + + // get image size + TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &imgWidth); + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &imgHeight); + + // get cellsize + // Note: GeoTiff allows anisotropic pixels. This is not supported here and equilateral pixels are assumed. + if (TIFFGetField(tiff, GTIFF_PIXELSCALE, &pntCount, &pnts)) + { + if (pnts[0] != pnts[1]) + std::cout << + "OGSRaster::loadImageFromTIFF() - Warning: Original raster data has anisotrop pixel size!" + << std::endl; + cellsize = pnts[0]; + } + + // get upper left point / origin + if (TIFFGetField(tiff, GTIFF_TIEPOINTS, &pntCount, &pnts)) + { + origin.setX(pnts[3]); + origin.setY(pnts[4] - (imgHeight * cellsize)); // the origin should be the lower left corner of the img + } + + // read pixel values + uint32* pixVal = + (uint32*) _TIFFmalloc(imgWidth * imgHeight * sizeof (uint32)); + if ((imgWidth > 0) && (imgHeight > 0)) + if (!TIFFReadRGBAImage(tiff, imgWidth, imgHeight, pixVal, 0)) + { + std::cout << + "OGSRaster::loadImageFromTIFF() - Error reading GeoTIFF file." + << std::endl; + _TIFFfree(pixVal); + GTIFFree(geoTiff); + XTIFFClose(tiff); + return false; + } + + // read colormap if it exists + uint16* cmap_red = NULL, * cmap_green = NULL, * cmap_blue = NULL; + int colormap_used = TIFFGetField(tiff, + TIFFTAG_COLORMAP, + &cmap_red, + &cmap_green, + &cmap_blue); + + int lineindex = 0, idx = 0; + QImage img(imgWidth, imgHeight, QImage::Format_ARGB32); + + int* pxl (new int[4]); + for (int j = 0; j < imgHeight; j++) + { + lineindex = j * imgWidth; + for (int i = 0; i < imgWidth; i++) + { // scale intensities and set nodata values to white (i.e. the background colour) + idx = TIFFGetR(pixVal[lineindex + i]); + if (colormap_used) + img.setPixel(i,j, + qRgba(cmap_red[idx] >> 8, + cmap_green[idx] >> 8, + cmap_blue[idx] >> 8, 255)); + else + { + //img.setPixel(i,j, qRgba(TIFFGetB(pixVal[idx]), TIFFGetG(pixVal[idx]), TIFFGetR(pixVal[idx]), TIFFGetA(pixVal[idx]))); + uint32toRGBA(pixVal[lineindex + i], pxl); + img.setPixel(i,j, + qRgba(pxl[0], pxl[1], pxl[2], pxl[3])); + } + } + } + delete [] pxl; + + raster = img; + + _TIFFfree(pixVal); + GTIFFree(geoTiff); + XTIFFClose(tiff); + return true; + } + + XTIFFClose(tiff); + std::cout << + "OGSRaster::loadImageFromTIFF() - File not recognised as GeoTIFF-Image." << + std::endl; + return false; + } + + std::cout << "OGSRaster::loadImageFromTIFF() - File not recognised as TIFF-Image." << + std::endl; + return false; +} +#endif + +bool VtkRaster::loadImageFromFile(const std::string &fileName, QImage &raster) +{ + return raster.load(fileName); +} + +void VtkRaster::convertToGreyscale(vtkImageData &raster, const int &min, const int &max) +{ + int value = 0; + double scalingFactor = 255.0 / (max - min); + + for (int i = 0; i < raster.width(); i++) + for (int j = 0; j < raster.height(); j++) + { + QRgb pix = raster.pixel(i,j); + value = + static_cast<int>(floor(((0.3 * qRed(pix) + 0.6 * qGreen(pix) + + 0.1 * + qBlue(pix)) - min) * scalingFactor)); + raster.setPixel(i, j, qRgb(value, value, value)); + } +} + +int* VtkRaster::getGreyscaleData(vtkImageData &raster, const int &min, const int &max) +{ + int index = 0; + double scalingFactor = 255.0 / (max - min); + int* pixVal (new int[raster.height() * raster.width()]); + + for (int j = 0; j < raster.height(); j++) + { + index = j * raster.width(); + for (int i = 0; i < raster.width(); i++) + { + QRgb pix = raster.pixel(i,j); + pixVal[index + + i] = + static_cast<int>(floor(((0.3 * qRed(pix) + 0.6 * qGreen(pix) + + 0.1 * + qBlue(pix)) - min) * scalingFactor)); + } + } + return pixVal; +} +*/ + +void VtkRaster::uint32toRGBA(const unsigned int s, int* p) +{ + p[3] = s / (256 * 256 * 256); + int r = s % (256 * 256 * 256); + p[2] = r / (256 * 256); + r %= (256 * 256); + p[1] = r / 256; + p[0] = r % 256; +} diff --git a/VtkVis/VtkRaster.h b/VtkVis/VtkRaster.h new file mode 100644 index 0000000000000000000000000000000000000000..8de5554a8d6997fe70c1ff4af8a4f909496b35b9 --- /dev/null +++ b/VtkVis/VtkRaster.h @@ -0,0 +1,118 @@ +/** + * \file VtkRaster.h + * 2012/02/01 KR Initial implementation + * + */ +#ifndef VTKRASTER_H +#define VTKRASTER_H + +#include <fstream> + +class vtkImageAlgorithm; +class vtkImageImport; + +/** + * \brief Loading of raster data such as images or ArcGIS-data. + * + * The VtkRaster class enables loading of raster data such as images or ArcGIS-data. Supported image formats are ..... + * Georeferenced data can be imported via the GeoTIFF- or asc-format. + */ +class VtkRaster +{ + /// Data structure for the asc-file header. + struct ascHeader + { + int ncols; + int nrows; + double x; + double y; + double cellsize; + int noData; + }; + +public: + /** + * \brief Loads an image- or raster-file into an vtkImageData-Object. + * + * Public method for loading all data formats. Internally the method automatically differentiates between + * images and georeferenced files and then calls the appropriate method for reading the file. + * \param fileName Filename of the file that should be loaded. + * \param raster The QImage into which the raster data will be written. + * \param origin The upper left corner of the data set, the default value is (0,0). + * \param scalingFactor The size of each pixel in the image which is needed for re-scaling the data, the default value is 1. + * \param autoscale Determines if the histogram of the raster will be contrast-stretched to [0, 255]. If false, the streching process will be skipped. + * \param mirrorX Mirror around x-axis. + * \return True if the raster data was loaded correctly, false otherwise. + */ + static vtkImageAlgorithm* loadImage(const std::string &fileName, bool autoscale = false); + + /** + * \brief Loads an ASC file into a double array + * + * \param fileName Filename of the file that should be loaded. + * \param x0 The x-coordinate of the origin. + * \param y0 The y-coordinate of the origin. + * \param width The width of the image. + * \param height The height of the image + * \param delta The size of each pixel in the image which is needed for re-scaling the data. + * \return True if the raster data was loaded correctly, false otherwise. + */ + static float* loadDataFromASC(const std::string &fileName, + double &x0, + double &y0, + size_t &width, + size_t &height, + double &delta); + + /// Converts raster to an 8 bit greyscale image that is contrast-stretched in [min:max]. + //static void convertToGreyscale(vtkImageData &raster, const int &min = 0, const int &max = 255); + + /// Returns an int-array containing the raster converted an 8 bit greyscale values that are contrast-stretched in [min:max]. + //static int* getGreyscaleData(vtkImageData &raster, const int &min = 0, const int &max = 255); + +private: + /** + * Loads ArcGIS asc-files to a QPixmap object and automatically does a contrast stretching to adjust values to 8 bit greyscale images. + * \param fileName Filename of the file that should be loaded. + * \param raster The QPixmap into which the raster data will be written. + * \param origin The upper left corner of the data set + * \param scalingFactor + * \param autoscale + * \return True if the raster data was loaded correctly, false otherwise. + */ + static vtkImageImport* loadImageFromASC(const std::string &fileName, bool autoscale = true); + + /** + * Loads ArcGIS asc-files to a QPixmap object and automatically does a contrast stretching to adjust values to 8 bit greyscale images. + * \param fileName Filename of the file that should be loaded. + * \param raster The QPixmap into which the raster data will be written. + * \param origin The upper left corner of the data set + * \param scalingFactor + * \return True if the raster data was loaded correctly, false otherwise. + */ + /* +#ifdef libgeotiff_FOUND + static bool loadImageFromTIFF(const std::string &fileName, + vtkImageData &raster, +#endif + */ + + /** + * Loads image files into a QPixmap object. Since images are not geo-referenced no origin point will be returned. + * \param fileName Filename of the file that should be loaded. + * \param raster The QPixmap into which the raster data will be written. + * \return True if the raster data was loaded correctly, false otherwise. + */ + //static bool loadImageFromFile(const std::string &fileName, vtkImageData &raster); + + /** + * Reads the header of an ArcGIS asc-file. + * \param header The ascHeader-object into which all the information will be written. + * \param in FileInputStream used for reading the data. + * \return True if the header could be read correctly, false otherwise. + */ + static bool readASCHeader(ascHeader &header, std::ifstream &in); + static void uint32toRGBA(const unsigned int s, int* p); +}; + +#endif //VTKRASTER_H diff --git a/VtkVis/VtkVisImageItem.cpp b/VtkVis/VtkVisImageItem.cpp index 11e784c0741edca32b11f3ea789df49dc14cddd5..f4706b67615ad84c20443bc77110b1b41073e58a 100644 --- a/VtkVis/VtkVisImageItem.cpp +++ b/VtkVis/VtkVisImageItem.cpp @@ -6,11 +6,13 @@ // ** INCLUDES ** #include "VtkAlgorithmProperties.h" #include "VtkVisImageItem.h" +#include "VtkGeoImageSource.h" #include <vtkActor.h> #include <vtkDataSetMapper.h> #include <vtkImageAlgorithm.h> #include <vtkImageChangeInformation.h> +#include <vtkImageData.h> #include <vtkRenderer.h> #include <vtkSmartPointer.h> @@ -39,8 +41,13 @@ VtkVisImageItem::~VtkVisImageItem() void VtkVisImageItem::Initialize(vtkRenderer* renderer) { + VtkGeoImageSource* img = dynamic_cast<VtkGeoImageSource*>(_algorithm); _transformFilter = vtkImageChangeInformation::New(); _transformFilter->SetInputConnection(_algorithm->GetOutputPort()); + double origin[3] = {0,0,0}; + double scaling[3] = {1,1,1}; + _transformFilter->SetOutputOrigin(origin);//img->GetOutput()->GetOrigin()); + _transformFilter->SetOutputSpacing(img->GetOutput()->GetSpacing()); _transformFilter->Update(); _renderer = renderer; diff --git a/VtkVis/VtkVisPipelineItem.cpp b/VtkVis/VtkVisPipelineItem.cpp index cc2fe2cb975855ddcfe74f61f6d30c051d3d66e5..dcdefcc3778b2180f8f7a1cc276873ed414033ff 100644 --- a/VtkVis/VtkVisPipelineItem.cpp +++ b/VtkVis/VtkVisPipelineItem.cpp @@ -96,6 +96,9 @@ void VtkVisPipelineItem::setVisible( bool visible ) _actor->SetVisibility((int)visible); _actor->Modified(); _renderer->Render(); + + double extend[6]; + _actor->GetBounds(extend); } int VtkVisPipelineItem::writeToFile(const std::string &filename) const diff --git a/VtkVis/VtkVisPipelineView.cpp b/VtkVis/VtkVisPipelineView.cpp index 302a4c1c5701f245a8755103a3b41f5b952d2b05..bb56c65df19ed9e6315633a952d43f4c894d8ea3 100644 --- a/VtkVis/VtkVisPipelineView.cpp +++ b/VtkVis/VtkVisPipelineView.cpp @@ -179,8 +179,8 @@ void VtkVisPipelineView::constructMeshFromImage(QString msh_name, MshElemType::t vtkSmartPointer<VtkGeoImageSource> imageSource = VtkGeoImageSource::SafeDownCast(algorithm); vtkSmartPointer<vtkImageData> image = imageSource->GetOutput(); - GridAdapter* mesh = VtkMeshConverter::convertImgToMesh(image, imageSource->getOrigin(), - imageSource->getSpacing(), + GridAdapter* mesh = VtkMeshConverter::convertImgToMesh(image, imageSource->GetOutput()->GetOrigin(), + imageSource->GetOutput()->GetSpacing()[0], element_type, intensity_type); mesh->setName(msh_name.toStdString()); emit meshAdded(mesh);