std::shared_ptr<VolumeRAM> VolumeGL2RAMConverter::createFrom( std::shared_ptr<const VolumeGL> volumeGL) const { auto volume = createVolumeRAM(volumeGL->getDimensions(), volumeGL->getDataFormat()); if (volume) { volumeGL->getTexture()->download(volume->getData()); return volume; } else { LogError("Cannot convert format from GL to RAM:" << volumeGL->getDataFormat()->getString()); } return nullptr; }
DataRepresentation* VolumeGL2RAMConverter::createFrom(const DataRepresentation* source) { const VolumeGL* volumeGL = static_cast<const VolumeGL*>(source); VolumeRAM* volume = createVolumeRAM(volumeGL->getDimensions(), volumeGL->getDataFormat()); if (volume) { volumeGL->getTexture()->download(volume->getData()); return volume; } else { LogError("Cannot convert format from GL to RAM:" << volumeGL->getDataFormat()->getString()); } return nullptr; }
std::shared_ptr<VolumeRAM> VolumeCL2RAMConverter::createFrom( std::shared_ptr<const VolumeCL> volumeCL) const { size3_t dimensions = volumeCL->getDimensions(); auto destination = createVolumeRAM(dimensions, volumeCL->getDataFormat()); if (destination) { volumeCL->download(destination->getData()); // const cl::CommandQueue& queue = OpenCL::getInstance()->getQueue(); // queue.enqueueReadImage(volumeCL->getVolume(), true, glm::size3_t(0), // glm::size3_t(dimension), 0, 0, volumeRAM->getData()); } return destination; }
DataRepresentation* VolumeCL2RAMConverter::createFrom(const DataRepresentation* source) { DataRepresentation* destination = 0; const VolumeCL* volumeCL = static_cast<const VolumeCL*>(source); size3_t dimensions = volumeCL->getDimensions(); destination = createVolumeRAM(dimensions, volumeCL->getDataFormat()); if (destination) { VolumeRAM* volumeRAM = static_cast<VolumeRAM*>(destination); volumeCL->download(volumeRAM->getData()); //const cl::CommandQueue& queue = OpenCL::getInstance()->getQueue(); //queue.enqueueReadImage(volumeCL->getVolume(), true, glm::size3_t(0), glm::size3_t(dimension), 0, 0, volumeRAM->getData()); } return destination; }
std::shared_ptr<VolumeRAM> VolumeCLGL2RAMConverter::createFrom( std::shared_ptr<const VolumeCLGL> volumeCLGL) const { const size3_t dimensions{volumeCLGL->getDimensions()}; auto destination = createVolumeRAM(dimensions, volumeCLGL->getDataFormat()); if (destination) { volumeCLGL->getTexture()->download(destination->getData()); // const cl::CommandQueue& queue = OpenCL::getPtr()->getQueue(); // queue.enqueueReadVolume(volumeCL->get(), true, glm::size3_t(0), glm::size3_t(dimensions, // 1), 0, 0, volumeRAM->getData()); } else { LogError("Invalid conversion or not implemented"); } return destination; }
std::shared_ptr<VolumeRepresentation> Volume::createDefaultRepresentation() const { return createVolumeRAM(getDimensions(), getDataFormat()); }
Volume* MPVMVolumeReader::readMetaData(std::string filePath) { if (!filesystem::fileExists(filePath)) { std::string newPath = filesystem::addBasePath(filePath); if (filesystem::fileExists(newPath)) { filePath = newPath; } else { throw DataReaderException("Error could not find input file: " + filePath, IvwContext); } } std::string fileDirectory = filesystem::getFileDirectory(filePath); // Read the mpvm file content std::istream* f = new std::ifstream(filePath.c_str()); std::string textLine; std::vector<std::string> files; while (!f->eof()) { getline(*f, textLine); textLine = trim(textLine); files.push_back(textLine); }; delete f; if (files.empty()) throw DataReaderException("Error: No PVM files found in " + filePath, IvwContext); if (files.size() > 4) throw DataReaderException("Error: Maximum 4 pvm files are supported, file: " + filePath, IvwContext); // Read all pvm volumes std::vector<Volume*> volumes; for (size_t i = 0; i < files.size(); i++) { Volume* newVol = PVMVolumeReader::readPVMData(fileDirectory + files[i]); if (newVol) volumes.push_back(newVol); else LogWarn("Could not load " << fileDirectory << files[i]); } if (volumes.empty()) throw DataReaderException("No PVM volumes could be read from file: " + filePath, IvwContext); if (volumes.size() == 1) { printPVMMeta(volumes[0], fileDirectory + files[0]); return volumes[0]; } // Make sure dimension and format match const DataFormatBase* format = volumes[0]->getDataFormat(); size3_t mdim = volumes[0]->getDimensions(); for (size_t i = 1; i < volumes.size(); i++) { if (format != volumes[i]->getDataFormat() || mdim != volumes[i]->getDimensions()) { LogWarn("PVM volumes did not have the same format or dimensions, using first volume."); printPVMMeta(volumes[0], fileDirectory + files[0]); return volumes[0]; } } // Create new format const DataFormatBase* mformat = DataFormatBase::get(format->getNumericType(), volumes.size(), format->getSize()*8); // Create new volume Volume* volume = new Volume(); glm::mat3 basis = volumes[0]->getBasis(); volume->setBasis(basis); volume->setOffset(-0.5f * (basis[0] + basis[1] + basis[2])); volume->setDimensions(mdim); volume->dataMap_.initWithFormat(mformat); volume->setDataFormat(mformat); volume->copyMetaDataFrom(*volumes[0]); // Merge descriptions but ignore the rest StringMetaData* metaData = volume->getMetaData<StringMetaData>("description"); if (metaData) { std::string descStr = metaData->get(); for (size_t i = 1; i < volumes.size(); i++) { metaData = volumes[0]->getMetaData<StringMetaData>("description"); if (metaData) descStr = descStr + ", " + metaData->get(); } volume->setMetaData<StringMetaData>("description", descStr); } // Create RAM volume VolumeRAM* mvolRAM = createVolumeRAM(mdim, mformat); unsigned char* dataPtr = static_cast<unsigned char*>(mvolRAM->getData()); std::vector<const unsigned char*> volumesDataPtr; for (size_t i = 0; i < volumes.size(); i++) { volumesDataPtr.push_back(static_cast<const unsigned char*>( volumes[i]->getRepresentation<VolumeRAM>()->getData())); } // Copy the data from the other volumes to the new multichannel volume size_t mbytes = mformat->getSize(); size_t bytes = format->getSize(); size_t dims = mdim.x * mdim.y * mdim.z; size_t vsize = volumesDataPtr.size(); for (size_t i = 0; i < dims; i++) { for (size_t j = 0; j < vsize; j++) { for (size_t b = 0; b < bytes; b++) { dataPtr[i * mbytes + (j * bytes) + b] = volumesDataPtr[j][i * bytes + b]; } } } // Delete the single channel volumes for (size_t i = 0; i < volumes.size(); i++) { delete volumes[i]; } volume->addRepresentation(mvolRAM); printPVMMeta(volume, filePath); return volume; }