void writeAttachment( const ::boost::filesystem::path& filePath, const ::fwAtoms::Object::sptr atom ) { const ::boost::filesystem::path folderPath = filePath.parent_path(); const ::boost::filesystem::path filename = filePath.filename(); std::string extension = ::boost::filesystem::extension(filePath); // Write atom ::fwZip::IWriteArchive::sptr writeArchive; ::fwAtomsBoostIO::FormatType format; ::boost::filesystem::path archiveRootName; if ( extension == ".json" ) { writeArchive = ::fwZip::WriteDirArchive::New(folderPath.string()); archiveRootName = filename; format = ::fwAtomsBoostIO::JSON; } else if ( extension == ".jsonz" ) { if ( ::boost::filesystem::exists( filePath ) ) { ::boost::filesystem::remove( filePath ); } writeArchive = ::fwZip::WriteZipArchive::New(filePath.string()); archiveRootName = "root.json"; format = ::fwAtomsBoostIO::JSON; } else { FW_RAISE( "This file extension '" << extension << "' is not managed" ); } ::fwAtomsBoostIO::Writer(atom).write( writeArchive, archiveRootName, format ); writeArchive.reset(); }
::fwAtoms::Object::sptr readAttachment( const ::boost::filesystem::path& filePath ) { const ::boost::filesystem::path folderPath = filePath.parent_path(); const ::boost::filesystem::path filename = filePath.filename(); const std::string extension = ::boost::filesystem::extension(filePath); ::fwZip::IReadArchive::sptr readArchive; ::boost::filesystem::path archiveRootName; ::fwAtomsBoostIO::FormatType format = ::fwAtomsBoostIO::UNSPECIFIED; if ( extension == ".json" ) { readArchive = ::fwZip::ReadDirArchive::New(folderPath.string()); archiveRootName = filename; format = ::fwAtomsBoostIO::JSON; } else if ( extension == ".jsonz" ) { readArchive = ::fwZip::ReadZipArchive::New(filePath.string()); archiveRootName = "root.json"; format = ::fwAtomsBoostIO::JSON; } else { FW_RAISE( "This file extension '" << extension << "' is not managed" ); } ::fwAtomsBoostIO::Reader reader; ::fwAtoms::Object::sptr atom = ::fwAtoms::Object::dynamicCast(reader.read(readArchive, archiveRootName, format)); return atom; }
void MetaImageReader::read() { assert( !m_object.expired() ); assert( m_object.lock() ); ::fwData::Image::sptr pImage = this->getConcreteObject(); vtkSmartPointer< vtkMetaImageReader > reader = vtkSmartPointer< vtkMetaImageReader >::New(); reader->SetFileName(this->getFile().string().c_str()); Progressor progress(reader, this->getSptr(), this->getFile().string()); reader->Update(); reader->UpdateInformation(); reader->PropagateUpdateExtent(); vtkDataObject *obj = reader->GetOutput(); vtkImageData* img = vtkImageData::SafeDownCast(obj); FW_RAISE_IF("MetaImageReader cannot read mhd image file :"<<this->getFile().string(), !img); try { ::fwVtkIO::fromVTKImage( img, pImage); } catch( std::exception &e) { FW_RAISE("MetaImage to fwData::Image failed : "<<e.what()); } }
void ImageReader::read() { assert( !m_object.expired() ); assert( m_object.lock() ); ::fwData::Image::sptr pImage = getConcreteObject(); vtkSmartPointer< vtkGenericDataObjectReader > reader = vtkSmartPointer< vtkGenericDataObjectReader >::New(); reader->SetFileName(this->getFile().string().c_str()); //add progress observation Progressor progress(reader, this->getSptr(), this->getFile().string()); reader->Update(); vtkDataObject *obj = reader->GetOutput(); vtkImageData* img = vtkImageData::SafeDownCast(obj); FW_RAISE_IF("ImageReader cannot read VTK image file :"<<this->getFile().string(), !img); try { ::vtkIO::fromVTKImage( img, pImage); } catch( std::exception &e) { FW_RAISE("VTKImage to fwData::Image failed "<<e.what()); } }
void IProgressDialog::cancelPressed() { m_canceled = true; if(m_cancelCallback) { m_cancelCallback(); } else if (m_raise) { FW_RAISE("Operation canceled"); } }
static SPTR(DATATYPE) getAttribute( xmlNodePtr source, const std::string & name , bool isMandatory = true ) { SPTR(DATATYPE) castedData; xmlNodePtr fatherNode = XMLParser::findChildNamed( source, name ); if ( fatherNode ) { OSLM_ASSERT("Sorry, node '"<< name <<"' not instanced", fatherNode); xmlNodePtr node = ::fwXML::XMLParser::getChildrenXMLElement( fatherNode ); OSLM_ASSERT("Sorry, child node of '"<< name <<"' node not instanced", node); ::fwData::Object::sptr obj; obj = Serializer().ObjectsFromXml( node ); castedData = ::boost::dynamic_pointer_cast<DATATYPE>( obj ); OSLM_ASSERT("DynamicCast "<< ::fwCore::TypeDemangler<DATATYPE>().getFullClassname()<<" failed", castedData); } else if ( isMandatory ) { FW_RAISE("Sorry, attribute " << name << " is mandatory."); } return castedData; }