void VolumeCrop::crop() { if (!inport_.hasData()) return; const VolumeHandleBase* inputHandle = inport_.getData(); VolumeHandle* outputVolume = 0; tgt::ivec3 start, dimensions; start.x = clipRight_.get(); start.y = clipFront_.get(); start.z = clipBottom_.get(); dimensions.x = clipLeft_.get() - clipRight_.get() + 1; dimensions.y = clipBack_.get() - clipFront_.get() + 1; dimensions.z = clipTop_.get() - clipBottom_.get() + 1; outputVolume = VolumeOperatorSubset::APPLY_OP(inport_.getData(), start, dimensions, progressBar_); outputVolume->setSpacing(inputHandle->getSpacing()); // assign computed volume to outport if (outputVolume) { if(preserveLocation_.get()) { outputVolume->setPhysicalToWorldMatrix(inputHandle->getPhysicalToWorldMatrix()); } else { oldVolumePosition(outputVolume); outputVolume->setPhysicalToWorldMatrix(tgt::mat4::identity); } outport_.setData(outputVolume); } else outport_.setData(0); }
voreen::VolumeCollection* VolumeCollection::selectOriginTimestep(const VolumeOrigin& origin, float timestep) const { VolumeCollection* collection = new VolumeCollection(); for (size_t i=0; i<volumeHandles_.size(); ++i) { VolumeHandle* vh = dynamic_cast<VolumeHandle*>(volumeHandles_[i]); if (vh && vh->getOrigin() == origin && vh->getTimestep() == timestep) collection->add(volumeHandles_[i]); } return collection; }
void VolumeHandlePropertyWidget::volumeAdded(const VolumeCollection* /*source*/, const VolumeHandle* /*handle*/) { int i = volumeContainer_->size()-1; VolumeHandle* handle = volumeContainer_->at(i); volumeSelectorBox_->addItem(VolumeViewHelper::generateBorderedPreview(handle->getVolume(), 30, 1), QString::fromStdString(VolumeViewHelper::getStrippedVolumeName(handle)), QString::fromStdString(VolumeViewHelper::getVolumeName(handle))); // disable selector box, when no volume available volumeSelectorBox_->setEnabled(volumeSelectorBox_->count() > 1); emit modified(); }
void VolumeHandlePropertyWidget::updateFromContainer() { if (!volumeContainer_) return; volumeSelectorBox_->clear(); QPixmap white = QPixmap(30, 30); white.fill(); volumeSelectorBox_->addItem(white, tr("Select volume ...")); for (size_t i = 0; i < volumeContainer_->size(); i++) { VolumeHandle* handle = volumeContainer_->at(i); volumeSelectorBox_->addItem(VolumeViewHelper::generateBorderedPreview(handle->getVolume(), 30, 1), QString::fromStdString(VolumeViewHelper::getStrippedVolumeName(handle)), QString::fromStdString(VolumeViewHelper::getVolumeName(handle))); } // disable selector box, when no volume available volumeSelectorBox_->setEnabled(volumeSelectorBox_->count() > 1); }
VolumeCollection* FlowReader::read(const std::string& url) throw(tgt::FileException, std::bad_alloc) { VolumeOrigin origin(url); std::string fileName = origin.getPath(); LINFO("reading flow file '" << fileName << "'..."); // try to open the file // std::fstream ifs(fileName.c_str(), std::ios_base::in | std::ios_base::binary); if (ifs.good() == false) throw tgt::IOException("Unable to open flow file for reading", fileName); // read the magic number (string "VOREENFLOW") // char magicNumber[11] = {0}; ifs.read(magicNumber, 11); std::string temp(magicNumber); if (temp != "VOREENFLOW") throw tgt::IOException("Missing magic number in flow file", fileName); // read file version (must currently be 1 or 2) // unsigned int fileVersion = 0; ifs.read(reinterpret_cast<char*>(&fileVersion), sizeof(unsigned int)); LINFO("file version: " << fileVersion); if ((fileVersion < 1) || (fileVersion > 2)) throw tgt::IOException("Unsupported file version of flow file", fileName); // read flow dimension (usually 3 for 3D flows) // unsigned int flowDimension = 0; ifs.read(reinterpret_cast<char*>(&flowDimension), sizeof(unsigned int)); LINFO("flow dimension: " << flowDimension << "D"); if (flowDimension != 3) throw tgt::IOException("Unsupported flow dimension in flow file", fileName); unsigned char dataOrientation = 0; unsigned char reverseSlicesMask = 0; ifs.read(reinterpret_cast<char*>(&dataOrientation), sizeof(unsigned char)); if (fileVersion > 1) { ifs.read(reinterpret_cast<char*>(&reverseSlicesMask), sizeof(unsigned char)); } // read the dimension of the volume data containing the flow // tgt::ivec3 dimensions; ifs.read(reinterpret_cast<char*>(&dimensions), sizeof(tgt::ivec3)); LINFO("volume dimensions: " << dimensions); unsigned int byteSize = 0; ifs.read(reinterpret_cast<char*>(&byteSize), sizeof(unsigned int)); LINFO("expected size of vector field: " << byteSize << " byte"); VolumeFlow3D* volume = readConvert(dimensions, dataOrientation, ifs); ifs.close(); if (volume == 0) { LERROR("an error occured during reading flow data! Proceeding impossible."); return 0; } if (reverseSlicesMask != 0) reverseSlices(volume, reverseSlicesMask); // TODO: volume container merge /*VolumeSet* volumeSet = new VolumeSet(fileName); VolumeSeries* volumeSeries = new VolumeSeries(Modality::MODALITY_FLOW.getName(), Modality::MODALITY_FLOW); volumeSet->addSeries(volumeSeries); VolumeHandle* volumeHandle = new VolumeHandle(volume, 0.0f); volumeSeries->addVolumeHandle(volumeHandle); */ VolumeCollection* collection = new VolumeCollection(); VolumeHandle* volumeHandle = new VolumeHandle(volume, tgt::vec3(1.0f), tgt::vec3(0.0f));//FIXME: spacing? oldVolumePosition(volumeHandle); volumeHandle->setModality(Modality::MODALITY_FLOW); collection->add(volumeHandle); // TODO: origin does not save series and timestamp anymore //volumeHandle->setOrigin(fileName, Modality::MODALITY_FLOW.getName(), 0.0f); volumeHandle->setOrigin(fileName); return collection; }
VolumeCollection* PVMVolumeReader::read(const std::string &url) throw (tgt::FileException, tgt::IOException, std::bad_alloc) { VolumeOrigin origin(url); std::string fileName = origin.getPath(); uint8_t* data; uint8_t* tmpData; unsigned int width, height, depth, components; float scalex, scaley, scalez; unsigned char *description; unsigned char *courtesy; unsigned char *parameter; unsigned char *comment; LINFO("Reading PVM volume " << fileName); /* TODO This subroutine returns an array created with malloc but it should be created with 'new[]' because this chunk of data will be deleted with 'delete[]'. This can cause hard to find errors. As a temporary workaround the data are copied over into a new array and the c-array is deleted with 'free'. Because of some c-pointer vodoo done in ddsbase.cpp free must be invoked after the use of all other returned pointers. (roland) */ tmpData = readPVMvolume(const_cast<char*>(fileName.c_str()), getProgressBar(), &width, &height, &depth, &components, &scalex, &scaley, &scalez, &description, &courtesy, ¶meter, &comment); if (!tmpData) { LERROR("PVM Reading failed"); return 0; } data = new uint8_t[width * height * depth * components]; memcpy(data, tmpData, width * height * depth * components); Volume* dataset = 0; if (!data) { throw tgt::IOException(); } else { LINFO("Size: " << width << " x " << height << " x " << depth); LINFO("Spacing: " << scalex << " x " << scaley << " x " << scalez); LINFO("Components: " << components); if (description) LINFO("Description: " << description); if (courtesy) LINFO("Courtesy: " << courtesy); if (parameter) LINFO("Parameter: " << parameter); if (comment) LINFO("Comment: " << comment); if (components == 1) { LINFO("Create 8 bit data set."); dataset = new VolumeUInt8(data, tgt::ivec3(width, height, depth), tgt::vec3(scalex, scaley, scalez)); } else if (components == 2) { // the endianness conversion in ddsbase.cpp seem to be broken, // so we perform it here instead uint16_t* data16 = reinterpret_cast<uint16_t*>(data); int numElements = width * height * depth; uint16_t maxValue = 0; for (int i=0; i < numElements; i++) { endian_swap(data16[i]); if (data16[i] > maxValue) maxValue = data16[i]; } int bits; if (maxValue < 4096) { LINFO("Create 12 bit data set."); bits = 12; } else { LINFO("Create 16 bit data set."); bits = 16; } dataset = new VolumeUInt16((uint16_t*)data, tgt::ivec3(width, height, depth), tgt::vec3(scalex, scaley, scalez), tgt::mat4::identity, bits); } else LERROR("Bit depth not supported."); } // TODO now it is safe to free free(tmpData); VolumeCollection* volumeCollection = new VolumeCollection(); if (dataset) { VolumeHandle* volumeHandle = new VolumeHandle(dataset, 0.0f); volumeHandle->setOrigin(VolumeOrigin(fileName)); volumeCollection->add(volumeHandle); } return volumeCollection; }
void CoordinateTransformation::process() { // do nothing, if neither input data nor coordinate system selection has changed if (!geometryInport_.hasChanged() && !volumeInport_.hasChanged() && !forceUpdate_) return; // clear output delete geometryOutport_.getData(); geometryOutport_.setData(0); forceUpdate_ = false; // return if no input data present if (!geometryInport_.hasData() || !volumeInport_.hasData()) return; // retrieve and check geometry from inport PointListGeometryVec3* geometrySrc = dynamic_cast<PointListGeometryVec3*>(geometryInport_.getData()); PointSegmentListGeometryVec3* geometrySegmentSrc = dynamic_cast<PointSegmentListGeometryVec3*>(geometryInport_.getData()); if (!geometrySrc && !geometrySegmentSrc) { LWARNING("Geometry of type TGTvec3PointListGeometry or TGTvec3PointSegmentListGeometry expected"); return; } // retrieve volume handle from inport VolumeHandle* volumeHandle = volumeInport_.getData(); tgtAssert(volumeHandle, "No volume handle"); tgtAssert(volumeHandle->getVolume(), "No volume"); // create output geometry object PointListGeometryVec3* geometryConv = 0; PointSegmentListGeometryVec3* geometrySegmentConv = 0; if (geometrySrc) geometryConv = new PointListGeometryVec3(); else if (geometrySegmentSrc) geometrySegmentConv = new PointSegmentListGeometryVec3(); // // convert points // // voxel coordinates (no transformation necessary) if (targetCoordinateSystem_.isSelected("voxel-coordinates")) { // pointlist if (geometrySrc) { std::vector<tgt::vec3> geomPointsConv = std::vector<tgt::vec3>(geometrySrc->getData()); geometryConv->setData(geomPointsConv); } // segmentlist else if (geometrySegmentSrc) { std::vector< std::vector<tgt::vec3> >geomPointsConv = std::vector< std::vector<tgt::vec3> >(geometrySegmentSrc->getData()); geometrySegmentConv->setData(geomPointsConv); } } // volume coordinates else if (targetCoordinateSystem_.isSelected("volume-coordinates")) { tgt::vec3 dims(volumeHandle->getVolume()->getDimensions()); tgt::vec3 cubeSize = volumeHandle->getVolume()->getCubeSize(); // pointlist if (geometrySrc) { std::vector<tgt::vec3> geomPointsConv = std::vector<tgt::vec3>(geometrySrc->getData()); for (size_t i=0; i<geomPointsConv.size(); i++) geomPointsConv[i] = ((geomPointsConv[i]/dims) - 0.5f) * cubeSize; geometryConv->setData(geomPointsConv); } // segmentlist else if (geometrySegmentSrc) { std::vector< std::vector<tgt::vec3> >geomPointsConv = std::vector< std::vector<tgt::vec3> >(geometrySegmentSrc->getData()); for (size_t i=0; i<geomPointsConv.size(); ++i) { for (size_t j=0; j<geomPointsConv[i].size(); ++j) { geomPointsConv[i][j] = ((geomPointsConv[i][j]/dims) - 0.5f) * cubeSize; } geometrySegmentConv->addSegment(geomPointsConv[i]); } } } // world coordinates else if (targetCoordinateSystem_.isSelected("world-coordinates")) { tgt::mat4 voxelToWorldTrafo = volumeHandle->getVolume()->getVoxelToWorldMatrix(); // pointlist if (geometrySrc) { std::vector<tgt::vec3> geomPointsConv = std::vector<tgt::vec3>(geometrySrc->getData()); for (size_t i=0; i<geomPointsConv.size(); i++) geomPointsConv[i] = voxelToWorldTrafo * geomPointsConv[i]; geometryConv->setData(geomPointsConv); } // segmentlist else if (geometrySegmentSrc) { std::vector< std::vector<tgt::vec3> >geomPointsConv = std::vector< std::vector<tgt::vec3> >(geometrySegmentSrc->getData()); for (size_t i=0; i<geomPointsConv.size(); ++i) { for (size_t j=0; j<geomPointsConv[i].size(); ++j) { geomPointsConv[i][j] = voxelToWorldTrafo * geomPointsConv[i][j]; } geometrySegmentConv->addSegment(geomPointsConv[i]); } } } // texture coordinates: [0:1.0]^3 else if (targetCoordinateSystem_.isSelected("texture-coordinates")) { tgt::vec3 dims(volumeHandle->getVolume()->getDimensions()); // pointlist if (geometrySrc) { std::vector<tgt::vec3> geomPointsConv = std::vector<tgt::vec3>(geometrySrc->getData()); for (size_t i=0; i<geomPointsConv.size(); i++) geomPointsConv[i] /= dims; geometryConv->setData(geomPointsConv); } // segmentlist else if (geometrySegmentSrc) { std::vector< std::vector<tgt::vec3> >geomPointsConv = std::vector< std::vector<tgt::vec3> >(geometrySegmentSrc->getData()); for (size_t i=0; i<geomPointsConv.size(); ++i) { for (size_t j=0; j<geomPointsConv[i].size(); ++j) { geomPointsConv[i][j] /= dims; } geometrySegmentConv->addSegment(geomPointsConv[i]); } } } // assign result to outport if (geometrySrc) geometryOutport_.setData(geometryConv); else if (geometrySegmentSrc) geometryOutport_.setData(geometrySegmentConv); else { LWARNING("No geometry object created"); } }
void VolumeHandlePropertyWidget::updateFromProperty() { VolumeHandle* handle = getVolume(); if (handle) { dimensionLabel_->show(); pathLabel_->show(); spacingLabel_->show(); memSizeLabel_->show(); previewLabel_->show(); std::string name = VolumeViewHelper::getStrippedVolumeName(handle); std::string path = VolumeViewHelper::getVolumePath(handle); if(name.size() > 30) { volumeNameLabel_->setToolTip(QString::fromStdString(name)); int end = name.size(); std::string startString; std::string endString; for(size_t i = 0; i < 14; i++){ startString += name.at(i); endString += name.at(end-14+i); } name = startString+"..."+endString; } if (path.size() > 30) { pathLabel_->setToolTip(QString::fromStdString(path)); int end = path.size(); std::string startString; std::string endString; for(size_t i = 0; i < 14; i++){ startString += path.at(i); endString += path.at(end-14+i); } path = startString+"..."+endString; } volumeNameLabel_->setText(QString::fromStdString(" " + name+ " ("+ VolumeViewHelper::getVolumeType(handle->getVolume())+") ")); pathLabel_->setText(QString::fromStdString(" "+path)); dimensionLabel_->setText(QString::fromStdString(VolumeViewHelper::getVolumeDimension(handle->getVolume()))); spacingLabel_->setText(QString::fromStdString(VolumeViewHelper::getVolumeSpacing(handle->getVolume()))); memSizeLabel_->setText(QString::fromStdString(VolumeViewHelper::getVolumeMemorySize(handle->getVolume()))); previewLabel_->setPixmap(VolumeViewHelper::generateBorderedPreview(handle->getVolume(), 70, 0)); // adjust selected index of volume selector box to currently assigned volume volumeSelectorBox_->setCurrentIndex(0); if (volumeContainer_) { tgtAssert(volumeContainer_->size()+1 == static_cast<size_t>(volumeSelectorBox_->count()), "Sizes of volume container and volume selector box do not match"); for (size_t i=0; i < volumeContainer_->size(); ++i) { if (handle == volumeContainer_->at(i)) { volumeSelectorBox_->setCurrentIndex(i+1); break; } } } } else { volumeNameLabel_->setText(tr(" no volume")); volumeNameLabel_->adjustSize(); pathLabel_->hide(); previewLabel_->setPixmap(QPixmap()); dimensionLabel_->hide(); spacingLabel_->hide(); memSizeLabel_->hide(); previewLabel_->hide(); } }